This commit is contained in:
2025-03-25 16:35:39 +08:00
parent 2b456dc17e
commit 9463635e03
66 changed files with 864 additions and 64 deletions

30
src/utils/AESCrypto.js Normal file
View File

@@ -0,0 +1,30 @@
import AES from 'crypto-js/aes.js';
import utf8 from 'crypto-js/enc-utf8.js';
class AESCrypto {
/**
* 密钥
* @type {string}
*/
static #AES_KEY = import.meta.env.VITE_AES_KEY;
/**
* AES加密
* @param context {string} 加密内容
*/
static encrypt = (context) => {
return AES.encrypt(context, this.#AES_KEY).toString();
}
/**
* AES解密
* @param context {string}
* @return {string}
*/
static decrypt = (context) => {
const bytes = AES.decrypt(context, this.#AES_KEY);
return bytes.toString(utf8);
}
}
export default AESCrypto;

24
src/utils/request.js Normal file
View File

@@ -0,0 +1,24 @@
import {showToast} from "./uils.js";
const request = (options) => {
return new Promise((resolve, reject) => {
const {url, method} = options;
uni.request({
method: method,
url: `${import.meta.env.VITE_API_URL}${url}`,
success: ({data}) => {
if (data.code !== 0) {
showToast(data.msg);
reject(data.msg);
}
resolve(data);
},
fail: (err) => {
reject(err);
}
});
});
}
export default request;

15
src/utils/uils.js Normal file
View File

@@ -0,0 +1,15 @@
export const showToast = (options) => {
if (typeof options === 'string') {
uni.showToast({
title: options,
icon: 'none',
}).then();
} else {
uni.showToast(options).then();
}
}
export const isWXWeb = () => {
const userAgent = navigator.userAgent;
return userAgent.includes('MicroMessenger');
}