新增数据,开始安全巡检模块
This commit is contained in:
@@ -35,6 +35,15 @@ const service = axios.create({
|
||||
}
|
||||
});
|
||||
|
||||
// 不需要小区id 或者 加上小区id报错的接口地址
|
||||
const whiteVillageId = ['/decoration/list', '/parking/list'];
|
||||
function handleWhiteVillageid(url) {
|
||||
const spliturl = url.split('?')[0];
|
||||
if (whiteVillageId.includes(spliturl)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
@@ -51,17 +60,41 @@ service.interceptors.request.use(
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
}
|
||||
// get请求映射params参数
|
||||
const villageid = localStorage.getItem('villageid');
|
||||
if (config.method === 'get' && config.params) {
|
||||
let url = config.url + '?' + tansParams(config.params);
|
||||
let url = '';
|
||||
if (villageid != 'null' && !Number.isNaN(Number(villageid)) && handleWhiteVillageid(config.url)) {
|
||||
url =
|
||||
config.url +
|
||||
'?' +
|
||||
tansParams({
|
||||
...config.params,
|
||||
villageId: Number(villageid)
|
||||
});
|
||||
} else {
|
||||
url = config.url + '?' + tansParams(config.params);
|
||||
}
|
||||
url = url.slice(0, -1);
|
||||
config.params = {};
|
||||
config.url = url;
|
||||
}
|
||||
|
||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||
let obj = null;
|
||||
if (villageid != 'null' && !Number.isNaN(Number(villageid)) && handleWhiteVillageid(config.url)) {
|
||||
obj = {
|
||||
...config.data,
|
||||
villageId: Number(villageid)
|
||||
};
|
||||
} else {
|
||||
obj = config.data;
|
||||
}
|
||||
if (!config.data) config.data = {};
|
||||
Object.assign(config.data, obj);
|
||||
|
||||
const requestObj = {
|
||||
url: config.url,
|
||||
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
||||
data: typeof obj === 'object' ? JSON.stringify(obj) : obj,
|
||||
time: new Date().getTime()
|
||||
};
|
||||
const sessionObj = cache.session.getJSON('sessionObj');
|
||||
@@ -128,6 +161,7 @@ service.interceptors.response.use(
|
||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
if (code === 401) {
|
||||
// prettier-ignore
|
||||
if (!isRelogin.show) {
|
||||
@@ -151,12 +185,15 @@ service.interceptors.response.use(
|
||||
});
|
||||
}
|
||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
|
||||
// 500
|
||||
} else if (code === HttpStatus.SERVER_ERROR) {
|
||||
// 500
|
||||
console.log(res);
|
||||
|
||||
console.log(res.config.url.split('?')[0]);
|
||||
ElMessage({ message: msg, type: 'error' });
|
||||
return Promise.reject(res.data);
|
||||
// 601
|
||||
} else if (code === HttpStatus.WARN) {
|
||||
// 601
|
||||
ElMessage({ message: msg, type: 'warning' });
|
||||
return Promise.reject(new Error(msg));
|
||||
} else if (code !== HttpStatus.SUCCESS) {
|
||||
|
||||
@@ -64,3 +64,54 @@ export function formatTimeDiff(startTime: string | number | Date, endTime: strin
|
||||
|
||||
return res.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成指定日期所在周的日期数组(周一到周日)
|
||||
* @param date 基准日期,默认今天
|
||||
* @param format 返回格式
|
||||
* @returns 一周日期数组
|
||||
*/
|
||||
export function generateWeekDays(date: Date | string | number = new Date(), format: 'name' | 'date' | 'full' = 'name'): string[] {
|
||||
const weekNames = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
const baseDate = new Date(date);
|
||||
|
||||
// 计算本周一的日期(getDay() 0=周日,1=周一)
|
||||
const day = baseDate.getDay();
|
||||
const monday = new Date(baseDate);
|
||||
monday.setDate(baseDate.getDate() - (day === 0 ? 6 : day - 1));
|
||||
|
||||
// 生成周一到周日7天
|
||||
const week = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const current = new Date(monday);
|
||||
current.setDate(monday.getDate() + i);
|
||||
|
||||
if (format === 'name') {
|
||||
week.push(weekNames[i]);
|
||||
} else if (format === 'date') {
|
||||
// YYYY-MM-DD 格式
|
||||
const year = current.getFullYear();
|
||||
const month = String(current.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(current.getDate()).padStart(2, '0');
|
||||
week.push(`${year}-${month}-${day}`);
|
||||
} else {
|
||||
// 完整格式:周一 (2026-04-20)
|
||||
const year = current.getFullYear();
|
||||
const month = String(current.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(current.getDate()).padStart(2, '0');
|
||||
week.push(`${weekNames[i]} (${year}-${month}-${day})`);
|
||||
}
|
||||
}
|
||||
|
||||
return week;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数字 1-7 生成对应星期
|
||||
* @param num 1=周一,2=周二...7=周日
|
||||
* @returns 周一 / 周二 ... / 周日
|
||||
*/
|
||||
export function numToWeek(num: number): string {
|
||||
const weekMap = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
return weekMap[num - 1] || '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user