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';
|
||||
|
||||
/**
|
||||
* 分页查询角色
|
||||
* 分页查询配置
|
||||
*/
|
||||
export async function configData(params: ConfigParam) {
|
||||
const res = await request.get<ApiResult<PageResult<Config>>>(
|
||||
@ -17,7 +17,7 @@ export async function configData(params: ConfigParam) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色列表
|
||||
* 查询配置列表
|
||||
*/
|
||||
export async function listConfig(params?: ConfigParam) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加配置
|
||||
*/
|
||||
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>
|
||||
<ele-modal
|
||||
form
|
||||
destroy-on-close
|
||||
:width="460"
|
||||
v-model="visible"
|
||||
:title="isUpdate ? '修改角色' : '添加角色'"
|
||||
:title="isUpdate ? '修改配置' : '添加配置'"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
@ -14,20 +14,45 @@
|
||||
label-width="80px"
|
||||
@submit.prevent=""
|
||||
>
|
||||
<el-form-item label="角色名称" prop="roleName">
|
||||
<el-form-item label="配置标题" prop="title">
|
||||
<el-input
|
||||
clearable
|
||||
:maxlength="20"
|
||||
v-model="form.roleName"
|
||||
placeholder="请输入角色名称"
|
||||
v-model="form.title"
|
||||
placeholder="请输入配置标题(一般由中文组成,仅用于显示)"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色标识" prop="roleCode">
|
||||
<el-form-item label="配置名称" prop="name">
|
||||
<el-input
|
||||
clearable
|
||||
:maxlength="20"
|
||||
v-model="form.roleCode"
|
||||
placeholder="请输入角色标识"
|
||||
v-model="form.name"
|
||||
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 label="备注">
|
||||
@ -53,12 +78,12 @@
|
||||
import type { FormInstance, FormRules } from 'element-plus';
|
||||
import { EleMessage } from 'ele-admin-plus';
|
||||
import { useFormData } from '@/utils/use-form-data';
|
||||
import { addRole, updateRole } from '@/api/system/role';
|
||||
import type { Role } from '@/api/system/role/model';
|
||||
import type { Config } from '@/api/system/config/model';
|
||||
import {addConfig, updateConfig} from "@/api/system/config";
|
||||
|
||||
const props = defineProps<{
|
||||
/** 修改回显的数据 */
|
||||
data?: Role | null;
|
||||
data?: Config | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@ -78,7 +103,7 @@
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
|
||||
/** 表单数据 */
|
||||
const [form, resetFields, assignFields] = useFormData<Role>({
|
||||
const [form, resetFields, assignFields] = useFormData<Config>({
|
||||
roleId: void 0,
|
||||
roleName: '',
|
||||
roleCode: '',
|
||||
@ -90,7 +115,7 @@
|
||||
roleName: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入角色名称',
|
||||
message: '请输入配置名称',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
@ -98,7 +123,7 @@
|
||||
roleCode: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入角色标识',
|
||||
message: '请输入配置标识',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
@ -117,7 +142,7 @@
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
const saveOrUpdate = isUpdate.value ? updateRole : addRole;
|
||||
const saveOrUpdate = isUpdate.value ? updateConfig : addConfig;
|
||||
saveOrUpdate(form)
|
||||
.then((msg) => {
|
||||
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>
|
||||
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<ele-page>
|
||||
<!-- 搜索表单 -->
|
||||
<role-search @search="reload" />
|
||||
<role-search @search="reload"/>
|
||||
|
||||
<ele-tabs
|
||||
type="card"
|
||||
@ -48,11 +48,13 @@
|
||||
<el-link type="primary" underline="never" @click="openEdit(row)">
|
||||
修改
|
||||
</el-link>
|
||||
<el-divider direction="vertical" />
|
||||
<template v-if="row.group != 'system'">
|
||||
<el-divider direction="vertical"/>
|
||||
<el-link type="danger" underline="never" @click="remove(row)">
|
||||
删除
|
||||
</el-link>
|
||||
</template>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<el-switch
|
||||
size="small"
|
||||
@ -63,39 +65,33 @@
|
||||
</ele-pro-table>
|
||||
</ele-card>
|
||||
<!-- 编辑弹窗 -->
|
||||
<role-edit v-model="showEdit" :data="current" @done="reload" />
|
||||
<!-- 权限分配弹窗 -->
|
||||
<role-auth v-model="showAuth" :data="current" />
|
||||
<config-edit v-model="showEdit" :data="current" @done="reload"/>
|
||||
</ele-page>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {onMounted, ref} from 'vue';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import { EleMessage } from 'ele-admin-plus';
|
||||
import type { EleProTable } from 'ele-admin-plus';
|
||||
import type {
|
||||
import {ElMessageBox} from 'element-plus';
|
||||
import {EleMessage} from 'ele-admin-plus';
|
||||
import type {EleProTable} from 'ele-admin-plus';
|
||||
import type {
|
||||
DatasourceFunction,
|
||||
Columns
|
||||
} from 'ele-admin-plus/es/ele-pro-table/types';
|
||||
import { PlusOutlined, DeleteOutlined } from '@/components/icons';
|
||||
import RoleSearch from './components/role-search.vue';
|
||||
import RoleEdit from './components/role-edit.vue';
|
||||
import RoleAuth from './components/role-auth.vue';
|
||||
import { pageRoles, removeRoles, listRoles } from '@/api/system/role';
|
||||
import type { Role, RoleParam } from '@/api/system/role/model';
|
||||
import { listConfig } from "@/api/system/config";
|
||||
} from 'ele-admin-plus/es/ele-pro-table/types';
|
||||
import {PlusOutlined, DeleteOutlined} from '@/components/icons';
|
||||
import RoleSearch from './components/role-search.vue';
|
||||
import ConfigEdit from './components/config-edit.vue';
|
||||
import type {Config, ConfigParam} from '@/api/system/config/model';
|
||||
import {listConfig, updateConfigStatus, removeConfigs} from "@/api/system/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);
|
||||
|
||||
/** 表格列配置 */
|
||||
const columns = ref<Columns>([
|
||||
/** 表格列配置 */
|
||||
const columns = ref<Columns>([
|
||||
{
|
||||
type: 'index',
|
||||
columnKey: 'index',
|
||||
@ -142,104 +138,94 @@ import {updateUserStatus} from "@/api/system/user";
|
||||
hideInPrint: true,
|
||||
hideInExport: true
|
||||
}
|
||||
]);
|
||||
]);
|
||||
|
||||
/** 表格选中数据 */
|
||||
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 }) => {
|
||||
return listConfig({ ...where, ...orders, ...pages, group: configGroup.value });
|
||||
};
|
||||
/** 表格数据源 */
|
||||
const datasource: DatasourceFunction = ({pages, where, orders}) => {
|
||||
return listConfig({...where, ...orders, ...pages, group: configGroup.value});
|
||||
};
|
||||
|
||||
/** 搜索 */
|
||||
const reload = (where?: RoleParam) => {
|
||||
/** 搜索 */
|
||||
const reload = (where?: ConfigParam) => {
|
||||
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;
|
||||
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];
|
||||
if (!rows.length) {
|
||||
EleMessage.error({ message: '请至少选择一条数据', plain: true });
|
||||
EleMessage.error({message: '请至少选择一条数据', plain: true});
|
||||
return;
|
||||
}
|
||||
ElMessageBox.confirm(
|
||||
'确定要删除“' + rows.map((d) => d.roleName).join(', ') + '”吗?',
|
||||
'系统提示',
|
||||
{ type: 'warning', draggable: true }
|
||||
{type: 'warning', draggable: true}
|
||||
)
|
||||
.then(() => {
|
||||
const loading = EleMessage.loading({
|
||||
message: '请求中..',
|
||||
plain: true
|
||||
});
|
||||
removeRoles(rows.map((d) => d.roleId))
|
||||
removeConfigs(rows.map((d) => d.roleId))
|
||||
.then((msg) => {
|
||||
loading.close();
|
||||
EleMessage.success({ message: msg, plain: true });
|
||||
EleMessage.success({message: msg, plain: true});
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.close();
|
||||
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;
|
||||
updateUserStatus(row.id, status)
|
||||
updateConfigStatus(row.id, status)
|
||||
.then((msg) => {
|
||||
row.status = status;
|
||||
EleMessage.success({ message: msg, plain: true });
|
||||
EleMessage.success({message: msg, plain: true});
|
||||
})
|
||||
.catch((e) => {
|
||||
EleMessage.error({ message: e.message, plain: true });
|
||||
EleMessage.error({message: e.message, plain: true});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const groupItems = ref([]);
|
||||
const configGroup = ref("");
|
||||
onMounted(async ()=>{
|
||||
const groupItems = ref([]);
|
||||
const configGroup = ref("");
|
||||
onMounted(async () => {
|
||||
// 配置分组
|
||||
const group = [];
|
||||
const { valueData } = await getSysConfig( "system.config_group");
|
||||
const {valueData} = await getSysConfig("config_group");
|
||||
for (const name in valueData) {
|
||||
group.push({ name: name, label: valueData[name] })
|
||||
group.push({name: name, label: valueData[name]})
|
||||
}
|
||||
groupItems.value = group
|
||||
if(group.length > 0){
|
||||
if (group.length > 0) {
|
||||
configGroup.value = group[0].name
|
||||
}
|
||||
reload();
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user