Blame view

src/components/UniPopup/uni-popup-dialog.vue 4.94 KB
863d3aa95   BigBoss   新增验光数据页面
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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
  <template>
  	<view class="uni-popup-dialog">
  		<view class="uni-dialog-title">
  			<text class="uni-dialog-title-text" :class="['uni-popup__'+dialogType]">{{title}}</text>
  		</view>
  		<view class="uni-dialog-content">
  			<text class="uni-dialog-content-text" v-if="mode === 'base'">{{content}}</text>
  			<input v-else class="uni-dialog-input" v-model="val" type="text" :placeholder="placeholder" :focus="focus" >
  		</view>
  		<view class="uni-dialog-button-group">
  			<view class="uni-dialog-button" @click="close">
  				<text class="uni-dialog-button-text">取消</text>
  			</view>
  			<view class="uni-dialog-button uni-border-left" @click="onOk">
  				<text class="uni-dialog-button-text uni-button-color">确定</text>
  			</view>
  		</view>
  
  	</view>
  </template>
  
  <script>
  	/**
  	 * PopUp 弹出层-对话框样式
  	 * @description 弹出层-对话框样式
  	 * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  	 * @property {String} value input 模式下的默认值
  	 * @property {String} placeholder input 模式下输入提示
  	 * @property {String} type = [success|warning|info|error] 主题样式
  	 *  @value success 成功
  	 * 	@value warning 提示
  	 * 	@value info 消息
  	 * 	@value error 错误
  	 * @property {String} mode = [base|input] 模式、
  	 * 	@value base 基础对话框
  	 * 	@value input 可输入对话框
  	 * @property {String} content 对话框内容
  	 * @property {Boolean} beforeClose 是否拦截取消事件
  	 * @event {Function} confirm 点击确认按钮触发
  	 * @event {Function} close 点击取消按钮触发
  	 */
  
  	export default {
  		name: "uniPopupDialog",
  		props: {
  			value: {
  				type: [String, Number],
  				default: ''
  			},
  			placeholder: {
  				type: [String, Number],
  				default: '请输入内容'
  			},
  			/**
  			 * 对话框主题 success/warning/info/error	  默认 success
  			 */
  			type: {
  				type: String,
  				default: 'error'
  			},
  			/**
  			 * 对话框模式 base/input
  			 */
  			mode: {
  				type: String,
  				default: 'base'
  			},
  			/**
  			 * 对话框标题
  			 */
  			title: {
  				type: String,
  				default: '提示'
  			},
  			/**
  			 * 对话框内容
  			 */
  			content: {
  				type: String,
  				default: ''
  			},
  			/**
  			 * 拦截取消事件 ,如果拦截取消事件,必须监听close事件,执行 done()
  			 */
  			beforeClose: {
  				type: Boolean,
  				default: false
  			}
  		},
  		data() {
  			return {
  				dialogType: 'error',
  				focus: false,
  				val: ""
  			}
  		},
  		inject: ['popup'],
  		watch: {
  			type(val) {
  				this.dialogType = val
  			},
  			mode(val) {
  				if (val === 'input') {
  					this.dialogType = 'info'
  				}
  			},
  			value(val) {
  				this.val = val
  			}
  		},
  		created() {
  			// 对话框遮罩不可点击
  			this.popup.mkclick = false
  			if (this.mode === 'input') {
  				this.dialogType = 'info'
  				this.val = this.value
  			} else {
  				this.dialogType = this.type
  			}
  		},
  		mounted() {
  			this.focus = true
  		},
  		methods: {
  			/**
  			 * 点击确认按钮
  			 */
  			onOk() {
  				this.$emit('confirm', () => {
  					this.popup.close()
  					if (this.mode === 'input') this.val = this.value
  				}, this.mode === 'input' ? this.val : '')
  			},
  			/**
  			 * 点击取消按钮
  			 */
  			close() {
  				if (this.beforeClose) {
  					this.$emit('close', () => {
  						this.popup.close()
  					})
  					return
  				}
  				this.popup.close()
  			}
  		}
  	}
  </script>
  
  <style lang="scss" scoped>
  	.uni-popup-dialog {
  		width: 300px;
  		border-radius: 15px;
  		background-color: #fff;
  	}
  
  	.uni-dialog-title {
  		/* #ifndef APP-NVUE */
  		display: flex;
  		/* #endif */
  		flex-direction: row;
  		justify-content: center;
  		padding-top: 15px;
  		padding-bottom: 5px;
  	}
  
  	.uni-dialog-title-text {
  		font-size: 16px;
  		font-weight: 500;
  	}
  
  	.uni-dialog-content {
  		/* #ifndef APP-NVUE */
  		display: flex;
  		/* #endif */
  		flex-direction: row;
  		justify-content: center;
  		align-items: center;
  		padding: 5px 15px 15px 15px;
  	}
  
  	.uni-dialog-content-text {
  		font-size: 14px;
  		color: #6e6e6e;
  	}
  
  	.uni-dialog-button-group {
  		/* #ifndef APP-NVUE */
  		display: flex;
  		/* #endif */
  		flex-direction: row;
  		border-top-color: #f5f5f5;
  		border-top-style: solid;
  		border-top-width: 1px;
  	}
  
  	.uni-dialog-button {
  		/* #ifndef APP-NVUE */
  		display: flex;
  		/* #endif */
  
  		flex: 1;
  		flex-direction: row;
  		justify-content: center;
  		align-items: center;
  		height: 45px;
  	}
  
  	.uni-border-left {
  		border-left-color: #f0f0f0;
  		border-left-style: solid;
  		border-left-width: 1px;
  	}
  
  	.uni-dialog-button-text {
  		font-size: 14px;
  	}
  
  	.uni-button-color {
  		color: $uni-color-primary;
  	}
  
  	.uni-dialog-input {
  		flex: 1;
  		font-size: 14px;
  	}
  
  	.uni-popup__success {
  		color: $uni-color-success;
  	}
  
  	.uni-popup__warn {
  		color: $uni-color-warning;
  	}
  
  	.uni-popup__error {
  		color: $uni-color-error;
  	}
  
  	.uni-popup__info {
  		color: #909399;
  	}
  </style>