2025-03-26 10:09:11 +08:00
|
|
|
|
import {
|
|
|
|
|
getJSONData,
|
|
|
|
|
setJSONData,
|
|
|
|
|
removeJSONData,
|
2025-03-27 09:50:13 +08:00
|
|
|
|
setStrData,
|
|
|
|
|
getStrData
|
2025-03-26 10:09:11 +08:00
|
|
|
|
} from '@/utils/auth'
|
2025-03-27 09:50:13 +08:00
|
|
|
|
import constant from '@/utils/constant'
|
2025-04-10 09:36:39 +08:00
|
|
|
|
import {
|
|
|
|
|
selectMemberRights
|
|
|
|
|
} from '@/api/business/member.js'
|
2025-03-21 17:57:53 +08:00
|
|
|
|
|
2025-04-02 11:34:12 +08:00
|
|
|
|
export function getWXStatusHeight() {
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
// 获取距上
|
|
|
|
|
const barTop = wx.getSystemInfoSync().statusBarHeight
|
|
|
|
|
// 获取胶囊按钮位置信息
|
|
|
|
|
const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
|
|
|
|
|
// 获取导航栏高度
|
|
|
|
|
const barHeight = menuButtonInfo.height + (menuButtonInfo.top - barTop) * 2
|
|
|
|
|
let barWidth = menuButtonInfo.width
|
|
|
|
|
console.log('menuButtonInfo', menuButtonInfo)
|
|
|
|
|
let barLeftPosition = 375 - menuButtonInfo.right + menuButtonInfo.width
|
|
|
|
|
let menuButtonLeft = menuButtonInfo.left
|
|
|
|
|
let menuButtonRight = menuButtonInfo.right
|
|
|
|
|
return {
|
|
|
|
|
barHeight,
|
|
|
|
|
barTop,
|
|
|
|
|
barWidth,
|
|
|
|
|
barLeftPosition,
|
|
|
|
|
menuButtonLeft,
|
|
|
|
|
menuButtonRight
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
}
|
2025-03-21 17:57:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 判断某用户是否有某权益
|
|
|
|
|
* @param {Object} code 权益code
|
|
|
|
|
*/
|
|
|
|
|
export function hasRights(code) {
|
2025-04-10 09:36:39 +08:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
//会员权益刷新
|
|
|
|
|
selectMemberRights().then(res => {
|
|
|
|
|
setJSONData(constant.userRightsKey, res.data)
|
|
|
|
|
//取用户当前身份
|
|
|
|
|
let userType = getStrData(constant.userTypeKey)
|
|
|
|
|
let userRights = {}
|
|
|
|
|
if (constant.bz == userType) {
|
|
|
|
|
//博主
|
|
|
|
|
userRights = getJSONData(constant.userRightsKey)['bz']
|
|
|
|
|
} else {
|
|
|
|
|
//通告主
|
|
|
|
|
userRights = getJSONData(constant.userRightsKey)['tgz']
|
|
|
|
|
}
|
|
|
|
|
//默认无权限
|
|
|
|
|
let rtnData = false
|
|
|
|
|
if (userRights.hasOwnProperty(code)) {
|
|
|
|
|
rtnData = userRights[code]
|
|
|
|
|
}
|
|
|
|
|
resolve(rtnData)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2025-03-31 14:31:41 +08:00
|
|
|
|
}
|
|
|
|
|
/**
|
2025-03-21 17:57:53 +08:00
|
|
|
|
* 切换用户当前身份
|
|
|
|
|
* @param {Object} value 身份值
|
|
|
|
|
*/
|
|
|
|
|
export function changeUserType(value) {
|
2025-03-27 09:50:13 +08:00
|
|
|
|
setStrData(constant.userTypeKey, value)
|
2025-03-21 17:57:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-31 14:31:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取用户当前身份
|
|
|
|
|
* @param {Object} value 身份值
|
|
|
|
|
*/
|
|
|
|
|
export function getUserType() {
|
|
|
|
|
return getStrData(constant.userTypeKey)
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2025-04-14 14:24:40 +08:00
|
|
|
|
if (!num) {
|
|
|
|
|
return '无限制';
|
|
|
|
|
}
|
2025-03-26 10:09:11 +08:00
|
|
|
|
const units = ['', 'k', 'w', 'kw'];
|
2025-03-31 14:31:41 +08:00
|
|
|
|
// 获取绝对值以处理负数
|
|
|
|
|
let absNum = Math.abs(num);
|
2025-03-26 10:09:11 +08:00
|
|
|
|
// 处理小于1000的情况,直接返回原数字的字符串形式
|
|
|
|
|
if (absNum < 1000) {
|
2025-03-31 14:31:41 +08:00
|
|
|
|
return num;
|
2025-03-26 10:09:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-14 14:24:40 +08:00
|
|
|
|
|
2025-03-26 10:09:11 +08:00
|
|
|
|
// 寻找合适的单位
|
|
|
|
|
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];
|
2025-03-27 09:50:13 +08:00
|
|
|
|
}
|
2025-03-31 14:31:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算某个时间是几天、几小时之前
|
|
|
|
|
* @param {Object} time
|
|
|
|
|
*/
|
|
|
|
|
export function calculateTimeDifference(time) {
|
|
|
|
|
// 将时间字符串转换为Date对象
|
|
|
|
|
const nowDate = new Date();
|
|
|
|
|
const lastDate = new Date(time);
|
|
|
|
|
|
|
|
|
|
// 计算时间差(毫秒)
|
|
|
|
|
const diffMs = Math.abs(nowDate.getTime() - lastDate.getTime());
|
|
|
|
|
|
|
|
|
|
// 将毫秒转换为小时
|
|
|
|
|
const diffHours = diffMs / (1000 * 60 * 60);
|
|
|
|
|
|
|
|
|
|
// 计算完整的整天天数和剩余的小时数
|
|
|
|
|
const diffDays = Math.floor(diffHours / 24);
|
|
|
|
|
const remainingHours = diffHours % 24;
|
|
|
|
|
if (diffDays > 0) {
|
|
|
|
|
return parseInt(diffDays) + "天前"
|
|
|
|
|
} else {
|
2025-04-14 14:24:40 +08:00
|
|
|
|
if (parseInt(remainingHours) == 0) {
|
|
|
|
|
return "刚刚"
|
|
|
|
|
} else {
|
|
|
|
|
return parseInt(remainingHours) + "小时前"
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-31 14:31:41 +08:00
|
|
|
|
}
|
2025-04-09 15:00:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 翻译认证身份类型
|
|
|
|
|
* @param {Object} key
|
|
|
|
|
*/
|
|
|
|
|
export function getTextByIdentityType(key) {
|
|
|
|
|
if ("01" == key) {
|
|
|
|
|
return "品牌方"
|
|
|
|
|
} else if ("02" == key) {
|
|
|
|
|
return "代运营公司"
|
|
|
|
|
} else if ("03" == key) {
|
|
|
|
|
return "个人PR"
|
|
|
|
|
} else if ("04" == key) {
|
|
|
|
|
return "电商"
|
|
|
|
|
}
|
2025-04-14 14:24:40 +08:00
|
|
|
|
}
|
2025-04-15 15:00:48 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化数字
|
|
|
|
|
* @param {Object} number
|
|
|
|
|
*/
|
|
|
|
|
export function formatNumberWithCommas(number) {
|
|
|
|
|
return new Intl.NumberFormat().format(number);
|
|
|
|
|
}
|