@mpxjs/core 2.8.50 → 2.8.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.8.50",
3
+ "version": "2.8.52",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "main": "src/index.js",
21
21
  "dependencies": {
22
- "@mpxjs/utils": "^2.8.50",
22
+ "@mpxjs/utils": "^2.8.52",
23
23
  "lodash": "^4.1.1",
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
@@ -47,5 +47,5 @@
47
47
  "url": "https://github.com/didi/mpx/issues"
48
48
  },
49
49
  "sideEffects": false,
50
- "gitHead": "32f30631cc5f37503fb7791cb3b0d6c901ee2b27"
50
+ "gitHead": "87bec6efa6bd62939b2fb7714b16e33d4d29f5c8"
51
51
  }
@@ -19,7 +19,7 @@ export function injectMixins (mixins, options = {}) {
19
19
  }
20
20
  }
21
21
 
22
- let types = options.types || ['app', 'page', 'component']
22
+ let types = options.types || ['page', 'component']
23
23
  const stage = options.stage || -1
24
24
 
25
25
  if (typeof types === 'string') {
@@ -89,29 +89,34 @@ export default function proxyEventMixin () {
89
89
  }
90
90
  if (__mpx_mode__ === 'ali') {
91
91
  Object.assign(methods, {
92
- triggerEvent (eventName, eventDetail) {
92
+ triggerEvent (eventName, eventDetail, e) {
93
93
  const handlerName = eventName.replace(/^./, matched => matched.toUpperCase()).replace(/-([a-z])/g, (match, p1) => p1.toUpperCase())
94
94
  const handler = this.props && (this.props['on' + handlerName] || this.props['catch' + handlerName])
95
95
  if (handler && typeof handler === 'function') {
96
- const dataset = collectDataset(this.props)
97
- const id = this.props.id || ''
98
- const timeStamp = +new Date()
99
- const eventObj = {
100
- type: eventName,
101
- timeStamp,
102
- target: {
103
- id,
104
- dataset,
105
- targetDataset: dataset
106
- },
107
- currentTarget: {
108
- id,
109
- dataset
110
- },
111
- detail: eventDetail
96
+ let eventObj = {}
97
+ if (e) {
98
+ e.detail = Object.assign(e.detail, eventDetail)
99
+ eventObj = e
100
+ } else {
101
+ const dataset = collectDataset(this.props)
102
+ const id = this.props.id || ''
103
+ const timeStamp = +new Date()
104
+ eventObj = {
105
+ type: eventName,
106
+ timeStamp,
107
+ target: { id, dataset, targetDataset: dataset },
108
+ currentTarget: { id, dataset },
109
+ detail: eventDetail
110
+ }
112
111
  }
113
112
  handler.call(this, eventObj)
114
113
  }
114
+ },
115
+ __proxyEvent (e) {
116
+ const eventName = e.type
117
+ // 保持和微信一致
118
+ e.target = e.currentTarget
119
+ this.triggerEvent(eventName, {}, e)
115
120
  }
116
121
  })
117
122
  }
@@ -18,6 +18,12 @@ export default function proxyEventMixin () {
18
18
  const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
19
19
  const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
20
20
  setByPath(this, expr, value)
21
+ },
22
+ __proxyEvent (e) {
23
+ const type = e.type
24
+ // 保持和微信一致 target 和 currentTarget 相同
25
+ e.target = e.currentTarget
26
+ this.triggerEvent(type, {}, e)
21
27
  }
22
28
  }
23
29
  }
package/src/vuePlugin.js CHANGED
@@ -1,12 +1,39 @@
1
- import { walkChildren, parseSelector, error } from '@mpxjs/utils'
1
+ import { walkChildren, parseSelector, error, hasOwn } from '@mpxjs/utils'
2
2
  import * as webApi from '@mpxjs/api-proxy/src/web/api'
3
+ const datasetReg = /^data-(.+)$/
4
+
5
+ function collectDataset (attrs) {
6
+ const dataset = {}
7
+ for (const key in attrs) {
8
+ if (hasOwn(attrs, key)) {
9
+ const matched = datasetReg.exec(key)
10
+ if (matched) {
11
+ dataset[matched[1]] = attrs[key]
12
+ }
13
+ }
14
+ }
15
+ return dataset
16
+ }
3
17
 
4
18
  export default function install (Vue) {
5
- Vue.prototype.triggerEvent = function (eventName, eventDetail) {
6
- return this.$emit(eventName, {
7
- type: eventName,
8
- detail: eventDetail
9
- })
19
+ Vue.prototype.triggerEvent = function (eventName, eventDetail, e) {
20
+ let eventObj = {}
21
+ if (e) {
22
+ e.detail = Object.assign(e.detail, eventDetail)
23
+ eventObj = e
24
+ } else {
25
+ const dataset = collectDataset(this.$attrs)
26
+ const id = this.$attrs.id || ''
27
+ const timeStamp = +new Date()
28
+ eventObj = {
29
+ type: eventName,
30
+ timeStamp,
31
+ target: { id, dataset, targetDataset: dataset },
32
+ currentTarget: { id, dataset },
33
+ detail: eventDetail
34
+ }
35
+ }
36
+ return this.$emit(eventName, eventObj)
10
37
  }
11
38
  Vue.prototype.selectComponent = function (selector, all) {
12
39
  const result = []