crud的提取
This commit is contained in:
@@ -95,6 +95,10 @@ const createCrudOptions = function (prop?: CrudOptions): CreateCrudOptionsTypes
|
|||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
labelWidth: '120px',
|
labelWidth: '120px',
|
||||||
|
wrapper: {
|
||||||
|
is: 'el-dialog',
|
||||||
|
width: '600px',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
columns: {
|
columns: {
|
||||||
_index: {
|
_index: {
|
||||||
@@ -116,8 +120,6 @@ const createCrudOptions = function (prop?: CrudOptions): CreateCrudOptionsTypes
|
|||||||
search: {
|
search: {
|
||||||
title: '关键词',
|
title: '关键词',
|
||||||
column: { show: false },
|
column: { show: false },
|
||||||
show: false,
|
|
||||||
disabled: true,
|
|
||||||
type: 'text',
|
type: 'text',
|
||||||
search: { show: true },
|
search: { show: true },
|
||||||
form: {
|
form: {
|
||||||
@@ -177,7 +179,11 @@ const createCrudOptions = function (prop?: CrudOptions): CreateCrudOptionsTypes
|
|||||||
search: { show: false },
|
search: { show: false },
|
||||||
form: {
|
form: {
|
||||||
col: { span: 24 },
|
col: { span: 24 },
|
||||||
helper: '请正确填写,以免请求时被拦截。匹配单例使用正则,例如:/api/xx/.*?/',
|
helper: {
|
||||||
|
render() {
|
||||||
|
return [`<div>请正确填写,以免请求时被拦截。匹配单例使用正则,例如:/api/xx/.*?/</div>`];
|
||||||
|
},
|
||||||
|
},
|
||||||
component: {
|
component: {
|
||||||
maxlength: 20,
|
maxlength: 20,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,240 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="system-add-role-container">
|
|
||||||
<el-dialog title="新增角色" v-model="isShowDialog" width="769px">
|
|
||||||
<el-form :model="ruleForm" size="default" label-width="90px">
|
|
||||||
<el-row :gutter="35">
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="角色名称">
|
|
||||||
<el-input v-model="ruleForm.roleName" placeholder="请输入角色名称" clearable></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="角色标识">
|
|
||||||
<template #label>
|
|
||||||
<el-tooltip effect="dark" content="用于 `router/route.ts` meta.roles" placement="top-start">
|
|
||||||
<span>角色标识</span>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
<el-input v-model="ruleForm.roleSign" placeholder="请输入角色标识" clearable></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="排序">
|
|
||||||
<el-input-number v-model="ruleForm.sort" :min="0" :max="999" controls-position="right" placeholder="请输入排序" class="w100" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="角色状态">
|
|
||||||
<el-switch v-model="ruleForm.status" inline-prompt active-text="启" inactive-text="禁"></el-switch>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
||||||
<el-form-item label="角色描述">
|
|
||||||
<el-input v-model="ruleForm.describe" type="textarea" placeholder="请输入角色描述" maxlength="150"></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
||||||
<el-form-item label="菜单权限">
|
|
||||||
<el-tree :data="menuData" :props="menuProps" show-checkbox class="menu-data-tree" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</el-form>
|
|
||||||
<template #footer>
|
|
||||||
<span class="dialog-footer">
|
|
||||||
<el-button @click="onCancel" size="default">取 消</el-button>
|
|
||||||
<el-button type="primary" @click="onSubmit" size="default">新 增</el-button>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { reactive, toRefs, defineComponent } from 'vue';
|
|
||||||
|
|
||||||
// 定义接口来定义对象的类型
|
|
||||||
interface MenuDataTree {
|
|
||||||
id: number;
|
|
||||||
label: string;
|
|
||||||
children?: MenuDataTree[];
|
|
||||||
}
|
|
||||||
interface RoleState {
|
|
||||||
isShowDialog: boolean;
|
|
||||||
ruleForm: {
|
|
||||||
roleName: string;
|
|
||||||
roleSign: string;
|
|
||||||
sort: number;
|
|
||||||
status: boolean;
|
|
||||||
describe: string;
|
|
||||||
};
|
|
||||||
menuData: Array<MenuDataTree>;
|
|
||||||
menuProps: {
|
|
||||||
children: string;
|
|
||||||
label: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'systemAddRole',
|
|
||||||
setup() {
|
|
||||||
const state = reactive<RoleState>({
|
|
||||||
isShowDialog: false,
|
|
||||||
ruleForm: {
|
|
||||||
roleName: '', // 角色名称
|
|
||||||
roleSign: '', // 角色标识
|
|
||||||
sort: 0, // 排序
|
|
||||||
status: true, // 角色状态
|
|
||||||
describe: '', // 角色描述
|
|
||||||
},
|
|
||||||
menuData: [],
|
|
||||||
menuProps: {
|
|
||||||
children: 'children',
|
|
||||||
label: 'label',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// 打开弹窗
|
|
||||||
const openDialog = () => {
|
|
||||||
state.isShowDialog = true;
|
|
||||||
getMenuData();
|
|
||||||
};
|
|
||||||
// 关闭弹窗
|
|
||||||
const closeDialog = () => {
|
|
||||||
state.isShowDialog = false;
|
|
||||||
};
|
|
||||||
// 取消
|
|
||||||
const onCancel = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 新增
|
|
||||||
const onSubmit = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 获取菜单结构数据
|
|
||||||
const getMenuData = () => {
|
|
||||||
state.menuData = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
label: '系统管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 11,
|
|
||||||
label: '菜单管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 111,
|
|
||||||
label: '菜单新增',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 112,
|
|
||||||
label: '菜单修改',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 113,
|
|
||||||
label: '菜单删除',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 114,
|
|
||||||
label: '菜单查询',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 12,
|
|
||||||
label: '角色管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 121,
|
|
||||||
label: '角色新增',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 122,
|
|
||||||
label: '角色修改',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 123,
|
|
||||||
label: '角色删除',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 124,
|
|
||||||
label: '角色查询',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 13,
|
|
||||||
label: '用户管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 131,
|
|
||||||
label: '用户新增',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 132,
|
|
||||||
label: '用户修改',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 133,
|
|
||||||
label: '用户删除',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 134,
|
|
||||||
label: '用户查询',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
label: '权限管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 21,
|
|
||||||
label: '前端控制',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 211,
|
|
||||||
label: '页面权限',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 212,
|
|
||||||
label: '页面权限',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 22,
|
|
||||||
label: '后端控制',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 221,
|
|
||||||
label: '页面权限',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
openDialog,
|
|
||||||
closeDialog,
|
|
||||||
onCancel,
|
|
||||||
onSubmit,
|
|
||||||
...toRefs(state),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.system-add-role-container {
|
|
||||||
.menu-data-tree {
|
|
||||||
width: 100%;
|
|
||||||
border: 1px solid var(--el-border-color);
|
|
||||||
border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
|
|
||||||
padding: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,242 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="system-edit-role-container">
|
|
||||||
<el-dialog title="修改角色" v-model="isShowDialog" width="769px">
|
|
||||||
<el-form :model="ruleForm" size="default" label-width="90px">
|
|
||||||
<el-row :gutter="35">
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="角色名称">
|
|
||||||
<el-input v-model="ruleForm.roleName" placeholder="请输入角色名称" clearable></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="角色标识">
|
|
||||||
<template #label>
|
|
||||||
<el-tooltip effect="dark" content="用于 `router/route.ts` meta.roles" placement="top-start">
|
|
||||||
<span>角色标识</span>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
<el-input v-model="ruleForm.roleSign" placeholder="请输入角色标识" clearable></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="排序">
|
|
||||||
<el-input-number v-model="ruleForm.sort" :min="0" :max="999" controls-position="right" placeholder="请输入排序" class="w100" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
||||||
<el-form-item label="角色状态">
|
|
||||||
<el-switch v-model="ruleForm.status" inline-prompt active-text="启" inactive-text="禁"></el-switch>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
||||||
<el-form-item label="角色描述">
|
|
||||||
<el-input v-model="ruleForm.describe" type="textarea" placeholder="请输入角色描述" maxlength="150"></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
||||||
<el-form-item label="菜单权限">
|
|
||||||
<el-tree :data="menuData" :props="menuProps" :default-checked-keys="[112, 113]" node-key="id" show-checkbox class="menu-data-tree" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</el-form>
|
|
||||||
<template #footer>
|
|
||||||
<span class="dialog-footer">
|
|
||||||
<el-button @click="onCancel" size="default">取 消</el-button>
|
|
||||||
<el-button type="primary" @click="onSubmit" size="default">修 改</el-button>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { reactive, toRefs, defineComponent } from 'vue';
|
|
||||||
|
|
||||||
// 定义接口来定义对象的类型
|
|
||||||
interface MenuDataTree {
|
|
||||||
id: number;
|
|
||||||
label: string;
|
|
||||||
children?: MenuDataTree[];
|
|
||||||
}
|
|
||||||
interface DialogRow {
|
|
||||||
roleName: string;
|
|
||||||
roleSign: string;
|
|
||||||
sort: number;
|
|
||||||
status: boolean;
|
|
||||||
describe: string;
|
|
||||||
}
|
|
||||||
interface RoleState {
|
|
||||||
isShowDialog: boolean;
|
|
||||||
ruleForm: DialogRow;
|
|
||||||
menuData: Array<MenuDataTree>;
|
|
||||||
menuProps: {
|
|
||||||
children: string;
|
|
||||||
label: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'systemEditRole',
|
|
||||||
setup() {
|
|
||||||
const state = reactive<RoleState>({
|
|
||||||
isShowDialog: false,
|
|
||||||
ruleForm: {
|
|
||||||
roleName: '', // 角色名称
|
|
||||||
roleSign: '', // 角色标识
|
|
||||||
sort: 0, // 排序
|
|
||||||
status: true, // 角色状态
|
|
||||||
describe: '', // 角色描述
|
|
||||||
},
|
|
||||||
menuData: [],
|
|
||||||
menuProps: {
|
|
||||||
children: 'children',
|
|
||||||
label: 'label',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// 打开弹窗
|
|
||||||
const openDialog = (row: DialogRow) => {
|
|
||||||
state.ruleForm = row;
|
|
||||||
state.isShowDialog = true;
|
|
||||||
getMenuData();
|
|
||||||
};
|
|
||||||
// 关闭弹窗
|
|
||||||
const closeDialog = () => {
|
|
||||||
state.isShowDialog = false;
|
|
||||||
};
|
|
||||||
// 取消
|
|
||||||
const onCancel = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 新增
|
|
||||||
const onSubmit = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 获取菜单结构数据
|
|
||||||
const getMenuData = () => {
|
|
||||||
state.menuData = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
label: '系统管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 11,
|
|
||||||
label: '菜单管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 111,
|
|
||||||
label: '菜单新增',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 112,
|
|
||||||
label: '菜单修改',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 113,
|
|
||||||
label: '菜单删除',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 114,
|
|
||||||
label: '菜单查询',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 12,
|
|
||||||
label: '角色管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 121,
|
|
||||||
label: '角色新增',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 122,
|
|
||||||
label: '角色修改',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 123,
|
|
||||||
label: '角色删除',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 124,
|
|
||||||
label: '角色查询',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 13,
|
|
||||||
label: '用户管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 131,
|
|
||||||
label: '用户新增',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 132,
|
|
||||||
label: '用户修改',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 133,
|
|
||||||
label: '用户删除',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 134,
|
|
||||||
label: '用户查询',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
label: '权限管理',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 21,
|
|
||||||
label: '前端控制',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 211,
|
|
||||||
label: '页面权限',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 212,
|
|
||||||
label: '页面权限',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 22,
|
|
||||||
label: '后端控制',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 221,
|
|
||||||
label: '页面权限',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
openDialog,
|
|
||||||
closeDialog,
|
|
||||||
onCancel,
|
|
||||||
onSubmit,
|
|
||||||
...toRefs(state),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.system-edit-role-container {
|
|
||||||
.menu-data-tree {
|
|
||||||
width: 100%;
|
|
||||||
border: 1px solid var(--el-border-color);
|
|
||||||
border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
|
|
||||||
padding: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
259
web/src/views/system/role/curd.tsx
Normal file
259
web/src/views/system/role/curd.tsx
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
import {CrudOptions, AddReq, DelReq, EditReq, dict } from '@fast-crud/fast-crud';
|
||||||
|
import _ from 'lodash-es';
|
||||||
|
|
||||||
|
interface CreateCrudOptionsTypes {
|
||||||
|
crudOptions: CrudOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
//此处为crudOptions配置
|
||||||
|
export const createCrudOptions = function (prop?: CrudOptions): CreateCrudOptionsTypes {
|
||||||
|
//本地模拟后台crud接口方法 ----开始
|
||||||
|
const records = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
modifier_name: '超级管理员',
|
||||||
|
creator_name: '超级管理员',
|
||||||
|
create_datetime: '2022-04-08 11:02:22',
|
||||||
|
update_datetime: '2022-05-31 02:09:00',
|
||||||
|
description: null,
|
||||||
|
modifier: '1',
|
||||||
|
dept_belong_id: '1',
|
||||||
|
name: '管理员',
|
||||||
|
key: 'admin',
|
||||||
|
sort: 1,
|
||||||
|
status: true,
|
||||||
|
admin: true,
|
||||||
|
data_range: 3,
|
||||||
|
remark: null,
|
||||||
|
creator: 1,
|
||||||
|
dept: [],
|
||||||
|
menu: [1, 2, 10, 20, 7, 8, 11, 16, 17, 5, 13, 15, 4, 18, 19, 3, 9],
|
||||||
|
permission: [
|
||||||
|
53, 4, 8, 13, 18, 32, 37, 42, 45, 49, 55, 2, 6, 11, 16, 21, 26, 30, 35, 40, 52, 1, 7, 12, 17, 22, 27, 31, 36, 41, 46, 50, 54, 3, 9, 14, 19,
|
||||||
|
23, 25, 33, 38, 43, 47, 48, 5, 10, 15, 20, 24, 28, 34, 39, 44, 51, 29,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const pageRequest = async (query: any) => {
|
||||||
|
return {
|
||||||
|
records,
|
||||||
|
currentPage: 1,
|
||||||
|
pageSize: 20,
|
||||||
|
total: records.length,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const editRequest = async (req: EditReq) => {
|
||||||
|
const target = _.find(records, (item) => {
|
||||||
|
return req.row.id === item.id;
|
||||||
|
});
|
||||||
|
_.merge(target, req.form);
|
||||||
|
return target;
|
||||||
|
};
|
||||||
|
const delRequest = async (req: DelReq) => {
|
||||||
|
_.remove(records, (item) => {
|
||||||
|
return item.id === req.row.id;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const addRequest = async (req: AddReq) => {
|
||||||
|
const maxRecord = _.maxBy(records, (item) => {
|
||||||
|
return item.id;
|
||||||
|
});
|
||||||
|
req.form.id = (maxRecord?.id || 0) + 1;
|
||||||
|
records.push(req.form);
|
||||||
|
return req.form;
|
||||||
|
};
|
||||||
|
//本地模拟后台crud接口方法 ----结束
|
||||||
|
return {
|
||||||
|
crudOptions: {
|
||||||
|
request: {
|
||||||
|
pageRequest,
|
||||||
|
addRequest,
|
||||||
|
editRequest,
|
||||||
|
delRequest,
|
||||||
|
},
|
||||||
|
rowHandle: {
|
||||||
|
buttons: {},
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
col: { span: 24 },
|
||||||
|
labelWidth: '100px',
|
||||||
|
wrapper: {
|
||||||
|
is: 'el-dialog',
|
||||||
|
width: '600px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
columns: {
|
||||||
|
_index: {
|
||||||
|
title: '序号',
|
||||||
|
form: { show: false },
|
||||||
|
column: {
|
||||||
|
//type: 'index',
|
||||||
|
align: 'center',
|
||||||
|
width: '70px',
|
||||||
|
columnSetDisabled: true, //禁止在列设置中选择
|
||||||
|
formatter: (context) => {
|
||||||
|
//计算序号,你可以自定义计算规则,此处为翻页累加
|
||||||
|
let index = context.index ?? 1;
|
||||||
|
let pagination = crudExpose.crudBinding.value.pagination;
|
||||||
|
return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
title: '关键词',
|
||||||
|
column: { show: false },
|
||||||
|
type: 'text',
|
||||||
|
search: { show: true },
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
component: {
|
||||||
|
placeholder: '输入关键词搜索',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id: {
|
||||||
|
title: 'ID',
|
||||||
|
type: 'text',
|
||||||
|
column: { show: false },
|
||||||
|
search: { show: false },
|
||||||
|
form: { show: false },
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
title: '角色名称',
|
||||||
|
type: 'text',
|
||||||
|
search: { show: true },
|
||||||
|
column: {
|
||||||
|
minWidth: 120,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
rules: [{ required: true, message: '角色名称必填' }],
|
||||||
|
component: {
|
||||||
|
placeholder: '输入角色名称搜索',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
key: {
|
||||||
|
title: '权限标识',
|
||||||
|
type: 'text',
|
||||||
|
search: { show: false },
|
||||||
|
column: {
|
||||||
|
width: 120,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
rules: [{ required: true, message: '权限标识必填' }],
|
||||||
|
placeholder: '输入权限标识',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
title: '排序',
|
||||||
|
search: { show: false },
|
||||||
|
type: 'number',
|
||||||
|
column: {
|
||||||
|
width: 90,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
title: '是否管理员',
|
||||||
|
search: { show: false },
|
||||||
|
type: 'dict-radio',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
label: '是',
|
||||||
|
value: true,
|
||||||
|
color: 'success',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '否',
|
||||||
|
value: false,
|
||||||
|
color: 'danger',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
column: {
|
||||||
|
width: 130,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
title: '状态',
|
||||||
|
search: { show: true },
|
||||||
|
type: 'dict-radio',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
label: '启用',
|
||||||
|
value: true,
|
||||||
|
color: 'success',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '禁用',
|
||||||
|
value: false,
|
||||||
|
color: 'danger',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
column: {
|
||||||
|
width: 90,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update_datetime: {
|
||||||
|
title: '更新时间',
|
||||||
|
type: 'text',
|
||||||
|
search: { show: false },
|
||||||
|
column: {
|
||||||
|
width: 170,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
component: {
|
||||||
|
placeholder: '输入关键词搜索',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create_datetime: {
|
||||||
|
title: '创建时间',
|
||||||
|
type: 'text',
|
||||||
|
search: { show: false },
|
||||||
|
column: {
|
||||||
|
sortable: true,
|
||||||
|
width: 170,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
component: {
|
||||||
|
placeholder: '输入关键词搜索',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
description: {
|
||||||
|
title: '备注',
|
||||||
|
type: 'textarea',
|
||||||
|
search: { show: false },
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
maxlength: 200,
|
||||||
|
placeholder: '输入备注',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,164 +1,291 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="system-role-container">
|
<fs-page>
|
||||||
<el-card shadow="hover">
|
<fs-crud ref="crudRef" v-bind="crudBinding">
|
||||||
<div class="system-user-search mb15">
|
<template #cell_url="scope">
|
||||||
<el-input size="default" placeholder="请输入角色名称" style="max-width: 180px"> </el-input>
|
<el-tag size="small">{{ scope.row.url }}</el-tag>
|
||||||
<el-button size="default" type="primary" class="ml10">
|
</template>
|
||||||
<el-icon>
|
</fs-crud>
|
||||||
<ele-Search />
|
</fs-page>
|
||||||
</el-icon>
|
|
||||||
查询
|
|
||||||
</el-button>
|
|
||||||
<el-button size="default" type="success" class="ml10" @click="onOpenAddRole">
|
|
||||||
<el-icon>
|
|
||||||
<ele-FolderAdd />
|
|
||||||
</el-icon>
|
|
||||||
新增角色
|
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
<el-table :data="tableData.data" style="width: 100%">
|
|
||||||
<el-table-column type="index" label="序号" width="60" />
|
|
||||||
<el-table-column prop="roleName" label="角色名称" show-overflow-tooltip></el-table-column>
|
|
||||||
<el-table-column prop="roleSign" label="角色标识" show-overflow-tooltip></el-table-column>
|
|
||||||
<el-table-column prop="sort" label="排序" show-overflow-tooltip></el-table-column>
|
|
||||||
<el-table-column prop="status" label="角色状态" show-overflow-tooltip>
|
|
||||||
<template #default="scope">
|
|
||||||
<el-tag type="success" v-if="scope.row.status">启用</el-tag>
|
|
||||||
<el-tag type="info" v-else>禁用</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column prop="describe" label="角色描述" show-overflow-tooltip></el-table-column>
|
|
||||||
<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip></el-table-column>
|
|
||||||
<el-table-column label="操作" width="100">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-button :disabled="scope.row.roleName === '超级管理员'" size="small" text type="primary" @click="onOpenEditRole(scope.row)"
|
|
||||||
>修改</el-button
|
|
||||||
>
|
|
||||||
<el-button :disabled="scope.row.roleName === '超级管理员'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
<el-pagination
|
|
||||||
@size-change="onHandleSizeChange"
|
|
||||||
@current-change="onHandleCurrentChange"
|
|
||||||
class="mt15"
|
|
||||||
:pager-count="5"
|
|
||||||
:page-sizes="[10, 20, 30]"
|
|
||||||
v-model:current-page="tableData.param.pageNum"
|
|
||||||
background
|
|
||||||
v-model:page-size="tableData.param.pageSize"
|
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
|
||||||
:total="tableData.total"
|
|
||||||
>
|
|
||||||
</el-pagination>
|
|
||||||
</el-card>
|
|
||||||
<AddRole ref="addRoleRef" />
|
|
||||||
<EditRole ref="editRoleRef" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { ElMessageBox, ElMessage } from 'element-plus';
|
import { useExpose, useCrud, CrudOptions, AddReq, DelReq, EditReq, dict } from '@fast-crud/fast-crud';
|
||||||
import AddRole from '/@/views/system/role/component/addRole.vue';
|
import _ from 'lodash-es';
|
||||||
import EditRole from '/@/views/system/role/component/editRole.vue';
|
import { createCrudOptions } from './curd';
|
||||||
|
|
||||||
// 定义接口来定义对象的类型
|
/* interface CreateCrudOptionsTypes {
|
||||||
interface TableData {
|
crudOptions: CrudOptions;
|
||||||
roleName: string;
|
|
||||||
roleSign: string;
|
|
||||||
describe: string;
|
|
||||||
sort: number;
|
|
||||||
status: boolean;
|
|
||||||
createTime: string;
|
|
||||||
}
|
}
|
||||||
interface TableDataState {
|
|
||||||
tableData: {
|
//此处为crudOptions配置
|
||||||
data: Array<TableData>;
|
const createCrudOptions = function (prop?: CrudOptions): CreateCrudOptionsTypes {
|
||||||
total: number;
|
//本地模拟后台crud接口方法 ----开始
|
||||||
loading: boolean;
|
const records = [
|
||||||
param: {
|
{
|
||||||
pageNum: number;
|
id: 1,
|
||||||
pageSize: number;
|
modifier_name: '超级管理员',
|
||||||
|
creator_name: '超级管理员',
|
||||||
|
create_datetime: '2022-04-08 11:02:22',
|
||||||
|
update_datetime: '2022-05-31 02:09:00',
|
||||||
|
description: null,
|
||||||
|
modifier: '1',
|
||||||
|
dept_belong_id: '1',
|
||||||
|
name: '管理员',
|
||||||
|
key: 'admin',
|
||||||
|
sort: 1,
|
||||||
|
status: true,
|
||||||
|
admin: true,
|
||||||
|
data_range: 3,
|
||||||
|
remark: null,
|
||||||
|
creator: 1,
|
||||||
|
dept: [],
|
||||||
|
menu: [1, 2, 10, 20, 7, 8, 11, 16, 17, 5, 13, 15, 4, 18, 19, 3, 9],
|
||||||
|
permission: [
|
||||||
|
53, 4, 8, 13, 18, 32, 37, 42, 45, 49, 55, 2, 6, 11, 16, 21, 26, 30, 35, 40, 52, 1, 7, 12, 17, 22, 27, 31, 36, 41, 46, 50, 54, 3, 9, 14, 19,
|
||||||
|
23, 25, 33, 38, 43, 47, 48, 5, 10, 15, 20, 24, 28, 34, 39, 44, 51, 29,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const pageRequest = async (query: any) => {
|
||||||
|
return {
|
||||||
|
records,
|
||||||
|
currentPage: 1,
|
||||||
|
pageSize: 20,
|
||||||
|
total: records.length,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
const editRequest = async (req: EditReq) => {
|
||||||
|
const target = _.find(records, (item) => {
|
||||||
|
return req.row.id === item.id;
|
||||||
|
});
|
||||||
|
_.merge(target, req.form);
|
||||||
|
return target;
|
||||||
|
};
|
||||||
|
const delRequest = async (req: DelReq) => {
|
||||||
|
_.remove(records, (item) => {
|
||||||
|
return item.id === req.row.id;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default defineComponent({
|
const addRequest = async (req: AddReq) => {
|
||||||
name: 'systemRole',
|
const maxRecord = _.maxBy(records, (item) => {
|
||||||
components: { AddRole, EditRole },
|
return item.id;
|
||||||
setup() {
|
});
|
||||||
const addRoleRef = ref();
|
req.form.id = (maxRecord?.id || 0) + 1;
|
||||||
const editRoleRef = ref();
|
records.push(req.form);
|
||||||
const state = reactive<TableDataState>({
|
return req.form;
|
||||||
tableData: {
|
};
|
||||||
data: [],
|
//本地模拟后台crud接口方法 ----结束
|
||||||
total: 0,
|
return {
|
||||||
loading: false,
|
crudOptions: {
|
||||||
param: {
|
request: {
|
||||||
pageNum: 1,
|
pageRequest,
|
||||||
pageSize: 10,
|
addRequest,
|
||||||
|
editRequest,
|
||||||
|
delRequest,
|
||||||
|
},
|
||||||
|
rowHandle: {
|
||||||
|
buttons: {},
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
col: { span: 24 },
|
||||||
|
labelWidth: '100px',
|
||||||
|
wrapper: {
|
||||||
|
is: 'el-dialog',
|
||||||
|
width: '600px',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
columns: {
|
||||||
// 初始化表格数据
|
_index: {
|
||||||
const initTableData = () => {
|
title: '序号',
|
||||||
const data: Array<TableData> = [];
|
form: { show: false },
|
||||||
for (let i = 0; i < 2; i++) {
|
column: {
|
||||||
data.push({
|
//type: 'index',
|
||||||
roleName: i === 0 ? '超级管理员' : '普通用户',
|
align: 'center',
|
||||||
roleSign: i === 0 ? 'admin' : 'common',
|
width: '70px',
|
||||||
describe: `测试角色${i + 1}`,
|
columnSetDisabled: true, //禁止在列设置中选择
|
||||||
sort: i,
|
formatter: (context) => {
|
||||||
status: true,
|
//计算序号,你可以自定义计算规则,此处为翻页累加
|
||||||
createTime: new Date().toLocaleString(),
|
let index = context.index ?? 1;
|
||||||
});
|
let pagination = crudExpose.crudBinding.value.pagination;
|
||||||
}
|
return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
|
||||||
state.tableData.data = data;
|
},
|
||||||
state.tableData.total = state.tableData.data.length;
|
},
|
||||||
};
|
},
|
||||||
// 打开新增角色弹窗
|
search: {
|
||||||
const onOpenAddRole = () => {
|
title: '关键词',
|
||||||
addRoleRef.value.openDialog();
|
column: { show: false },
|
||||||
};
|
type: 'text',
|
||||||
// 打开修改角色弹窗
|
search: { show: true },
|
||||||
const onOpenEditRole = (row: Object) => {
|
form: {
|
||||||
editRoleRef.value.openDialog(row);
|
show: false,
|
||||||
};
|
component: {
|
||||||
// 删除角色
|
placeholder: '输入关键词搜索',
|
||||||
const onRowDel = (row: any) => {
|
},
|
||||||
ElMessageBox.confirm(`此操作将永久删除角色名称:“${row.roleName}”,是否继续?`, '提示', {
|
},
|
||||||
confirmButtonText: '确认',
|
},
|
||||||
cancelButtonText: '取消',
|
id: {
|
||||||
type: 'warning',
|
title: 'ID',
|
||||||
})
|
type: 'text',
|
||||||
.then(() => {
|
column: { show: false },
|
||||||
ElMessage.success('删除成功');
|
search: { show: false },
|
||||||
})
|
form: { show: false },
|
||||||
.catch(() => {});
|
},
|
||||||
};
|
name: {
|
||||||
// 分页改变
|
title: '角色名称',
|
||||||
const onHandleSizeChange = (val: number) => {
|
type: 'text',
|
||||||
state.tableData.param.pageSize = val;
|
search: { show: true },
|
||||||
};
|
column: {
|
||||||
// 分页改变
|
minWidth: 120,
|
||||||
const onHandleCurrentChange = (val: number) => {
|
sortable: true,
|
||||||
state.tableData.param.pageNum = val;
|
},
|
||||||
};
|
form: {
|
||||||
// 页面加载时
|
rules: [{ required: true, message: '角色名称必填' }],
|
||||||
onMounted(() => {
|
component: {
|
||||||
initTableData();
|
placeholder: '输入角色名称搜索',
|
||||||
});
|
},
|
||||||
return {
|
},
|
||||||
addRoleRef,
|
},
|
||||||
editRoleRef,
|
key: {
|
||||||
onOpenAddRole,
|
title: '权限标识',
|
||||||
onOpenEditRole,
|
type: 'text',
|
||||||
onRowDel,
|
search: { show: false },
|
||||||
onHandleSizeChange,
|
column: {
|
||||||
onHandleCurrentChange,
|
width: 120,
|
||||||
...toRefs(state),
|
sortable: true,
|
||||||
};
|
},
|
||||||
},
|
form: {
|
||||||
|
rules: [{ required: true, message: '权限标识必填' }],
|
||||||
|
placeholder: '输入权限标识',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
title: '排序',
|
||||||
|
search: { show: false },
|
||||||
|
type: 'number',
|
||||||
|
column: {
|
||||||
|
width: 90,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
title: '是否管理员',
|
||||||
|
search: { show: false },
|
||||||
|
type: 'dict-radio',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
label: '是',
|
||||||
|
value: true,
|
||||||
|
color: 'success',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '否',
|
||||||
|
value: false,
|
||||||
|
color: 'danger',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
column: {
|
||||||
|
width: 130,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
title: '状态',
|
||||||
|
search: { show: true },
|
||||||
|
type: 'dict-radio',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
label: '启用',
|
||||||
|
value: true,
|
||||||
|
color: 'success',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '禁用',
|
||||||
|
value: false,
|
||||||
|
color: 'danger',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
column: {
|
||||||
|
width: 90,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update_datetime: {
|
||||||
|
title: '更新时间',
|
||||||
|
type: 'text',
|
||||||
|
search: { show: false },
|
||||||
|
column: {
|
||||||
|
width: 170,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
component: {
|
||||||
|
placeholder: '输入关键词搜索',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create_datetime: {
|
||||||
|
title: '创建时间',
|
||||||
|
type: 'text',
|
||||||
|
search: { show: false },
|
||||||
|
column: {
|
||||||
|
sortable: true,
|
||||||
|
width: 170,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
component: {
|
||||||
|
placeholder: '输入关键词搜索',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
description: {
|
||||||
|
title: '备注',
|
||||||
|
type: 'textarea',
|
||||||
|
search: { show: false },
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
maxlength: 200,
|
||||||
|
placeholder: '输入备注',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}; */
|
||||||
|
|
||||||
|
// crud组件的ref
|
||||||
|
const crudRef = ref();
|
||||||
|
// crud 配置的ref
|
||||||
|
const crudBinding = ref();
|
||||||
|
// 暴露的方法
|
||||||
|
const { crudExpose } = useExpose({ crudRef, crudBinding });
|
||||||
|
// 你的crud配置
|
||||||
|
const { crudOptions } = createCrudOptions({ crudExpose });
|
||||||
|
// 初始化crud配置
|
||||||
|
const { resetCrudOptions } = useCrud({ crudExpose, crudOptions });
|
||||||
|
// 你可以调用此方法,重新初始化crud配置
|
||||||
|
// resetCrudOptions(options)
|
||||||
|
|
||||||
|
// 页面打开后获取列表数据
|
||||||
|
onMounted(() => {
|
||||||
|
crudExpose.doRefresh();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user