REVIEW 商品分类

This commit is contained in:
YunaiV 2023-04-02 00:17:56 +08:00
parent 59c44d9819
commit 00c3133391
7 changed files with 72 additions and 112 deletions

View File

@ -163,7 +163,7 @@ const queryParams = reactive({
const queryFormRef = ref() // const queryFormRef = ref() //
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) //
/** 查询参数列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {

View File

@ -168,7 +168,7 @@ const queryParams = reactive({
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
/** 查询参数列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {

View File

@ -141,7 +141,7 @@ const queryParams = reactive({
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
/** 查询参数列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {

View File

@ -10,11 +10,11 @@
<el-form-item label="上级分类" prop="parentId"> <el-form-item label="上级分类" prop="parentId">
<el-tree-select <el-tree-select
v-model="formData.parentId" v-model="formData.parentId"
:data="parentCategoryOptions" :data="categoryTree"
check-strictly
:render-after-expand="false"
placeholder="上级分类"
:props="{ label: 'name', value: 'id' }" :props="{ label: 'name', value: 'id' }"
:render-after-expand="false"
placeholder="请选择上级分类"
check-strictly
default-expand-all default-expand-all
/> />
</el-form-item> </el-form-item>
@ -32,10 +32,11 @@
<el-form-item label="开启状态" prop="status"> <el-form-item label="开启状态" prop="status">
<el-radio-group v-model="formData.status"> <el-radio-group v-model="formData.status">
<el-radio <el-radio
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :key="dict.value"
:label="parseInt(dict.value)" :label="dict.value"
>{{ dict.label }} >
{{ dict.label }}
</el-radio> </el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
@ -44,18 +45,16 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<div class="dialog-footer"> <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button> <el-button @click="modelVisible = false"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</div>
</template> </template>
</Dialog> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as ProductCategoryApi from '@/api/mall/product/category' import { CommonStatusEnum } from '@/utils/constants'
import { handleTree } from '@/utils/tree' import { handleTree } from '@/utils/tree'
import * as ProductCategoryApi from '@/api/mall/product/category'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -63,15 +62,13 @@ const modelVisible = ref(false) // 弹窗的是否展示
const modelTitle = ref('') // const modelTitle = ref('') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const formData = ref({
const defaultFormData: ProductCategoryApi.CategoryVO = {
id: undefined, id: undefined,
name: '', name: '',
picUrl: '', picUrl: '',
status: 0, status: CommonStatusEnum.ENABLE,
description: '' description: ''
} })
const formData = ref({ ...defaultFormData })
const formRules = reactive({ const formRules = reactive({
parentId: [{ required: true, message: '请选择上级分类', trigger: 'blur' }], parentId: [{ required: true, message: '请选择上级分类', trigger: 'blur' }],
name: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }], name: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }],
@ -80,17 +77,14 @@ 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 list = ref([])
const parentCategoryOptions = ref<any[]>([])
/** 打开弹窗 */ /** 打开弹窗 */
const openModal = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
modelVisible.value = true modelVisible.value = true
modelTitle.value = t('action.' + type) modelTitle.value = t('action.' + type)
formType.value = type formType.value = type
resetForm() resetForm()
getList()
// //
if (id) { if (id) {
formLoading.value = true formLoading.value = true
@ -100,20 +94,10 @@ const openModal = async (type: string, id?: number) => {
formLoading.value = false formLoading.value = false
} }
} }
//
await getTree()
} }
defineExpose({ openModal }) // openModal defineExpose({ open }) // open
//
const getList = async () => {
try {
const data = await ProductCategoryApi.getCategoryList({})
list.value = data
const tree = handleTree(data, 'id', 'parentId')
const menu = { id: 0, name: '顶级分类', children: tree }
parentCategoryOptions.value = [menu]
} finally {
}
}
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
@ -143,7 +127,21 @@ const submitForm = async () => {
/** 重置表单 */ /** 重置表单 */
const resetForm = () => { const resetForm = () => {
formData.value = { ...defaultFormData } formData.value = {
id: undefined,
name: '',
picUrl: '',
status: CommonStatusEnum.ENABLE,
description: ''
}
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

@ -1,7 +1,13 @@
<template> <template>
<content-wrap> <!-- 搜索工作栏 -->
<!-- 搜索工作栏 --> <ContentWrap>
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> <el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="分类名称" prop="name"> <el-form-item label="分类名称" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
@ -13,23 +19,25 @@
<el-form-item> <el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" @click="openModal('create')" v-hasPermi="['infra:config:create']"> <el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['product:category:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<el-table v-loading="loading" :data="list" align="center" default-expand-all row-key="id"> <ContentWrap>
<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 <img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="分类图片" class="h-100px" />
v-if="scope.row.picUrl"
:src="scope.row.picUrl"
alt="分类图片"
style="height: 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" />
@ -50,8 +58,8 @@
<el-button <el-button
link link
type="primary" type="primary"
@click="openModal('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['infra:config:update']" v-hasPermi="['product:category:update']"
> >
编辑 编辑
</el-button> </el-button>
@ -59,25 +67,24 @@
link link
type="danger" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['infra:config:delete']" v-hasPermi="['product:category:delete']"
> >
删除 删除
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</content-wrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<config-form ref="modalRef" @success="getList" /> <CategoryForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="Config"> <script setup lang="ts" name="ProductCategory">
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
import { handleTree } from '@/utils/tree'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import * as ProductCategoryApi from '@/api/mall/product/category' import * as ProductCategoryApi from '@/api/mall/product/category'
import ConfigForm from './form.vue' import CategoryForm from './CategoryForm.vue'
import { handleTree } from '@/utils/tree'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -88,13 +95,12 @@ const queryParams = reactive({
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
/** 查询参数列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await ProductCategoryApi.getCategoryList(queryParams) const data = await ProductCategoryApi.getCategoryList(queryParams)
list.value = handleTree(data, 'id', 'parentId') list.value = handleTree(data, 'id', 'parentId')
console.info(list)
} finally { } finally {
loading.value = false loading.value = false
} }
@ -112,9 +118,9 @@ const resetQuery = () => {
} }
/** 添加/修改操作 */ /** 添加/修改操作 */
const modalRef = ref() const formRef = ref()
const openModal = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
modalRef.value.openModal(type, id) formRef.value.open(type, id)
} }
/** 删除按钮操作 */ /** 删除按钮操作 */

View File

@ -1,44 +0,0 @@
export const parseTime = (time) => {
if (!time) {
return null
}
const format = '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time
.replace(new RegExp(/-/gm), '/')
.replace('T', ' ')
.replace(new RegExp(/\.[\d]{3}/gm), '')
}
if (typeof time === 'number' && time.toString().length === 10) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}

View File

@ -55,8 +55,8 @@
v-loading="loading" v-loading="loading"
:data="list" :data="list"
row-key="id" row-key="id"
default-expand-all
v-if="refreshTable" v-if="refreshTable"
:default-expand-all="isExpandAll"
> >
<el-table-column prop="name" label="部门名称" width="260" /> <el-table-column prop="name" label="部门名称" width="260" />
<el-table-column prop="leader" label="负责人" width="120"> <el-table-column prop="leader" label="负责人" width="120">