WMS_PDA/src/core/request/index.js
liufumingren e8db7a2293 feat: 退件收件任务模块(列表/扫码登记/扫描记录/导出)+ 库存盘点作业页完善
- 退件收件:returnRecord 改为收件任务列表(默认只看本人创建、可切全部、新建任务默认「用户名 当天日期」、左滑删除),扫码登记抽到 ReturnScanPanel 组件并由 returnRecordScan 页面承载,登记带 return_received_task_id

- 扫描记录:按任务 ID 过滤、底部剩余空间独立滚动(上拉/点击加载更多、下拉刷新)、标题显示任务登记总条数、原单退回显示货主名、常用备注抽屉(localStorage)、导出(异步任务+进度轮询+二维码/复制链接)

- 库存盘点:库位/商品/单库位作业页拆分与 workDataDetail/workDataSpaceDetails/recordList 接入;App.vue 图片预览层 z-index、auth-guard 整页启动路由修复;apis.js 补 returnReceivedTask/returnReceived.list/export 与漏登记保护
2026-10-06 04:49:40 +08:00

120 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import coreRequest from './request'
import apiList from './apis.js'
import store from '@/core/store/index.js'
import { setToken,removeToken } from '../utils/auth';
import router from '@/core/router'
import { handleTokenExpired } from '@/core/utils/auth-guard'
const Request = new coreRequest();
export default function http(
url,
data = {},
toastBefore = '', // 请求前加载提示
toastAfter = true, // 请求后错误提示
responseType = 'text',
timeout = 0 // 自定义请求超时(ms),0 表示使用默认 20s;长轮询接口需传入大于服务端等待时长的值
) {
let api = getApiPath(url);
console.log(api);
const token = uni.getStorageSync('token');
console.log('[Request] token:', token);
if (api.auth && !token) {
store.dispatch('logout');
uni.hideLoading();
return Promise.reject({
msg: `暂未登录,已阻止此次API请求: '${api.url}'`
});
}
/* 请求之前拦截器 */
Request.interceptor.request((config, cancel) => {
token && Request.setConfig(config => {
config.header.authorization = `Bearer ${token}`
console.log('[Request] Authorization:', config.header.authorization);
})
if (toastBefore !== '') {
uni.showLoading({
title: toastBefore,
mask: true
});
}
return config
});
/* 请求之后拦截器 */
Request.interceptor.response((res) => {
const headers = res.header;
console.log(res);
const response = res.data;
const getHeaderValue = (headerMap, key) => {
if (!headerMap) {
return '';
}
const targetKey = Object.keys(headerMap).find(item => String(item).toLowerCase() === String(key).toLowerCase());
return targetKey ? headerMap[targetKey] : '';
};
const normalizeToken = (rawToken) => {
if (!rawToken) {
return '';
}
const text = String(rawToken).trim();
if (!text) {
return '';
}
return text.startsWith('Bearer ') ? text.substring(7).trim() : text;
};
const token =
getHeaderValue(headers, 'authorization') ||
getHeaderValue(headers, 'token') ||
getHeaderValue(headers, 'x-access-token') ||
getHeaderValue(headers, 'access-token');
const normalizedToken = normalizeToken(token);
if (normalizedToken) {
setToken(normalizedToken)
}
uni.hideLoading();
if (response?.flag === "failure") {
if (toastAfter) {
uni.showToast({
title: response.message || '请求出错,稍后重试',
icon: 'none',
duration: 1000,
mask: true
});
}
}
// token过期注销
if (res.statusCode === 401) {
handleTokenExpired(store)
return Promise.reject({
msg: '登录已过期,请重新登录'
})
}
return response
})
return Request.request({
url: api.url,
path: api.path,
data,
method: api.method,
responseType,
...(timeout ? { timeout } : {})
})
}
// 组装接口路径
function getApiPath(url) {
let apiArray = url.split(".");
let api = apiList;
apiArray.forEach(v => {
api = api[v];
});
// 未登记时报错信息要可读,避免出现 "Cannot read properties of undefined (reading 'auth')"
if (!api || typeof api !== 'object' || !api.path) {
throw new Error(`接口未注册: ${url}(请在 core/request/apis.js 中登记)`);
}
return api;
}