@dcloudio/uni-mp-toutiao 3.0.0-alpha-3070720230314001 → 3.0.0-alpha-3071220230324001

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.
@@ -3,1017 +3,1018 @@ import { isArray, hasOwn, isFunction, extend, isPlainObject, isObject } from '@v
3
3
  import { ref, nextTick, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache } from 'vue';
4
4
  import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
5
5
 
6
- const MP_METHODS = [
7
- 'createSelectorQuery',
8
- 'createIntersectionObserver',
9
- 'selectAllComponents',
10
- 'selectComponent',
11
- ];
12
- function createEmitFn(oldEmit, ctx) {
13
- return function emit(event, ...args) {
14
- const scope = ctx.$scope;
15
- if (scope && event) {
16
- const detail = { __args__: args };
17
- {
18
- scope.triggerEvent(event, detail);
19
- }
20
- }
21
- return oldEmit.apply(this, [event, ...args]);
22
- };
23
- }
24
- function initBaseInstance(instance, options) {
25
- const ctx = instance.ctx;
26
- // mp
27
- ctx.mpType = options.mpType; // @deprecated
28
- ctx.$mpType = options.mpType;
29
- ctx.$mpPlatform = "mp-toutiao";
30
- ctx.$scope = options.mpInstance;
31
- // TODO @deprecated
32
- ctx.$mp = {};
33
- if (__VUE_OPTIONS_API__) {
34
- ctx._self = {};
35
- }
36
- // slots
37
- instance.slots = {};
38
- if (isArray(options.slots) && options.slots.length) {
39
- options.slots.forEach((name) => {
40
- instance.slots[name] = true;
41
- });
42
- if (instance.slots[SLOT_DEFAULT_NAME]) {
43
- instance.slots.default = true;
44
- }
45
- }
46
- ctx.getOpenerEventChannel = function () {
47
- if (!this.__eventChannel__) {
48
- this.__eventChannel__ = new EventChannel();
49
- }
50
- return this.__eventChannel__;
51
- };
52
- ctx.$hasHook = hasHook;
53
- ctx.$callHook = callHook;
54
- // $emit
55
- instance.emit = createEmitFn(instance.emit, ctx);
56
- }
57
- function initComponentInstance(instance, options) {
58
- initBaseInstance(instance, options);
59
- const ctx = instance.ctx;
60
- MP_METHODS.forEach((method) => {
61
- ctx[method] = function (...args) {
62
- const mpInstance = ctx.$scope;
63
- if (mpInstance && mpInstance[method]) {
64
- return mpInstance[method].apply(mpInstance, args);
65
- }
66
- };
67
- });
68
- }
69
- function initMocks(instance, mpInstance, mocks) {
70
- const ctx = instance.ctx;
71
- mocks.forEach((mock) => {
72
- if (hasOwn(mpInstance, mock)) {
73
- instance[mock] = ctx[mock] = mpInstance[mock];
74
- }
75
- });
76
- }
77
- function hasHook(name) {
78
- const hooks = this.$[name];
79
- if (hooks && hooks.length) {
80
- return true;
81
- }
82
- return false;
83
- }
84
- function callHook(name, args) {
85
- if (name === 'mounted') {
86
- callHook.call(this, 'bm'); // beforeMount
87
- this.$.isMounted = true;
88
- name = 'm';
89
- }
90
- {
91
- if (name === 'onLoad' && args && args.__id__) {
92
- this.__eventChannel__ = tt.getEventChannel(args.__id__);
93
- delete args.__id__;
94
- }
95
- }
96
- const hooks = this.$[name];
97
- return hooks && invokeArrayFns(hooks, args);
6
+ const MP_METHODS = [
7
+ 'createSelectorQuery',
8
+ 'createIntersectionObserver',
9
+ 'selectAllComponents',
10
+ 'selectComponent',
11
+ ];
12
+ function createEmitFn(oldEmit, ctx) {
13
+ return function emit(event, ...args) {
14
+ const scope = ctx.$scope;
15
+ if (scope && event) {
16
+ const detail = { __args__: args };
17
+ {
18
+ scope.triggerEvent(event, detail);
19
+ }
20
+ }
21
+ return oldEmit.apply(this, [event, ...args]);
22
+ };
23
+ }
24
+ function initBaseInstance(instance, options) {
25
+ const ctx = instance.ctx;
26
+ // mp
27
+ ctx.mpType = options.mpType; // @deprecated
28
+ ctx.$mpType = options.mpType;
29
+ ctx.$mpPlatform = "mp-toutiao";
30
+ ctx.$scope = options.mpInstance;
31
+ // TODO @deprecated
32
+ ctx.$mp = {};
33
+ if (__VUE_OPTIONS_API__) {
34
+ ctx._self = {};
35
+ }
36
+ // slots
37
+ instance.slots = {};
38
+ if (isArray(options.slots) && options.slots.length) {
39
+ options.slots.forEach((name) => {
40
+ instance.slots[name] = true;
41
+ });
42
+ if (instance.slots[SLOT_DEFAULT_NAME]) {
43
+ instance.slots.default = true;
44
+ }
45
+ }
46
+ ctx.getOpenerEventChannel = function () {
47
+ if (!this.__eventChannel__) {
48
+ this.__eventChannel__ = new EventChannel();
49
+ }
50
+ return this.__eventChannel__;
51
+ };
52
+ ctx.$hasHook = hasHook;
53
+ ctx.$callHook = callHook;
54
+ // $emit
55
+ instance.emit = createEmitFn(instance.emit, ctx);
56
+ }
57
+ function initComponentInstance(instance, options) {
58
+ initBaseInstance(instance, options);
59
+ const ctx = instance.ctx;
60
+ MP_METHODS.forEach((method) => {
61
+ ctx[method] = function (...args) {
62
+ const mpInstance = ctx.$scope;
63
+ if (mpInstance && mpInstance[method]) {
64
+ return mpInstance[method].apply(mpInstance, args);
65
+ }
66
+ };
67
+ });
68
+ }
69
+ function initMocks(instance, mpInstance, mocks) {
70
+ const ctx = instance.ctx;
71
+ mocks.forEach((mock) => {
72
+ if (hasOwn(mpInstance, mock)) {
73
+ instance[mock] = ctx[mock] = mpInstance[mock];
74
+ }
75
+ });
76
+ }
77
+ function hasHook(name) {
78
+ const hooks = this.$[name];
79
+ if (hooks && hooks.length) {
80
+ return true;
81
+ }
82
+ return false;
83
+ }
84
+ function callHook(name, args) {
85
+ if (name === 'mounted') {
86
+ callHook.call(this, 'bm'); // beforeMount
87
+ this.$.isMounted = true;
88
+ name = 'm';
89
+ }
90
+ {
91
+ if (name === 'onLoad' && args && args.__id__) {
92
+ this.__eventChannel__ = tt.getEventChannel(args.__id__);
93
+ delete args.__id__;
94
+ }
95
+ }
96
+ const hooks = this.$[name];
97
+ return hooks && invokeArrayFns(hooks, args);
98
98
  }
99
99
 
100
- const PAGE_INIT_HOOKS = [
101
- ON_LOAD,
102
- ON_SHOW,
103
- ON_HIDE,
104
- ON_UNLOAD,
105
- ON_RESIZE,
106
- ON_TAB_ITEM_TAP,
107
- ON_REACH_BOTTOM,
108
- ON_PULL_DOWN_REFRESH,
109
- ON_ADD_TO_FAVORITES,
110
- // 'onReady', // lifetimes.ready
111
- // 'onPageScroll', // 影响性能,开发者手动注册
112
- // 'onShareTimeline', // 右上角菜单,开发者手动注册
113
- // 'onShareAppMessage' // 右上角菜单,开发者手动注册
114
- ];
115
- function findHooks(vueOptions, hooks = new Set()) {
116
- if (vueOptions) {
117
- Object.keys(vueOptions).forEach((name) => {
118
- if (isUniLifecycleHook(name, vueOptions[name])) {
119
- hooks.add(name);
120
- }
121
- });
122
- if (__VUE_OPTIONS_API__) {
123
- const { extends: extendsOptions, mixins } = vueOptions;
124
- if (mixins) {
125
- mixins.forEach((mixin) => findHooks(mixin, hooks));
126
- }
127
- if (extendsOptions) {
128
- findHooks(extendsOptions, hooks);
129
- }
130
- }
131
- }
132
- return hooks;
133
- }
134
- function initHook(mpOptions, hook, excludes) {
135
- if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
136
- mpOptions[hook] = function (args) {
137
- if (hook === 'onError') {
138
- return getApp().$vm.$callHook(hook, args);
139
- }
140
- return this.$vm && this.$vm.$callHook(hook, args);
141
- };
142
- }
143
- }
144
- const EXCLUDE_HOOKS = [ON_READY];
145
- function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
146
- hooks.forEach((hook) => initHook(mpOptions, hook, excludes));
147
- }
148
- function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
149
- findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes));
150
- }
151
- function initRuntimeHooks(mpOptions, runtimeHooks) {
152
- if (!runtimeHooks) {
153
- return;
154
- }
155
- const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
156
- hooks.forEach((hook) => {
157
- if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) {
158
- initHook(mpOptions, hook, []);
159
- }
160
- });
161
- }
162
- const findMixinRuntimeHooks = /*#__PURE__*/ once(() => {
163
- const runtimeHooks = [];
164
- const app = isFunction(getApp) && getApp({ allowDefault: true });
165
- if (app && app.$vm && app.$vm.$) {
166
- const mixins = app.$vm.$.appContext.mixins;
167
- if (isArray(mixins)) {
168
- const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
169
- mixins.forEach((mixin) => {
170
- hooks.forEach((hook) => {
171
- if (hasOwn(mixin, hook) && !runtimeHooks.includes(hook)) {
172
- runtimeHooks.push(hook);
173
- }
174
- });
175
- });
176
- }
177
- }
178
- return runtimeHooks;
179
- });
180
- function initMixinRuntimeHooks(mpOptions) {
181
- initHooks(mpOptions, findMixinRuntimeHooks());
100
+ const PAGE_INIT_HOOKS = [
101
+ ON_LOAD,
102
+ ON_SHOW,
103
+ ON_HIDE,
104
+ ON_UNLOAD,
105
+ ON_RESIZE,
106
+ ON_TAB_ITEM_TAP,
107
+ ON_REACH_BOTTOM,
108
+ ON_PULL_DOWN_REFRESH,
109
+ ON_ADD_TO_FAVORITES,
110
+ // 'onReady', // lifetimes.ready
111
+ // 'onPageScroll', // 影响性能,开发者手动注册
112
+ // 'onShareTimeline', // 右上角菜单,开发者手动注册
113
+ // 'onShareAppMessage' // 右上角菜单,开发者手动注册
114
+ ];
115
+ function findHooks(vueOptions, hooks = new Set()) {
116
+ if (vueOptions) {
117
+ Object.keys(vueOptions).forEach((name) => {
118
+ if (isUniLifecycleHook(name, vueOptions[name])) {
119
+ hooks.add(name);
120
+ }
121
+ });
122
+ if (__VUE_OPTIONS_API__) {
123
+ const { extends: extendsOptions, mixins } = vueOptions;
124
+ if (mixins) {
125
+ mixins.forEach((mixin) => findHooks(mixin, hooks));
126
+ }
127
+ if (extendsOptions) {
128
+ findHooks(extendsOptions, hooks);
129
+ }
130
+ }
131
+ }
132
+ return hooks;
133
+ }
134
+ function initHook(mpOptions, hook, excludes) {
135
+ if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
136
+ mpOptions[hook] = function (args) {
137
+ if (hook === 'onError') {
138
+ return getApp().$vm.$callHook(hook, args);
139
+ }
140
+ return this.$vm && this.$vm.$callHook(hook, args);
141
+ };
142
+ }
143
+ }
144
+ const EXCLUDE_HOOKS = [ON_READY];
145
+ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
146
+ hooks.forEach((hook) => initHook(mpOptions, hook, excludes));
147
+ }
148
+ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
149
+ findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes));
150
+ }
151
+ function initRuntimeHooks(mpOptions, runtimeHooks) {
152
+ if (!runtimeHooks) {
153
+ return;
154
+ }
155
+ const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
156
+ hooks.forEach((hook) => {
157
+ if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) {
158
+ initHook(mpOptions, hook, []);
159
+ }
160
+ });
161
+ }
162
+ const findMixinRuntimeHooks = /*#__PURE__*/ once(() => {
163
+ const runtimeHooks = [];
164
+ const app = isFunction(getApp) && getApp({ allowDefault: true });
165
+ if (app && app.$vm && app.$vm.$) {
166
+ const mixins = app.$vm.$.appContext.mixins;
167
+ if (isArray(mixins)) {
168
+ const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
169
+ mixins.forEach((mixin) => {
170
+ hooks.forEach((hook) => {
171
+ if (hasOwn(mixin, hook) && !runtimeHooks.includes(hook)) {
172
+ runtimeHooks.push(hook);
173
+ }
174
+ });
175
+ });
176
+ }
177
+ }
178
+ return runtimeHooks;
179
+ });
180
+ function initMixinRuntimeHooks(mpOptions) {
181
+ initHooks(mpOptions, findMixinRuntimeHooks());
182
182
  }
183
183
 
184
- const HOOKS = [
185
- ON_SHOW,
186
- ON_HIDE,
187
- ON_ERROR,
188
- ON_THEME_CHANGE,
189
- ON_PAGE_NOT_FOUND,
190
- ON_UNHANDLE_REJECTION,
191
- ];
192
- function parseApp(instance, parseAppOptions) {
193
- const internalInstance = instance.$;
194
- if (__VUE_PROD_DEVTOOLS__) {
195
- // 定制 App 的 $children
196
- Object.defineProperty(internalInstance.ctx, '$children', {
197
- get() {
198
- return getCurrentPages().map((page) => page.$vm);
199
- },
200
- });
201
- }
202
- const appOptions = {
203
- globalData: (instance.$options && instance.$options.globalData) || {},
204
- $vm: instance,
205
- onLaunch(options) {
206
- this.$vm = instance; // 飞书小程序可能会把 AppOptions 序列化,导致 $vm 对象部分属性丢失
207
- const ctx = internalInstance.ctx;
208
- if (this.$vm && ctx.$scope) {
209
- // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
210
- return;
211
- }
212
- initBaseInstance(internalInstance, {
213
- mpType: 'app',
214
- mpInstance: this,
215
- slots: [],
216
- });
217
- ctx.globalData = this.globalData;
218
- instance.$callHook(ON_LAUNCH, options);
219
- },
220
- };
221
- initLocale(instance);
222
- const vueOptions = instance.$.type;
223
- initHooks(appOptions, HOOKS);
224
- initUnknownHooks(appOptions, vueOptions);
225
- if (__VUE_OPTIONS_API__) {
226
- const methods = vueOptions.methods;
227
- methods && extend(appOptions, methods);
228
- }
229
- if (parseAppOptions) {
230
- parseAppOptions.parse(appOptions);
231
- }
232
- return appOptions;
233
- }
234
- function initCreateApp(parseAppOptions) {
235
- return function createApp(vm) {
236
- return App(parseApp(vm, parseAppOptions));
237
- };
238
- }
239
- function initCreateSubpackageApp(parseAppOptions) {
240
- return function createApp(vm) {
241
- const appOptions = parseApp(vm, parseAppOptions);
242
- const app = isFunction(getApp) &&
243
- getApp({
244
- allowDefault: true,
245
- });
246
- if (!app)
247
- return;
248
- vm.$.ctx.$scope = app;
249
- const globalData = app.globalData;
250
- if (globalData) {
251
- Object.keys(appOptions.globalData).forEach((name) => {
252
- if (!hasOwn(globalData, name)) {
253
- globalData[name] = appOptions.globalData[name];
254
- }
255
- });
256
- }
257
- Object.keys(appOptions).forEach((name) => {
258
- if (!hasOwn(app, name)) {
259
- app[name] = appOptions[name];
260
- }
261
- });
262
- initAppLifecycle(appOptions, vm);
263
- if (process.env.UNI_SUBPACKAGE) {
264
- (tt.$subpackages || (tt.$subpackages = {}))[process.env.UNI_SUBPACKAGE] = {
265
- $vm: vm,
266
- };
267
- }
268
- };
269
- }
270
- function initAppLifecycle(appOptions, vm) {
271
- if (isFunction(appOptions.onLaunch)) {
272
- const args = tt.getLaunchOptionsSync && tt.getLaunchOptionsSync();
273
- appOptions.onLaunch(args);
274
- }
275
- if (isFunction(appOptions.onShow) && tt.onAppShow) {
276
- tt.onAppShow((args) => {
277
- vm.$callHook('onShow', args);
278
- });
279
- }
280
- if (isFunction(appOptions.onHide) && tt.onAppHide) {
281
- tt.onAppHide((args) => {
282
- vm.$callHook('onHide', args);
283
- });
284
- }
285
- }
286
- function initLocale(appVm) {
287
- const locale = ref(normalizeLocale(tt.getSystemInfoSync().language) || LOCALE_EN);
288
- Object.defineProperty(appVm, '$locale', {
289
- get() {
290
- return locale.value;
291
- },
292
- set(v) {
293
- locale.value = v;
294
- },
295
- });
184
+ const HOOKS = [
185
+ ON_SHOW,
186
+ ON_HIDE,
187
+ ON_ERROR,
188
+ ON_THEME_CHANGE,
189
+ ON_PAGE_NOT_FOUND,
190
+ ON_UNHANDLE_REJECTION,
191
+ ];
192
+ function parseApp(instance, parseAppOptions) {
193
+ const internalInstance = instance.$;
194
+ if (__VUE_PROD_DEVTOOLS__) {
195
+ // 定制 App 的 $children
196
+ Object.defineProperty(internalInstance.ctx, '$children', {
197
+ get() {
198
+ return getCurrentPages().map((page) => page.$vm);
199
+ },
200
+ });
201
+ }
202
+ const appOptions = {
203
+ globalData: (instance.$options && instance.$options.globalData) || {},
204
+ $vm: instance,
205
+ onLaunch(options) {
206
+ this.$vm = instance; // 飞书小程序可能会把 AppOptions 序列化,导致 $vm 对象部分属性丢失
207
+ const ctx = internalInstance.ctx;
208
+ if (this.$vm && ctx.$scope) {
209
+ // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
210
+ return;
211
+ }
212
+ initBaseInstance(internalInstance, {
213
+ mpType: 'app',
214
+ mpInstance: this,
215
+ slots: [],
216
+ });
217
+ ctx.globalData = this.globalData;
218
+ instance.$callHook(ON_LAUNCH, options);
219
+ },
220
+ };
221
+ initLocale(instance);
222
+ const vueOptions = instance.$.type;
223
+ initHooks(appOptions, HOOKS);
224
+ initUnknownHooks(appOptions, vueOptions);
225
+ if (__VUE_OPTIONS_API__) {
226
+ const methods = vueOptions.methods;
227
+ methods && extend(appOptions, methods);
228
+ }
229
+ if (parseAppOptions) {
230
+ parseAppOptions.parse(appOptions);
231
+ }
232
+ return appOptions;
233
+ }
234
+ function initCreateApp(parseAppOptions) {
235
+ return function createApp(vm) {
236
+ return App(parseApp(vm, parseAppOptions));
237
+ };
238
+ }
239
+ function initCreateSubpackageApp(parseAppOptions) {
240
+ return function createApp(vm) {
241
+ const appOptions = parseApp(vm, parseAppOptions);
242
+ const app = isFunction(getApp) &&
243
+ getApp({
244
+ allowDefault: true,
245
+ });
246
+ if (!app)
247
+ return;
248
+ vm.$.ctx.$scope = app;
249
+ const globalData = app.globalData;
250
+ if (globalData) {
251
+ Object.keys(appOptions.globalData).forEach((name) => {
252
+ if (!hasOwn(globalData, name)) {
253
+ globalData[name] = appOptions.globalData[name];
254
+ }
255
+ });
256
+ }
257
+ Object.keys(appOptions).forEach((name) => {
258
+ if (!hasOwn(app, name)) {
259
+ app[name] = appOptions[name];
260
+ }
261
+ });
262
+ initAppLifecycle(appOptions, vm);
263
+ if (process.env.UNI_SUBPACKAGE) {
264
+ (tt.$subpackages || (tt.$subpackages = {}))[process.env.UNI_SUBPACKAGE] = {
265
+ $vm: vm,
266
+ };
267
+ }
268
+ };
269
+ }
270
+ function initAppLifecycle(appOptions, vm) {
271
+ if (isFunction(appOptions.onLaunch)) {
272
+ const args = tt.getLaunchOptionsSync && tt.getLaunchOptionsSync();
273
+ appOptions.onLaunch(args);
274
+ }
275
+ if (isFunction(appOptions.onShow) && tt.onAppShow) {
276
+ tt.onAppShow((args) => {
277
+ vm.$callHook('onShow', args);
278
+ });
279
+ }
280
+ if (isFunction(appOptions.onHide) && tt.onAppHide) {
281
+ tt.onAppHide((args) => {
282
+ vm.$callHook('onHide', args);
283
+ });
284
+ }
285
+ }
286
+ function initLocale(appVm) {
287
+ const locale = ref(normalizeLocale(tt.getSystemInfoSync().language) || LOCALE_EN);
288
+ Object.defineProperty(appVm, '$locale', {
289
+ get() {
290
+ return locale.value;
291
+ },
292
+ set(v) {
293
+ locale.value = v;
294
+ },
295
+ });
296
296
  }
297
297
 
298
- function initVueIds(vueIds, mpInstance) {
299
- if (!vueIds) {
300
- return;
301
- }
302
- const ids = vueIds.split(',');
303
- const len = ids.length;
304
- if (len === 1) {
305
- mpInstance._$vueId = ids[0];
306
- }
307
- else if (len === 2) {
308
- mpInstance._$vueId = ids[0];
309
- mpInstance._$vuePid = ids[1];
310
- }
311
- }
312
- const EXTRAS = ['externalClasses'];
313
- function initExtraOptions(miniProgramComponentOptions, vueOptions) {
314
- EXTRAS.forEach((name) => {
315
- if (hasOwn(vueOptions, name)) {
316
- miniProgramComponentOptions[name] = vueOptions[name];
317
- }
318
- });
319
- }
320
- function initWxsCallMethods(methods, wxsCallMethods) {
321
- if (!isArray(wxsCallMethods)) {
322
- return;
323
- }
324
- wxsCallMethods.forEach((callMethod) => {
325
- methods[callMethod] = function (args) {
326
- return this.$vm[callMethod](args);
327
- };
328
- });
329
- }
330
- function selectAllComponents(mpInstance, selector, $refs) {
331
- const components = mpInstance.selectAllComponents(selector);
332
- components.forEach((component) => {
333
- const ref = component.properties.uR;
334
- $refs[ref] = component.$vm || component;
335
- });
336
- }
337
- function initRefs(instance, mpInstance) {
338
- Object.defineProperty(instance, 'refs', {
339
- get() {
340
- const $refs = {};
341
- selectAllComponents(mpInstance, '.r', $refs);
342
- const forComponents = mpInstance.selectAllComponents('.r-i-f');
343
- forComponents.forEach((component) => {
344
- const ref = component.properties.uR;
345
- if (!ref) {
346
- return;
347
- }
348
- if (!$refs[ref]) {
349
- $refs[ref] = [];
350
- }
351
- $refs[ref].push(component.$vm || component);
352
- });
353
- return $refs;
354
- },
355
- });
356
- }
357
- function findVmByVueId(instance, vuePid) {
358
- // 标准 vue3 中 没有 $children,定制了内核
359
- const $children = instance.$children;
360
- // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
361
- for (let i = $children.length - 1; i >= 0; i--) {
362
- const childVm = $children[i];
363
- if (childVm.$scope._$vueId === vuePid) {
364
- return childVm;
365
- }
366
- }
367
- // 反向递归查找
368
- let parentVm;
369
- for (let i = $children.length - 1; i >= 0; i--) {
370
- parentVm = findVmByVueId($children[i], vuePid);
371
- if (parentVm) {
372
- return parentVm;
373
- }
374
- }
375
- }
376
- function nextSetDataTick(mpInstance, fn) {
377
- // 随便设置一个字段来触发回调(部分平台必须有字段才可以,比如头条)
378
- mpInstance.setData({ r1: 1 }, () => fn());
379
- }
380
- function initSetRef(mpInstance) {
381
- if (!mpInstance._$setRef) {
382
- mpInstance._$setRef = (fn) => {
383
- nextTick(() => nextSetDataTick(mpInstance, fn));
384
- };
385
- }
298
+ function initVueIds(vueIds, mpInstance) {
299
+ if (!vueIds) {
300
+ return;
301
+ }
302
+ const ids = vueIds.split(',');
303
+ const len = ids.length;
304
+ if (len === 1) {
305
+ mpInstance._$vueId = ids[0];
306
+ }
307
+ else if (len === 2) {
308
+ mpInstance._$vueId = ids[0];
309
+ mpInstance._$vuePid = ids[1];
310
+ }
311
+ }
312
+ const EXTRAS = ['externalClasses'];
313
+ function initExtraOptions(miniProgramComponentOptions, vueOptions) {
314
+ EXTRAS.forEach((name) => {
315
+ if (hasOwn(vueOptions, name)) {
316
+ miniProgramComponentOptions[name] = vueOptions[name];
317
+ }
318
+ });
319
+ }
320
+ function initWxsCallMethods(methods, wxsCallMethods) {
321
+ if (!isArray(wxsCallMethods)) {
322
+ return;
323
+ }
324
+ wxsCallMethods.forEach((callMethod) => {
325
+ methods[callMethod] = function (args) {
326
+ return this.$vm[callMethod](args);
327
+ };
328
+ });
329
+ }
330
+ function selectAllComponents(mpInstance, selector, $refs) {
331
+ const components = mpInstance.selectAllComponents(selector);
332
+ components.forEach((component) => {
333
+ const ref = component.properties.uR;
334
+ $refs[ref] = component.$vm || component;
335
+ });
336
+ }
337
+ function initRefs(instance, mpInstance) {
338
+ Object.defineProperty(instance, 'refs', {
339
+ get() {
340
+ const $refs = {};
341
+ selectAllComponents(mpInstance, '.r', $refs);
342
+ const forComponents = mpInstance.selectAllComponents('.r-i-f');
343
+ forComponents.forEach((component) => {
344
+ const ref = component.properties.uR;
345
+ if (!ref) {
346
+ return;
347
+ }
348
+ if (!$refs[ref]) {
349
+ $refs[ref] = [];
350
+ }
351
+ $refs[ref].push(component.$vm || component);
352
+ });
353
+ return $refs;
354
+ },
355
+ });
356
+ }
357
+ function findVmByVueId(instance, vuePid) {
358
+ // 标准 vue3 中 没有 $children,定制了内核
359
+ const $children = instance.$children;
360
+ // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
361
+ for (let i = $children.length - 1; i >= 0; i--) {
362
+ const childVm = $children[i];
363
+ if (childVm.$scope._$vueId === vuePid) {
364
+ return childVm;
365
+ }
366
+ }
367
+ // 反向递归查找
368
+ let parentVm;
369
+ for (let i = $children.length - 1; i >= 0; i--) {
370
+ parentVm = findVmByVueId($children[i], vuePid);
371
+ if (parentVm) {
372
+ return parentVm;
373
+ }
374
+ }
375
+ }
376
+ function nextSetDataTick(mpInstance, fn) {
377
+ // 随便设置一个字段来触发回调(部分平台必须有字段才可以,比如头条)
378
+ mpInstance.setData({ r1: 1 }, () => fn());
379
+ }
380
+ function initSetRef(mpInstance) {
381
+ if (!mpInstance._$setRef) {
382
+ mpInstance._$setRef = (fn) => {
383
+ nextTick(() => nextSetDataTick(mpInstance, fn));
384
+ };
385
+ }
386
386
  }
387
387
 
388
- const builtInProps = [
389
- // 百度小程序,快手小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
390
- // event-opts
391
- 'eO',
392
- // 组件 ref
393
- 'uR',
394
- // 组件 ref-in-for
395
- 'uRIF',
396
- // 组件 id
397
- 'uI',
398
- // 组件类型 m: 小程序组件
399
- 'uT',
400
- // 组件 props
401
- 'uP',
402
- // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
403
- 'uS',
404
- ];
405
- function initDefaultProps(options, isBehavior = false) {
406
- const properties = {};
407
- if (!isBehavior) {
408
- // 均不指定类型,避免微信小程序 property received type-uncompatible value 警告
409
- builtInProps.forEach((name) => {
410
- properties[name] = {
411
- type: null,
412
- value: '',
413
- };
414
- });
415
- // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
416
- properties.uS = {
417
- type: null,
418
- value: [],
419
- observer: function (newVal) {
420
- const $slots = Object.create(null);
421
- newVal &&
422
- newVal.forEach((slotName) => {
423
- $slots[slotName] = true;
424
- });
425
- this.setData({
426
- $slots,
427
- });
428
- },
429
- };
430
- }
431
- if (options.behaviors) {
432
- // wx://form-field
433
- if (options.behaviors.includes('tt://form-field')) {
434
- properties.name = {
435
- type: null,
436
- value: '',
437
- };
438
- properties.value = {
439
- type: null,
440
- value: '',
441
- };
442
- }
443
- }
444
- return properties;
445
- }
446
- function initVirtualHostProps(options) {
447
- const properties = {};
448
- return properties;
449
- }
450
- /**
451
- *
452
- * @param mpComponentOptions
453
- * @param isBehavior
454
- */
455
- function initProps(mpComponentOptions) {
456
- if (!mpComponentOptions.properties) {
457
- mpComponentOptions.properties = {};
458
- }
459
- extend(mpComponentOptions.properties, initDefaultProps(mpComponentOptions), initVirtualHostProps(mpComponentOptions.options));
460
- }
461
- const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
462
- function parsePropType(type, defaultValue) {
463
- // [String]=>String
464
- if (isArray(type) && type.length === 1) {
465
- return type[0];
466
- }
467
- return type;
468
- }
469
- function normalizePropType(type, defaultValue) {
470
- const res = parsePropType(type);
471
- return PROP_TYPES.indexOf(res) !== -1 ? res : null;
472
- }
473
- /**
474
- * 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
475
- * @param param
476
- * @param rawProps
477
- */
478
- function initPageProps({ properties }, rawProps) {
479
- if (isArray(rawProps)) {
480
- rawProps.forEach((key) => {
481
- properties[key] = {
482
- type: String,
483
- value: '',
484
- };
485
- });
486
- }
487
- else if (isPlainObject(rawProps)) {
488
- Object.keys(rawProps).forEach((key) => {
489
- const opts = rawProps[key];
490
- if (isPlainObject(opts)) {
491
- // title:{type:String,default:''}
492
- let value = opts.default;
493
- if (isFunction(value)) {
494
- value = value();
495
- }
496
- const type = opts.type;
497
- opts.type = normalizePropType(type);
498
- properties[key] = {
499
- type: opts.type,
500
- value,
501
- };
502
- }
503
- else {
504
- // content:String
505
- properties[key] = {
506
- type: normalizePropType(opts),
507
- };
508
- }
509
- });
510
- }
511
- }
512
- function findPropsData(properties, isPage) {
513
- return ((isPage
514
- ? findPagePropsData(properties)
515
- : findComponentPropsData(properties.uP)) || {});
516
- }
517
- function findPagePropsData(properties) {
518
- const propsData = {};
519
- if (isPlainObject(properties)) {
520
- Object.keys(properties).forEach((name) => {
521
- if (builtInProps.indexOf(name) === -1) {
522
- propsData[name] = properties[name];
523
- }
524
- });
525
- }
526
- return propsData;
527
- }
528
- function initFormField(vm) {
529
- // 同步 form-field 的 name,value 值
530
- const vueOptions = vm.$options;
531
- if (isArray(vueOptions.behaviors) &&
532
- vueOptions.behaviors.includes('uni://form-field')) {
533
- vm.$watch('modelValue', () => {
534
- vm.$scope &&
535
- vm.$scope.setData({
536
- name: vm.name,
537
- value: vm.modelValue,
538
- });
539
- }, {
540
- immediate: true,
541
- });
542
- }
388
+ const builtInProps = [
389
+ // 百度小程序,快手小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
390
+ // event-opts
391
+ 'eO',
392
+ // 组件 ref
393
+ 'uR',
394
+ // 组件 ref-in-for
395
+ 'uRIF',
396
+ // 组件 id
397
+ 'uI',
398
+ // 组件类型 m: 小程序组件
399
+ 'uT',
400
+ // 组件 props
401
+ 'uP',
402
+ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
403
+ 'uS',
404
+ ];
405
+ function initDefaultProps(options, isBehavior = false) {
406
+ const properties = {};
407
+ if (!isBehavior) {
408
+ // 均不指定类型,避免微信小程序 property received type-uncompatible value 警告
409
+ builtInProps.forEach((name) => {
410
+ properties[name] = {
411
+ type: null,
412
+ value: '',
413
+ };
414
+ });
415
+ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
416
+ properties.uS = {
417
+ type: null,
418
+ value: [],
419
+ observer: function (newVal) {
420
+ const $slots = Object.create(null);
421
+ newVal &&
422
+ newVal.forEach((slotName) => {
423
+ $slots[slotName] = true;
424
+ });
425
+ this.setData({
426
+ $slots,
427
+ });
428
+ },
429
+ };
430
+ }
431
+ if (options.behaviors) {
432
+ // wx://form-field
433
+ if (options.behaviors.includes('tt://form-field')) {
434
+ properties.name = {
435
+ type: null,
436
+ value: '',
437
+ };
438
+ properties.value = {
439
+ type: null,
440
+ value: '',
441
+ };
442
+ }
443
+ }
444
+ return properties;
445
+ }
446
+ function initVirtualHostProps(options) {
447
+ const properties = {};
448
+ return properties;
449
+ }
450
+ /**
451
+ *
452
+ * @param mpComponentOptions
453
+ * @param isBehavior
454
+ */
455
+ function initProps(mpComponentOptions) {
456
+ if (!mpComponentOptions.properties) {
457
+ mpComponentOptions.properties = {};
458
+ }
459
+ extend(mpComponentOptions.properties, initDefaultProps(mpComponentOptions), initVirtualHostProps(mpComponentOptions.options));
460
+ }
461
+ const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
462
+ function parsePropType(type, defaultValue) {
463
+ // [String]=>String
464
+ if (isArray(type) && type.length === 1) {
465
+ return type[0];
466
+ }
467
+ return type;
468
+ }
469
+ function normalizePropType(type, defaultValue) {
470
+ const res = parsePropType(type);
471
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
472
+ }
473
+ /**
474
+ * 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
475
+ * @param param
476
+ * @param rawProps
477
+ */
478
+ function initPageProps({ properties }, rawProps) {
479
+ if (isArray(rawProps)) {
480
+ rawProps.forEach((key) => {
481
+ properties[key] = {
482
+ type: String,
483
+ value: '',
484
+ };
485
+ });
486
+ }
487
+ else if (isPlainObject(rawProps)) {
488
+ Object.keys(rawProps).forEach((key) => {
489
+ const opts = rawProps[key];
490
+ if (isPlainObject(opts)) {
491
+ // title:{type:String,default:''}
492
+ let value = opts.default;
493
+ if (isFunction(value)) {
494
+ value = value();
495
+ }
496
+ const type = opts.type;
497
+ opts.type = normalizePropType(type);
498
+ properties[key] = {
499
+ type: opts.type,
500
+ value,
501
+ };
502
+ }
503
+ else {
504
+ // content:String
505
+ properties[key] = {
506
+ type: normalizePropType(opts),
507
+ };
508
+ }
509
+ });
510
+ }
511
+ }
512
+ function findPropsData(properties, isPage) {
513
+ return ((isPage
514
+ ? findPagePropsData(properties)
515
+ : findComponentPropsData(properties.uP)) || {});
516
+ }
517
+ function findPagePropsData(properties) {
518
+ const propsData = {};
519
+ if (isPlainObject(properties)) {
520
+ Object.keys(properties).forEach((name) => {
521
+ if (builtInProps.indexOf(name) === -1) {
522
+ propsData[name] = properties[name];
523
+ }
524
+ });
525
+ }
526
+ return propsData;
527
+ }
528
+ function initFormField(vm) {
529
+ // 同步 form-field 的 name,value 值
530
+ const vueOptions = vm.$options;
531
+ if (isArray(vueOptions.behaviors) &&
532
+ vueOptions.behaviors.includes('uni://form-field')) {
533
+ vm.$watch('modelValue', () => {
534
+ vm.$scope &&
535
+ vm.$scope.setData({
536
+ name: vm.name,
537
+ value: vm.modelValue,
538
+ });
539
+ }, {
540
+ immediate: true,
541
+ });
542
+ }
543
543
  }
544
544
 
545
- function initData(_) {
546
- return {};
547
- }
548
- function initPropsObserver(componentOptions) {
549
- const observe = function observe() {
550
- const up = this.properties.uP;
551
- if (!up) {
552
- return;
553
- }
554
- if (this.$vm) {
555
- updateComponentProps(up, this.$vm.$);
556
- }
557
- else if (this.properties.uT === 'm') {
558
- // 小程序组件
559
- updateMiniProgramComponentProperties(up, this);
560
- }
561
- };
562
- {
563
- componentOptions.properties.uP.observer = observe;
564
- }
565
- }
566
- function updateMiniProgramComponentProperties(up, mpInstance) {
567
- const prevProps = mpInstance.properties;
568
- const nextProps = findComponentPropsData(up) || {};
569
- if (hasPropsChanged(prevProps, nextProps, false)) {
570
- mpInstance.setData(nextProps);
571
- }
572
- }
573
- function updateComponentProps(up, instance) {
574
- const prevProps = toRaw(instance.props);
575
- const nextProps = findComponentPropsData(up) || {};
576
- if (hasPropsChanged(prevProps, nextProps)) {
577
- updateProps(instance, nextProps, prevProps, false);
578
- if (hasQueueJob(instance.update)) {
579
- invalidateJob(instance.update);
580
- }
581
- {
582
- // 字节跳动小程序 https://github.com/dcloudio/uni-app/issues/3340
583
- // 百度小程序 https://github.com/dcloudio/uni-app/issues/3612
584
- if (!hasQueueJob(instance.update)) {
585
- instance.update();
586
- }
587
- }
588
- }
589
- }
590
- function hasPropsChanged(prevProps, nextProps, checkLen = true) {
591
- const nextKeys = Object.keys(nextProps);
592
- if (checkLen && nextKeys.length !== Object.keys(prevProps).length) {
593
- return true;
594
- }
595
- for (let i = 0; i < nextKeys.length; i++) {
596
- const key = nextKeys[i];
597
- if (nextProps[key] !== prevProps[key]) {
598
- return true;
599
- }
600
- }
601
- return false;
602
- }
603
- function initBehaviors(vueOptions) {
604
- const vueBehaviors = vueOptions.behaviors;
605
- let vueProps = vueOptions.props;
606
- if (!vueProps) {
607
- vueOptions.props = vueProps = [];
608
- }
609
- const behaviors = [];
610
- if (isArray(vueBehaviors)) {
611
- vueBehaviors.forEach((behavior) => {
612
- behaviors.push(behavior.replace('uni://', 'tt://'));
613
- if (behavior === 'uni://form-field') {
614
- if (isArray(vueProps)) {
615
- vueProps.push('name');
616
- vueProps.push('modelValue');
617
- }
618
- else {
619
- vueProps.name = {
620
- type: String,
621
- default: '',
622
- };
623
- vueProps.modelValue = {
624
- type: [String, Number, Boolean, Array, Object, Date],
625
- default: '',
626
- };
627
- }
628
- }
629
- });
630
- }
631
- return behaviors;
632
- }
633
- function applyOptions(componentOptions, vueOptions) {
634
- componentOptions.data = initData();
635
- componentOptions.behaviors = initBehaviors(vueOptions);
545
+ function initData(_) {
546
+ return {};
547
+ }
548
+ function initPropsObserver(componentOptions) {
549
+ const observe = function observe() {
550
+ const up = this.properties.uP;
551
+ if (!up) {
552
+ return;
553
+ }
554
+ if (this.$vm) {
555
+ updateComponentProps(up, this.$vm.$);
556
+ }
557
+ else if (this.properties.uT === 'm') {
558
+ // 小程序组件
559
+ updateMiniProgramComponentProperties(up, this);
560
+ }
561
+ };
562
+ {
563
+ componentOptions.properties.uP.observer = observe;
564
+ }
565
+ }
566
+ function updateMiniProgramComponentProperties(up, mpInstance) {
567
+ const prevProps = mpInstance.properties;
568
+ const nextProps = findComponentPropsData(up) || {};
569
+ if (hasPropsChanged(prevProps, nextProps, false)) {
570
+ mpInstance.setData(nextProps);
571
+ }
572
+ }
573
+ function updateComponentProps(up, instance) {
574
+ const prevProps = toRaw(instance.props);
575
+ const nextProps = findComponentPropsData(up) || {};
576
+ if (hasPropsChanged(prevProps, nextProps)) {
577
+ updateProps(instance, nextProps, prevProps, false);
578
+ if (hasQueueJob(instance.update)) {
579
+ invalidateJob(instance.update);
580
+ }
581
+ {
582
+ // 字节跳动小程序 https://github.com/dcloudio/uni-app/issues/3340
583
+ // 百度小程序 https://github.com/dcloudio/uni-app/issues/3612
584
+ if (!hasQueueJob(instance.update)) {
585
+ instance.update();
586
+ }
587
+ }
588
+ }
589
+ }
590
+ function hasPropsChanged(prevProps, nextProps, checkLen = true) {
591
+ const nextKeys = Object.keys(nextProps);
592
+ if (checkLen && nextKeys.length !== Object.keys(prevProps).length) {
593
+ return true;
594
+ }
595
+ for (let i = 0; i < nextKeys.length; i++) {
596
+ const key = nextKeys[i];
597
+ if (nextProps[key] !== prevProps[key]) {
598
+ return true;
599
+ }
600
+ }
601
+ return false;
602
+ }
603
+ function initBehaviors(vueOptions) {
604
+ const vueBehaviors = vueOptions.behaviors;
605
+ let vueProps = vueOptions.props;
606
+ if (!vueProps) {
607
+ vueOptions.props = vueProps = [];
608
+ }
609
+ const behaviors = [];
610
+ if (isArray(vueBehaviors)) {
611
+ vueBehaviors.forEach((behavior) => {
612
+ behaviors.push(behavior.replace('uni://', 'tt://'));
613
+ if (behavior === 'uni://form-field') {
614
+ if (isArray(vueProps)) {
615
+ vueProps.push('name');
616
+ vueProps.push('modelValue');
617
+ }
618
+ else {
619
+ vueProps.name = {
620
+ type: String,
621
+ default: '',
622
+ };
623
+ vueProps.modelValue = {
624
+ type: [String, Number, Boolean, Array, Object, Date],
625
+ default: '',
626
+ };
627
+ }
628
+ }
629
+ });
630
+ }
631
+ return behaviors;
632
+ }
633
+ function applyOptions(componentOptions, vueOptions) {
634
+ componentOptions.data = initData();
635
+ componentOptions.behaviors = initBehaviors(vueOptions);
636
636
  }
637
637
 
638
- function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
639
- vueOptions = vueOptions.default || vueOptions;
640
- const options = {
641
- multipleSlots: true,
642
- addGlobalClass: true,
643
- pureDataPattern: /^uP$/,
644
- };
645
- if (isArray(vueOptions.mixins)) {
646
- vueOptions.mixins.forEach((item) => {
647
- if (isObject(item.options)) {
648
- extend(options, item.options);
649
- }
650
- });
651
- }
652
- if (vueOptions.options) {
653
- extend(options, vueOptions.options);
654
- }
655
- const mpComponentOptions = {
656
- options,
657
- lifetimes: initLifetimes({ mocks, isPage, initRelation, vueOptions }),
658
- pageLifetimes: {
659
- show() {
660
- if (__VUE_PROD_DEVTOOLS__) {
661
- devtoolsComponentAdded(this.$vm.$);
662
- }
663
- this.$vm && this.$vm.$callHook('onPageShow');
664
- },
665
- hide() {
666
- this.$vm && this.$vm.$callHook('onPageHide');
667
- },
668
- resize(size) {
669
- this.$vm && this.$vm.$callHook('onPageResize', size);
670
- },
671
- },
672
- methods: {
673
- __l: handleLink,
674
- },
675
- };
676
- if (__VUE_OPTIONS_API__) {
677
- applyOptions(mpComponentOptions, vueOptions);
678
- }
679
- initProps(mpComponentOptions);
680
- initPropsObserver(mpComponentOptions);
681
- initExtraOptions(mpComponentOptions, vueOptions);
682
- initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
683
- if (parse) {
684
- parse(mpComponentOptions, { handleLink });
685
- }
686
- return mpComponentOptions;
687
- }
688
- function initCreateComponent(parseOptions) {
689
- return function createComponent(vueComponentOptions) {
690
- return Component(parseComponent(vueComponentOptions, parseOptions));
691
- };
692
- }
693
- let $createComponentFn;
694
- let $destroyComponentFn;
695
- function getAppVm() {
696
- if (process.env.UNI_MP_PLUGIN) {
697
- return tt.$vm;
698
- }
699
- if (process.env.UNI_SUBPACKAGE) {
700
- return tt.$subpackages[process.env.UNI_SUBPACKAGE].$vm;
701
- }
702
- return getApp().$vm;
703
- }
704
- function $createComponent(initialVNode, options) {
705
- if (!$createComponentFn) {
706
- $createComponentFn = getAppVm().$createComponent;
707
- }
708
- const proxy = $createComponentFn(initialVNode, options);
709
- return getExposeProxy(proxy.$) || proxy;
710
- }
711
- function $destroyComponent(instance) {
712
- if (!$destroyComponentFn) {
713
- $destroyComponentFn = getAppVm().$destroyComponent;
714
- }
715
- return $destroyComponentFn(instance);
638
+ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
639
+ vueOptions = vueOptions.default || vueOptions;
640
+ const options = {
641
+ multipleSlots: true,
642
+ // styleIsolation: 'apply-shared',
643
+ addGlobalClass: true,
644
+ pureDataPattern: /^uP$/,
645
+ };
646
+ if (isArray(vueOptions.mixins)) {
647
+ vueOptions.mixins.forEach((item) => {
648
+ if (isObject(item.options)) {
649
+ extend(options, item.options);
650
+ }
651
+ });
652
+ }
653
+ if (vueOptions.options) {
654
+ extend(options, vueOptions.options);
655
+ }
656
+ const mpComponentOptions = {
657
+ options,
658
+ lifetimes: initLifetimes({ mocks, isPage, initRelation, vueOptions }),
659
+ pageLifetimes: {
660
+ show() {
661
+ if (__VUE_PROD_DEVTOOLS__) {
662
+ devtoolsComponentAdded(this.$vm.$);
663
+ }
664
+ this.$vm && this.$vm.$callHook('onPageShow');
665
+ },
666
+ hide() {
667
+ this.$vm && this.$vm.$callHook('onPageHide');
668
+ },
669
+ resize(size) {
670
+ this.$vm && this.$vm.$callHook('onPageResize', size);
671
+ },
672
+ },
673
+ methods: {
674
+ __l: handleLink,
675
+ },
676
+ };
677
+ if (__VUE_OPTIONS_API__) {
678
+ applyOptions(mpComponentOptions, vueOptions);
679
+ }
680
+ initProps(mpComponentOptions);
681
+ initPropsObserver(mpComponentOptions);
682
+ initExtraOptions(mpComponentOptions, vueOptions);
683
+ initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
684
+ if (parse) {
685
+ parse(mpComponentOptions, { handleLink });
686
+ }
687
+ return mpComponentOptions;
688
+ }
689
+ function initCreateComponent(parseOptions) {
690
+ return function createComponent(vueComponentOptions) {
691
+ return Component(parseComponent(vueComponentOptions, parseOptions));
692
+ };
693
+ }
694
+ let $createComponentFn;
695
+ let $destroyComponentFn;
696
+ function getAppVm() {
697
+ if (process.env.UNI_MP_PLUGIN) {
698
+ return tt.$vm;
699
+ }
700
+ if (process.env.UNI_SUBPACKAGE) {
701
+ return tt.$subpackages[process.env.UNI_SUBPACKAGE].$vm;
702
+ }
703
+ return getApp().$vm;
704
+ }
705
+ function $createComponent(initialVNode, options) {
706
+ if (!$createComponentFn) {
707
+ $createComponentFn = getAppVm().$createComponent;
708
+ }
709
+ const proxy = $createComponentFn(initialVNode, options);
710
+ return getExposeProxy(proxy.$) || proxy;
711
+ }
712
+ function $destroyComponent(instance) {
713
+ if (!$destroyComponentFn) {
714
+ $destroyComponentFn = getAppVm().$destroyComponent;
715
+ }
716
+ return $destroyComponentFn(instance);
716
717
  }
717
718
 
718
- function parsePage(vueOptions, parseOptions) {
719
- const { parse, mocks, isPage, initRelation, handleLink, initLifetimes } = parseOptions;
720
- const miniProgramPageOptions = parseComponent(vueOptions, {
721
- mocks,
722
- isPage,
723
- initRelation,
724
- handleLink,
725
- initLifetimes,
726
- });
727
- initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
728
- const methods = miniProgramPageOptions.methods;
729
- methods.onLoad = function (query) {
730
- this.options = query;
731
- this.$page = {
732
- fullPath: addLeadingSlash(this.route + stringifyQuery(query)),
733
- };
734
- return this.$vm && this.$vm.$callHook(ON_LOAD, query);
735
- };
736
- initHooks(methods, PAGE_INIT_HOOKS);
737
- {
738
- initUnknownHooks(methods, vueOptions);
739
- }
740
- initRuntimeHooks(methods, vueOptions.__runtimeHooks);
741
- initMixinRuntimeHooks(methods);
742
- parse && parse(miniProgramPageOptions, { handleLink });
743
- return miniProgramPageOptions;
744
- }
745
- function initCreatePage(parseOptions) {
746
- return function createPage(vuePageOptions) {
747
- return Component(parsePage(vuePageOptions, parseOptions));
748
- };
719
+ function parsePage(vueOptions, parseOptions) {
720
+ const { parse, mocks, isPage, initRelation, handleLink, initLifetimes } = parseOptions;
721
+ const miniProgramPageOptions = parseComponent(vueOptions, {
722
+ mocks,
723
+ isPage,
724
+ initRelation,
725
+ handleLink,
726
+ initLifetimes,
727
+ });
728
+ initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
729
+ const methods = miniProgramPageOptions.methods;
730
+ methods.onLoad = function (query) {
731
+ this.options = query;
732
+ this.$page = {
733
+ fullPath: addLeadingSlash(this.route + stringifyQuery(query)),
734
+ };
735
+ return this.$vm && this.$vm.$callHook(ON_LOAD, query);
736
+ };
737
+ initHooks(methods, PAGE_INIT_HOOKS);
738
+ {
739
+ initUnknownHooks(methods, vueOptions);
740
+ }
741
+ initRuntimeHooks(methods, vueOptions.__runtimeHooks);
742
+ initMixinRuntimeHooks(methods);
743
+ parse && parse(miniProgramPageOptions, { handleLink });
744
+ return miniProgramPageOptions;
745
+ }
746
+ function initCreatePage(parseOptions) {
747
+ return function createPage(vuePageOptions) {
748
+ return Component(parsePage(vuePageOptions, parseOptions));
749
+ };
749
750
  }
750
751
 
751
- const MPPage = Page;
752
- const MPComponent = Component;
753
- function initTriggerEvent(mpInstance) {
754
- const oldTriggerEvent = mpInstance.triggerEvent;
755
- const newTriggerEvent = function (event, ...args) {
756
- return oldTriggerEvent.apply(mpInstance, [customizeEvent(event), ...args]);
757
- };
758
- // 京东小程序triggerEvent为只读属性
759
- try {
760
- mpInstance.triggerEvent = newTriggerEvent;
761
- }
762
- catch (error) {
763
- mpInstance._triggerEvent = newTriggerEvent;
764
- }
765
- }
766
- function initMiniProgramHook(name, options, isComponent) {
767
- if (isComponent) {
768
- // fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
769
- options = options.lifetimes || {};
770
- }
771
- const oldHook = options[name];
772
- if (!oldHook) {
773
- options[name] = function () {
774
- initTriggerEvent(this);
775
- };
776
- }
777
- else {
778
- options[name] = function (...args) {
779
- initTriggerEvent(this);
780
- return oldHook.apply(this, args);
781
- };
782
- }
783
- }
784
- Page = function (options) {
785
- initMiniProgramHook(ON_LOAD, options);
786
- return MPPage(options);
787
- };
788
- Component = function (options) {
789
- initMiniProgramHook('created', options, true);
790
- // 小程序组件
791
- const isVueComponent = options.properties && options.properties.uP;
792
- if (!isVueComponent) {
793
- initProps(options);
794
- initPropsObserver(options);
795
- }
796
- return MPComponent(options);
752
+ const MPPage = Page;
753
+ const MPComponent = Component;
754
+ function initTriggerEvent(mpInstance) {
755
+ const oldTriggerEvent = mpInstance.triggerEvent;
756
+ const newTriggerEvent = function (event, ...args) {
757
+ return oldTriggerEvent.apply(mpInstance, [customizeEvent(event), ...args]);
758
+ };
759
+ // 京东小程序triggerEvent为只读属性
760
+ try {
761
+ mpInstance.triggerEvent = newTriggerEvent;
762
+ }
763
+ catch (error) {
764
+ mpInstance._triggerEvent = newTriggerEvent;
765
+ }
766
+ }
767
+ function initMiniProgramHook(name, options, isComponent) {
768
+ if (isComponent) {
769
+ // fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
770
+ options = options.lifetimes || {};
771
+ }
772
+ const oldHook = options[name];
773
+ if (!oldHook) {
774
+ options[name] = function () {
775
+ initTriggerEvent(this);
776
+ };
777
+ }
778
+ else {
779
+ options[name] = function (...args) {
780
+ initTriggerEvent(this);
781
+ return oldHook.apply(this, args);
782
+ };
783
+ }
784
+ }
785
+ Page = function (options) {
786
+ initMiniProgramHook(ON_LOAD, options);
787
+ return MPPage(options);
788
+ };
789
+ Component = function (options) {
790
+ initMiniProgramHook('created', options, true);
791
+ // 小程序组件
792
+ const isVueComponent = options.properties && options.properties.uP;
793
+ if (!isVueComponent) {
794
+ initProps(options);
795
+ initPropsObserver(options);
796
+ }
797
+ return MPComponent(options);
797
798
  };
798
799
 
799
- function provide(instance, key, value) {
800
- if (!instance) {
801
- if ((process.env.NODE_ENV !== 'production')) {
802
- console.warn(`provide() can only be used inside setup().`);
803
- }
804
- }
805
- else {
806
- let provides = instance.provides;
807
- // by default an instance inherits its parent's provides object
808
- // but when it needs to provide values of its own, it creates its
809
- // own provides object using parent provides object as prototype.
810
- // this way in `inject` we can simply look up injections from direct
811
- // parent and let the prototype chain do the work.
812
- const parentProvides = instance.parent && instance.parent.provides;
813
- if (parentProvides === provides) {
814
- provides = instance.provides = Object.create(parentProvides);
815
- }
816
- // TS doesn't allow symbol as index type
817
- provides[key] = value;
818
- }
819
- }
820
- function initProvide(instance) {
821
- const provideOptions = instance.$options.provide;
822
- if (!provideOptions) {
823
- return;
824
- }
825
- const provides = isFunction(provideOptions)
826
- ? provideOptions.call(instance)
827
- : provideOptions;
828
- const internalInstance = instance.$;
829
- for (const key in provides) {
830
- provide(internalInstance, key, provides[key]);
831
- }
832
- }
833
- function inject(instance, key, defaultValue, treatDefaultAsFactory = false) {
834
- if (instance) {
835
- // #2400
836
- // to support `app.use` plugins,
837
- // fallback to appContext's `provides` if the intance is at root
838
- const provides = instance.parent == null
839
- ? instance.vnode.appContext && instance.vnode.appContext.provides
840
- : instance.parent.provides;
841
- if (provides && key in provides) {
842
- // TS doesn't allow symbol as index type
843
- return provides[key];
844
- }
845
- else if (arguments.length > 1) {
846
- return treatDefaultAsFactory && isFunction(defaultValue)
847
- ? defaultValue()
848
- : defaultValue;
849
- }
850
- else if ((process.env.NODE_ENV !== 'production')) {
851
- console.warn(`injection "${String(key)}" not found.`);
852
- }
853
- }
854
- else if ((process.env.NODE_ENV !== 'production')) {
855
- console.warn(`inject() can only be used inside setup() or functional components.`);
856
- }
857
- }
858
- function initInjections(instance) {
859
- const injectOptions = instance.$options.inject;
860
- if (!injectOptions) {
861
- return;
862
- }
863
- const internalInstance = instance.$;
864
- const ctx = internalInstance.ctx;
865
- if (isArray(injectOptions)) {
866
- for (let i = 0; i < injectOptions.length; i++) {
867
- const key = injectOptions[i];
868
- ctx[key] = inject(internalInstance, key);
869
- }
870
- }
871
- else {
872
- for (const key in injectOptions) {
873
- const opt = injectOptions[key];
874
- if (isObject(opt)) {
875
- ctx[key] = inject(internalInstance, opt.from || key, opt.default, true /* treat default function as factory */);
876
- }
877
- else {
878
- ctx[key] = inject(internalInstance, opt);
879
- }
880
- }
881
- }
800
+ function provide(instance, key, value) {
801
+ if (!instance) {
802
+ if ((process.env.NODE_ENV !== 'production')) {
803
+ console.warn(`provide() can only be used inside setup().`);
804
+ }
805
+ }
806
+ else {
807
+ let provides = instance.provides;
808
+ // by default an instance inherits its parent's provides object
809
+ // but when it needs to provide values of its own, it creates its
810
+ // own provides object using parent provides object as prototype.
811
+ // this way in `inject` we can simply look up injections from direct
812
+ // parent and let the prototype chain do the work.
813
+ const parentProvides = instance.parent && instance.parent.provides;
814
+ if (parentProvides === provides) {
815
+ provides = instance.provides = Object.create(parentProvides);
816
+ }
817
+ // TS doesn't allow symbol as index type
818
+ provides[key] = value;
819
+ }
820
+ }
821
+ function initProvide(instance) {
822
+ const provideOptions = instance.$options.provide;
823
+ if (!provideOptions) {
824
+ return;
825
+ }
826
+ const provides = isFunction(provideOptions)
827
+ ? provideOptions.call(instance)
828
+ : provideOptions;
829
+ const internalInstance = instance.$;
830
+ for (const key in provides) {
831
+ provide(internalInstance, key, provides[key]);
832
+ }
833
+ }
834
+ function inject(instance, key, defaultValue, treatDefaultAsFactory = false) {
835
+ if (instance) {
836
+ // #2400
837
+ // to support `app.use` plugins,
838
+ // fallback to appContext's `provides` if the intance is at root
839
+ const provides = instance.parent == null
840
+ ? instance.vnode.appContext && instance.vnode.appContext.provides
841
+ : instance.parent.provides;
842
+ if (provides && key in provides) {
843
+ // TS doesn't allow symbol as index type
844
+ return provides[key];
845
+ }
846
+ else if (arguments.length > 1) {
847
+ return treatDefaultAsFactory && isFunction(defaultValue)
848
+ ? defaultValue()
849
+ : defaultValue;
850
+ }
851
+ else if ((process.env.NODE_ENV !== 'production')) {
852
+ console.warn(`injection "${String(key)}" not found.`);
853
+ }
854
+ }
855
+ else if ((process.env.NODE_ENV !== 'production')) {
856
+ console.warn(`inject() can only be used inside setup() or functional components.`);
857
+ }
858
+ }
859
+ function initInjections(instance) {
860
+ const injectOptions = instance.$options.inject;
861
+ if (!injectOptions) {
862
+ return;
863
+ }
864
+ const internalInstance = instance.$;
865
+ const ctx = internalInstance.ctx;
866
+ if (isArray(injectOptions)) {
867
+ for (let i = 0; i < injectOptions.length; i++) {
868
+ const key = injectOptions[i];
869
+ ctx[key] = inject(internalInstance, key);
870
+ }
871
+ }
872
+ else {
873
+ for (const key in injectOptions) {
874
+ const opt = injectOptions[key];
875
+ if (isObject(opt)) {
876
+ ctx[key] = inject(internalInstance, opt.from || key, opt.default, true /* treat default function as factory */);
877
+ }
878
+ else {
879
+ ctx[key] = inject(internalInstance, opt);
880
+ }
881
+ }
882
+ }
882
883
  }
883
884
 
884
- // @ts-ignore
885
- // 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
886
- const components = [];
887
- function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
888
- function created() {
889
- components.push(this);
890
- }
891
- function attached() {
892
- initSetRef(this);
893
- const properties = this.properties;
894
- initVueIds(properties.uI, this);
895
- const relationOptions = {
896
- vuePid: this._$vuePid,
897
- };
898
- // 初始化 vue 实例
899
- const mpInstance = this;
900
- const mpType = isPage(mpInstance) ? 'page' : 'component';
901
- if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
902
- mpInstance.route = mpInstance.__route__;
903
- }
904
- const props = findPropsData(properties, mpType === 'page');
905
- this.$vm = $createComponent({
906
- type: vueOptions,
907
- props,
908
- }, {
909
- mpType,
910
- mpInstance,
911
- slots: properties.uS || {},
912
- parentComponent: relationOptions.parent && relationOptions.parent.$,
913
- onBeforeSetup(instance, options) {
914
- initRefs(instance, mpInstance);
915
- initMocks(instance, mpInstance, mocks);
916
- initComponentInstance(instance, options);
917
- },
918
- });
919
- if (mpType === 'component') {
920
- initFormField(this.$vm);
921
- }
922
- if (mpType === 'page') {
923
- if (__VUE_OPTIONS_API__) {
924
- initInjections(this.$vm);
925
- initProvide(this.$vm);
926
- }
927
- }
928
- // 处理父子关系
929
- initRelation(this, relationOptions);
930
- }
931
- function detached() {
932
- if (this.$vm) {
933
- pruneComponentPropsCache(this.$vm.$.uid);
934
- $destroyComponent(this.$vm);
935
- }
936
- }
937
- return {
938
- created,
939
- attached() {
940
- this.__lifetimes_attached = function () {
941
- attached.call(this);
942
- };
943
- let component = this;
944
- while (component &&
945
- component.__lifetimes_attached &&
946
- components[0] &&
947
- component === components[0]) {
948
- components.shift();
949
- component.__lifetimes_attached();
950
- delete component.__lifetimes_attached;
951
- component = components[0];
952
- }
953
- },
954
- detached,
955
- };
885
+ // @ts-ignore
886
+ // 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
887
+ const components = [];
888
+ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
889
+ function created() {
890
+ components.push(this);
891
+ }
892
+ function attached() {
893
+ initSetRef(this);
894
+ const properties = this.properties;
895
+ initVueIds(properties.uI, this);
896
+ const relationOptions = {
897
+ vuePid: this._$vuePid,
898
+ };
899
+ // 初始化 vue 实例
900
+ const mpInstance = this;
901
+ const mpType = isPage(mpInstance) ? 'page' : 'component';
902
+ if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
903
+ mpInstance.route = mpInstance.__route__;
904
+ }
905
+ const props = findPropsData(properties, mpType === 'page');
906
+ this.$vm = $createComponent({
907
+ type: vueOptions,
908
+ props,
909
+ }, {
910
+ mpType,
911
+ mpInstance,
912
+ slots: properties.uS || {},
913
+ parentComponent: relationOptions.parent && relationOptions.parent.$,
914
+ onBeforeSetup(instance, options) {
915
+ initRefs(instance, mpInstance);
916
+ initMocks(instance, mpInstance, mocks);
917
+ initComponentInstance(instance, options);
918
+ },
919
+ });
920
+ if (mpType === 'component') {
921
+ initFormField(this.$vm);
922
+ }
923
+ if (mpType === 'page') {
924
+ if (__VUE_OPTIONS_API__) {
925
+ initInjections(this.$vm);
926
+ initProvide(this.$vm);
927
+ }
928
+ }
929
+ // 处理父子关系
930
+ initRelation(this, relationOptions);
931
+ }
932
+ function detached() {
933
+ if (this.$vm) {
934
+ pruneComponentPropsCache(this.$vm.$.uid);
935
+ $destroyComponent(this.$vm);
936
+ }
937
+ }
938
+ return {
939
+ created,
940
+ attached() {
941
+ this.__lifetimes_attached = function () {
942
+ attached.call(this);
943
+ };
944
+ let component = this;
945
+ while (component &&
946
+ component.__lifetimes_attached &&
947
+ components[0] &&
948
+ component === components[0]) {
949
+ components.shift();
950
+ component.__lifetimes_attached();
951
+ delete component.__lifetimes_attached;
952
+ component = components[0];
953
+ }
954
+ },
955
+ detached,
956
+ };
956
957
  }
957
958
 
958
- const mocks = [
959
- '__route__',
960
- '__webviewId__',
961
- '__nodeId__',
962
- '__nodeid__' /* @Deprecated */,
963
- ];
964
- function isPage(mpInstance) {
965
- return (mpInstance.__nodeId__ === 0 || mpInstance.__nodeid__ === 0);
966
- }
967
- const instances = Object.create(null);
968
- function initRelation(mpInstance, detail) {
969
- // 头条 triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
970
- const nodeId = hasOwn(mpInstance, '__nodeId__')
971
- ? mpInstance.__nodeId__
972
- : mpInstance.__nodeid__;
973
- const webviewId = mpInstance.__webviewId__ + '';
974
- instances[webviewId + '_' + nodeId] = mpInstance.$vm;
975
- mpInstance.triggerEvent('__l', {
976
- vuePid: detail.vuePid,
977
- nodeId,
978
- webviewId,
979
- });
980
- }
981
- function handleLink({ detail: { vuePid, nodeId, webviewId }, }) {
982
- const vm = instances[webviewId + '_' + nodeId];
983
- if (!vm) {
984
- return;
985
- }
986
- let parentVm;
987
- if (vuePid) {
988
- parentVm = findVmByVueId(this.$vm, vuePid);
989
- }
990
- if (!parentVm) {
991
- parentVm = this.$vm;
992
- }
993
- vm.$.parent = parentVm.$;
994
- if (__VUE_OPTIONS_API__) {
995
- parentVm.$children.push(vm);
996
- const parent = parentVm.$;
997
- vm.$.provides = parent
998
- ? parent.provides
999
- : Object.create(parent.appContext.provides);
1000
- initInjections(vm);
1001
- initProvide(vm);
1002
- }
1003
- vm.$callCreatedHook();
1004
- // TODO 字节小程序父子组件关系建立的较晚,导致 inject 和 provide 初始化变慢
1005
- // 由此引发在 setup 中暂不可用,只能通过 options 方式配置
1006
- // 初始化完 inject 后,再次调用 update,触发一次更新
1007
- if (vm.$options.inject) {
1008
- vm.$.update();
1009
- }
1010
- nextSetDataTick(this, () => {
1011
- vm.$callHook('mounted');
1012
- vm.$callHook(ON_READY);
1013
- });
1014
- }
1015
- function parse(componentOptions, { handleLink }) {
1016
- componentOptions.methods.__l = handleLink;
959
+ const mocks = [
960
+ '__route__',
961
+ '__webviewId__',
962
+ '__nodeId__',
963
+ '__nodeid__' /* @Deprecated */,
964
+ ];
965
+ function isPage(mpInstance) {
966
+ return (mpInstance.__nodeId__ === 0 || mpInstance.__nodeid__ === 0);
967
+ }
968
+ const instances = Object.create(null);
969
+ function initRelation(mpInstance, detail) {
970
+ // 头条 triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
971
+ const nodeId = hasOwn(mpInstance, '__nodeId__')
972
+ ? mpInstance.__nodeId__
973
+ : mpInstance.__nodeid__;
974
+ const webviewId = mpInstance.__webviewId__ + '';
975
+ instances[webviewId + '_' + nodeId] = mpInstance.$vm;
976
+ mpInstance.triggerEvent('__l', {
977
+ vuePid: detail.vuePid,
978
+ nodeId,
979
+ webviewId,
980
+ });
981
+ }
982
+ function handleLink({ detail: { vuePid, nodeId, webviewId }, }) {
983
+ const vm = instances[webviewId + '_' + nodeId];
984
+ if (!vm) {
985
+ return;
986
+ }
987
+ let parentVm;
988
+ if (vuePid) {
989
+ parentVm = findVmByVueId(this.$vm, vuePid);
990
+ }
991
+ if (!parentVm) {
992
+ parentVm = this.$vm;
993
+ }
994
+ vm.$.parent = parentVm.$;
995
+ if (__VUE_OPTIONS_API__) {
996
+ parentVm.$children.push(vm);
997
+ const parent = parentVm.$;
998
+ vm.$.provides = parent
999
+ ? parent.provides
1000
+ : Object.create(parent.appContext.provides);
1001
+ initInjections(vm);
1002
+ initProvide(vm);
1003
+ }
1004
+ vm.$callCreatedHook();
1005
+ // TODO 字节小程序父子组件关系建立的较晚,导致 inject 和 provide 初始化变慢
1006
+ // 由此引发在 setup 中暂不可用,只能通过 options 方式配置
1007
+ // 初始化完 inject 后,再次调用 update,触发一次更新
1008
+ if (vm.$options.inject) {
1009
+ vm.$.update();
1010
+ }
1011
+ nextSetDataTick(this, () => {
1012
+ vm.$callHook('mounted');
1013
+ vm.$callHook(ON_READY);
1014
+ });
1015
+ }
1016
+ function parse(componentOptions, { handleLink }) {
1017
+ componentOptions.methods.__l = handleLink;
1017
1018
  }
1018
1019
 
1019
1020
  var parseComponentOptions = /*#__PURE__*/Object.freeze({
@@ -1027,35 +1028,35 @@ var parseComponentOptions = /*#__PURE__*/Object.freeze({
1027
1028
  parse: parse
1028
1029
  });
1029
1030
 
1030
- function initLifetimes(lifetimesOptions) {
1031
- return extend(initLifetimes$1(lifetimesOptions), {
1032
- ready() {
1033
- if (this.$vm && lifetimesOptions.isPage(this)) {
1034
- if (this.pageinstance) {
1035
- this.__webviewId__ = this.pageinstance.__pageId__;
1036
- }
1037
- this.$vm.$callCreatedHook();
1038
- nextSetDataTick(this, () => {
1039
- this.$vm.$callHook('mounted');
1040
- this.$vm.$callHook(ON_READY);
1041
- });
1042
- }
1043
- else {
1044
- this.is && console.warn(this.is + ' is not ready');
1045
- }
1046
- },
1047
- detached() {
1048
- this.$vm && $destroyComponent(this.$vm);
1049
- // 清理
1050
- const webviewId = this.__webviewId__;
1051
- webviewId &&
1052
- Object.keys(instances).forEach((key) => {
1053
- if (key.indexOf(webviewId + '_') === 0) {
1054
- delete instances[key];
1055
- }
1056
- });
1057
- },
1058
- });
1031
+ function initLifetimes(lifetimesOptions) {
1032
+ return extend(initLifetimes$1(lifetimesOptions), {
1033
+ ready() {
1034
+ if (this.$vm && lifetimesOptions.isPage(this)) {
1035
+ if (this.pageinstance) {
1036
+ this.__webviewId__ = this.pageinstance.__pageId__;
1037
+ }
1038
+ this.$vm.$callCreatedHook();
1039
+ nextSetDataTick(this, () => {
1040
+ this.$vm.$callHook('mounted');
1041
+ this.$vm.$callHook(ON_READY);
1042
+ });
1043
+ }
1044
+ else {
1045
+ this.is && console.warn(this.is + ' is not ready');
1046
+ }
1047
+ },
1048
+ detached() {
1049
+ this.$vm && $destroyComponent(this.$vm);
1050
+ // 清理
1051
+ const webviewId = this.__webviewId__;
1052
+ webviewId &&
1053
+ Object.keys(instances).forEach((key) => {
1054
+ if (key.indexOf(webviewId + '_') === 0) {
1055
+ delete instances[key];
1056
+ }
1057
+ });
1058
+ },
1059
+ });
1059
1060
  }
1060
1061
 
1061
1062
  var parsePageOptions = /*#__PURE__*/Object.freeze({
@@ -1068,15 +1069,15 @@ var parsePageOptions = /*#__PURE__*/Object.freeze({
1068
1069
  parse: parse
1069
1070
  });
1070
1071
 
1071
- const createApp = initCreateApp();
1072
- const createPage = initCreatePage(parsePageOptions);
1073
- const createComponent = initCreateComponent(parseComponentOptions);
1074
- const createSubpackageApp = initCreateSubpackageApp();
1075
- tt.EventChannel = EventChannel;
1076
- tt.createApp = global.createApp = createApp;
1077
- tt.createPage = createPage;
1078
- tt.createComponent = createComponent;
1079
- tt.createSubpackageApp = global.createSubpackageApp =
1072
+ const createApp = initCreateApp();
1073
+ const createPage = initCreatePage(parsePageOptions);
1074
+ const createComponent = initCreateComponent(parseComponentOptions);
1075
+ const createSubpackageApp = initCreateSubpackageApp();
1076
+ tt.EventChannel = EventChannel;
1077
+ tt.createApp = global.createApp = createApp;
1078
+ tt.createPage = createPage;
1079
+ tt.createComponent = createComponent;
1080
+ tt.createSubpackageApp = global.createSubpackageApp =
1080
1081
  createSubpackageApp;
1081
1082
 
1082
1083
  export { createApp, createComponent, createPage, createSubpackageApp };