ruoyi-geek-App/utils/geek.ts
2025-11-30 22:19:19 +08:00

73 lines
1.6 KiB
TypeScript
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 { tansParams } from "./ruoyi";
/**
* 获取uuid
* @returns 生成的uuid字符串
*/
export function generateUUID() : string {
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;
}
export function getWxCode() {
}
/**
* 微信登录APP 端)
* @returns {Promise<{code: string}>} 临时登录凭证
*/
export function wechatLoginApp() {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin', // 指定登录方式为微信
onlyAuthorize: true, // 微信登录仅请求授权认证
success: (res) => {
console.log(res)
if (res.code) {
resolve( res.code);
} else if (res.authResult) {
// 如果不存在 code但是有 authResult则返回 authResult
resolve({ authResult: res.authResult });
} else {
reject(new Error('微信登录失败:未获取到有效响应'));
}
},
fail: (err) => {
reject(new Error('微信登录失败:' + err.errMsg));
}
});
});
}
/**
* 微信登录(小程序端)
* @returns {Promise<{code: string}>} 临时登录凭证
*/
export function wechatLoginMp() {
return new Promise((resolve, reject) => {
// 小程序端无需指定 provider默认就是微信
uni.login({
success: (res) => {
if (res.code) {
resolve({ code: res.code });
} else {
reject(new Error('获取微信 code 失败:' + res.errMsg));
}
},
fail: (err) => {
reject(new Error('微信登录失败:' + err.errMsg));
}
});
});
}