eoss-mobiles 0.2.38 → 0.2.39

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": "eoss-mobiles",
3
- "version": "0.2.38",
3
+ "version": "0.2.39",
4
4
  "description": "eoss内部移动端业务组件",
5
5
  "main": "lib/eoss-mobile.common.js",
6
6
  "files": [
@@ -1,17 +1,91 @@
1
1
  <template>
2
- <div class="em-grid">
2
+ <div class="em-grid" @click="showHide = false">
3
3
  <van-grid v-bind="$attrs" v-on="$listeners" :column-num="columnNum">
4
4
  <van-grid-item
5
5
  v-bind="item"
6
6
  :class="{ 'em-grid-ellipsis': textEllipsis }"
7
7
  :style="`width:${100 / columnNum}%;`"
8
- @click="goView($event, item)"
9
- v-show="$attrs.data && $attrs.data.length > 0"
10
- v-for="(item, index) of $attrs.data"
8
+ @click.stop="goView($event, item)"
9
+ v-show="newData && newData.length > 0"
10
+ v-for="(item, index) of newData"
11
11
  :key="index"
12
- />
13
- <slot v-show="$attrs.data && $attrs.data.length == 0" />
12
+ >
13
+ <i
14
+ class="van-icon van-grid-item__icon"
15
+ :class="
16
+ item.icon.startsWith('http') && item.icon.indexOf('/') != -1
17
+ ? ''
18
+ : `van-icon-${item.icon}`
19
+ "
20
+ :style="{ size: item.iconSize ? item.iconSize : '' }"
21
+ >
22
+ <img
23
+ v-if="item.icon.startsWith('http') || item.icon.indexOf('/') != -1"
24
+ class="van-icon__image"
25
+ :src="item.icon"
26
+ :style="{
27
+ width: item.iconSize ? item.iconSize : '',
28
+ height: item.iconSize ? item.iconSize : ''
29
+ }"
30
+ />
31
+ <div
32
+ v-show="item.dot"
33
+ :style="{ background: item.dotColor || '' }"
34
+ class="van-info van-info--dot"
35
+ ></div>
36
+ <div
37
+ class="van-info"
38
+ :style="{ background: badgeColor || '' }"
39
+ v-show="item.badge"
40
+ >
41
+ {{
42
+ maxBadge &&
43
+ !isNaN(item.badge) &&
44
+ Number(maxBadge) < Number(item.badge)
45
+ ? maxBadge + '+'
46
+ : item.badge
47
+ }}
48
+ </div>
49
+ </i>
50
+ <span class="van-grid-item__text">{{ item.text }}</span>
51
+ <van-icon
52
+ v-if="showHide && item.menuType != 'add'"
53
+ @click.stop="handleHide(item)"
54
+ name="clear"
55
+ size="20px"
56
+ class="em-grid-del"
57
+ />
58
+ <div v-if="item.showMenu" class="em-grid-select-box">
59
+ <van-icon size="30px" color="#fff" name="success" />
60
+ </div>
61
+ </van-grid-item>
62
+ <slot v-show="newData && newData.length == 0" />
14
63
  </van-grid>
64
+ <em-popup style="width:80%;height:80%" v-if="show" v-model="show">
65
+ <div class="em-grid-popup">
66
+ <p class="em-grid-popup-label">添加菜单</p>
67
+ <em-grid
68
+ class="em-grid-popup-content"
69
+ :data="hideMenuList"
70
+ v-bind="$attrs"
71
+ :border="false"
72
+ :column-num="$attrs.columnNum"
73
+ @click="selectMenu"
74
+ />
75
+ <div class="em-grid-popup-button">
76
+ <em-button round style="width:49%" @click="show = false"
77
+ >取消</em-button
78
+ >
79
+ <em-button
80
+ round
81
+ style="width:49%"
82
+ type="primary"
83
+ @click="handleShowMenu"
84
+ >确认</em-button
85
+ >
86
+ </div>
87
+ </div>
88
+ </em-popup>
15
89
  </div>
16
90
  </template>
17
91
 
@@ -20,6 +94,10 @@ export default {
20
94
  name: 'EmGrid',
21
95
  inheritAttrs: false,
22
96
  props: {
97
+ data: {
98
+ type: Array,
99
+ default: () => []
100
+ },
23
101
  columnNum: {
24
102
  type: [Number, String],
25
103
  default: 4
@@ -31,12 +109,178 @@ export default {
31
109
  targetStop: {
32
110
  type: Boolean,
33
111
  default: true
112
+ },
113
+ badgeColor: {
114
+ type: String,
115
+ default: ''
116
+ },
117
+ maxBadge: {
118
+ type: String,
119
+ default: ''
120
+ },
121
+ isHideMenu: {
122
+ type: Boolean,
123
+ default: false
124
+ },
125
+ hideMenuKey: {
126
+ type: String,
127
+ default: 'id'
128
+ },
129
+ hideMenu: {
130
+ type: [String, Array],
131
+ default: () => []
132
+ },
133
+ addMenuIcon: {
134
+ type: String,
135
+ default: 'plus'
136
+ },
137
+ addMenuIconSize: {
138
+ type: String,
139
+ default: ''
140
+ }
141
+ },
142
+ data() {
143
+ return {
144
+ lastTapTime: 0,
145
+ timer: null,
146
+ showHide: false,
147
+ newData: [],
148
+ show: false,
149
+ selectMenuArr: [],
150
+ hideMenuList: []
151
+ };
152
+ },
153
+ watch: {
154
+ hideMenu: {
155
+ handler(val) {
156
+ this.defaultHide(val);
157
+ },
158
+ deep: true,
159
+ immediate: true
160
+ },
161
+ data: {
162
+ handler(val) {
163
+ this.newData = JSON.parse(JSON.stringify(val));
164
+ this.defaultHide(this.hideMenu);
165
+ },
166
+ deep: true,
167
+ immediate: true
34
168
  }
35
169
  },
36
170
  methods: {
171
+ hideDelIcon() {
172
+ this.showHide = false;
173
+ },
174
+ handleShowMenu() {
175
+ let str = this.selectMenuArr.join(',');
176
+ if (Array.isArray(this.hideMenu)) {
177
+ let hideArr = this.hideMenuList.filter(
178
+ x => str.indexOf(x[this.hideMenuKey]) == -1
179
+ );
180
+ this.$emit('hide', hideArr);
181
+ } else {
182
+ let hide = this.hideMenuList.filter(x => str.indexOf(x[this.hideMenuKey]) == -1 );
183
+ hide = hide.map(x => x[this.hideMenuKey])
184
+ this.$emit('hide', hide.join(','));
185
+ }
186
+ this.selectMenuArr = [];
187
+ this.show = false;
188
+ },
189
+ selectMenu(val) {
190
+ if (val.showMenu) {
191
+ this.selectMenuArr = this.selectMenuArr.filter(
192
+ x => x != val[this.hideMenuKey]
193
+ );
194
+ } else {
195
+ this.selectMenuArr.push(val[this.hideMenuKey]);
196
+ }
197
+ this.$set(val, 'showMenu', !val.showMenu);
198
+ },
199
+ defaultHide(val) {
200
+ if (this.isHideMenu && val != undefined) {
201
+ if (Array.isArray(val)) {
202
+ let menuKey = val.map(x => x.id).join(',');
203
+ this.newData = this.data.filter(
204
+ x => menuKey.indexOf(x[this.hideMenuKey]) == -1
205
+ );
206
+ this.hideMenuList = this.data.filter(
207
+ x => menuKey.indexOf(x[this.hideMenuKey]) != -1
208
+ );
209
+ } else {
210
+ val = val + '';
211
+ this.newData = this.data.filter(
212
+ x => val.indexOf(x[this.hideMenuKey]) == -1
213
+ );
214
+ this.hideMenuList = this.data.filter(
215
+ x => val.indexOf(x[this.hideMenuKey]) != -1
216
+ );
217
+ }
218
+ }
219
+ if (
220
+ this.isHideMenu != undefined &&
221
+ (this.newData.length > 0 &&
222
+ this.newData[this.newData.length - 1].menuType === 'add'
223
+ ? this.newData.length - 1 < this.data.length
224
+ : this.newData.length < this.data.length)
225
+ ) {
226
+ this.newData.push({
227
+ icon: this.addMenuIcon || 'plus',
228
+ iconSize: this.addMenuIconSize,
229
+ menuType: 'add'
230
+ });
231
+ }
232
+ },
233
+ handleHide(item) {
234
+ this.$dialog
235
+ .confirm({
236
+ message: `确定要隐藏<span style="color:red;font-weight:bold;margin:0px 5px">${
237
+ item.text
238
+ }</span>菜单吗?`
239
+ })
240
+ .then(() => {
241
+ if (Array.isArray(this.hideMenu)) {
242
+ let hideArr = [...this.hideMenu, item];
243
+ this.$emit('hide', hideArr);
244
+ } else {
245
+ let hideStr = this.hideMenu
246
+ ? this.hideMenu + ',' + item[this.hideMenuKey]
247
+ : item[this.hideMenuKey];
248
+ this.$emit('hide', hideStr);
249
+ }
250
+ });
251
+ },
37
252
  goView(event, val) {
38
- this.$emit('click', val);
39
- this.targetStop && event.stopPropagation();
253
+ if (val.menuType === 'add') {
254
+ this.show = true;
255
+ return;
256
+ }
257
+ const currentTime = new Date().getTime();
258
+ const tapLength = currentTime - this.lastTapTime;
259
+ this.lastTapTime = currentTime;
260
+ if (this.isHideMenu) {
261
+ if (tapLength < 500) {
262
+ this.handleDoubleClick(val);
263
+ clearTimeout(this.timer);
264
+ return;
265
+ }
266
+ if (this.showHide) {
267
+ this.showHide = false;
268
+ return;
269
+ }
270
+ this.timer = setTimeout(() => {
271
+ this.$emit('click', val, event);
272
+ this.targetStop && event.stopPropagation();
273
+ }, 500);
274
+ } else {
275
+ this.$emit('click', val, event);
276
+ this.targetStop && event.stopPropagation();
277
+ }
278
+ },
279
+ handleDoubleClick(val) {
280
+ if (this.isHideMenu) {
281
+ this.showHide = true;
282
+ }
283
+ this.$emit('dbclick', val);
40
284
  }
41
285
  }
42
286
  };
@@ -0,0 +1 @@
1
+ .em-grid-popup,.em-grid-popup-button{display:-webkit-box;display:-ms-flexbox}.em-grid-del{position:absolute;top:5px;right:5px}.em-grid-popup{padding:10px;height:100%;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.em-grid-popup-label{text-align:center;font-size:16px;color:#000;font-weight:700;margin-bottom:10px}.em-grid-popup-content{-webkit-box-flex:1;-ms-flex:1;flex:1;overflow-y:auto}.em-grid-popup-button{display:flex;-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between;margin-top:10px}.em-grid-select-box{position:absolute;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.6);display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.em-grid .van-popup{border-radius:5px}