mixin.js
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"use strict";
var common_vendor = require("../../../../common/vendor.js");
var mixin = {
props: {
customStyle: {
type: [Object, String],
default: () => ({})
},
customClass: {
type: String,
default: ""
},
url: {
type: String,
default: ""
},
linkType: {
type: String,
default: "navigateTo"
}
},
data() {
return {};
},
onLoad() {
this.$u.getRect = this.$uGetRect;
},
created() {
this.$u.getRect = this.$uGetRect;
},
computed: {
$u() {
return common_vendor.index.$u.deepMerge(common_vendor.index.$u, {
props: void 0,
http: void 0,
mixin: void 0
});
},
bem() {
return function(name, fixed, change) {
const prefix = `u-${name}--`;
const classes = {};
if (fixed) {
fixed.map((item) => {
classes[prefix + this[item]] = true;
});
}
if (change) {
change.map((item) => {
this[item] ? classes[prefix + item] = this[item] : delete classes[prefix + item];
});
}
return Object.keys(classes);
};
}
},
methods: {
openPage(urlKey = "url") {
const url = this[urlKey];
if (url) {
this.$u.route({ type: this.linkType, url });
}
},
$uGetRect(selector, all) {
return new Promise((resolve) => {
common_vendor.index.createSelectorQuery().in(this)[all ? "selectAll" : "select"](selector).boundingClientRect((rect) => {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect);
}
if (!all && rect) {
resolve(rect);
}
}).exec();
});
},
getParentData(parentName = "") {
if (!this.parent)
this.parent = {};
this.parent = common_vendor.index.$u.$parent.call(this, parentName);
if (this.parent.children) {
this.parent.children.indexOf(this) === -1 && this.parent.children.push(this);
}
if (this.parent && this.parentData) {
Object.keys(this.parentData).map((key) => {
this.parentData[key] = this.parent[key];
});
}
},
preventEvent(e) {
e && typeof e.stopPropagation === "function" && e.stopPropagation();
},
noop(e) {
this.preventEvent(e);
}
},
onReachBottom() {
common_vendor.index.$emit("uOnReachBottom");
},
beforeDestroy() {
if (this.parent && common_vendor.index.$u.test.array(this.parent.children)) {
const childrenList = this.parent.children;
childrenList.map((child, index) => {
if (child === this) {
childrenList.splice(index, 1);
}
});
}
}
};
exports.mixin = mixin;