index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!--
  2. * @Author: gaoshoujun gaosj@yueworld.cn
  3. * @Date: 2022-06-24 17:16:58
  4. * @LastEditors: 傅豪杰 18516149270@163.com
  5. * @LastEditTime: 2023-05-18 16:55:01
  6. -->
  7. <template>
  8. <el-date-picker
  9. v-bind="$attrs"
  10. v-model="currentValue"
  11. :disabled="isDisabled"
  12. :type="type"
  13. width='100%'
  14. :range-separator="$attrs.rangeSeparator||'~'"
  15. :start-placeholder="$attrs.startPlaceholder || '开始日期'"
  16. :end-placeholder="$attrs.endPlaceholder || '结束日期'"
  17. class="f-el-date"
  18. :class="{hours:$attrs.dateType==='hours'}"
  19. :value-format="getValueFormat"
  20. :format="getFormat"
  21. :placeholder="$attrs.placeholder || '选择日期'"
  22. prefix-icon="none"
  23. :editable="false"
  24. @change="handleChange"
  25. @blur="handleBlur"
  26. @focus="handleFocus"
  27. />
  28. </template>
  29. <script>
  30. import formMixins from'../../mixins/formMixins.js'
  31. export default {
  32. name: 'FDatePicker',
  33. mixins:[formMixins],
  34. inheritAttrs: false,
  35. props: {
  36. // 绑定的数据
  37. value: {},
  38. // 当前行下表
  39. index: {
  40. type: [String, Number],
  41. default: ''
  42. },
  43. // 类型
  44. type:{
  45. type:String,
  46. default:'date'
  47. },
  48. // 格式化数据
  49. valueFormat:{
  50. type:String,
  51. default:'yyyy-MM-dd'
  52. },
  53. },
  54. data() {
  55. return {
  56. };
  57. },
  58. computed:{
  59. // 组件内数据
  60. currentValue:{
  61. get(){
  62. return this.value || ''
  63. },
  64. set(val){
  65. this.$emit('input',val)
  66. }
  67. },
  68. // 数据值格式
  69. getValueFormat(){
  70. if(this.type === 'year'){
  71. return 'yyyy'
  72. }
  73. if(this.type === 'month'){
  74. return 'yyyy-MM'
  75. }
  76. return this.valueFormat
  77. },
  78. // 显示格式
  79. getFormat() {
  80. if (this.$attrs.format) {
  81. return this.$attrs.format
  82. }
  83. return this.getValueFormat
  84. }
  85. },
  86. methods: {
  87. clearDate() {
  88. this.$emit('input', '')
  89. this.$emit('change', '')
  90. this.$emit('clear', '')
  91. },
  92. handleChange(val){
  93. this.$emit('change',val)
  94. },
  95. handleBlur(val){
  96. this.$emit('blur',this.currentValue)
  97. },
  98. handleFocus(val){
  99. this.$emit('focus',this.currentValue)
  100. }
  101. }
  102. };
  103. </script>
  104. <style lang="scss" scoped>
  105. .el-date-editor--daterange.el-input__inner,.el-date-editor.el-input, .el-date-editor.el-input__inner{
  106. width: 100%;
  107. }
  108. </style>