@cloudbase/framework-plugin-low-code 0.7.22 → 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 (48) hide show
  1. package/lib/builder/mp/index.d.ts +2 -2
  2. package/lib/builder/mp/index.d.ts.map +1 -1
  3. package/lib/builder/mp/index.js +3 -3
  4. package/lib/generate.d.ts +1 -2
  5. package/lib/generate.d.ts.map +1 -1
  6. package/lib/index.d.ts +2 -3
  7. package/lib/index.d.ts.map +1 -1
  8. package/lib/index.js +18 -13
  9. package/lib/utils/dataSource.d.ts +0 -4
  10. package/lib/utils/dataSource.d.ts.map +1 -1
  11. package/lib/utils/dataSource.js +4 -20
  12. package/package.json +3 -2
  13. package/template/html/index.html.ejs +1 -1
  14. package/template/mp/app/app-global.js +0 -4
  15. package/template/mp/app/common.js +0 -26
  16. package/template/mp/app/handlers.js +0 -15
  17. package/template/mp/app/weapps-api.js +0 -89
  18. package/template/mp/app.js +0 -114
  19. package/template/mp/app.json +0 -1
  20. package/template/mp/app.wxss +0 -15
  21. package/template/mp/common/data-patch-test.js +0 -60
  22. package/template/mp/common/data-patch.js +0 -44
  23. package/template/mp/common/merge-renderer.js +0 -67
  24. package/template/mp/common/process.js +0 -1
  25. package/template/mp/common/style.js +0 -34
  26. package/template/mp/common/url.js +0 -21
  27. package/template/mp/common/util.js +0 -395
  28. package/template/mp/common/utils.wxs +0 -11
  29. package/template/mp/common/weapp-component.js +0 -250
  30. package/template/mp/common/weapp-page.js +0 -204
  31. package/template/mp/common/weapp-sdk.js +0 -76
  32. package/template/mp/common/widget.js +0 -381
  33. package/template/mp/common/wx_yypt_report_v2.js +0 -460
  34. package/template/mp/component/index.js +0 -66
  35. package/template/mp/component/index.json +0 -4
  36. package/template/mp/component/index.wxml +0 -1
  37. package/template/mp/component/index.wxss +0 -1
  38. package/template/mp/datasources/config.js.tpl +0 -25
  39. package/template/mp/datasources/dataset-profiles.js.tpl +0 -5
  40. package/template/mp/datasources/datasource-profiles.js.tpl +0 -4
  41. package/template/mp/datasources/index.js +0 -31
  42. package/template/mp/package.json +0 -17
  43. package/template/mp/page/api.js +0 -1
  44. package/template/mp/page/index.js +0 -42
  45. package/template/mp/page/index.json +0 -3
  46. package/template/mp/page/index.wxml +0 -1
  47. package/template/mp/page/index.wxss +0 -3
  48. package/template/mp/project.config.json +0 -1
@@ -1,67 +0,0 @@
1
- import { autorun } from 'mobx'
2
- import { touchObj, throttle } from './util'
3
- import { resolveWidgetData } from './widget'
4
- import { getDatapatch } from './data-patch'
5
-
6
- export default {
7
- // Attention, must be called at the end of attached or page load to make sure user init take effect
8
- initMergeRenderer(widgets) {
9
- this.flushPendingData = throttle(this.flushPendingData.bind(this), 18)
10
-
11
- const dataFactory = {
12
- // <%= dataPropNames.pageState %>: () => pageState,
13
- // <%= dataPropNames.pageComputed %>: () => pageComputed,
14
- }
15
- for (const id in widgets) {
16
- const props = widgets[id]
17
- dataFactory['<%= dataPropNames.widgetProp %>' + id] = () => resolveWidgetData(props)
18
- }
19
- const disposers = []
20
- for (const k in dataFactory) {
21
- const disposer = autorun(r => {
22
- this.requestRender({ [k]: dataFactory[k]() })
23
- })
24
- disposers.push(disposer)
25
- }
26
- this.flushPendingData() // Prepare data for first paint
27
- return disposers
28
- },
29
-
30
- // setData merging
31
- pendingData: null,
32
- _settingData: false, // flag to prevent multiple setData at the same time
33
- flushPendingData() {
34
- if (!this.pendingData || this._settingData) { return }
35
- const patch = getDatapatch(this.data, this.pendingData)
36
- this.pendingData = null
37
- const label = `setData ${this.is} ${this.id}(${Object.keys(patch).join(',')})`
38
-
39
- if (Object.keys(patch).length < 1) {
40
- return
41
- }
42
- this._settingData = true
43
- const lastUpdateTime = Date.now()
44
- this.setData(patch, () => {<% if(debug) {%>
45
- const elapsedTime = Date.now() - lastUpdateTime;
46
- if(elapsedTime > 16) {
47
- console.warn(label, elapsedTime)
48
- }else {
49
- console.info(label, elapsedTime)
50
- }<%} %>
51
- this._settingData = false;
52
- this.flushPendingData()
53
- })
54
- },
55
- requestRender(data) {
56
- if(!this._pageActive) {
57
- // The callback of wx.chooseLocation occured when page is inactive
58
- console.warn(`Attention, you're updating widgets(${Object.keys(data).join(',')}) of inactive page(${this.is})`)
59
- }
60
- if (!this.pendingData) {
61
- this.pendingData = {}
62
- }
63
- wx.nextTick(this.flushPendingData)
64
- touchObj(data) // Touch all props to monitor data deeply, FIXME
65
- Object.assign(this.pendingData, data)
66
- },
67
- }
@@ -1 +0,0 @@
1
- export default { env: { buildType: 'mp' } }
@@ -1,34 +0,0 @@
1
- import { toDash } from './util'
2
- /**
3
- * Convert HtmlElement.style object to css declarations
4
- */
5
- export function styleToCss(style) {
6
- const styleDeclars = [] // ['color: red;', 'background-color: green']
7
- for (const key in style) {
8
- styleDeclars.push(toDash(key) + ':' + style[key] + ';')
9
- }
10
- return styleDeclars.join('')
11
- }
12
-
13
- export function concatClassList(classList1 = [], classList2 = []) {
14
- if (!Array.isArray(classList1)) {
15
- classList1 = [classList1]
16
- }
17
- if (!Array.isArray(classList2)) {
18
- classList2 = [classList2]
19
- }
20
- return classList1.concat(classList2)
21
- }
22
-
23
- export function px2rpx(object) {
24
- let reg = /\b(\d+(\.\d+)?)px\b/g
25
- for (const key in object) {
26
- let value = object[key]
27
- if (typeof value === 'string') {
28
- object[key] = value.replace(reg, function (item, value) {
29
- return `${value}rpx`
30
- })
31
- }
32
- }
33
- return object
34
- }
@@ -1,21 +0,0 @@
1
- // 处理url链接,加入params参数
2
- export function urlJoinParams(url, params) {
3
- if (!url || !params || typeof params !== 'object') {
4
- return url
5
- }
6
- const separate = url.indexOf('?') === -1 ? '?' : '&'
7
- const tempStr = Object.keys(params)
8
- .map(key => {
9
- let value = params[key]
10
- if (typeof value === 'object') {
11
- value = JSON.stringify(value)
12
- }
13
- if (value != undefined) {
14
- return `${key}=${encodeURIComponent(value)}`
15
- }
16
- return ''
17
- })
18
- .filter(value => value)
19
- .join('&')
20
- return `${url}${separate}${tempStr}`
21
- }
@@ -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
- }