feat: 商品详情
This commit is contained in:
parent
3f18c2ea0e
commit
e1f682b95c
@ -1,25 +1,21 @@
|
||||
<template>
|
||||
<div class="max-w-1/2">
|
||||
<div class="max-w-1/2 sku-config">
|
||||
<dl v-for="item in list" :key="item.typeId" class="flex mb-1 items-center">
|
||||
<dt>
|
||||
<dt class="flex items-center">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
:on-change="handleFileChange"
|
||||
:on-change="(file: any, fileList: any[]) => handleFileChange(file, fileList, item)"
|
||||
:on-exceed="handleExceed"
|
||||
accept="image/*"
|
||||
list-type="picture-card"
|
||||
class="w-10 h-10"
|
||||
:show-file-list="false"
|
||||
class="w-10 h-10 el-upload-img"
|
||||
>
|
||||
<el-icon><Plus /></el-icon>
|
||||
<template #file="{ file }">
|
||||
<div class="relative w-10 h-10">
|
||||
<img class="w-10 h-10" :src="file.url" alt="" />
|
||||
</div>
|
||||
</template>
|
||||
<el-icon v-if="!item.imageUrl" size="12"><Plus /></el-icon>
|
||||
<img v-else :src="item.imageUrl" class="w-10 h-10" alt="" />
|
||||
</el-upload>
|
||||
<el-button type="primary" plain size="small" class="mr-2">{{ item.name }}</el-button>
|
||||
<el-button type="primary" plain size="small" class="mr-2 ml-2">{{ item.name }}</el-button>
|
||||
</dt>
|
||||
<dd class="flex">
|
||||
<p>
|
||||
@ -58,51 +54,44 @@ const props = defineProps<Props>()
|
||||
const uploadRef = ref()
|
||||
|
||||
// 处理文件选择
|
||||
const handleFileChange = (file: any, fileList: any[]) => {
|
||||
// 限制只能选择一张图片
|
||||
if (fileList.length > 1) {
|
||||
fileList.splice(0, 1)
|
||||
}
|
||||
const handleFileChange = async (file: any, fileList: any[], item: any) => {
|
||||
console.warn('----- my data is 22: ', file, fileList)
|
||||
const form = new FormData()
|
||||
// 关键:一次性把所有文件塞到同一个键 'files'
|
||||
fileList.forEach((f) => {
|
||||
form.append('files', f.raw as File)
|
||||
})
|
||||
const res = await api.resource.uploadFile.post!<any>(form)
|
||||
item.imageUrl = res.data[0].url
|
||||
}
|
||||
|
||||
// 超出限制时的处理
|
||||
const handleExceed = () => {
|
||||
ElMessage.warning('只能选择一张图片')
|
||||
}
|
||||
</script>
|
||||
|
||||
// 上传图片
|
||||
const uploadImage = async (item: any) => {
|
||||
if (!uploadRef.value) return
|
||||
|
||||
const uploadInstance = uploadRef.value
|
||||
const fileList = uploadInstance.fileList
|
||||
|
||||
if (fileList.length === 0) {
|
||||
ElMessage.warning('请选择要上传的图片')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建FormData
|
||||
const form = new FormData()
|
||||
form.append('files', fileList[0].raw)
|
||||
|
||||
// 调用上传API
|
||||
const res = await (globalThis as any).api.resource.uploadFile.post!(form)
|
||||
|
||||
if (res.data && res.data.length > 0) {
|
||||
// 更新图片URL
|
||||
item.imageUrl = res.data[0].url
|
||||
ElMessage.success('图片上传成功')
|
||||
|
||||
// 清空上传列表
|
||||
uploadInstance.clearFiles()
|
||||
} else {
|
||||
ElMessage.error('图片上传失败')
|
||||
<style scoped lang="scss">
|
||||
.sku-config {
|
||||
:deep(.el-upload-img) {
|
||||
.el-upload {
|
||||
border: 1px dashed var(--el-border-color);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.el-upload-list--picture-card {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
.el-upload-list__item {
|
||||
height: 100%;
|
||||
}
|
||||
.el-upload--picture-card {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('上传失败:', error)
|
||||
ElMessage.error('图片上传失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</style>
|
||||
|
||||
@ -74,7 +74,7 @@
|
||||
</el-tree-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="测试商品">
|
||||
<el-switch v-model="isTest" active-value="1" inactive-value="0" />
|
||||
<el-switch v-model="$dialog.data.isTest" active-value="1" inactive-value="0" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div ref="dragRef">
|
||||
@ -125,7 +125,7 @@
|
||||
<h4 class="font-bold mb-2">内容编辑:</h4>
|
||||
<wan-editor v-model="htmlContent"></wan-editor>
|
||||
</el-card>
|
||||
<el-button type="primary" @click="onSubmit()">提交</el-button>
|
||||
<el-button class="mt-2 !text-white" type="primary" @click="onSubmit()">提交</el-button>
|
||||
<FileExplorerDialog
|
||||
v-model="showFileExplorer"
|
||||
v-model:initPathArray="currentPathArray"
|
||||
@ -171,8 +171,6 @@ const {
|
||||
onClickChooseResourceBtn
|
||||
} = useImportFile()
|
||||
|
||||
const isTest = ref(0)
|
||||
|
||||
const categoryData = ref(categoryDataMock)
|
||||
const {
|
||||
inputValue,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user