@cloudbase/lowcode-builder 0.1.26 → 1.0.0

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 (84) hide show
  1. package/lib/builder/core/index.d.ts +1 -3
  2. package/lib/builder/core/index.js +42 -52
  3. package/lib/builder/h5/compile.d.ts +1 -1
  4. package/lib/builder/h5/compile.js +59 -20
  5. package/lib/builder/h5/copy.js +2 -4
  6. package/lib/builder/h5/generate.js +3 -3
  7. package/lib/builder/h5/index.d.ts +5 -4
  8. package/lib/builder/h5/index.js +25 -14
  9. package/lib/builder/h5/material.js +6 -11
  10. package/lib/builder/h5/npm.js +6 -5
  11. package/lib/builder/mp/index.js +38 -49
  12. package/lib/builder/mp/materials.js +25 -18
  13. package/lib/builder/mp/mixMode.js +7 -10
  14. package/lib/builder/mp/mp_config.js +2 -3
  15. package/lib/builder/mp/wxml.js +1 -1
  16. package/lib/builder/service/webpack.d.ts +7 -1
  17. package/lib/builder/service/webpack.js +97 -24
  18. package/lib/builder/types/common.d.ts +1 -1
  19. package/lib/builder/types/common.js +2 -1
  20. package/lib/builder/util/common.js +1 -4
  21. package/lib/builder/util/generateFiles.js +12 -10
  22. package/lib/builder/util/mp.js +2 -8
  23. package/lib/builder.web.js +71 -0
  24. package/lib/index.d.ts +4 -0
  25. package/lib/index.js +6 -0
  26. package/lib/types.d.ts +1 -0
  27. package/lib/types.js +11 -0
  28. package/package.json +3 -8
  29. package/template/html/index.html.ejs +59 -29
  30. package/template/mp/common/weapp-page.js +23 -1
  31. package/template/mp/package.json +1 -1
  32. package/template/mp/page/index.js +2 -1
  33. package/template/package.json +5 -2
  34. package/template/webpack/getCSSModuleLocalIdent.js +28 -0
  35. package/template/webpack/web.prod.js +112 -103
  36. package/template/src/app/common.js +0 -13
  37. package/template/src/app/global-api.js +0 -99
  38. package/template/src/app/handlers.js +0 -13
  39. package/template/src/app/material-actions.js +0 -16
  40. package/template/src/app/mountAppApis.js +0 -25
  41. package/template/src/app/mountMpApis.js +0 -4
  42. package/template/src/datasources/config.js.tpl +0 -23
  43. package/template/src/datasources/dataset-profiles.js.tpl +0 -5
  44. package/template/src/datasources/datasource-profiles.js.tpl +0 -4
  45. package/template/src/datasources/index.js +0 -31
  46. package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -331
  47. package/template/src/handlers/HotAreas.js +0 -36
  48. package/template/src/handlers/PositionHandler.jsx +0 -8
  49. package/template/src/handlers/actionHandler/utils.js +0 -149
  50. package/template/src/handlers/componentEventActionEmitter.js +0 -29
  51. package/template/src/handlers/componentNodeMap.js +0 -24
  52. package/template/src/handlers/controller.js +0 -5
  53. package/template/src/handlers/emitComponentEvent.js +0 -8
  54. package/template/src/handlers/eventListener/componentEventListener.js +0 -15
  55. package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
  56. package/template/src/handlers/eventListener/index.js +0 -29
  57. package/template/src/handlers/eventListener/pageEventListener.js +0 -11
  58. package/template/src/handlers/eventListener/types.js +0 -32
  59. package/template/src/handlers/hooks/index.js +0 -14
  60. package/template/src/handlers/initWebEnv.js +0 -4
  61. package/template/src/handlers/injectStyle.js +0 -14
  62. package/template/src/handlers/instanceMap.js +0 -39
  63. package/template/src/handlers/lifecycle.js +0 -232
  64. package/template/src/handlers/render.jsx +0 -131
  65. package/template/src/handlers/utils/common.js +0 -151
  66. package/template/src/handlers/utils/eventProxy.js +0 -64
  67. package/template/src/handlers/utils/events.js +0 -8
  68. package/template/src/handlers/utils/index.js +0 -4
  69. package/template/src/handlers/utils/widgets.js +0 -320
  70. package/template/src/index.jsx +0 -142
  71. package/template/src/index.less +0 -119
  72. package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
  73. package/template/src/pages/app.tpl +0 -124
  74. package/template/src/router/index.tpl +0 -28
  75. package/template/src/store/computed.js +0 -11
  76. package/template/src/store/index.js +0 -40
  77. package/template/src/utils/ScanCodeComponent.js +0 -396
  78. package/template/src/utils/date.js +0 -324
  79. package/template/src/utils/history.js +0 -72
  80. package/template/src/utils/index.js +0 -67
  81. package/template/src/utils/kbone.js +0 -18
  82. package/template/src/utils/monitor-jssdk.min.js +0 -763
  83. package/template/src/utils/request.js +0 -5
  84. package/template/src/utils/scan-code-action.js +0 -27
@@ -1,32 +0,0 @@
1
- export const EventListenerTarget = {
2
- PAGE: 'page',
3
- COMPONENT: 'component',
4
- HOT_AREA: 'hotarea',
5
- };
6
-
7
- /**
8
- * @desc Page Events
9
- */
10
-
11
- export const PageEventListenerTypes = {
12
- INIT: 'afterRender',
13
- };
14
-
15
- /**
16
- * @desc Component Events
17
- */
18
- export const ComponentEventListenerTypes = {
19
- INIT: 'afterRender',
20
- CLICK: 'click',
21
- MOUSE_ENTER: 'mouseEnter',
22
- MOUSE_LEAVE: 'mouseLeave',
23
- DOUBLE_CLICK: 'doubleClick',
24
- LONG_PRESS: 'longPress',
25
- ENTER_VIEW: 'enterView',
26
- LEAVE_VIEW: 'leaveView',
27
- };
28
-
29
- /**
30
- * @desc HotArea Events
31
- */
32
- export const HotAreaEventListenerTypes = ComponentEventListenerTypes;
@@ -1,14 +0,0 @@
1
- import * as React from 'react'
2
- import { useLocation } from 'react-router-dom'
3
-
4
- export function useScrollTop() {
5
- const { pathname } = useLocation()
6
- React.useEffect(() => {
7
- window.scrollTo({
8
- top: 0,
9
- left: 0,
10
- behavior: 'auto'
11
- })
12
- }, [pathname])
13
- return null
14
- }
@@ -1,4 +0,0 @@
1
-
2
- export function initGlobalVar() {
3
- window.$$global = window.$$global || {}
4
- }
@@ -1,14 +0,0 @@
1
- export function injectStyle(content, className) {
2
- if (typeof window === 'undefined') {
3
- return;
4
- }
5
- if (!content.toString().trim()) {
6
- return;
7
- }
8
-
9
- const style = document.createElement('style');
10
- style.setAttribute('type', 'text/css');
11
- style.setAttribute('class', className);
12
- style.innerHTML = content;
13
- document.head.appendChild(style);
14
- }
@@ -1,39 +0,0 @@
1
- let instances = null;
2
- const componentInstanceIndexMap = new Map();
3
-
4
- export function initComponentInstanceIndexMap(componentInstances) {
5
- instances = componentInstances;
6
- return generateComponentInstanceIndexMap(instances);
7
- }
8
-
9
- function generateComponentInstanceIndexMap() {
10
- componentInstanceIndexMap.clear();
11
- instances.forEach(({ key, children }, index) => {
12
- if (children) {
13
- children.forEach(({ key }, childIndex) => setComponentInstanceIndex(key, childIndex, index));
14
- }
15
- setComponentInstanceIndex(key, index);
16
- });
17
-
18
- function setComponentInstanceIndex(key, index, parentIndex) {
19
- return componentInstanceIndexMap.set(key, { index, parentIndex });
20
- }
21
- }
22
-
23
- export function getComponentInstanceIndex(key) {
24
- return componentInstanceIndexMap.get(key);
25
- }
26
-
27
- export function getComponentInstance(key) {
28
- const iIndex = getComponentInstanceIndex(key);
29
- if (!iIndex) {
30
- return null;
31
- }
32
-
33
- const { index, parentIndex } = iIndex;
34
- let componentInstances = instances;
35
- if (typeof parentIndex === 'number') {
36
- componentInstances = componentInstances[parentIndex].children;
37
- }
38
- return componentInstances[index];
39
- }
@@ -1,232 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- /**
3
- * 生命周期处理函数
4
- */
5
- import * as throttle from 'lodash/throttle';
6
- import { wx } from '@tcwd/weapps-sdk';
7
- import * as querystring from 'querystring';
8
- // 小程序 端使用lifeCycle
9
-
10
- export function initLifeCycle(
11
- {
12
- onAppLaunch = () => {},
13
- onAppShow = () => {},
14
- onAppHide = () => {},
15
- onAppError = () => {},
16
- onAppPageNotFound = () => {},
17
- onAppUnhandledRejection = () => {},
18
- beforeCustomLaunch = (query) => {},
19
-
20
- onPageLoad = () => {},
21
- onPageShow = () => {},
22
- onPageReady = () => {},
23
- onPageHide = () => {},
24
- onPageUnload = () => {},
25
- beforePageCustomLaunch = (query) => {},
26
- onPullDownRefresh,
27
- onReachBottom,
28
- onShareAppMessage,
29
- onPageScroll,
30
- onResize,
31
- onAddToFavorites,
32
- onShareTimeline,
33
- onTabItemTap,
34
- },
35
- app,
36
- mainApp
37
- ) {
38
- if (!process.env.isMiniprogram) {
39
- window.$$global = window.$$global || {};
40
- }
41
- // 包装应用显示回掉, 增加取数据变量值逻辑
42
- const onAppLaunchCb = (...args) => {
43
- beforeCustomLaunch(...args);
44
- onAppLaunch(...args);
45
- };
46
-
47
- // 包装页面加载回掉, 增加取数据变量值逻辑
48
- const onPageLoadCb = (...args) => {
49
- beforePageCustomLaunch(...args);
50
- onPageLoad(...args);
51
- };
52
-
53
- // 应用级别事件监听
54
- if (!window.$$global.alreadyInitAppLifeCycle) {
55
- if (!window.$$global.isOnLaunchRunned) {
56
- onAppLaunchCb(wx.getLaunchOptionsSync());
57
- window.$$global.isOnLaunchRunned = true;
58
- }
59
-
60
- mainApp.onAppShow && mainApp.onAppShow(onAppShow);
61
- mainApp.onAppHide && mainApp.onAppHide(onAppHide);
62
- mainApp.onError && mainApp.onError(onAppError);
63
- mainApp.onPageNotFound && mainApp.onPageNotFound(onAppPageNotFound);
64
- mainApp.onUnhandledRejection &&
65
- mainApp.onUnhandledRejection(onAppUnhandledRejection);
66
-
67
- // 预留等客户端来触发
68
- window.addEventListener('appLaunch', (...args) => onAppLaunchCb(...args));
69
- window.addEventListener('appShow', (...args) => onAppShow(...args));
70
- window.addEventListener('appHide', (...args) => onAppHide(...args));
71
- window.addEventListener('error', (...args) => onAppError(...args));
72
- window.addEventListener('unhandledRejection', (...args) =>
73
- onAppUnhandledRejection(...args)
74
- );
75
- window.$$global.alreadyInitAppLifeCycle = true;
76
- }
77
-
78
- // wx兼容的页面级别事件监听
79
- if (process.env.isMiniprogram) {
80
- window.addEventListener('wxload', (...args) => onPageLoadCb(...args));
81
- window.addEventListener('wxshow', (...args) => onPageShow(...args));
82
- window.addEventListener('wxready', (...args) => onPageReady(...args));
83
- window.addEventListener('wxhide', (...args) => onPageHide(...args));
84
- window.addEventListener('wxunload', (...args) => onPageUnload(...args));
85
- // 页面级别特殊事件
86
- if (typeof onPullDownRefresh === 'function') {
87
- window.addEventListener('pulldownrefresh', (...args) =>
88
- onPullDownRefresh(...args)
89
- );
90
- }
91
-
92
- if (typeof onPageScroll === 'function') {
93
- window.addEventListener('scroll', () => {
94
- onPageScroll({
95
- scrollTop: document.documentElement.scrollTop,
96
- });
97
- });
98
- }
99
-
100
- if (typeof onReachBottom === 'function') {
101
- window.addEventListener('reachbottom', onReachBottom);
102
- }
103
-
104
- if (typeof onShareAppMessage === 'function') {
105
- window.onShareAppMessage = onShareAppMessage;
106
- }
107
-
108
- if (typeof onShareTimeline === 'function') {
109
- window.onShareTimeline = onShareTimeline;
110
- }
111
-
112
- if (typeof onAddToFavorites === 'function') {
113
- window.onAddToFavorites = onAddToFavorites;
114
- }
115
-
116
- if (typeof onResize === 'function') {
117
- window.addEventListener('resize', onResize);
118
- }
119
-
120
- if (typeof onTabItemTap === 'function') {
121
- window.onTabItemTap = onTabItemTap;
122
- }
123
- }
124
- }
125
-
126
- let isReachBottom = false;
127
- // web 端使用lifeCycle
128
- export function pageLifeCycleMount(
129
- useEffect,
130
- {
131
- onPageLoad,
132
- beforePageCustomLaunch,
133
- onPageShow,
134
- onPageReady,
135
- onPageHide,
136
- onPageUnload,
137
- onPullDownRefresh,
138
- onReachBottom,
139
- onShareAppMessage,
140
- onPageScroll,
141
- onResize,
142
- onAddToFavorites,
143
- onShareTimeline,
144
- onTabItemTap,
145
- },
146
- app = {}
147
- ) {
148
- let queryText = location.href.split('?')[1];
149
- let query = querystring.parse(queryText);
150
- // 页面挂载时加载数据源变量值
151
- typeof fetchPageDataVar === 'function' && fetchPageDataVar();
152
- // 包装页面加载回掉, 增加取数据变量值逻辑
153
- const onPageLoadCallback = (...args) => {
154
- beforePageCustomLaunch(...args);
155
- onPageLoad && onPageLoad(...args);
156
- };
157
- useEffect(() => {
158
- onPageLoadCallback(query);
159
- typeof onPageReady === 'function' && onPageReady();
160
- typeof onPageShow === 'function' && onPageShow();
161
-
162
- if (typeof onPullDownRefresh === 'function') {
163
- app.onPullDownRefresh(onPullDownRefresh);
164
- }
165
- if (
166
- typeof onPageScroll === 'function' ||
167
- typeof onReachBottom === 'function'
168
- ) {
169
- window.onscroll = throttle(() => {
170
- //变量scrollTop是滚动条滚动时,滚动条上端距离顶部的距离
171
- let scrollTop =
172
- document.documentElement.scrollTop || document.body.scrollTop;
173
-
174
- //变量windowHeight是可视区的高度
175
- let windowHeight =
176
- document.documentElement.clientHeight || document.body.clientHeight;
177
-
178
- //变量scrollHeight是滚动条的总高度(当前可滚动的页面的总高度)
179
- let scrollHeight =
180
- document.documentElement.scrollHeight || document.body.scrollHeight;
181
- if (typeof onPageScroll === 'function') {
182
- onPageScroll({
183
- scrollTop: window.pageYOffset,
184
- });
185
- }
186
-
187
- // console.log(scrollTop, windowHeight, scrollTop + windowHeight, scrollHeight, isReachBottom)
188
- //滚动条到底部
189
- if (scrollTop + windowHeight >= scrollHeight && !isReachBottom) {
190
- //要进行的操作
191
- isReachBottom = true;
192
- if (typeof onReachBottom === 'function') {
193
- onReachBottom();
194
- }
195
- }
196
- // 容许用户回弹50然后执行ReachBottom, 50为测试最佳值
197
- if (scrollTop + windowHeight < scrollHeight - 50) {
198
- isReachBottom = false;
199
- }
200
- }, 300);
201
- }
202
- // todo
203
- if (typeof onShareAppMessage === 'function') {
204
- window.onShareAppMessage = onShareAppMessage;
205
- }
206
-
207
- if (typeof onResize === 'function') {
208
- window.onresize = () => {
209
- onResize({
210
- size: {
211
- windowWidth: window.innerWidth,
212
- windowHeight: window.innerHeight,
213
- },
214
- });
215
- };
216
- }
217
- return () => {
218
- typeof onPageHide === 'function' && onPageHide({});
219
- typeof onPageUnload === 'function' && onPageUnload({});
220
- if (typeof onPullDownRefresh === 'function') {
221
- app.offPullDownRefresh(onPullDownRefresh);
222
- }
223
-
224
- window.onscroll = null;
225
- window.onresize = null;
226
- };
227
- }, []);
228
- }
229
- export function initWebConfig(app, appConfig) {
230
- // miniprogram.config 配置截取
231
- app.setConfig(appConfig);
232
- }
@@ -1,131 +0,0 @@
1
- import * as React from 'react';
2
- import { useRef } from 'react';
3
- import * as _ from 'lodash';
4
- import { CompRenderer } from './FieldMiddleware/renderer';
5
- import { isScopeSlot } from '../utils/index';
6
-
7
- function getComponentChildren(component) {
8
- const { properties } = component;
9
- if (!properties) {
10
- return [];
11
- }
12
- return Object.values(properties).sort(
13
- (a, b) => (a['x-index'] || 0) - (b['x-index'] || 0)
14
- );
15
- }
16
-
17
- export function AppRender(props) {
18
- const {
19
- className,
20
- virtualFields,
21
- componentSchema,
22
- renderSlot,
23
- rootNode = true,
24
- codeContext,
25
- scopeContext = {},
26
- } = props;
27
-
28
- const { 'x-props': xProps, properties = {} } = componentSchema;
29
-
30
- // 判断是否为 slot
31
- const isSlot = !xProps;
32
- if (isSlot && !(renderSlot || rootNode)) {
33
- return null;
34
- }
35
-
36
- const preClassName = useRef();
37
-
38
- // wrapperClass
39
- const containerEl = Object.values(properties)[0];
40
- if (containerEl && containerEl['x-props'] && className) {
41
- let { classNameList = [] } = containerEl['x-props'];
42
-
43
- // 先替换掉先前计算出来的className部分
44
- if (preClassName.current) {
45
- if (preClassName.current !== className) {
46
- classNameList = classNameList.filter(
47
- (clsName) => clsName !== preClassName.current
48
- );
49
- preClassName.current = className;
50
- }
51
- } else {
52
- preClassName.current = className;
53
- }
54
-
55
- containerEl['x-props'].classNameList = [className, ...classNameList];
56
- }
57
-
58
- if (xProps && xProps.sourceKey) {
59
- const { sourceKey } = xProps;
60
- const Field = virtualFields[sourceKey];
61
- if (!Field) {
62
- return (
63
- <div style={{ color: 'red' }}>
64
- 组件<em>{sourceKey}</em>未找到
65
- </div>
66
- );
67
- }
68
- }
69
-
70
- const children = getComponentChildren(componentSchema);
71
- const slots = {};
72
- // eslint-disable-next-line guard-for-in
73
- for (const key in properties) {
74
- const child = properties[key];
75
- if (!child['x-props'] && child.properties) {
76
- slots[key] = isScopeSlot(componentSchema, key) ? (
77
- (props) => {
78
- let clonedScopeContext = _.cloneDeep(scopeContext);
79
- _.set(
80
- clonedScopeContext,
81
- `${componentSchema.key}.${child.key}`,
82
- props
83
- );
84
- return (
85
- <AppRender
86
- key={child.key}
87
- componentSchema={child}
88
- renderSlot
89
- virtualFields={virtualFields}
90
- codeContext={codeContext}
91
- scopeContext={clonedScopeContext}
92
- />
93
- );
94
- }
95
- ) : (
96
- <AppRender
97
- key={child.key}
98
- componentSchema={child}
99
- renderSlot
100
- virtualFields={virtualFields}
101
- codeContext={codeContext}
102
- scopeContext={scopeContext}
103
- />
104
- );
105
- }
106
- }
107
-
108
- return (
109
- <CompRenderer
110
- id={componentSchema.key}
111
- xProps={xProps}
112
- emitEvents={componentSchema.emitEvents || []}
113
- virtualFields={virtualFields}
114
- slots={slots}
115
- codeContext={codeContext}
116
- scopeContext={scopeContext}
117
- >
118
- {children.map((comp) => (
119
- <AppRender
120
- key={comp.key}
121
- componentSchema={comp}
122
- rootNode={false}
123
- renderSlot={false}
124
- virtualFields={virtualFields}
125
- codeContext={codeContext}
126
- scopeContext={scopeContext}
127
- />
128
- ))}
129
- </CompRenderer>
130
- );
131
- }
@@ -1,151 +0,0 @@
1
- export function getComponentId(key) {
2
- return `__weapps-component-wrapper-${key}`;
3
- }
4
-
5
- export const pathSpecialSymbol = '__$__';
6
-
7
- export function pathTransformDotToSymbol(str) {
8
- return str.replace(/\./g, pathSpecialSymbol);
9
- }
10
-
11
- export function pathTransformSymbolToDot(str) {
12
- return String(str).replace(new RegExp(`__\\$__`, 'g'), '.');
13
- }
14
-
15
- /**
16
- * All data bindings are generated as functions: (forItems, event?) => any
17
- * @param {*} dataBinds
18
- * @param {*} forItems
19
- */
20
- export function resolveDataBinds(
21
- dataBinds,
22
- forItems,
23
- codeContext,
24
- scopeContext,
25
- throwError
26
- ) {
27
- const resolvedProps = {};
28
- for (const prop in dataBinds) {
29
- let fn = dataBinds[prop];
30
- try {
31
- if (codeContext && codeContext.$WEAPPS_COMP) {
32
- fn = fn.bind(codeContext.$WEAPPS_COMP);
33
- }
34
- resolvedProps[prop] = fn(
35
- forItems,
36
- codeContext && codeContext.event,
37
- scopeContext
38
- );
39
- } catch (e) {
40
- console.error('Error resolving data binding', prop, dataBinds[prop], e);
41
- if (throwError) {
42
- throw e;
43
- }
44
- }
45
- }
46
- return resolvedProps;
47
- }
48
-
49
- const varSeparator = '.';
50
- export function getDeep(target, key) {
51
- if (key == null) {
52
- return target;
53
- }
54
- const keys = (key + '').split(varSeparator);
55
- let prop = target[keys[0]];
56
- for (let i = 1; i < keys.length; i++) {
57
- prop = prop[keys[i]];
58
- }
59
- return prop;
60
- }
61
-
62
- /**
63
- * 用于处理自定义组件props传参结构,对系统变量进行保留
64
- */
65
- export function resolveComponentProps(props, isPlainProps) {
66
- const { staticResourceAttribute } = props;
67
- staticResourceAttribute &&
68
- staticResourceAttribute.map((property) => {
69
- if (props.data && props.data[property]) {
70
- props.data[property] = getStaticResourceAttribute(props.data[property]);
71
- }
72
- });
73
- if (!isPlainProps) {
74
- return {
75
- ...props,
76
- };
77
- }
78
- const { data = {}, events = [], ...restProps } = props;
79
- const customProps = { ...data };
80
- const builtinProps = [
81
- // react 保留字
82
- 'ref',
83
- 'key',
84
- 'dangerouslySetInnerHTML',
85
- 'className',
86
- 'htmlFor',
87
- 'style',
88
- 'contentEditable',
89
- // lowcode 保留字
90
- 'events',
91
- 'children',
92
- '_parentId',
93
- '_visible',
94
- 'classList',
95
- 'widgetType',
96
- 'getWidgetsByType',
97
- 'getDom',
98
- 'domRef',
99
- 'extends',
100
- // 小程序保留字
101
- 'id',
102
- 'class',
103
- 'hidden',
104
- 'slot',
105
- ];
106
- builtinProps.map((prop) => delete customProps[prop]);
107
- return {
108
- ...data,
109
- ...restProps,
110
- events: events.reduce((events, item) => {
111
- const propName = item;
112
- events[propName] = (e) => restProps.emit(propName, e);
113
- return events;
114
- }, {}),
115
- };
116
- }
117
-
118
- export function getStaticResourceAttribute(staticUrl) {
119
- if (/^\//.test(staticUrl)) {
120
- const { domain = '' } = window.app || {};
121
- const url = `https://${domain}${staticUrl}`;
122
- return url;
123
- }
124
- return staticUrl;
125
- }
126
- /**
127
- * 检查页面权限
128
- **/
129
- export async function checkAuth(app, appId, pageId) {
130
- app.showNavigationBarLoading();
131
- const checkAuthResult = await app.cloud.callWedaApi({
132
- action: 'DescribeResourcesPermission',
133
- data: {
134
- ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
135
- ResourceIdList: [`${appId}-${pageId}`],
136
- },
137
- });
138
- let isLogin = false;
139
- if (Array.isArray(checkAuthResult) && checkAuthResult.length > 0) {
140
- isLogin = checkAuthResult[0]?.IsAccess ?? false;
141
- }
142
- app.hideNavigationBarLoading();
143
-
144
- if (!isLogin) {
145
- app.showToast({
146
- title: '页面无访问权限',
147
- icon: 'error',
148
- });
149
- }
150
- return isLogin;
151
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * @author elliothu@tencent.com
3
- * @date 2019-05-07
4
- * @desc 事件系统,用于全局通信
5
- */
6
-
7
- export class EventProxy {
8
- proxies = {};
9
-
10
- onceProxies = {};
11
-
12
- on = (eventName, handler) => {
13
- if (this.proxies[eventName]) {
14
- return this.proxies[eventName].push(handler);
15
- }
16
- this.proxies[eventName] = [handler];
17
- };
18
-
19
- only = (eventName, handler) => {
20
- this.proxies[eventName] = [handler];
21
- };
22
-
23
- once = (eventName, handler) => {
24
- if (this.onceProxies[eventName]) {
25
- return this.onceProxies[eventName].push(handler);
26
- }
27
- this.onceProxies[eventName] = [handler];
28
- };
29
-
30
- emit = (eventName, ...args) => {
31
- if (this.proxies[eventName]) {
32
- this.proxies[eventName].forEach(handler => handler(...args));
33
- }
34
- if (this.onceProxies[eventName]) {
35
- this.onceProxies[eventName].forEach(handler => handler(...args));
36
- this.onceProxies[eventName] = [];
37
- }
38
- };
39
-
40
- cancel = (eventName, handler) => {
41
- if (!this.proxies[eventName]) { return; }
42
- this.proxies[eventName] = this.proxies[eventName].filter(h => h !== handler);
43
- };
44
-
45
- cancelOnce = (eventName, handler) => {
46
- if (!this.onceProxies[eventName]) { return; }
47
- this.onceProxies[eventName] = this.onceProxies[eventName].filter(h => h !== handler);
48
- };
49
-
50
- cancelAll = eventName => {
51
- if (!this.proxies[eventName]) { return; }
52
- this.proxies[eventName] = [];
53
- };
54
-
55
- cancelAllOnce = eventName => {
56
- if (!this.onceProxies[eventName]) { return; }
57
- this.onceProxies[eventName] = [];
58
- };
59
-
60
- clear = () => {
61
- this.proxies = {};
62
- this.onceProxies = {};
63
- };
64
- }
@@ -1,8 +0,0 @@
1
- import { EventProxy } from './eventProxy';
2
-
3
- export const EventEmitTypes = {
4
- COMPONENT_INTERSECTING_CHANGE: 'component_intersecting_change',
5
- HOT_AREA_INTERSECTING_CHANGE: 'hot_area_intersecting_change',
6
- };
7
-
8
- export const events = new EventProxy();
@@ -1,4 +0,0 @@
1
- export * from './events'
2
- export * from './eventProxy'
3
- export * from './common'
4
- export * from './widgets'