Commit 7954c91a authored by “yiyousong”'s avatar “yiyousong”

perf: 优化用户管理

parent d0e1b86a
<template>
<div class="system flex flexc">
<a-tabs :activeKey="activeKey" @change="changeRouter">
<!-- <a-tab-pane key="/system/user">
<a-tab-pane key="/system/user">
<span slot="tab">
<a-icon type="user" />
用户管理
......@@ -24,7 +24,7 @@
<a-icon type="deployment-unit" />
维度管理
</span>
</a-tab-pane> -->
</a-tab-pane>
<a-tab-pane key="/system/parameter">
<span slot="tab">
<a-icon type="container" />
......
......@@ -108,6 +108,10 @@ export default {
return this.dict.dimensionType[text];
},
},
{
title: "维度值",
dataIndex: "dimensionValue",
},
{
title: "创建时间",
dataIndex: "createTime",
......
......@@ -43,6 +43,12 @@
>
</a-select>
</a-form-model-item>
<a-form-model-item label="维度值" prop="dimensionValue">
<a-input
v-model="form.dimensionValue"
placeholder="请输入维度值"
></a-input>
</a-form-model-item>
</a-form-model>
</a-modal>
</div>
......@@ -85,6 +91,9 @@ export default {
dimensionCode: [
{ required: true, message: "请输入维度编码", trigger: "blur" },
],
dimensionValue: [
{ required: true, message: "请输入维度值", trigger: "blur" },
],
dimensionType: [
{ required: true, message: "请选择维度类型", trigger: "change" },
],
......
......@@ -54,7 +54,7 @@
>分配资源</span
>
<span class="primary pointer" @click="handleResDim(text)"
>资源维度</span
>资源规则</span
>
<span class="primary pointer" @click="handleEdit(text)">编辑</span>
<span class="delete pointer" @click="handleDel(text.id)">删除</span>
......@@ -71,7 +71,7 @@
></AddRole>
<!-- 分配资源 -->
<ApportionRes ref="ApportionRes" :visible.sync="resVisible"></ApportionRes>
<!-- 角色维度 -->
<!-- 资源规则 -->
<ResDimList ref="ResDimList" :visible.sync="resDimListVisible"></ResDimList>
</div>
</template>
......
......@@ -5,15 +5,8 @@
:visible="Visible"
@cancel="handleCancel"
:maskClosable="false"
:zIndex="1001"
>
<a-button slot="footer" @click="handleReset">重置</a-button>
<a-button
slot="footer"
type="primary"
:loading="loading"
@click="handleOk"
>确定</a-button
>
<a-form-model
:model="form"
ref="form"
......@@ -21,22 +14,65 @@
:label-col="{ span: 5 }"
:wrapper-col="{ span: 19 }"
>
<a-form-model-item label="名称" prop="name">
<a-input v-model="form.name" placeholder="请输入角色名称"></a-input>
<a-form-model-item label="所属资源" prop="resourceId">
<a-cascader
:options="resourceList"
v-model="resource"
placeholder="请选择资源"
@change="changeRes"
/>
</a-form-model-item>
<a-form-model-item label="所属维度" prop="ruleCode">
<a-select
allowClear
v-model="form.ruleCode"
@change="changeDim"
placeholder="请选择所属维度"
>
<a-select-option
v-for="v in dimensionList"
:key="v.id"
:value="v.dimensionCode"
:dataset-row="v"
>
{{ v.dimensionName }}
</a-select-option>
</a-select>
</a-form-model-item>
<a-form-model-item label="备注" prop="remark">
<a-textarea
v-model="form.remark"
placeholder="请输入备注"
></a-textarea>
<a-form-model-item label="规则条件" prop="ruleCondition">
<a-select
allowClear
v-model="form.ruleCondition"
placeholder="请选择规则条件"
>
<a-select-option
v-for="(v, key) in dict.ruleCondition"
:key="key"
:value="key"
>
{{ v }}
</a-select-option>
</a-select>
</a-form-model-item>
</a-form-model>
<a-button slot="footer" @click="handleReset">重置</a-button>
<a-button
slot="footer"
type="primary"
:loading="loading"
@click="handleOk"
>确定</a-button
>
</a-modal>
</div>
</template>
<script>
import { saveRole } from "@/services/system";
import {
getDimensionList,
getResourceList,
saveDimRes,
} from "@/services/system";
export default {
components: {},
......@@ -60,9 +96,30 @@ export default {
data() {
return {
loading: false,
form: {},
resource: [],
dimensionList: [], // 维度列表
resourceList: [], // 资源列表
form: {
roleId: "", // 角色id
resourceId: "", // 资源id
ruleCode: undefined, // 维度编码
ruleName: "", // 维度名称
ruleCondition: undefined, // 规则条件
ruleValue: "", // 维度值
ruleType: "", // 维度类型
roleName: "", // 角色名称
resourceName: "", // 资源名称
},
rules: {
name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
resourceId: [
{ required: true, message: "请选择资源", trigger: "change" },
],
ruleCode: [
{ required: true, message: "请选择维度", trigger: "change" },
],
ruleCondition: [
{ required: true, message: "请选择规则条件", trigger: "change" },
],
},
};
},
......@@ -76,17 +133,106 @@ export default {
},
},
},
created() {},
created() {
this.getDimensionList();
this.getResourceList();
},
methods: {
// 获取维度列表
async getDimensionList() {
let res = await getDimensionList({
page: 1,
size: -1,
});
if (res.data.code == 1) {
let { data } = res.data.data;
this.dimensionList = data;
}
},
// 获取资源列表
async getResourceList() {
let res = await getResourceList({
page: 1,
size: -1,
});
if (res.data.code == 1) {
let { data } = res.data.data;
this.resourceList = this.groupByAuth(data);
}
},
// 资源分组
groupByAuth(list) {
let group = {};
let groupList = [];
list.forEach((item) => {
let name = item.name.split("-")[0];
if (!group[name]) {
group[name] = {
indeterminate: false,
checkAll: false,
list: [],
};
}
group[name].list.push(item);
});
groupList = Object.keys(group).map((key) => {
return {
label: key,
value: key,
children: group[key].list.map((v) => {
return {
label: v.name,
value: v.id,
};
}),
};
});
return groupList;
},
// 选择资源
changeRes(val, selectedOptions) {
if (selectedOptions.length) {
this.form.resourceId = selectedOptions[1].value;
this.form.resourceName = selectedOptions[1].label;
} else {
this.form.resourceId = "";
this.form.resourceName = "";
}
},
// 选择维度
changeDim(val, e) {
if (val && e) {
let { dimensionName, dimensionType, dimensionValue } = e.data.attrs[
"dataset-row"
];
this.form.ruleName = dimensionName;
this.form.ruleType = dimensionType;
this.form.ruleValue = dimensionValue;
} else {
this.form.ruleName = "";
this.form.ruleType = "";
this.form.ruleValue = "";
}
},
// 新增
onAdd() {
onAdd(roleInfo) {
Object.assign(this.form, this.$options.data().form);
this.form.id && this.$delete(this.form, "id");
this.form.roleId = roleInfo.id;
this.form.roleName = roleInfo.name;
},
// 编辑
onEdit(row) {
this.$nextTick(() => {
this.form = { ...row };
let resName = this.form.resourceName.split("-")[0];
this.resource = [resName, this.form.resourceId];
});
},
// 保存
......@@ -94,7 +240,7 @@ export default {
this.$refs.form.validate(async (valid) => {
if (valid) {
this.loading = true;
let res = await saveRole(this.form);
let res = await saveDimRes(this.form);
let { code, msg } = res.data;
this.loading = false;
if (code == 1) {
......@@ -108,10 +254,16 @@ export default {
// 重置
handleReset() {
this.$refs.form.resetFields();
this.form.ruleName = "";
this.form.ruleType = "";
this.form.ruleValue = "";
this.form.resourceId = "";
this.form.resourceName = "";
this.resource = [];
},
// 关闭
handleCancel() {
this.$refs.form.resetFields();
this.handleReset();
this.Visible = false;
},
},
......
<template>
<div>
<a-drawer
title="角色资源规则管理"
title="资源规则"
:visible="Visible"
@close="onClose"
:maskClosable="false"
:destroyOnClose="true"
width="50%"
>
<div class="mb10">
角色名称:<span class="primary">{{ roleInfo.name }}</span>
</div>
<div class="search-box flex aic jcb mb20">
<div>
<a-space>
......@@ -17,7 +20,7 @@
</div>
<a-input-search
style="width: 300px"
placeholder="请输入名称搜索"
placeholder="请输入维度名称搜索"
enter-button="搜索"
v-model="searchVal"
allowClear
......@@ -31,6 +34,7 @@
selectedRowKeys: selectedRowKeys,
onChange: onSelectChange,
}"
size="small"
:loading="loading"
bordered
:scroll="{ y: 460 }"
......@@ -53,15 +57,7 @@
<span slot="num" slot-scope="text, record, index">{{
(current - 1) * size + index + 1
}}</span>
<!-- 统计类型 -->
<template slot="censusType" slot-scope="text">
{{ filterDict(text.censusType) }}
</template>
<!-- 是否开放 -->
<template slot="status" slot-scope="text">
<a-tag color="blue" v-if="text.status === 1"></a-tag>
<a-tag color="red" v-else></a-tag>
</template>
<!-- 操作 -->
<template slot="action" slot-scope="text">
<a-space>
......@@ -80,6 +76,7 @@
:addVisible.sync="addVisible"
:title="title"
:dict="dict"
@addSuccess="getDimResList"
></AddResDim>
</a-drawer>
</div>
......@@ -87,46 +84,9 @@
<script>
import { pageSizeOptions } from "@/config/pageConfig.js";
import { getDimResList } from "@/services/system";
import { getDimResList, delDimRes } from "@/services/system";
import AddResDim from "./AddResDim.vue";
const ruleCondition = [
{
key: "IN",
name: "属于",
},
{
key: "<",
name: "小于",
},
{
key: ">",
name: "大于",
},
{
key: "=",
name: "等于",
},
{
key: "!=",
name: "不等于",
},
{
key: ">=",
name: "大于等于",
},
{
key: "<=",
name: "小于等于",
},
{
key: "% like",
name: "左模糊",
},
{
key: "like %",
name: "右模糊",
},
];
export default {
props: {
visible: {
......@@ -147,32 +107,38 @@ export default {
},
},
{
title: "规则名称",
title: "维度名称",
dataIndex: "ruleName",
},
{
title: "规则编码",
title: "维度编码",
dataIndex: "ruleCode",
},
{
title: "规则条件",
dataIndex: "ruleCondition",
title: "维度类型",
dataIndex: "ruleType",
},
{
title: "规则",
title: "维度",
dataIndex: "ruleValue",
},
{
title: "规则类型",
dataIndex: "ruleType",
},
{
title: "所属资源",
dataIndex: "resourceName",
},
{
title: "规则条件",
dataIndex: "ruleCondition",
customRender: (text) => {
return this.dict.ruleCondition[text];
},
},
{
title: "创建时间",
dataIndex: "createTime",
customRender: (text) => {
return this.$moment(text).format("YYYY-MM-DD HH:mm:ss");
},
},
{
title: "操作",
......@@ -181,7 +147,6 @@ export default {
},
];
return {
ruleCondition,
columns,
roleInfo: {}, // 模块信息
loading: false,
......@@ -216,21 +181,26 @@ export default {
// 获取列表
async getDimResList() {
this.loading = true;
let res = await getDimResList({
current: this.current,
size: this.size,
roleId: this.roleInfo.id,
ruleName: this.searchVal,
ruleName: `%${this.searchVal}%`,
});
this.loading = false;
if (res.data.code == 1) {
console.log(res.data);
let { data, total, dict } = res.data.data;
this.total = total;
this.tableData = data;
this.dict = dict;
}
},
handleAdd() {
this.title = "新增";
this.addVisible = true;
this.$refs.AddResDim.onAdd();
this.$refs.AddResDim.onAdd(this.roleInfo);
},
handleDelAll() {
if (!this.selectedRowKeys.length) {
......@@ -249,6 +219,7 @@ export default {
// 搜索
onSearch() {
this.current = 1;
this.getDimResList();
},
// 编辑
handleEdit(row) {
......@@ -259,11 +230,13 @@ export default {
// 翻页
handleChange(cur) {
this.current = cur;
this.getDimResList();
},
// 改变每页显示数量
showSizeChange(current, size) {
this.current = current;
this.size = size;
this.getDimResList();
},
// 删除
handleDel(id) {
......@@ -278,7 +251,11 @@ export default {
icon: "exclamation-circle",
maskClosable: true,
async onOk() {
console.log(id, _this);
let res = await delDimRes({ id });
if (res.data.code == 1) {
_this.$message.success(res.data.msg);
_this.getDimResList();
}
},
});
},
......@@ -286,16 +263,6 @@ export default {
onSelectChange(keys) {
this.selectedRowKeys = keys;
},
// 过滤列表数据
filterDict(dict) {
let str = "";
Object.keys(this.dict.censusType).forEach((keys) => {
if (dict == keys) {
str = this.dict.censusType[keys];
}
});
return str;
},
},
};
</script>
......
......@@ -61,7 +61,11 @@
</a-table>
</div>
<!-- 分配角色 -->
<AddUserRole ref="AddUserRole" :addVisible.sync="addVisible"></AddUserRole>
<AddUserRole
ref="AddUserRole"
:addVisible.sync="addVisible"
@addSuccess="getUserList"
></AddUserRole>
</div>
</template>
......
......@@ -107,9 +107,12 @@ export default {
this.$refs.form.validate(async (valid) => {
if (valid) {
this.loading = true;
let { id, roleIds, lastLoginAddress, mobile } = this.form;
let res = await saveUser({
...this.form,
roleIds: this.form.roleIds.join(","),
id,
lastLoginAddress,
mobile,
roleIds: roleIds.join(","),
});
this.loading = false;
let { code, msg } = res.data;
......
......@@ -306,7 +306,7 @@ const options = {
meta: {
icon: "global",
},
redirect: "system/parameter",
redirect: "system/user",
children: [
{
path: "user",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment