2024-01-03 08:41:25 +00:00
|
|
|
|
import { tansParams } from "./ruoyi";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-27 10:16:10 +00:00
|
|
|
|
* 通配符比较
|
|
|
|
|
|
* @param {*} str 待比较的字符串
|
|
|
|
|
|
* @param {*} pattern 含有*或者?通配符的字符串
|
2024-01-03 08:41:25 +00:00
|
|
|
|
* @returns
|
2023-08-27 10:16:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
export function wildcardCompare(str: string, pattern: string): boolean {
|
2024-01-03 08:41:25 +00:00
|
|
|
|
const regex = pattern.replace(/[*?]/g, (match) => {
|
|
|
|
|
|
if (match === "*") {
|
|
|
|
|
|
return ".*";
|
|
|
|
|
|
} else if (match === "?") {
|
|
|
|
|
|
return ".";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return match;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
const regexPattern = new RegExp("^" + regex + "$");
|
|
|
|
|
|
return regexPattern.test(str);
|
2023-08-27 10:16:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-27 11:38:56 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 深度复制
|
|
|
|
|
|
* @param obj 待复制的对象
|
|
|
|
|
|
* @returns 复制的对象
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function deepClone(obj: any) {
|
2024-01-03 08:41:25 +00:00
|
|
|
|
if (obj == null || typeof obj !== "object") {
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
let result;
|
|
|
|
|
|
if (Array.isArray(obj)) {
|
|
|
|
|
|
result = [];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
result = new Map();
|
|
|
|
|
|
}
|
|
|
|
|
|
for (let [key, value] of Object.entries(obj)) {
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
result[key] = deepClone(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
2023-08-28 10:21:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 深度复制
|
|
|
|
|
|
* @param obj 待复制的对象
|
|
|
|
|
|
* @param result 要复制到的对象
|
|
|
|
|
|
* @returns 复制的对象
|
|
|
|
|
|
*/
|
2023-08-28 15:36:12 +00:00
|
|
|
|
export function deepCloneTo<T>(obj: T, result: T) {
|
2024-01-03 08:41:25 +00:00
|
|
|
|
if (obj == null || typeof obj !== "object") {
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (let [key, value] of Object.entries(obj)) {
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
result[key] = deepClone(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
2023-09-12 17:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取uuid
|
|
|
|
|
|
* @returns 生成的uuid字符串
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function generateUUID(): string {
|
2024-01-03 08:41:25 +00:00
|
|
|
|
let uuid = "";
|
|
|
|
|
|
const chars = "0123456789abcdef";
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 32; i++) {
|
|
|
|
|
|
if (i === 8 || i === 12 || i === 16 || i === 20) {
|
|
|
|
|
|
uuid += "-";
|
|
|
|
|
|
}
|
|
|
|
|
|
uuid += chars[Math.floor(Math.random() * chars.length)];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return uuid;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取code
|
|
|
|
|
|
* @returns 生成的code字符串
|
|
|
|
|
|
*/
|
2024-01-17 18:45:14 +00:00
|
|
|
|
export async function getWxCode(appid?: string,redirect_uri?:string) {
|
2024-01-03 08:41:25 +00:00
|
|
|
|
// #ifdef H5
|
2024-01-17 18:45:14 +00:00
|
|
|
|
if (appid == undefined || redirect_uri == undefined) return ""
|
2024-01-03 08:41:25 +00:00
|
|
|
|
let code = "";
|
|
|
|
|
|
|
|
|
|
|
|
// 截取url中的code方法
|
|
|
|
|
|
function getUrlCode() {
|
|
|
|
|
|
let url = location.search;
|
|
|
|
|
|
console.log(url);
|
|
|
|
|
|
let theRequest: any = new Object();
|
|
|
|
|
|
if (url.indexOf("?") != -1) {
|
|
|
|
|
|
let str = url.substr(1);
|
|
|
|
|
|
let strs = str.split("&");
|
|
|
|
|
|
for (let i = 0; i < strs.length; i++) {
|
|
|
|
|
|
theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
|
2023-09-12 17:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-03 08:41:25 +00:00
|
|
|
|
return theRequest as { code: string };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
code = getUrlCode().code; // 截取code
|
|
|
|
|
|
if (code == undefined || code == "" || code == null) {
|
|
|
|
|
|
// 如果没有code,则去请求
|
|
|
|
|
|
console.log("h5");
|
2024-01-17 18:45:14 +00:00
|
|
|
|
let href= "https://open.weixin.qq.com/connect/oauth2/authorize?"+
|
2024-01-03 08:41:25 +00:00
|
|
|
|
tansParams({
|
|
|
|
|
|
appid: appid,
|
2024-01-17 18:45:14 +00:00
|
|
|
|
redirect_uri: redirect_uri,
|
2024-01-03 08:41:25 +00:00
|
|
|
|
response_type: "code",
|
|
|
|
|
|
scope: "snsapi_userinfo",
|
|
|
|
|
|
state: "STATE",
|
|
|
|
|
|
}) +
|
|
|
|
|
|
"#wechat_redirect";
|
2024-01-17 18:45:14 +00:00
|
|
|
|
console.log(href);
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
window.location.href = href;
|
|
|
|
|
|
}, 5000);
|
2024-01-03 08:41:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
return code;
|
|
|
|
|
|
}
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
const res = await wx.login();
|
|
|
|
|
|
return res.code;
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
}
|