123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- import { computed } from "vue";
- import { useAuthStore } from "@/stores/modules/auth";
- import { useUserStore } from "@/stores/modules/user";
- import { Edit, Plus, Menu } from "@element-plus/icons-vue";
- import { useRoute, useRouter } from "vue-router";
- import { detailAction } from "@/components/LjDetail/interface";
- import { isArray, isString } from "@/utils/is";
- interface BusinessButtonProps extends detailAction {
- /**
- * @argument 继承:ElButton的type
- */
- type?: any;
- /**
- * @argument 路由地址
- */
- path?: string;
- }
- /**
- * @description 页面按钮
- * @param {Object} t i18n
- * */
- export const useAuthButtons = (t?: any) => {
- // const route = useRoute();
- const authStore = useAuthStore();
- const authPower: (number | string)[] = authStore.authButtonListGet || [];
- const authOption = authStore.authOptionListGet || [];
- // console.log("route.name :>> ", route.name);
- // const BUTTONS = computed(() => {
- // let currentPageAuthButton: { [key: string]: boolean } = {};
- // authButtons.forEach(item => (currentPageAuthButton[item] = true));
- // return currentPageAuthButton;
- // });
- /**
- * 查询权限值
- * @param {number | string} num 权限值 | super
- * @returns {boolean} 是否存在
- */
- const CheckPower = (data: number | string) => {
- if (isString(data)) {
- const { userInfo } = useUserStore();
- return userInfo.usercode?.toLowerCase() === "super";
- }
- return authPower.includes(data);
- };
- /**
- * 查询系统选项
- * @param {string} val 系统选项
- * @returns {string}
- */
- const CheckOption = (val: string | number) => {
- let _option = authOption.find((item: any) => Number(item.optionid) === Number(val));
- return _option?.optionvalue;
- };
- /**
- * @description 业务按钮:新建
- */
- const buttonNew = (data: BusinessButtonProps): detailAction => {
- const router = useRouter();
- return {
- ...data,
- label: data.label ?? t("common.add"),
- icon: data.icon ?? Plus,
- // type: data.type ?? "success",
- // type: undefined,
- // plain: true,
- disabledTextCallBack: (item: any) => {
- return data.disabledTextCallBack ? data.disabledTextCallBack(item) : "";
- },
- clickFunc: (item: any) => {
- console.log("item :>> ", item);
- if (data.clickFunc) {
- data.clickFunc(item);
- } else {
- router.push({
- path: data.path ?? "/"
- });
- }
- }
- };
- };
- /**
- * @description 业务按钮:初审
- */
- const buttonDefault = (data: BusinessButtonProps): detailAction => {
- return {
- ...data,
- icon: data.icon ?? undefined
- // type: data.type ?? "",
- // type: undefined
- // plain: true
- };
- };
- /**
- * @description 过滤无权限,按钮组
- * @param action 筛选合法操作
- * @returns array
- */
- const funcFilterPower = (action: any) => {
- console.log("funcFilterPower _action :>> ", action);
- if (!action) return [];
- let _action = action.map((item: any) => {
- if (!Object.keys(item).includes("power")) {
- return item;
- }
- if (isArray(item)) {
- return item.filter((i: any) => {
- return CheckPower(i.power);
- });
- }
- return CheckPower(item.power) ? item : {};
- });
- _action = _action.filter((item: any) => {
- if (isArray(item)) {
- return item.length;
- }
- return Object.keys(item).length;
- });
- return _action;
- };
- /**
- * @description 过滤无权限,单据功能,
- * @param action 筛选合法操作
- * @returns array
- */
- const funcRightActionPower = (action: any) => {
- let rst = action;
- if (isArray(rst)) {
- rst = rst.map((itm: any) => {
- console.log(itm);
- if (itm?.groupAction && itm.groupAction.length) {
- itm.groupAction = funcRightActionPower(itm.groupAction);
- return itm;
- } else {
- return funcRightActionPower(itm);
- }
- });
- rst = rst.filter((item: any) => {
- if (isArray(item)) {
- return item.length;
- }
- return Object.keys(item).length;
- });
- } else {
- if (rst?.groupAction && rst.groupAction.length) {
- rst = funcRightActionPower(rst.groupAction);
- } else if (Object.keys(rst).includes("power")) {
- rst = CheckPower(rst.power) ? rst : {};
- }
- }
- return rst;
- };
- return {
- CheckPower,
- CheckOption,
- buttonNew,
- buttonDefault,
- funcFilterPower,
- funcRightActionPower
- };
- };
|