xm-datetimeforyear-render.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <a-date-picker
  3. v-bind="$attrs"
  4. v-model="defaultValue"
  5. mode="year"
  6. picker="YYYY"
  7. format="YYYY"
  8. :allow-clear="false"
  9. placeholder="选择年度"
  10. :input-read-only="true"
  11. :open="endOpen"
  12. @panelChange="yearChange"
  13. @openChange="handleEndOpenChange"
  14. v-if="!readOnly"
  15. />
  16. <span v-else>{{ defaultValue ? new Date(defaultValue).getFullYear() : '' }}</span>
  17. </template>
  18. <script>
  19. import moment from 'moment'
  20. import components from './_import-components/xm-datetimeforyear-render-import'
  21. const XmDatetimeforyearRender = {
  22. name: 'XmDatetimeforyearRender',
  23. metaInfo: {
  24. title: 'XmDatetimeforyearRender',
  25. },
  26. components: {
  27. ...components,
  28. },
  29. computed: {},
  30. props: {
  31. label: {
  32. type: String,
  33. default: '',
  34. },
  35. field: {
  36. type: Object,
  37. default: () => {},
  38. },
  39. currentAsDefaultValue: {
  40. type: Boolean,
  41. default: undefined,
  42. },
  43. },
  44. data() {
  45. return {
  46. endOpen: false,
  47. defaultValue: this.$attrs?.value
  48. ? this.$attrs?.value
  49. : this.currentAsDefaultValue
  50. ? moment()
  51. : this.$attrs?.value || '',
  52. readOnly: this.$attrs ? this.$attrs['read-only'] : false,
  53. // readOnly: false,
  54. }
  55. },
  56. inject: {
  57. webflow: { default: () => ({}) },
  58. SdFormContext: { default: () => ({}) },
  59. },
  60. created() {
  61. if (this.currentAsDefaultValue) {
  62. this.$emit('input', moment().format('YYYY'))
  63. }
  64. },
  65. methods: {
  66. yearChange(value) {
  67. this.defaultValue = value
  68. this.$emit('input', value.format('YYYY'))
  69. this.$emit('change', value.format('YYYY'))
  70. if (document.getElementsByClassName('ant-calendar-picker-container').length > 0) {
  71. for (
  72. let i = 0;
  73. i < document.getElementsByClassName('ant-calendar-picker-container').length;
  74. i++
  75. ) {
  76. document.getElementsByClassName('ant-calendar-picker-container')[i].style.display = 'none'
  77. }
  78. }
  79. },
  80. handleEndOpenChange(open) {
  81. this.endOpen = open
  82. },
  83. },
  84. }
  85. export function updateOnPreview(component) {
  86. // 处理“当前日期”
  87. if (component.attr.currentAsDefaultValue === 'true') {
  88. component.attr.defaultValue = Date.now().toString()
  89. }
  90. }
  91. // 默认导出:编辑模式的组件
  92. export default XmDatetimeforyearRender
  93. // forDisplay导出:只读模式的组件
  94. export { XmDatetimeforyearRender as forDisplay }
  95. </script>
  96. <style module lang="scss">
  97. @use '@/common/design' as *;
  98. .expandicon {
  99. // color: #0b75f3;#40a9ff
  100. // color: rgba(0, 0, 0, 0.85);
  101. color: #40a9ff;
  102. line-height: 22px;
  103. cursor: pointer;
  104. }
  105. .maingroupdiv {
  106. position: relative;
  107. .groupstyle {
  108. float: left;
  109. position: relative;
  110. z-index: 11;
  111. }
  112. .expandCount {
  113. // float: right;
  114. position: absolute;
  115. top: 0;
  116. right: 0;
  117. }
  118. }
  119. </style>