lius
2023-06-08 c66a22e4b6bb02667a5000f2e04aeb4ef5ae44c2
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
<template>
  <a-date-picker
    dropdownClassName="j-date-picker"
    :disabled="disabled || readOnly"
    :placeholder="placeholder"
    @change="handleDateChange"
    :value="momVal"
    :showTime="showTime"
    :format="dateFormat"
    :getCalendarContainer="getCalendarContainer"
    v-bind="$attrs"/>
</template>
<script>
import moment from 'moment'
export default {
  name: 'JDate',
  props: {
    placeholder:{
      type: String,
      default: '',
      required: false
    },
    value:{
      type: String,
      required: false
    },
    dateFormat:{
      type: String,
      default: 'YYYY-MM-DD',
      required: false
    },
    //此属性可以被废弃了
    triggerChange:{
      type: Boolean,
      required: false,
      default: false
    },
    readOnly:{
      type: Boolean,
      required: false,
      default: false
    },
    disabled:{
      type: Boolean,
      required: false,
      default: false
    },
    showTime:{
      type: Object,
      required: {},
      default: {}
    },
    getCalendarContainer: {
      type: Function,
      default: (node) => node.parentNode
    }
  },
  data () {
    let dateStr = this.value;
    return {
      decorator:"",
      momVal:!dateStr?null:moment(dateStr,this.dateFormat)
    }
  },
  watch: {
    value (val) {
      if(!val){
        this.momVal = null
      }else{
        this.momVal = moment(val,this.dateFormat)
      }
    }
  },
  methods: {
    moment,
    handleDateChange(mom,dateStr){
      this.$emit('change', dateStr);
    }
  },
  //2.2新增 在组件内定义 指定父组件调用时候的传值属性和事件类型 这个牛逼
  model: {
    prop: 'value',
    event: 'change'
  }
}
</script>