mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-12 10:05:07 +08:00
refactor: role
This commit is contained in:
@ -1,8 +1,24 @@
|
|||||||
import request from '@/config/axios'
|
import request from '@/config/axios'
|
||||||
import type { RoleVO } from './types'
|
|
||||||
|
export type RoleVO = {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
code: string
|
||||||
|
sort: number
|
||||||
|
status: number
|
||||||
|
type: number
|
||||||
|
createTime: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RolePageReqVO extends PageParam {
|
||||||
|
name?: string
|
||||||
|
code?: string
|
||||||
|
status?: number
|
||||||
|
createTime?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
// 查询角色列表
|
// 查询角色列表
|
||||||
export const getRolePageApi = async (params) => {
|
export const getRolePageApi = async (params: RolePageReqVO) => {
|
||||||
return await request.get({ url: '/system/role/page', params })
|
return await request.get({ url: '/system/role/page', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
export type RoleVO = {
|
|
||||||
id: number
|
|
||||||
name: string
|
|
||||||
code: string
|
|
||||||
sort: number
|
|
||||||
status: number
|
|
||||||
type: number
|
|
||||||
createTime: string
|
|
||||||
}
|
|
@ -1,42 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- 搜索工作区 -->
|
|
||||||
<ContentWrap>
|
<ContentWrap>
|
||||||
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
|
|
||||||
</ContentWrap>
|
|
||||||
<ContentWrap>
|
|
||||||
<!-- 操作工具栏 -->
|
|
||||||
<div class="mb-10px">
|
|
||||||
<XButton
|
|
||||||
type="primary"
|
|
||||||
preIcon="ep:zoom-in"
|
|
||||||
:title="t('action.add')"
|
|
||||||
v-hasPermi="['system:role:create']"
|
|
||||||
@click="handleCreate()"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<Table
|
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
|
||||||
:columns="allSchemas.tableColumns"
|
<!-- 操作:新增 -->
|
||||||
:selection="false"
|
<template #toolbar_buttons>
|
||||||
:data="tableObject.tableList"
|
<XButton
|
||||||
:loading="tableObject.loading"
|
type="primary"
|
||||||
:pagination="{
|
preIcon="ep:zoom-in"
|
||||||
total: tableObject.total
|
:title="t('action.add')"
|
||||||
}"
|
v-hasPermi="['system:role:create']"
|
||||||
v-model:pageSize="tableObject.pageSize"
|
@click="handleCreate()"
|
||||||
v-model:currentPage="tableObject.currentPage"
|
/>
|
||||||
@register="register"
|
|
||||||
>
|
|
||||||
<template #type="{ row }">
|
|
||||||
<DictTag :type="DICT_TYPE.SYSTEM_ROLE_TYPE" :value="row.type" />
|
|
||||||
</template>
|
</template>
|
||||||
<template #status="{ row }">
|
<template #actionbtns_default="{ row }">
|
||||||
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
|
|
||||||
</template>
|
|
||||||
<template #createTime="{ row }">
|
|
||||||
<span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
|
|
||||||
</template>
|
|
||||||
<template #action="{ row }">
|
|
||||||
<XTextButton
|
<XTextButton
|
||||||
preIcon="ep:edit"
|
preIcon="ep:edit"
|
||||||
:title="t('action.edit')"
|
:title="t('action.edit')"
|
||||||
@ -47,7 +23,7 @@
|
|||||||
preIcon="ep:view"
|
preIcon="ep:view"
|
||||||
:title="t('action.detail')"
|
:title="t('action.detail')"
|
||||||
v-hasPermi="['system:role:update']"
|
v-hasPermi="['system:role:update']"
|
||||||
@click="handleDetail(row)"
|
@click="handleDetail(row.id)"
|
||||||
/>
|
/>
|
||||||
<XTextButton
|
<XTextButton
|
||||||
preIcon="ep:basketball"
|
preIcon="ep:basketball"
|
||||||
@ -65,10 +41,10 @@
|
|||||||
preIcon="ep:delete"
|
preIcon="ep:delete"
|
||||||
:title="t('action.del')"
|
:title="t('action.del')"
|
||||||
v-hasPermi="['system:role:delete']"
|
v-hasPermi="['system:role:delete']"
|
||||||
@click="delList(row.id, false)"
|
@click="handleDelete(row.id)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Table>
|
</vxe-grid>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
|
|
||||||
<XModal v-model="dialogVisible" :title="dialogTitle">
|
<XModal v-model="dialogVisible" :title="dialogTitle">
|
||||||
@ -91,10 +67,10 @@
|
|||||||
v-if="['create', 'update'].includes(actionType)"
|
v-if="['create', 'update'].includes(actionType)"
|
||||||
type="primary"
|
type="primary"
|
||||||
:title="t('action.save')"
|
:title="t('action.save')"
|
||||||
:loading="loading"
|
:loading="actionLoading"
|
||||||
@click="submitForm()"
|
@click="submitForm()"
|
||||||
/>
|
/>
|
||||||
<XButton :loading="loading" :title="t('dialog.close')" @click="dialogVisible = false" />
|
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
|
||||||
</template>
|
</template>
|
||||||
</XModal>
|
</XModal>
|
||||||
<XModal v-model="dialogScopeVisible" :title="dialogScopeTitle">
|
<XModal v-model="dialogScopeVisible" :title="dialogScopeTitle">
|
||||||
@ -151,56 +127,66 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<!-- 操作按钮 -->
|
<!-- 操作按钮 -->
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<XButton type="primary" :title="t('action.save')" :loading="loading" @click="submitScope()" />
|
<XButton
|
||||||
<XButton :loading="loading" :title="t('dialog.close')" @click="dialogScopeVisible = false" />
|
type="primary"
|
||||||
|
:title="t('action.save')"
|
||||||
|
:loading="actionLoading"
|
||||||
|
@click="submitScope()"
|
||||||
|
/>
|
||||||
|
<XButton
|
||||||
|
:loading="actionLoading"
|
||||||
|
:title="t('dialog.close')"
|
||||||
|
@click="dialogScopeVisible = false"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</XModal>
|
</XModal>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, reactive, ref, unref } from 'vue'
|
import { onMounted, reactive, ref, unref } from 'vue'
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import {
|
import {
|
||||||
ElForm,
|
ElForm,
|
||||||
ElFormItem,
|
ElFormItem,
|
||||||
ElInput,
|
ElInput,
|
||||||
ElSelect,
|
ElSelect,
|
||||||
ElOption,
|
ElOption,
|
||||||
ElMessage,
|
|
||||||
ElTree,
|
ElTree,
|
||||||
ElCard,
|
ElCard,
|
||||||
ElSwitch
|
ElSwitch
|
||||||
} from 'element-plus'
|
} from 'element-plus'
|
||||||
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
||||||
import { useTable } from '@/hooks/web/useTable'
|
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
import { FormExpose } from '@/components/Form'
|
import { FormExpose } from '@/components/Form'
|
||||||
import { rules, allSchemas } from './role.data'
|
import { rules, allSchemas } from './role.data'
|
||||||
import type { RoleVO } from '@/api/system/role/types'
|
import { handleTree } from '@/utils/tree'
|
||||||
|
import { SystemDataScopeEnum } from '@/utils/constants'
|
||||||
|
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
||||||
|
import { VxeGridInstance } from 'vxe-table'
|
||||||
|
import * as RoleApi from '@/api/system/role'
|
||||||
|
import { listSimpleMenusApi } from '@/api/system/menu'
|
||||||
|
import { listSimpleDeptApi } from '@/api/system/dept'
|
||||||
|
import * as PermissionApi from '@/api/system/permission'
|
||||||
import type {
|
import type {
|
||||||
PermissionAssignRoleDataScopeReqVO,
|
PermissionAssignRoleDataScopeReqVO,
|
||||||
PermissionAssignRoleMenuReqVO
|
PermissionAssignRoleMenuReqVO
|
||||||
} from '@/api/system/permission/types'
|
} from '@/api/system/permission/types'
|
||||||
import * as RoleApi from '@/api/system/role'
|
|
||||||
import * as PermissionApi from '@/api/system/permission'
|
|
||||||
import { listSimpleMenusApi } from '@/api/system/menu'
|
|
||||||
import { listSimpleDeptApi } from '@/api/system/dept'
|
|
||||||
import { handleTree } from '@/utils/tree'
|
|
||||||
import { SystemDataScopeEnum } from '@/utils/constants'
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
// ========== 列表相关 ==========
|
// 列表相关的变量
|
||||||
const { register, tableObject, methods } = useTable<RoleVO>({
|
const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
|
||||||
|
const { gridOptions, reloadList, delList } = useVxeGrid<RoleApi.RoleVO>({
|
||||||
|
allSchemas: allSchemas,
|
||||||
getListApi: RoleApi.getRolePageApi,
|
getListApi: RoleApi.getRolePageApi,
|
||||||
delListApi: RoleApi.deleteRoleApi
|
delListApi: RoleApi.deleteRoleApi
|
||||||
})
|
})
|
||||||
const { getList, setSearchParams, delList } = methods
|
|
||||||
|
|
||||||
// ========== CRUD 相关 ==========
|
// ========== CRUD 相关 ==========
|
||||||
const loading = ref(false) // 遮罩层
|
const actionLoading = ref(false) // 遮罩层
|
||||||
const actionType = ref('') // 操作按钮的类型
|
const actionType = ref('') // 操作按钮的类型
|
||||||
const dialogVisible = ref(false) // 是否显示弹出层
|
const dialogVisible = ref(false) // 是否显示弹出层
|
||||||
const dialogTitle = ref('edit') // 弹出层标题
|
const dialogTitle = ref('edit') // 弹出层标题
|
||||||
const formRef = ref<FormExpose>() // 表单 Ref
|
const formRef = ref<FormExpose>() // 表单 Ref
|
||||||
|
const detailRef = ref() // 详情 Ref
|
||||||
|
|
||||||
// 设置标题
|
// 设置标题
|
||||||
const setDialogTile = (type: string) => {
|
const setDialogTile = (type: string) => {
|
||||||
@ -222,41 +208,44 @@ const handleUpdate = async (rowId: number) => {
|
|||||||
unref(formRef)?.setValues(res)
|
unref(formRef)?.setValues(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除操作
|
||||||
|
const handleDelete = async (rowId: number) => {
|
||||||
|
await delList(xGrid, rowId)
|
||||||
|
}
|
||||||
|
|
||||||
// 提交按钮
|
// 提交按钮
|
||||||
const submitForm = async () => {
|
const submitForm = async () => {
|
||||||
const elForm = unref(formRef)?.getElFormRef()
|
const elForm = unref(formRef)?.getElFormRef()
|
||||||
if (!elForm) return
|
if (!elForm) return
|
||||||
elForm.validate(async (valid) => {
|
elForm.validate(async (valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
loading.value = true
|
actionLoading.value = true
|
||||||
// 提交请求
|
// 提交请求
|
||||||
try {
|
try {
|
||||||
const data = unref(formRef)?.formModel as RoleVO
|
const data = unref(formRef)?.formModel as RoleApi.RoleVO
|
||||||
if (actionType.value === 'create') {
|
if (actionType.value === 'create') {
|
||||||
await RoleApi.createRoleApi(data)
|
await RoleApi.createRoleApi(data)
|
||||||
ElMessage.success(t('common.createSuccess'))
|
message.success(t('common.createSuccess'))
|
||||||
} else {
|
} else {
|
||||||
await RoleApi.updateRoleApi(data)
|
await RoleApi.updateRoleApi(data)
|
||||||
ElMessage.success(t('common.updateSuccess'))
|
message.success(t('common.updateSuccess'))
|
||||||
}
|
}
|
||||||
// 操作成功,重新加载列表
|
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
await getList()
|
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
actionLoading.value = false
|
||||||
|
// 刷新列表
|
||||||
|
reloadList(xGrid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 详情相关 ==========
|
|
||||||
const detailRef = ref() // 详情 Ref
|
|
||||||
|
|
||||||
// 详情操作
|
// 详情操作
|
||||||
const handleDetail = async (row: RoleVO) => {
|
const handleDetail = async (rowId: number) => {
|
||||||
// 设置数据
|
|
||||||
detailRef.value = row
|
|
||||||
setDialogTile('detail')
|
setDialogTile('detail')
|
||||||
|
// 设置数据
|
||||||
|
const res = await RoleApi.getRoleApi(rowId)
|
||||||
|
detailRef.value = res
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 数据权限 ==========
|
// ========== 数据权限 ==========
|
||||||
@ -287,7 +276,7 @@ const handleCheckedTreeNodeAll = () => {
|
|||||||
treeRef.value!.setCheckedNodes(treeNodeAll.value ? treeOptions.value : [])
|
treeRef.value!.setCheckedNodes(treeNodeAll.value ? treeOptions.value : [])
|
||||||
}
|
}
|
||||||
// 权限操作
|
// 权限操作
|
||||||
const handleScope = async (type: string, row: RoleVO) => {
|
const handleScope = async (type: string, row: RoleApi.RoleVO) => {
|
||||||
dataScopeForm.id = row.id
|
dataScopeForm.id = row.id
|
||||||
dataScopeForm.name = row.name
|
dataScopeForm.name = row.name
|
||||||
dataScopeForm.code = row.code
|
dataScopeForm.code = row.code
|
||||||
@ -329,7 +318,7 @@ const submitScope = async () => {
|
|||||||
})
|
})
|
||||||
await PermissionApi.assignRoleMenuApi(data.value)
|
await PermissionApi.assignRoleMenuApi(data.value)
|
||||||
}
|
}
|
||||||
ElMessage.success(t('common.updateSuccess'))
|
message.success(t('common.updateSuccess'))
|
||||||
dialogScopeVisible.value = false
|
dialogScopeVisible.value = false
|
||||||
}
|
}
|
||||||
const init = () => {
|
const init = () => {
|
||||||
@ -337,7 +326,6 @@ const init = () => {
|
|||||||
}
|
}
|
||||||
// ========== 初始化 ==========
|
// ========== 初始化 ==========
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getList()
|
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,7 +2,7 @@ import { reactive } from 'vue'
|
|||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { required } from '@/utils/formRules'
|
import { required } from '@/utils/formRules'
|
||||||
import { DICT_TYPE } from '@/utils/dict'
|
import { DICT_TYPE } from '@/utils/dict'
|
||||||
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
|
||||||
// 国际化
|
// 国际化
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
// 表单校验
|
// 表单校验
|
||||||
@ -12,82 +12,52 @@ export const rules = reactive({
|
|||||||
sort: [required]
|
sort: [required]
|
||||||
})
|
})
|
||||||
// CrudSchema
|
// CrudSchema
|
||||||
const crudSchemas = reactive<CrudSchema[]>([
|
const crudSchemas = reactive<VxeCrudSchema>({
|
||||||
{
|
primaryKey: 'id',
|
||||||
label: t('common.index'),
|
primaryType: 'seq',
|
||||||
field: 'id',
|
action: true,
|
||||||
type: 'index',
|
actionWidth: '400px',
|
||||||
form: {
|
columns: [
|
||||||
show: false
|
{
|
||||||
|
title: '角色名称',
|
||||||
|
field: 'name',
|
||||||
|
isSearch: true
|
||||||
},
|
},
|
||||||
detail: {
|
{
|
||||||
show: false
|
title: '角色类型',
|
||||||
}
|
field: 'type',
|
||||||
},
|
dictType: DICT_TYPE.SYSTEM_ROLE_TYPE
|
||||||
{
|
|
||||||
label: '角色名称',
|
|
||||||
field: 'name',
|
|
||||||
search: {
|
|
||||||
show: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '角色类型',
|
|
||||||
field: 'type',
|
|
||||||
dictType: DICT_TYPE.SYSTEM_ROLE_TYPE
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '角色标识',
|
|
||||||
field: 'code',
|
|
||||||
search: {
|
|
||||||
show: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '显示顺序',
|
|
||||||
field: 'sort',
|
|
||||||
form: {
|
|
||||||
component: 'InputNumber',
|
|
||||||
value: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: t('common.status'),
|
|
||||||
field: 'status',
|
|
||||||
dictType: DICT_TYPE.COMMON_STATUS,
|
|
||||||
search: {
|
|
||||||
show: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: t('common.createTime'),
|
|
||||||
field: 'createTime',
|
|
||||||
form: {
|
|
||||||
show: false
|
|
||||||
},
|
},
|
||||||
detail: {
|
{
|
||||||
show: false
|
title: '角色标识',
|
||||||
|
field: 'code',
|
||||||
|
isSearch: true
|
||||||
},
|
},
|
||||||
search: {
|
{
|
||||||
show: true,
|
title: '显示顺序',
|
||||||
component: 'DatePicker',
|
field: 'sort',
|
||||||
componentProps: {
|
form: {
|
||||||
type: 'daterange',
|
component: 'InputNumber'
|
||||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
}
|
||||||
defaultTime: [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]
|
},
|
||||||
|
{
|
||||||
|
title: t('common.status'),
|
||||||
|
field: 'status',
|
||||||
|
dictType: DICT_TYPE.COMMON_STATUS,
|
||||||
|
isSearch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t('common.createTime'),
|
||||||
|
field: 'createTime',
|
||||||
|
formatter: 'formatDate',
|
||||||
|
isForm: false,
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
itemRender: {
|
||||||
|
name: 'XDataTimePicker'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
]
|
||||||
{
|
})
|
||||||
field: 'action',
|
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)
|
||||||
width: '450px',
|
|
||||||
label: t('table.action'),
|
|
||||||
form: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
detail: {
|
|
||||||
show: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
])
|
|
||||||
export const { allSchemas } = useCrudSchemas(crudSchemas)
|
|
||||||
|
Reference in New Issue
Block a user