143 lines
3.4 KiB
TypeScript
143 lines
3.4 KiB
TypeScript
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",
|
|
}; |