mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-12 05:33:48 +08:00
v2.0
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 权限插件
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:50:46
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import { useUserStore } from '/@/store/modules/system/user';
|
||||
|
||||
const privilege = (value) => {
|
||||
// 超级管理员
|
||||
if (useUserStore().administratorFlag) {
|
||||
return true;
|
||||
}
|
||||
// 获取功能点权限
|
||||
let userPointsList = useUserStore().getPointList;
|
||||
if (!userPointsList) {
|
||||
return false;
|
||||
}
|
||||
return userPointsList && userPointsList.includes(value);
|
||||
};
|
||||
|
||||
export default {
|
||||
install: (app) => {
|
||||
app.config.globalProperties.$privilege = privilege;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 枚举插件
|
||||
* 此插件为 1024创新实验室 自创的插件
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:51:03
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import _ from 'lodash';
|
||||
import { FLAG_NUMBER_ENUM } from '/@/constants/common-const';
|
||||
|
||||
export default {
|
||||
install: (app, smartEnumWrapper) => {
|
||||
const smartEnumPlugin = {};
|
||||
/**
|
||||
* 根据枚举值获取描述
|
||||
* @param {*} constantName 枚举名
|
||||
* @param {*} value 枚举值
|
||||
* @returns
|
||||
*/
|
||||
smartEnumPlugin.getDescByValue = function (constantName, value) {
|
||||
if (!smartEnumWrapper || !Object.prototype.hasOwnProperty.call(smartEnumWrapper, constantName)) {
|
||||
return '';
|
||||
}
|
||||
// boolean类型需要做特殊处理
|
||||
if (constantName === 'FLAG_NUMBER_ENUM' && !_.isUndefined(value) && typeof value === 'boolean') {
|
||||
value = value ? FLAG_NUMBER_ENUM.TRUE.value : FLAG_NUMBER_ENUM.FALSE.value;
|
||||
}
|
||||
|
||||
let smartEnum = smartEnumWrapper[constantName];
|
||||
for (let item in smartEnum) {
|
||||
if (smartEnum[item].value === value) {
|
||||
return smartEnum[item].desc;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
/**
|
||||
* 根据枚举名获取对应的描述键值对[{value:desc}]
|
||||
* @param {*} constantName 枚举名
|
||||
* @returns
|
||||
*/
|
||||
smartEnumPlugin.getValueDescList = function (constantName) {
|
||||
if (!Object.prototype.hasOwnProperty.call(smartEnumWrapper, constantName)) {
|
||||
return [];
|
||||
}
|
||||
const result = [];
|
||||
let targetSmartEnum = smartEnumWrapper[constantName];
|
||||
for (let item in targetSmartEnum) {
|
||||
result.push(targetSmartEnum[item]);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据枚举名获取对应的value描述键值对{value:desc}
|
||||
* @param {*} constantName 枚举名
|
||||
* @returns
|
||||
*/
|
||||
smartEnumPlugin.getValueDesc = function (constantName) {
|
||||
if (!Object.prototype.hasOwnProperty.call(smartEnumWrapper, constantName)) {
|
||||
return {};
|
||||
}
|
||||
let smartEnum = smartEnumWrapper[constantName];
|
||||
let result = {};
|
||||
for (let item in smartEnum) {
|
||||
let key = smartEnum[item].value + '';
|
||||
result[key] = smartEnum[item].desc;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
app.config.globalProperties.$smartEnumPlugin = smartEnumPlugin;
|
||||
app.provide('smartEnumPlugin', smartEnumPlugin);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user