@cloudbase/framework-plugin-low-code 0.7.23 → 1.0.1

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 (47) hide show
  1. package/lib/generate.d.ts +1 -2
  2. package/lib/generate.d.ts.map +1 -1
  3. package/lib/generate.js +4 -5
  4. package/lib/index.d.ts +4 -7
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +94 -136
  7. package/lib/utils/dataSource.d.ts +0 -4
  8. package/lib/utils/dataSource.d.ts.map +1 -1
  9. package/lib/utils/dataSource.js +12 -27
  10. package/lib/utils/postProcess.d.ts.map +1 -1
  11. package/package.json +4 -3
  12. package/template/html/index.html.ejs +1 -1
  13. package/template/mp/app/app-global.js +0 -4
  14. package/template/mp/app/common.js +0 -26
  15. package/template/mp/app/handlers.js +0 -15
  16. package/template/mp/app/weapps-api.js +0 -89
  17. package/template/mp/app.js +0 -114
  18. package/template/mp/app.json +0 -1
  19. package/template/mp/app.wxss +0 -15
  20. package/template/mp/common/data-patch-test.js +0 -60
  21. package/template/mp/common/data-patch.js +0 -44
  22. package/template/mp/common/merge-renderer.js +0 -67
  23. package/template/mp/common/process.js +0 -1
  24. package/template/mp/common/style.js +0 -34
  25. package/template/mp/common/url.js +0 -21
  26. package/template/mp/common/util.js +0 -395
  27. package/template/mp/common/utils.wxs +0 -11
  28. package/template/mp/common/weapp-component.js +0 -250
  29. package/template/mp/common/weapp-page.js +0 -204
  30. package/template/mp/common/weapp-sdk.js +0 -76
  31. package/template/mp/common/widget.js +0 -381
  32. package/template/mp/common/wx_yypt_report_v2.js +0 -460
  33. package/template/mp/component/index.js +0 -66
  34. package/template/mp/component/index.json +0 -4
  35. package/template/mp/component/index.wxml +0 -1
  36. package/template/mp/component/index.wxss +0 -1
  37. package/template/mp/datasources/config.js.tpl +0 -25
  38. package/template/mp/datasources/dataset-profiles.js.tpl +0 -5
  39. package/template/mp/datasources/datasource-profiles.js.tpl +0 -4
  40. package/template/mp/datasources/index.js +0 -31
  41. package/template/mp/package.json +0 -17
  42. package/template/mp/page/api.js +0 -1
  43. package/template/mp/page/index.js +0 -42
  44. package/template/mp/page/index.json +0 -3
  45. package/template/mp/page/index.wxml +0 -1
  46. package/template/mp/page/index.wxss +0 -3
  47. package/template/mp/project.config.json +0 -1
@@ -1,395 +0,0 @@
1
- 'use strict';
2
-
3
- import { findForItemsOfWidget, mpCompToWidget } from './widget'
4
- import { observable } from 'mobx';
5
- import { app } from '../app/weapps-api'
6
- import { auth } from '@cloudbase/weda-client'
7
-
8
- /**
9
- * Convert abcWordSnd -> abc-word-snd
10
- */
11
- export function toDash(str) {
12
- return str.replace(/[A-Z]/g, upperLetter => `-${upperLetter.toLowerCase()}`)
13
- }
14
-
15
- export function createComputed(funcs, bindContext = null) {
16
- const computed = {}
17
- for (const name in funcs) {
18
- Object.defineProperty(computed, name, {
19
- get() {
20
- try {
21
- return bindContext ? funcs[name].call(bindContext) : funcs[name]()
22
- } catch (e) {
23
- console.error('Computed error', e)
24
- }
25
- },
26
- enumerable: true
27
- })
28
- }
29
- return computed
30
- }
31
-
32
- export function createEventHandlers(evtListeners, context) {
33
- const evtHandlers = {}
34
- for (const name in evtListeners) {
35
- const listeners = evtListeners[name]
36
- evtHandlers[name] = function (event) {
37
- const self = this
38
- const [prefix = ''] = name.split('$')
39
- // The page event handler
40
- const { lists, itemsById } = findForItemsOfWidget(mpCompToWidget(self, event.currentTarget)) || {}
41
- listeners.forEach(async l => {
42
- let { data = {}, boundData = {} } = l
43
- data = { ...data }
44
- for (const k in boundData) {
45
- set(data, k, boundData[k](lists, itemsById, event, context))
46
- }
47
- try {
48
- let res = await l.handler.call(self, { event, lists, forItems: itemsById, data })
49
- let eventName = prefix && l.key ? `${prefix}$${l.key}_success` : ''
50
- self[eventName] && self[eventName]({
51
- ...event,
52
- detail: res
53
- })
54
- } catch (e) {
55
- let eventName = l.key ? `${prefix}$${l.key}_fail` : ''
56
- if (self[eventName]) {
57
- await self[eventName]({
58
- ...event,
59
- detail: e
60
- })
61
- } else {
62
- throw e
63
- }
64
-
65
- }
66
- })
67
- }
68
- }
69
- return evtHandlers
70
- }
71
-
72
- export function getDeep(target, key, keySeparator = '.') {
73
- if (key == null) {
74
- return target
75
- }
76
- const keys = (key + '').split(keySeparator)
77
- let prop = target[keys[0]]
78
- for (let i = 1; i < keys.length; i++) {
79
- prop = prop[keys[i]]
80
- }
81
- return prop
82
- }
83
-
84
- /**
85
- * Touch all props of given object deeply
86
- */
87
- export function touchObj(obj) {
88
- if (!obj) {
89
- return
90
- }
91
- if (typeof obj === 'string') {
92
- return
93
- }
94
- if (Array.isArray(obj)) {
95
- obj.forEach(touchObj)
96
- } else if (obj) {
97
- Object.keys(obj).forEach(key => touchObj(obj[key]))
98
- }
99
- }
100
-
101
- export function throttle(fn, limit) {
102
- let lastExecTime = 0
103
- let timer = null
104
-
105
- function invoke() {
106
- lastExecTime = Date.now()
107
- timer = null
108
- fn()
109
- }
110
-
111
- const throttled = function () {
112
- const idledDuration = Date.now() - lastExecTime
113
- if (idledDuration >= limit) {
114
- if (timer) {
115
- clearTimeout(timer)
116
- timer = null
117
- }
118
- invoke()
119
- } else if (!timer) {
120
- timer = setTimeout(invoke, limit - idledDuration)
121
- }
122
- }
123
- return throttled
124
- }
125
-
126
- export function deepEqual(a, b) {
127
- if (a === b) {
128
- return true
129
- }
130
-
131
- if (Array.isArray(a) && Array.isArray(b)) {
132
- if (a.length !== b.length) {
133
- return false
134
- }
135
- for (let i = 0; i < a.length; i++) {
136
- if (!deepEqual(a[i], b[i])) {
137
- return false
138
- }
139
- }
140
- return true
141
- }
142
-
143
- if (a && b && typeof a === 'object' && typeof b === 'object') {
144
- const aProps = Object.keys(a), bProps = Object.keys(b)
145
- if (!deepEqual(aProps, bProps)) {
146
- return false
147
- }
148
- for (let i = 0; i < aProps.length; i++) {
149
- const prop = aProps[i]
150
- if (!deepEqual(a[prop], b[prop])) {
151
- return false
152
- }
153
- }
154
- return true
155
- }
156
- return false
157
- }
158
-
159
- function isObject(value) {
160
- var type = typeof value
161
- return !!value && (type == 'object' || type == 'function')
162
- }
163
-
164
- function isIndex(value, length) {
165
- length = length == null ? 9007199254740991 : length
166
- return (
167
- !!length &&
168
- (typeof value == 'number' || /^(?:0|[1-9]\d*)$/.test(value)) &&
169
- value > -1 &&
170
- value % 1 == 0 &&
171
- value < length
172
- )
173
- }
174
-
175
- function assignValue(object, key, value) {
176
- var objValue = object[key]
177
- if (
178
- !(
179
- Object.hasOwnProperty.call(object, key) &&
180
- (objValue === value || (objValue !== objValue && value !== value))
181
- ) ||
182
- (value === undefined && !(key in object))
183
- ) {
184
- object[key] = value
185
- }
186
- }
187
-
188
- export function set(object, path, value) {
189
- if (!isObject(object)) {
190
- return object
191
- }
192
- path = path.split('.')
193
-
194
- var index = -1,
195
- length = path.length,
196
- lastIndex = length - 1,
197
- nested = object
198
-
199
- while (nested != null && ++index < length) {
200
- var key = path[index],
201
- newValue = value
202
-
203
- if (index != lastIndex) {
204
- var objValue = nested[key]
205
- newValue = undefined
206
- if (newValue === undefined) {
207
- newValue = isObject(objValue)
208
- ? objValue
209
- : isIndex(path[index + 1])
210
- ? []
211
- : {}
212
- }
213
- }
214
- assignValue(nested, key, newValue)
215
- nested = nested[key]
216
- }
217
- return object
218
- }
219
-
220
- export function findLoginPage() {
221
- const { app } = getApp();
222
- const { pages = [] } = app.__internal__.getConfig();
223
- return pages.find(item => item.type === 'login');
224
- }
225
-
226
- let _AUTH_CONFIG_CACHE = null;
227
- export async function getAuthConfig() {
228
- const { app } = getApp();
229
- if (_AUTH_CONFIG_CACHE) {
230
- return _AUTH_CONFIG_CACHE;
231
- }
232
- try {
233
- const res = await app.cloud.callWedaApi({
234
- action: "DescribeRuntimeResourceStrategy",
235
- data: {
236
- ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
237
- ResourceId: app.id,
238
- },
239
- });
240
- const settingData = {};
241
- // 云api不支持map只能传字符串,需要转换
242
- res.forEach((item) => {
243
- settingData[item.Key] = ['AllowRegister', 'NeedLogin'].includes(item.Key) ? item.Value === '1' : item.Value;
244
- });
245
- _AUTH_CONFIG_CACHE = settingData;
246
- return _AUTH_CONFIG_CACHE;
247
- } catch (e) {
248
- return {
249
- NeedLogin: false,
250
- RejectStrategy: "show_warning",
251
- };
252
- }
253
- }
254
-
255
- let _AUTH_CACHE_MAP = {}
256
- async function getAccessPermission(app, appId, pageId) {
257
- const cacheKey = `${appId}-${pageId}`
258
- if (_AUTH_CACHE_MAP[cacheKey] !== undefined) {
259
- return _AUTH_CACHE_MAP[cacheKey];
260
- }
261
-
262
- let isAccess = false;
263
- try {
264
- const res = await app.cloud.callWedaApi({
265
- action: 'DescribeResourcesPermission',
266
- data: {
267
- ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
268
- ResourceIdList: [cacheKey],
269
- AppResourceId: appId,
270
- },
271
- });
272
- if (Array.isArray(res) && res.length > 0) {
273
- isAccess = !!res[0].IsAccess;
274
- }
275
- _AUTH_CACHE_MAP[cacheKey] = isAccess;
276
- } catch (e) {
277
- console.warn('getAccessPermission', e);
278
- }
279
- return isAccess
280
- }
281
-
282
- /**
283
- * 检查页面权限
284
- **/
285
- export async function checkAuth(app, appId, $page) {
286
- const loginPage = findLoginPage(app);
287
- if (loginPage?.id === $page.id) {
288
- return true
289
- }
290
- app.showNavigationBarLoading();
291
- const requestList = [getAccessPermission(app, appId, $page.id)];
292
- // 暂时先认为有登录页则自定义登录功能开启且生效
293
- if (loginPage) {
294
- requestList.push(getAuthConfig(app));
295
- }
296
- const [isAccess, authConfig] = await Promise.all(requestList);
297
- app.hideNavigationBarLoading();
298
-
299
- let isAnonymousUser = true;
300
- try {
301
- const { accessToken } = await auth.getAccessToken();
302
- isAnonymousUser = !accessToken;
303
- } catch (e) { }
304
-
305
- if (!isAccess) {
306
- if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
307
- redirectToLogin($page);
308
- } else {
309
- app.showToast({
310
- title: '页面无访问权限',
311
- icon: 'error',
312
- });
313
- }
314
- } else if (loginPage && authConfig.NeedLogin) {
315
- // 此分支逻辑本不应该前端判断是否登录,历史原因后端短期内搞不定,后续后端优化后删除
316
- try {
317
- if (isAnonymousUser) {
318
- redirectToLogin($page);
319
- }
320
- } catch (e) {
321
- redirectToLogin($page);
322
- }
323
- }
324
- return isAccess;
325
- }
326
-
327
- export function redirectToLogin(currentPage) {
328
- // 去登录则清空权限缓存。
329
- _AUTH_CACHE_MAP = {};
330
- const { app } = getApp();
331
- const loginPage = findLoginPage(app);
332
- if (!currentPage) {
333
- currentPage = app.utils.getCurrentPage() || {};
334
- }
335
- if (loginPage?.id === currentPage.id) {
336
- return true
337
- }
338
- if (loginPage) {
339
- app.redirectTo({
340
- pageId: loginPage.id,
341
- params: {
342
- sourcePageId: currentPage.id,
343
- sourcePageParams: currentPage.params
344
- }
345
- })
346
- } else {
347
- app.showToast({
348
- title: '用户未登录',
349
- icon: 'error',
350
- });
351
- }
352
- }
353
-
354
- let loading = {};
355
- export let enumOptions = observable({});
356
- export function formatEnum(path, optionname) {
357
- // 判断是单选还是多选
358
- let isSingle = Array.isArray(path);
359
- // 获取到options
360
- let parseOptions = getEnumOptions(optionname);
361
- if (parseOptions === '') {
362
- return !isSingle ? path : path.join(',');
363
- }
364
- let multiTmp = [];
365
- let value = !isSingle
366
- ? JSON.parse(parseOptions)?.find((item) => item?.key === path)?.value
367
- : JSON.parse(parseOptions)
368
- ?.filter((item) => path.some((pathValue) => item?.key === pathValue))
369
- .map((item) => multiTmp.push(item?.value));
370
- // 对多选或者单选有不同处理
371
- return !isSingle ? value : multiTmp?.join(',');
372
- }
373
- function getEnumOptions(optionName) {
374
- if (enumOptions[optionName]) {
375
- return enumOptions[optionName];
376
- }
377
- if (!loading[optionName]) {
378
- loading[optionName] = true;
379
- getGeneralOptions(optionName).then((data) => {
380
- enumOptions[optionName] = data?.Items[0]?.Config;
381
- });
382
- }
383
- return '';
384
- }
385
- async function getGeneralOptions(optionName) {
386
- return app.cloud.callWedaApi({
387
- action: 'DescribeGeneralOptionsDetailList',
388
- data: {
389
- PageSize: 1,
390
- PageIndex: 1,
391
- LikeNameOrTitle: optionName,
392
- },
393
- });
394
- }
395
-
@@ -1,11 +0,0 @@
1
- function getStaticResourceAttribute(staticUrl) {
2
- if (staticUrl && staticUrl[0] == '/') {
3
- var domain = '<%=domain%>'
4
- return 'https://' + domain + staticUrl;
5
- }
6
- return staticUrl
7
- }
8
-
9
- module.exports = {
10
- _getStaticResourceAttribute: getStaticResourceAttribute
11
- }
@@ -1,250 +0,0 @@
1
- import { observable, autorun } from 'mobx'
2
- import { createEventHandlers, createComputed } from './util'
3
- import { createWidgets, mpCompToWidget, disposeWidget } from './widget'
4
- import mergeRenderer from './merge-renderer'
5
- import sdk from './weapp-sdk'
6
- import lodashGet from 'lodash.get';
7
-
8
- /**
9
- * Lowcodes of all components
10
- */
11
- export const compLowcodes = {}
12
-
13
- export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, undefined, context) {
14
-
15
- compLowcodes[key] = {
16
- index,
17
- stateFn,
18
- computedFuncs,
19
- handler,
20
- // events,
21
- lib: libCommonRes,
22
- config,
23
- }
24
-
25
- return Component({
26
- options: {
27
- virtualHost: true,
28
- multipleSlots: true,
29
- styleIsolation: 'shared',
30
- },
31
- behaviors: behaviors,
32
- // externalClasses: ['class'],
33
- properties: {
34
- id: {
35
- type: String
36
- },
37
- style: {
38
- type: String
39
- },
40
- className: {
41
- type: String,
42
- },
43
- ...properties,
44
- },
45
- lifetimes: {
46
- created() {
47
- this._pageActive = true
48
- this._disposers = []
49
- },
50
- attached() {
51
- const $comp = this.getWeAppInst()
52
- if (!$comp) return
53
-
54
- $comp.props.events = createPropEvents(events, this)
55
- $comp.widgets = {}
56
- const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBindsBindContext(dataBinds, $comp), $comp.widgets, context, this)
57
- this._virtualRootWidget = virtualRootWidget
58
-
59
- try {
60
- lifeCycle.onAttached && lifeCycle.onAttached.call($comp)
61
- this.__handlerAttached__ = (e) => {
62
- const widget = lodashGet(widgets, e.target.id);
63
- widget._methods = e.detail.methods;
64
- }
65
- this.__handlerDetached__ = (e) => {
66
- const widget = lodashGet(widgets, e.target.id);
67
- delete widget._methods;
68
- }
69
- if ($comp.methods) {
70
- this.triggerEvent('attached', {
71
- 'methods': $comp.methods
72
- })
73
- }
74
- } catch (e) {
75
- console.error('Component lifecycle(attached) error', this.is, e)
76
- }
77
-
78
- this._disposers = this.initMergeRenderer(widgets)
79
- },
80
- ready() {
81
- this._runWatch()
82
- lifeCycle.onReady && lifeCycle.onReady.call(this.getWeAppInst())
83
- },
84
- detached() {
85
- const $comp = this.getWeAppInst()
86
- if (!$comp) return
87
-
88
- $comp.widgets = null
89
- disposeWidget(this._virtualRootWidget)
90
- this._disposers.forEach(dispose => dispose())
91
- lifeCycle.onDetached && lifeCycle.onDetached.call($comp)
92
-
93
- if ($comp?.methods) {
94
- this.triggerEvent('detached');
95
- }
96
- }
97
- },
98
-
99
- pageLifetimes: {
100
- show() {
101
- const $comp = this.getWeAppInst()
102
- if (!$comp) return
103
- lifeCycle.onPageShow && lifeCycle.onPageShow.call($comp)
104
- },
105
- hide() {
106
- const $comp = this.getWeAppInst()
107
- if (!$comp) return
108
- lifeCycle.onPageHide && lifeCycle.onPageHide.call($comp)
109
- },
110
- resize(size) {
111
- const $comp = this.getWeAppInst()
112
- if (!$comp) return
113
- lifeCycle.onPageResize && lifeCycle.onPageResize.call($comp, size)
114
- }
115
- },
116
-
117
- methods: {
118
- ...createEventHandlers(evtListeners, context),
119
- ...mergeRenderer,
120
- getWeAppInst() {
121
- const $comp = this.$WEAPPS_COMP
122
- if ($comp) { return $comp }
123
-
124
- if (!this.selectOwnerComponent) {
125
- console.error('Fatal error: not support selectOwnerComponent API, need 2.8.2')
126
- return null
127
- }
128
-
129
- const owner = this.selectOwnerComponent()
130
- const widget = mpCompToWidget(owner, this)
131
- if (!widget || !widget.$comp) {
132
- console.error('Fatal error: weapps component instance not created', this.is, this.id)
133
- }
134
- widget.getDom = (fields) => this._virtualRootWidget.children[0].getDom(fields)
135
-
136
- this.$WEAPPS_COMP = widget.$comp
137
- return widget.$comp
138
- },
139
- _runWatch() {
140
- const { watchEffects = {} } = index
141
- Object.keys(watchEffects).map(name => {
142
- const fn = watchEffects[name]
143
- if (fn instanceof Function) {
144
- const $comp = this.getWeAppInst()
145
- if (!$comp) return
146
- this._disposers.push(autorun(fn.bind($comp)))
147
- } else {
148
- console.error(`WatchEffect(${name}) of ${key} is not a function.`)
149
- }
150
- })
151
- },
152
- },
153
- // observers: createObservers(Object.keys(properties))
154
- })
155
- }
156
-
157
- // The component instance for lowcode
158
- export function create$comp(w) {
159
- const lowcode = compLowcodes[w.widgetType]
160
- if (!lowcode) {
161
- return
162
- }
163
- const libCode = w.widgetType.split(':')[0]
164
- const { stateFn, computedFuncs, handler, lib } = lowcode
165
-
166
- const $comp = {
167
- node: w,
168
- widgets: null,
169
- props: {
170
- data: w,
171
- // events: createPropEvents(events, $comp),
172
- get style() { return w.style },
173
- get classList() { return w.classList },
174
- },
175
- lib,
176
- methods: undefined,
177
- i18n: {
178
- ...sdk.i18n,
179
- t(key, data) {
180
- const ns = libCode;
181
- return sdk.i18n.t(`${ns}:${key}`, data)
182
- },
183
- }
184
- }
185
- $comp.$WEAPPS_COMP = $comp // TODO $comp will replaced to this.$WEAPPS_COMP
186
- $comp.state = observable(stateFn.call($comp)) // May depend on this.props.data.xxx
187
- $comp.computed = createComputed(computedFuncs, $comp)
188
- $comp.handler = Object.keys(handler).reduce((result, key) => {
189
- result[key] = handler[key].bind($comp)
190
- return result
191
- }, {})
192
-
193
- return $comp
194
- }
195
-
196
- function createObservers(props) {
197
- return props.reduce((observers, prop) => {
198
- observers[prop] = function (newVal) {
199
- const data = this.getWeAppInst().props.data
200
- if (!deepEqual(data[prop], newVal)) {
201
- data[prop] = newVal
202
- } else {
203
- // console.log('Same comp prop will not trigger observer', prop, newVal)
204
- }
205
- }
206
- return observers
207
- }, {})
208
- }
209
-
210
- function dataBindsBindContext(dataBinds, self) {
211
- return Object.keys(dataBinds).reduce((result, widgetId) => {
212
- result[widgetId] = Object.keys(dataBinds[widgetId]).reduce((result, prop) => {
213
- result[prop] = dataBinds[widgetId][prop].bind(self)
214
- return result
215
- }, {})
216
- return result
217
- }, {})
218
- }
219
-
220
- function createPropEvents(events, mpInst) {
221
- const protectEventKeys = [
222
- 'touchstart', // 手指触摸动作开始
223
- 'touchmove', // 手指触摸后移动
224
- 'touchcancel', // 手指触摸动作被打断,如来电提醒,弹窗
225
- 'touchend', // 手指触摸动作结束
226
- 'tap', // 手指触摸后马上离开
227
- 'longpress', // 手指触摸后,超过350ms再离开,如果指定了事件回调函数并触发了这个事件,tap事件将不被触发 1.5.0
228
- 'longtap', // 手指触摸后,超过350ms再离开(推荐使用longpress事件代替)
229
- 'transitionend', // 会在 WXSS transition 或 wx.createAnimation 动画结束后触发
230
- 'animationstart', // 会在一个 WXSS animation 动画开始时触发
231
- 'animationiteration', // 会在一个 WXSS animation 一次迭代结束时触发
232
- 'animationend', // 会在一个 WXSS animation 动画完成时触发
233
- 'touchforcechange', // 在支持 3D Touch 的 iPhone 设备,重按时会触发
234
- ]
235
- const result = {}
236
- events.forEach(evt => {
237
- const isProtectKey = protectEventKeys.some(key => key === evt.name)
238
- if (isProtectKey) {
239
- result[evt.name] = function () { }
240
- } else {
241
- result[evt.name] = function (evtDetail) {
242
- if (evt.getValueFromEvent) {
243
- mpInst.setData({ value: evt.getValueFromEvent({ detail: evtDetail }) })
244
- }
245
- mpInst.triggerEvent(evt.name, evtDetail)
246
- }
247
- }
248
- })
249
- return result
250
- }