feat: 初始化
This commit is contained in:
143
utils/const.ts
Normal file
143
utils/const.ts
Normal file
@ -0,0 +1,143 @@
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const reportMenu = {
|
||||
report14:"/pages/report/report14/index",
|
||||
report16:"/pages/report/report16/index",
|
||||
report17:"/pages/report/report17/index",
|
||||
report20:"/pages/report/report20/index",
|
||||
report22:"/pages/report/report22/index",
|
||||
report21:"/pages/report/report21/index",
|
||||
report28:"/pages/report/report28/index",
|
||||
report27:"/pages/report/report27/index",
|
||||
report26:"/pages/report/report26/index",
|
||||
report24:"/pages/report/report24/index",
|
||||
report81:"/pages/report/report81/index"
|
||||
};
|
||||
|
||||
export const auditMenu = {
|
||||
goldIn:"/pages/audit/goldIn/index",
|
||||
goldOut:"/pages/audit/goldOut/index",
|
||||
salesGoldOut:"/pages/audit/salesGoldOut/index",
|
||||
integral:"/pages/audit/integral/index"
|
||||
};
|
||||
|
||||
export const customerMenu = {
|
||||
sell:'/pages/customer/sell/index',
|
||||
ib:'/pages/customer/ib/index',
|
||||
customer:'/pages/customer/customer/index',
|
||||
mt:'/pages/customer/mt/index'
|
||||
};
|
||||
|
||||
|
||||
export const applyRecordMenu = {
|
||||
mt:"/pages/applyRecord/mt/index",
|
||||
leverage:"/pages/applyRecord/leverage/index",
|
||||
userChange:"/pages/applyRecord/userChange/index",
|
||||
goldIn:"/pages/applyRecord/goldIn/index",
|
||||
goldOut:"/pages/applyRecord/goldOut/index",
|
||||
transfer:"/pages/applyRecord/transfer/index",
|
||||
fundOut:"/pages/applyRecord/fundOut/index",
|
||||
fundTransfer:"/pages/applyRecord/fundTransfer/index",
|
||||
};
|
53
utils/options.ts
Normal file
53
utils/options.ts
Normal 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
118
utils/request.ts
Normal 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;
|
Reference in New Issue
Block a user