提交 | 用户 | 时间
|
b1d33f
|
1 |
<template> |
潘 |
2 |
<!-- 搜索工作栏 --> |
|
3 |
<ContentWrap> |
|
4 |
<el-form |
|
5 |
ref="queryFormRef" |
|
6 |
:inline="true" |
|
7 |
:model="queryParams" |
|
8 |
class="-mb-15px" |
|
9 |
label-width="68px" |
|
10 |
> |
|
11 |
<el-form-item label="分类名称" prop="name"> |
|
12 |
<el-input |
|
13 |
v-model="queryParams.label" |
|
14 |
class="!w-240px" |
|
15 |
clearable |
|
16 |
placeholder="请输入分类名称" |
|
17 |
@keyup.enter="handleQuery" |
|
18 |
/> |
|
19 |
</el-form-item> |
|
20 |
<el-form-item> |
|
21 |
<el-button @click="handleQuery"> |
|
22 |
<Icon class="mr-5px" icon="ep:search" /> |
|
23 |
搜索 |
|
24 |
</el-button> |
|
25 |
<el-button @click="resetQuery"> |
|
26 |
<Icon class="mr-5px" icon="ep:refresh" /> |
|
27 |
重置 |
|
28 |
</el-button> |
|
29 |
<el-button |
|
30 |
v-hasPermi="['data:plan-item-category:create']" |
|
31 |
plain |
|
32 |
type="primary" |
|
33 |
@click="openForm('create')" |
|
34 |
> |
|
35 |
<Icon class="mr-5px" icon="ep:plus" /> |
|
36 |
新增 |
|
37 |
</el-button> |
|
38 |
<el-button plain type="danger" @click="toggleExpandAll"> |
|
39 |
<Icon class="mr-5px" icon="ep:sort" /> |
|
40 |
展开/折叠 |
|
41 |
</el-button> |
|
42 |
</el-form-item> |
|
43 |
</el-form> |
|
44 |
</ContentWrap> |
|
45 |
|
|
46 |
<!-- 列表 --> |
|
47 |
<ContentWrap> |
|
48 |
<el-table |
|
49 |
v-if="refreshTable" |
|
50 |
v-loading="loading" |
|
51 |
:data="list" |
|
52 |
:default-expand-all="isExpandAll" |
|
53 |
row-key="id" |
|
54 |
> |
|
55 |
<el-table-column :show-overflow-tooltip="true" label="分类名称" prop="label" width="300" /> |
|
56 |
<el-table-column label="排序" prop="sort" width="60" /> |
|
57 |
<el-table-column align="center" label="操作"> |
|
58 |
<template #default="scope"> |
|
59 |
<el-button |
|
60 |
v-hasPermi="['data:plan-item-category:update']" |
|
61 |
link |
|
62 |
type="primary" |
|
63 |
@click="openForm('update', scope.row.id)" |
|
64 |
> |
|
65 |
修改 |
|
66 |
</el-button> |
|
67 |
<el-button |
|
68 |
v-hasPermi="['data:plan-item-category:delete']" |
|
69 |
link |
|
70 |
type="danger" |
|
71 |
@click="handleDelete(scope.row.id)" |
|
72 |
> |
|
73 |
删除 |
|
74 |
</el-button> |
|
75 |
</template> |
|
76 |
</el-table-column> |
|
77 |
</el-table> |
|
78 |
</ContentWrap> |
|
79 |
|
|
80 |
<!-- 表单弹窗:添加/修改 --> |
|
81 |
<CategoryForm ref="formRef" @success="getList" /> |
|
82 |
</template> |
|
83 |
<script lang="ts" setup> |
|
84 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
85 |
import { handleTree } from '@/utils/tree' |
|
86 |
import * as CategoryApi from '@/api/data/plan/category' |
|
87 |
import CategoryForm from './CategoryForm.vue' |
|
88 |
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' |
|
89 |
|
|
90 |
defineOptions({ name: 'PlanItemCategory' }) |
|
91 |
|
|
92 |
const { wsCache } = useCache() |
|
93 |
const { t } = useI18n() // 国际化 |
|
94 |
const message = useMessage() // 消息弹窗 |
|
95 |
|
|
96 |
const loading = ref(true) // 列表的加载中 |
|
97 |
const list = ref<any>([]) // 列表的数据 |
|
98 |
const queryParams = reactive({ |
|
99 |
label: undefined |
|
100 |
}) |
|
101 |
const queryFormRef = ref() // 搜索的表单 |
|
102 |
const isExpandAll = ref(false) // 是否展开,默认全部折叠 |
|
103 |
const refreshTable = ref(true) // 重新渲染表格状态 |
|
104 |
|
|
105 |
/** 查询列表 */ |
|
106 |
const getList = async () => { |
|
107 |
loading.value = true |
|
108 |
try { |
|
109 |
const data = await CategoryApi.getCategoryList(queryParams) |
|
110 |
list.value = handleTree(data, 'id', 'pid') |
|
111 |
} finally { |
|
112 |
loading.value = false |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
/** 搜索按钮操作 */ |
|
117 |
const handleQuery = () => { |
|
118 |
getList() |
|
119 |
} |
|
120 |
|
|
121 |
/** 重置按钮操作 */ |
|
122 |
const resetQuery = () => { |
|
123 |
queryFormRef.value.resetFields() |
|
124 |
handleQuery() |
|
125 |
} |
|
126 |
|
|
127 |
/** 添加/修改操作 */ |
|
128 |
const formRef = ref() |
|
129 |
const openForm = (type: string, id?: number, parentId?: number) => { |
|
130 |
formRef.value.open(type, id, parentId) |
|
131 |
} |
|
132 |
|
|
133 |
/** 展开/折叠操作 */ |
|
134 |
const toggleExpandAll = () => { |
|
135 |
refreshTable.value = false |
|
136 |
isExpandAll.value = !isExpandAll.value |
|
137 |
nextTick(() => { |
|
138 |
refreshTable.value = true |
|
139 |
}) |
|
140 |
} |
|
141 |
|
|
142 |
/** 删除按钮操作 */ |
|
143 |
const handleDelete = async (id: number) => { |
|
144 |
try { |
|
145 |
// 删除的二次确认 |
|
146 |
await message.delConfirm() |
|
147 |
// 发起删除 |
|
148 |
await CategoryApi.deleteCategory(id) |
|
149 |
message.success(t('common.delSuccess')) |
|
150 |
// 刷新列表 |
|
151 |
await getList() |
|
152 |
} catch {} |
|
153 |
} |
|
154 |
|
|
155 |
/** 初始化 **/ |
|
156 |
onMounted(() => { |
|
157 |
getList() |
|
158 |
}) |
|
159 |
</script> |