Skip to content

Commit 1a43113

Browse files
committed
Vue3 重构:REVIEW 角色管理
1 parent 17395a4 commit 1a43113

File tree

5 files changed

+36
-75
lines changed

5 files changed

+36
-75
lines changed

src/api/system/role/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,13 @@ export interface RoleVO {
1010
createTime: Date
1111
}
1212

13-
export interface RolePageReqVO extends PageParam {
14-
name?: string
15-
code?: string
16-
status?: number
17-
createTime?: Date[]
18-
}
19-
2013
export interface UpdateStatusReqVO {
2114
id: number
2215
status: number
2316
}
2417

2518
// 查询角色列表
26-
export const getRolePage = async (params: RolePageReqVO) => {
19+
export const getRolePage = async (params: PageParam) => {
2720
return await request.get({ url: '/system/role/page', params })
2821
}
2922

src/types/auto-components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ declare module '@vue/runtime-core' {
5252
ElForm: typeof import('element-plus/es')['ElForm']
5353
ElFormItem: typeof import('element-plus/es')['ElFormItem']
5454
ElIcon: typeof import('element-plus/es')['ElIcon']
55+
ElImage: typeof import('element-plus/es')['ElImage']
5556
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
5657
ElInput: typeof import('element-plus/es')['ElInput']
5758
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']

src/views/system/notice/form.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
<script setup lang="ts">
4747
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
4848
import * as NoticeApi from '@/api/system/notice'
49-
5049
const { t } = useI18n() // 国际化
5150
const message = useMessage() // 消息弹窗
5251

src/views/system/role/RoleForm.vue

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Dialog :title="dialogTitle" v-model="modelVisible" width="800">
2+
<Dialog :title="modelTitle" v-model="modelVisible">
33
<el-form
44
ref="formRef"
55
:model="formData"
@@ -10,9 +10,6 @@
1010
<el-form-item label="角色名称" prop="name">
1111
<el-input v-model="formData.name" placeholder="请输入角色名称" />
1212
</el-form-item>
13-
<el-form-item label="角色类型" prop="type">
14-
<el-input :model-value="formData.type" placeholder="请输入角色类型" height="150px" />
15-
</el-form-item>
1613
<el-form-item label="角色标识" prop="code">
1714
<el-input :model-value="formData.code" placeholder="请输入角色标识" height="150px" />
1815
</el-form-item>
@@ -22,10 +19,10 @@
2219
<el-form-item label="状态" prop="status">
2320
<el-select v-model="formData.status" placeholder="请选择状态" clearable>
2421
<el-option
25-
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
26-
:key="parseInt(dict.value)"
22+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
23+
:key="dict.value"
2724
:label="dict.label"
28-
:value="parseInt(dict.value)"
25+
:value="dict.value"
2926
/>
3027
</el-select>
3128
</el-form-item>
@@ -34,34 +31,25 @@
3431
</el-form-item>
3532
</el-form>
3633
<template #footer>
37-
<div class="dialog-footer">
38-
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
39-
<el-button @click="modelVisible = false">取 消</el-button>
40-
</div>
34+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
35+
<el-button @click="modelVisible = false">取 消</el-button>
4136
</template>
4237
</Dialog>
4338
</template>
4439
<script setup lang="ts">
45-
import { getDictOptions } from '@/utils/dict'
46-
import { CommonStatusEnum } from '@/utils/constants'
4740
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
41+
import { CommonStatusEnum } from '@/utils/constants'
4842
import * as RoleApi from '@/api/system/role'
49-
// ========== CRUD 相关 ==========
50-
const dialogTitle = ref('edit') // 弹出层标题
51-
const formRef = ref() // 表单 Ref
5243
const { t } = useI18n() // 国际化
53-
const dataScopeDictDatas = ref()
5444
const message = useMessage() // 消息弹窗
5545
5646
const modelVisible = ref(false) // 弹窗的是否展示
5747
const modelTitle = ref('') // 弹窗的标题
5848
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
5949
const formType = ref('') // 表单的类型:create - 新增;update - 修改
60-
6150
const formData = ref({
6251
id: undefined,
6352
name: '',
64-
type: '',
6553
code: '',
6654
sort: undefined,
6755
status: CommonStatusEnum.ENABLE,
@@ -74,9 +62,10 @@ const formRules = reactive({
7462
status: [{ required: true, message: '岗位状态不能为空', trigger: 'change' }],
7563
remark: [{ required: false, message: '岗位内容不能为空', trigger: 'blur' }]
7664
})
65+
const formRef = ref() // 表单 Ref
7766
7867
/** 打开弹窗 */
79-
const openModal = async (type: string, id?: number) => {
68+
const open = async (type: string, id?: number) => {
8069
modelVisible.value = true
8170
modelTitle.value = t('action.' + type)
8271
formType.value = type
@@ -91,20 +80,21 @@ const openModal = async (type: string, id?: number) => {
9180
}
9281
}
9382
}
83+
9484
/** 重置表单 */
9585
const resetForm = () => {
9686
formData.value = {
9787
id: undefined,
9888
name: '',
99-
type: '',
10089
code: '',
10190
sort: undefined,
10291
status: CommonStatusEnum.ENABLE,
10392
remark: ''
10493
}
10594
formRef.value?.resetFields()
10695
}
107-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
96+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
97+
10898
/** 提交表单 */
10999
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
110100
const submitForm = async () => {
@@ -130,19 +120,4 @@ const submitForm = async () => {
130120
formLoading.value = false
131121
}
132122
}
133-
134-
const init = () => {
135-
dataScopeDictDatas.value = getIntDictOptions(DICT_TYPE.SYSTEM_DATA_SCOPE)
136-
}
137-
// ========== 初始化 ==========
138-
onMounted(() => {
139-
init()
140-
})
141123
</script>
142-
<style scoped>
143-
.card {
144-
width: 100%;
145-
max-height: 400px;
146-
overflow-y: scroll;
147-
}
148-
</style>

src/views/system/role/index.vue

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
placeholder="请输入角色名称"
1515
clearable
1616
@keyup.enter="handleQuery"
17+
class="!w-240px"
1718
/>
1819
</el-form-item>
1920
<el-form-item label="角色标识" prop="code">
@@ -22,10 +23,11 @@
2223
placeholder="请输入角色标识"
2324
clearable
2425
@keyup.enter="handleQuery"
26+
class="!w-240px"
2527
/>
2628
</el-form-item>
2729
<el-form-item label="状态" prop="status">
28-
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
30+
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
2931
<el-option
3032
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
3133
:key="dict.value"
@@ -48,7 +50,12 @@
4850
<el-form-item>
4951
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
5052
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
51-
<el-button type="primary" @click="openModal('create')" v-hasPermi="['system:role:create']">
53+
<el-button
54+
type="primary"
55+
plain
56+
@click="openForm('create')"
57+
v-hasPermi="['system:role:create']"
58+
>
5259
<Icon icon="ep:plus" class="mr-5px" /> 新增
5360
</el-button>
5461
<el-button
@@ -66,7 +73,7 @@
6673

6774
<!-- 列表 -->
6875
<ContentWrap>
69-
<el-table v-loading="loading" :data="list" align="center">
76+
<el-table v-loading="loading" :data="list">
7077
<el-table-column label="角色编号" align="center" prop="id" />
7178
<el-table-column label="角色名称" align="center" prop="name" />
7279
<el-table-column label="角色类型" align="center" prop="type" />
@@ -90,12 +97,11 @@
9097
<el-button
9198
link
9299
type="primary"
93-
@click="openModal('update', scope.row.id)"
100+
@click="openForm('update', scope.row.id)"
94101
v-hasPermi="['system:role:update']"
95102
>
96103
编辑
97104
</el-button>
98-
<!-- 操作:菜单权限 -->
99105
<el-button
100106
link
101107
type="primary"
@@ -106,7 +112,6 @@
106112
>
107113
菜单权限
108114
</el-button>
109-
<!-- 操作:数据权限 -->
110115
<el-button
111116
link
112117
type="primary"
@@ -149,18 +154,12 @@ import MenuPermissionForm from './MenuPermissionForm.vue'
149154
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
150155
import { dateFormatter } from '@/utils/formatTime'
151156
import download from '@/utils/download'
152-
153157
const message = useMessage() // 消息弹窗
154158
const { t } = useI18n() // 国际化
159+
155160
const loading = ref(true) // 列表的加载中
156161
const total = ref(0) // 列表的总页数
157162
const list = ref([]) // 列表的数据
158-
const dialogTitle = ref('编辑') // 弹出层标题
159-
const actionType = ref('') // 操作按钮的类型
160-
const modelVisible = ref(false) // 是否显示弹出层
161-
const queryFormRef = ref() // 搜索的表单
162-
const exportLoading = ref(false) // 导出的加载中
163-
164163
const queryParams = reactive({
165164
pageNo: 1,
166165
pageSize: 10,
@@ -169,13 +168,8 @@ const queryParams = reactive({
169168
status: undefined,
170169
createTime: []
171170
})
172-
173-
// 设置标题
174-
const setDialogTile = (type: string) => {
175-
dialogTitle.value = t('action.' + type)
176-
actionType.value = type
177-
modelVisible.value = true
178-
}
171+
const queryFormRef = ref() // 搜索的表单
172+
const exportLoading = ref(false) // 导出的加载中
179173
180174
/** 查询角色列表 */
181175
const getList = async () => {
@@ -203,9 +197,14 @@ const resetQuery = () => {
203197
204198
/** 添加/修改操作 */
205199
const formRef = ref()
206-
const openModal = (type: string, id?: number) => {
207-
setDialogTile('编辑')
208-
formRef.value.openModal(type, id)
200+
const openForm = (type: string, id?: number) => {
201+
formRef.value.open(type, id)
202+
}
203+
204+
/** 数据权限操作 */
205+
const menuPermissionFormRef = ref()
206+
const handleScope = async (type: string, row: RoleApi.RoleVO) => {
207+
menuPermissionFormRef.value.openForm(type, row)
209208
}
210209
211210
/** 删除按钮操作 */
@@ -235,13 +234,7 @@ const handleExport = async () => {
235234
exportLoading.value = false
236235
}
237236
}
238-
/** 数据权限操作 */
239-
const menuPermissionFormRef = ref()
240237
241-
// 权限操作
242-
const handleScope = async (type: string, row: RoleApi.RoleVO) => {
243-
menuPermissionFormRef.value.openModal(type, row)
244-
}
245238
/** 初始化 **/
246239
onMounted(() => {
247240
getList()

0 commit comments

Comments
 (0)