diff --git a/src/api/consumable.js b/src/api/consumable.js index 10fc6d0..ece7e69 100644 --- a/src/api/consumable.js +++ b/src/api/consumable.js @@ -39,13 +39,8 @@ export function puttbConsType(data) { * @returns */ export function gettbConsInfo(data) { - // return request({ - // url: '/api/tbConsInfo', - // method: "get", - // params - // }); return request({ - url: "/api/viewConInfoFlow/get", + url: "/api/tbConsInfo/allAndPro", method: "post", data }); diff --git a/src/api/shop.js b/src/api/shop.js index e452c19..79ed2c8 100644 --- a/src/api/shop.js +++ b/src/api/shop.js @@ -581,6 +581,14 @@ export function tbShopPermissionlist(params) { }); } +export function getHasPermission(params) { + return request({ + url: `/api/tbShopPermission/hasPermission`, + method: "get", + params + }); +} + /** * 通过id获取员工信息 * @returns diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 8bdfbd2..3937682 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -42,6 +42,7 @@ const user = { localStorage.setItem("shopName", res.shopName); localStorage.setItem("logo", res.logo); localStorage.setItem("loginType", res.loginType); + localStorage.setItem("userInfo", JSON.stringify(res.user.user)); setToken(res.token, rememberMe); commit("SET_TOKEN", res.token); setUserInfo(res.user, commit); diff --git a/src/utils/limits.js b/src/utils/limits.js new file mode 100644 index 0000000..ab82fc4 --- /dev/null +++ b/src/utils/limits.js @@ -0,0 +1,153 @@ +import { getHasPermission } from "@/api/shop"; +import { Notification } from 'element-ui' + +const userInfo = JSON.parse(localStorage.getItem("userInfo")); +const $PermissionObj = { + data: [{ + key: 'yun_xu_cha_kan_jing_ying_shu_ju', + text: '允许查看经营数据' + }, + { + key: 'yun_xu_cha_kan_suo_you_jiao_ban_ji_lu', + text: '允许查看所有交班记录' + } + ], + default: [{ + key: 'yun_xu_xia_dan', + text: '允许下单' + }, + { + key: 'yun_xu_shou_kuan', + text: '允许收款' + }, + { + key: 'yun_xu_tui_kuan', + text: '允许退款' + }, + { + key: 'yun_xu_jiao_ban', + text: '允许交班' + } + ], + goods: [{ + key: 'yun_xu_xiu_gai_shang_pin', + text: '允许修改商品' + }, + { + key: 'yun_xu_shang_xia_jia_shang_pin', + text: '允许上下架商品' + }, + { + key: 'yun_xu_xiu_gai_fen_lei', + text: '允许修改分类' + }, + { + key: 'yun_xu_xiu_gai_fen_zu', + text: '允许修改分组' + } + ], + discount:[ + { + key: 'yun_xu_da_zhe', + text: '允许打折' + } + ], + vip:[ + { + key: 'yun_xu_guan_li_hui_yuan_xin_xi', + text: '允许管理会员信息' + }, + { + key: 'yun_xu_xiu_gai_hui_yuan_yu_e', + text: '允许修改会员余额' + } + ], + stock:[ + { + text: '允许提交报损', + key: 'yun_xu_ti_jiao_bao_sun' + }, + { + text: '允许沽清', + key: 'yun_xu_gu_qing' + }, + { + text: '允许售罄商品', + key: 'yun_xu_shou_qing_shang_pin' + }, + { + text:'允许修改商品库存', + key:'yun_xu_xiu_gai_shang_pin_ku_cun' + }, + { + text: '允许耗材入库', + key: 'yun_xu_hao_cai_ru_ku' + }, + { + text: '允许耗材出库', + key: 'yun_xu_hao_cai_chu_ku' + }, + { + text: '允许耗材盘点', + key: 'yun_xu_hao_cai_pan_dian' + } + ] +} + +export async function hasPermission (params) { + //如果是商户默认拥有全部权限 + const loginType = localStorage.getItem('loginType') + if(loginType=='merchant'){ + return true + } + params = returnFormatParams(params) + if (!params) { + return infoBox.showToast('未找到相关权限,请检查代码或在权限配置文件commons/utils/hasPermission.js文件进行修改或增加') + } + const option = Object.assign({ + tips: true, + key: '', + text: '' + }, params) + const res = await getHasPermission({ + userId : userInfo.id, + + code: params.key + }) + if (!res && option.tips) { + Notification.error({ + title: '您没有' + params.text + '权限!', + duration: 5000 + }) + } + return res +} + +export function isObjectButNotArray(value) { + return typeof value === 'object' && Array.isArray(value) === false; +} + +export function findPermissionObj(str) { + for (let i in $PermissionObj) { + const obj = $PermissionObj[i].find(v => v.key == str || v.text == str) + if (obj) { + return obj + break + } + } + console.error('未找到相关权限配置,请检查权限配置文件commons/utils/hasPermission.js文件进行修改或增加') + return false +} + +export function returnFormatParams(params) { + if (typeof params === 'string') { + return findPermissionObj(params) + } else { + if (isObjectButNotArray(params)) { + const obj=findPermissionObj(params.key || params.text) + return {...params,...obj} + } else { + console.error('参数只能是字符串或者对象,不能是数组') + } + } +} diff --git a/src/views/home/data_record.vue b/src/views/home/data_record.vue index d4a144d..62cf22b 100644 --- a/src/views/home/data_record.vue +++ b/src/views/home/data_record.vue @@ -75,6 +75,7 @@