index.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { getDomainParts, setDomainParts, buildHostUrls } from './domainState'
  2. // #ifdef H5
  3. const [p, h] = [window.location.protocol, window.location.host]
  4. const isIP = /^\d+\.\d+\.\d+\.\d+:\d+$/.test(h)
  5. const [h5Ho, h5Dt] = isIP ? ['44a5c8109e4', 'com'] : h.split('.').slice(-2)
  6. const h5Ht = p == 'http:' ? 'https:' : p
  7. setDomainParts({ ho: h5Ho, dt: h5Dt, ht: h5Ht })
  8. // #endif
  9. const staticConfig = {
  10. Code: {
  11. StatusOK: 200,
  12. StatusFail: 400,
  13. StatusSessionExpire: 600,
  14. StatusSNotFound: 404,
  15. },
  16. Pattern: {
  17. Email: /^[\w.%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i,
  18. Phone: /^1[3-9]\d{9}$/,
  19. Pin: /^(?!(\d)\1{5})(?!012345)(?!123456)(?!234567)(?!345678)(?!456789)(?!987654)(?!876543)(?!765432)(?!654321)(?!543210)\d{6}$/,
  20. Password: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{}|;:,.<>?/~]{8,16}$/,
  21. Tel: /^0[1-9]{2,3}-\d{5,10}$/,
  22. Num: /\d/,
  23. NonNegInt: /^\d+$/, // 非负整数
  24. PosInt: /^[1-9]\d*$/, // 正整数
  25. nonnegative: /^\d+(\.\d{1,2})?$/, // 非负数(最多两位小数)
  26. englishName: /^[^\u4E00-\u9FA5]+$/,
  27. },
  28. }
  29. const hostKeys = [
  30. 'HostWs',
  31. 'Host80',
  32. 'Host00',
  33. 'Host85',
  34. 'Host04',
  35. 'Host90',
  36. 'HostShop',
  37. 'HostShopImg',
  38. 'Host87',
  39. 'Host05',
  40. 'HostEnter',
  41. ] as const
  42. type HostKey = (typeof hostKeys)[number]
  43. const config: Record<string, unknown> = {
  44. ...staticConfig,
  45. get ho() {
  46. return getDomainParts().ho
  47. },
  48. get host() {
  49. return getDomainParts().ho
  50. },
  51. }
  52. hostKeys.forEach((key) => {
  53. Object.defineProperty(config, key, {
  54. enumerable: true,
  55. configurable: true,
  56. get() {
  57. return buildHostUrls()[key as HostKey]
  58. },
  59. })
  60. })
  61. export default config as typeof staticConfig & Record<HostKey, string> & {
  62. ho: string
  63. host: string
  64. }