|
@@ -2,12 +2,11 @@ import { removeToken } from '@/utils/token-util';
|
|
|
import axios from 'axios';
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
export async function downloadOssLink(url, name) {
|
|
export async function downloadOssLink(url, name) {
|
|
|
- const res = await axios.get(url, {
|
|
|
|
|
- responseType: 'blob' // 设置响应类型为blob,以便处理二进制数据
|
|
|
|
|
- });
|
|
|
|
|
- console.log(res, '12321321');
|
|
|
|
|
- await checkDownloadRes(res);
|
|
|
|
|
- download(res.data, `${name}_${Date.now()}.xlsx`);
|
|
|
|
|
|
|
+ const res = await axios.get(url, {
|
|
|
|
|
+ responseType: 'blob' // 设置响应类型为blob,以便处理二进制数据
|
|
|
|
|
+ });
|
|
|
|
|
+ await checkDownloadRes(res);
|
|
|
|
|
+ download(res.data, `${name}_${Date.now()}.xlsx`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -17,18 +16,18 @@ export async function downloadOssLink(url, name) {
|
|
|
* @param push 路由跳转方法
|
|
* @param push 路由跳转方法
|
|
|
*/
|
|
*/
|
|
|
export function logout(route, from, push) {
|
|
export function logout(route, from, push) {
|
|
|
- removeToken();
|
|
|
|
|
- if (route && push) {
|
|
|
|
|
- push({
|
|
|
|
|
- path: '/login',
|
|
|
|
|
- query: from ? { from: encodeURIComponent(from) } : void 0
|
|
|
|
|
- });
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- // 这样跳转避免再次登录重复注册动态路由, hash 路由模式使用 location.reload();
|
|
|
|
|
- const BASE_URL = import.meta.env.BASE_URL;
|
|
|
|
|
- const url = BASE_URL + 'login';
|
|
|
|
|
- location.replace(from ? `${url}?from=${encodeURIComponent(from)}` : url);
|
|
|
|
|
|
|
+ removeToken();
|
|
|
|
|
+ if (route && push) {
|
|
|
|
|
+ push({
|
|
|
|
|
+ path: '/login',
|
|
|
|
|
+ query: from ? { from: encodeURIComponent(from) } : void 0
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 这样跳转避免再次登录重复注册动态路由, hash 路由模式使用 location.reload();
|
|
|
|
|
+ const BASE_URL = import.meta.env.BASE_URL;
|
|
|
|
|
+ const url = BASE_URL + 'login';
|
|
|
|
|
+ location.replace(from ? `${url}?from=${encodeURIComponent(from)}` : url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,16 +37,16 @@ export function logout(route, from, push) {
|
|
|
* @param type 文件类型
|
|
* @param type 文件类型
|
|
|
*/
|
|
*/
|
|
|
export function download(data, name, type) {
|
|
export function download(data, name, type) {
|
|
|
- const blob = new Blob([data], { type: type || 'application/octet-stream' });
|
|
|
|
|
- const url = URL.createObjectURL(blob);
|
|
|
|
|
- const a = document.createElement('a');
|
|
|
|
|
- a.href = url;
|
|
|
|
|
- a.download = name;
|
|
|
|
|
- a.style.display = 'none';
|
|
|
|
|
- document.body.appendChild(a);
|
|
|
|
|
- a.click();
|
|
|
|
|
- document.body.removeChild(a);
|
|
|
|
|
- URL.revokeObjectURL(url);
|
|
|
|
|
|
|
+ const blob = new Blob([data], { type: type || 'application/octet-stream' });
|
|
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
|
|
+ const a = document.createElement('a');
|
|
|
|
|
+ a.href = url;
|
|
|
|
|
+ a.download = name;
|
|
|
|
|
+ a.style.display = 'none';
|
|
|
|
|
+ document.body.appendChild(a);
|
|
|
|
|
+ a.click();
|
|
|
|
|
+ document.body.removeChild(a);
|
|
|
|
|
+ URL.revokeObjectURL(url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -56,16 +55,16 @@ export function download(data, name, type) {
|
|
|
* @param url 需要拼接参数的地址
|
|
* @param url 需要拼接参数的地址
|
|
|
*/
|
|
*/
|
|
|
export function toURLSearch(params, url) {
|
|
export function toURLSearch(params, url) {
|
|
|
- if (typeof params !== 'object' || params == null) {
|
|
|
|
|
- return '';
|
|
|
|
|
- }
|
|
|
|
|
- const result = transformParams(params)
|
|
|
|
|
- .map((d) => `${encodeURIComponent(d[0])}=${encodeURIComponent(d[1])}`)
|
|
|
|
|
- .join('&');
|
|
|
|
|
- if (!url) {
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
- return (url.includes('?') ? `${url}&` : `${url}?`) + result;
|
|
|
|
|
|
|
+ if (typeof params !== 'object' || params == null) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ const result = transformParams(params)
|
|
|
|
|
+ .map((d) => `${encodeURIComponent(d[0])}=${encodeURIComponent(d[1])}`)
|
|
|
|
|
+ .join('&');
|
|
|
|
|
+ if (!url) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ return (url.includes('?') ? `${url}&` : `${url}?`) + result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -73,14 +72,14 @@ export function toURLSearch(params, url) {
|
|
|
* @param params 参数
|
|
* @param params 参数
|
|
|
*/
|
|
*/
|
|
|
export function toFormData(params) {
|
|
export function toFormData(params) {
|
|
|
- const formData = new FormData();
|
|
|
|
|
- if (typeof params !== 'object' || params == null) {
|
|
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ if (typeof params !== 'object' || params == null) {
|
|
|
|
|
+ return formData;
|
|
|
|
|
+ }
|
|
|
|
|
+ transformParams(params).forEach((d) => {
|
|
|
|
|
+ formData.append(d[0], d[1]);
|
|
|
|
|
+ });
|
|
|
return formData;
|
|
return formData;
|
|
|
- }
|
|
|
|
|
- transformParams(params).forEach((d) => {
|
|
|
|
|
- formData.append(d[0], d[1]);
|
|
|
|
|
- });
|
|
|
|
|
- return formData;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -88,26 +87,26 @@ export function toFormData(params) {
|
|
|
* @param params 参数
|
|
* @param params 参数
|
|
|
*/
|
|
*/
|
|
|
export function transformParams(params) {
|
|
export function transformParams(params) {
|
|
|
- const result = [];
|
|
|
|
|
- if (params != null && typeof params === 'object') {
|
|
|
|
|
- Object.keys(params).forEach((key) => {
|
|
|
|
|
- const value = params[key];
|
|
|
|
|
- if (value != null && value !== '') {
|
|
|
|
|
- if (Array.isArray(value) && value.length && isBlobFile(value[0])) {
|
|
|
|
|
- value.forEach((file) => {
|
|
|
|
|
- result.push([key, file]);
|
|
|
|
|
- });
|
|
|
|
|
- } else if (typeof value === 'object' && !isBlobFile(value)) {
|
|
|
|
|
- getObjectParamsArray(value).forEach((item) => {
|
|
|
|
|
- result.push([`${key}${item[0]}`, item[1]]);
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- result.push([key, value]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ const result = [];
|
|
|
|
|
+ if (params != null && typeof params === 'object') {
|
|
|
|
|
+ Object.keys(params).forEach((key) => {
|
|
|
|
|
+ const value = params[key];
|
|
|
|
|
+ if (value != null && value !== '') {
|
|
|
|
|
+ if (Array.isArray(value) && value.length && isBlobFile(value[0])) {
|
|
|
|
|
+ value.forEach((file) => {
|
|
|
|
|
+ result.push([key, file]);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (typeof value === 'object' && !isBlobFile(value)) {
|
|
|
|
|
+ getObjectParamsArray(value).forEach((item) => {
|
|
|
|
|
+ result.push([`${key}${item[0]}`, item[1]]);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.push([key, value]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -115,21 +114,21 @@ export function transformParams(params) {
|
|
|
* @param obj 对象
|
|
* @param obj 对象
|
|
|
*/
|
|
*/
|
|
|
export function getObjectParamsArray(obj) {
|
|
export function getObjectParamsArray(obj) {
|
|
|
- const result = [];
|
|
|
|
|
- Object.keys(obj).forEach((key) => {
|
|
|
|
|
- const value = obj[key];
|
|
|
|
|
- if (value != null && value !== '') {
|
|
|
|
|
- const name = `[${key}]`;
|
|
|
|
|
- if (typeof value === 'object' && !isBlobFile(value)) {
|
|
|
|
|
- getObjectParamsArray(value).forEach((item) => {
|
|
|
|
|
- result.push([`${name}${item[0]}`, item[1]]);
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- result.push([name, value]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ const result = [];
|
|
|
|
|
+ Object.keys(obj).forEach((key) => {
|
|
|
|
|
+ const value = obj[key];
|
|
|
|
|
+ if (value != null && value !== '') {
|
|
|
|
|
+ const name = `[${key}]`;
|
|
|
|
|
+ if (typeof value === 'object' && !isBlobFile(value)) {
|
|
|
|
|
+ getObjectParamsArray(value).forEach((item) => {
|
|
|
|
|
+ result.push([`${name}${item[0]}`, item[1]]);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.push([name, value]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -137,7 +136,7 @@ export function getObjectParamsArray(obj) {
|
|
|
* @param obj 对象
|
|
* @param obj 对象
|
|
|
*/
|
|
*/
|
|
|
export function isBlobFile(obj) {
|
|
export function isBlobFile(obj) {
|
|
|
- return obj != null && (obj instanceof Blob || obj instanceof File);
|
|
|
|
|
|
|
+ return obj != null && (obj instanceof Blob || obj instanceof File);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -145,13 +144,13 @@ export function isBlobFile(obj) {
|
|
|
* @param res 请求结果
|
|
* @param res 请求结果
|
|
|
*/
|
|
*/
|
|
|
export async function checkDownloadRes(res) {
|
|
export async function checkDownloadRes(res) {
|
|
|
- if (res.headers['content-type'].startsWith('application/json')) {
|
|
|
|
|
- const json = await res.data.text();
|
|
|
|
|
- return Promise.reject(
|
|
|
|
|
- new Error(JSON.parse(json).msg || '系统未知错误,请反馈给管理员')
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ if (res.headers['content-type'].startsWith('application/json')) {
|
|
|
|
|
+ const json = await res.data.text();
|
|
|
|
|
+ return Promise.reject(
|
|
|
|
|
+ new Error(JSON.parse(json).msg || '系统未知错误,请反馈给管理员')
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -161,39 +160,51 @@ export async function checkDownloadRes(res) {
|
|
|
* @param isOut 是否是退出方向
|
|
* @param isOut 是否是退出方向
|
|
|
*/
|
|
*/
|
|
|
export function doWithTransition(callback, el, isOut) {
|
|
export function doWithTransition(callback, el, isOut) {
|
|
|
- if (!el || typeof document.startViewTransition !== 'function') {
|
|
|
|
|
- callback().then(() => {});
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- document.documentElement.classList.add('disabled-transition');
|
|
|
|
|
- el.classList.add('view-transition-trigger');
|
|
|
|
|
- el.style.setProperty('view-transition-name', 'view-transition-trigger');
|
|
|
|
|
- const rect = el.getBoundingClientRect();
|
|
|
|
|
- const x = rect.left + rect.width / 2;
|
|
|
|
|
- const y = rect.top + rect.height / 2;
|
|
|
|
|
- const endRadius = Math.hypot(
|
|
|
|
|
- Math.max(x, innerWidth - x),
|
|
|
|
|
- Math.max(y, innerHeight - y)
|
|
|
|
|
- );
|
|
|
|
|
- document.startViewTransition(callback).ready.then(() => {
|
|
|
|
|
- const clipPath = [
|
|
|
|
|
- `circle(0px at ${x}px ${y}px)`,
|
|
|
|
|
- `circle(${endRadius}px at ${x}px ${y}px)`
|
|
|
|
|
- ];
|
|
|
|
|
- const anim = document.documentElement.animate(
|
|
|
|
|
- { clipPath: isOut ? [...clipPath].reverse() : clipPath },
|
|
|
|
|
- {
|
|
|
|
|
- duration: 400,
|
|
|
|
|
- easing: 'ease-in',
|
|
|
|
|
- pseudoElement: isOut
|
|
|
|
|
- ? `::view-transition-old(root)`
|
|
|
|
|
- : `::view-transition-new(root)`
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!el || typeof document.startViewTransition !== 'function') {
|
|
|
|
|
+ callback().then(() => { });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ document.documentElement.classList.add('disabled-transition');
|
|
|
|
|
+ el.classList.add('view-transition-trigger');
|
|
|
|
|
+ el.style.setProperty('view-transition-name', 'view-transition-trigger');
|
|
|
|
|
+ const rect = el.getBoundingClientRect();
|
|
|
|
|
+ const x = rect.left + rect.width / 2;
|
|
|
|
|
+ const y = rect.top + rect.height / 2;
|
|
|
|
|
+ const endRadius = Math.hypot(
|
|
|
|
|
+ Math.max(x, innerWidth - x),
|
|
|
|
|
+ Math.max(y, innerHeight - y)
|
|
|
);
|
|
);
|
|
|
- anim.onfinish = () => {
|
|
|
|
|
- el.style.removeProperty('view-transition-name');
|
|
|
|
|
- el.classList.remove('view-transition-trigger');
|
|
|
|
|
- document.documentElement.classList.remove('disabled-transition');
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ document.startViewTransition(callback).ready.then(() => {
|
|
|
|
|
+ const clipPath = [
|
|
|
|
|
+ `circle(0px at ${x}px ${y}px)`,
|
|
|
|
|
+ `circle(${endRadius}px at ${x}px ${y}px)`
|
|
|
|
|
+ ];
|
|
|
|
|
+ const anim = document.documentElement.animate(
|
|
|
|
|
+ { clipPath: isOut ? [...clipPath].reverse() : clipPath },
|
|
|
|
|
+ {
|
|
|
|
|
+ duration: 400,
|
|
|
|
|
+ easing: 'ease-in',
|
|
|
|
|
+ pseudoElement: isOut
|
|
|
|
|
+ ? `::view-transition-old(root)`
|
|
|
|
|
+ : `::view-transition-new(root)`
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ anim.onfinish = () => {
|
|
|
|
|
+ el.style.removeProperty('view-transition-name');
|
|
|
|
|
+ el.classList.remove('view-transition-trigger');
|
|
|
|
|
+ document.documentElement.classList.remove('disabled-transition');
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+//格式化手机号
|
|
|
|
|
+export function formatPhone(phone) {
|
|
|
|
|
+ if (!phone) return '-';
|
|
|
|
|
+ return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
|
|
|
|
|
+}
|
|
|
|
|
+//格式化姓名 只保留第一个字,其他用*代替
|
|
|
|
|
+export function formatName(name) {
|
|
|
|
|
+ if (!name) return '-';
|
|
|
|
|
+ return name.substring(0, 1) + '*'.repeat(name.length - 1);
|
|
|
}
|
|
}
|
|
|
|
|
+
|