@cloudbase/framework-plugin-low-code 0.6.17 → 0.6.19

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.
@@ -94,9 +94,9 @@ export function retryDataBinds(tryTime = 10) {
94
94
  retryDataBinds(tryTime - 1);
95
95
  }, 0);
96
96
  }
97
- export function createWidgets(widgetProps, dataBinds, scopeContext = {}) {
97
+ export function createWidgets(widgetProps, dataBinds, scopeContext = {}, context = {}) {
98
98
  const nodeTree = createWidgetTree(widgetProps, dataBinds);
99
- const widgets = runFor(nodeTree, {}, null, null, scopeContext);
99
+ const widgets = runFor(nodeTree, {}, null, null, scopeContext, context);
100
100
  return widgets;
101
101
 
102
102
  /**
@@ -106,6 +106,7 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}) {
106
106
  * @param {*} parentLevelWidgets
107
107
  * @param {*} parentWidget
108
108
  * @param {*} scopeContext
109
+ * @param {*} context
109
110
  * @returns top level widgets or for dispose
110
111
  */
111
112
  function runFor(
@@ -113,7 +114,8 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}) {
113
114
  forItems,
114
115
  parentLevelWidgets,
115
116
  parentWidget,
116
- scopeContext
117
+ scopeContext,
118
+ context,
117
119
  ) {
118
120
  const nodeId = curForNode.id;
119
121
  if (!curForNode.value) {
@@ -122,7 +124,7 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}) {
122
124
  const dispose = autorun(() => {
123
125
  let forList = [];
124
126
  try {
125
- forList = dataBinds[nodeId]._waFor(forItems, undefined, scopeContext);
127
+ forList = dataBinds[nodeId]._waFor(forItems, undefined, context);
126
128
  } catch (e) {
127
129
  console.warn('waFor error', e);
128
130
  }
@@ -247,7 +249,8 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}) {
247
249
  subForItems,
248
250
  widgets,
249
251
  node.parent && widgets[node.parent.id],
250
- scopeContext
252
+ scopeContext,
253
+ context
251
254
  );
252
255
  curForNode.id && widgets[curForNode.id]._disposers.push(dispose);
253
256
  }
@@ -64,6 +64,27 @@ initLifeCycle({
64
64
  export default function App() {
65
65
  // 检查权限
66
66
  const [weDaHasLogin, setWeDaHasLogin] = React.useState(false);
67
+ const context = React.useRef(observable({})).current;
68
+
69
+ /**
70
+ * 更新数据容器的上下文的方法
71
+ * 会传递到事件emit的地方,将从组件获取到的数据data赋值给上下文
72
+ * 当组件卸载时,传过来的data为undefined即可
73
+ * {
74
+ * id1: [{...}],
75
+ * id2: {...},
76
+ * id3: undefined,
77
+ * id4: null,
78
+ * ...
79
+ * }
80
+ * @param id
81
+ * @param data
82
+ */
83
+ const updateContext = (id, data) => {
84
+ if (id) {
85
+ context[id] = { data };
86
+ }
87
+ }
67
88
 
68
89
  React.useEffect(() => {
69
90
  checkAuth(app, app.id, '<%= pageName %>').then((checkAuthResult) => {
@@ -86,12 +107,13 @@ export default function App() {
86
107
  app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
87
108
  });
88
109
  };
110
+ }, []);
89
111
 
90
- $page.widgets = createWidgets(widgetsContext, dataBinds, {});
112
+ React.useEffect(() => {
113
+ $page.widgets = createWidgets(widgetsContext, dataBinds, {}, context);
91
114
  // widgets 内的 dataBinds 可能需要关联 widgets,需要重新执行 dataBinds
92
115
  retryDataBinds();
93
- }, []);
94
-
116
+ }, [context]);
95
117
 
96
118
  // Web 环境页面级别生命周期
97
119
  if (!process.env.isMiniprogram) {
@@ -115,6 +137,8 @@ export default function App() {
115
137
  <AppRender pageListenerInstances={pageListenerInstances}
116
138
  virtualFields={virtualFields}
117
139
  componentSchema={componentSchema}
140
+ context={context}
141
+ updateContext={updateContext}
118
142
  />)}
119
143
  </div>
120
144
  );
@@ -12,6 +12,7 @@ export default () => {
12
12
  <Router history={process.env.isAdminPortal? generateHashHistory({basename: "<%= basename %>"}) : history }>
13
13
  <Switch>
14
14
  <%= routerRenders %>
15
+ {process.env.isAdminPortal && <Route children={() => <Redirect to={'/404'} />} />}
15
16
  </Switch>
16
17
  </Router>
17
18
  )