a9f91ab39e9027ae71080d6d2a86e5b38c857d26.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div :class="clazz" :style="boxStyle">
  3. <a-checkbox
  4. ref="checkbox"
  5. :checked="innerValue"
  6. v-bind="cellProps"
  7. @change="handleChange"
  8. />
  9. </div>
  10. </template>
  11. <script>
  12. import { neverNull } from '@/utils/util'
  13. import JVxeCellMixins from '@/components/jeecg/JVxeTable/mixins/JVxeCellMixins'
  14. export default {
  15. name: 'JVxeCheckboxCell',
  16. mixins: [JVxeCellMixins],
  17. props: {},
  18. computed: {
  19. bordered() {
  20. return !!this.renderOptions.bordered
  21. },
  22. scrolling() {
  23. return !!this.renderOptions.scrolling
  24. },
  25. clazz() {
  26. return {
  27. 'j-vxe-checkbox': true,
  28. 'no-animation': this.scrolling
  29. }
  30. },
  31. boxStyle() {
  32. const style = {}
  33. // 如果有边框且未设置align属性,就强制居中
  34. if (this.bordered && !this.originColumn.align) {
  35. style['text-align'] = 'center'
  36. }
  37. return style
  38. },
  39. },
  40. methods: {
  41. handleChange(event) {
  42. this.handleChangeCommon(event.target.checked)
  43. },
  44. },
  45. // 【组件增强】注释详见:JVxeCellMixins.js
  46. enhanced: {
  47. switches: {
  48. visible: true,
  49. },
  50. getValue(value) {
  51. let {own: col} = this.column
  52. // 处理 customValue
  53. if (Array.isArray(col.customValue)) {
  54. let customValue = getCustomValue(col)
  55. if (typeof value === 'boolean') {
  56. return value ? customValue[0] : customValue[1]
  57. } else {
  58. return value
  59. }
  60. } else {
  61. return value
  62. }
  63. },
  64. setValue(value) {
  65. let {own: col} = this.column
  66. // 判断是否设定了customValue(自定义值)
  67. if (Array.isArray(col.customValue)) {
  68. let customValue = getCustomValue(col)
  69. return neverNull(value).toString() === customValue[0].toString()
  70. } else {
  71. return !!value
  72. }
  73. },
  74. createValue({column}) {
  75. let {own: col} = column
  76. if (Array.isArray(col.customValue)) {
  77. let customValue = getCustomValue(col)
  78. return col.defaultChecked ? customValue[0] : customValue[1]
  79. } else {
  80. return !!col.defaultChecked
  81. }
  82. },
  83. }
  84. }
  85. function getCustomValue(col) {
  86. let customTrue = neverNull(col.customValue[0], true)
  87. let customFalse = neverNull(col.customValue[1], false)
  88. return [customTrue, customFalse]
  89. }
  90. </script>
  91. <style lang="less">
  92. // 关闭动画,防止滚动时动态赋值出现问题
  93. .j-vxe-checkbox.no-animation {
  94. .ant-checkbox-inner,
  95. .ant-checkbox-inner::after {
  96. transition: none !important;
  97. }
  98. }
  99. </style>