2025-03-26 10:09:11 +08:00
|
|
|
|
import {
|
|
|
|
|
getJSONData,
|
|
|
|
|
setJSONData,
|
|
|
|
|
removeJSONData,
|
|
|
|
|
setStrData
|
|
|
|
|
} from '@/utils/auth'
|
2025-03-21 17:57:53 +08:00
|
|
|
|
// 用户权益code
|
|
|
|
|
const UserRightsKey = 'User-Rights'
|
|
|
|
|
//用户当前身份code
|
|
|
|
|
const UserTypeKey = 'User-Type'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断某用户是否有某权益
|
|
|
|
|
* @param {Object} code 权益code
|
|
|
|
|
*/
|
|
|
|
|
export function hasRights(code) {
|
|
|
|
|
let userRights = getJSONData(UserRightsKey)
|
|
|
|
|
//默认无权限
|
|
|
|
|
let rtnData = false
|
2025-03-26 10:09:11 +08:00
|
|
|
|
if ('' != userRights && userRights.con) {
|
2025-03-21 17:57:53 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return rtnData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 切换用户当前身份
|
|
|
|
|
* @param {Object} value 身份值
|
|
|
|
|
*/
|
|
|
|
|
export function changeUserType(value) {
|
2025-03-26 10:09:11 +08:00
|
|
|
|
setStrData(UserTypeKey, value)
|
2025-03-21 17:57:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-18 17:41:45 +08:00
|
|
|
|
/**
|
2025-03-26 10:09:11 +08:00
|
|
|
|
* 显示消息提示框
|
|
|
|
|
* @param content 提示的标题
|
|
|
|
|
*/
|
2025-03-18 17:41:45 +08:00
|
|
|
|
export function toast(content) {
|
2025-03-26 10:09:11 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: 'none',
|
|
|
|
|
title: content
|
|
|
|
|
})
|
2025-03-18 17:41:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-03-26 10:09:11 +08:00
|
|
|
|
* 显示模态弹窗
|
|
|
|
|
* @param content 提示的标题
|
|
|
|
|
*/
|
2025-03-18 17:41:45 +08:00
|
|
|
|
export function showConfirm(content) {
|
2025-03-26 10:09:11 +08:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: content,
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
confirmText: '确定',
|
|
|
|
|
success: function(res) {
|
|
|
|
|
resolve(res)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-03-18 17:41:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-03-26 10:09:11 +08:00
|
|
|
|
* 参数处理
|
|
|
|
|
* @param params 参数
|
|
|
|
|
*/
|
2025-03-18 17:41:45 +08:00
|
|
|
|
export function tansParams(params) {
|
2025-03-26 10:09:11 +08:00
|
|
|
|
let result = ''
|
|
|
|
|
for (const propName of Object.keys(params)) {
|
|
|
|
|
const value = params[propName]
|
|
|
|
|
var part = encodeURIComponent(propName) + "="
|
|
|
|
|
if (value !== null && value !== "" && typeof(value) !== "undefined") {
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
|
for (const key of Object.keys(value)) {
|
|
|
|
|
if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
|
|
|
|
|
let params = propName + '[' + key + ']'
|
|
|
|
|
var subPart = encodeURIComponent(params) + "="
|
|
|
|
|
result += subPart + encodeURIComponent(value[key]) + "&"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result += part + encodeURIComponent(value) + "&"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result
|
2025-03-21 17:57:53 +08:00
|
|
|
|
}
|
2025-03-26 10:09:11 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数字单位转换
|
|
|
|
|
* @param {Object} num
|
|
|
|
|
*/
|
|
|
|
|
export function formatNumberWithUnits(num) {
|
|
|
|
|
const units = ['', 'k', 'w', 'kw'];
|
|
|
|
|
const absNum = Math.abs(num); // 获取绝对值以处理负数
|
|
|
|
|
// 处理小于1000的情况,直接返回原数字的字符串形式
|
|
|
|
|
if (absNum < 1000) {
|
|
|
|
|
return absNum.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 寻找合适的单位
|
|
|
|
|
let unitIndex = 0;
|
|
|
|
|
if (absNum > 10000000) {
|
|
|
|
|
absNum /= 10000000;
|
|
|
|
|
unitIndex = 3;
|
|
|
|
|
} else if (absNum > 10000) {
|
|
|
|
|
absNum /= 10000;
|
|
|
|
|
unitIndex = 2;
|
|
|
|
|
} else if (absNum > 1000) {
|
|
|
|
|
absNum /= 1000;
|
|
|
|
|
unitIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
// 格式化数字,并添加单位
|
|
|
|
|
const formattedNum = absNum.toFixed(2).replace(/\.?0+$/, ''); // 保留两位小数并去除末尾的零
|
|
|
|
|
return formattedNum + units[unitIndex];
|
|
|
|
|
}
|