@dcloudio/uni-quickapp-webview 2.0.1-35320220729002 → 2.0.1-36220220914001

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -14
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1230,11 +1230,12 @@ function getPushClientId (args) {
1230
1230
  const hasSuccess = isFn(success);
1231
1231
  const hasFail = isFn(fail);
1232
1232
  const hasComplete = isFn(complete);
1233
+
1233
1234
  Promise.resolve().then(() => {
1234
1235
  if (typeof enabled === 'undefined') {
1235
1236
  enabled = false;
1236
1237
  cid = '';
1237
- cidErrMsg = 'unipush is not enabled';
1238
+ cidErrMsg = 'uniPush is not enabled';
1238
1239
  }
1239
1240
  getPushCidCallbacks.push((cid, errMsg) => {
1240
1241
  let res;
@@ -1263,7 +1264,7 @@ const onPushMessageCallbacks = [];
1263
1264
  const onPushMessage = (fn) => {
1264
1265
  if (onPushMessageCallbacks.indexOf(fn) === -1) {
1265
1266
  onPushMessageCallbacks.push(fn);
1266
- }
1267
+ }
1267
1268
  };
1268
1269
 
1269
1270
  const offPushMessage = (fn) => {
@@ -1297,7 +1298,11 @@ const customize = cached((str) => {
1297
1298
  function initTriggerEvent (mpInstance) {
1298
1299
  const oldTriggerEvent = mpInstance.triggerEvent;
1299
1300
  const newTriggerEvent = function (event, ...args) {
1300
- return oldTriggerEvent.apply(mpInstance, [customize(event), ...args])
1301
+ // 事件名统一转驼峰格式,仅处理:当前组件为 vue 组件、当前组件为 vue 组件子组件
1302
+ if (this.$vm || (this.dataset && this.dataset.comType)) {
1303
+ event = customize(event);
1304
+ }
1305
+ return oldTriggerEvent.apply(this, [event, ...args])
1301
1306
  };
1302
1307
  try {
1303
1308
  // 京东小程序 triggerEvent 为只读
@@ -1396,6 +1401,29 @@ function initHooks (mpOptions, hooks, vueOptions) {
1396
1401
  });
1397
1402
  }
1398
1403
 
1404
+ function initUnknownHooks (mpOptions, vueOptions, excludes = []) {
1405
+ findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes));
1406
+ }
1407
+
1408
+ function findHooks (vueOptions, hooks = []) {
1409
+ if (vueOptions) {
1410
+ Object.keys(vueOptions).forEach((name) => {
1411
+ if (name.indexOf('on') === 0 && isFn(vueOptions[name])) {
1412
+ hooks.push(name);
1413
+ }
1414
+ });
1415
+ }
1416
+ return hooks
1417
+ }
1418
+
1419
+ function initHook$1 (mpOptions, hook, excludes) {
1420
+ if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
1421
+ mpOptions[hook] = function (args) {
1422
+ return this.$vm && this.$vm.__call_hook(hook, args)
1423
+ };
1424
+ }
1425
+ }
1426
+
1399
1427
  function initVueComponent (Vue, vueOptions) {
1400
1428
  vueOptions = vueOptions.default || vueOptions;
1401
1429
  let VueComponent;
@@ -1446,7 +1474,7 @@ function initData (vueOptions, context) {
1446
1474
  try {
1447
1475
  // 对 data 格式化
1448
1476
  data = JSON.parse(JSON.stringify(data));
1449
- } catch (e) {}
1477
+ } catch (e) { }
1450
1478
  }
1451
1479
 
1452
1480
  if (!isPlainObject(data)) {
@@ -1598,7 +1626,7 @@ function wrapper$1 (event) {
1598
1626
  // TODO 又得兼容 mpvue 的 mp 对象
1599
1627
  try {
1600
1628
  event.mp = JSON.parse(JSON.stringify(event));
1601
- } catch (e) {}
1629
+ } catch (e) { }
1602
1630
 
1603
1631
  event.stopPropagation = noop;
1604
1632
  event.preventDefault = noop;
@@ -1669,7 +1697,7 @@ function getExtraValue (vm, dataPathsArray) {
1669
1697
  return context
1670
1698
  }
1671
1699
 
1672
- function processEventExtra (vm, extra, event) {
1700
+ function processEventExtra (vm, extra, event, __args__) {
1673
1701
  const extraObj = {};
1674
1702
 
1675
1703
  if (Array.isArray(extra) && extra.length) {
@@ -1692,11 +1720,7 @@ function processEventExtra (vm, extra, event) {
1692
1720
  if (dataPath === '$event') { // $event
1693
1721
  extraObj['$' + index] = event;
1694
1722
  } else if (dataPath === 'arguments') {
1695
- if (event.detail && event.detail.__args__) {
1696
- extraObj['$' + index] = event.detail.__args__;
1697
- } else {
1698
- extraObj['$' + index] = [event];
1699
- }
1723
+ extraObj['$' + index] = event.detail ? event.detail.__args__ || __args__ : __args__;
1700
1724
  } else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
1701
1725
  extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
1702
1726
  } else {
@@ -1723,6 +1747,12 @@ function getObjByArray (arr) {
1723
1747
 
1724
1748
  function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
1725
1749
  let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
1750
+
1751
+ // fixed 用户直接触发 mpInstance.triggerEvent
1752
+ const __args__ = isPlainObject(event.detail)
1753
+ ? event.detail.__args__ || [event.detail]
1754
+ : [event.detail];
1755
+
1726
1756
  if (isCustom) { // 自定义事件
1727
1757
  isCustomMPEvent = event.currentTarget &&
1728
1758
  event.currentTarget.dataset &&
@@ -1731,11 +1761,11 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
1731
1761
  if (isCustomMPEvent) {
1732
1762
  return [event]
1733
1763
  }
1734
- return event.detail.__args__ || event.detail
1764
+ return __args__
1735
1765
  }
1736
1766
  }
1737
1767
 
1738
- const extraObj = processEventExtra(vm, extra, event);
1768
+ const extraObj = processEventExtra(vm, extra, event, __args__);
1739
1769
 
1740
1770
  const ret = [];
1741
1771
  args.forEach(arg => {
@@ -1744,7 +1774,7 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
1744
1774
  ret.push(event.target.value);
1745
1775
  } else {
1746
1776
  if (isCustom && !isCustomMPEvent) {
1747
- ret.push(event.detail.__args__[0]);
1777
+ ret.push(__args__[0]);
1748
1778
  } else { // wxcomponent 组件或内置组件
1749
1779
  ret.push(event);
1750
1780
  }
@@ -1978,6 +2008,7 @@ function parseBaseApp (vm, {
1978
2008
  initAppLocale(Vue, vm, normalizeLocale(qa.getSystemInfoSync().language) || LOCALE_EN);
1979
2009
 
1980
2010
  initHooks(appOptions, hooks);
2011
+ initUnknownHooks(appOptions, vm.$options);
1981
2012
 
1982
2013
  return appOptions
1983
2014
  }
@@ -2335,6 +2366,7 @@ function parseBasePage (vuePageOptions, {
2335
2366
  const pageOptions = parseComponent(vuePageOptions);
2336
2367
 
2337
2368
  initHooks(pageOptions.methods, hooks$1, vuePageOptions);
2369
+ initUnknownHooks(pageOptions.methods, vuePageOptions);
2338
2370
 
2339
2371
  pageOptions.methods.onLoad = function (query) {
2340
2372
  this.options = query;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-quickapp-webview",
3
- "version": "2.0.1-35320220729002",
3
+ "version": "2.0.1-36220220914001",
4
4
  "description": "uni-app quickapp-webview",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -17,5 +17,5 @@
17
17
  "name": "quickapp-webview",
18
18
  "title": "快应用(Webview)版"
19
19
  },
20
- "gitHead": "99c489d7a19425ade612162abd21b441260e7ba7"
20
+ "gitHead": "67fdc447148dd3e05d528bfb4e5ed103430ec05b"
21
21
  }