@cloudbase/framework-plugin-low-code 0.7.22 → 0.7.25
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.
- package/lib/builder/mp/index.d.ts +2 -2
- package/lib/builder/mp/index.d.ts.map +1 -1
- package/lib/builder/mp/index.js +3 -3
- package/lib/generate.d.ts +1 -2
- package/lib/generate.d.ts.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +18 -13
- package/lib/utils/dataSource.d.ts +0 -4
- package/lib/utils/dataSource.d.ts.map +1 -1
- package/lib/utils/dataSource.js +4 -20
- package/package.json +3 -2
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/app-global.js +0 -4
- package/template/mp/app/common.js +0 -26
- package/template/mp/app/handlers.js +0 -15
- package/template/mp/app/weapps-api.js +0 -89
- package/template/mp/app.js +0 -114
- package/template/mp/app.json +0 -1
- package/template/mp/app.wxss +0 -15
- package/template/mp/common/data-patch-test.js +0 -60
- package/template/mp/common/data-patch.js +0 -44
- package/template/mp/common/merge-renderer.js +0 -67
- package/template/mp/common/process.js +0 -1
- package/template/mp/common/style.js +0 -34
- package/template/mp/common/url.js +0 -21
- package/template/mp/common/util.js +0 -395
- package/template/mp/common/utils.wxs +0 -11
- package/template/mp/common/weapp-component.js +0 -250
- package/template/mp/common/weapp-page.js +0 -204
- package/template/mp/common/weapp-sdk.js +0 -76
- package/template/mp/common/widget.js +0 -381
- package/template/mp/common/wx_yypt_report_v2.js +0 -460
- package/template/mp/component/index.js +0 -66
- package/template/mp/component/index.json +0 -4
- package/template/mp/component/index.wxml +0 -1
- package/template/mp/component/index.wxss +0 -1
- package/template/mp/datasources/config.js.tpl +0 -25
- package/template/mp/datasources/dataset-profiles.js.tpl +0 -5
- package/template/mp/datasources/datasource-profiles.js.tpl +0 -4
- package/template/mp/datasources/index.js +0 -31
- package/template/mp/package.json +0 -17
- package/template/mp/page/api.js +0 -1
- package/template/mp/page/index.js +0 -42
- package/template/mp/page/index.json +0 -3
- package/template/mp/page/index.wxml +0 -1
- package/template/mp/page/index.wxss +0 -3
- package/template/mp/project.config.json +0 -1
|
@@ -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
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { observable } from 'mobx';
|
|
2
|
-
import { createComputed, createEventHandlers, checkAuth } from './util';
|
|
3
|
-
import { createWidgets, createInitData, disposeWidget } from './widget';
|
|
4
|
-
import mergeRenderer from './merge-renderer';
|
|
5
|
-
import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser, setConfig } from '../datasources/index';
|
|
6
|
-
import lodashGet from 'lodash.get';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export function createPage(
|
|
10
|
-
lifecycle,
|
|
11
|
-
widgetProps,
|
|
12
|
-
pageState,
|
|
13
|
-
pageComputed,
|
|
14
|
-
evtListeners,
|
|
15
|
-
dataBinds,
|
|
16
|
-
app,
|
|
17
|
-
$page,
|
|
18
|
-
context,
|
|
19
|
-
pageAttributes
|
|
20
|
-
) {
|
|
21
|
-
const evtHandlers = createEventHandlers(evtListeners, context);
|
|
22
|
-
|
|
23
|
-
function extractLifecyles() {
|
|
24
|
-
const result = { ...lifecycle };
|
|
25
|
-
const nameMaps = [
|
|
26
|
-
['onReady', 'onPageReady'],
|
|
27
|
-
];
|
|
28
|
-
nameMaps.forEach(e => {
|
|
29
|
-
if (!result[e[0]] && result[e[1]]) {
|
|
30
|
-
result[e[0]] = result[e[1]];
|
|
31
|
-
delete result[e[1]];
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
result['onShareAppMessage'] = (res) => {
|
|
35
|
-
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
36
|
-
return res?.target?.dataset?.weda_share_info;
|
|
37
|
-
}
|
|
38
|
-
if (res?.from === 'menu' && pageAttributes?.appShareMessage) {
|
|
39
|
-
let { enable, pageId, params, imageUrl, title } = pageAttributes.appShareMessage;
|
|
40
|
-
if (enable) {
|
|
41
|
-
pageId = pageId ? pageId.replace(/^(\.)?\//, '') : pageId;
|
|
42
|
-
let realPath = `/pages/${pageId}/index` + (params ? '?' + params.map(pair => pair.key + '=' + pair.value).join('&') : '');
|
|
43
|
-
return {
|
|
44
|
-
path: realPath,
|
|
45
|
-
imageUrl,
|
|
46
|
-
title
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.log(error);
|
|
54
|
-
return {};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return Component({
|
|
61
|
-
_componentType: 'page',
|
|
62
|
-
data: createInitData(widgetProps, dataBinds),
|
|
63
|
-
lifetimes: {
|
|
64
|
-
attached() {
|
|
65
|
-
const $page = this.getWeAppInst()
|
|
66
|
-
// createWidgets 从上面移到这里是为了 i18n 切换语言的时候页面能生效
|
|
67
|
-
$page.widgets = {};
|
|
68
|
-
const { rootWidget, widgets } = createWidgets(widgetProps, dataBinds, $page.widgets, context);
|
|
69
|
-
this._rootWidget = rootWidget;
|
|
70
|
-
this._widgets = widgets;
|
|
71
|
-
this._pageActive = true;
|
|
72
|
-
this.__handlerAttached__ = (e) => {
|
|
73
|
-
if (!$page.componentMethods) {
|
|
74
|
-
$page.componentMethods = {};
|
|
75
|
-
}
|
|
76
|
-
const [id, index = 0] = e.target.id.split('-');
|
|
77
|
-
if (!$page.componentMethods[id]) {
|
|
78
|
-
$page.componentMethods[id] = [];
|
|
79
|
-
}
|
|
80
|
-
$page.componentMethods[id][index] = e.detail.methods;
|
|
81
|
-
};
|
|
82
|
-
this.__handlerDetached__ = (e) => {
|
|
83
|
-
const [id, index = 0] = e.target.id.split('-');
|
|
84
|
-
if ($page.componentMethods) {
|
|
85
|
-
const components = $page.componentMethods[id];
|
|
86
|
-
if (components) {
|
|
87
|
-
components[index] = undefined;
|
|
88
|
-
if (components.filter(com => com !== undefined).length === 0) {
|
|
89
|
-
delete $page.componentMethods[id];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
this._disposers = this.initMergeRenderer(widgets);
|
|
95
|
-
},
|
|
96
|
-
detached() {
|
|
97
|
-
disposeWidget(this._rootWidget);
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
pageLifetimes: {
|
|
101
|
-
// 组件所在页面的生命周期函数,定义下给运营平台上报用
|
|
102
|
-
show: function () {
|
|
103
|
-
},
|
|
104
|
-
hide: function () {
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
methods: {
|
|
108
|
-
_pageActive: true,
|
|
109
|
-
/** page lifecycles **/
|
|
110
|
-
...extractLifecyles(),
|
|
111
|
-
...evtHandlers,
|
|
112
|
-
...mergeRenderer,
|
|
113
|
-
onLoad(options) {
|
|
114
|
-
const $page = this.getWeAppInst()
|
|
115
|
-
|
|
116
|
-
app.__internal__.activePage = $page;
|
|
117
|
-
setConfig({ currentPageId: $page.uuid });
|
|
118
|
-
this._pageActive = true;
|
|
119
|
-
|
|
120
|
-
let query = decodePageQuery(options || {});
|
|
121
|
-
EXTRA_API.setParams($page.uuid, query);
|
|
122
|
-
createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page }));
|
|
123
|
-
|
|
124
|
-
const hook = lifecycle.onLoad || lifecycle.onPageLoad;
|
|
125
|
-
hook && hook.call(this, query);
|
|
126
|
-
},
|
|
127
|
-
onUnload() {
|
|
128
|
-
const $page = this.getWeAppInst()
|
|
129
|
-
this._disposers.forEach(dispose => dispose());
|
|
130
|
-
|
|
131
|
-
const hook = lifecycle.onUnload || lifecycle.onPageUnload;
|
|
132
|
-
hook && hook.call(this);
|
|
133
|
-
},
|
|
134
|
-
async onShow() {
|
|
135
|
-
const $page = this.getWeAppInst()
|
|
136
|
-
app.__internal__.activePage = $page;
|
|
137
|
-
setConfig({ currentPageId: $page.uuid });
|
|
138
|
-
$page.widgets = this._widgets;
|
|
139
|
-
this._pageActive = true;
|
|
140
|
-
|
|
141
|
-
const hook = lifecycle.onShow || lifecycle.onPageShow;
|
|
142
|
-
hook && hook.call(this);
|
|
143
|
-
|
|
144
|
-
// 权限检查
|
|
145
|
-
if (await checkAuth(app, app.id, $page)) {
|
|
146
|
-
this.setData({
|
|
147
|
-
weDaHasLogin: true,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
onHide() {
|
|
152
|
-
const $page = this.getWeAppInst()
|
|
153
|
-
const hook = lifecycle.onHide || lifecycle.onPageHide;
|
|
154
|
-
hook && hook.call(this);
|
|
155
|
-
this._pageActive = false;
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
getWeAppInst() {
|
|
159
|
-
if (!this.$WEAPPS_PAGE) {
|
|
160
|
-
$page.state = observable(pageState);
|
|
161
|
-
let dataset = createDataset($page.uuid);
|
|
162
|
-
$page.dataset = dataset;
|
|
163
|
-
$page.state.dataset = dataset;
|
|
164
|
-
$page.computed = createComputed(pageComputed);
|
|
165
|
-
$page.setState = (userSetState) => {
|
|
166
|
-
Object.keys(userSetState).forEach((keyPath) => {
|
|
167
|
-
app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
171
|
-
const components = lodashGet($page.componentMethods, component);
|
|
172
|
-
let componentInstance = undefined
|
|
173
|
-
if (Array.isArray(components)) {
|
|
174
|
-
if(components.length > 1){
|
|
175
|
-
throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
|
|
176
|
-
}
|
|
177
|
-
componentInstance = components[0]
|
|
178
|
-
// components.forEach(component => {
|
|
179
|
-
// component[method](params);
|
|
180
|
-
// })
|
|
181
|
-
} else {
|
|
182
|
-
componentInstance = components
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if(!componentInstance?.[method] || typeof componentInstance[method]!= 'function') {
|
|
186
|
-
throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
|
|
187
|
-
}
|
|
188
|
-
return componentInstance[method](params);
|
|
189
|
-
};
|
|
190
|
-
this.$WEAPPS_PAGE = $page;
|
|
191
|
-
}
|
|
192
|
-
return this.$WEAPPS_PAGE
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function decodePageQuery(query) {
|
|
199
|
-
return Object.keys(query)
|
|
200
|
-
.reduce((decoded, key) => {
|
|
201
|
-
decoded[key] = decodeURIComponent(query[key]);
|
|
202
|
-
return decoded;
|
|
203
|
-
}, {});
|
|
204
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { urlJoinParams } from './url'
|
|
2
|
-
import { promisifyAll } from 'miniprogram-api-promise'
|
|
3
|
-
|
|
4
|
-
function createNavigatorFn(fnName) {
|
|
5
|
-
return function ({ pageId, packageName, params, mode='', events, success, fail, complete }) {
|
|
6
|
-
let url;
|
|
7
|
-
if(mode == 'plugin'){
|
|
8
|
-
url = `plugin://${packageName}/${pageId}`
|
|
9
|
-
} else if(mode ==='web'){
|
|
10
|
-
console.warn(`${fnName} url can only be used in h5 build`);
|
|
11
|
-
return;
|
|
12
|
-
} else {
|
|
13
|
-
pageId = pageId ? pageId.replace(/^(\.)?\//,'') : pageId;
|
|
14
|
-
url = packageName
|
|
15
|
-
? `/${packageName}/pages/${pageId}/index`
|
|
16
|
-
: `/pages/${pageId}/index`
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (fnName === 'navigateTo') {
|
|
20
|
-
navigateToFn(urlJoinParams(url, params), { events, success, fail, complete});
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
wx[fnName]({
|
|
25
|
-
url: urlJoinParams(url, params),
|
|
26
|
-
events,
|
|
27
|
-
success,
|
|
28
|
-
fail,
|
|
29
|
-
complete
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 页面堆栈10以内使用wx.navigateTo,超过10则使用wx.redirectTo
|
|
36
|
-
* @param url
|
|
37
|
-
* @param param1
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
function navigateToFn(url, { events, success, fail, complete}) {
|
|
41
|
-
const pages = getCurrentPages();
|
|
42
|
-
if(pages && pages.length >= 10) {
|
|
43
|
-
wx.redirectTo({
|
|
44
|
-
url,
|
|
45
|
-
success,
|
|
46
|
-
fail,
|
|
47
|
-
complete
|
|
48
|
-
});
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
wx.navigateTo({
|
|
53
|
-
url,
|
|
54
|
-
// @types/weixin-app@2.9.3没有events的定义,但实际上官方文档有:https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
events,
|
|
57
|
-
success,
|
|
58
|
-
fail,
|
|
59
|
-
complete
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const navigateTo = createNavigatorFn('navigateTo')
|
|
64
|
-
const reLaunch = createNavigatorFn('reLaunch')
|
|
65
|
-
const redirectTo = createNavigatorFn('redirectTo')
|
|
66
|
-
|
|
67
|
-
export const wxp = {}
|
|
68
|
-
promisifyAll(wx, wxp)
|
|
69
|
-
|
|
70
|
-
export default {
|
|
71
|
-
...wxp,
|
|
72
|
-
navigateTo,
|
|
73
|
-
reLaunch,
|
|
74
|
-
redirectTo,
|
|
75
|
-
auth: undefined
|
|
76
|
-
}
|