2024-12-22 08:06:28 +00:00
|
|
|
import Vue from "vue";
|
|
|
|
import router from "@/router";
|
|
|
|
import store from "@/store";
|
2024-08-05 08:26:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取uuid
|
|
|
|
*/
|
2024-12-22 08:06:28 +00:00
|
|
|
export function getUUID() {
|
|
|
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
|
|
return (c === "x" ? (Math.random() * 16) | 0 : "r&0x3" | "0x8").toString(
|
|
|
|
16
|
|
|
|
);
|
|
|
|
});
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否有权限
|
|
|
|
* @param {*} key
|
|
|
|
*/
|
2024-12-22 08:06:28 +00:00
|
|
|
export function isAuth(key) {
|
|
|
|
return (
|
|
|
|
JSON.parse(sessionStorage.getItem("permissions") || "[]").indexOf(key) !==
|
|
|
|
-1 || false
|
|
|
|
);
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 树形数据转换
|
|
|
|
* @param {*} data
|
|
|
|
* @param {*} id
|
|
|
|
* @param {*} pid
|
|
|
|
*/
|
2024-12-22 08:06:28 +00:00
|
|
|
export function treeDataTranslate(data, id = "id", pid = "parentId") {
|
|
|
|
var res = [];
|
|
|
|
var temp = {};
|
2024-08-05 08:26:35 +00:00
|
|
|
for (var i = 0; i < data.length; i++) {
|
2024-12-22 08:06:28 +00:00
|
|
|
temp[data[i][id]] = data[i];
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
for (var k = 0; k < data.length; k++) {
|
|
|
|
if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
|
2024-12-22 08:06:28 +00:00
|
|
|
if (!temp[data[k][pid]]["children"]) {
|
|
|
|
temp[data[k][pid]]["children"] = [];
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
2024-12-22 08:06:28 +00:00
|
|
|
if (!temp[data[k][pid]]["_level"]) {
|
|
|
|
temp[data[k][pid]]["_level"] = 1;
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
2024-12-22 08:06:28 +00:00
|
|
|
data[k]["_level"] = temp[data[k][pid]]._level + 1;
|
|
|
|
temp[data[k][pid]]["children"].push(data[k]);
|
2024-08-05 08:26:35 +00:00
|
|
|
} else {
|
2024-12-22 08:06:28 +00:00
|
|
|
res.push(data[k]);
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
2024-12-22 08:06:28 +00:00
|
|
|
return res;
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 清除登录信息
|
|
|
|
*/
|
2024-12-22 08:06:28 +00:00
|
|
|
export function clearLoginInfo() {
|
|
|
|
Vue.cookie.delete("token");
|
|
|
|
store.commit("resetStore");
|
|
|
|
sessionStorage.removeItem("password");
|
|
|
|
sessionStorage.removeItem("role");
|
|
|
|
sessionStorage.removeItem("userInfo");
|
|
|
|
router.options.isAddDynamicMenuRoutes = false;
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 深拷贝对象
|
|
|
|
export function deepClone(obj) {
|
2024-12-22 08:06:28 +00:00
|
|
|
const _toString = Object.prototype.toString;
|
2024-08-05 08:26:35 +00:00
|
|
|
|
|
|
|
// null, undefined, non-object, function
|
2024-12-22 08:06:28 +00:00
|
|
|
if (!obj || typeof obj !== "object") {
|
|
|
|
return obj;
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DOM Node
|
2024-12-22 08:06:28 +00:00
|
|
|
if (obj.nodeType && "cloneNode" in obj) {
|
|
|
|
return obj.cloneNode(true);
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Date
|
2024-12-22 08:06:28 +00:00
|
|
|
if (_toString.call(obj) === "[object Date]") {
|
|
|
|
return new Date(obj.getTime());
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegExp
|
2024-12-22 08:06:28 +00:00
|
|
|
if (_toString.call(obj) === "[object RegExp]") {
|
|
|
|
const flags = [];
|
|
|
|
if (obj.global) {
|
|
|
|
flags.push("g");
|
|
|
|
}
|
|
|
|
if (obj.multiline) {
|
|
|
|
flags.push("m");
|
|
|
|
}
|
|
|
|
if (obj.ignoreCase) {
|
|
|
|
flags.push("i");
|
|
|
|
}
|
2024-08-05 08:26:35 +00:00
|
|
|
|
2024-12-22 08:06:28 +00:00
|
|
|
return new RegExp(obj.source, flags.join(""));
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2024-12-22 08:06:28 +00:00
|
|
|
const result = Array.isArray(obj)
|
|
|
|
? []
|
|
|
|
: obj.constructor
|
|
|
|
? new obj.constructor()
|
|
|
|
: {};
|
2024-08-05 08:26:35 +00:00
|
|
|
|
|
|
|
for (const key in obj) {
|
2024-12-22 08:06:28 +00:00
|
|
|
result[key] = deepClone(obj[key]);
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2024-12-22 08:06:28 +00:00
|
|
|
return result;
|
2024-08-05 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2024-12-24 10:30:47 +00:00
|
|
|
/**
|
|
|
|
* 获取时间
|
|
|
|
* @param {*} min
|
|
|
|
* @param {*} max
|
|
|
|
*/
|
|
|
|
export function getDay(day) {
|
|
|
|
let today = new Date();
|
|
|
|
let targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
|
|
|
|
today.setTime(targetday_milliseconds); //注意,这行是关键代码
|
|
|
|
let tYear = today.getFullYear();
|
|
|
|
let tMonth = today.getMonth();
|
|
|
|
let tDate = today.getDate();
|
|
|
|
tMonth = doHandleMonth(tMonth + 1);
|
|
|
|
tDate = doHandleMonth(tDate);
|
|
|
|
return tYear + "-" + tMonth + "-" + tDate;
|
|
|
|
}
|
|
|
|
function doHandleMonth(month) {
|
|
|
|
let m = month;
|
|
|
|
if (month.toString().length === 1) {
|
|
|
|
m = "0" + month;
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
2024-12-30 09:58:37 +00:00
|
|
|
/**
|
|
|
|
* 权限
|
|
|
|
* @param {*} min
|
|
|
|
* @param {*} max
|
|
|
|
*/
|
|
|
|
export function getMenu(role) {
|
|
|
|
if (role == "ROLE_MERCHANT" || role == "ROLE_MANAGER") {
|
|
|
|
return [
|
|
|
|
"operation-management",
|
|
|
|
"operation-management/commodity/index",
|
|
|
|
"operation-management/order/index",
|
|
|
|
"operation-management/banner/index",
|
|
|
|
"operation-management/notice/index",
|
|
|
|
"operation-management/role/index",
|
|
|
|
"datacenter",
|
|
|
|
"datacenter/customer-analysis/index",
|
|
|
|
"datacenter/product-analysis/index",
|
|
|
|
"datacenter/order-analysis/index",
|
|
|
|
"coupon/index",
|
|
|
|
"presale",
|
|
|
|
"presale/products/index",
|
|
|
|
"presale/order/index",
|
|
|
|
"marketing",
|
|
|
|
"marketing/level/index",
|
|
|
|
"marketing/user/index",
|
|
|
|
"marketing/points-setting/index",
|
|
|
|
"marketing/points-mall/index",
|
|
|
|
"marketing/points-order/index",
|
|
|
|
"local-course/resources",
|
|
|
|
"wallet/index",
|
|
|
|
"ogistics-fare",
|
|
|
|
"logistics-fare/logistics-template/index",
|
|
|
|
];
|
|
|
|
} else if (role == "ROLE_BRAND_MANAGER") {
|
|
|
|
return [
|
|
|
|
"operation-management",
|
|
|
|
"operation-management/shop-list/index",
|
|
|
|
"operation-management/order/index",
|
|
|
|
"operation-management/role/index",
|
|
|
|
"datacenter",
|
|
|
|
"datacenter/customer-analysis/index",
|
|
|
|
"datacenter/product-analysis/index",
|
|
|
|
"datacenter/order-analysis/index",
|
|
|
|
"brand",
|
|
|
|
"brand/config/index",
|
|
|
|
"local-course/resources",
|
|
|
|
"wallet/index",
|
|
|
|
];
|
|
|
|
} else if (role == "ROLE_AGENT") {
|
|
|
|
return [
|
|
|
|
"operation-management",
|
|
|
|
"operation-management/shop-list/index",
|
|
|
|
"operation-management/order/index",
|
|
|
|
"operation-management/role/index",
|
|
|
|
"datacenter",
|
|
|
|
"datacenter/customer-analysis/index",
|
|
|
|
"datacenter/product-analysis/index",
|
|
|
|
"datacenter/order-analysis/index",
|
|
|
|
"local-course/resources",
|
|
|
|
"wallet/index",
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2024-12-24 10:30:47 +00:00
|
|
|
|
2024-08-05 08:26:35 +00:00
|
|
|
export function isNumberStr(str) {
|
2024-12-22 08:06:28 +00:00
|
|
|
return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str);
|
|
|
|
}
|