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