|
|
|
|
// 设置购物车数量
|
|
|
|
|
const setGoodsNum = (data) => {
|
|
|
|
|
$globalStore.useCommon.SET_GOODS_NUM(data);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 判断是否还是一个对象
|
|
|
|
|
const isObject = (obj) => {
|
|
|
|
|
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 扁平化对象
|
|
|
|
|
const getObjKeys = (obj) => {
|
|
|
|
|
let result = {}; // 用于保存扁平化后的对象
|
|
|
|
|
const helpLoop = (obj) => {
|
|
|
|
|
const objKeys = Object.keys(obj);
|
|
|
|
|
for (let i = 0; i < objKeys.length; i++) {
|
|
|
|
|
if (typeof obj[objKeys[i]] == "object") {
|
|
|
|
|
helpLoop(obj[objKeys[i]]);
|
|
|
|
|
} else {
|
|
|
|
|
result[objKeys[i]] = obj[objKeys[i]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
helpLoop(obj);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 比较两个对象差异
|
|
|
|
|
const comparisonObject = (objPre, objNext) => {
|
|
|
|
|
if (Object.keys(objPre).length == 0 || !objPre || !objNext) return false;
|
|
|
|
|
const tempPre = getObjKeys(objPre);
|
|
|
|
|
const tempNext = getObjKeys(objNext);
|
|
|
|
|
// 数组去重
|
|
|
|
|
let keys = [];
|
|
|
|
|
keys.push(...Object.keys(tempPre));
|
|
|
|
|
keys.push(...Object.keys(tempNext));
|
|
|
|
|
keys = [...new Set(keys)];
|
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
|
if (tempPre[keys[i]] != tempNext[keys[i]]) {
|
|
|
|
|
return keys[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ele:要插入的元素(父元素要设置相对定位)
|
|
|
|
|
cloneEl:要克隆的元素
|
|
|
|
|
cssStyles:克隆时去掉不克隆的样式
|
|
|
|
|
*/
|
|
|
|
|
const isElementHidden = (ele = "", cloneEl = "", cssStyles = []) => {
|
|
|
|
|
if (!ele || !cloneEl) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const clonedNode = cloneEl.cloneNode(true);
|
|
|
|
|
const allStyle = cloneEl.computedStyleMap();
|
|
|
|
|
for (const [prop, val] of allStyle) {
|
|
|
|
|
if (!cssStyles.includes(prop)) {
|
|
|
|
|
clonedNode.style[prop] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
clonedNode.className = "";
|
|
|
|
|
clonedNode.style.visibility = "hidden";
|
|
|
|
|
clonedNode.style.position = "absolute";
|
|
|
|
|
clonedNode.setAttribute("id", "ellipt_hidden__node___id");
|
|
|
|
|
ele.appendChild(clonedNode);
|
|
|
|
|
const differ = clonedNode.offsetHeight > ele.offsetHeight;
|
|
|
|
|
ele.removeChild(clonedNode);
|
|
|
|
|
return differ;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formattedTimeYYYYmmdd = (dateTime) =>{
|
|
|
|
|
const date = new Date(dateTime);
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = ("0" + (date.getMonth() + 1)).slice(-2);
|
|
|
|
|
const day = ("0" + date.getDate()).slice(-2);
|
|
|
|
|
const hour = ("0" + date.getHours()).slice(-2);
|
|
|
|
|
const minute = ("0" + date.getMinutes()).slice(-2);
|
|
|
|
|
const second = ("0" + date.getSeconds()).slice(-2);
|
|
|
|
|
const type = getDeviceType();
|
|
|
|
|
console.log("机型格式",type)
|
|
|
|
|
|
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
|
}
|
|
|
|
|
const formattedTime = (dateTime) =>{
|
|
|
|
|
const date = new Date(dateTime);
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = ("0" + (date.getMonth() + 1)).slice(-2);
|
|
|
|
|
const day = ("0" + date.getDate()).slice(-2);
|
|
|
|
|
const hour = ("0" + date.getHours()).slice(-2);
|
|
|
|
|
const minute = ("0" + date.getMinutes()).slice(-2);
|
|
|
|
|
const second = ("0" + date.getSeconds()).slice(-2);
|
|
|
|
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formattedDate = (dateTime) =>{
|
|
|
|
|
const date = new Date(dateTime);
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = ("0" + (date.getMonth() + 1)).slice(-2);
|
|
|
|
|
const day = ("0" + date.getDate()).slice(-2);
|
|
|
|
|
const hour = ("0" + date.getHours()).slice(-2);
|
|
|
|
|
const minute = ("0" + date.getMinutes()).slice(-2);
|
|
|
|
|
const second = ("0" + date.getSeconds()).slice(-2);
|
|
|
|
|
if(hour==="00" && minute==="00" && second==="00"){
|
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
|
}else{
|
|
|
|
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化用户名称为两个字的姓名
|
|
|
|
|
* @param {*} name
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
const alignNames = (name) =>{
|
|
|
|
|
if(name.length == 2){
|
|
|
|
|
name = name.substring(0,1) + " " + name.substring(1,2);
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getDeviceType = () =>{
|
|
|
|
|
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
|
|
|
|
|
|
|
|
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/iPod/i)) {
|
|
|
|
|
return 'iOS';
|
|
|
|
|
} else if (userAgent.match(/Android/i)) {
|
|
|
|
|
return 'Android';
|
|
|
|
|
} else {
|
|
|
|
|
return 'unknown';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化执法人员/入企人员数据,支持逗号分隔的名字和ID对应显示
|
|
|
|
|
* 支持多种字段名:lawEnforcerTwo/lawEnforcerIdTwo 或 lawEnforcerOther/lawEnforcerIdOther
|
|
|
|
|
* @param {Object} item - 包含执法人员信息的对象
|
|
|
|
|
* @returns {Array} - 格式化后的执法人员数组,每个元素为 "名字 - ID" 的格式
|
|
|
|
|
*/
|
|
|
|
|
const formatEnforcer = (item) => {
|
|
|
|
|
const enforcers = [];
|
|
|
|
|
if (item.lawEnforcer) {
|
|
|
|
|
// 处理逗号分隔的多个执法人员
|
|
|
|
|
const names = item.lawEnforcer.split(',').map(n => n.trim()).filter(n => n);
|
|
|
|
|
const ids = item.lawEnforcerId ? item.lawEnforcerId.split(',').map(id => id.trim()).filter(id => id) : [];
|
|
|
|
|
names.forEach((name, index) => {
|
|
|
|
|
const id = ids[index] || '';
|
|
|
|
|
enforcers.push(id ? `${name} - ${id}` : name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 支持两种字段名:lawEnforcerTwo 或 lawEnforcerOther
|
|
|
|
|
const secondName = item.lawEnforcerTwo || item.lawEnforcerOther;
|
|
|
|
|
const secondId = item.lawEnforcerIdTwo || item.lawEnforcerIdOther;
|
|
|
|
|
if (secondName) {
|
|
|
|
|
const names = secondName.split(',').map(n => n.trim()).filter(n => n);
|
|
|
|
|
const ids = secondId ? secondId.split(',').map(id => id.trim()).filter(id => id) : [];
|
|
|
|
|
names.forEach((name, index) => {
|
|
|
|
|
const id = ids[index] || '';
|
|
|
|
|
enforcers.push(id ? `${name} ${id}` : name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return enforcers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export { setGoodsNum, isObject, comparisonObject, isElementHidden, formattedTimeYYYYmmdd, formattedTime, getDeviceType, formattedDate, formatEnforcer };
|