Ben Lin
2024-06-27 1e4b207c532a50651a3e9d1e79db221542eb30eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * @Description: 菜单Api相关
 * @Author: Ben Lin
 * @version: 
 * @Date: 2024-06-18 15:09:47
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-24 22:50:45
 */
import { defHttp } from '/@/utils/http/axios';
import { getMenuListResultModel } from './model/menuModel';
import { genAction, Api } from '../tigerapi/system';
import { useUserStore } from '/@/store/modules/user';
 
enum _Api {
  GetMenuList = '/SYS/getMenuList',
  GetMenuListAll = '/SYS/getMenuListAll',
}
 
/**
 * @description: Get user menu based on userid
 */
 
export const getMenuList = (userid: {}) => {
  return defHttp.get<getMenuListResultModel>(
    { url: _Api.GetMenuList, params: userid },
    {
      isTransformResponse: false, //api返回不做转换格式,保留原来数据
    },
  );
};
 
export const getMenuListAll = () => {
  return defHttp.get<getMenuListResultModel>(
    { url: _Api.GetMenuListAll },
    {
      isTransformResponse: false, //api返回不做转换格式,保留原来数据
    },
  );
};
 
/**
 * @description: 菜单权限
 * @param {string} params
 * @return {*}
 */
export const getMenuAuthList = async (params: string) => {
  const usParams = genAction('V_USER_MENU', {
    QueryAble_T: '',
    where: "USER_ID = '" + params + "'",
    order: '',
  });
  return await defHttp.post(
    { url: Api.QueryUrl, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/**
 * @description: 获取菜单下的按钮
 * @param {string} params
 * @return {*}
 */
export const getMenuButtons = async (params: string) =>{
  const usParams = genAction('SYS_MENU', {
    QueryAble_T: '',
    where: "PFUNC_CODE = '" + params + "' And BUTTON_TYPE < 3",
    order: 'SEQ_NO',
  });
  return await defHttp.post(
    { url: Api.QueryUrl, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/**
 * @description: 根据当前菜单代码获取用户有权限的按钮列表
 * @param {string} menuCode
 * @return {*}
 */
export async function getRoleButtons(menuCode: string) {
  const buttons = (await getMenuButtons(menuCode)).Data.Items;
  const roles = useUserStore().getUserInfo.roles;
  return buttons.filter((btn) => roles.some((item) => item.MENU_CODE === btn.FUNC_CODE));
}