| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import { getDomainParts, setDomainParts, buildHostUrls } from './domainState'
- import { DOMAIN_CACHE_KEY } from './domainConstants'
- declare const uni: any
- /** 模块加载时同步恢复缓存(含过期缓存),避免首屏走默认域名 */
- function loadCachedDomainSync() {
- try {
- const raw = uni.getStorageSync(DOMAIN_CACHE_KEY)
- if (!raw) return
- const cache = typeof raw === 'string' ? JSON.parse(raw) : raw
- if (cache?.ho && cache?.dt) {
- setDomainParts({ ho: cache.ho, dt: cache.dt, ht: cache.ht || 'https:' })
- }
- } catch (e) {
- console.warn('[dynamicDomain] 同步恢复缓存失败', e)
- }
- }
- // #ifdef H5
- const [p, h] = [window.location.protocol, window.location.host]
- const isIP = /^\d+\.\d+\.\d+\.\d+:\d+$/.test(h)
- const [h5Ho, h5Dt] = isIP ? ['44a5c8109e4', 'com'] : h.split('.').slice(-2)
- const h5Ht = p == 'http:' ? 'https:' : p
- setDomainParts({ ho: h5Ho, dt: h5Dt, ht: h5Ht })
- // #endif
- // #ifdef APP-PLUS
- loadCachedDomainSync()
- // #endif
- const staticConfig = {
- Code: {
- StatusOK: 200,
- StatusFail: 400,
- StatusSessionExpire: 600,
- StatusSNotFound: 404,
- },
- Pattern: {
- Email: /^[\w.%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i,
- Phone: /^1[3-9]\d{9}$/,
- Pin: /^(?!(\d)\1{5})(?!012345)(?!123456)(?!234567)(?!345678)(?!456789)(?!987654)(?!876543)(?!765432)(?!654321)(?!543210)\d{6}$/,
- Password: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{}|;:,.<>?/~]{8,16}$/,
- Tel: /^0[1-9]{2,3}-\d{5,10}$/,
- Num: /\d/,
- NonNegInt: /^\d+$/, // 非负整数
- PosInt: /^[1-9]\d*$/, // 正整数
- nonnegative: /^\d+(\.\d{1,2})?$/, // 非负数(最多两位小数)
- englishName: /^[^\u4E00-\u9FA5]+$/,
- },
- }
- const hostKeys = [
- 'HostWs',
- 'Host80',
- 'Host00',
- 'Host85',
- 'Host04',
- 'Host90',
- 'HostShop',
- 'HostShopImg',
- 'Host87',
- 'Host05',
- 'HostEnter',
- ] as const
- type HostKey = (typeof hostKeys)[number]
- const config: Record<string, unknown> = {
- ...staticConfig,
- get ho() {
- return getDomainParts().ho
- },
- get host() {
- return getDomainParts().ho
- },
- }
- hostKeys.forEach((key) => {
- Object.defineProperty(config, key, {
- enumerable: true,
- configurable: true,
- get() {
- return buildHostUrls()[key as HostKey]
- },
- })
- })
- export default config as typeof staticConfig & Record<HostKey, string> & {
- ho: string
- host: string
- }
|