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