Skip to content

Commit 4ddba9d

Browse files
author
puhui999
committed
fix: 解决商品上一版遗留的各种小bug关键部分已添加fix注释。完成的TODO也已添加fix标记
1 parent 3c4a39d commit 4ddba9d

File tree

10 files changed

+215
-217
lines changed

10 files changed

+215
-217
lines changed

src/api/mall/product/spu.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ export const getSpu = (id: number) => {
8282
export const deleteSpu = (id: number) => {
8383
return request.delete({ url: `/product/spu/delete?id=${id}` })
8484
}
85+
86+
// 导出商品 Spu
87+
export const exportUser = (params) => {
88+
return request.download({ url: '/product/spu/export', params })
89+
}

src/components/UploadFile/src/UploadImgs.vue

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<template>
22
<div class="upload-box">
33
<el-upload
4+
v-model:file-list="fileList"
5+
:accept="fileType.join(',')"
46
:action="updateUrl"
5-
list-type="picture-card"
7+
:before-upload="beforeUpload"
68
:class="['upload', drag ? 'no-border' : '']"
7-
v-model:file-list="fileList"
8-
:multiple="true"
9-
:limit="limit"
9+
:drag="drag"
1010
:headers="uploadHeaders"
11-
:before-upload="beforeUpload"
11+
:limit="limit"
12+
:multiple="true"
13+
:on-error="uploadError"
1214
:on-exceed="handleExceed"
1315
:on-success="uploadSuccess"
14-
:on-error="uploadError"
15-
:drag="drag"
16-
:accept="fileType.join(',')"
16+
list-type="picture-card"
1717
>
1818
<div class="upload-empty">
1919
<slot name="empty">
@@ -40,15 +40,15 @@
4040
</div>
4141
<el-image-viewer
4242
v-if="imgViewVisible"
43-
@close="imgViewVisible = false"
4443
:url-list="[viewImageUrl]"
44+
@close="imgViewVisible = false"
4545
/>
4646
</div>
4747
</template>
48-
<script setup lang="ts" name="UploadImgs">
48+
<script lang="ts" name="UploadImgs" setup>
4949
import { PropType } from 'vue'
50+
import type { UploadFile, UploadProps, UploadUserFile } from 'element-plus'
5051
import { ElNotification } from 'element-plus'
51-
import type { UploadProps, UploadFile, UploadUserFile } from 'element-plus'
5252
5353
import { propTypes } from '@/utils/propTypes'
5454
import { getAccessToken, getTenantId } from '@/utils/auth'
@@ -88,8 +88,19 @@ const uploadHeaders = ref({
8888
'tenant-id': getTenantId()
8989
})
9090
91-
const fileList = ref<UploadUserFile[]>(props.modelValue)
92-
91+
const fileList = ref<UploadUserFile[]>()
92+
// fix: 改为动态监听赋值解决图片回显问题
93+
watch(
94+
() => props.modelValue,
95+
(data) => {
96+
if (!data) return
97+
fileList.value = data
98+
},
99+
{
100+
deep: true,
101+
immediate: true
102+
}
103+
)
93104
/**
94105
* @description 文件上传之前判断
95106
* @param rawFile 上传的文件
@@ -116,9 +127,11 @@ const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
116127
interface UploadEmits {
117128
(e: 'update:modelValue', value: UploadUserFile[]): void
118129
}
130+
119131
const emit = defineEmits<UploadEmits>()
120132
const uploadSuccess = (response, uploadFile: UploadFile) => {
121133
if (!response) return
134+
// TODO 多图上传组件成功后只是把保存成功后的url替换掉组件选图时的文件路径,所以返回的fileList包含的是一个包含文件信息的对象列表
122135
uploadFile.url = response.data
123136
emit('update:modelValue', fileList.value)
124137
message.success('上传成功')
@@ -159,35 +172,40 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
159172
}
160173
</script>
161174

162-
<style scoped lang="scss">
175+
<style lang="scss" scoped>
163176
.is-error {
164177
.upload {
165178
:deep(.el-upload--picture-card),
166179
:deep(.el-upload-dragger) {
167180
border: 1px dashed var(--el-color-danger) !important;
181+
168182
&:hover {
169183
border-color: var(--el-color-primary) !important;
170184
}
171185
}
172186
}
173187
}
188+
174189
:deep(.disabled) {
175190
.el-upload--picture-card,
176191
.el-upload-dragger {
177192
cursor: not-allowed;
178193
background: var(--el-disabled-bg-color) !important;
179194
border: 1px dashed var(--el-border-color-darker);
195+
180196
&:hover {
181197
border-color: var(--el-border-color-darker) !important;
182198
}
183199
}
184200
}
201+
185202
.upload-box {
186203
.no-border {
187204
:deep(.el-upload--picture-card) {
188205
border: none !important;
189206
}
190207
}
208+
191209
:deep(.upload) {
192210
.el-upload-dragger {
193211
display: flex;
@@ -199,26 +217,31 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
199217
overflow: hidden;
200218
border: 1px dashed var(--el-border-color-darker);
201219
border-radius: v-bind(borderRadius);
220+
202221
&:hover {
203222
border: 1px dashed var(--el-color-primary);
204223
}
205224
}
225+
206226
.el-upload-dragger.is-dragover {
207227
background-color: var(--el-color-primary-light-9);
208228
border: 2px dashed var(--el-color-primary) !important;
209229
}
230+
210231
.el-upload-list__item,
211232
.el-upload--picture-card {
212233
width: v-bind(width);
213234
height: v-bind(height);
214235
background-color: transparent;
215236
border-radius: v-bind(borderRadius);
216237
}
238+
217239
.upload-image {
218240
width: 100%;
219241
height: 100%;
220242
object-fit: contain;
221243
}
244+
222245
.upload-handle {
223246
position: absolute;
224247
top: 0;
@@ -233,42 +256,49 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
233256
background: rgb(0 0 0 / 60%);
234257
opacity: 0;
235258
transition: var(--el-transition-duration-fast);
259+
236260
.handle-icon {
237261
display: flex;
238262
flex-direction: column;
239263
align-items: center;
240264
justify-content: center;
241265
padding: 0 6%;
242266
color: aliceblue;
267+
243268
.el-icon {
244269
margin-bottom: 15%;
245270
font-size: 140%;
246271
}
272+
247273
span {
248274
font-size: 100%;
249275
}
250276
}
251277
}
278+
252279
.el-upload-list__item {
253280
&:hover {
254281
.upload-handle {
255282
opacity: 1;
256283
}
257284
}
258285
}
286+
259287
.upload-empty {
260288
display: flex;
261289
flex-direction: column;
262290
align-items: center;
263291
font-size: 12px;
264292
line-height: 30px;
265293
color: var(--el-color-info);
294+
266295
.el-icon {
267296
font-size: 28px;
268297
color: var(--el-text-color-secondary);
269298
}
270299
}
271300
}
301+
272302
.el-upload__tip {
273303
line-height: 15px;
274304
text-align: center;

src/router/modules/remaining.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,22 +349,35 @@ const remainingRouter: AppRouteRecordRaw[] = [
349349
{
350350
path: '/product',
351351
component: Layout,
352-
name: 'ProductManagementEdit',
352+
name: 'Product',
353353
meta: {
354354
hidden: true
355355
},
356356
children: [
357357
{
358-
path: 'productManagementAdd', // TODO @puhui999:最好拆成 add 和 edit 两个路由;添加商品;修改商品
358+
path: 'productSpuAdd', // TODO @puhui999:最好拆成 add 和 edit 两个路由;添加商品;修改商品 fix
359359
component: () => import('@/views/mall/product/spu/addForm.vue'),
360-
name: 'ProductManagementAdd',
360+
name: 'ProductSpuAdd',
361361
meta: {
362362
noCache: true,
363363
hidden: true,
364364
canTo: true,
365365
icon: 'ep:edit',
366366
title: '添加商品',
367-
activeMenu: '/product/product-management'
367+
activeMenu: '/product/product-spu'
368+
}
369+
},
370+
{
371+
path: 'productSpuEdit/:spuId(\\d+)',
372+
component: () => import('@/views/mall/product/spu/addForm.vue'),
373+
name: 'productSpuEdit',
374+
meta: {
375+
noCache: true,
376+
hidden: true,
377+
canTo: true,
378+
icon: 'ep:edit',
379+
title: '编辑商品',
380+
activeMenu: '/product/product-spu'
368381
}
369382
}
370383
]

0 commit comments

Comments
 (0)