mirror of
https://gitee.com/log4j/pig-ui.git
synced 2025-01-03 23:42:23 +08:00
🐛 Fixing a bug. tagsViewName正则匹配错误,匹配到含en单词
This commit is contained in:
parent
744caa4a51
commit
237edb87d1
@ -8,10 +8,10 @@ import { useThemeConfig } from '/@/stores/themeConfig';
|
|||||||
import { i18n } from '/@/i18n/index';
|
import { i18n } from '/@/i18n/index';
|
||||||
import { Local } from '/@/utils/storage';
|
import { Local } from '/@/utils/storage';
|
||||||
import { verifyUrl } from '/@/utils/toolsValidate';
|
import { verifyUrl } from '/@/utils/toolsValidate';
|
||||||
import request from "/@/utils/request";
|
import request from '/@/utils/request';
|
||||||
import { useMessage } from "/@/hooks/message";
|
import { useMessage } from '/@/hooks/message';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import * as CryptoJS from "crypto-js";
|
import * as CryptoJS from 'crypto-js';
|
||||||
|
|
||||||
// 引入组件
|
// 引入组件
|
||||||
const SvgIcon = defineAsyncComponent(() => import('/@/components/svgIcon/index.vue'));
|
const SvgIcon = defineAsyncComponent(() => import('/@/components/svgIcon/index.vue'));
|
||||||
@ -57,8 +57,10 @@ export function useTitle() {
|
|||||||
export function setTagsViewNameI18n(item: any) {
|
export function setTagsViewNameI18n(item: any) {
|
||||||
let tagsViewName: string = '';
|
let tagsViewName: string = '';
|
||||||
const { query, params, meta } = item;
|
const { query, params, meta } = item;
|
||||||
|
//修复tagsViewName匹配到其他含下列单词的路由
|
||||||
|
const pattern = /^\{("(zh-cn|en|zh-tw)":"[^,]+",?){1,3}}$/;
|
||||||
if (query?.tagsViewName || params?.tagsViewName) {
|
if (query?.tagsViewName || params?.tagsViewName) {
|
||||||
if (/\/zh-cn|en|zh-tw\//.test(query?.tagsViewName) || /\/zh-cn|en|zh-tw\//.test(params?.tagsViewName)) {
|
if (pattern.test(query?.tagsViewName) || pattern.test(params?.tagsViewName)) {
|
||||||
// 国际化
|
// 国际化
|
||||||
const urlTagsParams = (query?.tagsViewName && JSON.parse(query?.tagsViewName)) || (params?.tagsViewName && JSON.parse(params?.tagsViewName));
|
const urlTagsParams = (query?.tagsViewName && JSON.parse(query?.tagsViewName)) || (params?.tagsViewName && JSON.parse(params?.tagsViewName));
|
||||||
tagsViewName = urlTagsParams[i18n.global.locale.value];
|
tagsViewName = urlTagsParams[i18n.global.locale.value];
|
||||||
@ -180,35 +182,29 @@ export function handleOpenLink(val: RouteItem) {
|
|||||||
*/
|
*/
|
||||||
export const openWindow = (url: string, title: string, w: number, h: number) => {
|
export const openWindow = (url: string, title: string, w: number, h: number) => {
|
||||||
// Fixes dual-screen position Most browsers Firefox
|
// Fixes dual-screen position Most browsers Firefox
|
||||||
const dualScreenLeft =
|
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
|
||||||
window.screenLeft !== undefined ? window.screenLeft : screen.left;
|
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;
|
||||||
const dualScreenTop =
|
|
||||||
window.screenTop !== undefined ? window.screenTop : screen.top;
|
|
||||||
|
|
||||||
const width = window.innerWidth
|
const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
||||||
? window.innerWidth
|
|
||||||
: document.documentElement.clientWidth
|
|
||||||
? document.documentElement.clientWidth
|
|
||||||
: screen.width;
|
|
||||||
const height = window.innerHeight
|
const height = window.innerHeight
|
||||||
? window.innerHeight
|
? window.innerHeight
|
||||||
: document.documentElement.clientHeight
|
: document.documentElement.clientHeight
|
||||||
? document.documentElement.clientHeight
|
? document.documentElement.clientHeight
|
||||||
: screen.height;
|
: screen.height;
|
||||||
|
|
||||||
const left = width / 2 - w / 2 + dualScreenLeft;
|
const left = width / 2 - w / 2 + dualScreenLeft;
|
||||||
const top = height / 2 - h / 2 + dualScreenTop;
|
const top = height / 2 - h / 2 + dualScreenTop;
|
||||||
return window.open(
|
return window.open(
|
||||||
url,
|
url,
|
||||||
title,
|
title,
|
||||||
"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=" +
|
'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' +
|
||||||
w +
|
w +
|
||||||
", height=" +
|
', height=' +
|
||||||
h +
|
h +
|
||||||
", top=" +
|
', top=' +
|
||||||
top +
|
top +
|
||||||
", left=" +
|
', left=' +
|
||||||
left
|
left
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -217,7 +213,7 @@ export const openWindow = (url: string, title: string, w: number, h: number) =>
|
|||||||
export function encryption(params: any) {
|
export function encryption(params: any) {
|
||||||
let { data, type, param, key } = params;
|
let { data, type, param, key } = params;
|
||||||
const result = JSON.parse(JSON.stringify(data));
|
const result = JSON.parse(JSON.stringify(data));
|
||||||
if (type === "Base64") {
|
if (type === 'Base64') {
|
||||||
param.forEach((ele: any) => {
|
param.forEach((ele: any) => {
|
||||||
result[ele] = btoa(result[ele]);
|
result[ele] = btoa(result[ele]);
|
||||||
});
|
});
|
||||||
@ -230,7 +226,7 @@ export function encryption(params: any) {
|
|||||||
var encrypted = CryptoJS.AES.encrypt(data, key, {
|
var encrypted = CryptoJS.AES.encrypt(data, key, {
|
||||||
iv: iv,
|
iv: iv,
|
||||||
mode: CryptoJS.mode.CFB,
|
mode: CryptoJS.mode.CFB,
|
||||||
padding: CryptoJS.pad.NoPadding
|
padding: CryptoJS.pad.NoPadding,
|
||||||
});
|
});
|
||||||
result[ele] = encrypted.toString();
|
result[ele] = encrypted.toString();
|
||||||
});
|
});
|
||||||
@ -248,27 +244,27 @@ export function encryption(params: any) {
|
|||||||
export function downBlobFile(url: any, query: any, fileName: string) {
|
export function downBlobFile(url: any, query: any, fileName: string) {
|
||||||
return request({
|
return request({
|
||||||
url: url,
|
url: url,
|
||||||
method: "get",
|
method: 'get',
|
||||||
responseType: "blob",
|
responseType: 'blob',
|
||||||
params: query
|
params: query,
|
||||||
}).then(response => {
|
}).then((response) => {
|
||||||
handleBlobFile(response, fileName)
|
handleBlobFile(response, fileName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* blob 文件刘处理
|
* blob 文件刘处理
|
||||||
* @param response 响应结果
|
* @param response 响应结果
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function handleBlobFile(response: any, fileName: string) {
|
export function handleBlobFile(response: any, fileName: string) {
|
||||||
// 处理返回的文件流
|
// 处理返回的文件流
|
||||||
const blob = response;
|
const blob = response;
|
||||||
if (blob && blob.size === 0) {
|
if (blob && blob.size === 0) {
|
||||||
useMessage().error("内容为空,无法下载");
|
useMessage().error('内容为空,无法下载');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const link = document.createElement("a");
|
const link = document.createElement('a');
|
||||||
|
|
||||||
// 兼容一下 入参不是 File Blob 类型情况
|
// 兼容一下 入参不是 File Blob 类型情况
|
||||||
var binaryData = [] as any;
|
var binaryData = [] as any;
|
||||||
@ -325,37 +321,37 @@ const other = {
|
|||||||
handleOpenLink(val);
|
handleOpenLink(val);
|
||||||
},
|
},
|
||||||
encryption: (data: any) => {
|
encryption: (data: any) => {
|
||||||
return encryption(data)
|
return encryption(data);
|
||||||
},
|
},
|
||||||
downBlobFile: (url: any, query: any, fileName: string) => {
|
downBlobFile: (url: any, query: any, fileName: string) => {
|
||||||
return downBlobFile(url, query, fileName)
|
return downBlobFile(url, query, fileName);
|
||||||
},
|
},
|
||||||
toUnderline: (str: string) => {
|
toUnderline: (str: string) => {
|
||||||
return toUnderline(str)
|
return toUnderline(str);
|
||||||
},
|
},
|
||||||
openWindow: (url: string, title: string, w: number, h: number) => {
|
openWindow: (url: string, title: string, w: number, h: number) => {
|
||||||
return openWindow(url, title, w, h)
|
return openWindow(url, title, w, h);
|
||||||
},
|
},
|
||||||
getQueryString: (url: string, paraName: string) => {
|
getQueryString: (url: string, paraName: string) => {
|
||||||
return getQueryString(url, paraName)
|
return getQueryString(url, paraName);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getQueryString(url: string, paraName: string) {
|
export function getQueryString(url: string, paraName: string) {
|
||||||
const arrObj = url.split("?");
|
const arrObj = url.split('?');
|
||||||
if (arrObj.length > 1) {
|
if (arrObj.length > 1) {
|
||||||
const arrPara = arrObj[1].split("&");
|
const arrPara = arrObj[1].split('&');
|
||||||
let arr;
|
let arr;
|
||||||
for (let i = 0; i < arrPara.length; i++) {
|
for (let i = 0; i < arrPara.length; i++) {
|
||||||
arr = arrPara[i].split("=");
|
arr = arrPara[i].split('=');
|
||||||
// eslint-disable-next-line eqeqeq
|
// eslint-disable-next-line eqeqeq
|
||||||
if (arr != null && arr[0] == paraName) {
|
if (arr != null && arr[0] == paraName) {
|
||||||
return arr[1];
|
return arr[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return '';
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,25 +365,31 @@ export function getQueryString(url: string, paraName: string) {
|
|||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
export function handleTree(data, id, parentId, children, rootId) {
|
export function handleTree(data, id, parentId, children, rootId) {
|
||||||
id = id || 'id'
|
id = id || 'id';
|
||||||
parentId = parentId || 'parentId'
|
parentId = parentId || 'parentId';
|
||||||
children = children || 'children'
|
children = children || 'children';
|
||||||
rootId = rootId || Math.min.apply(Math, data.map(item => {
|
rootId =
|
||||||
return item[parentId]
|
rootId ||
|
||||||
})) || 0
|
Math.min.apply(
|
||||||
|
Math,
|
||||||
|
data.map((item) => {
|
||||||
|
return item[parentId];
|
||||||
|
})
|
||||||
|
) ||
|
||||||
|
0;
|
||||||
//对源数据深度克隆
|
//对源数据深度克隆
|
||||||
const cloneData = JSON.parse(JSON.stringify(data))
|
const cloneData = JSON.parse(JSON.stringify(data));
|
||||||
//循环所有项
|
//循环所有项
|
||||||
const treeData = cloneData.filter(father => {
|
const treeData = cloneData.filter((father) => {
|
||||||
const branchArr = cloneData.filter(child => {
|
const branchArr = cloneData.filter((child) => {
|
||||||
//返回每一项的子级数组
|
//返回每一项的子级数组
|
||||||
return father[id] === child[parentId]
|
return father[id] === child[parentId];
|
||||||
})
|
});
|
||||||
branchArr.length > 0 ? father[children] = branchArr : ''
|
branchArr.length > 0 ? (father[children] = branchArr) : '';
|
||||||
//返回第一层
|
//返回第一层
|
||||||
return father[parentId] === rootId
|
return father[parentId] === rootId;
|
||||||
})
|
});
|
||||||
return treeData !== '' ? treeData : data
|
return treeData !== '' ? treeData : data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -396,9 +398,8 @@ export function handleTree(data, id, parentId, children, rootId) {
|
|||||||
* @returns 下划线
|
* @returns 下划线
|
||||||
*/
|
*/
|
||||||
export function toUnderline(str: string) {
|
export function toUnderline(str: string) {
|
||||||
return str.replace(/([A-Z])/g, "_$1").toLowerCase()
|
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 统一批量导出
|
// 统一批量导出
|
||||||
export default other;
|
export default other;
|
||||||
|
@ -8,18 +8,23 @@ import Cookies from 'js-cookie';
|
|||||||
* @method clear 移除全部永久缓存
|
* @method clear 移除全部永久缓存
|
||||||
*/
|
*/
|
||||||
export const Local = {
|
export const Local = {
|
||||||
|
// 查看 v2.4.3版本更新日志
|
||||||
|
setKey(key: string) {
|
||||||
|
// @ts-ignore
|
||||||
|
return `${__NEXT_NAME__}:${key}`;
|
||||||
|
},
|
||||||
// 设置永久缓存
|
// 设置永久缓存
|
||||||
set(key: string, val: any) {
|
set<T>(key: string, val: T) {
|
||||||
window.localStorage.setItem(key, JSON.stringify(val));
|
window.localStorage.setItem(Local.setKey(key), JSON.stringify(val));
|
||||||
},
|
},
|
||||||
// 获取永久缓存
|
// 获取永久缓存
|
||||||
get(key: string) {
|
get(key: string) {
|
||||||
let json = <string>window.localStorage.getItem(key);
|
let json = <string>window.localStorage.getItem(Local.setKey(key));
|
||||||
return JSON.parse(json);
|
return JSON.parse(json);
|
||||||
},
|
},
|
||||||
// 移除永久缓存
|
// 移除永久缓存
|
||||||
remove(key: string) {
|
remove(key: string) {
|
||||||
window.localStorage.removeItem(key);
|
window.localStorage.removeItem(Local.setKey(key));
|
||||||
},
|
},
|
||||||
// 移除全部永久缓存
|
// 移除全部永久缓存
|
||||||
clear() {
|
clear() {
|
||||||
@ -36,25 +41,24 @@ export const Local = {
|
|||||||
*/
|
*/
|
||||||
export const Session = {
|
export const Session = {
|
||||||
// 设置临时缓存
|
// 设置临时缓存
|
||||||
set(key: string, val: any) {
|
set<T>(key: string, val: T) {
|
||||||
if (key === 'token' || key === 'refresh_token') return Cookies.set(key, val);
|
if (key === 'token') return Cookies.set(key, val);
|
||||||
window.sessionStorage.setItem(key, JSON.stringify(val));
|
window.sessionStorage.setItem(Local.setKey(key), JSON.stringify(val));
|
||||||
},
|
},
|
||||||
// 获取临时缓存
|
// 获取临时缓存
|
||||||
get(key: string) {
|
get(key: string) {
|
||||||
if (key === 'token' || key === 'refresh_token') return Cookies.get(key);
|
if (key === 'token') return Cookies.get(key);
|
||||||
let json = <string>window.sessionStorage.getItem(key);
|
let json = <string>window.sessionStorage.getItem(Local.setKey(key));
|
||||||
return JSON.parse(json);
|
return JSON.parse(json);
|
||||||
},
|
},
|
||||||
// 移除临时缓存
|
// 移除临时缓存
|
||||||
remove(key: string) {
|
remove(key: string) {
|
||||||
if (key === 'token' || key === 'refresh_token') return Cookies.remove(key);
|
if (key === 'token') return Cookies.remove(key);
|
||||||
window.sessionStorage.removeItem(key);
|
window.sessionStorage.removeItem(Local.setKey(key));
|
||||||
},
|
},
|
||||||
// 移除全部临时缓存
|
// 移除全部临时缓存
|
||||||
clear() {
|
clear() {
|
||||||
Cookies.remove('token');
|
Cookies.remove('token');
|
||||||
Cookies.remove('refresh_token');
|
|
||||||
window.sessionStorage.clear();
|
window.sessionStorage.clear();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user