设备管理,设备列表,客户列表功能完善提交

This commit is contained in:
fengerli
2025-07-05 14:30:12 +08:00
parent 1aa9eb23e0
commit 9715c8755d
22 changed files with 633 additions and 326 deletions

View File

@ -3,6 +3,11 @@ const TokenKey = 'Admin-Token';
const tokenStorage = useStorage<null | string>(TokenKey, null);
export const getToken = () => tokenStorage.value;
//添加token特殊处理没有应用到全局
export const getBearerToken = () => ({
Authorization: tokenStorage.value ? `Bearer ${tokenStorage.value}` : undefined,
clientid: import.meta.env.VITE_APP_CLIENT_ID,
});
export const setToken = (access_token: string) => (tokenStorage.value = access_token);

View File

@ -146,7 +146,7 @@ service.interceptors.response.use(
isRelogin.show = false;
});
}
return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
return Promise.reject('token已过期,请重新登录。');
} else if (code === HttpStatus.SERVER_ERROR) {
ElMessage({ message: msg, type: 'error' });
return Promise.reject(new Error(msg));
@ -173,19 +173,28 @@ service.interceptors.response.use(
return Promise.reject(error);
}
);
// 通用下载方法
export function download(url: string, params: any, fileName: string) {
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
// prettier-ignore
return service.post(url, params, {
transformRequest: [
(params: any) => {
return tansParams(params);
}
],
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'blob'
}).then(async (resp: any) => {
// 通用下载方法 get 跟post下载方式
export function download(url: string, params: any, fileName: string, method: 'get' | 'post' = 'post') {
downloadLoadingInstance = ElLoading.service({
text: '正在下载数据,请稍候',
background: 'rgba(0, 0, 0, 0.7)'
});
// 请求配置
const config = {
method,
responseType: 'blob',
[method === 'get' ? 'params' : 'data']: method === 'get' ? params : tansParams(params),
headers: {
'Content-Type': method === 'get'
? 'application/json'
: 'application/x-www-form-urlencoded'
}
};
return service.request({
url,
...config
})
.then(async (resp: any) => {
const isLogin = blobValidate(resp);
if (isLogin) {
const blob = new Blob([resp]);
@ -203,6 +212,7 @@ export function download(url: string, params: any, fileName: string) {
ElMessage.error('下载文件出现错误,请联系管理员!');
downloadLoadingInstance.close();
});
}
// 导出 axios 实例
export default service;