houzhongjian
2024-08-08 820397e43a0b64d35c6d31d2a55475061438593b
提交 | 用户 | 时间
820397 1 <template>
H 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.name"
14           class="!w-240px"
15           clearable
16           placeholder="请输入字典名称"
17           @keyup.enter="handleQuery"
18         />
19       </el-form-item>
20       <el-form-item label="字典类型" prop="type">
21         <el-input
22           v-model="queryParams.type"
23           class="!w-240px"
24           clearable
25           placeholder="请输入字典类型"
26           @keyup.enter="handleQuery"
27         />
28       </el-form-item>
29       <el-form-item label="状态" prop="status">
30         <el-select
31           v-model="queryParams.status"
32           class="!w-240px"
33           clearable
34           placeholder="请选择字典状态"
35         >
36           <el-option
37             v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
38             :key="dict.value"
39             :label="dict.label"
40             :value="dict.value"
41           />
42         </el-select>
43       </el-form-item>
44       <el-form-item label="创建时间" prop="createTime">
45         <el-date-picker
46           v-model="queryParams.createTime"
47           :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
48           class="!w-240px"
49           end-placeholder="结束日期"
50           start-placeholder="开始日期"
51           type="daterange"
52           value-format="YYYY-MM-DD HH:mm:ss"
53         />
54       </el-form-item>
55       <el-form-item>
56         <el-button @click="handleQuery">
57           <Icon class="mr-5px" icon="ep:search" />
58           搜索
59         </el-button>
60         <el-button @click="resetQuery">
61           <Icon class="mr-5px" icon="ep:refresh" />
62           重置
63         </el-button>
64         <el-button
65           v-hasPermi="['system:dict:create']"
66           plain
67           type="primary"
68           @click="openForm('create')"
69         >
70           <Icon class="mr-5px" icon="ep:plus" />
71           新增
72         </el-button>
73         <el-button
74           v-hasPermi="['system:dict:export']"
75           :loading="exportLoading"
76           plain
77           type="success"
78           @click="handleExport"
79         >
80           <Icon class="mr-5px" icon="ep:download" />
81           导出
82         </el-button>
83       </el-form-item>
84     </el-form>
85   </ContentWrap>
86
87   <!-- 列表 -->
88   <ContentWrap>
89     <el-table v-loading="loading" :data="list">
90       <el-table-column align="center" label="字典编号" prop="id" />
91       <el-table-column align="center" label="字典名称" prop="name" show-overflow-tooltip />
92       <el-table-column align="center" label="字典类型" prop="type" width="300" />
93       <el-table-column align="center" label="状态" prop="status">
94         <template #default="scope">
95           <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
96         </template>
97       </el-table-column>
98       <el-table-column align="center" label="备注" prop="remark" />
99       <el-table-column
100         :formatter="dateFormatter"
101         align="center"
102         label="创建时间"
103         prop="createTime"
104         width="180"
105       />
106       <el-table-column align="center" label="操作">
107         <template #default="scope">
108           <el-button
109             v-hasPermi="['system:dict:update']"
110             link
111             type="primary"
112             @click="openForm('update', scope.row.id)"
113           >
114             修改
115           </el-button>
116           <router-link :to="'/dict/type/data/' + scope.row.type">
117             <el-button link type="primary">数据</el-button>
118           </router-link>
119           <el-button
120             v-hasPermi="['system:dict:delete']"
121             link
122             type="danger"
123             @click="handleDelete(scope.row.id)"
124           >
125             删除
126           </el-button>
127         </template>
128       </el-table-column>
129     </el-table>
130     <!-- 分页 -->
131     <Pagination
132       v-model:limit="queryParams.pageSize"
133       v-model:page="queryParams.pageNo"
134       :total="total"
135       @pagination="getList"
136     />
137   </ContentWrap>
138
139   <!-- 表单弹窗:添加/修改 -->
140   <DictTypeForm ref="formRef" @success="getList" />
141 </template>
142
143 <script lang="ts" setup>
144 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
145 import { dateFormatter } from '@/utils/formatTime'
146 import * as DictTypeApi from '@/api/system/dict/dict.type'
147 import DictTypeForm from './DictTypeForm.vue'
148 import download from '@/utils/download'
149
150 defineOptions({ name: 'SystemDictType' })
151
152 const message = useMessage() // 消息弹窗
153 const { t } = useI18n() // 国际化
154
155 const loading = ref(true) // 列表的加载中
156 const total = ref(0) // 列表的总页数
157 const list = ref([]) // 字典表格数据
158 const queryParams = reactive({
159   pageNo: 1,
160   pageSize: 10,
161   name: '',
162   type: '',
163   status: undefined,
164   createTime: []
165 })
166 const queryFormRef = ref() // 搜索的表单
167 const exportLoading = ref(false) // 导出的加载中
168
169 /** 查询字典类型列表 */
170 const getList = async () => {
171   loading.value = true
172   try {
173     const data = await DictTypeApi.getDictTypePage(queryParams)
174     list.value = data.list
175     total.value = data.total
176   } finally {
177     loading.value = false
178   }
179 }
180
181 /** 搜索按钮操作 */
182 const handleQuery = () => {
183   queryParams.pageNo = 1
184   getList()
185 }
186
187 /** 重置按钮操作 */
188 const resetQuery = () => {
189   queryFormRef.value.resetFields()
190   handleQuery()
191 }
192
193 /** 添加/修改操作 */
194 const formRef = ref()
195 const openForm = (type: string, id?: number) => {
196   formRef.value.open(type, id)
197 }
198
199 /** 删除按钮操作 */
200 const handleDelete = async (id: number) => {
201   try {
202     // 删除的二次确认
203     await message.delConfirm()
204     // 发起删除
205     await DictTypeApi.deleteDictType(id)
206     message.success(t('common.delSuccess'))
207     // 刷新列表
208     await getList()
209   } catch {}
210 }
211
212 /** 导出按钮操作 */
213 const handleExport = async () => {
214   try {
215     // 导出的二次确认
216     await message.exportConfirm()
217     // 发起导出
218     exportLoading.value = true
219     const data = await DictTypeApi.exportDictType(queryParams)
220     download.excel(data, '字典类型.xls')
221   } catch {
222   } finally {
223     exportLoading.value = false
224   }
225 }
226
227 /** 初始化 **/
228 onMounted(() => {
229   getList()
230 })
231 </script>