Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7f2db94a
authored
Aug 21, 2025
by
孙美琪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改图片取值,为单个string
parent
45cb85c9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
133 additions
and
599 deletions
+133
-599
src/views/biz/bannerinfo/BannerInfoForm.vue
+19
-112
src/views/biz/bannerinfo/index.vue
+2
-8
src/views/biz/computilityinformation/ComputilityInformationForm.vue
+8
-97
src/views/biz/computilityinformation/index.vue
+2
-2
src/views/biz/industryapplication/IndustryApplicationForm.vue
+27
-163
src/views/biz/industryapplication/index.vue
+9
-34
src/views/biz/information/InformationForm.vue
+45
-92
src/views/biz/information/index.vue
+3
-4
src/views/biz/partner/PartnerForm.vue
+15
-84
src/views/biz/partner/index.vue
+3
-3
No files found.
src/views/biz/bannerinfo/BannerInfoForm.vue
View file @
7f2db94a
...
...
@@ -7,36 +7,14 @@
label-width=
"100px"
v-loading=
"formLoading"
>
<el-form-item
label=
"轮播图地址"
prop=
"images"
>
<div
class=
"upload-box"
>
<el-upload
v-model:file-list=
"formData.images"
:action=
"uploadUrl"
:http-request=
"httpRequest"
list-type=
"picture-card"
:on-preview=
"handlePictureCardPreview"
:on-remove=
"handleRemove"
:on-success=
"handleUploadSuccess"
:on-error=
"handleUploadError"
multiple
>
<el-icon>
<Plus
/>
</el-icon>
</el-upload>
<!-- 添加预览对话框 -->
<el-dialog
v-model=
"previewVisible"
append-to-body
>
<img
style=
"width: 100%"
:src=
"dialogImageUrl"
alt=
"Preview Image"
/>
</el-dialog>
<!-- 添加提示信息 -->
<p
class=
"upload-tips"
>
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
</p>
</div>
<el-form-item
label=
"轮播图地址"
prop=
"image"
>
<UploadImg
v-model=
"formData.image"
/>
<p
class=
"upload-tips"
>
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
</p>
</el-form-item>
<el-form-item
label=
"内容"
prop=
"information"
>
<el-input
v-model=
"formData.information"
placeholder=
"请输入内容"
/>
</el-form-item>
...
...
@@ -58,6 +36,11 @@
<el-form-item
label=
"排序值"
prop=
"orderNum"
>
<el-input
v-model=
"formData.orderNum"
placeholder=
"请输入排序值"
/>
</el-form-item>
<!--
<el-form-item
label=
"状态"
prop=
"showStatus"
>
-->
<!--
<el-radio-group
v-model=
"formData.showStatus"
>
-->
<!--
<el-radio
value=
"1"
>
请选择字典生成
</el-radio>
-->
<!--
</el-radio-group>
-->
<!--
</el-form-item>
-->
<el-form-item
label=
"状态"
prop=
"showStatus"
>
<el-radio-group
v-model=
"formData.showStatus"
>
<el-radio
...
...
@@ -81,13 +64,8 @@
</Dialog>
</template>
<
script
setup
lang=
"ts"
>
import
{
BannerInfoApi
}
from
'@/api/biz/bannerinfo'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
useUpload
}
from
'@/components/UploadFile/src/useUpload'
import
{
Plus
}
from
'@element-plus/icons-vue'
import
{
BannerInfoApi
,
BannerInfo
}
from
'@/api/biz/bannerinfo'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
/** banner页管理 表单 */
defineOptions
({
name
:
'BannerInfoForm'
})
...
...
@@ -95,20 +73,13 @@ defineOptions({ name: 'BannerInfoForm' })
const
{
t
}
=
useI18n
()
// 国际化
const
message
=
useMessage
()
// 消息弹窗
// 添加预览相关的响应式变量
const
previewVisible
=
ref
(
false
)
// 获取上传相关配置
const
{
uploadUrl
,
httpRequest
}
=
useUpload
()
const
dialogImageUrl
=
ref
(
''
)
const
dialogVisible
=
ref
(
false
)
// 弹窗的是否展示
const
dialogTitle
=
ref
(
''
)
// 弹窗的标题
const
formLoading
=
ref
(
false
)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formData
=
ref
({
id
:
undefined
,
image
s
:
[],
// 改为数组,存储多张图片的地址
image
:
undefined
,
information
:
undefined
,
title
:
undefined
,
url
:
undefined
,
...
...
@@ -141,13 +112,7 @@ const open = async (type: string, id?: number) => {
if
(
data
.
description
===
null
)
{
data
.
description
=
''
}
// 将 images 字段转换为 file-list 需要的格式
if
(
data
.
images
&&
Array
.
isArray
(
data
.
images
))
{
formData
.
value
.
images
=
data
.
images
.
map
((
url
)
=>
({
url
,
name
:
'image.jpg'
}))
// 添加 name 属性
}
else
{
formData
.
value
.
images
=
[]
}
formData
.
value
=
{
...
data
,
images
:
formData
.
value
.
images
}
// 确保 image 是数组
formData
.
value
=
data
}
finally
{
formLoading
.
value
=
false
}
...
...
@@ -163,27 +128,7 @@ const submitForm = async () => {
// 提交请求
formLoading
.
value
=
true
try
{
// 确保只提取真实的 URL,而不是本地的 Blob URL
const
imageUrls
=
formData
.
value
.
images
.
filter
((
item
)
=>
item
.
url
&&
!
item
.
url
.
startsWith
(
'blob:'
))
// 过滤掉 Blob URL
.
map
((
item
)
=>
item
.
url
)
// 如果还有 Blob URL,说明有文件还未上传完成
const
hasBlobUrls
=
formData
.
value
.
images
.
some
(
(
item
)
=>
item
.
url
&&
item
.
url
.
startsWith
(
'blob:'
)
)
if
(
hasBlobUrls
)
{
message
.
warning
(
'请等待图片上传完成后再提交'
)
formLoading
.
value
=
false
return
}
// 构造最终数据
const
data
=
{
...
formData
.
value
,
images
:
imageUrls
}
const
data
=
formData
.
value
as
unknown
as
BannerInfo
if
(
formType
.
value
===
'bannerCreate'
)
{
await
BannerInfoApi
.
createBannerInfo
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
...
...
@@ -203,7 +148,7 @@ const submitForm = async () => {
const
resetForm
=
()
=>
{
formData
.
value
=
{
id
:
undefined
,
image
s
:
[]
,
image
:
undefined
,
information
:
undefined
,
title
:
undefined
,
url
:
undefined
,
...
...
@@ -214,51 +159,13 @@ const resetForm = () => {
}
formRef
.
value
?.
resetFields
()
}
// 预览图片
const
handlePictureCardPreview
=
(
file
)
=>
{
dialogImageUrl
.
value
=
file
.
url
previewVisible
.
value
=
true
// 使用独立的预览状态
}
// 删除图片
const
handleRemove
=
(
file
,
fileList
)
=>
{
// 更新 formData.image 数组
// formData.value.images = fileList.map(item => ({ url: item.url, name: item.name }))
formData
.
value
.
images
=
fileList
}
// 上传成功处理函数
const
handleUploadSuccess
=
(
response
,
file
,
fileList
)
=>
{
// 从响应中提取真实的URL并更新文件对象
if
(
response
&&
response
.
data
)
{
// 根据 useUpload.ts 的实现,可能是 response.data.url 或直接是 response.data
const
realUrl
=
response
.
data
.
url
||
response
.
data
if
(
realUrl
)
{
file
.
url
=
realUrl
}
}
// 更新 formData.images
formData
.
value
.
images
=
fileList
}
// 上传失败处理函数
const
handleUploadError
=
(
err
,
file
,
fileList
)
=>
{
message
.
error
(
'图片上传失败: '
+
(
err
.
message
||
'未知错误'
))
}
</
script
>
<
style
scoped
>
.upload-box
{
display
:
flex
;
flex-direction
:
column
;
}
.upload-tips
{
font-size
:
12px
;
color
:
#999
;
margin-top
:
10px
;
margin-left
:
10px
;
}
.red-text
{
...
...
src/views/biz/bannerinfo/index.vue
View file @
7f2db94a
...
...
@@ -93,10 +93,9 @@
<el-table-column
label=
"排序值"
align=
"center"
prop=
"orderNum"
/>
<el-table-column
label=
"轮播图地址"
align=
"center"
prop=
"images"
width=
"100"
>
<template
#
default=
"scope"
>
<!-- 只显示第一张图片 -->
<img
v-if=
"scope.row.image
s && scope.row.images.length > 0
"
:src=
"scope.row.image
s[0]
"
v-if=
"scope.row.image"
:src=
"scope.row.image"
alt=
"轮播图"
class=
"h-36px"
/>
...
...
@@ -257,10 +256,5 @@ const handleExport = async () => {
/** 初始化 **/
onMounted
(()
=>
{
getList
()
console
.
log
(
getIntDictOptions
(
DICT_TYPE
.
HOME_INFO_STATUS
),
'getIntDictOptions(DICT_TYPE.HOME_INFO_STATUS)'
)
})
</
script
>
src/views/biz/computilityinformation/ComputilityInformationForm.vue
View file @
7f2db94a
...
...
@@ -7,34 +7,8 @@
label-width=
"140px"
v-loading=
"formLoading"
>
<el-form-item
label=
"展示图地址"
prop=
"images"
>
<div
class=
"upload-box"
>
<el-upload
v-model:file-list=
"formData.images"
:action=
"uploadUrl"
:http-request=
"httpRequest"
list-type=
"picture-card"
:on-preview=
"handlePictureCardPreview"
:on-remove=
"handleRemove"
:on-success=
"handleUploadSuccess"
:on-error=
"handleUploadError"
multiple
>
<el-icon>
<Plus
/>
</el-icon>
</el-upload>
<!-- 添加预览对话框 -->
<el-dialog
v-model=
"previewVisible"
append-to-body
>
<img
style=
"width: 100%"
:src=
"dialogImageUrl"
alt=
"Preview Image"
/>
</el-dialog>
<!-- 添加提示信息 -->
<p
class=
"upload-tips"
>
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
</p>
</div>
<el-form-item
label=
"展示图地址"
prop=
"image"
>
<UploadImg
v-model=
"formData.image"
/>
</el-form-item>
<el-form-item
label=
"内容"
prop=
"information"
>
...
...
@@ -91,17 +65,12 @@
<
script
setup
lang=
"ts"
>
import
{
ComputilityInformationApi
,
ComputilityInformation
}
from
'@/api/biz/computilityinformation'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
useUpload
}
from
'@/components/UploadFile/src/useUpload'
import
{
Plus
}
from
'@element-plus/icons-vue'
import
{
BannerInfo
}
from
"@/api/biz/bannerinfo"
;
// 添加预览相关的响应式变量
const
previewVisible
=
ref
(
false
)
// 获取上传相关配置
const
{
uploadUrl
,
httpRequest
}
=
useUpload
()
const
dialogImageUrl
=
ref
(
''
)
/** 计算资源首页管理 表单 */
defineOptions
({
name
:
'ComputilityInformationForm'
})
...
...
@@ -114,7 +83,7 @@ const formLoading = ref(false) // 表单的加载中:1)修改时的数据加
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formData
=
ref
({
id
:
undefined
,
image
s
:
[]
,
image
:
undefined
,
information
:
undefined
,
title
:
undefined
,
url
:
undefined
,
...
...
@@ -127,7 +96,7 @@ const formRules = reactive({
information
:
[{
required
:
true
,
message
:
'内容不能为空'
,
trigger
:
'blur'
}],
title
:
[{
required
:
true
,
message
:
'标题不能为空'
,
trigger
:
'blur'
}],
category
:
[{
required
:
true
,
message
:
'计算资源应用类别不能为空'
,
trigger
:
'change'
}],
showStatus
:
[{
required
:
true
,
message
:
'状态
:0-已隐藏,1-已显示
不能为空'
,
trigger
:
'blur'
}]
showStatus
:
[{
required
:
true
,
message
:
'状态不能为空'
,
trigger
:
'blur'
}]
})
const
formRef
=
ref
()
// 表单 Ref
...
...
@@ -148,13 +117,7 @@ const open = async (type: string, id?: number) => {
data
.
description
=
''
}
// 将 images 字段转换为 file-list 需要的格式
if
(
data
.
images
&&
Array
.
isArray
(
data
.
images
))
{
formData
.
value
.
images
=
data
.
images
.
map
((
url
)
=>
({
url
,
name
:
'image.jpg'
}))
// 添加 name 属性
}
else
{
formData
.
value
.
images
=
[]
}
formData
.
value
=
{
...
data
,
images
:
formData
.
value
.
images
}
// 确保 image 是数组
formData
.
value
=
data
}
finally
{
formLoading
.
value
=
false
}
...
...
@@ -170,26 +133,7 @@ const submitForm = async () => {
// 提交请求
formLoading
.
value
=
true
try
{
// 确保只提取真实的 URL,而不是本地的 Blob URL
const
imageUrls
=
formData
.
value
.
images
.
filter
((
item
)
=>
item
.
url
&&
!
item
.
url
.
startsWith
(
'blob:'
))
// 过滤掉 Blob URL
.
map
((
item
)
=>
item
.
url
)
// 如果还有 Blob URL,说明有文件还未上传完成
const
hasBlobUrls
=
formData
.
value
.
images
.
some
(
(
item
)
=>
item
.
url
&&
item
.
url
.
startsWith
(
'blob:'
)
)
if
(
hasBlobUrls
)
{
message
.
warning
(
'请等待图片上传完成后再提交'
)
formLoading
.
value
=
false
return
}
// 构造最终数据
const
data
=
{
...
formData
.
value
,
images
:
imageUrls
}
const
data
=
formData
.
value
as
unknown
as
BannerInfo
if
(
formType
.
value
===
'computilityCreate'
)
{
await
ComputilityInformationApi
.
createComputilityInformation
(
data
)
...
...
@@ -210,7 +154,7 @@ const submitForm = async () => {
const
resetForm
=
()
=>
{
formData
.
value
=
{
id
:
undefined
,
image
s
:
[]
,
image
:
undefined
,
information
:
undefined
,
title
:
undefined
,
url
:
undefined
,
...
...
@@ -221,39 +165,6 @@ const resetForm = () => {
}
formRef
.
value
?.
resetFields
()
}
// 预览图片
const
handlePictureCardPreview
=
(
file
)
=>
{
dialogImageUrl
.
value
=
file
.
url
previewVisible
.
value
=
true
// 使用独立的预览状态
}
// 删除图片
const
handleRemove
=
(
file
,
fileList
)
=>
{
// 更新 formData.image 数组
// formData.value.images = fileList.map(item => ({ url: item.url, name: item.name }))
formData
.
value
.
images
=
fileList
}
// 上传成功处理函数
const
handleUploadSuccess
=
(
response
,
file
,
fileList
)
=>
{
// 从响应中提取真实的URL并更新文件对象
if
(
response
&&
response
.
data
)
{
// 根据 useUpload.ts 的实现,可能是 response.data.url 或直接是 response.data
const
realUrl
=
response
.
data
.
url
||
response
.
data
if
(
realUrl
)
{
file
.
url
=
realUrl
}
}
// 更新 formData.images
formData
.
value
.
images
=
fileList
}
// 上传失败处理函数
const
handleUploadError
=
(
err
,
file
,
fileList
)
=>
{
message
.
error
(
'图片上传失败: '
+
(
err
.
message
||
'未知错误'
))
}
</
script
>
<
style
scoped
>
...
...
src/views/biz/computilityinformation/index.vue
View file @
7f2db94a
...
...
@@ -110,8 +110,8 @@
<template
#
default=
"scope"
>
<!-- 只显示第一张图片 -->
<img
v-if=
"scope.row.image
s && scope.row.images.length > 0
"
:src=
"scope.row.image
s[0]
"
v-if=
"scope.row.image"
:src=
"scope.row.image"
alt=
"展示图"
class=
"h-36px"
/>
...
...
src/views/biz/industryapplication/IndustryApplicationForm.vue
View file @
7f2db94a
This diff is collapsed.
Click to expand it.
src/views/biz/industryapplication/index.vue
View file @
7f2db94a
...
...
@@ -106,39 +106,15 @@
>
<el-table-column
type=
"selection"
width=
"55"
/>
<el-table-column
label=
"排序值"
align=
"center"
prop=
"orderNum"
/>
<!--
<el-table-column
label=
"展示图地址"
align=
"center"
prop=
"image"
width=
"100"
>
-->
<!--
<template
#
default=
"scope"
>
-->
<!--
<img
:src=
"scope.row.image"
alt=
"资源展示图"
class=
"h-36px"
/>
-->
<!--
</
template
>
-->
<!-- </el-table-column>-->
<el-table-column
label=
"展示图地址"
align=
"center"
prop=
"images"
width=
"100"
>
<el-table-column
label=
"展示图地址"
align=
"center"
prop=
"image"
width=
"100"
>
<template
#
default=
"scope"
>
<!-- 只显示第一张图片 -->
<img
v-if=
"scope.row.images && scope.row.images.length > 0"
:src=
"scope.row.images[0]"
alt=
"展示图"
class=
"h-36px"
/>
<span
v-else
>
暂无图片
</span>
<img
:src=
"scope.row.image"
alt=
"资源展示图"
class=
"h-36px"
/>
</
template
>
</el-table-column>
<!-- <el-table-column label="首页展示图片" align="center" prop="homeImage" width="100">-->
<!-- <template #default="scope">-->
<!-- <img :src="scope.row.homeImage" alt="首页展示图片" class="h-36px" />-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column
label=
"首页展示图片"
align=
"center"
prop=
"homeImages"
width=
"110"
>
<el-table-column
label=
"首页展示图片"
align=
"center"
prop=
"homeImage"
width=
"100"
>
<
template
#
default=
"scope"
>
<!-- 只显示第一张图片 -->
<img
v-if=
"scope.row.homeImages && scope.row.homeImages.length > 0"
:src=
"scope.row.homeImages[0]"
alt=
"首页展示图片"
class=
"h-36px"
/>
<span
v-else
>
暂无图片
</span>
<img
:src=
"scope.row.homeImage"
alt=
"首页展示图片"
class=
"h-36px"
/>
</
template
>
</el-table-column>
...
...
@@ -153,11 +129,11 @@
</
template
>
</el-table-column>
<!-- <el-table-column label="描述内容" align="center" prop="description">-->
<!-- <template #default="scope">-->
<!-- <div v-html="scope.row.description" class="line-clamp-2"></div>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column label="描述内容" align="center" prop="description">-->
<!-- <template #default="scope">-->
<!-- <div v-html="scope.row.description" class="line-clamp-2"></div>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column
label=
"状态"
align=
"center"
prop=
"showStatus"
>
<
template
#
default=
"scope"
>
...
...
@@ -222,7 +198,6 @@ const queryParams = reactive({
title
:
undefined
,
showStatus
:
undefined
,
createTime
:
[],
// homeImages: [],
assemblyType
:
undefined
,
orderNum
:
undefined
})
...
...
src/views/biz/information/InformationForm.vue
View file @
7f2db94a
...
...
@@ -7,9 +7,13 @@
label-width=
"100px"
v-loading=
"formLoading"
>
<el-form-item
label=
"资讯类别"
prop=
"category"
>
<el-select
v-model=
"formData.category"
placeholder=
"请选择资讯类别"
clearable
class=
"!w-160px"
>
<el-select
v-model=
"formData.category"
placeholder=
"请选择资讯类别"
clearable
class=
"!w-160px"
>
<el-option
v-for=
"dict in getIntDictOptions(DICT_TYPE.HOME_INFO_INFORMATION_CATEGORY)"
:key=
"dict.value"
...
...
@@ -20,7 +24,12 @@
</el-form-item>
<el-form-item
label=
"行业类别"
prop=
"industryCategory"
>
<el-select
v-model=
"formData.industryCategory"
placeholder=
"请选择行业类别"
clearable
class=
"!w-160px"
>
<el-select
v-model=
"formData.industryCategory"
placeholder=
"请选择行业类别"
clearable
class=
"!w-160px"
>
<el-option
v-for=
"dict in getIntDictOptions(DICT_TYPE.HOME_INFO_INDUSTRY_CATEGORY)"
:key=
"dict.value"
...
...
@@ -49,32 +58,34 @@
</el-radio-group>
</el-form-item>
<!--
<el-form-item
label=
"预览图"
prop=
"image"
>
-->
<!--
<UploadImg
v-model=
"formData.image"
/>
-->
<!--
</el-form-item>
-->
<el-form-item
label=
"预览图"
prop=
"images"
>
<el-upload
v-model:file-list=
"formData.images"
:action=
"uploadUrl"
:http-request=
"httpRequest"
list-type=
"picture-card"
:on-preview=
"handlePictureCardPreview"
:on-remove=
"handleRemove"
:on-success=
"handleUploadSuccess"
:on-error=
"handleUploadError"
multiple
>
<el-icon><Plus
/></el-icon>
</el-upload>
<!-- 添加预览对话框 -->
<el-dialog
v-model=
"previewVisible"
append-to-body
>
<img
style=
"width: 100%"
:src=
"dialogImageUrl"
alt=
"Preview Image"
/>
</el-dialog>
<!-- 添加提示信息 -->
<el-form-item
label=
"预览图"
prop=
"image"
>
<UploadImg
v-model=
"formData.image"
/>
<p
class=
"upload-tips"
>
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
</p>
</el-form-item>
<!--
<el-form-item
label=
"预览图"
prop=
"images"
>
-->
<!--
<el-upload-->
<!-- v-model:file-list="formData.images"-->
<!-- :action="uploadUrl"-->
<!-- :http-request="httpRequest"-->
<!-- list-type="picture-card"-->
<!-- :on-preview="handlePictureCardPreview"-->
<!-- :on-remove="handleRemove"-->
<!-- :on-success="handleUploadSuccess"-->
<!-- :on-error="handleUploadError"-->
<!-- multiple-->
<!-- >-->
<!--
<el-icon><Plus
/></el-icon>
-->
<!--
</el-upload>
-->
<!-- <!– 添加预览对话框 –>-->
<!--
<el-dialog
v-model=
"previewVisible"
append-to-body
>
-->
<!--
<img
style=
"width: 100%"
:src=
"dialogImageUrl"
alt=
"Preview Image"
/>
-->
<!--
</el-dialog>
-->
<!-- <!– 添加提示信息 –>-->
<!--
</el-form-item>
-->
<el-form-item
label=
"备注"
prop=
"remark"
>
<el-input
v-model=
"formData.remark"
placeholder=
"请输入备注"
/>
...
...
@@ -87,10 +98,10 @@
</Dialog>
</template>
<
script
setup
lang=
"ts"
>
import
{
InformationApi
,
Information
}
from
'@/api/biz/information'
import
{
InformationApi
}
from
'@/api/biz/information'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
useUpload
}
from
'@/components/UploadFile/src/useUpload'
import
{
Plus
}
from
"@element-plus/icons-vue
"
;
import
{
BannerInfo
}
from
"@/api/biz/bannerinfo
"
;
// 添加预览相关的响应式变量
const
previewVisible
=
ref
(
false
)
...
...
@@ -123,7 +134,7 @@ const formRules = reactive({
category
:
[{
required
:
true
,
message
:
'咨询类别不能为空'
,
trigger
:
'blur'
}],
industryCategory
:
[{
required
:
true
,
message
:
'行业类别不能为空'
,
trigger
:
'blur'
}],
title
:
[{
required
:
true
,
message
:
'标题不能为空'
,
trigger
:
'blur'
}],
showStatus
:
[{
required
:
true
,
message
:
'状态
:0-已隐藏,1-已显示
不能为空'
,
trigger
:
'blur'
}]
showStatus
:
[{
required
:
true
,
message
:
'状态不能为空'
,
trigger
:
'blur'
}]
})
const
formRef
=
ref
()
// 表单 Ref
...
...
@@ -147,14 +158,7 @@ const open = async (type: string, id?: number) => {
data
.
category
=
Number
(
data
.
category
)
data
.
industryCategory
=
Number
(
data
.
industryCategory
)
// 将 images 字段转换为 file-list 需要的格式
if
(
data
.
images
&&
Array
.
isArray
(
data
.
images
))
{
formData
.
value
.
images
=
data
.
images
.
map
(
url
=>
({
url
,
name
:
'image.jpg'
}))
// 添加 name 属性
}
else
{
formData
.
value
.
images
=
[]
}
formData
.
value
=
{
...
data
,
images
:
formData
.
value
.
images
}
// 确保 image 是数组
formData
.
value
=
data
}
finally
{
formLoading
.
value
=
false
}
...
...
@@ -170,26 +174,7 @@ const submitForm = async () => {
// 提交请求
formLoading
.
value
=
true
try
{
// 确保只提取真实的 URL,而不是本地的 Blob URL
const
imageUrls
=
formData
.
value
.
images
.
filter
(
item
=>
item
.
url
&&
!
item
.
url
.
startsWith
(
'blob:'
))
// 过滤掉 Blob URL
.
map
(
item
=>
item
.
url
);
// 如果还有 Blob URL,说明有文件还未上传完成
const
hasBlobUrls
=
formData
.
value
.
images
.
some
(
item
=>
item
.
url
&&
item
.
url
.
startsWith
(
'blob:'
));
if
(
hasBlobUrls
)
{
message
.
warning
(
'请等待图片上传完成后再提交'
);
formLoading
.
value
=
false
;
return
;
}
// 构造最终数据
const
data
=
{
...
formData
.
value
,
images
:
imageUrls
};
const
data
=
formData
.
value
as
unknown
as
BannerInfo
if
(
formType
.
value
===
'informationCreate'
)
{
await
InformationApi
.
createInformation
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
...
...
@@ -219,46 +204,14 @@ const resetForm = () => {
}
formRef
.
value
?.
resetFields
()
}
// 预览图片
const
handlePictureCardPreview
=
(
file
)
=>
{
dialogImageUrl
.
value
=
file
.
url
previewVisible
.
value
=
true
// 使用独立的预览状态
}
// 删除图片
const
handleRemove
=
(
file
,
fileList
)
=>
{
// 更新 formData.image 数组
// formData.value.images = fileList.map(item => ({ url: item.url, name: item.name }))
formData
.
value
.
images
=
fileList
}
// 上传成功处理函数
const
handleUploadSuccess
=
(
response
,
file
,
fileList
)
=>
{
// 从响应中提取真实的URL并更新文件对象
if
(
response
&&
response
.
data
)
{
// 根据 useUpload.ts 的实现,可能是 response.data.url 或直接是 response.data
const
realUrl
=
response
.
data
.
url
||
response
.
data
;
if
(
realUrl
)
{
file
.
url
=
realUrl
;
}
}
// 更新 formData.images
formData
.
value
.
images
=
fileList
;
}
// 上传失败处理函数
const
handleUploadError
=
(
err
,
file
,
fileList
)
=>
{
message
.
error
(
'图片上传失败: '
+
(
err
.
message
||
'未知错误'
))
}
</
script
>
<
style
scoped
>
.upload-tips
{
<
style
scoped
>
.upload-tips
{
font-size
:
12px
;
color
:
#999
;
margin-top
:
10px
;
margin-left
:
10px
;
}
.red-text
{
...
...
src/views/biz/information/index.vue
View file @
7f2db94a
...
...
@@ -121,12 +121,12 @@
<!-- <img :src="scope.row.image" alt="预览图" class="h-36px" />-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column
label=
"预览图"
align=
"center"
prop=
"image
s
"
width=
"100"
>
<el-table-column
label=
"预览图"
align=
"center"
prop=
"image"
width=
"100"
>
<
template
#
default=
"scope"
>
<!-- 只显示第一张图片 -->
<img
v-if=
"scope.row.image
s && scope.row.images.length > 0
"
:src=
"scope.row.image
s[0]
"
v-if=
"scope.row.image"
:src=
"scope.row.image"
alt=
"预览图"
class=
"h-36px"
/>
...
...
@@ -169,7 +169,6 @@
<
script
setup
lang=
"ts"
>
import
{
isEmpty
}
from
'@/utils/is'
import
{
dateFormatter
}
from
'@/utils/formatTime'
import
download
from
'@/utils/download'
import
{
InformationApi
,
Information
}
from
'@/api/biz/information'
import
InformationForm
from
'./InformationForm.vue'
...
...
src/views/biz/partner/PartnerForm.vue
View file @
7f2db94a
...
...
@@ -7,27 +7,13 @@
label-width=
"100px"
v-loading=
"formLoading"
>
<el-form-item
label=
"展示图地址"
prop=
"images"
>
<el-upload
v-model:file-list=
"formData.images"
:action=
"uploadUrl"
:http-request=
"httpRequest"
list-type=
"picture-card"
:on-preview=
"handlePictureCardPreview"
:on-remove=
"handleRemove"
:on-success=
"handleUploadSuccess"
:on-error=
"handleUploadError"
multiple
>
<el-icon><Plus
/></el-icon>
</el-upload>
<!-- 添加预览对话框 -->
<el-dialog
v-model=
"previewVisible"
append-to-body
>
<img
style=
"width: 100%"
:src=
"dialogImageUrl"
alt=
"Preview Image"
/>
</el-dialog>
<el-form-item
label=
"展示图地址"
prop=
"image"
>
<UploadImg
v-model=
"formData.image"
/>
<!-- 添加提示信息 -->
<p
class=
"upload-tips"
>
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
请上传 大小不超过
<span
class=
"red-text"
>
5MB
</span>
格式为
<span
class=
"red-text"
>
png/jpg/jpeg
</span>
的文件
</p>
</el-form-item>
<el-form-item
label=
"内容"
prop=
"information"
>
...
...
@@ -71,7 +57,8 @@ import { PartnerApi, Partner } from '@/api/biz/partner'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
useUpload
}
from
'@/components/UploadFile/src/useUpload'
import
{
Plus
}
from
"@element-plus/icons-vue"
;
import
{
Plus
}
from
'@element-plus/icons-vue'
import
{
BannerInfo
}
from
"@/api/biz/bannerinfo"
;
// 添加预览相关的响应式变量
const
previewVisible
=
ref
(
false
)
...
...
@@ -99,7 +86,7 @@ const formData = ref({
description
:
undefined
,
orderNum
:
undefined
,
showStatus
:
undefined
,
remark
:
undefined
,
remark
:
undefined
})
const
formRules
=
reactive
({
information
:
[{
required
:
true
,
message
:
'内容不能为空'
,
trigger
:
'blur'
}],
...
...
@@ -142,15 +129,7 @@ const open = async (type: string, id?: number) => {
data
.
description
=
''
}
// 将 images 字段转换为 file-list 需要的格式
if
(
data
.
images
&&
Array
.
isArray
(
data
.
images
))
{
formData
.
value
.
images
=
data
.
images
.
map
(
url
=>
({
url
,
name
:
'image.jpg'
}))
// 添加 name 属性
}
else
{
formData
.
value
.
images
=
[]
}
formData
.
value
=
{
...
data
,
images
:
formData
.
value
.
images
,
homeImages
:
formData
.
value
.
homeImages
}
// 确保 image 是数组
formData
.
value
=
data
}
finally
{
formLoading
.
value
=
false
}
...
...
@@ -167,25 +146,7 @@ const submitForm = async () => {
formLoading
.
value
=
true
try
{
// 确保只提取真实的 URL,而不是本地的 Blob URL
const
imageUrls
=
formData
.
value
.
images
.
filter
(
item
=>
item
.
url
&&
!
item
.
url
.
startsWith
(
'blob:'
))
// 过滤掉 Blob URL
.
map
(
item
=>
item
.
url
);
// 如果还有 Blob URL,说明有文件还未上传完成
const
hasBlobUrls
=
formData
.
value
.
images
.
some
(
item
=>
item
.
url
&&
item
.
url
.
startsWith
(
'blob:'
));
if
(
hasBlobUrls
)
{
message
.
warning
(
'请等待图片上传完成后再提交'
);
formLoading
.
value
=
false
;
return
;
}
// 构造最终数据
const
data
=
{
...
formData
.
value
,
images
:
imageUrls
};
const
data
=
formData
.
value
as
unknown
as
BannerInfo
if
(
formType
.
value
===
'create'
)
{
await
PartnerApi
.
createPartner
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
...
...
@@ -205,55 +166,25 @@ const submitForm = async () => {
const
resetForm
=
()
=>
{
formData
.
value
=
{
id
:
undefined
,
image
s
:
[]
,
image
:
undefined
,
information
:
undefined
,
title
:
undefined
,
url
:
undefined
,
description
:
undefined
,
orderNum
:
undefined
,
showStatus
:
undefined
,
remark
:
undefined
,
remark
:
undefined
}
formRef
.
value
?.
resetFields
()
}
// 预览图片
const
handlePictureCardPreview
=
(
file
)
=>
{
dialogImageUrl
.
value
=
file
.
url
previewVisible
.
value
=
true
// 使用独立的预览状态
}
// 删除图片
const
handleRemove
=
(
file
,
fileList
)
=>
{
// 更新 formData.image 数组
// formData.value.images = fileList.map(item => ({ url: item.url, name: item.name }))
formData
.
value
.
images
=
fileList
}
// 上传成功处理函数
const
handleUploadSuccess
=
(
response
,
file
,
fileList
)
=>
{
// 从响应中提取真实的URL并更新文件对象
if
(
response
&&
response
.
data
)
{
// 根据 useUpload.ts 的实现,可能是 response.data.url 或直接是 response.data
const
realUrl
=
response
.
data
.
url
||
response
.
data
;
if
(
realUrl
)
{
file
.
url
=
realUrl
;
}
}
// 更新 formData.images
formData
.
value
.
images
=
fileList
;
}
// 上传失败处理函数
const
handleUploadError
=
(
err
,
file
,
fileList
)
=>
{
message
.
error
(
'图片上传失败: '
+
(
err
.
message
||
'未知错误'
))
}
</
script
>
<
style
scoped
>
.upload-tips
{
<
style
scoped
>
.upload-tips
{
font-size
:
12px
;
color
:
#999
;
margin-top
:
10px
;
margin-left
:
10px
;
}
.red-text
{
...
...
src/views/biz/partner/index.vue
View file @
7f2db94a
...
...
@@ -94,12 +94,12 @@
@
selection-change=
"handleRowCheckboxChange"
>
<el-table-column
type=
"selection"
width=
"55"
/>
<el-table-column
label=
"展示图地址"
align=
"center"
prop=
"image
s
"
width=
"100"
>
<el-table-column
label=
"展示图地址"
align=
"center"
prop=
"image"
width=
"100"
>
<template
#
default=
"scope"
>
<!-- 只显示第一张图片 -->
<img
v-if=
"scope.row.image
s && scope.row.images.length > 0
"
:src=
"scope.row.image
s[0]
"
v-if=
"scope.row.image"
:src=
"scope.row.image"
alt=
"展示图"
class=
"h-36px"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment