@dcloudio/uni-mp-toutiao 3.0.0-alpha-4030620241126001 → 3.0.0-alpha-4040120241206001

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/LICENSE CHANGED
File without changes
@@ -1,6 +1,7 @@
1
1
  import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend, remove } from '@vue/shared';
2
2
  import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
3
- import { Emitter, onCreateVueApp, invokeCreateVueAppHook } from '@dcloudio/uni-shared';
3
+ import { injectHook } from 'vue';
4
+ import { Emitter, ON_ERROR, onCreateVueApp, invokeCreateVueAppHook } from '@dcloudio/uni-shared';
4
5
 
5
6
  function getBaseSystemInfo() {
6
7
  return tt.getSystemInfoSync();
@@ -449,7 +450,7 @@ let isIOS = false;
449
450
  let deviceWidth = 0;
450
451
  let deviceDPR = 0;
451
452
  function checkDeviceWidth() {
452
- const { platform, pixelRatio, windowWidth } = getBaseSystemInfo();
453
+ const { windowWidth, pixelRatio, platform } = getBaseSystemInfo();
453
454
  deviceWidth = windowWidth;
454
455
  deviceDPR = pixelRatio;
455
456
  isIOS = platform === 'ios';
@@ -479,6 +480,13 @@ const upx2px = defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
479
480
  return number < 0 ? -result : result;
480
481
  }, Upx2pxProtocol);
481
482
 
483
+ function __f__(type, filename, ...args) {
484
+ if (filename) {
485
+ args.push(filename);
486
+ }
487
+ console[type].apply(console, args);
488
+ }
489
+
482
490
  const API_ADD_INTERCEPTOR = 'addInterceptor';
483
491
  const API_REMOVE_INTERCEPTOR = 'removeInterceptor';
484
492
  const AddInterceptorProtocol = [
@@ -719,10 +727,11 @@ const offPushMessage = (fn) => {
719
727
  }
720
728
  };
721
729
 
722
- const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
730
+ const SYNC_API_RE = /^\$|__f__|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|rpx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
723
731
  const CONTEXT_API_RE = /^create|Manager$/;
724
732
  // Context例外情况
725
733
  const CONTEXT_API_RE_EXC = ['createBLEConnection'];
734
+ const TASK_APIS = ['request', 'downloadFile', 'uploadFile', 'connectSocket'];
726
735
  // 同步例外情况
727
736
  const ASYNC_API = ['createBLEConnection'];
728
737
  const CALLBACK_API_RE = /^on|^off/;
@@ -735,6 +744,9 @@ function isSyncApi(name) {
735
744
  function isCallbackApi(name) {
736
745
  return CALLBACK_API_RE.test(name) && name !== 'onPush';
737
746
  }
747
+ function isTaskApi(name) {
748
+ return TASK_APIS.indexOf(name) !== -1;
749
+ }
738
750
  function shouldPromise(name) {
739
751
  if (isContextApi(name) || isSyncApi(name) || isCallbackApi(name)) {
740
752
  return false;
@@ -820,6 +832,9 @@ function initWrapper(protocols) {
820
832
  return toArgs;
821
833
  }
822
834
  else if (isFunction(fromArgs)) {
835
+ if (isFunction(argsOption)) {
836
+ argsOption(fromArgs, {});
837
+ }
823
838
  fromArgs = processCallback(methodName, fromArgs, returnValue);
824
839
  }
825
840
  return fromArgs;
@@ -829,14 +844,26 @@ function initWrapper(protocols) {
829
844
  // 处理通用 returnValue
830
845
  res = protocols.returnValue(methodName, res);
831
846
  }
832
- return processArgs(methodName, res, returnValue, {}, keepReturnValue);
847
+ const realKeepReturnValue = keepReturnValue || (false);
848
+ return processArgs(methodName, res, returnValue, {}, realKeepReturnValue);
833
849
  }
834
850
  return function wrapper(methodName, method) {
835
- if (!hasOwn(protocols, methodName)) {
851
+ if ((isContextApi(methodName) || isTaskApi(methodName)) && method) {
852
+ const oldMethod = method;
853
+ method = function (...args) {
854
+ const contextOrTask = oldMethod.apply(this, args);
855
+ if (contextOrTask) {
856
+ contextOrTask.__v_skip = true;
857
+ }
858
+ return contextOrTask;
859
+ };
860
+ }
861
+ if ((!hasOwn(protocols, methodName) && !isFunction(protocols.returnValue)) ||
862
+ !isFunction(method)) {
836
863
  return method;
837
864
  }
838
865
  const protocol = protocols[methodName];
839
- if (!protocol) {
866
+ if (!protocol && !isFunction(protocols.returnValue)) {
840
867
  // 暂不支持的 api
841
868
  return function () {
842
869
  console.error(`字节跳动小程序 暂不支持${methodName}`);
@@ -844,7 +871,7 @@ function initWrapper(protocols) {
844
871
  }
845
872
  return function (arg1, arg2) {
846
873
  // 目前 api 最多两个参数
847
- let options = protocol;
874
+ let options = protocol || {};
848
875
  if (isFunction(protocol)) {
849
876
  options = protocol(arg1);
850
877
  }
@@ -854,6 +881,11 @@ function initWrapper(protocols) {
854
881
  args.push(arg2);
855
882
  }
856
883
  const returnValue = tt[options.name || methodName].apply(tt, args);
884
+ if (isContextApi(methodName) || isTaskApi(methodName)) {
885
+ if (returnValue && !returnValue.__v_skip) {
886
+ returnValue.__v_skip = true;
887
+ }
888
+ }
857
889
  if (isSyncApi(methodName)) {
858
890
  // 同步 api
859
891
  return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName));
@@ -956,7 +988,7 @@ function populateParameters(fromRes, toRes) {
956
988
  // SDKVersion
957
989
  let _SDKVersion = SDKVersion;
958
990
  // hostLanguage
959
- const hostLanguage = language.replace(/_/g, '-');
991
+ const hostLanguage = (language || '').replace(/_/g, '-');
960
992
  // wx.getAccountInfoSync
961
993
  const parameters = {
962
994
  appId: process.env.UNI_APP_ID,
@@ -1115,12 +1147,51 @@ const navigateTo$1 = () => {
1115
1147
  };
1116
1148
  };
1117
1149
 
1150
+ const onError = {
1151
+ args(fromArgs) {
1152
+ const app = getApp({ allowDefault: true }) || {};
1153
+ if (!app.$vm) {
1154
+ if (!tt.$onErrorHandlers) {
1155
+ tt.$onErrorHandlers = [];
1156
+ }
1157
+ tt.$onErrorHandlers.push(fromArgs);
1158
+ }
1159
+ else {
1160
+ injectHook(ON_ERROR, fromArgs, app.$vm.$);
1161
+ }
1162
+ },
1163
+ };
1164
+ const offError = {
1165
+ args(fromArgs) {
1166
+ const app = getApp({ allowDefault: true }) || {};
1167
+ if (!app.$vm) {
1168
+ if (!tt.$onErrorHandlers) {
1169
+ return;
1170
+ }
1171
+ const index = tt.$onErrorHandlers.findIndex((fn) => fn === fromArgs);
1172
+ if (index !== -1) {
1173
+ tt.$onErrorHandlers.splice(index, 1);
1174
+ }
1175
+ }
1176
+ else if (fromArgs.__weh) {
1177
+ const onErrors = app.$vm.$[ON_ERROR];
1178
+ if (onErrors) {
1179
+ const index = onErrors.indexOf(fromArgs.__weh);
1180
+ if (index > -1) {
1181
+ onErrors.splice(index, 1);
1182
+ }
1183
+ }
1184
+ }
1185
+ },
1186
+ };
1187
+
1118
1188
  const baseApis = {
1119
1189
  $on,
1120
1190
  $off,
1121
1191
  $once,
1122
1192
  $emit,
1123
1193
  upx2px,
1194
+ rpx2px: upx2px,
1124
1195
  interceptors,
1125
1196
  addInterceptor,
1126
1197
  removeInterceptor,
@@ -1133,6 +1204,7 @@ const baseApis = {
1133
1204
  onPushMessage,
1134
1205
  offPushMessage,
1135
1206
  invokePushCallback,
1207
+ __f__,
1136
1208
  };
1137
1209
  function initUni(api, protocols, platform = tt) {
1138
1210
  const wrapper = initWrapper(protocols);
@@ -1248,6 +1320,8 @@ var protocols = /*#__PURE__*/Object.freeze({
1248
1320
  getUserInfo: getUserInfo,
1249
1321
  login: login,
1250
1322
  navigateTo: navigateTo,
1323
+ offError: offError,
1324
+ onError: onError,
1251
1325
  previewImage: previewImage,
1252
1326
  redirectTo: redirectTo,
1253
1327
  requestPayment: requestPayment,
@@ -1,6 +1,6 @@
1
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
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';
3
+ import { nextTick, injectHook, ref, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache } from 'vue';
4
4
  import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
5
5
 
6
6
  function initVueIds(vueIds, mpInstance) {
@@ -312,11 +312,12 @@ function parseApp(instance, parseAppOptions) {
312
312
  instance.$callHook(ON_LAUNCH, options);
313
313
  },
314
314
  };
315
- const { onError } = internalInstance;
316
- if (onError) {
317
- internalInstance.appContext.config.errorHandler = (err) => {
318
- instance.$callHook(ON_ERROR, err);
319
- };
315
+ const onErrorHandlers = tt.$onErrorHandlers;
316
+ if (onErrorHandlers) {
317
+ onErrorHandlers.forEach((fn) => {
318
+ injectHook(ON_ERROR, fn, internalInstance);
319
+ });
320
+ onErrorHandlers.length = 0;
320
321
  }
321
322
  initLocale(instance);
322
323
  const vueOptions = instance.$.type;
@@ -668,7 +669,7 @@ function applyOptions(componentOptions, vueOptions) {
668
669
  componentOptions.behaviors = initBehaviors(vueOptions);
669
670
  }
670
671
 
671
- function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
672
+ function parseComponent(vueOptions, { parse, mocks, isPage, isPageInProject, initRelation, handleLink, initLifetimes, }) {
672
673
  vueOptions = vueOptions.default || vueOptions;
673
674
  const options = {
674
675
  multipleSlots: true,
@@ -754,6 +755,7 @@ function parsePage(vueOptions, parseOptions) {
754
755
  const miniProgramPageOptions = parseComponent(vueOptions, {
755
756
  mocks,
756
757
  isPage,
758
+ isPageInProject: true,
757
759
  initRelation,
758
760
  handleLink,
759
761
  initLifetimes,
@@ -761,7 +763,9 @@ function parsePage(vueOptions, parseOptions) {
761
763
  initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
762
764
  const methods = miniProgramPageOptions.methods;
763
765
  methods.onLoad = function (query) {
764
- this.options = query;
766
+ {
767
+ this.options = query;
768
+ }
765
769
  this.$page = {
766
770
  fullPath: addLeadingSlash(this.route + stringifyQuery(query)),
767
771
  };
@@ -880,8 +884,32 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
880
884
  if (mpType === 'component') {
881
885
  initFormField(this.$vm);
882
886
  }
883
- // 处理父子关系
884
- initRelation(this, relationOptions);
887
+ {
888
+ // 处理父子关系
889
+ initRelation(this, relationOptions);
890
+ }
891
+ }
892
+ function ready() {
893
+ if (process.env.UNI_DEBUG) {
894
+ console.log('uni-app:[' + Date.now() + '][' + (this.is || this.route) + ']ready');
895
+ }
896
+ if (this.$vm) {
897
+ if (isPage(this)) {
898
+ if (this.pageinstance) {
899
+ this.__webviewId__ = this.pageinstance.__pageId__;
900
+ }
901
+ {
902
+ this.$vm.$callCreatedHook();
903
+ }
904
+ nextSetDataTick(this, () => {
905
+ this.$vm.$callHook('mounted');
906
+ this.$vm.$callHook(ON_READY);
907
+ });
908
+ }
909
+ }
910
+ else {
911
+ this.is && console.warn(this.is + ' is not ready');
912
+ }
885
913
  }
886
914
  function detached() {
887
915
  if (this.$vm) {
@@ -906,6 +934,7 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
906
934
  component = components[0];
907
935
  }
908
936
  },
937
+ ready,
909
938
  detached,
910
939
  };
911
940
  }
@@ -1008,24 +1037,6 @@ var parseComponentOptions = /*#__PURE__*/Object.freeze({
1008
1037
 
1009
1038
  function initLifetimes(lifetimesOptions) {
1010
1039
  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
1040
  detached() {
1030
1041
  this.$vm && $destroyComponent(this.$vm);
1031
1042
  // 清理
@@ -1,7 +1,7 @@
1
1
  import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend, remove } from '@vue/shared';
2
2
  import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
3
- import { findUniElement } from 'vue';
4
- import { Emitter, onCreateVueApp, invokeCreateVueAppHook } from '@dcloudio/uni-shared';
3
+ import { findUniElement, injectHook } from 'vue';
4
+ import { Emitter, ON_ERROR, onCreateVueApp, invokeCreateVueAppHook } from '@dcloudio/uni-shared';
5
5
 
6
6
  function validateProtocolFail(name, msg) {
7
7
  console.warn(`${name}: ${msg}`);
@@ -449,11 +449,32 @@ const getElementById = defineSyncApi(API_GET_ELEMENT_BY_ID, (id) => {
449
449
 
450
450
  const API_CREATE_CANVAS_CONTEXT_ASYNC = 'createCanvasContextAsync';
451
451
  class CanvasContext {
452
- constructor(element) {
452
+ constructor(element, width, height) {
453
+ // 跳过vue的响应式
454
+ this.__v_skip = true;
455
+ this._width = 0;
456
+ this._height = 0;
453
457
  this._element = element;
458
+ this._width = width;
459
+ this._height = height;
454
460
  }
455
461
  getContext(type) {
456
- return this._element.getContext(type);
462
+ const context = this._element.getContext(type);
463
+ if (!context.canvas.offsetWidth || !context.canvas.offsetHeight) {
464
+ Object.defineProperties(context.canvas, {
465
+ offsetWidth: {
466
+ value: this._width,
467
+ writable: true,
468
+ },
469
+ });
470
+ Object.defineProperties(context.canvas, {
471
+ offsetHeight: {
472
+ value: this._height,
473
+ writable: true,
474
+ },
475
+ });
476
+ }
477
+ return context;
457
478
  }
458
479
  toDataURL(type, encoderOptions) {
459
480
  return this._element.toDataURL(type, encoderOptions);
@@ -486,11 +507,11 @@ const createCanvasContextAsync = defineAsyncApi(API_CREATE_CANVAS_CONTEXT_ASYNC,
486
507
  : tt.createSelectorQuery();
487
508
  query
488
509
  .select('#' + options.id)
489
- .fields({ node: true }, () => { })
510
+ .fields({ node: true, size: true }, () => { })
490
511
  .exec((res) => {
491
- if (res.length > 0) {
492
- const canvas = res[0].node;
493
- resolve(new CanvasContext(canvas));
512
+ if (res.length > 0 && res[0].node) {
513
+ const result = res[0];
514
+ resolve(new CanvasContext(result.node, result.width, result.height));
494
515
  }
495
516
  else {
496
517
  reject('canvas id invalid.');
@@ -518,7 +539,7 @@ let isIOS = false;
518
539
  let deviceWidth = 0;
519
540
  let deviceDPR = 0;
520
541
  function checkDeviceWidth() {
521
- const { platform, pixelRatio, windowWidth } = getBaseSystemInfo();
542
+ const { windowWidth, pixelRatio, platform } = getBaseSystemInfo();
522
543
  deviceWidth = windowWidth;
523
544
  deviceDPR = pixelRatio;
524
545
  isIOS = platform === 'ios';
@@ -548,6 +569,13 @@ const upx2px = defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
548
569
  return number < 0 ? -result : result;
549
570
  }, Upx2pxProtocol);
550
571
 
572
+ function __f__(type, filename, ...args) {
573
+ if (filename) {
574
+ args.push(filename);
575
+ }
576
+ console[type].apply(console, args);
577
+ }
578
+
551
579
  const API_ADD_INTERCEPTOR = 'addInterceptor';
552
580
  const API_REMOVE_INTERCEPTOR = 'removeInterceptor';
553
581
  const AddInterceptorProtocol = [
@@ -792,11 +820,12 @@ const offPushMessage = (fn) => {
792
820
  }
793
821
  };
794
822
 
795
- const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
823
+ const SYNC_API_RE = /^\$|__f__|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|rpx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
796
824
  const SYNC_API_RE_X = /getElementById/;
797
825
  const CONTEXT_API_RE = /^create|Manager$/;
798
826
  // Context例外情况
799
827
  const CONTEXT_API_RE_EXC = ['createBLEConnection'];
828
+ const TASK_APIS = ['request', 'downloadFile', 'uploadFile', 'connectSocket'];
800
829
  // 同步例外情况
801
830
  const ASYNC_API = ['createBLEConnection'];
802
831
  const CALLBACK_API_RE = /^on|^off/;
@@ -812,6 +841,9 @@ function isSyncApi(name) {
812
841
  function isCallbackApi(name) {
813
842
  return CALLBACK_API_RE.test(name) && name !== 'onPush';
814
843
  }
844
+ function isTaskApi(name) {
845
+ return TASK_APIS.indexOf(name) !== -1;
846
+ }
815
847
  function shouldPromise(name) {
816
848
  if (isContextApi(name) || isSyncApi(name) || isCallbackApi(name)) {
817
849
  return false;
@@ -849,6 +881,10 @@ function promisify(name, api) {
849
881
  };
850
882
  }
851
883
 
884
+ function shouldKeepReturnValue(methodName) {
885
+ return methodName === 'getStorage' || methodName === 'getStorageSync';
886
+ }
887
+
852
888
  const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
853
889
  function initWrapper(protocols) {
854
890
  function processCallback(methodName, method, returnValue) {
@@ -897,6 +933,9 @@ function initWrapper(protocols) {
897
933
  return toArgs;
898
934
  }
899
935
  else if (isFunction(fromArgs)) {
936
+ if (isFunction(argsOption)) {
937
+ argsOption(fromArgs, {});
938
+ }
900
939
  fromArgs = processCallback(methodName, fromArgs, returnValue);
901
940
  }
902
941
  return fromArgs;
@@ -906,14 +945,26 @@ function initWrapper(protocols) {
906
945
  // 处理通用 returnValue
907
946
  res = protocols.returnValue(methodName, res);
908
947
  }
909
- return processArgs(methodName, res, returnValue, {}, keepReturnValue);
948
+ const realKeepReturnValue = keepReturnValue || (shouldKeepReturnValue(methodName));
949
+ return processArgs(methodName, res, returnValue, {}, realKeepReturnValue);
910
950
  }
911
951
  return function wrapper(methodName, method) {
912
- if (!hasOwn(protocols, methodName)) {
952
+ if ((isContextApi(methodName) || isTaskApi(methodName)) && method) {
953
+ const oldMethod = method;
954
+ method = function (...args) {
955
+ const contextOrTask = oldMethod.apply(this, args);
956
+ if (contextOrTask) {
957
+ contextOrTask.__v_skip = true;
958
+ }
959
+ return contextOrTask;
960
+ };
961
+ }
962
+ if ((!hasOwn(protocols, methodName) && !isFunction(protocols.returnValue)) ||
963
+ !isFunction(method)) {
913
964
  return method;
914
965
  }
915
966
  const protocol = protocols[methodName];
916
- if (!protocol) {
967
+ if (!protocol && !isFunction(protocols.returnValue)) {
917
968
  // 暂不支持的 api
918
969
  return function () {
919
970
  console.error(`字节跳动小程序 暂不支持${methodName}`);
@@ -921,7 +972,7 @@ function initWrapper(protocols) {
921
972
  }
922
973
  return function (arg1, arg2) {
923
974
  // 目前 api 最多两个参数
924
- let options = protocol;
975
+ let options = protocol || {};
925
976
  if (isFunction(protocol)) {
926
977
  options = protocol(arg1);
927
978
  }
@@ -931,6 +982,11 @@ function initWrapper(protocols) {
931
982
  args.push(arg2);
932
983
  }
933
984
  const returnValue = tt[options.name || methodName].apply(tt, args);
985
+ if (isContextApi(methodName) || isTaskApi(methodName)) {
986
+ if (returnValue && !returnValue.__v_skip) {
987
+ returnValue.__v_skip = true;
988
+ }
989
+ }
934
990
  if (isSyncApi(methodName)) {
935
991
  // 同步 api
936
992
  return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName));
@@ -1033,7 +1089,7 @@ function populateParameters(fromRes, toRes) {
1033
1089
  // SDKVersion
1034
1090
  let _SDKVersion = SDKVersion;
1035
1091
  // hostLanguage
1036
- const hostLanguage = language.replace(/_/g, '-');
1092
+ const hostLanguage = (language || '').replace(/_/g, '-');
1037
1093
  // wx.getAccountInfoSync
1038
1094
  const parameters = {
1039
1095
  appId: process.env.UNI_APP_ID,
@@ -1071,7 +1127,6 @@ function populateParameters(fromRes, toRes) {
1071
1127
  };
1072
1128
  {
1073
1129
  try {
1074
- parameters.uniCompileVersionCode = parseFloat(process.env.UNI_COMPILER_VERSION);
1075
1130
  parameters.uniCompilerVersionCode = parseFloat(process.env.UNI_COMPILER_VERSION);
1076
1131
  parameters.uniRuntimeVersionCode = parseFloat(process.env.UNI_COMPILER_VERSION);
1077
1132
  }
@@ -1200,12 +1255,51 @@ const navigateTo$1 = () => {
1200
1255
  };
1201
1256
  };
1202
1257
 
1258
+ const onError = {
1259
+ args(fromArgs) {
1260
+ const app = getApp({ allowDefault: true }) || {};
1261
+ if (!app.$vm) {
1262
+ if (!tt.$onErrorHandlers) {
1263
+ tt.$onErrorHandlers = [];
1264
+ }
1265
+ tt.$onErrorHandlers.push(fromArgs);
1266
+ }
1267
+ else {
1268
+ injectHook(ON_ERROR, fromArgs, app.$vm.$);
1269
+ }
1270
+ },
1271
+ };
1272
+ const offError = {
1273
+ args(fromArgs) {
1274
+ const app = getApp({ allowDefault: true }) || {};
1275
+ if (!app.$vm) {
1276
+ if (!tt.$onErrorHandlers) {
1277
+ return;
1278
+ }
1279
+ const index = tt.$onErrorHandlers.findIndex((fn) => fn === fromArgs);
1280
+ if (index !== -1) {
1281
+ tt.$onErrorHandlers.splice(index, 1);
1282
+ }
1283
+ }
1284
+ else if (fromArgs.__weh) {
1285
+ const onErrors = app.$vm.$[ON_ERROR];
1286
+ if (onErrors) {
1287
+ const index = onErrors.indexOf(fromArgs.__weh);
1288
+ if (index > -1) {
1289
+ onErrors.splice(index, 1);
1290
+ }
1291
+ }
1292
+ }
1293
+ },
1294
+ };
1295
+
1203
1296
  const baseApis = {
1204
1297
  $on,
1205
1298
  $off,
1206
1299
  $once,
1207
1300
  $emit,
1208
1301
  upx2px,
1302
+ rpx2px: upx2px,
1209
1303
  interceptors,
1210
1304
  addInterceptor,
1211
1305
  removeInterceptor,
@@ -1218,6 +1312,7 @@ const baseApis = {
1218
1312
  onPushMessage,
1219
1313
  offPushMessage,
1220
1314
  invokePushCallback,
1315
+ __f__,
1221
1316
  getElementById,
1222
1317
  createCanvasContextAsync,
1223
1318
  };
@@ -1335,6 +1430,8 @@ var protocols = /*#__PURE__*/Object.freeze({
1335
1430
  getUserInfo: getUserInfo,
1336
1431
  login: login,
1337
1432
  navigateTo: navigateTo,
1433
+ offError: offError,
1434
+ onError: onError,
1338
1435
  previewImage: previewImage,
1339
1436
  redirectTo: redirectTo,
1340
1437
  requestPayment: requestPayment,
@@ -1,6 +1,6 @@
1
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
2
  import { hasOwn, isArray, isString, isFunction, extend, isPlainObject as isPlainObject$1, isObject } from '@vue/shared';
3
- import { nextTick, onUpdated, pruneUniElements, onUnmounted, destroyUniElements, ref, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, registerCustomElement, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache } from 'vue';
3
+ import { nextTick, onUpdated, pruneUniElements, onUnmounted, destroyUniElements, injectHook, ref, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, registerCustomElement, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache } from 'vue';
4
4
  import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
5
5
 
6
6
  function arrayPop(array) {
@@ -124,6 +124,9 @@ function isImplementationOf(leftType, rightType, visited = []) {
124
124
  });
125
125
  }
126
126
  function isInstanceOf(value, type) {
127
+ if (type === UTSValueIterable) {
128
+ return value && value[Symbol.iterator];
129
+ }
127
130
  const isNativeInstanceofType = value instanceof type;
128
131
  if (isNativeInstanceofType || typeof value !== 'object') {
129
132
  return isNativeInstanceofType;
@@ -663,6 +666,9 @@ let UTSJSONObject$1 = class UTSJSONObject {
663
666
  }
664
667
  };
665
668
 
669
+ let UTSValueIterable$1 = class UTSValueIterable {
670
+ };
671
+
666
672
  // @ts-nocheck
667
673
  function getGlobal() {
668
674
  if (typeof globalThis !== 'undefined') {
@@ -694,6 +700,7 @@ const realGlobal = getGlobal();
694
700
  realGlobal.UTSJSONObject = UTSJSONObject$1;
695
701
  realGlobal.UniError = UniError;
696
702
  realGlobal.UTS = UTS;
703
+ realGlobal.UTSValueIterable = UTSValueIterable$1;
697
704
 
698
705
  function initVueIds(vueIds, mpInstance) {
699
706
  if (!vueIds) {
@@ -1007,6 +1014,9 @@ function parseApp(instance, parseAppOptions) {
1007
1014
  $vm: instance, // mp-alipay 组件 data 初始化比 onLaunch 早,提前挂载
1008
1015
  onLaunch(options) {
1009
1016
  this.$vm = instance; // 飞书小程序可能会把 AppOptions 序列化,导致 $vm 对象部分属性丢失
1017
+ {
1018
+ this.vm = this.$vm;
1019
+ }
1010
1020
  const ctx = internalInstance.ctx;
1011
1021
  if (this.$vm && ctx.$scope && ctx.$callHook) {
1012
1022
  // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
@@ -1022,11 +1032,12 @@ function parseApp(instance, parseAppOptions) {
1022
1032
  instance.$callHook(ON_LAUNCH, options);
1023
1033
  },
1024
1034
  };
1025
- const { onError } = internalInstance;
1026
- if (onError) {
1027
- internalInstance.appContext.config.errorHandler = (err) => {
1028
- instance.$callHook(ON_ERROR, err);
1029
- };
1035
+ const onErrorHandlers = tt.$onErrorHandlers;
1036
+ if (onErrorHandlers) {
1037
+ onErrorHandlers.forEach((fn) => {
1038
+ injectHook(ON_ERROR, fn, internalInstance);
1039
+ });
1040
+ onErrorHandlers.length = 0;
1030
1041
  }
1031
1042
  initLocale(instance);
1032
1043
  const vueOptions = instance.$.type;
@@ -1378,7 +1389,7 @@ function applyOptions(componentOptions, vueOptions) {
1378
1389
  componentOptions.behaviors = initBehaviors(vueOptions);
1379
1390
  }
1380
1391
 
1381
- function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
1392
+ function parseComponent(vueOptions, { parse, mocks, isPage, isPageInProject, initRelation, handleLink, initLifetimes, }) {
1382
1393
  vueOptions = vueOptions.default || vueOptions;
1383
1394
  const options = {
1384
1395
  multipleSlots: true,
@@ -1386,6 +1397,9 @@ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handle
1386
1397
  addGlobalClass: true,
1387
1398
  pureDataPattern: /^uP$/,
1388
1399
  };
1400
+ if (__UNI_FEATURE_VIRTUAL_HOST__ && !isPageInProject) {
1401
+ options.virtualHost = true;
1402
+ }
1389
1403
  if (isArray(vueOptions.mixins)) {
1390
1404
  vueOptions.mixins.forEach((item) => {
1391
1405
  if (isObject(item.options)) {
@@ -1470,6 +1484,7 @@ function parsePage(vueOptions, parseOptions) {
1470
1484
  const miniProgramPageOptions = parseComponent(vueOptions, {
1471
1485
  mocks,
1472
1486
  isPage,
1487
+ isPageInProject: true,
1473
1488
  initRelation,
1474
1489
  handleLink,
1475
1490
  initLifetimes,
@@ -1477,7 +1492,9 @@ function parsePage(vueOptions, parseOptions) {
1477
1492
  initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
1478
1493
  const methods = miniProgramPageOptions.methods;
1479
1494
  methods.onLoad = function (query) {
1480
- this.options = query;
1495
+ {
1496
+ this.options = new UTSJSONObject(query || {});
1497
+ }
1481
1498
  this.$page = {
1482
1499
  fullPath: addLeadingSlash(this.route + stringifyQuery(query)),
1483
1500
  };
@@ -1584,6 +1601,9 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
1584
1601
  initComponentInstance(instance, options);
1585
1602
  },
1586
1603
  });
1604
+ {
1605
+ this.vm = this.$vm;
1606
+ }
1587
1607
  if (process.env.UNI_DEBUG) {
1588
1608
  console.log('uni-app:[' +
1589
1609
  Date.now() +
@@ -1596,8 +1616,32 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
1596
1616
  if (mpType === 'component') {
1597
1617
  initFormField(this.$vm);
1598
1618
  }
1599
- // 处理父子关系
1600
- initRelation(this, relationOptions);
1619
+ {
1620
+ // 处理父子关系
1621
+ initRelation(this, relationOptions);
1622
+ }
1623
+ }
1624
+ function ready() {
1625
+ if (process.env.UNI_DEBUG) {
1626
+ console.log('uni-app:[' + Date.now() + '][' + (this.is || this.route) + ']ready');
1627
+ }
1628
+ if (this.$vm) {
1629
+ if (isPage(this)) {
1630
+ if (this.pageinstance) {
1631
+ this.__webviewId__ = this.pageinstance.__pageId__;
1632
+ }
1633
+ {
1634
+ this.$vm.$callCreatedHook();
1635
+ }
1636
+ nextSetDataTick(this, () => {
1637
+ this.$vm.$callHook('mounted');
1638
+ this.$vm.$callHook(ON_READY);
1639
+ });
1640
+ }
1641
+ }
1642
+ else {
1643
+ this.is && console.warn(this.is + ' is not ready');
1644
+ }
1601
1645
  }
1602
1646
  function detached() {
1603
1647
  if (this.$vm) {
@@ -1622,6 +1666,7 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
1622
1666
  component = components[0];
1623
1667
  }
1624
1668
  },
1669
+ ready,
1625
1670
  detached,
1626
1671
  };
1627
1672
  }
@@ -1724,24 +1769,6 @@ var parseComponentOptions = /*#__PURE__*/Object.freeze({
1724
1769
 
1725
1770
  function initLifetimes(lifetimesOptions) {
1726
1771
  return extend(initLifetimes$1(lifetimesOptions), {
1727
- ready() {
1728
- if (this.$vm && lifetimesOptions.isPage(this)) {
1729
- if (this.pageinstance) {
1730
- this.__webviewId__ = this.pageinstance.__pageId__;
1731
- }
1732
- if (process.env.UNI_DEBUG) {
1733
- console.log('uni-app:[' + Date.now() + '][' + (this.is || this.route) + ']ready');
1734
- }
1735
- this.$vm.$callCreatedHook();
1736
- nextSetDataTick(this, () => {
1737
- this.$vm.$callHook('mounted');
1738
- this.$vm.$callHook(ON_READY);
1739
- });
1740
- }
1741
- else {
1742
- this.is && console.warn(this.is + ' is not ready');
1743
- }
1744
- },
1745
1772
  detached() {
1746
1773
  this.$vm && $destroyComponent(this.$vm);
1747
1774
  // 清理
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-mp-toutiao",
3
- "version": "3.0.0-alpha-4030620241126001",
3
+ "version": "3.0.0-alpha-4040120241206001",
4
4
  "description": "uni-app mp-toutiao",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -12,9 +12,6 @@
12
12
  "url": "git+https://github.com/dcloudio/uni-app.git",
13
13
  "directory": "packages/uni-mp-toutiao"
14
14
  },
15
- "scripts": {
16
- "test": "echo \"Error: no test specified\" && exit 1"
17
- },
18
15
  "license": "Apache-2.0",
19
16
  "uni-app": {
20
17
  "name": "mp-toutiao",
@@ -26,12 +23,15 @@
26
23
  },
27
24
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
28
25
  "dependencies": {
29
- "@dcloudio/uni-cli-shared": "3.0.0-alpha-4030620241126001",
30
- "@dcloudio/uni-mp-compiler": "3.0.0-alpha-4030620241126001",
31
- "@dcloudio/uni-mp-vite": "3.0.0-alpha-4030620241126001",
32
- "@dcloudio/uni-mp-vue": "3.0.0-alpha-4030620241126001",
33
- "@dcloudio/uni-shared": "3.0.0-alpha-4030620241126001",
34
26
  "@vue/shared": "3.4.21",
35
- "@vue/compiler-core": "3.4.21"
27
+ "@vue/compiler-core": "3.4.21",
28
+ "@dcloudio/uni-cli-shared": "3.0.0-alpha-4040120241206001",
29
+ "@dcloudio/uni-mp-compiler": "3.0.0-alpha-4040120241206001",
30
+ "@dcloudio/uni-mp-vite": "3.0.0-alpha-4040120241206001",
31
+ "@dcloudio/uni-mp-vue": "3.0.0-alpha-4040120241206001",
32
+ "@dcloudio/uni-shared": "3.0.0-alpha-4040120241206001"
33
+ },
34
+ "scripts": {
35
+ "test": "echo \"Error: no test specified\" && exit 1"
36
36
  }
37
- }
37
+ }