quick-platform 1.0.46

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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/application/constants.d.ts +4 -0
  4. package/dist/application/index.d.ts +29 -0
  5. package/dist/application/manage.d.ts +31 -0
  6. package/dist/business/index.d.ts +72 -0
  7. package/dist/business/version.d.ts +7 -0
  8. package/dist/components/IconFont.d.ts +4 -0
  9. package/dist/components/LocalDebug.d.ts +6 -0
  10. package/dist/components/MicroApp.d.ts +14 -0
  11. package/dist/components/Permission.d.ts +6 -0
  12. package/dist/components/context.d.ts +3 -0
  13. package/dist/components/i18n.d.ts +2 -0
  14. package/dist/config.d.ts +2 -0
  15. package/dist/config.js +2 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/event.d.ts +13 -0
  18. package/dist/index-543d110b.js +547 -0
  19. package/dist/index-543d110b.js.map +1 -0
  20. package/dist/index-be61d86b.js +2 -0
  21. package/dist/index-be61d86b.js.map +1 -0
  22. package/dist/index.d.ts +12 -0
  23. package/dist/index.js +2 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/theme/define/color.d.ts +9 -0
  26. package/dist/theme/define/font.d.ts +50 -0
  27. package/dist/theme/define/index.d.ts +5 -0
  28. package/dist/theme/define/size.d.ts +24 -0
  29. package/dist/theme/define/style.d.ts +21 -0
  30. package/dist/theme/doc.d.ts +2 -0
  31. package/dist/theme/index.d.ts +3 -0
  32. package/dist/theme/lib/index.d.ts +1 -0
  33. package/dist/theme/react/hook.d.ts +5 -0
  34. package/dist/theme/react/index.d.ts +3 -0
  35. package/dist/theme/uno.d.ts +19 -0
  36. package/dist/utils/i18n.d.ts +6 -0
  37. package/dist/utils/image.d.ts +2 -0
  38. package/dist/utils/index.d.ts +5 -0
  39. package/dist/utils/localstorage.d.ts +6 -0
  40. package/dist/utils/request.d.ts +37 -0
  41. package/dist/utils/utils.d.ts +3 -0
  42. package/package.json +67 -0
  43. package/src/application/constants.ts +7 -0
  44. package/src/application/index.ts +82 -0
  45. package/src/application/manage.ts +119 -0
  46. package/src/business/declare.d.ts +39 -0
  47. package/src/business/index.ts +130 -0
  48. package/src/business/version.ts +58 -0
  49. package/src/components/IconFont.ts +11 -0
  50. package/src/components/LocalDebug.ts +244 -0
  51. package/src/components/MicroApp.ts +97 -0
  52. package/src/components/Permission.ts +13 -0
  53. package/src/components/context.ts +31 -0
  54. package/src/components/i18n.ts +17 -0
  55. package/src/config.ts +3 -0
  56. package/src/event.ts +24 -0
  57. package/src/index.ts +38 -0
  58. package/src/theme/define/color.ts +53 -0
  59. package/src/theme/define/font.ts +29 -0
  60. package/src/theme/define/index.ts +8 -0
  61. package/src/theme/define/size.ts +31 -0
  62. package/src/theme/define/style.ts +41 -0
  63. package/src/theme/doc.tsx +438 -0
  64. package/src/theme/index.ts +5 -0
  65. package/src/theme/lib/index.ts +15 -0
  66. package/src/theme/react/hook.ts +42 -0
  67. package/src/theme/react/index.ts +14 -0
  68. package/src/theme/uno.ts +218 -0
  69. package/src/utils/i18n.ts +84 -0
  70. package/src/utils/image.ts +52 -0
  71. package/src/utils/index.ts +9 -0
  72. package/src/utils/localstorage.ts +32 -0
  73. package/src/utils/request.ts +173 -0
  74. package/src/utils/utils.ts +15 -0
@@ -0,0 +1,42 @@
1
+ import React, { useContext, useState } from 'react';
2
+
3
+ import { Color } from '../define';
4
+ import { setPrimaryColor } from '../lib';
5
+
6
+ const ThemeContext = React.createContext({
7
+ colorPrimary: Color.PrimaryColor,
8
+ setPrimaryColor(_color: string) {},
9
+ });
10
+
11
+ export const ReactThemeHOC = <T extends {}>(
12
+ Component: React.FunctionComponent<T>,
13
+ ): React.FC<T> => {
14
+ return (props) => {
15
+ // eslint-disable-next-line react-hooks/rules-of-hooks
16
+ const [primaryColor, setPrimaryColor] = useState(Color.PrimaryColor);
17
+ return React.createElement(
18
+ ThemeContext.Provider,
19
+ {
20
+ key: 'theme-hoc',
21
+ value: {
22
+ colorPrimary: primaryColor,
23
+ setPrimaryColor(color) {
24
+ setPrimaryColor(color);
25
+ },
26
+ },
27
+ },
28
+ [React.createElement(Component, { ...props, key: 'theme-hoc-component' })],
29
+ );
30
+ };
31
+ };
32
+
33
+ export const useThemePrimaryColor = () => {
34
+ const context = useContext(ThemeContext);
35
+ return {
36
+ color: context.colorPrimary,
37
+ set(color: string) {
38
+ context.setPrimaryColor(color);
39
+ setPrimaryColor(color);
40
+ },
41
+ };
42
+ };
@@ -0,0 +1,14 @@
1
+ import { ReactThemeHOC, useThemePrimaryColor } from './hook';
2
+
3
+ export const ThemeHOC = <T extends {}>(
4
+ Component: React.FC<T>
5
+ // options: { antd?: boolean; iconPark?: boolean; antdPrefixCls?: string } = {},
6
+ ): React.FC<T> => {
7
+ // const { antd = true } = options;
8
+ // if (antd) {
9
+ // Component = AntdHOC(Component, { prefixCls: options.antdPrefixCls });
10
+ // }
11
+ return ReactThemeHOC(Component);
12
+ };
13
+
14
+ export { useThemePrimaryColor };
@@ -0,0 +1,218 @@
1
+ import { Color, Font, Size, Style } from './define';
2
+
3
+ const prefix = 'q-';
4
+
5
+ const convertToCss = (obj: any) => {
6
+ const toUnit = (value: string | number) => {
7
+ if (typeof value === 'number') return value + 'px';
8
+ return value;
9
+ };
10
+ return Object.keys(obj).reduce<any>((css, key) => {
11
+ css[toLine(key)] = toUnit(obj[key]); //todo 转rem
12
+ return css;
13
+ }, {});
14
+ };
15
+
16
+ const colors = (() => {
17
+ const convertToConfig = (origin: any, colors: any) => {
18
+ return Object.keys(colors).reduce<any>((map, key) => {
19
+ const varKey = Color.generateVar(key);
20
+ map['colors'][prefix + key] = `var(${varKey})`; //colors[key];
21
+ map['preflights'].push(
22
+ `.bg-${prefix}${key}{ background-color:var(${varKey})}\n.text-${prefix}${key}{ color:var(${varKey})}`
23
+ );
24
+ map['vars'].push(`${varKey}:${colors[key]};`);
25
+ return map;
26
+ }, origin);
27
+ };
28
+ return [
29
+ Color.BrandColor,
30
+ // Color.NeutralColor,
31
+ // Color.NeutralHelperColor,
32
+ // Color.FunctionalColor,
33
+ // Color.FunctionalHelperColor,
34
+ { primary: Color.PrimaryColor },
35
+ ].reduce(convertToConfig, {
36
+ colors: {},
37
+ preflights: [],
38
+ vars: [],
39
+ });
40
+ })();
41
+
42
+ const toLine = (str: string) => {
43
+ return str.replace(/\B([A-Z])/g, '-$1').toLowerCase();
44
+ };
45
+
46
+ const toCamel = (str: string) => {
47
+ return str
48
+ .replace(/\-(\w)/g, function(_, letter) {
49
+ return letter.toUpperCase();
50
+ })
51
+ .replace(/^[a-z]/, m => m.toUpperCase());
52
+ };
53
+
54
+ const fonts = (() => {
55
+ const results = {
56
+ rules: [] as [RegExp, Function][],
57
+ };
58
+
59
+ const convertToRules = (rule: RegExp, fonts: any) => {
60
+ results.rules!.push([
61
+ rule,
62
+ ([_, match]: any) => {
63
+ const name = toCamel(match);
64
+ if (fonts[name]) return convertToCss(fonts[name]);
65
+ return {};
66
+ },
67
+ ]);
68
+ };
69
+ convertToRules(/^text-q-([a-zA-Z-]+)$/, Font.TextFont);
70
+ convertToRules(/^title-q-([a-zA-Z-]+)$/, Font.TitleFont);
71
+ return results;
72
+ })();
73
+
74
+ const size = (() => {
75
+ const results = {
76
+ shortcuts: [] as [RegExp, Function][],
77
+ vars: {},
78
+ };
79
+ const matchCovert = (match: string[]) => ({
80
+ origin: match[0],
81
+ type: match[1],
82
+ value: match[2],
83
+ });
84
+ const convertToShortCuts = (
85
+ rule: RegExp,
86
+ size: any,
87
+ {
88
+ prefix = '',
89
+ covert = matchCovert,
90
+ }: {
91
+ prefix?: string;
92
+ covert?: typeof matchCovert;
93
+ }
94
+ ) => {
95
+ results.shortcuts!.push([
96
+ rule,
97
+ (match: any) => {
98
+ const { origin: _, type, value } = covert(match);
99
+ if (/title|text|top/.test(type)) return _;
100
+ if (!prefix) {
101
+ // 不为数字的情况,针对内置的样式需要过滤处理
102
+ if (/^(border)|(rd)|shadow/.test(type)) return _;
103
+ }
104
+
105
+ if (size[prefix + value]) {
106
+ if (Array.isArray(type))
107
+ return type.map(t => `${t}-${size[prefix + value]}px`).join(' ');
108
+ return `${type}-${size[prefix + value]}px`; //todo toRem
109
+ }
110
+ return _;
111
+ },
112
+ ]);
113
+ };
114
+ convertToShortCuts(/^(.*)-q-(\d+)$/, Size.BaseSize, { prefix: 'size-' });
115
+ // convertToShortCuts(/^(.*)-q-([a-z]*)$/, Size.ComponentSize, {});
116
+ convertToShortCuts(/^(m(-[rltbxy]+)?)-q-([a-z]*)$/, Size.MarginSize, {
117
+ covert(match) {
118
+ const res = matchCovert(match);
119
+ res.value = match[3];
120
+ if (res.type === 'm-lr' || res.type === 'm-x') {
121
+ res.type = ['m-l', 'm-r'] as any;
122
+ }
123
+ if (res.type === 'm-tb' || res.type === 'm-y') {
124
+ res.type = ['m-t', 'm-b'] as any;
125
+ }
126
+ return res;
127
+ },
128
+ });
129
+ convertToShortCuts(/^(p(-[rltbxy]+)?)-q-([a-z]*)$/, Size.MarginSize, {
130
+ covert(match) {
131
+ const res = matchCovert(match);
132
+ res.value = match[3];
133
+ if (res.type === 'p-lr' || res.type === 'p-x') {
134
+ res.type = ['p-l', 'p-r'] as any;
135
+ }
136
+ if (res.type === 'p-tb' || res.type === 'p-y') {
137
+ res.type = ['p-t', 'p-b'] as any;
138
+ }
139
+
140
+ return res;
141
+ },
142
+ });
143
+
144
+ convertToShortCuts(/^(gap)-q-([a-z]*)$/, Size.MarginSize, {});
145
+
146
+ return results;
147
+ })();
148
+
149
+ const styles = (() => {
150
+ const results = {
151
+ rules: [] as [RegExp, Function, any][],
152
+ };
153
+
154
+ const convertToRules = (rule: RegExp, style: any, convert = convertToCss) => {
155
+ results.rules!.push([
156
+ rule,
157
+ ([_, match]: any) => {
158
+ const name = toCamel(match);
159
+ if (style[name]) return convert(style[name]);
160
+ return {};
161
+ },
162
+ {
163
+ // layer: 'weight-lower',
164
+ },
165
+ ]);
166
+ };
167
+ convertToRules(/^rd-q-([a-zA-Z-]+)$/, Style.BorderRadius);
168
+ convertToRules(/^border-q-([a-zA-Z-]+)$/, Style.Border);
169
+ ['left', 'right', 'bottom', 'top'].forEach(dir => {
170
+ convertToRules(
171
+ new RegExp(`^border-${dir.slice(0, 1)}-${prefix}([a-zA-Z-]+)$`),
172
+ Style.Border,
173
+ style => {
174
+ return {
175
+ [`border-${dir}`]: `${style.borderWidth}px ${style.borderStyle} ${style.borderColor}`,
176
+ };
177
+ }
178
+ );
179
+ });
180
+ convertToRules(/^shadow-q-([a-zA-Z0-9-]+)$/, Style.Shadow, shadow => {
181
+ return {
182
+ 'box-shadow': `${shadow.offsetX}px ${shadow.offsetY}px ${shadow.blurRadius}px ${shadow.spreadRadius}px ${shadow.color}`,
183
+ };
184
+ });
185
+ return results;
186
+ })();
187
+
188
+ export const UnoConfig = () => {
189
+ return {
190
+ // ...UnoCSS options
191
+ content: {
192
+ pipeline: {
193
+ include: ['src/**/*.{js,ts,tsx}'],
194
+ },
195
+ },
196
+ rules: [...fonts.rules!, ...styles.rules!],
197
+ theme: {
198
+ colors: colors.colors,
199
+ },
200
+ shortcuts: [...size.shortcuts],
201
+ layers: {
202
+ default: 1,
203
+ 'weight-lower': -1,
204
+ },
205
+ preflights: [
206
+ {
207
+ getCSS() {
208
+ return `:root{${colors.vars.join('\n')} }`;
209
+ },
210
+ },
211
+ {
212
+ getCSS() {
213
+ return colors.preflights;
214
+ },
215
+ },
216
+ ],
217
+ };
218
+ };
@@ -0,0 +1,84 @@
1
+ import { getSystem } from '../business';
2
+ import { isMicroApp } from './utils';
3
+
4
+ const baseUrl =
5
+ 'https://quick-multilingual.obs.ap-southeast-3.myhuaweicloud.com';
6
+
7
+ const langMap = {
8
+ 'zh-CN': 'zh',
9
+ 'en-US': 'en',
10
+ ko: 'ko',
11
+ ja: 'ja',
12
+ 'zh-TW': 'zh-tw',
13
+ };
14
+
15
+ const getI18nConfigUrl = (
16
+ env: 'test' | 'dev' | 'prod',
17
+ name: string,
18
+ lang: 'zh-CN' | 'en-US' | 'ko' | 'ja' | 'zh-TW'
19
+ ) => {
20
+ if (env === 'prod') return `${baseUrl}/${name}/${langMap[lang]}.json`;
21
+ return `${baseUrl}/${name}/${env}/${langMap[lang]}.json`;
22
+ };
23
+
24
+ const loadRemoteI18n = (
25
+ env: string,
26
+ name: string,
27
+ lang: 'zh-CN' | 'en-US' | 'ko' | 'ja' | 'zh-TW'
28
+ ) => {
29
+ let url = '';
30
+ if (env === 'dev') {
31
+ url = getI18nConfigUrl('dev', name, lang);
32
+ } else {
33
+ url = getI18nConfigUrl(env === 'prod' ? 'prod' : 'test', name, lang);
34
+ }
35
+ return fetch(`${url}?t=${Date.now()}`)
36
+ .then(res => {
37
+ return res.json();
38
+ })
39
+ .catch(() => ({}));
40
+ };
41
+
42
+ const $$i18n = (text: string, value: Record<string, any> = {}) => {
43
+ return text.replace(/\{[a-zA-Z_0-9]*\}/g, key => {
44
+ return value[key.slice(1, -1)];
45
+ });
46
+ };
47
+
48
+ const initI18n = (name: string, env?: string) => {
49
+ const messages: Record<string, string> = {};
50
+ const system = getSystem();
51
+
52
+ return {
53
+ messages,
54
+ setup() {
55
+ const lang: any = (() => {
56
+ if (isMicroApp) return system.lang;
57
+ return (
58
+ window.localStorage.getItem('quick_local_debug_lang') || system.lang
59
+ );
60
+ })();
61
+ return loadRemoteI18n(env || 'prod', name, lang).then(lang => {
62
+ Object.assign(messages, lang);
63
+ });
64
+ },
65
+ i18n(key: string, value?: Record<string, string>) {
66
+ const content = messages[key];
67
+ if (typeof content === 'undefined') return key;
68
+ if (!value) return content;
69
+ return content.replace(/\{[a-zA-Z_0-9]*\}/g, key => {
70
+ return value[key.slice(1, -1)];
71
+ });
72
+ },
73
+ };
74
+ };
75
+
76
+ export const installI18n = (name: string, env?: string) => {
77
+ const { i18n, setup, messages } = initI18n(name, env);
78
+ return {
79
+ $i18n: i18n,
80
+ $$i18n,
81
+ messages,
82
+ loadPromise: setup(),
83
+ };
84
+ };
@@ -0,0 +1,52 @@
1
+ import heic2any from 'heic2any';
2
+
3
+ const handlerBlob = (url: string, blob: Blob) =>
4
+ new Promise<string>((resolve, reject) => {
5
+ const img = new window.Image();
6
+ img.src = URL.createObjectURL(blob);
7
+ img.onload = resolve.bind(null, img.src);
8
+ img.onerror = reject.bind(null, url);
9
+ });
10
+
11
+ // eslint-disable-next-line max-len
12
+ const createFetch = (handler: (url: string) => Promise<Blob>) => (
13
+ url: string
14
+ ): Promise<string> =>
15
+ handler(url)
16
+ .then(handlerBlob.bind(null, url))
17
+ .catch(() => Promise.reject(url));
18
+
19
+ // eslint-disable-next-line max-len
20
+ const tryHeic = createFetch(url =>
21
+ fetch(url, { headers: {}, mode: 'cors' })
22
+ .then(res => res.blob())
23
+ .then(blob => heic2any({ blob }))
24
+ .then(blob => {
25
+ if (Array.isArray(blob)) return blob[0];
26
+ return blob;
27
+ })
28
+ );
29
+
30
+ // const tryProxy = createFetch((url) => fetch(`/store/stream/downloadFileStream?fileUrl=${encodeURIComponent(url)}`).then((res) => res.blob()));
31
+
32
+ const stack: Map<string, Promise<string>> = new Map();
33
+ const tryCache = (url: string, fetch: (url: string) => Promise<string>) => {
34
+ if (stack.has(url)) return stack.get(url)!;
35
+ const promise = fetch(url);
36
+ stack.set(url, promise);
37
+ promise.finally(() => {
38
+ stack.delete(url);
39
+ });
40
+ return promise;
41
+ };
42
+
43
+ const tryImageTranscode = function(
44
+ url: string,
45
+ customTry?: (url: string) => Promise<Blob>
46
+ ) {
47
+ if (!customTry) return tryCache(url, () => tryHeic(url));
48
+ const customTryProxy = createFetch(customTry);
49
+ return tryCache(url, () => tryHeic(url).catch(customTryProxy));
50
+ };
51
+
52
+ export { tryImageTranscode };
@@ -0,0 +1,9 @@
1
+ import { isMicroApp } from './utils';
2
+
3
+ export * from './image';
4
+
5
+ export * from './request';
6
+
7
+ export * from './i18n';
8
+
9
+ export { isMicroApp };
@@ -0,0 +1,32 @@
1
+ /*
2
+ * @Author: zhaoxuan (zhaoxuan@quickcep.com)
3
+ * @LastEditors: zhaoxuan (zhaoxuan@quickcep.com)
4
+ * @Date: 2023-05-10 13:42:03
5
+ * @Description:
6
+ * @LastEditDescription:
7
+ * @LastEditTime: 2023-05-10 17:36:24
8
+ */
9
+ const ls = {
10
+ getData(key: string) {
11
+ const data = window.localStorage.getItem(key);
12
+ if (data) {
13
+ try {
14
+ return JSON.parse(data);
15
+ } catch (e) {
16
+ console.error(e);
17
+ }
18
+ }
19
+ return null;
20
+ },
21
+ setData(key: string, value: any) {
22
+ try {
23
+ window.localStorage.setItem(key, JSON.stringify(value));
24
+ } catch (e) {
25
+ console.error(e);
26
+ }
27
+ },
28
+ removeItem(key: string) {
29
+ window.localStorage.removeItem(key);
30
+ },
31
+ };
32
+ export default ls;
@@ -0,0 +1,173 @@
1
+ import axios, { AxiosInstance, CancelTokenSource } from 'axios';
2
+ const CancelToken = axios.CancelToken;
3
+
4
+ export interface IResponse<Data> {
5
+ code: number;
6
+ message: string;
7
+ success: boolean;
8
+ data: Data;
9
+ }
10
+ export interface IResponsePage<Data> {
11
+ pageIndex: number; // 当前分页
12
+ pageSize: number; // 分页条数
13
+ total: number; // 总数
14
+ row: Data[];
15
+ }
16
+ export type TPageRequest<Params> = {
17
+ pageIndex?: number;
18
+ pageSize?: number;
19
+ } & Params;
20
+
21
+ interface IRequestConfig {
22
+ cancelTokenSource?: CancelTokenSource;
23
+ }
24
+ type TCanceler = (reason?: string) => void;
25
+
26
+ type IMethod = <D = any, P extends Record<string, any> = any>(
27
+ url: string,
28
+ params?: P,
29
+ config?: IRequestConfig
30
+ ) => Promise<D>;
31
+
32
+ interface TCancelCreator {
33
+ <
34
+ T extends (
35
+ url: string,
36
+ params?: any,
37
+ config?: IRequestConfig
38
+ ) => ReturnType<IMethod>
39
+ >(
40
+ request: T
41
+ ): (...args: Parameters<T>) => [ReturnType<T>, TCanceler];
42
+ <T extends (params?: any, config?: IRequestConfig) => ReturnType<IMethod>>(
43
+ request: T
44
+ ): (...args: Parameters<T>) => [ReturnType<T>, TCanceler];
45
+ }
46
+
47
+ const createMethods = (
48
+ inst: AxiosInstance,
49
+ requestQueue: CancelTokenSource[]
50
+ ) => {
51
+ return ['get', 'post'].map(method => {
52
+ return <D = any, P extends Record<string, any> = any>(
53
+ url: string,
54
+ params?: P,
55
+ config?: IRequestConfig
56
+ ) => {
57
+ const source = config?.cancelTokenSource || CancelToken.source();
58
+ delete config?.cancelTokenSource;
59
+ const requestConfig = {
60
+ [method === 'get' ? 'params' : 'data']: params,
61
+ };
62
+ requestQueue.push(source);
63
+
64
+ const requestUrl = url.replace(/\{([a-zA-Z]+)\}/g, (_match, key) => {
65
+ if (!params) return key;
66
+ const value = params[key] || key;
67
+ /**兼容不删除的场景*/
68
+ if (!params['saveQuery']) {
69
+ delete params[key];
70
+ } else {
71
+ console.log('params', params);
72
+ delete params['saveQuery'];
73
+ }
74
+ return value;
75
+ });
76
+ return inst
77
+ .request<IResponse<D>>({
78
+ url: requestUrl,
79
+ method: method.toUpperCase() as any,
80
+ cancelToken: source.token,
81
+ ...requestConfig,
82
+ ...(config || {}),
83
+ })
84
+ .then(res => res?.data)
85
+ .then(res => {
86
+ if (!(res as any).success) return Promise.reject(res);
87
+ return res.data;
88
+ });
89
+ };
90
+ });
91
+ };
92
+
93
+ const createAbort = (queue: CancelTokenSource[]): TCanceler => {
94
+ return (reason?: string) => {
95
+ while (queue.length) {
96
+ queue.shift()!.cancel(reason);
97
+ }
98
+ };
99
+ };
100
+
101
+ const creatorFactory = (request: IMethod, config1: IRequestConfig = {}) => <
102
+ D1 = any,
103
+ P1 extends Record<string, any> = any
104
+ >(
105
+ url: string,
106
+ config2: IRequestConfig = {}
107
+ ) => (params: P1, config3: IRequestConfig = {}) =>
108
+ request<D1, P1>(
109
+ url,
110
+ params || ({} as any),
111
+ Object.assign({}, config1, config2, config3)
112
+ );
113
+
114
+ const createAxios = (baseURL: string) => {
115
+ const inst = axios.create({
116
+ baseURL,
117
+ });
118
+ const useResponseInterCeptor = inst.interceptors.response.use.bind(
119
+ inst.interceptors.response
120
+ );
121
+ const useRequestInterCeptor = inst.interceptors.request.use.bind(
122
+ inst.interceptors.request
123
+ );
124
+
125
+ return {
126
+ instance: inst,
127
+ useRequestInterCeptor,
128
+ useResponseInterCeptor,
129
+ };
130
+ };
131
+
132
+ const cancelCreatorFactory = (): TCancelCreator => (request: any) => {
133
+ return (...args: any[]) => {
134
+ const source = CancelToken.source();
135
+ const configIndex = typeof args[0] === 'string' ? 2 : 1;
136
+ args[configIndex] = Object.assign({}, args[configIndex] || {}, {
137
+ cancelTokenSource: source,
138
+ });
139
+ return [
140
+ request(...args),
141
+ (reason: string) => {
142
+ source.cancel(reason);
143
+ },
144
+ ] as any;
145
+ };
146
+ };
147
+
148
+ export const buildHttpCtrl = (server: string) => {
149
+ const requestQueue: CancelTokenSource[] = [];
150
+ const {
151
+ instance: inst,
152
+ useRequestInterCeptor,
153
+ useResponseInterCeptor,
154
+ } = createAxios(server);
155
+ const abort = createAbort(requestQueue);
156
+ const [get, post] = createMethods(inst, requestQueue);
157
+
158
+ const getCreator = creatorFactory(get);
159
+ const postCreator = creatorFactory(post);
160
+ const cancelCreator = cancelCreatorFactory();
161
+ return {
162
+ abort,
163
+ get,
164
+ post,
165
+ cancelCreator,
166
+ getCreator,
167
+ postCreator,
168
+ useRequestInterCeptor,
169
+ useResponseInterCeptor,
170
+ };
171
+ };
172
+
173
+ export default buildHttpCtrl;
@@ -0,0 +1,15 @@
1
+ export const isMicroApp = !!(window as any).__POWERED_BY_QIANKUN__;
2
+
3
+ export const assign = (
4
+ key: string | number,
5
+ value?: any,
6
+ obj?: Record<string, any>
7
+ ) => {
8
+ if (!key || !value) return obj || {};
9
+ return Object.assign(obj || {}, { [key]: value });
10
+ };
11
+
12
+ export const envValue = (prod: string, dev: string) => {
13
+ if (process.env.NODE_ENV === 'production') return prod;
14
+ return dev;
15
+ };