2025-08-06 18:00:28 +08:00
|
|
|
|
import request from "@/utils/request";
|
|
|
|
|
|
import {
|
|
|
|
|
|
setStorageWithExpiry,
|
|
|
|
|
|
getStorageWithExpiry
|
|
|
|
|
|
} from './auth'
|
|
|
|
|
|
|
2024-08-21 20:18:30 +08:00
|
|
|
|
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-08-06 18:00:28 +08:00
|
|
|
|
export function formatDateTimeToMinute(timestamp) {
|
|
|
|
|
|
// 将时间戳转换为 Date 对象
|
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
|
// 获取年月日时分
|
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
|
const hours = date.getHours().toString().padStart(2, '0');
|
|
|
|
|
|
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
|
// 组合成日期时间字符串(格式:yyyy-MM-dd hh:mm)
|
|
|
|
|
|
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function formatDateChinese(timestamp) {
|
|
|
|
|
|
// 将时间戳转换为Date对象
|
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
|
// 获取年月日时分秒
|
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
|
// 组合成日期时间字符串
|
|
|
|
|
|
return `${year}年${month}月${day}日`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function formatDate(timestamp) {
|
|
|
|
|
|
// 将时间戳转换为Date对象
|
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
|
// 获取年月日时分秒
|
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
|
// 组合成日期时间字符串
|
|
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 角色权限校验
|
|
|
|
|
|
* @param dictType 校验值
|
|
|
|
|
|
* @returns {Boolean}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function ifHasRoleByDictType(dictType) {
|
|
|
|
|
|
const res = await request({
|
|
|
|
|
|
url: '/partnerOwn/partner/ifHasRole',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
params: {
|
|
|
|
|
|
dictType
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return res.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function getDictDataByType(type) {
|
|
|
|
|
|
let data = getStorageWithExpiry(type);
|
|
|
|
|
|
if (data === null || data === undefined || data.length == 0) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await request({
|
|
|
|
|
|
url: '/system/dict-data/type',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
params: {
|
|
|
|
|
|
type
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
data = response.data;
|
|
|
|
|
|
setStorageWithExpiry(type, data, 3600); // 存储数据并设置过期时间
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("请求字典数据时出现了异常:", error);
|
|
|
|
|
|
throw error; // 确保错误能够被外部捕获
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
|
|
|
}
|
2025-08-29 17:13:05 +08:00
|
|
|
|
|
|
|
|
|
|
export async function getDictDataById(id) {
|
|
|
|
|
|
let data = getStorageWithExpiry(id);
|
|
|
|
|
|
if (data === null || data === undefined || data.length == 0) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await request({
|
|
|
|
|
|
url: '/system/dict-data/get',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
params: {
|
|
|
|
|
|
id
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
data = response.data;
|
|
|
|
|
|
setStorageWithExpiry(id, data, 3600); // 存储数据并设置过期时间
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("请求字典数据时出现了异常:", error);
|
|
|
|
|
|
throw error; // 确保错误能够被外部捕获
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
|
|
|
}
|
2025-10-17 15:25:04 +08:00
|
|
|
|
|
|
|
|
|
|
export function getDateRange(type) {
|
|
|
|
|
|
const now = new Date()
|
|
|
|
|
|
let start, end
|
|
|
|
|
|
|
|
|
|
|
|
if (type === 'week') {
|
|
|
|
|
|
// 获取本周的开始(周一)和结束(周日)
|
|
|
|
|
|
const day = now.getDay() || 7 // Sunday 为 0,设为 7
|
|
|
|
|
|
start = new Date(now)
|
|
|
|
|
|
start.setDate(now.getDate() - day + 1)
|
|
|
|
|
|
|
|
|
|
|
|
end = new Date(start)
|
|
|
|
|
|
end.setDate(start.getDate() + 6)
|
|
|
|
|
|
} else if (type === 'month') {
|
|
|
|
|
|
// 获取本月的开始和结束
|
|
|
|
|
|
start = new Date(now.getFullYear(), now.getMonth(), 1)
|
|
|
|
|
|
end = new Date(now.getFullYear(), now.getMonth() + 1, 0) // 本月最后一天
|
|
|
|
|
|
}else if (type === 'day') {
|
|
|
|
|
|
// 获取当天的开始和结束(00:00:00 到 23:59:59)
|
|
|
|
|
|
start = new Date(now)
|
|
|
|
|
|
start.setHours(0, 0, 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
end = new Date(now)
|
|
|
|
|
|
end.setHours(23, 59, 59, 999)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.warn('不支持的类型:', type)
|
|
|
|
|
|
return []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
formatDateCus(start),
|
|
|
|
|
|
formatDateCus(end)
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function formatDateCus(date) {
|
|
|
|
|
|
const y = date.getFullYear()
|
|
|
|
|
|
const m = (date.getMonth() + 1).toString().padStart(2, '0')
|
|
|
|
|
|
const d = date.getDate().toString().padStart(2, '0')
|
|
|
|
|
|
return `${y}-${m}-${d}`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-21 20:18:30 +08:00
|
|
|
|
export {
|
|
|
|
|
|
getWXStatusHeight,
|
|
|
|
|
|
}
|