up.
This commit is contained in:
parent
31b8e5807f
commit
23ee3f6d7c
@ -3,7 +3,7 @@ import type { ApiResult, PageResult } from '@/api';
|
|||||||
import type { Config, ConfigParam } from './model';
|
import type { Config, ConfigParam } from './model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询角色
|
* 分页查询配置
|
||||||
*/
|
*/
|
||||||
export async function configData(params: ConfigParam) {
|
export async function configData(params: ConfigParam) {
|
||||||
const res = await request.get<ApiResult<PageResult<Config>>>(
|
const res = await request.get<ApiResult<PageResult<Config>>>(
|
||||||
@ -17,7 +17,7 @@ export async function configData(params: ConfigParam) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询角色列表
|
* 查询配置列表
|
||||||
*/
|
*/
|
||||||
export async function listConfig(params?: ConfigParam) {
|
export async function listConfig(params?: ConfigParam) {
|
||||||
const res = await request.get<ApiResult<Config[]>>('/system/config', {
|
const res = await request.get<ApiResult<Config[]>>('/system/config', {
|
||||||
@ -28,3 +28,49 @@ export async function listConfig(params?: ConfigParam) {
|
|||||||
}
|
}
|
||||||
return Promise.reject(new Error(res.data.message));
|
return Promise.reject(new Error(res.data.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加配置
|
||||||
|
*/
|
||||||
|
export async function addConfig(data: Config) {
|
||||||
|
const res = await request.post<ApiResult<unknown>>('/system/config', data);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改配置
|
||||||
|
*/
|
||||||
|
export async function updateConfig(data: Config) {
|
||||||
|
const res = await request.put<ApiResult<unknown>>('/system/config', data);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改配置状态
|
||||||
|
*/
|
||||||
|
export async function updateConfigStatus(data: Config) {
|
||||||
|
const res = await request.put<ApiResult<unknown>>('/system/config/status', data);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除配置
|
||||||
|
*/
|
||||||
|
export async function removeConfigs(id?: number) {
|
||||||
|
const res = await request.delete<ApiResult<unknown>>('/system/config/batch');
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
<!-- 角色编辑弹窗 -->
|
<!-- 配置编辑弹窗 -->
|
||||||
<template>
|
<template>
|
||||||
<ele-modal
|
<ele-modal
|
||||||
form
|
form
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
:width="460"
|
:width="460"
|
||||||
v-model="visible"
|
v-model="visible"
|
||||||
:title="isUpdate ? '修改角色' : '添加角色'"
|
:title="isUpdate ? '修改配置' : '添加配置'"
|
||||||
>
|
>
|
||||||
<el-form
|
<el-form
|
||||||
ref="formRef"
|
ref="formRef"
|
||||||
@ -14,20 +14,45 @@
|
|||||||
label-width="80px"
|
label-width="80px"
|
||||||
@submit.prevent=""
|
@submit.prevent=""
|
||||||
>
|
>
|
||||||
<el-form-item label="角色名称" prop="roleName">
|
<el-form-item label="配置标题" prop="title">
|
||||||
<el-input
|
<el-input
|
||||||
clearable
|
clearable
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
v-model="form.roleName"
|
v-model="form.title"
|
||||||
placeholder="请输入角色名称"
|
placeholder="请输入配置标题(一般由中文组成,仅用于显示)"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色标识" prop="roleCode">
|
<el-form-item label="配置名称" prop="name">
|
||||||
<el-input
|
<el-input
|
||||||
clearable
|
clearable
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
v-model="form.roleCode"
|
v-model="form.name"
|
||||||
placeholder="请输入角色标识"
|
placeholder="请输入配置名称"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<!-- //由英文字母和下划线组成,如 web_site_title,调用方法:config('web_site_title')-->
|
||||||
|
<el-form-item label="配置值">
|
||||||
|
<el-input
|
||||||
|
:rows="4"
|
||||||
|
type="textarea"
|
||||||
|
v-model="form.value"
|
||||||
|
placeholder="请输入配置值"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="配置项">
|
||||||
|
<el-input
|
||||||
|
:rows="4"
|
||||||
|
type="textarea"
|
||||||
|
v-model="form.options"
|
||||||
|
placeholder="请输入配置项"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注">
|
||||||
|
<el-input
|
||||||
|
:rows="4"
|
||||||
|
type="textarea"
|
||||||
|
v-model="form.tips"
|
||||||
|
placeholder="请输入备注"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="备注">
|
<el-form-item label="备注">
|
||||||
@ -53,12 +78,12 @@
|
|||||||
import type { FormInstance, FormRules } from 'element-plus';
|
import type { FormInstance, FormRules } from 'element-plus';
|
||||||
import { EleMessage } from 'ele-admin-plus';
|
import { EleMessage } from 'ele-admin-plus';
|
||||||
import { useFormData } from '@/utils/use-form-data';
|
import { useFormData } from '@/utils/use-form-data';
|
||||||
import { addRole, updateRole } from '@/api/system/role';
|
import type { Config } from '@/api/system/config/model';
|
||||||
import type { Role } from '@/api/system/role/model';
|
import {addConfig, updateConfig} from "@/api/system/config";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
/** 修改回显的数据 */
|
/** 修改回显的数据 */
|
||||||
data?: Role | null;
|
data?: Config | null;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@ -78,7 +103,7 @@
|
|||||||
const formRef = ref<FormInstance | null>(null);
|
const formRef = ref<FormInstance | null>(null);
|
||||||
|
|
||||||
/** 表单数据 */
|
/** 表单数据 */
|
||||||
const [form, resetFields, assignFields] = useFormData<Role>({
|
const [form, resetFields, assignFields] = useFormData<Config>({
|
||||||
roleId: void 0,
|
roleId: void 0,
|
||||||
roleName: '',
|
roleName: '',
|
||||||
roleCode: '',
|
roleCode: '',
|
||||||
@ -90,7 +115,7 @@
|
|||||||
roleName: [
|
roleName: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入角色名称',
|
message: '请输入配置名称',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}
|
}
|
||||||
@ -98,7 +123,7 @@
|
|||||||
roleCode: [
|
roleCode: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入角色标识',
|
message: '请输入配置标识',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}
|
}
|
||||||
@ -117,7 +142,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const saveOrUpdate = isUpdate.value ? updateRole : addRole;
|
const saveOrUpdate = isUpdate.value ? updateConfig : addConfig;
|
||||||
saveOrUpdate(form)
|
saveOrUpdate(form)
|
||||||
.then((msg) => {
|
.then((msg) => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@ -1,148 +0,0 @@
|
|||||||
<!-- 角色权限分配弹窗 -->
|
|
||||||
<template>
|
|
||||||
<ele-modal
|
|
||||||
:width="460"
|
|
||||||
title="分配权限"
|
|
||||||
position="center"
|
|
||||||
v-model="visible"
|
|
||||||
:body-style="{ padding: '12px 0 12px 22px' }"
|
|
||||||
@open="handleOpen"
|
|
||||||
>
|
|
||||||
<ele-loading
|
|
||||||
:loading="authLoading"
|
|
||||||
:spinner-style="{ background: 'transparent' }"
|
|
||||||
:style="{
|
|
||||||
paddingRight: '20px',
|
|
||||||
height: 'calc(100vh - 192px)',
|
|
||||||
maxHeight: 'calc(100dvh - 192px)',
|
|
||||||
minHeight: '100px',
|
|
||||||
overflow: 'auto'
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<el-tree
|
|
||||||
ref="treeRef"
|
|
||||||
show-checkbox
|
|
||||||
:data="authData"
|
|
||||||
node-key="menuId"
|
|
||||||
:default-expand-all="true"
|
|
||||||
:props="{ label: 'title' }"
|
|
||||||
:default-checked-keys="checkedKeys"
|
|
||||||
:style="{ '--ele-tree-item-height': '28px' }"
|
|
||||||
>
|
|
||||||
<template #default="scope">
|
|
||||||
<div>
|
|
||||||
<el-icon
|
|
||||||
v-if="scope.data.icon"
|
|
||||||
:size="16"
|
|
||||||
style="margin-right: 6px; vertical-align: -5px"
|
|
||||||
>
|
|
||||||
<component :is="scope.data.icon" />
|
|
||||||
</el-icon>
|
|
||||||
<span style="vertical-align: -2px">{{ scope.data.title }}</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-tree>
|
|
||||||
</ele-loading>
|
|
||||||
<template #footer>
|
|
||||||
<el-button @click="handleCancel">取消</el-button>
|
|
||||||
<el-button type="primary" :loading="loading" @click="save">
|
|
||||||
保存
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</ele-modal>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { ref, nextTick } from 'vue';
|
|
||||||
import type { ElTree } from 'element-plus';
|
|
||||||
import { EleMessage, toTree, eachTree } from 'ele-admin-plus';
|
|
||||||
import { listRoleMenus, updateRoleMenus } from '@/api/system/role';
|
|
||||||
import type { Role } from '@/api/system/role/model';
|
|
||||||
import type { Menu } from '@/api/system/menu/model';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
/** 当前角色数据 */
|
|
||||||
data?: Role | null;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
/** 弹窗是否打开 */
|
|
||||||
const visible = defineModel({ type: Boolean });
|
|
||||||
|
|
||||||
/** 树组件实例 */
|
|
||||||
const treeRef = ref<InstanceType<typeof ElTree> | null>(null);
|
|
||||||
|
|
||||||
/** 权限数据 */
|
|
||||||
const authData = ref<Menu[]>([]);
|
|
||||||
|
|
||||||
/** 权限数据请求状态 */
|
|
||||||
const authLoading = ref(false);
|
|
||||||
|
|
||||||
/** 提交状态 */
|
|
||||||
const loading = ref(false);
|
|
||||||
|
|
||||||
/** 角色权限选中的keys */
|
|
||||||
const checkedKeys = ref<number[]>([]);
|
|
||||||
|
|
||||||
/** 查询权限数据 */
|
|
||||||
const query = () => {
|
|
||||||
authData.value = [];
|
|
||||||
checkedKeys.value = [];
|
|
||||||
if (!props.data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
authLoading.value = true;
|
|
||||||
listRoleMenus(props.data.roleId)
|
|
||||||
.then((data) => {
|
|
||||||
authLoading.value = false;
|
|
||||||
// 转成树形结构的数据
|
|
||||||
authData.value = toTree({
|
|
||||||
data: data,
|
|
||||||
idField: 'menuId',
|
|
||||||
parentIdField: 'parentId'
|
|
||||||
});
|
|
||||||
// 回显选中的数据
|
|
||||||
nextTick(() => {
|
|
||||||
const cks: number[] = [];
|
|
||||||
eachTree(authData.value, (d) => {
|
|
||||||
if (d.menuId && d.checked && !d.children?.length) {
|
|
||||||
cks.push(d.menuId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
checkedKeys.value = cks;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
authLoading.value = false;
|
|
||||||
EleMessage.error({ message: e.message, plain: true });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 关闭弹窗 */
|
|
||||||
const handleCancel = () => {
|
|
||||||
visible.value = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 保存权限分配 */
|
|
||||||
const save = () => {
|
|
||||||
loading.value = true;
|
|
||||||
const ids =
|
|
||||||
(treeRef.value?.getCheckedKeys?.() ?? []).concat(
|
|
||||||
treeRef.value?.getHalfCheckedKeys?.() ?? []
|
|
||||||
) ?? [];
|
|
||||||
updateRoleMenus(props.data?.roleId, ids as unknown as number[])
|
|
||||||
.then((msg) => {
|
|
||||||
loading.value = false;
|
|
||||||
EleMessage.success({ message: msg, plain: true });
|
|
||||||
handleCancel();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
loading.value = false;
|
|
||||||
EleMessage.error({ message: e.message, plain: true });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 弹窗打开事件 */
|
|
||||||
const handleOpen = () => {
|
|
||||||
query();
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
@ -48,11 +48,13 @@
|
|||||||
<el-link type="primary" underline="never" @click="openEdit(row)">
|
<el-link type="primary" underline="never" @click="openEdit(row)">
|
||||||
修改
|
修改
|
||||||
</el-link>
|
</el-link>
|
||||||
|
<template v-if="row.group != 'system'">
|
||||||
<el-divider direction="vertical"/>
|
<el-divider direction="vertical"/>
|
||||||
<el-link type="danger" underline="never" @click="remove(row)">
|
<el-link type="danger" underline="never" @click="remove(row)">
|
||||||
删除
|
删除
|
||||||
</el-link>
|
</el-link>
|
||||||
</template>
|
</template>
|
||||||
|
</template>
|
||||||
<template #status="{ row }">
|
<template #status="{ row }">
|
||||||
<el-switch
|
<el-switch
|
||||||
size="small"
|
size="small"
|
||||||
@ -63,9 +65,7 @@
|
|||||||
</ele-pro-table>
|
</ele-pro-table>
|
||||||
</ele-card>
|
</ele-card>
|
||||||
<!-- 编辑弹窗 -->
|
<!-- 编辑弹窗 -->
|
||||||
<role-edit v-model="showEdit" :data="current" @done="reload" />
|
<config-edit v-model="showEdit" :data="current" @done="reload"/>
|
||||||
<!-- 权限分配弹窗 -->
|
|
||||||
<role-auth v-model="showAuth" :data="current" />
|
|
||||||
</ele-page>
|
</ele-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -80,16 +80,12 @@ import {onMounted, ref} from 'vue';
|
|||||||
} from 'ele-admin-plus/es/ele-pro-table/types';
|
} from 'ele-admin-plus/es/ele-pro-table/types';
|
||||||
import {PlusOutlined, DeleteOutlined} from '@/components/icons';
|
import {PlusOutlined, DeleteOutlined} from '@/components/icons';
|
||||||
import RoleSearch from './components/role-search.vue';
|
import RoleSearch from './components/role-search.vue';
|
||||||
import RoleEdit from './components/role-edit.vue';
|
import ConfigEdit from './components/config-edit.vue';
|
||||||
import RoleAuth from './components/role-auth.vue';
|
import type {Config, ConfigParam} from '@/api/system/config/model';
|
||||||
import { pageRoles, removeRoles, listRoles } from '@/api/system/role';
|
import {listConfig, updateConfigStatus, removeConfigs} from "@/api/system/config";
|
||||||
import type { Role, RoleParam } from '@/api/system/role/model';
|
|
||||||
import { listConfig } from "@/api/system/config";
|
|
||||||
import {getSysConfig} from "@/utils/sys-config";
|
import {getSysConfig} from "@/utils/sys-config";
|
||||||
import type {User} from "@/api/system/user/model";
|
|
||||||
import {updateUserStatus} from "@/api/system/user";
|
|
||||||
|
|
||||||
defineOptions({ name: 'SystemRole' });
|
defineOptions({name: 'SystemConfig'});
|
||||||
|
|
||||||
/** 表格实例 */
|
/** 表格实例 */
|
||||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||||
@ -145,16 +141,14 @@ import {updateUserStatus} from "@/api/system/user";
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
/** 表格选中数据 */
|
/** 表格选中数据 */
|
||||||
const selections = ref<Role[]>([]);
|
const selections = ref<Config[]>([]);
|
||||||
|
|
||||||
/** 当前编辑数据 */
|
/** 当前编辑数据 */
|
||||||
const current = ref<Role | null>(null);
|
const current = ref<Config | null>(null);
|
||||||
|
|
||||||
/** 是否显示编辑弹窗 */
|
/** 是否显示编辑弹窗 */
|
||||||
const showEdit = ref(false);
|
const showEdit = ref(false);
|
||||||
|
|
||||||
/** 是否显示权限分配弹窗 */
|
|
||||||
const showAuth = ref(false);
|
|
||||||
|
|
||||||
/** 表格数据源 */
|
/** 表格数据源 */
|
||||||
const datasource: DatasourceFunction = ({pages, where, orders}) => {
|
const datasource: DatasourceFunction = ({pages, where, orders}) => {
|
||||||
@ -162,25 +156,20 @@ import {updateUserStatus} from "@/api/system/user";
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** 搜索 */
|
/** 搜索 */
|
||||||
const reload = (where?: RoleParam) => {
|
const reload = (where?: ConfigParam) => {
|
||||||
selections.value = [];
|
selections.value = [];
|
||||||
tableRef.value?.reload?.({page: 1, where});
|
tableRef.value?.reload?.({page: 1, where});
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 打开编辑弹窗 */
|
/** 打开编辑弹窗 */
|
||||||
const openEdit = (row?: Role) => {
|
const openEdit = (row?: Config) => {
|
||||||
current.value = row ?? null;
|
current.value = row ?? null;
|
||||||
showEdit.value = true;
|
showEdit.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 打开权限分配弹窗 */
|
|
||||||
const openAuth = (row?: Role) => {
|
|
||||||
current.value = row ?? null;
|
|
||||||
showAuth.value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 删除单个 */
|
/** 删除单个 */
|
||||||
const remove = (row?: Role) => {
|
const remove = (row?: Config) => {
|
||||||
const rows = row == null ? selections.value : [row];
|
const rows = row == null ? selections.value : [row];
|
||||||
if (!rows.length) {
|
if (!rows.length) {
|
||||||
EleMessage.error({message: '请至少选择一条数据', plain: true});
|
EleMessage.error({message: '请至少选择一条数据', plain: true});
|
||||||
@ -196,7 +185,7 @@ import {updateUserStatus} from "@/api/system/user";
|
|||||||
message: '请求中..',
|
message: '请求中..',
|
||||||
plain: true
|
plain: true
|
||||||
});
|
});
|
||||||
removeRoles(rows.map((d) => d.roleId))
|
removeConfigs(rows.map((d) => d.roleId))
|
||||||
.then((msg) => {
|
.then((msg) => {
|
||||||
loading.close();
|
loading.close();
|
||||||
EleMessage.success({message: msg, plain: true});
|
EleMessage.success({message: msg, plain: true});
|
||||||
@ -207,17 +196,14 @@ import {updateUserStatus} from "@/api/system/user";
|
|||||||
EleMessage.error({message: e.message, plain: true});
|
EleMessage.error({message: e.message, plain: true});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 导出和打印全部数据的数据源 */
|
|
||||||
const exportSource: DatasourceFunction = ({ where, orders }) => {
|
|
||||||
return listRoles({ ...where, ...orders });
|
|
||||||
};
|
|
||||||
/** 修改配置状态 */
|
/** 修改配置状态 */
|
||||||
const editStatus = (checked: boolean, row: User) => {
|
const editStatus = (checked: boolean, row: Config) => {
|
||||||
const status = checked ? 1 : 0;
|
const status = checked ? 1 : 0;
|
||||||
updateUserStatus(row.id, status)
|
updateConfigStatus(row.id, status)
|
||||||
.then((msg) => {
|
.then((msg) => {
|
||||||
row.status = status;
|
row.status = status;
|
||||||
EleMessage.success({message: msg, plain: true});
|
EleMessage.success({message: msg, plain: true});
|
||||||
@ -232,7 +218,7 @@ import {updateUserStatus} from "@/api/system/user";
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 配置分组
|
// 配置分组
|
||||||
const group = [];
|
const group = [];
|
||||||
const { valueData } = await getSysConfig( "system.config_group");
|
const {valueData} = await getSysConfig("config_group");
|
||||||
for (const name in valueData) {
|
for (const name in valueData) {
|
||||||
group.push({name: name, label: valueData[name]})
|
group.push({name: name, label: valueData[name]})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user