code review

This commit is contained in:
YunaiV
2023-09-01 00:49:42 +08:00
parent 135c88a473
commit 3918fab1ec
9 changed files with 57 additions and 60 deletions

View File

@@ -59,7 +59,7 @@
<el-table-column label="品牌名称" prop="name" sortable />
<el-table-column label="品牌图片" align="center" prop="picUrl">
<template #default="scope">
<img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="品牌图片" class="h-100px" />
<img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="品牌图片" class="h-30px" />
</template>
</el-table-column>
<el-table-column label="品牌排序" align="center" prop="sort" />

View File

@@ -38,7 +38,7 @@
<el-table-column label="分类名称" prop="name" sortable />
<el-table-column label="移动端分类图" align="center" prop="picUrl">
<template #default="scope">
<img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="移动端分类图" class="h-100px" />
<img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="移动端分类图" class="h-30px" />
</template>
</el-table-column>
<el-table-column label="分类排序" align="center" prop="sort" />

View File

@@ -115,7 +115,7 @@
:formatter="dateFormatter"
width="170"
/>
<el-table-column label="状态" align="center" width="65px">
<el-table-column label="是否展示" align="center" width="80px">
<template #default="scope">
<el-switch
v-model="scope.row.visible"

View File

@@ -147,7 +147,7 @@ const handleDelete = async (id: number) => {
// 删除的二次确认
await message.delConfirm()
// 发起删除
await PropertyApi.deleteProperty(id)
await PropertyApi.deletePropertyValue(id)
message.success(t('common.delSuccess'))
// 刷新列表
await getList()

View File

@@ -1,4 +1,5 @@
import SkuList from './SkuList.vue'
import { Spu } from '@/api/mall/product/spu'
interface PropertyAndValues {
id: number
@@ -22,4 +23,32 @@ interface RuleConfig {
message: string
}
export { SkuList, PropertyAndValues, RuleConfig }
/**
* 获得商品的规格列表
*
* @param spu
* @return PropertyAndValues 规格列表
*/
const getPropertyList = (spu: Spu): PropertyAndValues[] => {
// 直接拿返回的 skus 属性逆向生成出 propertyList
const properties: PropertyAndValues[] = []
// 只有是多规格才处理
if (spu.specType) {
spu.skus?.forEach((sku) => {
sku.properties?.forEach(({ propertyId, propertyName, valueId, valueName }) => {
// 添加属性
if (!properties?.some((item) => item.id === propertyId)) {
properties.push({ id: propertyId!, name: propertyName!, values: [] })
}
// 添加属性值
const index = properties?.findIndex((item) => item.id === propertyId)
if (!properties[index].values?.some((value) => value.id === valueId)) {
properties[index].values?.push({ id: valueId!, name: valueName! })
}
})
})
}
return properties
}
export { SkuList, getPropertyList, PropertyAndValues, RuleConfig }

View File

@@ -175,7 +175,7 @@ import { propTypes } from '@/utils/propTypes'
import { checkSelectedNode, defaultProps, handleTree, treeToString } from '@/utils/tree'
import { createImageViewer } from '@/components/ImageViewer'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { PropertyAndValues, SkuList } from '@/views/mall/product/spu/components/index.ts'
import { getPropertyList, SkuList } from '@/views/mall/product/spu/components/index.ts'
import ProductAttributes from './ProductAttributes.vue'
import ProductPropertyAddForm from './ProductPropertyAddForm.vue'
import { basicInfoSchema } from './spu.data'
@@ -203,34 +203,6 @@ const imagePreview = (args) => {
})
}
/**
* 获得商品的规格列表
*
* @param spu
* @return PropertyAndValues 规格列表
*/
const getPropertyList = (spu: Spu): PropertyAndValues[] => {
// 直接拿返回的 skus 属性逆向生成出 propertyList
const properties: PropertyAndValues[] = []
// 只有是多规格才处理
if (spu.specType) {
spu.skus?.forEach((sku) => {
sku.properties?.forEach(({ propertyId, propertyName, valueId, valueName }) => {
// 添加属性
if (!properties?.some((item) => item.id === propertyId)) {
properties.push({ id: propertyId!, name: propertyName!, values: [] })
}
// 添加属性值
const index = properties?.findIndex((item) => item.id === propertyId)
if (!properties[index].values?.some((value) => value.id === valueId)) {
properties[index].values?.push({ id: valueId!, name: valueName! })
}
})
})
}
return properties
}
// ====== end ======
const message = useMessage() // 消息弹窗

View File

@@ -189,7 +189,7 @@ const submitForm = async () => {
/** 关闭按钮 */
const close = () => {
delView(unref(currentRoute))
push('/product/product-spu')
push({ name: 'ProductSpu' })
}
/** 初始化 */
onMounted(async () => {

View File

@@ -170,6 +170,14 @@
>
详情
</el-button>
<el-button
v-hasPermi="['product:spu:update']"
link
type="primary"
@click="openForm(row.id)"
>
修改
</el-button>
<template v-if="queryParams.tabType === 4">
<el-button
v-hasPermi="['product:spu:delete']"
@@ -189,16 +197,6 @@
</el-button>
</template>
<template v-else>
<!-- 只有不是上架和回收站的商品可以编辑 -->
<el-button
v-if="queryParams.tabType !== 0"
v-hasPermi="['product:spu:update']"
link
type="primary"
@click="openForm(row.id)"
>
修改
</el-button>
<el-button
v-hasPermi="['product:spu:update']"
link