Blame view

src/components/uni-drawer/uni-drawer.vue 3.81 KB
0db291810   BigBoss   “-mcomfirmOder页面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  <template>
  	<view v-if="visibleSync" :class="{ 'uni-drawer--visible': showDrawer }" class="uni-drawer" @touchmove.stop.prevent="clear">
  		<view class="uni-drawer__mask" :class="{ 'uni-drawer__mask--visible': showDrawer && mask }" @tap="close('mask')" />
  		<view class="uni-drawer__content" :class="{'uni-drawer--right': rightMode,'uni-drawer--left': !rightMode, 'uni-drawer__content--visible': showDrawer}" :style="{width:drawerWidth+'px'}">
  			<slot />
  		</view>
  	</view>
  </template>
  
  <script>
  	/**
  	 * Drawer 抽屉
  	 * @description 抽屉侧滑菜单
  	 * @tutorial https://ext.dcloud.net.cn/plugin?id=26
  	 * @property {Boolean} mask = [true | false] 是否显示遮罩
  	 * @property {Boolean} maskClick = [true | false] 点击遮罩是否关闭
  	 * @property {Boolean} mode = [left | right] Drawer 滑出位置
  	 * 	@value left 从左侧滑出
4506eedf6   Adam   ss
19
  	 * 	@value right 从右侧侧滑出
0db291810   BigBoss   “-mcomfirmOder页面
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  	 * @property {Number} width 抽屉的宽度 ,仅 vue 页面生效
  	 * @event {Function} close 组件关闭时触发事件
  	 */
  	export default {
  		name: 'UniDrawer',
  		props: {
  			/**
  			 * 显示模式(左、右),只在初始化生效
  			 */
  			mode: {
  				type: String,
  				default: ''
  			},
  			/**
  			 * 蒙层显示状态
  			 */
  			mask: {
  				type: Boolean,
  				default: true
4506eedf6   Adam   ss
39
40
41
42
43
44
45
  			},
  			/**
  			 * 遮罩是否可点击关闭
  			 */
  			maskClick:{
  				type: Boolean,
  				default: true
0db291810   BigBoss   “-mcomfirmOder页面
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  			},
  			/**
  			 * 抽屉宽度
  			 */
  			width: {
  				type: Number,
  				default: 220
  			}
  		},
  		data() {
  			return {
  				visibleSync: false,
  				showDrawer: false,
  				rightMode: false,
  				watchTimer: null,
  				drawerWidth: 220
  			}
  		},
  		created() {
4506eedf6   Adam   ss
65
  			// #ifndef APP-NVUE
0db291810   BigBoss   “-mcomfirmOder页面
66
67
68
69
  			this.drawerWidth = this.width
  			// #endif
  			this.rightMode = this.mode === 'right'
  		},
4506eedf6   Adam   ss
70
  		methods: {
0db291810   BigBoss   “-mcomfirmOder页面
71
  			clear(){},
4506eedf6   Adam   ss
72
73
  			close(type) {
  				// fixed by mehaotian 抽屉尚未完全关闭或遮罩禁止点击时不触发以下逻辑
0db291810   BigBoss   “-mcomfirmOder页面
74
75
76
  				if((type === 'mask' && !this.maskClick) || !this.visibleSync) return
  				this._change('showDrawer', 'visibleSync', false)
  			},
4506eedf6   Adam   ss
77
78
  			open() {
  				// fixed by mehaotian 处理重复点击打开的事件
0db291810   BigBoss   “-mcomfirmOder页面
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
  				if(this.visibleSync) return
  				this._change('visibleSync', 'showDrawer', true)
  			},
  			_change(param1, param2, status) {
  				this[param1] = status
  				if (this.watchTimer) {
  					clearTimeout(this.watchTimer)
  				}
  				this.watchTimer = setTimeout(() => {
  					this[param2] = status
  					this.$emit('change',status)
  				}, status ? 50 : 300)
  			}
  		}
  	}
  </script>
  
  <style lang="scss" scoped>
  	// 抽屉宽度
  	$drawer-width: 220px;
  
  	.uni-drawer {
  		/* #ifndef APP-NVUE */
  		display: block;
  		/* #endif */
  		position: fixed;
  		top: 0;
  		left: 0;
  		right: 0;
  		bottom: 0;
  		overflow: hidden;
  		z-index: 999;
  	}
  
  	.uni-drawer__content {
  		/* #ifndef APP-NVUE */
  		display: block;
  		/* #endif */
  		position: absolute;
  		top: 0;
  		width: $drawer-width;
  		bottom: 0;
  		background-color: $uni-bg-color;
  		transition: transform 0.3s ease;
  	}
  
  	.uni-drawer--left {
  		left: 0;
  		/* #ifdef APP-NVUE */
  		transform: translateX(-$drawer-width);
  		/* #endif */
  		/* #ifndef APP-NVUE */
  		transform: translateX(-100%);
  		/* #endif */
  	}
  
  	.uni-drawer--right {
  		right: 0;
  		/* #ifdef APP-NVUE */
  		transform: translateX($drawer-width);
  		/* #endif */
  		/* #ifndef APP-NVUE */
  		transform: translateX(100%);
  		/* #endif */
  	}
  
  	.uni-drawer__content--visible {
  		transform: translateX(0px);
  	}
  
  
  	.uni-drawer__mask {
  		/* #ifndef APP-NVUE */
  		display: block;
  		/* #endif */
  		opacity: 0;
  		position: absolute;
  		top: 0;
  		left: 0;
  		bottom: 0;
  		right: 0;
  		background-color: $uni-bg-color-mask;
  		transition: opacity 0.3s;
  	}
  
  	.uni-drawer__mask--visible {
  		/* #ifndef APP-NVUE */
  		display: block;
  		/* #endif */
  		opacity: 1;
  	}
4506eedf6   Adam   ss
170
  </style>