调整商品分类的实现

This commit is contained in:
YunaiV 2023-04-25 21:02:35 +08:00
parent c14b5c5bff
commit 9680a204ca
4 changed files with 46 additions and 40 deletions

View File

@ -64,6 +64,7 @@ const include = [
'element-plus/es/components/dropdown-menu/style/index', 'element-plus/es/components/dropdown-menu/style/index',
'element-plus/es/components/dropdown-item/style/index', 'element-plus/es/components/dropdown-item/style/index',
'element-plus/es/components/skeleton/style/index', 'element-plus/es/components/skeleton/style/index',
'element-plus/es/components/skeleton/style/css', 'element-plus/es/components/skeleton/style/css',
'element-plus/es/components/backtop/style/css', 'element-plus/es/components/backtop/style/css',
'element-plus/es/components/menu/style/css', 'element-plus/es/components/menu/style/css',
@ -76,7 +77,21 @@ const include = [
'element-plus/es/components/badge/style/css', 'element-plus/es/components/badge/style/css',
'element-plus/es/components/breadcrumb/style/css', 'element-plus/es/components/breadcrumb/style/css',
'element-plus/es/components/breadcrumb-item/style/css', 'element-plus/es/components/breadcrumb-item/style/css',
'element-plus/es/components/image/style/css' 'element-plus/es/components/image/style/css',
'element-plus/es/components/tag/style/css',
'element-plus/es/components/dialog/style/css',
'element-plus/es/components/form/style/css',
'element-plus/es/components/form-item/style/css',
'element-plus/es/components/card/style/css',
'element-plus/es/components/tooltip/style/css',
'element-plus/es/components/radio-group/style/css',
'element-plus/es/components/radio/style/css',
'element-plus/es/components/input-number/style/css',
'element-plus/es/components/tree-select/style/css',
'element-plus/es/components/drawer/style/css',
'element-plus/es/components/image-viewer/style/css',
'element-plus/es/components/upload/style/css',
'element-plus/es/components/switch/style/css'
] ]
const exclude = ['@iconify/json'] const exclude = ['@iconify/json']

View File

@ -17,17 +17,17 @@ export interface CategoryVO {
*/ */
name: string name: string
/** /**
* *
*/ */
picUrl: string picUrl: string
/**
* PC
*/
bigPicUrl?: string
/** /**
* *
*/ */
sort?: number sort: number
/**
*
*/
description?: string
/** /**
* *
*/ */

View File

@ -4,27 +4,30 @@
ref="formRef" ref="formRef"
:model="formData" :model="formData"
:rules="formRules" :rules="formRules"
label-width="80px" label-width="120px"
v-loading="formLoading" v-loading="formLoading"
> >
<el-form-item label="上级分类" prop="parentId"> <el-form-item label="上级分类" prop="parentId">
<el-tree-select <el-select v-model="formData.parentId" placeholder="请选择上级分类">
v-model="formData.parentId" <el-option :key="0" label="顶级分类" :value="0" />
:data="categoryTree" <el-option
:props="{ label: 'name', value: 'id' }" v-for="item in categoryList"
:render-after-expand="false" :key="item.id"
placeholder="请选择上级分类" :label="item.name"
check-strictly :value="item.id"
default-expand-all />
/> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="分类名称" prop="name"> <el-form-item label="分类名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入分类名称" /> <el-input v-model="formData.name" placeholder="请输入分类名称" />
</el-form-item> </el-form-item>
<el-form-item label="分类图" prop="picUrl"> <el-form-item label="移动端分类图" prop="picUrl">
<UploadImg v-model="formData.picUrl" :limit="1" :is-show-tip="false" /> <UploadImg v-model="formData.picUrl" :limit="1" :is-show-tip="false" />
<div v-if="formData.parentId === 0" style="font-size: 10px">推荐 200x100 图片分辨率</div> <div style="font-size: 10px" class="pl-10px">推荐 180x180 图片分辨率</div>
<div v-else style="font-size: 10px">推荐 100x100 图片分辨率</div> </el-form-item>
<el-form-item label="PC 端分类图" prop="bigPicUrl">
<UploadImg v-model="formData.bigPicUrl" :limit="1" :is-show-tip="false" />
<div style="font-size: 10px" class="pl-10px">推荐 468x340 图片分辨率</div>
</el-form-item> </el-form-item>
<el-form-item label="分类排序" prop="sort"> <el-form-item label="分类排序" prop="sort">
<el-input-number v-model="formData.sort" controls-position="right" :min="0" /> <el-input-number v-model="formData.sort" controls-position="right" :min="0" />
@ -40,9 +43,6 @@
</el-radio> </el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="分类描述">
<el-input v-model="formData.description" type="textarea" placeholder="请输入分类描述" />
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button> <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
@ -53,7 +53,6 @@
<script setup lang="ts" name="ProductCategory"> <script setup lang="ts" name="ProductCategory">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { CommonStatusEnum } from '@/utils/constants' import { CommonStatusEnum } from '@/utils/constants'
import { handleTree } from '@/utils/tree'
import * as ProductCategoryApi from '@/api/mall/product/category' import * as ProductCategoryApi from '@/api/mall/product/category'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -66,8 +65,8 @@ const formData = ref({
id: undefined, id: undefined,
name: '', name: '',
picUrl: '', picUrl: '',
status: CommonStatusEnum.ENABLE, bigPicUrl: '',
description: '' status: CommonStatusEnum.ENABLE
}) })
const formRules = reactive({ const formRules = reactive({
parentId: [{ required: true, message: '请选择上级分类', trigger: 'blur' }], parentId: [{ required: true, message: '请选择上级分类', trigger: 'blur' }],
@ -77,7 +76,7 @@ const formRules = reactive({
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }] status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const categoryTree = ref<any[]>([]) // const categoryList = ref<any[]>([]) //
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
@ -95,7 +94,7 @@ const open = async (type: string, id?: number) => {
} }
} }
// //
await getTree() categoryList.value = await ProductCategoryApi.getCategoryList({ parentId: 0 })
} }
defineExpose({ open }) // open defineExpose({ open }) // open
@ -131,17 +130,9 @@ const resetForm = () => {
id: undefined, id: undefined,
name: '', name: '',
picUrl: '', picUrl: '',
status: CommonStatusEnum.ENABLE, bigPicUrl: '',
description: '' status: CommonStatusEnum.ENABLE
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }
/** 获得分类树 */
const getTree = async () => {
const data = await ProductCategoryApi.getCategoryList({})
const tree = handleTree(data, 'id', 'parentId')
const menu = { id: 0, name: '顶级分类', children: tree }
categoryTree.value = [menu]
}
</script> </script>

View File

@ -36,9 +36,9 @@
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list" row-key="id" default-expand-all> <el-table v-loading="loading" :data="list" row-key="id" default-expand-all>
<el-table-column label="分类名称" prop="name" sortable /> <el-table-column label="分类名称" prop="name" sortable />
<el-table-column label="分类图" align="center" prop="picUrl"> <el-table-column label="移动端分类图" align="center" prop="picUrl">
<template #default="scope"> <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-100px" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="分类排序" align="center" prop="sort" /> <el-table-column label="分类排序" align="center" prop="sort" />