fix: 重写耗材模块

This commit is contained in:
2025-03-07 18:53:31 +08:00
parent 73057865da
commit 739f4a1062
67 changed files with 3610 additions and 1563 deletions

163
src/utils/limits.js Normal file
View File

@@ -0,0 +1,163 @@
import { ElMessage } from "element-plus";
function getHasPermission() {
return true;
}
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 ElMessage.error(
"未找到相关权限请检查代码或在权限配置文件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) {
ElMessage.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;
}
}
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("参数只能是字符串或者对象,不能是数组");
}
}
}

View File

@@ -4,7 +4,7 @@ import { getToken } from "@/utils/auth";
// 创建axios实例
const service = axios.create({
baseURL: "https://czgdoumei.sxczgkj.com/index.php/api/", // api 的 base_url
baseURL: "https://newblockwlx.sxczgkj.cn/index.php/api/", // api 的 base_url
timeout: 1000 * 20, // 请求超时时间
});