@10yun/cv-mobile-ui 0.4.6 → 0.4.8

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.
@@ -1,178 +1,185 @@
1
1
  <template>
2
- <view v-if="visibleSync" :class="{ 'uni-drawer--visible': showDrawer }" class="uni-drawer" @touchmove.stop.prevent="clear">
3
- <view class="uni-drawer__mask" :class="{ 'uni-drawer__mask--visible': showDrawer && mask }" @tap="close('mask')" />
4
- <view class="uni-drawer__content" :class="{'uni-drawer--right': rightMode,'uni-drawer--left': !rightMode, 'uni-drawer__content--visible': showDrawer}" :style="{width:drawerWidth+'px'}">
5
- <slot />
6
- </view>
7
- <!-- #ifdef H5 -->
8
- <keypress @esc="close('mask')" />
9
- <!-- #endif -->
10
- </view>
2
+ <view v-if="visibleSync" :class="{ 'uni-drawer--visible': showDrawer }" class="uni-drawer" @touchmove.stop.prevent="clear">
3
+ <view class="uni-drawer__mask" :class="{ 'uni-drawer__mask--visible': showDrawer && mask }" @tap="close('mask')" />
4
+ <view
5
+ class="uni-drawer__content"
6
+ :class="{ 'uni-drawer--right': rightMode, 'uni-drawer--left': !rightMode, 'uni-drawer__content--visible': showDrawer }"
7
+ :style="{ width: drawerWidth + 'px' }"
8
+ >
9
+ <slot />
10
+ </view>
11
+ <!-- #ifdef H5 -->
12
+ <keypress @esc="close('mask')" />
13
+ <!-- #endif -->
14
+ </view>
11
15
  </template>
12
16
 
13
17
  <script>
14
- // #ifdef H5
15
- import keypress from './keypress.js'
16
- // #endif
17
- /**
18
- * Drawer 抽屉
19
- * @description 抽屉侧滑菜单
20
- * @tutorial https://ext.dcloud.net.cn/plugin?id=26
21
- * @property {Boolean} mask = [true | false] 是否显示遮罩
22
- * @property {Boolean} maskClick = [true | false] 点击遮罩是否关闭
23
- * @property {Boolean} mode = [left | right] Drawer 滑出位置
24
- * @value left 从左侧滑出
25
- * @value right 从右侧侧滑出
26
- * @property {Number} width 抽屉的宽度 ,仅 vue 页面生效
27
- * @event {Function} close 组件关闭时触发事件
28
- */
29
- export default {
30
- name: 'UniDrawer',
31
- components: {
32
- // #ifdef H5
33
- keypress
34
- // #endif
35
- },
36
- emits: ['change'],
37
- props: {
38
- /**
39
- * 显示模式(左、右),只在初始化生效
40
- */
41
- mode: {
42
- type: String,
43
- default: ''
44
- },
45
- /**
46
- * 蒙层显示状态
47
- */
48
- mask: {
49
- type: Boolean,
50
- default: true
51
- },
52
- /**
53
- * 遮罩是否可点击关闭
54
- */
55
- maskClick: {
56
- type: Boolean,
57
- default: true
58
- },
59
- /**
60
- * 抽屉宽度
61
- */
62
- width: {
63
- type: Number,
64
- default: 220
65
- }
66
- },
67
- data() {
68
- return {
69
- visibleSync: false,
70
- showDrawer: false,
71
- rightMode: false,
72
- watchTimer: null,
73
- drawerWidth: 220
74
- }
75
- },
76
- created() {
77
- // #ifndef APP-NVUE
78
- this.drawerWidth = this.width
79
- // #endif
80
- this.rightMode = this.mode === 'right'
81
- },
82
- methods: {
83
- clear() {},
84
- close(type) {
85
- // fixed by mehaotian 抽屉尚未完全关闭或遮罩禁止点击时不触发以下逻辑
86
- if ((type === 'mask' && !this.maskClick) || !this.visibleSync) return
87
- this._change('showDrawer', 'visibleSync', false)
88
- },
89
- open() {
90
- // fixed by mehaotian 处理重复点击打开的事件
91
- if (this.visibleSync) return
92
- this._change('visibleSync', 'showDrawer', true)
93
- },
94
- _change(param1, param2, status) {
95
- this[param1] = status
96
- if (this.watchTimer) {
97
- clearTimeout(this.watchTimer)
98
- }
99
- this.watchTimer = setTimeout(() => {
100
- this[param2] = status
101
- this.$emit('change', status)
102
- }, status ? 50 : 300)
103
- }
104
- }
105
- }
18
+ // #ifdef H5
19
+ import keypress from './keypress.js';
20
+ // #endif
21
+ /**
22
+ * Drawer 抽屉
23
+ * @description 抽屉侧滑菜单
24
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=26
25
+ * @property {Boolean} mask = [true | false] 是否显示遮罩
26
+ * @property {Boolean} maskClick = [true | false] 点击遮罩是否关闭
27
+ * @property {Boolean} mode = [left | right] Drawer 滑出位置
28
+ * @value left 从左侧滑出
29
+ * @value right 从右侧侧滑出
30
+ * @property {Number} width 抽屉的宽度 ,仅 vue 页面生效
31
+ * @event {Function} close 组件关闭时触发事件
32
+ */
33
+ export default {
34
+ name: 'UniDrawer',
35
+ components: {
36
+ // #ifdef H5
37
+ keypress
38
+ // #endif
39
+ },
40
+ emits: ['change'],
41
+ props: {
42
+ /**
43
+ * 显示模式(左、右),只在初始化生效
44
+ */
45
+ mode: {
46
+ type: String,
47
+ default: ''
48
+ },
49
+ /**
50
+ * 蒙层显示状态
51
+ */
52
+ mask: {
53
+ type: Boolean,
54
+ default: true
55
+ },
56
+ /**
57
+ * 遮罩是否可点击关闭
58
+ */
59
+ maskClick: {
60
+ type: Boolean,
61
+ default: true
62
+ },
63
+ /**
64
+ * 抽屉宽度
65
+ */
66
+ width: {
67
+ type: Number,
68
+ default: 220
69
+ }
70
+ },
71
+ data() {
72
+ return {
73
+ visibleSync: false,
74
+ showDrawer: false,
75
+ rightMode: false,
76
+ watchTimer: null,
77
+ drawerWidth: 220
78
+ };
79
+ },
80
+ created() {
81
+ // #ifndef APP-NVUE
82
+ this.drawerWidth = this.width;
83
+ // #endif
84
+ this.rightMode = this.mode === 'right';
85
+ },
86
+ methods: {
87
+ clear() {},
88
+ close(type) {
89
+ // fixed by mehaotian 抽屉尚未完全关闭或遮罩禁止点击时不触发以下逻辑
90
+ if ((type === 'mask' && !this.maskClick) || !this.visibleSync) return;
91
+ this._change('showDrawer', 'visibleSync', false);
92
+ },
93
+ open() {
94
+ // fixed by mehaotian 处理重复点击打开的事件
95
+ if (this.visibleSync) return;
96
+ this._change('visibleSync', 'showDrawer', true);
97
+ },
98
+ _change(param1, param2, status) {
99
+ this[param1] = status;
100
+ if (this.watchTimer) {
101
+ clearTimeout(this.watchTimer);
102
+ }
103
+ this.watchTimer = setTimeout(
104
+ () => {
105
+ this[param2] = status;
106
+ this.$emit('change', status);
107
+ },
108
+ status ? 50 : 300
109
+ );
110
+ }
111
+ }
112
+ };
106
113
  </script>
107
114
 
108
115
  <style scoped>
109
- .uni-drawer {
110
- /* #ifndef APP-NVUE */
111
- display: block;
112
- /* #endif */
113
- position: fixed;
114
- top: 0;
115
- left: 0;
116
- right: 0;
117
- bottom: 0;
118
- overflow: hidden;
119
- z-index: 999;
120
- }
116
+ .uni-drawer {
117
+ /* #ifndef APP-NVUE */
118
+ display: block;
119
+ /* #endif */
120
+ position: fixed;
121
+ top: 0;
122
+ left: 0;
123
+ right: 0;
124
+ bottom: 0;
125
+ overflow: hidden;
126
+ z-index: 999;
127
+ }
121
128
 
122
- .uni-drawer__content {
123
- /* #ifndef APP-NVUE */
124
- display: block;
125
- /* #endif */
126
- position: absolute;
127
- top: 0;
128
- width: 220px;
129
- bottom: 0;
130
- background-color: #ffffff;
131
- transition: transform 0.3s ease;
132
- }
129
+ .uni-drawer__content {
130
+ /* #ifndef APP-NVUE */
131
+ display: block;
132
+ /* #endif */
133
+ position: absolute;
134
+ top: 0;
135
+ width: 220px;
136
+ bottom: 0;
137
+ background-color: #ffffff;
138
+ transition: transform 0.3s ease;
139
+ }
133
140
 
134
- .uni-drawer--left {
135
- left: 0;
136
- /* #ifdef APP-NVUE */
137
- transform: translateX(-220px);
138
- /* #endif */
139
- /* #ifndef APP-NVUE */
140
- transform: translateX(-100%);
141
- /* #endif */
142
- }
141
+ .uni-drawer--left {
142
+ left: 0;
143
+ /* #ifdef APP-NVUE */
144
+ transform: translateX(-220px);
145
+ /* #endif */
146
+ /* #ifndef APP-NVUE */
147
+ transform: translateX(-100%);
148
+ /* #endif */
149
+ }
143
150
 
144
- .uni-drawer--right {
145
- right: 0;
146
- /* #ifdef APP-NVUE */
147
- transform: translateX(220px);
148
- /* #endif */
149
- /* #ifndef APP-NVUE */
150
- transform: translateX(100%);
151
- /* #endif */
152
- }
151
+ .uni-drawer--right {
152
+ right: 0;
153
+ /* #ifdef APP-NVUE */
154
+ transform: translateX(220px);
155
+ /* #endif */
156
+ /* #ifndef APP-NVUE */
157
+ transform: translateX(100%);
158
+ /* #endif */
159
+ }
153
160
 
154
- .uni-drawer__content--visible {
155
- transform: translateX(0px);
156
- }
161
+ .uni-drawer__content--visible {
162
+ transform: translateX(0px);
163
+ }
157
164
 
158
- .uni-drawer__mask {
159
- /* #ifndef APP-NVUE */
160
- display: block;
161
- /* #endif */
162
- opacity: 0;
163
- position: absolute;
164
- top: 0;
165
- left: 0;
166
- bottom: 0;
167
- right: 0;
168
- background-color: rgba(0, 0, 0, 0.4);
169
- transition: opacity 0.3s;
170
- }
165
+ .uni-drawer__mask {
166
+ /* #ifndef APP-NVUE */
167
+ display: block;
168
+ /* #endif */
169
+ opacity: 0;
170
+ position: absolute;
171
+ top: 0;
172
+ left: 0;
173
+ bottom: 0;
174
+ right: 0;
175
+ background-color: rgba(0, 0, 0, 0.4);
176
+ transition: opacity 0.3s;
177
+ }
171
178
 
172
- .uni-drawer__mask--visible {
173
- /* #ifndef APP-NVUE */
174
- display: block;
175
- /* #endif */
176
- opacity: 1;
177
- }
178
- </style>
179
+ .uni-drawer__mask--visible {
180
+ /* #ifndef APP-NVUE */
181
+ display: block;
182
+ /* #endif */
183
+ opacity: 1;
184
+ }
185
+ </style>
@@ -7,7 +7,7 @@ export default {
7
7
  default: false
8
8
  }
9
9
  },
10
- mounted () {
10
+ mounted() {
11
11
  const keyNames = {
12
12
  esc: ['Esc', 'Escape'],
13
13
  tab: 'Tab',
@@ -18,28 +18,28 @@ export default {
18
18
  right: ['Right', 'ArrowRight'],
19
19
  down: ['Down', 'ArrowDown'],
20
20
  delete: ['Backspace', 'Delete', 'Del']
21
- }
21
+ };
22
22
  const listener = ($event) => {
23
23
  if (this.disable) {
24
- return
24
+ return;
25
25
  }
26
- const keyName = Object.keys(keyNames).find(key => {
27
- const keyName = $event.key
28
- const value = keyNames[key]
29
- return value === keyName || (Array.isArray(value) && value.includes(keyName))
30
- })
26
+ const keyName = Object.keys(keyNames).find((key) => {
27
+ const keyName = $event.key;
28
+ const value = keyNames[key];
29
+ return value === keyName || (Array.isArray(value) && value.includes(keyName));
30
+ });
31
31
  if (keyName) {
32
32
  // 避免和其他按键事件冲突
33
33
  setTimeout(() => {
34
- this.$emit(keyName, {})
35
- }, 0)
34
+ this.$emit(keyName, {});
35
+ }, 0);
36
36
  }
37
- }
38
- document.addEventListener('keyup', listener)
37
+ };
38
+ document.addEventListener('keyup', listener);
39
39
  // this.$once('hook:beforeDestroy', () => {
40
40
  // document.removeEventListener('keyup', listener)
41
41
  // })
42
42
  },
43
- render: () => {}
44
- }
43
+ render: () => {}
44
+ };
45
45
  // #endif
@@ -1,26 +1,23 @@
1
-
2
- export default {
3
- data() {
4
- return {
5
-
6
- }
7
- },
8
- created(){
9
- this.popup = this.getParent()
10
- },
11
- methods:{
12
- /**
13
- * 获取父元素实例
14
- */
15
- getParent(name = 'uniPopup') {
16
- let parent = this.$parent;
17
- let parentName = parent.$options.name;
18
- while (parentName !== name) {
19
- parent = parent.$parent;
20
- if (!parent) return false
21
- parentName = parent.$options.name;
22
- }
23
- return parent;
24
- },
25
- }
26
- }
1
+ export default {
2
+ data() {
3
+ return {};
4
+ },
5
+ created() {
6
+ this.popup = this.getParent();
7
+ },
8
+ methods: {
9
+ /**
10
+ * 获取父元素实例
11
+ */
12
+ getParent(name = 'uniPopup') {
13
+ let parent = this.$parent;
14
+ let parentName = parent.$options.name;
15
+ while (parentName !== name) {
16
+ parent = parent.$parent;
17
+ if (!parent) return false;
18
+ parentName = parent.$options.name;
19
+ }
20
+ return parent;
21
+ }
22
+ }
23
+ };