@dolphinweex/weex-harmony 0.1.70 → 0.1.72
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
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
ref="embedElement"
|
|
8
8
|
:id="embedId"
|
|
9
9
|
:type="embedType"
|
|
10
|
-
width="100%"
|
|
11
|
-
height="100%"
|
|
10
|
+
:width="embedWidth || '100%'"
|
|
11
|
+
:height="embedHeight || '100%'"
|
|
12
12
|
/>
|
|
13
13
|
</div>
|
|
14
14
|
</template>
|
|
@@ -47,6 +47,14 @@ export default {
|
|
|
47
47
|
required: false,
|
|
48
48
|
default: false,
|
|
49
49
|
},
|
|
50
|
+
embedWidth:{
|
|
51
|
+
type: String || Number,
|
|
52
|
+
defalut: '100%'
|
|
53
|
+
},
|
|
54
|
+
embedHeight:{
|
|
55
|
+
type: String || Number,
|
|
56
|
+
defalut: '100%'
|
|
57
|
+
}
|
|
50
58
|
},
|
|
51
59
|
data() {
|
|
52
60
|
return {
|
|
@@ -37,7 +37,7 @@ export default {
|
|
|
37
37
|
embedId: `embedId_iframe_${
|
|
38
38
|
Date.now().toString(36) + Math.random().toString(36).substring(2)
|
|
39
39
|
}`,
|
|
40
|
-
height:
|
|
40
|
+
height: 0px,
|
|
41
41
|
};
|
|
42
42
|
},
|
|
43
43
|
components: {
|
|
@@ -129,6 +129,7 @@ export default {
|
|
|
129
129
|
if(event.data.type==='IFRAME_CONTENT_HEIGHT'){
|
|
130
130
|
const h = Number(event.data.height) || 0;
|
|
131
131
|
if (!h) {
|
|
132
|
+
this.height = '100%'
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
if (this._wrapperEl) {
|
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<BaseSameLayer
|
|
3
3
|
:hosSameLayerArgs="hosSameLayerArgs"
|
|
4
|
+
ref="sameLayer"
|
|
4
5
|
embedType="native/midea-ijkplayer-view"
|
|
5
|
-
:defaultWidth="
|
|
6
|
-
:defaultHeight="
|
|
6
|
+
:defaultWidth="'100%'"
|
|
7
|
+
:defaultHeight="'100%'"
|
|
8
|
+
:embedWidth="embedWidth"
|
|
9
|
+
:embedHeight="embedHeight"
|
|
10
|
+
:style="
|
|
11
|
+
embedPosition !== 'fixed'
|
|
12
|
+
? { position: embedPosition }
|
|
13
|
+
: {
|
|
14
|
+
position: embedPosition,
|
|
15
|
+
top: 0,
|
|
16
|
+
left: 0,
|
|
17
|
+
bottom: 0,
|
|
18
|
+
right: 0,
|
|
19
|
+
}
|
|
20
|
+
"
|
|
7
21
|
></BaseSameLayer>
|
|
8
22
|
</template>
|
|
9
23
|
|
|
10
24
|
<script>
|
|
11
|
-
import BaseSameLayer from
|
|
25
|
+
import BaseSameLayer from './baseSameLayer.vue';
|
|
12
26
|
|
|
13
27
|
export default {
|
|
14
28
|
data() {
|
|
15
29
|
return {
|
|
16
30
|
width: 0,
|
|
17
31
|
height: 0,
|
|
32
|
+
embedWidth: '100%',
|
|
33
|
+
embedHeight: '100%',
|
|
34
|
+
embedPosition: 'static',
|
|
35
|
+
defaultWidth: '100%',
|
|
36
|
+
defaultHeight: '100%',
|
|
18
37
|
};
|
|
19
38
|
},
|
|
20
|
-
name:
|
|
39
|
+
name: 'MideaIjkplayerView',
|
|
21
40
|
components: {
|
|
22
41
|
BaseSameLayer,
|
|
23
42
|
},
|
|
@@ -34,6 +53,82 @@ export default {
|
|
|
34
53
|
return {};
|
|
35
54
|
},
|
|
36
55
|
},
|
|
56
|
+
config: {
|
|
57
|
+
type: Object,
|
|
58
|
+
default() {
|
|
59
|
+
return {};
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
muted: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: false,
|
|
65
|
+
},
|
|
66
|
+
playStatus: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: 'normal',
|
|
69
|
+
},
|
|
70
|
+
needDownload: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
default: false,
|
|
73
|
+
},
|
|
74
|
+
isSupportScale: {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
default: false,
|
|
77
|
+
},
|
|
78
|
+
videoResize: {
|
|
79
|
+
type: Number,
|
|
80
|
+
default: 0,
|
|
81
|
+
},
|
|
82
|
+
autoplay: {
|
|
83
|
+
type: Boolean,
|
|
84
|
+
default: false,
|
|
85
|
+
},
|
|
86
|
+
videoCover: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: '',
|
|
89
|
+
},
|
|
90
|
+
uiVisible: {
|
|
91
|
+
type: Object,
|
|
92
|
+
default() {
|
|
93
|
+
return {
|
|
94
|
+
voiceBtnVisible: true,
|
|
95
|
+
speedBtnVisible: true,
|
|
96
|
+
captureBtnVisible: true,
|
|
97
|
+
downloadBtnVisible: true,
|
|
98
|
+
batteryTimeLayoutVisible: false,
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
speedList: {
|
|
103
|
+
type: Array,
|
|
104
|
+
default() {
|
|
105
|
+
return ['0.5', '1', '1.5', '2'];
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
extraInfo: {
|
|
109
|
+
type: String,
|
|
110
|
+
default: '',
|
|
111
|
+
},
|
|
112
|
+
deleteBtnVisible: {
|
|
113
|
+
type: Number,
|
|
114
|
+
default: 0,
|
|
115
|
+
},
|
|
116
|
+
downloadDir: {
|
|
117
|
+
type: String,
|
|
118
|
+
default: '',
|
|
119
|
+
},
|
|
120
|
+
albumName: {
|
|
121
|
+
type: String,
|
|
122
|
+
default: '',
|
|
123
|
+
},
|
|
124
|
+
src: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: '',
|
|
127
|
+
},
|
|
128
|
+
isShowTopRightViewOnPortrait: {
|
|
129
|
+
type: Boolean,
|
|
130
|
+
default: false,
|
|
131
|
+
},
|
|
37
132
|
},
|
|
38
133
|
computed: {
|
|
39
134
|
hosSameLayerArgs() {
|
|
@@ -41,53 +136,104 @@ export default {
|
|
|
41
136
|
...this.hosUniqueProps, // 鸿蒙原生组件独有属性
|
|
42
137
|
width: this.width,
|
|
43
138
|
height: this.height,
|
|
139
|
+
onFullscreenChange: this.onFullscreenChange,
|
|
140
|
+
// 视频播放器相关属性
|
|
141
|
+
config: this.config,
|
|
142
|
+
muted: this.muted,
|
|
143
|
+
playStatus: this.playStatus,
|
|
144
|
+
needDownload: this.needDownload,
|
|
145
|
+
isSupportScale: this.isSupportScale,
|
|
146
|
+
videoResize: this.videoResize,
|
|
147
|
+
autoplay: this.autoplay,
|
|
148
|
+
videoCover: this.videoCover,
|
|
149
|
+
uiVisible: this.uiVisible,
|
|
150
|
+
speedList: this.speedList,
|
|
151
|
+
extraInfo: this.extraInfo,
|
|
152
|
+
deleteBtnVisible: this.deleteBtnVisible,
|
|
153
|
+
downloadDir: this.downloadDir,
|
|
154
|
+
albumName: this.albumName,
|
|
44
155
|
data: this.data,
|
|
156
|
+
src: this.src,
|
|
157
|
+
isShowTopRightViewOnPortrait: this.isShowTopRightViewOnPortrait,
|
|
45
158
|
|
|
159
|
+
// 事件回调
|
|
46
160
|
onProgress: this.onProgress,
|
|
47
161
|
onStart: this.onStart,
|
|
48
162
|
onPause: this.onPause,
|
|
49
163
|
finish: this.finish,
|
|
50
164
|
onFail: this.onFail,
|
|
51
|
-
onReadyToPlay: this.onReadyToPlay
|
|
165
|
+
onReadyToPlay: this.onReadyToPlay,
|
|
166
|
+
deleteVideo: this.deleteVideo,
|
|
167
|
+
onDownloadSuccess: this.onDownloadSuccess,
|
|
168
|
+
onStartDownload: this.onStartDownload,
|
|
169
|
+
onPreviewImageClick: this.onPreviewImageClick,
|
|
52
170
|
};
|
|
53
171
|
},
|
|
54
172
|
},
|
|
55
173
|
mounted() {
|
|
56
174
|
this.width = this.$el.clientWidth;
|
|
57
175
|
this.height = this.$el.clientHeight;
|
|
176
|
+
this.windowWidth = window.innerWidth;
|
|
177
|
+
this.windowHeight = window.innerHeight;
|
|
178
|
+
this.$nextTick(() => {
|
|
179
|
+
this.defaultWidth = this.$refs.sameLayer.$el.clientWidth;
|
|
180
|
+
this.defaultHeight = this.$refs.sameLayer.$el.clientHeight;
|
|
181
|
+
this.defaultPosition =
|
|
182
|
+
this.$refs.sameLayer.$el.style.position || 'static';
|
|
183
|
+
});
|
|
58
184
|
},
|
|
59
|
-
|
|
60
185
|
methods: {
|
|
186
|
+
onFullscreenChange(isFullScreeen) {
|
|
187
|
+
if (isFullScreeen.flag) {
|
|
188
|
+
this.embedPosition = 'fixed';
|
|
189
|
+
this.embedHeight = this.windowWidth;
|
|
190
|
+
this.embedWidth = this.windowHeight;
|
|
191
|
+
} else {
|
|
192
|
+
this.embedPosition = this.defaultPosition;
|
|
193
|
+
this.embedHeight = this.defaultHeight;
|
|
194
|
+
this.embedWidth = this.defaultWidth;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
61
197
|
// 自定义拓展其它逻辑
|
|
62
198
|
onProgress(res) {
|
|
63
|
-
|
|
64
|
-
this.$emit("onProgress", res);
|
|
199
|
+
this.$emit('onProgress', res);
|
|
65
200
|
},
|
|
66
201
|
|
|
67
202
|
onStart(res) {
|
|
68
|
-
|
|
69
|
-
this.$emit("onStart", res);
|
|
203
|
+
this.$emit('onStart', res);
|
|
70
204
|
},
|
|
71
205
|
|
|
72
206
|
onPause(res) {
|
|
73
|
-
|
|
74
|
-
this.$emit("onPause", res);
|
|
207
|
+
this.$emit('onPause', res);
|
|
75
208
|
},
|
|
76
209
|
|
|
77
210
|
finish(res) {
|
|
78
|
-
|
|
79
|
-
this.$emit("finish", res);
|
|
211
|
+
this.$emit('finish', res);
|
|
80
212
|
},
|
|
81
213
|
|
|
82
214
|
onFail(res) {
|
|
83
|
-
|
|
84
|
-
this.$emit("onFail", res);
|
|
215
|
+
this.$emit('onFail', res);
|
|
85
216
|
},
|
|
86
217
|
|
|
87
218
|
onReadyToPlay(res) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
219
|
+
this.$emit('onReadyToPlay', res);
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
deleteVideo(res) {
|
|
223
|
+
this.$emit('deleteVideo', res);
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
onDownloadSuccess(res) {
|
|
227
|
+
this.$emit('onDownloadSuccess', res);
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
onStartDownload(res) {
|
|
231
|
+
this.$emit('onStartDownload', res);
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
onPreviewImageClick(res) {
|
|
235
|
+
this.$emit('onPreviewImageClick', res);
|
|
236
|
+
},
|
|
91
237
|
},
|
|
92
238
|
};
|
|
93
|
-
</script>
|
|
239
|
+
</script>
|
package/src/transform-loader.js
CHANGED
|
@@ -21,10 +21,8 @@ const baseUrl = '../src/components/'
|
|
|
21
21
|
const componentMap = require("./index")
|
|
22
22
|
|
|
23
23
|
const componentSet = new Set()
|
|
24
|
-
const vBindMap = new Map()
|
|
25
24
|
// v-for 场景下,将 v-bind 转为方法调用所需的方法映射
|
|
26
25
|
const vBindMethodMap = new Map()
|
|
27
|
-
let vBindComputedCounter = 0
|
|
28
26
|
let vBindMethodCounter = 0
|
|
29
27
|
|
|
30
28
|
/**
|
|
@@ -71,7 +69,7 @@ function hasTargetElement(tagName) {
|
|
|
71
69
|
* 遍历html节点,将需要引入的组件添加到componentSet中
|
|
72
70
|
* @param {*} node html节点
|
|
73
71
|
*/
|
|
74
|
-
function traverseNode(node, parent = null) {
|
|
72
|
+
function traverseNode(node, parent = null, parentVForContext = false) {
|
|
75
73
|
if (node.type === 'element') {
|
|
76
74
|
const { hasElement, componentName } = hasTargetElement(node.tagName);
|
|
77
75
|
if (hasElement) {
|
|
@@ -79,9 +77,8 @@ function traverseNode(node, parent = null) {
|
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
// 判断当前或父节点是否处于 v-for 场景
|
|
82
|
-
const hasVForInParent = parent && parent.attributes && parent.attributes.some(attr => attr.key === 'v-for')
|
|
83
80
|
const hasVForInCurrent = node.attributes && node.attributes.some(attr => attr.key === 'v-for')
|
|
84
|
-
const isInsideVFor =
|
|
81
|
+
const isInsideVFor = parentVForContext || hasVForInCurrent
|
|
85
82
|
|
|
86
83
|
if (node.attributes) {
|
|
87
84
|
node.attributes.forEach((attr, index) => {
|
|
@@ -89,13 +86,13 @@ function traverseNode(node, parent = null) {
|
|
|
89
86
|
if (isInsideVFor) {
|
|
90
87
|
// v-for 场景:将 v-bind="expr" 转为 v-bind="customVBindMethodX(expr)"
|
|
91
88
|
const methodName = `customVBindMethod${vBindMethodCounter++}`;
|
|
92
|
-
const argExpression = (attr.value || '').trim() || '
|
|
89
|
+
const argExpression = (attr.value || '').trim() || 'undefined';
|
|
93
90
|
const paramName = 'arg';
|
|
94
91
|
if (!vBindMethodMap.has(methodName)) {
|
|
95
92
|
vBindMethodMap.set(methodName, { paramName });
|
|
96
93
|
}
|
|
97
94
|
// 更新模板中的属性为方法调用
|
|
98
|
-
node.attributes[index].value =
|
|
95
|
+
node.attributes[index].value = `{...${methodName}(${argExpression})}`;
|
|
99
96
|
} else {
|
|
100
97
|
if (
|
|
101
98
|
attr.value.trim().startsWith('{') &&
|
|
@@ -122,13 +119,13 @@ function traverseNode(node, parent = null) {
|
|
|
122
119
|
value: generator(parsedAst).code,
|
|
123
120
|
};
|
|
124
121
|
} else {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
node.attributes[index].value =
|
|
122
|
+
const methodName = `customVBindMethod${vBindMethodCounter++}`;
|
|
123
|
+
const argExpression = (attr.value || '').trim() || 'undefined';
|
|
124
|
+
const paramName = 'arg';
|
|
125
|
+
if (!vBindMethodMap.has(methodName)) {
|
|
126
|
+
vBindMethodMap.set(methodName, { paramName });
|
|
127
|
+
}
|
|
128
|
+
node.attributes[index].value = `{...${methodName}(${argExpression})}`;
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
131
|
}
|
|
@@ -138,7 +135,7 @@ function traverseNode(node, parent = null) {
|
|
|
138
135
|
// 继续递归处理子节点
|
|
139
136
|
if (node.children) {
|
|
140
137
|
node.children.forEach((child) => {
|
|
141
|
-
traverseNode(child, node); // 将当前节点作为 parent 传递给子节点
|
|
138
|
+
traverseNode(child, node, isInsideVFor); // 将当前节点作为 parent 传递给子节点
|
|
142
139
|
});
|
|
143
140
|
}
|
|
144
141
|
}
|
|
@@ -193,80 +190,6 @@ function getComponentLoc(name) {
|
|
|
193
190
|
}
|
|
194
191
|
}
|
|
195
192
|
//解决v-bind传的是 a.b.c这种 可能a是空导致报错
|
|
196
|
-
function createComputedProperty(vBindValue, computedName) {
|
|
197
|
-
// 使用辅助函数创建成员表达式,支持嵌套属性路径
|
|
198
|
-
const valueExpression = createMemberExpressionFromPath(vBindValue);
|
|
199
|
-
const styleExpression = t.memberExpression(createMemberExpressionFromPath(vBindValue), t.identifier('style'));
|
|
200
|
-
|
|
201
|
-
// 为嵌套路径创建逐级空值检查(如 a.b.c 需要检查 a && a.b && a.b.c)
|
|
202
|
-
const parts = vBindValue.split('.');
|
|
203
|
-
const nullCheckConditions = [];
|
|
204
|
-
for (let i = 0; i < parts.length; i++) {
|
|
205
|
-
nullCheckConditions.push(createMemberExpressionFromPath(parts.slice(0, i + 1).join('.')));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 构建逐级 && 检查表达式
|
|
209
|
-
let nullCheckExpression = nullCheckConditions[0];
|
|
210
|
-
for (let i = 1; i < nullCheckConditions.length; i++) {
|
|
211
|
-
nullCheckExpression = t.logicalExpression('&&', nullCheckExpression, nullCheckConditions[i]);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return t.objectProperty(
|
|
215
|
-
t.identifier('computed'), // 为对象添加 computed 属性
|
|
216
|
-
t.objectExpression([ // 计算属性
|
|
217
|
-
t.objectProperty(
|
|
218
|
-
t.identifier(computedName), // 计算属性的名称
|
|
219
|
-
t.functionExpression( // 计算属性的值是一个函数
|
|
220
|
-
null, //不需要传参
|
|
221
|
-
[],
|
|
222
|
-
t.blockStatement([ // 函数体是一个块语句,包含多个语句
|
|
223
|
-
// 先判断对象本身是否存在(逐级检查),不存在直接返回空对象
|
|
224
|
-
t.ifStatement(
|
|
225
|
-
t.unaryExpression('!', nullCheckExpression),
|
|
226
|
-
t.blockStatement([
|
|
227
|
-
t.returnStatement(t.objectExpression([]))
|
|
228
|
-
])
|
|
229
|
-
),
|
|
230
|
-
t.ifStatement(// if (this.xxx && this.xxx.style)
|
|
231
|
-
t.logicalExpression(
|
|
232
|
-
'&&', // 使用逻辑"与"操作符
|
|
233
|
-
valueExpression,
|
|
234
|
-
styleExpression
|
|
235
|
-
),
|
|
236
|
-
t.blockStatement([ // 如果条件符合
|
|
237
|
-
t.expressionStatement(
|
|
238
|
-
t.assignmentExpression(
|
|
239
|
-
'=', // 赋值操作
|
|
240
|
-
styleExpression,
|
|
241
|
-
t.callExpression(
|
|
242
|
-
t.memberExpression(t.thisExpression(), t.identifier('_px2rem')), // this._px2rem 函数
|
|
243
|
-
[styleExpression]
|
|
244
|
-
)
|
|
245
|
-
)
|
|
246
|
-
)
|
|
247
|
-
]),
|
|
248
|
-
),
|
|
249
|
-
t.returnStatement( // 返回展开后的浅拷贝,确保引用变化以触发依赖更新
|
|
250
|
-
t.objectExpression([
|
|
251
|
-
t.spreadElement(
|
|
252
|
-
t.callExpression(
|
|
253
|
-
t.memberExpression(t.identifier('Object'), t.identifier('assign')),
|
|
254
|
-
[
|
|
255
|
-
t.objectExpression([]),
|
|
256
|
-
valueExpression
|
|
257
|
-
]
|
|
258
|
-
)
|
|
259
|
-
)
|
|
260
|
-
])
|
|
261
|
-
)
|
|
262
|
-
])
|
|
263
|
-
)
|
|
264
|
-
)
|
|
265
|
-
])
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
193
|
/**
|
|
271
194
|
* 根据引入的路径获取组件导入的路径
|
|
272
195
|
* @param {*} address
|
|
@@ -286,15 +209,6 @@ function getAbsPath(address){
|
|
|
286
209
|
* @param {*} propertyPath 属性路径字符串
|
|
287
210
|
* @returns AST 成员表达式节点
|
|
288
211
|
*/
|
|
289
|
-
function createMemberExpressionFromPath(propertyPath) {
|
|
290
|
-
const parts = propertyPath.split('.');
|
|
291
|
-
let expression = t.memberExpression(t.thisExpression(), t.identifier(parts[0]));
|
|
292
|
-
for (let i = 1; i < parts.length; i++) {
|
|
293
|
-
expression = t.memberExpression(expression, t.identifier(parts[i]));
|
|
294
|
-
}
|
|
295
|
-
return expression;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
212
|
/**
|
|
299
213
|
* 生产SFC代码
|
|
300
214
|
* @param {*} moduleResoveRet
|
|
@@ -350,47 +264,7 @@ function addComponentsProperty(data) {
|
|
|
350
264
|
})
|
|
351
265
|
}
|
|
352
266
|
}
|
|
353
|
-
|
|
354
|
-
vBindMap.forEach((obj,customComputedName) => {
|
|
355
|
-
const computedProperty = createComputedProperty(obj.computedName, customComputedName);
|
|
356
|
-
traverse(scriptAst, {
|
|
357
|
-
ObjectExpression(path) { //对象key value
|
|
358
|
-
const computedNode = path.node.properties.find(
|
|
359
|
-
(property) => property.key && property.key.name === 'computed'
|
|
360
|
-
);
|
|
361
|
-
if (computedNode) { // 如果找到了computed,检查是否已经存在该计算属性
|
|
362
|
-
const existingProperty = computedNode.value.properties.find(
|
|
363
|
-
(property) => property.key && property.key.name === customComputedName
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
if (!existingProperty) { // 如果没有相同名称的计算属性,插入新计算属性
|
|
367
|
-
computedNode.value.properties.push(computedProperty.value.properties[0]);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
// 判断computed是否存在
|
|
372
|
-
ExportDefaultDeclaration(path) {
|
|
373
|
-
if (t.isObjectExpression(path.node.declaration)) {
|
|
374
|
-
const properties = path.node.declaration.properties;
|
|
375
|
-
let computedPropertyNode = properties.find((item) => item.key.name === 'computed');
|
|
376
|
-
if (!computedPropertyNode) {//创建
|
|
377
|
-
computedPropertyNode = t.objectProperty(t.identifier('computed'), t.objectExpression([]));
|
|
378
|
-
properties.push(computedPropertyNode);
|
|
379
|
-
}
|
|
380
|
-
// 继续检查是否已存在相同名称的计算属性
|
|
381
|
-
const existingProperty = computedPropertyNode.value.properties.find(
|
|
382
|
-
(property) => property.key && property.key.name === customComputedName
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
if (!existingProperty) {
|
|
386
|
-
computedPropertyNode.value.properties.push(computedProperty.value.properties[0]);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
// v-for: 注入 v-bind 方法(接收循环项,px2rem,返回新对象)
|
|
267
|
+
// 将 v-bind 表达式转为方法调用(接收源数据,px2rem,返回新对象)
|
|
394
268
|
/**
|
|
395
269
|
* v-for 场景专用:将模板中的 v-bind="expr" 改写为 v-bind="method(expr)"
|
|
396
270
|
* - methodName: 注入到 methods 的方法名
|
|
@@ -405,6 +279,12 @@ function createVBindMethod(methodName, paramName) {
|
|
|
405
279
|
t.identifier(methodName),
|
|
406
280
|
[t.identifier(paramName)],
|
|
407
281
|
t.blockStatement([
|
|
282
|
+
t.ifStatement(
|
|
283
|
+
t.unaryExpression('!', t.identifier(paramName)),
|
|
284
|
+
t.blockStatement([
|
|
285
|
+
t.returnStatement(t.objectExpression([]))
|
|
286
|
+
])
|
|
287
|
+
),
|
|
408
288
|
t.ifStatement(
|
|
409
289
|
t.logicalExpression(
|
|
410
290
|
'&&',
|
|
@@ -552,13 +432,10 @@ module.exports = function (source) {
|
|
|
552
432
|
componentSet.clear()
|
|
553
433
|
}
|
|
554
434
|
|
|
555
|
-
if (vBindMap.size !== 0) {
|
|
556
|
-
addComputedPropertyToScript(scriptAst, vBindMap);
|
|
557
|
-
vBindMap.clear()
|
|
558
|
-
}
|
|
559
435
|
if (vBindMethodMap.size !== 0) {
|
|
560
436
|
addVBindMethodsToScript(scriptAst, vBindMethodMap)
|
|
561
437
|
vBindMethodMap.clear()
|
|
438
|
+
vBindMethodCounter = 0
|
|
562
439
|
}
|
|
563
440
|
|
|
564
441
|
const {
|