Skip to content

Commit 11fb502

Browse files
committed
添加disabled属性
1 parent ec05fc5 commit 11fb502

7 files changed

+42
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default {
6666
| first-day-of-week | Number | 7 | set the first day of week (1-7) |
6767
| input-class | String | 'mx-input' | the input class name |
6868
| confirm-text | String | 'OK' | the default text to display on confirm button |
69+
| disabled | Boolean | false | Disable the component |
6970

7071
#### shortcuts
7172
* true - show the default shortcuts

README_CN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export default {
6565
| minute-step | Number | 0 | 分钟的步进,设置time-picker-options,这项无效
6666
| first-day-of-week | Number | 7 | 设置日历星期几开头(1-7)
6767
| input-class | String | 'mx-input' | 自定义输入框的类名
68-
| confirm-text | String | 'OK' | 确认按钮的名称
68+
| confirm-text | String | 'OK' | 确认按钮的名称
69+
| disabled | Boolean | false | 禁用组件
6970

7071
#### shortcuts
7172
* true - 显示默认快捷选择

datepicker/calendar-panel.vue

+8
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,20 @@ export default {
432432
const now = new Date(this.now)
433433
now.setFullYear(year)
434434
this.now = now
435+
if (this.value) {
436+
this.$emit('input', now)
437+
this.$emit('select', true)
438+
}
435439
this.currentPanel = 'months'
436440
},
437441
selectMonth(month) {
438442
const now = new Date(this.now)
439443
now.setMonth(month)
440444
this.now = now
445+
if (this.value) {
446+
this.$emit('input', now)
447+
this.$emit('select', true)
448+
}
441449
this.currentPanel = 'date'
442450
},
443451
selectTime(value, index) {

datepicker/index.vue

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<template>
22
<div class="mx-datepicker"
3+
:class="{'disabled': disabled}"
34
:style="{'width': width + 'px','min-width':range ? (type === 'datetime' ? '320px' : '210px') : '140px'}"
45
v-clickoutside="closePopup">
56
<input readonly
7+
name="date"
8+
:disabled="disabled"
69
:class="inputClass"
710
:value="text"
811
:placeholder="innerPlaceholder"
912
ref="input"
13+
@mouseenter="hoverIcon"
14+
@mouseleave="hoverIcon"
1015
@click="togglePopup"
1116
@mousedown="$event.preventDefault()">
1217
<i class="mx-input-icon"
@@ -120,6 +125,10 @@ export default {
120125
confirmText: {
121126
type: String,
122127
default: 'OK'
128+
},
129+
disabled: {
130+
type: Boolean,
131+
default: false
123132
}
124133
},
125134
data() {
@@ -186,10 +195,10 @@ export default {
186195
this.closePopup()
187196
this.$emit('confirm', this.currentValue)
188197
},
189-
selectDate() {
190-
if (!this.confirm) {
198+
selectDate(show = false) {
199+
if (!this.confirm && !this.disabled) {
191200
this.updateDate()
192-
if (this.type === 'date' && !this.range) {
201+
if (!show && this.type === 'date' && !this.range) {
193202
this.closePopup()
194203
}
195204
}
@@ -207,6 +216,9 @@ export default {
207216
}
208217
},
209218
hoverIcon(e) {
219+
if (this.disabled) {
220+
return
221+
}
210222
if (e.type === 'mouseenter' && this.text) {
211223
this.showCloseIcon = true
212224
}
@@ -215,6 +227,9 @@ export default {
215227
}
216228
},
217229
clickIcon() {
230+
if (this.disabled) {
231+
return
232+
}
218233
if (this.showCloseIcon) {
219234
this.$emit('input', '')
220235
} else {
@@ -297,6 +312,9 @@ export default {
297312
}
298313
},
299314
displayPopup() {
315+
if (this.disabled) {
316+
return
317+
}
300318
const dw = document.documentElement.clientWidth
301319
const dh = document.documentElement.clientHeight
302320
const InputRect = this.$el.getBoundingClientRect()
@@ -360,6 +378,10 @@ export default {
360378
* {
361379
box-sizing: border-box;
362380
}
381+
&.disabled {
382+
opacity: 0.7;
383+
cursor: not-allowed;
384+
}
363385
}
364386
.mx-datepicker-popup {
365387
position: absolute;
@@ -387,6 +409,10 @@ export default {
387409
border: 1px solid #ccc;
388410
border-radius: 4px;
389411
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
412+
&:disabled, &.disabled {
413+
opacity: 0.7;
414+
cursor: not-allowed;
415+
}
390416
}
391417
392418
.mx-input-icon {

dist/build.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
88
"demo": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.demo.config.js",
9-
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.build.config.js"
9+
"deploy": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.deploy.config.js"
1010
},
1111
"repository": {
1212
"type": "git",
File renamed without changes.

0 commit comments

Comments
 (0)