@gx-design-vue/create-gx-cli 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +4 -11
  2. package/package.json +3 -2
  3. package/src/main.js +9 -3
  4. package/template-mobile-vant-cli/.env +0 -0
  5. package/template-mobile-vant-cli/.env.pro +1 -1
  6. package/template-mobile-vant-cli/.env.production +2 -2
  7. package/template-mobile-vant-cli/.eslintignore +0 -1
  8. package/template-mobile-vant-cli/build/plugin/autoImport.ts +8 -10
  9. package/template-mobile-vant-cli/build/plugin/index.ts +2 -10
  10. package/template-mobile-vant-cli/build/plugin/mock.ts +5 -11
  11. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +88 -0
  12. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +271 -0
  13. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +69 -0
  14. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +48 -0
  15. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +48 -0
  16. package/template-mobile-vant-cli/eslint.config.js +49 -0
  17. package/template-mobile-vant-cli/mock/_createProductionServer.ts +4 -4
  18. package/template-mobile-vant-cli/mock/datasSource/api/index.ts +0 -0
  19. package/template-mobile-vant-cli/package.json +26 -33
  20. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -2
  21. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +7 -6
  22. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +1 -1
  23. package/template-mobile-vant-cli/src/core/vant-design/index.ts +1 -1
  24. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +8 -5
  25. package/template-mobile-vant-cli/src/layout/BasicLayout.vue +3 -3
  26. package/template-mobile-vant-cli/src/pages/home.vue +27 -27
  27. package/template-mobile-vant-cli/src/router/index.ts +3 -2
  28. package/template-mobile-vant-cli/src/router/typings.ts +1 -1
  29. package/template-mobile-vant-cli/src/settings/index.ts +2 -2
  30. package/template-mobile-vant-cli/src/store/modules/global.ts +1 -1
  31. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +101 -0
  32. package/template-mobile-vant-cli/src/utils/{cryptoJS.ts → crypto/index.ts} +23 -5
  33. package/template-mobile-vant-cli/src/utils/env.ts +15 -17
  34. package/template-mobile-vant-cli/src/utils/pageTitle.ts +5 -3
  35. package/template-mobile-vant-cli/src/utils/request/XHR.ts +38 -30
  36. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +32 -23
  37. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +1 -3
  38. package/template-mobile-vant-cli/src/utils/request/index.ts +3 -4
  39. package/template-mobile-vant-cli/src/utils/request/typings.ts +74 -17
  40. package/template-mobile-vant-cli/src/utils/storage.ts +25 -18
  41. package/template-mobile-vant-cli/src/utils/util.ts +0 -5
  42. package/template-mobile-vant-cli/src/utils/validate.ts +191 -3
  43. package/template-mobile-vant-cli/tsconfig.json +8 -9
  44. package/template-mobile-vant-cli/types/{gx-components.d.ts → ant-design-import.d.ts} +3 -3
  45. package/template-mobile-vant-cli/types/auto-imports.d.ts +3 -0
  46. package/template-mobile-vant-cli/types/components.d.ts +2 -5
  47. package/template-mobile-vant-cli/types/global.d.ts +7 -4
  48. package/template-mobile-vant-cli/types/module.d.ts +15 -2
  49. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +14 -0
  50. package/template-mobile-vant-cli/types/response.d.ts +8 -5
  51. package/template-mobile-vant-cli/types/vant-import.d.ts +13 -0
  52. package/template-mobile-vant-cli/unocss.config.ts +101 -0
  53. package/template-mobile-vant-cli/vite.config.ts +43 -11
  54. package/template-mobile-vant-cli/.eslintrc.js +0 -64
  55. package/template-mobile-vant-cli/.stylelintignore +0 -3
  56. package/template-mobile-vant-cli/mock/api/index.ts +0 -66
  57. package/template-mobile-vant-cli/stylelint.config.js +0 -106
  58. /package/template-mobile-vant-cli/{postcss.config.js → postcss.config.cjs} +0 -0
  59. /package/template-mobile-vant-cli/{prettier.config.js → prettier.config.cjs} +0 -0
@@ -5,8 +5,10 @@
5
5
  * @returns {string}
6
6
  */
7
7
  export default function getPageTitle(title: string, pageTitle: string) {
8
- let newTitles: any = []
9
- if (pageTitle) newTitles.push(pageTitle)
10
- if (title) newTitles.push(title)
8
+ const newTitles: string[] = []
9
+ if (pageTitle)
10
+ newTitles.push(pageTitle)
11
+ if (title)
12
+ newTitles.push(title)
11
13
  return newTitles.join('-')
12
14
  }
@@ -1,12 +1,15 @@
1
- import type { AxiosResponse, AxiosError } from 'axios'
1
+ import type { AxiosError } from 'axios'
2
2
  import axios from 'axios'
3
- import { deepCopy } from '@/utils/util'
3
+ import { cloneDeep } from 'lodash-es'
4
4
  import qs from 'qs'
5
5
  import { isFunction } from '@gx-design-vue/pro-utils'
6
- import type { GAxiosInstance, GAxiosOptions } from './typings'
6
+ import type { GAxiosInstance, GAxiosOptions, GAxiosResponse } from './typings'
7
7
  import { ContentTypeEnum, RequestEnum } from './typings'
8
8
  import { AxiosCanceler } from './axiosCancel'
9
9
 
10
+ export const getPendingUrl = (config: GAxiosOptions) => config.cancelKey || [ config.method, config.url ].join(
11
+ '&')
12
+
10
13
  /**
11
14
  * @Author gx12358
12
15
  * @DateTime 2023/1/6
@@ -19,7 +22,7 @@ export class GAxios {
19
22
 
20
23
  constructor(options: GAxiosOptions) {
21
24
  this.options = options
22
- this.axiosInstance = axios.create(options)
25
+ this.axiosInstance = axios.create(options) as GAxiosInstance
23
26
  this.setupInterceptors()
24
27
  }
25
28
 
@@ -34,16 +37,18 @@ export class GAxios {
34
37
  responseInterceptorsCatch
35
38
  } = this.options
36
39
 
37
- const axiosCanceler = new AxiosCanceler()
38
-
39
- this.axiosInstance.interceptors.request.use((config: GAxiosOptions) => {
40
- const { ignoreCancelToken } = config
41
- const ignoreCancel =
42
- ignoreCancelToken !== undefined
43
- ? ignoreCancelToken
44
- : this.options?.ignoreCancelToken
40
+ const axiosCanceler = new AxiosCanceler(this.options.ignoreCancelToken)
45
41
 
46
- !ignoreCancel && axiosCanceler.addPending(config)
42
+ this.axiosInstance.interceptors.request.use<GAxiosOptions>((config) => {
43
+ const { cancelCallBackHook } = config
44
+ axiosCanceler.addPending(config)
45
+ if (cancelCallBackHook) {
46
+ cancelCallBackHook({
47
+ reset: axiosCanceler.reset,
48
+ cancel: (key?: string) => axiosCanceler.removePending(config, key),
49
+ cancelAll: axiosCanceler.removeAllPending
50
+ })
51
+ }
47
52
  if (requestInterceptors && isFunction(requestInterceptors)) {
48
53
  config = requestInterceptors(config)
49
54
  }
@@ -51,12 +56,13 @@ export class GAxios {
51
56
  }, undefined)
52
57
 
53
58
  // Request interceptor error capture
54
- requestInterceptorsCatch &&
55
- isFunction(requestInterceptorsCatch) &&
56
- this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch)
59
+ requestInterceptorsCatch && isFunction(requestInterceptorsCatch) && this.axiosInstance.interceptors.request.use(
60
+ undefined,
61
+ requestInterceptorsCatch
62
+ )
57
63
 
58
64
  // Response result interceptor processing
59
- this.axiosInstance.interceptors.response.use((res: AxiosResponse) => {
65
+ this.axiosInstance.interceptors.response.use((res: GAxiosResponse) => {
60
66
  res && axiosCanceler.removePending(res.config)
61
67
  if (responseInterceptors && isFunction(responseInterceptors)) {
62
68
  return responseInterceptors(res)
@@ -65,11 +71,14 @@ export class GAxios {
65
71
  }, undefined)
66
72
 
67
73
  // Response result interceptor error capture
68
- responseInterceptorsCatch &&
69
- isFunction(responseInterceptorsCatch) &&
70
- this.axiosInstance.interceptors.response.use(undefined, (error) => {
71
- return responseInterceptorsCatch(this.axiosInstance, error)
72
- })
74
+ responseInterceptorsCatch && isFunction(responseInterceptorsCatch) && this.axiosInstance.interceptors.response.use(
75
+ undefined,
76
+ (error) => {
77
+ axiosCanceler.removePending(error.config)
78
+
79
+ return responseInterceptorsCatch(this.axiosInstance, error)
80
+ }
81
+ )
73
82
  }
74
83
 
75
84
  // support form-data
@@ -77,11 +86,10 @@ export class GAxios {
77
86
  const headers = config.headers || this.options.headers
78
87
  const contentType = headers?.['Content-Type'] || headers?.['content-type']
79
88
 
80
- if (
81
- contentType !== ContentTypeEnum.FORM_URLENCODED ||
82
- !Reflect.has(config, 'data') ||
83
- config.method?.toUpperCase() === RequestEnum.GET
84
- ) {
89
+ if (contentType !== ContentTypeEnum.FORM_URLENCODED || !Reflect.has(
90
+ config,
91
+ 'data'
92
+ ) || config.method?.toUpperCase() === RequestEnum.GET) {
85
93
  return config
86
94
  }
87
95
 
@@ -92,7 +100,7 @@ export class GAxios {
92
100
  }
93
101
 
94
102
  request<T = ResponseResult | boolean>(config: GAxiosOptions): Promise<T> {
95
- let conf: GAxiosOptions = deepCopy(config)
103
+ let conf: GAxiosOptions = cloneDeep(config)
96
104
 
97
105
  const opt: GAxiosOptions = Object.assign({}, this.options, conf)
98
106
 
@@ -105,8 +113,8 @@ export class GAxios {
105
113
 
106
114
  return new Promise((resolve) => {
107
115
  this.axiosInstance
108
- .request<any, AxiosResponse>(conf)
109
- .then((res: AxiosResponse) => {
116
+ .request<any, GAxiosResponse>(conf)
117
+ .then((res: GAxiosResponse) => {
110
118
  if (transformResponseHook && isFunction(transformResponseHook)) {
111
119
  try {
112
120
  const ret = transformResponseHook(res, config)
@@ -1,53 +1,62 @@
1
- import type { AxiosRequestConfig, Canceler } from 'axios'
1
+ import type { Canceler } from 'axios'
2
2
  import axios from 'axios'
3
3
  import { isFunction } from '@gx-design-vue/pro-utils'
4
+ import type { GAxiosOptions } from './typings'
4
5
 
5
- // Used to store the identification and cancellation function of each request
6
- let pendingMap = new Map<string, Canceler>()
7
-
8
- export const getPendingUrl = (config: AxiosRequestConfig) => [ config.method, config.url ].join('&')
6
+ export const getPendingUrl = (
7
+ config: GAxiosOptions,
8
+ key?: string
9
+ ) => key || config.cancelKey || [ config.method, config.url ].join('&')
9
10
 
10
11
  export class AxiosCanceler {
12
+ ignoreCancelToken: boolean
13
+ pendingMap: Map<string, Canceler>
14
+
15
+ constructor(ignoreCancel?: boolean) {
16
+ this.pendingMap = new Map<string, Canceler>()
17
+
18
+ this.ignoreCancelToken = ignoreCancel
19
+ }
20
+
11
21
  /**
12
22
  * Add request
13
23
  * @param {Object} config
14
24
  */
15
- addPending(config: AxiosRequestConfig) {
16
- this.removePending(config)
25
+ addPending(config: GAxiosOptions) {
26
+ !this.ignoreCancelToken && this.removePending(config)
27
+
17
28
  const url = getPendingUrl(config)
18
- config.cancelToken =
19
- config.cancelToken ||
20
- new axios.CancelToken((cancel) => {
21
- if (!pendingMap.has(url)) {
22
- // If there is no current request in pending, add it
23
- pendingMap.set(url, cancel)
24
- }
25
- })
29
+ config.cancelToken = config.cancelToken || new axios.CancelToken((cancel) => {
30
+ if (!this.pendingMap.has(url)) {
31
+ // If there is no current request in pending, add it
32
+ this.pendingMap.set(url, cancel)
33
+ }
34
+ })
26
35
  }
27
36
 
28
37
  /**
29
38
  * @description: Clear all pending
30
39
  */
31
40
  removeAllPending() {
32
- pendingMap.forEach((cancel) => {
41
+ this.pendingMap.forEach((cancel) => {
33
42
  cancel && isFunction(cancel) && cancel()
34
43
  })
35
- pendingMap.clear()
44
+ this.pendingMap.clear()
36
45
  }
37
46
 
38
47
  /**
39
48
  * Removal request
40
49
  * @param {Object} config
41
50
  */
42
- removePending(config: AxiosRequestConfig) {
43
- const url = getPendingUrl(config)
51
+ removePending(config: GAxiosOptions, key?: string) {
52
+ const url = getPendingUrl(config, key)
44
53
 
45
- if (pendingMap.has(url)) {
54
+ if (this.pendingMap.has(url)) {
46
55
  // If there is a current request identifier in pending,
47
56
  // the current request needs to be cancelled and removed
48
- const cancel = pendingMap.get(url)
57
+ const cancel = this.pendingMap.get(url)
49
58
  cancel && cancel(url)
50
- pendingMap.delete(url)
59
+ this.pendingMap.delete(url)
51
60
  }
52
61
  }
53
62
 
@@ -55,6 +64,6 @@ export class AxiosCanceler {
55
64
  * @description: reset
56
65
  */
57
66
  reset(): void {
58
- pendingMap = new Map<string, Canceler>()
67
+ this.pendingMap = new Map<string, Canceler>()
59
68
  }
60
69
  }
@@ -1,11 +1,9 @@
1
- import { showFailToast } from 'vant'
2
-
3
1
  /**
4
2
  * @author gx12358 2539306317@qq.com
5
3
  * @description 处理code异常
6
4
  * @param {*} code
7
5
  * @param {*} msg
8
6
  */
9
- export const handleCode = (code: number, msg: string) => {
7
+ export const handleCode = (_code: number, _msg: string) => {
10
8
  // 这里处理不同状态
11
9
  }
@@ -6,9 +6,8 @@ import { tansParams } from '@/utils/util'
6
6
  import { checkURL } from '@/utils/validate'
7
7
  import { isBoolean } from '@gx-design-vue/pro-utils'
8
8
  import { GAxios } from './XHR'
9
- import type { XhtInstance } from './typings'
9
+ import type { GAxiosOptions, XhtInstance } from './typings'
10
10
  import { RequestEnum } from './typings'
11
- import type { GAxiosOptions } from './typings'
12
11
  import { handleCode } from './checkStatus'
13
12
 
14
13
  const { requestPrefix, successCode, requestTimeout, tokenName, contentType } = settings
@@ -122,7 +121,7 @@ const xhtInstance: XhtInstance = {
122
121
  requestCatchHook: () => false
123
122
  }
124
123
 
125
- function createXhr(opt ?: Partial<GAxiosOptions>) {
124
+ function createXhr(opt?: Partial<GAxiosOptions>) {
126
125
  return new GAxios({
127
126
  method: 'get',
128
127
  timeout: requestTimeout,
@@ -138,6 +137,6 @@ function createXhr(opt ?: Partial<GAxiosOptions>) {
138
137
  })
139
138
  }
140
139
 
141
- const request: (opt?: GAxiosOptions) => Promise<ResponseResult> = (opt) => createXhr().request(opt)
140
+ const request: <T = any, R = undefined>(opt?: GAxiosOptions) => Promise<ResponseResult<T, R>> = opt => createXhr().request(opt)
142
141
 
143
142
  export default request
@@ -1,6 +1,27 @@
1
- import type { AxiosRequestConfig, AxiosResponse, Axios, AxiosPromise } from 'axios'
1
+ import type {
2
+ AxiosError,
3
+ AxiosInstance,
4
+ AxiosInterceptorManager,
5
+ AxiosInterceptorOptions,
6
+ AxiosPromise,
7
+ AxiosRequestConfig,
8
+ AxiosResponse,
9
+ InternalAxiosRequestConfig,
10
+ Method
11
+ } from 'axios'
12
+
13
+ export interface GAxiosResponse<T = any> extends Omit<AxiosResponse, 'data' | 'config'> {
14
+ data: T;
15
+ config: Omit<GAxiosOptions, 'headers'>;
16
+ }
17
+
18
+ export interface CancelOptions {
19
+ cancel: (key?: string) => void,
20
+ cancelAll: () => void;
21
+ reset: () => void
22
+ }
2
23
 
3
- export type XhtInstance = {
24
+ export interface XhtInstance {
4
25
  /**
5
26
  * @Author gx12358
6
27
  * @DateTime 2023/1/6
@@ -9,10 +30,18 @@ export type XhtInstance = {
9
30
  */
10
31
  beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
11
32
 
33
+ /**
34
+ * @Author gx12358
35
+ * @DateTime 2023/11/3
36
+ * @lastTime 2023/11/3
37
+ * @description 请求之前返回cancel函数
38
+ */
39
+ cancelCallBackHook?: ({ cancel, cancelAll, reset }: CancelOptions) => void;
40
+
12
41
  /**
13
42
  * @description: 处理响应数据
14
43
  */
15
- transformResponseHook?: (res: AxiosResponse, options: GAxiosOptions) => any;
44
+ transformResponseHook?: (res: GAxiosResponse, options: Partial<GAxiosOptions>) => any;
16
45
 
17
46
  /**
18
47
  * @description: 请求失败处理
@@ -27,69 +56,98 @@ export type XhtInstance = {
27
56
  /**
28
57
  * @description: 请求之后的拦截器
29
58
  */
30
- responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
59
+ responseInterceptors?: (res: GAxiosResponse) => GAxiosResponse;
31
60
 
32
61
  /**
33
62
  * @description: 请求之前的拦截器错误处理
34
63
  */
35
- requestInterceptorsCatch?: (error: Error) => void;
64
+ requestInterceptorsCatch?: (error: AxiosError) => void;
36
65
 
37
66
  /**
38
67
  * @description: 请求之后的拦截器错误处理
39
68
  */
40
- responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: Error) => void;
69
+ responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: AxiosError) => void;
41
70
  }
42
71
 
43
- export interface GAxiosOptions extends AxiosRequestConfig {
44
- headers?: RecordType;
72
+ export interface GAxiosOptions extends Omit<AxiosRequestConfig, 'headers' | 'method'> {
73
+ headers?: Record<string, any>;
74
+ method: Method;
45
75
  isMock?: boolean; // 是否是mock
76
+ retry?: boolean; // 是否是重试接口
46
77
  isReturnNativeResponse?: boolean; // 直接返回response,不作任何处理(包含响应值等基本信息)
47
78
  customize?: boolean; // 直接返回response.data(接口返回值),错误不做统一提示
48
79
  carryToken?: boolean; // 是否携带token
80
+ prefix?: string; // 接口自定义前缀
49
81
  ignoreCancelToken?: boolean; // 忽略重复请求
82
+ cancelKey?: string; // 取消请求key(用来需要请求)
50
83
  /**
51
84
  * @Author gx12358
52
85
  * @DateTime 2023/1/6
53
86
  * @lastTime 2023/1/6
54
87
  * @description 请求之前处理config
55
88
  */
56
- beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
89
+ beforeRequestHook?: XhtInstance['beforeRequestHook'];
90
+
91
+ /**
92
+ * @Author gx12358
93
+ * @DateTime 2023/11/3
94
+ * @lastTime 2023/11/3
95
+ * @description 请求之前返回cancel函数
96
+ */
97
+ cancelCallBackHook?: XhtInstance['cancelCallBackHook'];
57
98
 
58
99
  /**
59
100
  * @description: 处理响应数据
60
101
  */
61
- transformResponseHook?: (res: AxiosResponse, options: GAxiosOptions) => any;
102
+ transformResponseHook?: XhtInstance['transformResponseHook'];
62
103
 
63
104
  /**
64
105
  * @description: 请求失败处理
65
106
  */
66
- requestCatchHook?: (e: Error) => boolean;
107
+ requestCatchHook?: XhtInstance['requestCatchHook'];
67
108
 
68
109
  /**
69
110
  * @description: 请求之前的拦截器
70
111
  */
71
- requestInterceptors?: (config: GAxiosOptions) => GAxiosOptions;
112
+ requestInterceptors?: XhtInstance['requestInterceptors'];
72
113
 
73
114
  /**
74
115
  * @description: 请求之后的拦截器
75
116
  */
76
- responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
117
+ responseInterceptors?: XhtInstance['responseInterceptors'];
77
118
 
78
119
  /**
79
120
  * @description: 请求之前的拦截器错误处理
80
121
  */
81
- requestInterceptorsCatch?: (error: Error) => void;
122
+ requestInterceptorsCatch?: XhtInstance['requestInterceptorsCatch'];
82
123
 
83
124
  /**
84
125
  * @description: 请求之后的拦截器错误处理
85
126
  */
86
- responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: Error) => void;
127
+ responseInterceptorsCatch?: XhtInstance['responseInterceptorsCatch'];
87
128
  }
88
129
 
89
- export interface GAxiosInstance extends Axios {
130
+ export interface GAxiosInstance extends Omit<AxiosInstance, 'interceptors'> {
90
131
  (config: GAxiosOptions): AxiosPromise<ResponseResult>;
91
132
 
92
133
  (url: string, config?: GAxiosOptions): AxiosPromise<ResponseResult>;
134
+
135
+ interceptors: {
136
+ request: Omit<AxiosInterceptorManager<InternalAxiosRequestConfig>, 'use'> & {
137
+ use<V>(
138
+ onFulfilled?: ((value: V) => V | Promise<V>) | null,
139
+ onRejected?: ((error: any) => any) | null,
140
+ options?: AxiosInterceptorOptions
141
+ ): number;
142
+ };
143
+ response: Omit<AxiosInterceptorManager<AxiosResponse>, 'use'> & {
144
+ use<V>(
145
+ onFulfilled?: ((value: V) => V | Promise<V>) | null,
146
+ onRejected?: ((error: any) => any) | null,
147
+ options?: AxiosInterceptorOptions
148
+ ): number;
149
+ };
150
+ }
93
151
  }
94
152
 
95
153
  /**
@@ -111,4 +169,3 @@ export enum ContentTypeEnum {
111
169
  // form-data qs
112
170
  FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
113
171
  }
114
-
@@ -1,15 +1,18 @@
1
1
  import dayjs from 'dayjs'
2
- import { isPro } from '@/utils/env'
3
- import { Decrypt, Encrypt } from '@/utils/cryptoJS'
2
+ import { isPro, typeViteEnv } from '@/utils/env'
3
+ import { Decrypt, Encrypt } from '@/utils/crypto'
4
4
  import { isJSONStr } from '@/utils/validate'
5
5
  import { isObject } from '@gx-design-vue/pro-utils'
6
6
 
7
+ export type StorageKey = 'localStorage' | 'sessionStorage' | 'cookie'
8
+
7
9
  function isEncryption(status: boolean) {
8
10
  return isPro() ? status : false
9
11
  }
10
12
 
11
13
  function handleStorageValue(value: string) {
12
- if (isJSONStr(value)) return JSON.parse(value)
14
+ if (isJSONStr(value))
15
+ return JSON.parse(value)
13
16
  return value
14
17
  }
15
18
 
@@ -21,10 +24,9 @@ function handleStorageValue(value: string) {
21
24
  */
22
25
  export function getStorageKey(key: string, originKey?: boolean) {
23
26
  const { pkg } = __APP_INFO__
24
- const { VITE_USE_MODE, VITE_APP_ENV } = import.meta.env
25
- return originKey ? key : `live_${pkg.version}_${VITE_APP_ENV === 'dev'
27
+ return originKey ? key : `${pkg.name}_${pkg.version}_${typeViteEnv('VITE_APP_ENV') === 'dev'
26
28
  ? 'development'
27
- : VITE_USE_MODE}_${key}`
29
+ : typeViteEnv('VITE_USE_MODE')}_${key}`
28
30
  }
29
31
 
30
32
  /**
@@ -36,15 +38,16 @@ export function getStorageKey(key: string, originKey?: boolean) {
36
38
  export function getStorage({
37
39
  key,
38
40
  encryption = true,
39
- type = 'local',
41
+ type = 'localStorage',
40
42
  originKey
41
- }: { key: string, encryption?: boolean, type?: string, originKey?: boolean }) {
42
- const storageValue = type === 'local' ?
43
- localStorage.getItem(getStorageKey(key, originKey))
44
- : sessionStorage.getItem(getStorageKey(key, originKey))
45
- const result: string | LocalResult = storageValue ?
46
- isEncryption(encryption) ? Decrypt(storageValue) : handleStorageValue(storageValue)
47
- : ''
43
+ }: { key: string, encryption?: boolean, type?: StorageKey, originKey?: boolean }) {
44
+ const storageValue = type === 'localStorage'
45
+ ? localStorage.getItem(getStorageKey(key, originKey)) : type === 'sessionStorage'
46
+ ? sessionStorage.getItem(getStorageKey(key, originKey))
47
+ : getCookie(
48
+ getStorageKey(key, originKey))
49
+ const result: string | LocalResult = storageValue
50
+ ? isEncryption(encryption) ? Decrypt(storageValue) : handleStorageValue(storageValue) : ''
48
51
  if (result && isObject(result)) {
49
52
  if (result.expired) {
50
53
  const expiredStatus = dayjs().diff(dayjs(result.time)) >= result.expired
@@ -83,8 +86,10 @@ export function setStorage({
83
86
  time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
84
87
  expired: expired || 0
85
88
  }
86
- const storageValue = isEncryption(encryption) ? Encrypt(JSON.stringify(result)) : JSON.stringify(result)
87
- if (type === 'local') localStorage.setItem(getStorageKey(key, originKey), storageValue)
89
+ const storageValue = isEncryption(encryption) ? Encrypt(JSON.stringify(result)) : JSON.stringify(
90
+ result)
91
+ if (type === 'local')
92
+ localStorage.setItem(getStorageKey(key, originKey), storageValue)
88
93
  sessionStorage.setItem(getStorageKey(key, originKey), storageValue)
89
94
  }
90
95
 
@@ -95,7 +100,8 @@ export function setStorage({
95
100
  * @description 删除Storage
96
101
  */
97
102
  export function removeStorage(key: string, type = 'local', originKey?: boolean) {
98
- if (type === 'local') localStorage.removeItem(getStorageKey(key, originKey))
103
+ if (type === 'local')
104
+ localStorage.removeItem(getStorageKey(key, originKey))
99
105
  sessionStorage.removeItem(getStorageKey(key, originKey))
100
106
  }
101
107
 
@@ -130,7 +136,8 @@ function getCookies(cname: string) {
130
136
  function GetCookieDomain() {
131
137
  let host = location.hostname
132
138
  const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
133
- if (ip.test(host) === true || host === 'localhost') return host
139
+ if (ip.test(host) === true || host === 'localhost')
140
+ return host
134
141
  const regex = /([^]*).*/
135
142
  const match = host.match(regex)
136
143
  if (typeof match !== 'undefined' && match !== null) {
@@ -1,7 +1,3 @@
1
- export function deepCopy(data) {
2
- return JSON.parse(JSON.stringify(data))
3
- }
4
-
5
1
  /**
6
2
  * @Author gx12358
7
3
  * @DateTime 2021/11/3
@@ -29,4 +25,3 @@ export function tansParams(params) {
29
25
  }
30
26
  return result
31
27
  }
32
-