@dcloudio/uni-quickapp-webview 3.0.0-alpha-3021020211012005 → 3.0.0-alpha-3021220211102002

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.
@@ -289,13 +289,13 @@ function invokeApi(method, api, options, ...params) {
289
289
  }
290
290
 
291
291
  function handlePromise(promise) {
292
- if (__UNI_FEATURE_PROMISE__) {
293
- return promise
294
- .then((data) => {
295
- return [null, data];
296
- })
297
- .catch((err) => [err]);
298
- }
292
+ // if (__UNI_FEATURE_PROMISE__) {
293
+ // return promise
294
+ // .then((data) => {
295
+ // return [null, data]
296
+ // })
297
+ // .catch((err) => [err])
298
+ // }
299
299
  return promise;
300
300
  }
301
301
 
@@ -1,4 +1,4 @@
1
- import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared';
1
+ import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared';
2
2
  import { injectHook, ref } from 'vue';
3
3
 
4
4
  const encode = encodeURIComponent;
@@ -20,14 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) {
20
20
  : null;
21
21
  return res ? `?${res}` : '';
22
22
  }
23
-
24
- function cache(fn) {
25
- const cache = Object.create(null);
26
- return (str) => {
27
- const hit = cache[str];
28
- return hit || (cache[str] = fn(str));
29
- };
30
- }
31
23
  const invokeArrayFns = (fns, arg) => {
32
24
  let ret;
33
25
  for (let i = 0; i < fns.length; i++) {
@@ -129,229 +121,6 @@ function getEventChannel(id) {
129
121
  return eventChannelStack.shift();
130
122
  }
131
123
 
132
- function initBehavior(options) {
133
- return Behavior(options);
134
- }
135
- function initVueIds(vueIds, mpInstance) {
136
- if (!vueIds) {
137
- return;
138
- }
139
- const ids = vueIds.split(',');
140
- const len = ids.length;
141
- if (len === 1) {
142
- mpInstance._$vueId = ids[0];
143
- }
144
- else if (len === 2) {
145
- mpInstance._$vueId = ids[0];
146
- mpInstance._$vuePid = ids[1];
147
- }
148
- }
149
- const EXTRAS = ['externalClasses'];
150
- function initExtraOptions(miniProgramComponentOptions, vueOptions) {
151
- EXTRAS.forEach((name) => {
152
- if (hasOwn(vueOptions, name)) {
153
- miniProgramComponentOptions[name] = vueOptions[name];
154
- }
155
- });
156
- }
157
- function initWxsCallMethods(methods, wxsCallMethods) {
158
- if (!isArray(wxsCallMethods)) {
159
- return;
160
- }
161
- wxsCallMethods.forEach((callMethod) => {
162
- methods[callMethod] = function (args) {
163
- return this.$vm[callMethod](args);
164
- };
165
- });
166
- }
167
- function selectAllComponents(mpInstance, selector, $refs) {
168
- const components = mpInstance.selectAllComponents(selector);
169
- components.forEach((component) => {
170
- const ref = component.dataset.ref;
171
- $refs[ref] = component.$vm || component;
172
- });
173
- }
174
- function initRefs(instance, mpInstance) {
175
- Object.defineProperty(instance, 'refs', {
176
- get() {
177
- const $refs = {};
178
- selectAllComponents(mpInstance, '.vue-ref', $refs);
179
- const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
180
- forComponents.forEach((component) => {
181
- const ref = component.dataset.ref;
182
- if (!$refs[ref]) {
183
- $refs[ref] = [];
184
- }
185
- $refs[ref].push(component.$vm || component);
186
- });
187
- return $refs;
188
- },
189
- });
190
- }
191
- function getTarget(obj, path) {
192
- const parts = path.split('.');
193
- let key = parts[0];
194
- if (key.indexOf('__$n') === 0) {
195
- //number index
196
- key = parseInt(key.replace('__$n', ''));
197
- }
198
- if (!obj) {
199
- obj = {};
200
- }
201
- if (parts.length === 1) {
202
- return obj[key];
203
- }
204
- return getTarget(obj[key], parts.slice(1).join('.'));
205
- }
206
-
207
- function getValue(dataPath, target) {
208
- return getTarget(target || this, dataPath);
209
- }
210
- function getClass(dynamicClass, staticClass) {
211
- return renderClass(staticClass, dynamicClass);
212
- }
213
- function getStyle(dynamicStyle, staticStyle) {
214
- if (!dynamicStyle && !staticStyle) {
215
- return '';
216
- }
217
- var dynamicStyleObj = normalizeStyleBinding(dynamicStyle);
218
- var styleObj = staticStyle
219
- ? extend(staticStyle, dynamicStyleObj)
220
- : dynamicStyleObj;
221
- return Object.keys(styleObj)
222
- .map(function (name) {
223
- return hyphenate(name) + ':' + styleObj[name];
224
- })
225
- .join(';');
226
- }
227
- function toObject(arr) {
228
- var res = {};
229
- for (var i = 0; i < arr.length; i++) {
230
- if (arr[i]) {
231
- extend(res, arr[i]);
232
- }
233
- }
234
- return res;
235
- }
236
- function normalizeStyleBinding(bindingStyle) {
237
- if (Array.isArray(bindingStyle)) {
238
- return toObject(bindingStyle);
239
- }
240
- if (typeof bindingStyle === 'string') {
241
- return parseStyleText(bindingStyle);
242
- }
243
- return bindingStyle;
244
- }
245
- var parseStyleText = cache(function parseStyleText(cssText) {
246
- var res = {};
247
- var listDelimiter = /;(?![^(]*\))/g;
248
- var propertyDelimiter = /:(.+)/;
249
- cssText.split(listDelimiter).forEach(function (item) {
250
- if (item) {
251
- var tmp = item.split(propertyDelimiter);
252
- tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
253
- }
254
- });
255
- return res;
256
- });
257
- function isDef(v) {
258
- return v !== undefined && v !== null;
259
- }
260
- function renderClass(staticClass, dynamicClass) {
261
- if (isDef(staticClass) || isDef(dynamicClass)) {
262
- return concat(staticClass, stringifyClass(dynamicClass));
263
- }
264
- /* istanbul ignore next */
265
- return '';
266
- }
267
- function concat(a, b) {
268
- return a ? (b ? a + ' ' + b : a) : b || '';
269
- }
270
- function stringifyClass(value) {
271
- if (Array.isArray(value)) {
272
- return stringifyArray(value);
273
- }
274
- if (isObject(value)) {
275
- return stringifyObject(value);
276
- }
277
- if (typeof value === 'string') {
278
- return value;
279
- }
280
- /* istanbul ignore next */
281
- return '';
282
- }
283
- function stringifyArray(value) {
284
- var res = '';
285
- var stringified;
286
- for (var i = 0, l = value.length; i < l; i++) {
287
- if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') {
288
- if (res) {
289
- res += ' ';
290
- }
291
- res += stringified;
292
- }
293
- }
294
- return res;
295
- }
296
- function stringifyObject(value) {
297
- var res = '';
298
- for (var key in value) {
299
- if (value[key]) {
300
- if (res) {
301
- res += ' ';
302
- }
303
- res += key;
304
- }
305
- }
306
- return res;
307
- }
308
-
309
- function setModel(target, key, value, modifiers) {
310
- if (isArray(modifiers)) {
311
- if (modifiers.indexOf('trim') !== -1) {
312
- value = value.trim();
313
- }
314
- if (modifiers.indexOf('number') !== -1) {
315
- value = toNumber(value);
316
- }
317
- }
318
- if (!target) {
319
- target = this;
320
- }
321
- target[key] = value;
322
- }
323
- function setSync(target, key, value) {
324
- if (!target) {
325
- target = this;
326
- }
327
- target[key] = value;
328
- }
329
- function getOrig(data) {
330
- if (isPlainObject(data)) {
331
- return data.$orig || data;
332
- }
333
- return data;
334
- }
335
- function map(val, iteratee) {
336
- let ret, i, l, keys, key;
337
- if (isArray(val)) {
338
- ret = new Array(val.length);
339
- for (i = 0, l = val.length; i < l; i++) {
340
- ret[i] = iteratee(val[i], i);
341
- }
342
- return ret;
343
- }
344
- else if (isObject(val)) {
345
- keys = Object.keys(val);
346
- ret = Object.create(null);
347
- for (i = 0, l = keys.length; i < l; i++) {
348
- key = keys[i];
349
- ret[key] = iteratee(val[key], key, i);
350
- }
351
- return ret;
352
- }
353
- return [];
354
- }
355
124
  const MP_METHODS = [
356
125
  'createSelectorQuery',
357
126
  'createIntersectionObserver',
@@ -360,8 +129,10 @@ const MP_METHODS = [
360
129
  ];
361
130
  function createEmitFn(oldEmit, ctx) {
362
131
  return function emit(event, ...args) {
363
- if (ctx.$scope && event) {
364
- ctx.$scope.triggerEvent(event, { __args__: args });
132
+ const scope = ctx.$scope;
133
+ if (scope && event) {
134
+ const detail = { __args__: args };
135
+ scope.triggerEvent(event, detail);
365
136
  }
366
137
  return oldEmit.apply(this, [event, ...args]);
367
138
  };
@@ -410,15 +181,6 @@ function initComponentInstance(instance, options) {
410
181
  }
411
182
  };
412
183
  });
413
- // TODO other
414
- ctx.__set_model = setModel;
415
- ctx.__set_sync = setSync;
416
- ctx.__get_orig = getOrig;
417
- // TODO
418
- ctx.__get_value = getValue;
419
- ctx.__get_class = getClass;
420
- ctx.__get_style = getStyle;
421
- ctx.__map = map;
422
184
  }
423
185
  function initMocks(instance, mpInstance, mocks) {
424
186
  const ctx = instance.ctx;
@@ -564,6 +326,66 @@ function initLocale(appVm) {
564
326
  });
565
327
  }
566
328
 
329
+ function initBehavior(options) {
330
+ return Behavior(options);
331
+ }
332
+ function initVueIds(vueIds, mpInstance) {
333
+ if (!vueIds) {
334
+ return;
335
+ }
336
+ const ids = vueIds.split(',');
337
+ const len = ids.length;
338
+ if (len === 1) {
339
+ mpInstance._$vueId = ids[0];
340
+ }
341
+ else if (len === 2) {
342
+ mpInstance._$vueId = ids[0];
343
+ mpInstance._$vuePid = ids[1];
344
+ }
345
+ }
346
+ const EXTRAS = ['externalClasses'];
347
+ function initExtraOptions(miniProgramComponentOptions, vueOptions) {
348
+ EXTRAS.forEach((name) => {
349
+ if (hasOwn(vueOptions, name)) {
350
+ miniProgramComponentOptions[name] = vueOptions[name];
351
+ }
352
+ });
353
+ }
354
+ function initWxsCallMethods(methods, wxsCallMethods) {
355
+ if (!isArray(wxsCallMethods)) {
356
+ return;
357
+ }
358
+ wxsCallMethods.forEach((callMethod) => {
359
+ methods[callMethod] = function (args) {
360
+ return this.$vm[callMethod](args);
361
+ };
362
+ });
363
+ }
364
+ function selectAllComponents(mpInstance, selector, $refs) {
365
+ const components = mpInstance.selectAllComponents(selector);
366
+ components.forEach((component) => {
367
+ const ref = component.dataset.r;
368
+ $refs[ref] = component.$vm || component;
369
+ });
370
+ }
371
+ function initRefs(instance, mpInstance) {
372
+ Object.defineProperty(instance, 'refs', {
373
+ get() {
374
+ const $refs = {};
375
+ selectAllComponents(mpInstance, '.r', $refs);
376
+ const forComponents = mpInstance.selectAllComponents('.r-i-f');
377
+ forComponents.forEach((component) => {
378
+ const ref = component.dataset.r;
379
+ if (!$refs[ref]) {
380
+ $refs[ref] = [];
381
+ }
382
+ $refs[ref].push(component.$vm || component);
383
+ });
384
+ return $refs;
385
+ },
386
+ });
387
+ }
388
+
567
389
  const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
568
390
  function createObserver(name) {
569
391
  return function observer(newVal) {
@@ -572,22 +394,26 @@ function createObserver(name) {
572
394
  }
573
395
  };
574
396
  }
575
- function parsePropType(key, type, defaultValue) {
397
+ function parsePropType(type, defaultValue) {
576
398
  // [String]=>String
577
399
  if (isArray(type) && type.length === 1) {
578
400
  return type[0];
579
401
  }
580
402
  return type;
581
403
  }
404
+ function normalizePropType(type, defaultValue) {
405
+ const res = parsePropType(type);
406
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
407
+ }
582
408
  function initDefaultProps(isBehavior = false) {
583
409
  const properties = {};
584
410
  if (!isBehavior) {
585
- properties.vueId = {
586
- type: String,
411
+ properties.vI = {
412
+ type: null,
587
413
  value: '',
588
414
  };
589
415
  // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
590
- properties.vueSlots = {
416
+ properties.vS = {
591
417
  type: null,
592
418
  value: [],
593
419
  observer: function (newVal) {
@@ -607,6 +433,12 @@ function createProperty(key, prop) {
607
433
  prop.observer = createObserver(key);
608
434
  return prop;
609
435
  }
436
+ /**
437
+ *
438
+ * @param mpComponentOptions
439
+ * @param rawProps
440
+ * @param isBehavior
441
+ */
610
442
  function initProps(mpComponentOptions, rawProps, isBehavior = false) {
611
443
  const properties = initDefaultProps(isBehavior);
612
444
  if (isArray(rawProps)) {
@@ -626,17 +458,16 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
626
458
  value = value();
627
459
  }
628
460
  const type = opts.type;
629
- opts.type = parsePropType(key, type);
461
+ opts.type = normalizePropType(type);
630
462
  properties[key] = createProperty(key, {
631
- type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
463
+ type: opts.type,
632
464
  value,
633
465
  });
634
466
  }
635
467
  else {
636
468
  // content:String
637
- const type = parsePropType(key, opts);
638
469
  properties[key] = createProperty(key, {
639
- type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
470
+ type: normalizePropType(opts),
640
471
  });
641
472
  }
642
473
  });
@@ -720,252 +551,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
720
551
  componentOptions.behaviors = initBehaviors(vueOptions, initBehavior);
721
552
  }
722
553
 
723
- function getExtraValue(instance, dataPathsArray) {
724
- let context = instance;
725
- dataPathsArray.forEach((dataPathArray) => {
726
- const dataPath = dataPathArray[0];
727
- const value = dataPathArray[2];
728
- if (dataPath || typeof value !== 'undefined') {
729
- // ['','',index,'disable']
730
- const propPath = dataPathArray[1];
731
- const valuePath = dataPathArray[3];
732
- let vFor;
733
- if (Number.isInteger(dataPath)) {
734
- vFor = dataPath;
735
- }
736
- else if (!dataPath) {
737
- vFor = context;
738
- }
739
- else if (typeof dataPath === 'string' && dataPath) {
740
- if (dataPath.indexOf('#s#') === 0) {
741
- vFor = dataPath.substr(3);
742
- }
743
- else {
744
- vFor = getTarget(context, dataPath);
745
- }
746
- }
747
- if (Number.isInteger(vFor)) {
748
- context = value;
749
- }
750
- else if (!propPath) {
751
- context = vFor[value];
752
- }
753
- else {
754
- if (isArray(vFor)) {
755
- context = vFor.find((vForItem) => {
756
- return getTarget(vForItem, propPath) === value;
757
- });
758
- }
759
- else if (isPlainObject(vFor)) {
760
- context = Object.keys(vFor).find((vForKey) => {
761
- return getTarget(vFor[vForKey], propPath) === value;
762
- });
763
- }
764
- else {
765
- console.error('v-for 暂不支持循环数据:', vFor);
766
- }
767
- }
768
- if (valuePath) {
769
- context = getTarget(context, valuePath);
770
- }
771
- }
772
- });
773
- return context;
774
- }
775
- function processEventExtra(instance, extra, event) {
776
- const extraObj = {};
777
- if (isArray(extra) && extra.length) {
778
- /**
779
- *[
780
- * ['data.items', 'data.id', item.data.id],
781
- * ['metas', 'id', meta.id]
782
- *],
783
- *[
784
- * ['data.items', 'data.id', item.data.id],
785
- * ['metas', 'id', meta.id]
786
- *],
787
- *'test'
788
- */
789
- extra.forEach((dataPath, index) => {
790
- if (typeof dataPath === 'string') {
791
- if (!dataPath) {
792
- // model,prop.sync
793
- extraObj['$' + index] = instance;
794
- }
795
- else {
796
- if (dataPath === '$event') {
797
- // $event
798
- extraObj['$' + index] = event;
799
- }
800
- else if (dataPath === 'arguments') {
801
- if (event.detail && event.detail.__args__) {
802
- extraObj['$' + index] = event.detail.__args__;
803
- }
804
- else {
805
- extraObj['$' + index] = [event];
806
- }
807
- }
808
- else if (dataPath.indexOf('$event.') === 0) {
809
- // $event.target.value
810
- extraObj['$' + index] = getTarget(event, dataPath.replace('$event.', ''));
811
- }
812
- else {
813
- extraObj['$' + index] = getTarget(instance, dataPath);
814
- }
815
- }
816
- }
817
- else {
818
- extraObj['$' + index] = getExtraValue(instance, dataPath);
819
- }
820
- });
821
- }
822
- return extraObj;
823
- }
824
- function getObjByArray(arr) {
825
- const obj = {};
826
- for (let i = 1; i < arr.length; i++) {
827
- const element = arr[i];
828
- obj[element[0]] = element[1];
829
- }
830
- return obj;
831
- }
832
- function processEventArgs(instance, event, args = [], extra = [], isCustom, methodName) {
833
- let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
834
- if (isCustom) {
835
- // 自定义事件
836
- isCustomMPEvent =
837
- event.currentTarget &&
838
- event.currentTarget.dataset &&
839
- event.currentTarget.dataset.comType === 'wx';
840
- if (!args.length) {
841
- // 无参数,直接传入 event 或 detail 数组
842
- if (isCustomMPEvent) {
843
- return [event];
844
- }
845
- return event.detail.__args__ || event.detail;
846
- }
847
- }
848
- const extraObj = processEventExtra(instance, extra, event);
849
- const ret = [];
850
- args.forEach((arg) => {
851
- if (arg === '$event') {
852
- if (methodName === '__set_model' && !isCustom) {
853
- // input v-model value
854
- ret.push(event.target.value);
855
- }
856
- else {
857
- if (isCustom && !isCustomMPEvent) {
858
- ret.push(event.detail.__args__[0]);
859
- }
860
- else {
861
- // wxcomponent 组件或内置组件
862
- ret.push(event);
863
- }
864
- }
865
- }
866
- else {
867
- if (isArray(arg) && arg[0] === 'o') {
868
- ret.push(getObjByArray(arg));
869
- }
870
- else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
871
- ret.push(extraObj[arg]);
872
- }
873
- else {
874
- ret.push(arg);
875
- }
876
- }
877
- });
878
- return ret;
879
- }
880
- function wrapper(event) {
881
- event.stopPropagation = NOOP;
882
- event.preventDefault = NOOP;
883
- event.target = event.target || {};
884
- if (!hasOwn(event, 'detail')) {
885
- event.detail = {};
886
- }
887
- if (hasOwn(event, 'markerId')) {
888
- event.detail = typeof event.detail === 'object' ? event.detail : {};
889
- event.detail.markerId = event.markerId;
890
- }
891
- if (isPlainObject(event.detail)) {
892
- event.target = extend({}, event.target, event.detail);
893
- }
894
- return event;
895
- }
896
- const ONCE = '~';
897
- const CUSTOM = '^';
898
- function matchEventType(eventType, optType) {
899
- return (eventType === optType ||
900
- (optType === 'regionchange' &&
901
- (eventType === 'begin' || eventType === 'end')));
902
- }
903
- function handleEvent(event) {
904
- event = wrapper(event);
905
- // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
906
- const dataset = (event.currentTarget || event.target).dataset;
907
- if (!dataset) {
908
- return console.warn('事件信息不存在');
909
- }
910
- const eventOpts = (dataset.eventOpts ||
911
- dataset['event-opts']); // 支付宝 web-view 组件 dataset 非驼峰
912
- if (!eventOpts) {
913
- return console.warn('事件信息不存在');
914
- }
915
- // [['handle',[1,2,a]],['handle1',[1,2,a]]]
916
- const eventType = event.type;
917
- const ret = [];
918
- eventOpts.forEach((eventOpt) => {
919
- let type = eventOpt[0];
920
- const eventsArray = eventOpt[1];
921
- const isCustom = type.charAt(0) === CUSTOM;
922
- type = isCustom ? type.slice(1) : type;
923
- const isOnce = type.charAt(0) === ONCE;
924
- type = isOnce ? type.slice(1) : type;
925
- if (eventsArray && matchEventType(eventType, type)) {
926
- eventsArray.forEach((eventArray) => {
927
- const methodName = eventArray[0];
928
- if (methodName) {
929
- let handlerCtx = this.$vm;
930
- if (handlerCtx.$options.generic &&
931
- handlerCtx.$parent &&
932
- handlerCtx.$parent.$parent) {
933
- // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
934
- handlerCtx = handlerCtx.$parent.$parent;
935
- }
936
- if (methodName === '$emit') {
937
- handlerCtx.$emit.apply(handlerCtx, processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName));
938
- return;
939
- }
940
- const handler = handlerCtx[methodName];
941
- if (!isFunction(handler)) {
942
- throw new Error(` _vm.${methodName} is not a function`);
943
- }
944
- if (isOnce) {
945
- if (handler.once) {
946
- return;
947
- }
948
- handler.once = true;
949
- }
950
- let params = processEventArgs(this.$vm, event, eventArray[1], eventArray[2], isCustom, methodName);
951
- params = Array.isArray(params) ? params : [];
952
- // 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
953
- if (/=\s*\S+\.eventParams\s*\|\|\s*\S+\[['"]event-params['"]\]/.test(handler.toString())) {
954
- // eslint-disable-next-line no-sparse-arrays
955
- params = params.concat([, , , , , , , , , , event]);
956
- }
957
- ret.push(handler.apply(handlerCtx, params));
958
- }
959
- });
960
- }
961
- });
962
- if (eventType === 'input' &&
963
- ret.length === 1 &&
964
- typeof ret[0] !== 'undefined') {
965
- return ret[0];
966
- }
967
- }
968
-
969
554
  function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
970
555
  vueOptions = vueOptions.default || vueOptions;
971
556
  const options = {
@@ -991,7 +576,6 @@ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handle
991
576
  },
992
577
  methods: {
993
578
  __l: handleLink,
994
- __e: handleEvent,
995
579
  },
996
580
  };
997
581
  if (__VUE_OPTIONS_API__) {
@@ -1065,7 +649,7 @@ function initTriggerEvent(mpInstance) {
1065
649
  return oldTriggerEvent.apply(mpInstance, [customize(event), ...args]);
1066
650
  };
1067
651
  }
1068
- function initHook(name, options) {
652
+ function initHook(name, options, isComponent) {
1069
653
  const oldHook = options[name];
1070
654
  if (!oldHook) {
1071
655
  options[name] = function () {
@@ -1173,36 +757,65 @@ function initInjections(instance) {
1173
757
  }
1174
758
  }
1175
759
 
760
+ // 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
761
+ const components = [];
1176
762
  function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
1177
763
  return {
764
+ created() {
765
+ components.push(this);
766
+ },
1178
767
  attached() {
1179
- const properties = this.properties;
1180
- initVueIds(properties.vueId, this);
1181
- const relationOptions = {
1182
- vuePid: this._$vuePid,
768
+ this.__lifetimes_attached = function () {
769
+ const properties = this.properties;
770
+ initVueIds(properties.vI, this);
771
+ const relationOptions = {
772
+ vuePid: this._$vuePid,
773
+ };
774
+ // 初始化 vue 实例
775
+ const mpInstance = this;
776
+ const mpType = isPage(mpInstance) ? 'page' : 'component';
777
+ if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
778
+ mpInstance.route = mpInstance.__route__;
779
+ }
780
+ // 字节跳动小程序 properties
781
+ // 父组件在 attached 中 setData 设置了子组件的 props,在子组件的 attached 中,并不能立刻拿到
782
+ // 此时子组件的 properties 中获取到的值,除了一部分初始化就有的值,只要在模板上绑定了,动态设置的 prop 的值均会根据类型返回,不会应用 prop 自己的默认值
783
+ // 举例: easyinput 的 styles 属性,类型为 Object,`<easyinput :styles="styles"/>` 在 attached 中 styles 的值为 null
784
+ // 目前 null 值会影响 render 函数执行,临时解决方案,调整 properties 中的 null 值为 undefined,让 Vue 来补充为默认值
785
+ // 已知的其他隐患,当使用默认值时,可能组件行为不正确,比如 countdown 组件,默认值是0,导致直接就触发了 timeup 事件,这个应该是组件自身做处理?
786
+ // 难道要等父组件首次 setData 完成后,再去执行子组件的初始化?
787
+ Object.keys(properties).forEach((name) => {
788
+ if (properties[name] === null) {
789
+ properties[name] = undefined;
790
+ }
791
+ });
792
+ this.$vm = $createComponent({
793
+ type: vueOptions,
794
+ props: properties,
795
+ }, {
796
+ mpType,
797
+ mpInstance,
798
+ slots: properties.vS,
799
+ parentComponent: relationOptions.parent && relationOptions.parent.$,
800
+ onBeforeSetup(instance, options) {
801
+ initRefs(instance, mpInstance);
802
+ initMocks(instance, mpInstance, mocks);
803
+ initComponentInstance(instance, options);
804
+ },
805
+ });
806
+ // 处理父子关系
807
+ initRelation(this, relationOptions);
1183
808
  };
1184
- // 初始化 vue 实例
1185
- const mpInstance = this;
1186
- const mpType = isPage(mpInstance) ? 'page' : 'component';
1187
- if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
1188
- mpInstance.route = mpInstance.__route__;
809
+ let component = this;
810
+ while (component &&
811
+ component.__lifetimes_attached &&
812
+ components[0] &&
813
+ component === components[0]) {
814
+ components.shift();
815
+ component.__lifetimes_attached();
816
+ delete component.__lifetimes_attached;
817
+ component = components[0];
1189
818
  }
1190
- this.$vm = $createComponent({
1191
- type: vueOptions,
1192
- props: properties,
1193
- }, {
1194
- mpType,
1195
- mpInstance,
1196
- slots: properties.vueSlots,
1197
- parentComponent: relationOptions.parent && relationOptions.parent.$,
1198
- onBeforeSetup(instance, options) {
1199
- initRefs(instance, mpInstance);
1200
- initMocks(instance, mpInstance, mocks);
1201
- initComponentInstance(instance, options);
1202
- },
1203
- });
1204
- // 处理父子关系
1205
- initRelation(this, relationOptions);
1206
819
  },
1207
820
  detached() {
1208
821
  this.$vm && $destroyComponent(this.$vm);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-quickapp-webview",
3
- "version": "3.0.0-alpha-3021020211012005",
3
+ "version": "3.0.0-alpha-3021220211102002",
4
4
  "description": "uni-app quickapp-webview",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -16,5 +16,5 @@
16
16
  "name": "quickapp-webview",
17
17
  "title": "快应用(Webview)版"
18
18
  },
19
- "gitHead": "b68ad612a4426795673cd892f5f4a6af6bf16f20"
19
+ "gitHead": "370c4aaa417d694ecff57064e2427c18790e85cd"
20
20
  }