Skip to content

Commit 00c3133

Browse files
committed
REVIEW 商品分类
1 parent 59c44d9 commit 00c3133

File tree

7 files changed

+72
-112
lines changed

7 files changed

+72
-112
lines changed

src/views/infra/codegen/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const queryParams = reactive({
163163
const queryFormRef = ref() // 搜索的表单
164164
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
165165
166-
/** 查询参数列表 */
166+
/** 查询列表 */
167167
const getList = async () => {
168168
loading.value = true
169169
try {

src/views/infra/job/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const queryParams = reactive({
168168
const queryFormRef = ref() // 搜索的表单
169169
const exportLoading = ref(false) // 导出的加载中
170170
171-
/** 查询参数列表 */
171+
/** 查询列表 */
172172
const getList = async () => {
173173
loading.value = true
174174
try {

src/views/infra/job/logger/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const queryParams = reactive({
141141
const queryFormRef = ref() // 搜索的表单
142142
const exportLoading = ref(false) // 导出的加载中
143143
144-
/** 查询参数列表 */
144+
/** 查询列表 */
145145
const getList = async () => {
146146
loading.value = true
147147
try {

src/views/mall/product/category/form.vue renamed to src/views/mall/product/category/CategoryForm.vue

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<el-form-item label="上级分类" prop="parentId">
1111
<el-tree-select
1212
v-model="formData.parentId"
13-
:data="parentCategoryOptions"
14-
check-strictly
15-
:render-after-expand="false"
16-
placeholder="上级分类"
13+
:data="categoryTree"
1714
:props="{ label: 'name', value: 'id' }"
15+
:render-after-expand="false"
16+
placeholder="请选择上级分类"
17+
check-strictly
1818
default-expand-all
1919
/>
2020
</el-form-item>
@@ -32,10 +32,11 @@
3232
<el-form-item label="开启状态" prop="status">
3333
<el-radio-group v-model="formData.status">
3434
<el-radio
35-
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
35+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
3636
:key="dict.value"
37-
:label="parseInt(dict.value)"
38-
>{{ dict.label }}
37+
:label="dict.value"
38+
>
39+
{{ dict.label }}
3940
</el-radio>
4041
</el-radio-group>
4142
</el-form-item>
@@ -44,34 +45,30 @@
4445
</el-form-item>
4546
</el-form>
4647
<template #footer>
47-
<div class="dialog-footer">
48-
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
49-
<el-button @click="modelVisible = false">取 消</el-button>
50-
</div>
48+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
49+
<el-button @click="modelVisible = false">取 消</el-button>
5150
</template>
5251
</Dialog>
5352
</template>
5453
<script setup lang="ts">
55-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
56-
import * as ProductCategoryApi from '@/api/mall/product/category'
54+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
55+
import { CommonStatusEnum } from '@/utils/constants'
5756
import { handleTree } from '@/utils/tree'
58-
57+
import * as ProductCategoryApi from '@/api/mall/product/category'
5958
const { t } = useI18n() // 国际化
6059
const message = useMessage() // 消息弹窗
6160
6261
const modelVisible = ref(false) // 弹窗的是否展示
6362
const modelTitle = ref('') // 弹窗的标题
6463
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
6564
const formType = ref('') // 表单的类型:create - 新增;update - 修改
66-
67-
const defaultFormData: ProductCategoryApi.CategoryVO = {
65+
const formData = ref({
6866
id: undefined,
6967
name: '',
7068
picUrl: '',
71-
status: 0,
69+
status: CommonStatusEnum.ENABLE,
7270
description: ''
73-
}
74-
const formData = ref({ ...defaultFormData })
71+
})
7572
const formRules = reactive({
7673
parentId: [{ required: true, message: '请选择上级分类', trigger: 'blur' }],
7774
name: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }],
@@ -80,17 +77,14 @@ const formRules = reactive({
8077
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }]
8178
})
8279
const formRef = ref() // 表单 Ref
83-
84-
const list = ref([])
85-
const parentCategoryOptions = ref<any[]>([])
80+
const categoryTree = ref<any[]>([]) // 分类树
8681
8782
/** 打开弹窗 */
88-
const openModal = async (type: string, id?: number) => {
83+
const open = async (type: string, id?: number) => {
8984
modelVisible.value = true
9085
modelTitle.value = t('action.' + type)
9186
formType.value = type
9287
resetForm()
93-
getList()
9488
// 修改时,设置数据
9589
if (id) {
9690
formLoading.value = true
@@ -100,20 +94,10 @@ const openModal = async (type: string, id?: number) => {
10094
formLoading.value = false
10195
}
10296
}
97+
// 获得分类树
98+
await getTree()
10399
}
104-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
105-
106-
// 获取上级分类选项
107-
const getList = async () => {
108-
try {
109-
const data = await ProductCategoryApi.getCategoryList({})
110-
list.value = data
111-
const tree = handleTree(data, 'id', 'parentId')
112-
const menu = { id: 0, name: '顶级分类', children: tree }
113-
parentCategoryOptions.value = [menu]
114-
} finally {
115-
}
116-
}
100+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
117101
118102
/** 提交表单 */
119103
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
@@ -143,7 +127,21 @@ const submitForm = async () => {
143127
144128
/** 重置表单 */
145129
const resetForm = () => {
146-
formData.value = { ...defaultFormData }
130+
formData.value = {
131+
id: undefined,
132+
name: '',
133+
picUrl: '',
134+
status: CommonStatusEnum.ENABLE,
135+
description: ''
136+
}
147137
formRef.value?.resetFields()
148138
}
139+
140+
/** 获得分类树 */
141+
const getTree = async () => {
142+
const data = await ProductCategoryApi.getCategoryList({})
143+
const tree = handleTree(data, 'id', 'parentId')
144+
const menu = { id: 0, name: '顶级分类', children: tree }
145+
categoryTree.value = [menu]
146+
}
149147
</script>

src/views/mall/product/category/index.vue

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<template>
2-
<content-wrap>
3-
<!-- 搜索工作栏 -->
4-
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
2+
<!-- 搜索工作栏 -->
3+
<ContentWrap>
4+
<el-form
5+
class="-mb-15px"
6+
:model="queryParams"
7+
ref="queryFormRef"
8+
:inline="true"
9+
label-width="68px"
10+
>
511
<el-form-item label="分类名称" prop="name">
612
<el-input
713
v-model="queryParams.name"
@@ -13,23 +19,25 @@
1319
<el-form-item>
1420
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
1521
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
16-
<el-button type="primary" @click="openModal('create')" v-hasPermi="['infra:config:create']">
22+
<el-button
23+
type="primary"
24+
plain
25+
@click="openForm('create')"
26+
v-hasPermi="['product:category:create']"
27+
>
1728
<Icon icon="ep:plus" class="mr-5px" /> 新增
1829
</el-button>
1930
</el-form-item>
2031
</el-form>
32+
</ContentWrap>
2133

22-
<!-- 列表 -->
23-
<el-table v-loading="loading" :data="list" align="center" default-expand-all row-key="id">
34+
<!-- 列表 -->
35+
<ContentWrap>
36+
<el-table v-loading="loading" :data="list" row-key="id" default-expand-all>
2437
<el-table-column label="分类名称" prop="name" sortable />
2538
<el-table-column label="分类图片" align="center" prop="picUrl">
2639
<template #default="scope">
27-
<img
28-
v-if="scope.row.picUrl"
29-
:src="scope.row.picUrl"
30-
alt="分类图片"
31-
style="height: 100px"
32-
/>
40+
<img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="分类图片" class="h-100px" />
3341
</template>
3442
</el-table-column>
3543
<el-table-column label="分类排序" align="center" prop="sort" />
@@ -50,34 +58,33 @@
5058
<el-button
5159
link
5260
type="primary"
53-
@click="openModal('update', scope.row.id)"
54-
v-hasPermi="['infra:config:update']"
61+
@click="openForm('update', scope.row.id)"
62+
v-hasPermi="['product:category:update']"
5563
>
5664
编辑
5765
</el-button>
5866
<el-button
5967
link
6068
type="danger"
6169
@click="handleDelete(scope.row.id)"
62-
v-hasPermi="['infra:config:delete']"
70+
v-hasPermi="['product:category:delete']"
6371
>
6472
删除
6573
</el-button>
6674
</template>
6775
</el-table-column>
6876
</el-table>
69-
</content-wrap>
77+
</ContentWrap>
7078

7179
<!-- 表单弹窗:添加/修改 -->
72-
<config-form ref="modalRef" @success="getList" />
80+
<CategoryForm ref="formRef" @success="getList" />
7381
</template>
74-
<script setup lang="ts" name="Config">
82+
<script setup lang="ts" name="ProductCategory">
7583
import { DICT_TYPE } from '@/utils/dict'
84+
import { handleTree } from '@/utils/tree'
7685
import { dateFormatter } from '@/utils/formatTime'
7786
import * as ProductCategoryApi from '@/api/mall/product/category'
78-
import ConfigForm from './form.vue'
79-
import { handleTree } from '@/utils/tree'
80-
87+
import CategoryForm from './CategoryForm.vue'
8188
const message = useMessage() // 消息弹窗
8289
const { t } = useI18n() // 国际化
8390
@@ -88,13 +95,12 @@ const queryParams = reactive({
8895
})
8996
const queryFormRef = ref() // 搜索的表单
9097
91-
/** 查询参数列表 */
98+
/** 查询列表 */
9299
const getList = async () => {
93100
loading.value = true
94101
try {
95102
const data = await ProductCategoryApi.getCategoryList(queryParams)
96103
list.value = handleTree(data, 'id', 'parentId')
97-
console.info(list)
98104
} finally {
99105
loading.value = false
100106
}
@@ -112,9 +118,9 @@ const resetQuery = () => {
112118
}
113119
114120
/** 添加/修改操作 */
115-
const modalRef = ref()
116-
const openModal = (type: string, id?: number) => {
117-
modalRef.value.openModal(type, id)
121+
const formRef = ref()
122+
const openForm = (type: string, id?: number) => {
123+
formRef.value.open(type, id)
118124
}
119125
120126
/** 删除按钮操作 */

src/views/mall/product/category/utils.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/views/system/dept/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
v-loading="loading"
5656
:data="list"
5757
row-key="id"
58+
default-expand-all
5859
v-if="refreshTable"
59-
:default-expand-all="isExpandAll"
6060
>
6161
<el-table-column prop="name" label="部门名称" width="260" />
6262
<el-table-column prop="leader" label="负责人" width="120">

0 commit comments

Comments
 (0)