mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-25 02:20:37 +03:00
添加disabled属性
This commit is contained in:
@@ -66,6 +66,7 @@ export default {
|
|||||||
| first-day-of-week | Number | 7 | set the first day of week (1-7) |
|
| first-day-of-week | Number | 7 | set the first day of week (1-7) |
|
||||||
| input-class | String | 'mx-input' | the input class name |
|
| input-class | String | 'mx-input' | the input class name |
|
||||||
| confirm-text | String | 'OK' | the default text to display on confirm button |
|
| confirm-text | String | 'OK' | the default text to display on confirm button |
|
||||||
|
| disabled | Boolean | false | Disable the component |
|
||||||
|
|
||||||
#### shortcuts
|
#### shortcuts
|
||||||
* true - show the default shortcuts
|
* true - show the default shortcuts
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export default {
|
|||||||
| first-day-of-week | Number | 7 | 设置日历星期几开头(1-7)
|
| first-day-of-week | Number | 7 | 设置日历星期几开头(1-7)
|
||||||
| input-class | String | 'mx-input' | 自定义输入框的类名
|
| input-class | String | 'mx-input' | 自定义输入框的类名
|
||||||
| confirm-text | String | 'OK' | 确认按钮的名称
|
| confirm-text | String | 'OK' | 确认按钮的名称
|
||||||
|
| disabled | Boolean | false | 禁用组件
|
||||||
|
|
||||||
#### shortcuts
|
#### shortcuts
|
||||||
* true - 显示默认快捷选择
|
* true - 显示默认快捷选择
|
||||||
|
|||||||
@@ -432,12 +432,20 @@ export default {
|
|||||||
const now = new Date(this.now)
|
const now = new Date(this.now)
|
||||||
now.setFullYear(year)
|
now.setFullYear(year)
|
||||||
this.now = now
|
this.now = now
|
||||||
|
if (this.value) {
|
||||||
|
this.$emit('input', now)
|
||||||
|
this.$emit('select', true)
|
||||||
|
}
|
||||||
this.currentPanel = 'months'
|
this.currentPanel = 'months'
|
||||||
},
|
},
|
||||||
selectMonth(month) {
|
selectMonth(month) {
|
||||||
const now = new Date(this.now)
|
const now = new Date(this.now)
|
||||||
now.setMonth(month)
|
now.setMonth(month)
|
||||||
this.now = now
|
this.now = now
|
||||||
|
if (this.value) {
|
||||||
|
this.$emit('input', now)
|
||||||
|
this.$emit('select', true)
|
||||||
|
}
|
||||||
this.currentPanel = 'date'
|
this.currentPanel = 'date'
|
||||||
},
|
},
|
||||||
selectTime(value, index) {
|
selectTime(value, index) {
|
||||||
|
|||||||
+29
-3
@@ -1,12 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mx-datepicker"
|
<div class="mx-datepicker"
|
||||||
|
:class="{'disabled': disabled}"
|
||||||
:style="{'width': width + 'px','min-width':range ? (type === 'datetime' ? '320px' : '210px') : '140px'}"
|
:style="{'width': width + 'px','min-width':range ? (type === 'datetime' ? '320px' : '210px') : '140px'}"
|
||||||
v-clickoutside="closePopup">
|
v-clickoutside="closePopup">
|
||||||
<input readonly
|
<input readonly
|
||||||
|
name="date"
|
||||||
|
:disabled="disabled"
|
||||||
:class="inputClass"
|
:class="inputClass"
|
||||||
:value="text"
|
:value="text"
|
||||||
:placeholder="innerPlaceholder"
|
:placeholder="innerPlaceholder"
|
||||||
ref="input"
|
ref="input"
|
||||||
|
@mouseenter="hoverIcon"
|
||||||
|
@mouseleave="hoverIcon"
|
||||||
@click="togglePopup"
|
@click="togglePopup"
|
||||||
@mousedown="$event.preventDefault()">
|
@mousedown="$event.preventDefault()">
|
||||||
<i class="mx-input-icon"
|
<i class="mx-input-icon"
|
||||||
@@ -120,6 +125,10 @@ export default {
|
|||||||
confirmText: {
|
confirmText: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'OK'
|
default: 'OK'
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -186,10 +195,10 @@ export default {
|
|||||||
this.closePopup()
|
this.closePopup()
|
||||||
this.$emit('confirm', this.currentValue)
|
this.$emit('confirm', this.currentValue)
|
||||||
},
|
},
|
||||||
selectDate() {
|
selectDate(show = false) {
|
||||||
if (!this.confirm) {
|
if (!this.confirm && !this.disabled) {
|
||||||
this.updateDate()
|
this.updateDate()
|
||||||
if (this.type === 'date' && !this.range) {
|
if (!show && this.type === 'date' && !this.range) {
|
||||||
this.closePopup()
|
this.closePopup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,6 +216,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
hoverIcon(e) {
|
hoverIcon(e) {
|
||||||
|
if (this.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (e.type === 'mouseenter' && this.text) {
|
if (e.type === 'mouseenter' && this.text) {
|
||||||
this.showCloseIcon = true
|
this.showCloseIcon = true
|
||||||
}
|
}
|
||||||
@@ -215,6 +227,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
clickIcon() {
|
clickIcon() {
|
||||||
|
if (this.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (this.showCloseIcon) {
|
if (this.showCloseIcon) {
|
||||||
this.$emit('input', '')
|
this.$emit('input', '')
|
||||||
} else {
|
} else {
|
||||||
@@ -297,6 +312,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
displayPopup() {
|
displayPopup() {
|
||||||
|
if (this.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const dw = document.documentElement.clientWidth
|
const dw = document.documentElement.clientWidth
|
||||||
const dh = document.documentElement.clientHeight
|
const dh = document.documentElement.clientHeight
|
||||||
const InputRect = this.$el.getBoundingClientRect()
|
const InputRect = this.$el.getBoundingClientRect()
|
||||||
@@ -360,6 +378,10 @@ export default {
|
|||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
&.disabled {
|
||||||
|
opacity: 0.7;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.mx-datepicker-popup {
|
.mx-datepicker-popup {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -387,6 +409,10 @@ export default {
|
|||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||||
|
&:disabled, &.disabled {
|
||||||
|
opacity: 0.7;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx-input-icon {
|
.mx-input-icon {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
|
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
|
||||||
"demo": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.demo.config.js",
|
"demo": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.demo.config.js",
|
||||||
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.build.config.js"
|
"deploy": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.deploy.config.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user