feat: 初始化

This commit is contained in:
George
2025-07-07 15:55:44 +08:00
commit 9b7bfcfe5a
969 changed files with 123036 additions and 0 deletions

102
utils/const.ts Normal file
View File

@ -0,0 +1,102 @@
import type { LocaleType } from '@/types/common';
import { Locales } from '@/types/common';
import { useUserStore } from '@/stores/user.ts';
export const defaultLocale = Locales.en_US;
export const locales: Locales[] = [
Locales.ar_SA,
Locales.en_US,
Locales.es_ES,
Locales.ko_KR,
Locales.th_TH,
Locales.vi_VN,
Locales.zh_CN,
Locales.zh_TW,
Locales.hi_IN,
Locales.id_ID
];
export function setLocale(locale: LocaleType) {
// vantLocale.use(Locales[locale], vantLocales[locale]);
uni.setLocale(locale);
//#ifdef H5
window.location.reload();
//#endif
}
export const languages = {
'ar-SA': 'ar_SA',
'en-US': 'en_US',
'es-ES': 'es_ES',
'hi-IN': 'hi_IN',
'ko-KR': 'ko_KR',
'th-TH': 'th_TH',
'vi-VN': 'vi_VN',
'zh-CN': 'zh_CN',
'zh-TW': 'zh_TW',
'in-ID': 'id_ID'
};
export const UserLanguage: LocaleType = languages[uni.getLocale() as LocaleType] ?? 'en_US';
export function getToken() {
const userStore = useUserStore();
const token = userStore.token ?? uni.getStorageSync('access_token');
return token;
}
export function clearToken() {
const userStore = useUserStore();
userStore.clear();
uni.removeStorageSync('access_token');
}
export const patterns = {
/**
* 除英文字母、空格、-、'、@ 外
*/
name: /[^a-zA-Z\s\-'@/]/g,
/**
* 需包含8-15个字符
*/
passwordPattern1: /^.{8,15}$/,
/**
* 需包含至少一个大写和小写字母
*/
passwordPattern2: /(?=.*[a-z])(?=.*[A-Z]).+/,
/**
* 需包含至少一个数字
*/
passwordPattern3: /(?=.*\d).+/,
/**
* 需包含#,@,!其中一个字符
*/
passwordPattern4: /.*[@#!].*/,
/**
* 不允许包含空格
*/
noSpace: /^\S*$/
};
export function isValidNumber(val: string | number) {
if (isNaN(Number(val))) {
return false;
} else {
return true;
}
}
export function getNumberLocaleIntegerPart(number: number | string) {
if (isNaN(parseInt(number?.toString()))) {
return 0;
} else {
return Math.floor(Number(number)).toLocaleString('en-US');
}
}
export function getNumberDecimalPart(number: number | string, precision = 2) {
if (isNaN(parseInt(number?.toString()))) {
return '00';
} else {
return Number(number).toFixed(precision).toString().split('.')[1];
}
}

25
utils/jsencrypt.js Normal file
View File

@ -0,0 +1,25 @@
import JSEncrypt from '@/utils/jsencrypt.min.js';
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
'UP8iWi1Qw0Y='
export function encrypt(txt) {
const encryptor = new JSEncrypt.JSEncrypt ();
encryptor.setPublicKey(publicKey); // 设置公钥
return encryptor.encrypt(txt); // 对需要加密的数据进行加密
}
//解密
export function decrypt(txt) {
const encryptor = new JSEncrypt.JSEncrypt ();
encryptor.setPrivateKey(privateKey);
return encryptor.decrypt(txt);
}

2153
utils/jsencrypt.min.js vendored Normal file

File diff suppressed because it is too large Load Diff

53
utils/options.ts Normal file
View File

@ -0,0 +1,53 @@
import { i18n } from '@/locale/index.ts';
const t: any = i18n.global.t;
export const depositStatusOptions = {
'0': t('form.status.apply'),
'1': t('form.status.approved'),
'2': t('form.status.rejected'),
'-1': t('form.status.wait'),
'-2': t('form.status.canceled')
};
export const withdrawStatusOptions = {
'0': t('form.status.apply'),
'1': t('form.status.approved'),
'2': t('form.status.rejected'),
'3': t('form.status.breakUp'),
'-1': t('form.status.wait'),
'-2': t('form.status.canceled'),
'-3': t('form.status.waitWallet')
};
export const transferStatusOptions = {
'0': t('form.status.apply'),
'1': t('form.status.approved'),
'2': t('form.status.rejected'),
'3': t('form.status.depositFailed'),
'-2': t('form.status.canceled')
};
export const fundOutStatusOptions = {
'0': t('form.status.apply'),
'1': t('form.status.approved'),
'2': t('form.status.rejected'),
'3': t('form.status.breakUp'),
'-1': t('form.status.wait'),
'-2': t('form.status.canceled'),
'-3': t('form.status.waitWallet')
};
export const fundTransferStatusOptions = {
'0': t('form.status.apply'),
'1': t('form.status.approved'),
'2': t('form.status.rejected'),
'3': t('form.status.breakUp'),
'-1': t('form.status.wait'),
'-2': t('form.status.canceled'),
'-3': t('form.status.waitWallet')
};
export const userTypeOptions = {
'0': t('form.userType.emp'),
'1': t('form.userType.ib'),
'2': t('form.userType.customer')
};

118
utils/request.ts Normal file
View File

@ -0,0 +1,118 @@
import { i18n } from '@/locale/index.ts';
import { getToken, clearToken } from '@/utils/const';
const t: any = i18n.global.t;
let baseURL: string;
// #ifndef H5
console.log('------非H5------');
baseURL = 'https://user.htltd.net/api';
// baseURL = 'http://192.168.123.247:8080';
// #endif
// #ifdef H5
console.log('------H5------');
baseURL = 'http://localhost:8080';
// #endif
// const baseURL = 'http://47.238.103.157:81';
const proxyMap = { '/api': baseURL, '/api2': 'http://8.212.58.187:32249' };
const proxy = (url: string) => {
let target = url;
// #ifndef H5
const tags = Object.keys(proxyMap);
tags.find((tag) => {
if (!tag.startsWith('/')) return;
if (url.startsWith(tag + '/')) {
target = proxyMap[tag] + url.replace(tag, '');
return true;
} else {
return false;
}
});
// #endif
return target;
};
const httpInterceptor = {
invoke(options: UniApp.RequestOptions) {
if (!options.url.startsWith('http')) {
options.url = proxy(options.url);
}
options.timeout = 180000;
options.header = {
...options.header
};
const token = getToken();
if (token) {
options.header.Authorization = token;
}
}
};
uni.addInterceptor('request', httpInterceptor);
uni.addInterceptor('uploadFile', httpInterceptor);
interface Data<T> {
code: number;
msg: string;
result: T;
}
export const request = <T>(options: UniApp.RequestOptions) => {
return new Promise<Data<T>>((resolve, reject) => {
uni.request({
...options,
success: (res) => {
// 状态码2xx
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data as Data<T>);
} else if (res.statusCode === 401) {
uni.showToast({
icon: 'none',
title: t('common.error.401')
});
clearToken();
uni.navigateTo({ url: '/pages/login/index' });
resolve({ code: res.statusCode } as Data<T>);
} else {
reject(res);
}
},
fail(err) {
uni.showToast({
icon: 'none',
title: 'NetWork ERROR'
});
reject(err);
}
});
});
// return uni.request({
// ...options,
// success: (res) => {
// // 状态码2xx
// if (res.statusCode >= 200 && res.statusCode < 300) {
// return res.data as Data<T>;
// } else if (res.statusCode === 401) {
// const userStore = useUserStore();
// userStore.clear();
// uni.navigateTo({ url: '/pages/login/index' });
// return res;
// } else {
// uni.showToast({
// icon: 'none',
// title: t(`errorMsg.${res.statusCode}`)
// });
// return res;
// }
// },
// fail(err) {
// uni.showToast({
// icon: 'none',
// title: '网络连接失败,请稍后再试'
// });
// return err;
// }
// });
};
export const app_host = baseURL;