@lingxiteam/ebe-utils 0.4.3 → 0.4.5

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.
@@ -1,4 +1,9 @@
1
1
  import LcdpBaseApi from './lcdpBaseApi';
2
+ import { historytool, HISTORYTYPES } from '@/utils/historytool';
3
+ import { history } from 'alita';
4
+ import message from 'antd/es/message';
5
+ import DrawerMap from '@/components/drawer';
6
+ import ModalMap from '@/components/modal';
2
7
 
3
8
  export declare type LocaleFunction = (key: string, placeholder?: string, kv?: Record<string, string>) => string;
4
9
  // 对应用全局数据和全局方法访问的接口对象,为自定义代码提供更多可能性
@@ -15,26 +20,6 @@ class LcdpApi extends LcdpBaseApi {
15
20
  /* @__HOT_UPDATE__ @alias LcdpApi */
16
21
  constructor(mountObj?: any, singletonLcdpApi?: any) {
17
22
  super(mountObj, singletonLcdpApi);
18
- // 废弃
19
- // this.mount(mountObj);
20
- if (singletonLcdpApi) {
21
- // router 只应该由singletonLcdpApi访问
22
- ['router'].forEach(k => {
23
- (() => {
24
- // eslint-disable-next-line
25
- let val = null;
26
- Object.defineProperty(this, k, {
27
- get() {
28
- return (url: string, lcdpParentRenderId: string, state?: Record<string, any>) =>
29
- singletonLcdpApi[k](url, this.data.pages, this.data.appConfig.appId, lcdpParentRenderId, state);
30
- },
31
- set(value) {
32
- val = value;
33
- },
34
- });
35
- })();
36
- });
37
- }
38
23
  }
39
24
 
40
25
  /**
@@ -46,89 +31,39 @@ class LcdpApi extends LcdpBaseApi {
46
31
  * @param state 组件状态数据
47
32
  */
48
33
  router(url: string, currentAppPages: Array<any>, appId: string, lcdpParentRenderId: string, state?: Record<string, any>) {
49
- const { message } = this.antd;
50
34
  if (!url) {
51
35
  message?.warning(this.getLocale('lcdpApi.router.urlEmpty', '页面跳转地址缺失,请检查'));
52
36
  }
53
- if (/^((http|https):)?\/\/[^\s]+/.test(url) || !this.refs.history || !this.data.pages) {
37
+ if (/^((http|https):)?\/\/[^\s]+/.test(url)) {
54
38
  window.location.href = url;
55
39
  } else {
56
- const isPageId = /^\d+$/.test(url);
57
- let pageData: any = null;
58
- // 优先跳转当前应用页面
59
- if (currentAppPages?.length) {
60
- pageData = isPageId
61
- ? currentAppPages.find((n: any) => n.pageId === url)
62
- : currentAppPages.find((n: any) => url.split('?').includes(n.pagePath));
63
- }
64
- // this.data.pages 包含所有应用页面
65
- if (!pageData) {
66
- pageData = isPageId
67
- ? this.data.pages.find((n: any) => n.pageId === url)
68
- : this.data.pages.find((n: any) => url.split('?').includes(n.pagePath));
69
- }
70
- if (pageData) {
71
- const [pathname, search] = url.split('?');
72
- const searchPamams = search
73
- ? search.split('&').reduce((pre: any, cur: any) => {
74
- const [k, v] = cur.split('=');
75
- if (v) {
76
- pre[decodeURIComponent(k)] = decodeURIComponent(v);
77
- }
78
- return pre;
79
- }, {})
80
- : {};
81
- switch (pageData.pageContainerType) {
82
- case 'Page': {
83
- let realSearch = search;
84
- if (!searchPamams?.appId) {
85
- realSearch = `${search === undefined ? '?' : `${search}&`}appId=${pageData.appId || appId}`;
86
- }
87
- this.refs.history.push({
88
- pathname,
89
- search: realSearch,
90
- });
91
- break;
92
- }
93
- case 'Drawer': {
94
- try {
95
- this.refs.ModalManager.current.openDrawer({
96
- pageId: pageData.pageId,
97
- params: {
98
- ...searchPamams,
99
- ...state,
100
- },
101
- lcdpParentRenderId,
102
- });
103
- } catch (e) {
104
- console.error(e);
105
- message?.warning(this.getLocale('lcdpApi.router.openFail', '打开新页面失败,缺失Drawer', { type: 'Drawer' }));
106
- }
107
- break;
108
- }
109
- case 'Modal':
110
- case 'MobileModal': {
111
- try {
112
- this.refs.ModalManager.current.openModal({
113
- pageId: pageData.pageId,
114
- params: searchPamams,
115
- lcdpParentRenderId,
116
- });
117
- } catch (e) {
118
- console.error(e);
119
- message?.warning(this.getLocale('lcdpApi.router.openFail', '打开新页面失败,缺失Modal', { type: 'Modal' }));
120
- }
121
- break;
122
- }
123
- default: {
124
- message?.warning(
125
- this.getLocale('lcdpApi.router.notSupport', `不支持的页面类型: ${pageData.pageContainerType}`, { type: pageData.pageContainerType })
126
- );
127
- break;
40
+ const [pathname, search] = url.split('?');
41
+ const searchPamams = search
42
+ ? search.split('&').reduce((pre: any, cur: any) => {
43
+ const [k, v] = cur.split('=');
44
+ if (v) {
45
+ pre[decodeURIComponent(k)] = decodeURIComponent(v);
128
46
  }
129
- }
47
+ return pre;
48
+ }, {})
49
+ : {};
50
+ if (ModalMap[pathname]) {
51
+ this.refs.ModalManager.current.openModal({
52
+ pathname,
53
+ params: searchPamams,
54
+ });
55
+ } else if (DrawerMap[pathname]) {
56
+ this.refs.ModalManager.current.openDrawer({
57
+ pathname,
58
+ params: searchPamams,
59
+ });
130
60
  } else {
131
- message?.warning(this.getLocale('lcdpApi.router.notFound', '找不到跳转页面的数据'));
61
+ historytool(HISTORYTYPES.replace, {
62
+ pathname,
63
+ search,
64
+ state: {},
65
+ history,
66
+ });
132
67
  }
133
68
  }
134
69
  }
@@ -120,7 +120,16 @@ class LcdpBaseApi {
120
120
  /**
121
121
  * @name 发送请求
122
122
  */
123
- this.fetch = api.commonFetch;
123
+ this.fetch = {
124
+ post: (url: string, data?: any) => {
125
+ return api.commonFetch('post', url, data)
126
+ // return compatHttp.post(url, data, { appId: this.data.appId, ...(appCtx || {})}, options)
127
+ },
128
+ get: (url: string, data?: any) => {
129
+ return api.commonFetch('get', url, data)
130
+ // return compatHttp.get(url, data, { appId: this.data.appId, ...(appCtx || {})}, options)
131
+ }
132
+ }
124
133
 
125
134
  // 重构 屏蔽
126
135
  // this.isSupport = browserCompatible(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/ebe-utils",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -19,7 +19,7 @@
19
19
  "@babel/types": "^7.12.12",
20
20
  "cac": "^6.7.14",
21
21
  "fs-extra": "9.x",
22
- "@lingxiteam/ebe": "0.4.3"
22
+ "@lingxiteam/ebe": "0.4.5"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"