tableCols.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * @Author: Badguy
  3. * @Date: 2022-03-04 11:50:22
  4. * @LastEditTime: 2022-03-15 17:56:34
  5. * @LastEditors: your name
  6. * @Description: 航站视图表格通用部分
  7. * have a nice day!
  8. */
  9. export default {
  10. data () {
  11. return {
  12. // 筛选后表头
  13. tableColsCopy: [],
  14. // 列设置弹框选中
  15. checkedKeys: [],
  16. checkedKeysTemp: [],
  17. halfCheckedKeys: [],
  18. // 列设置弹框开关
  19. dialogFlag: false
  20. }
  21. },
  22. // created () {
  23. // this.initTableCols()
  24. // },
  25. updated () {
  26. // table数据更新
  27. this.$nextTick(() => {
  28. this.$refs.table?.doLayout()
  29. })
  30. },
  31. computed: {
  32. colsCheckClass () {
  33. return this.tableCols.some(col => col.children?.length) ? 'has-children' : 'no-children'
  34. }
  35. },
  36. methods: {
  37. // 列设置-初始化
  38. initTableCols () {
  39. const that = this
  40. function setTableCols (cols) {
  41. for (const col of cols) {
  42. col.index = that.checkedKeys.length
  43. that.checkedKeys.push(that.checkedKeys.length)
  44. if (col.children?.length) {
  45. setTableCols(col.children)
  46. }
  47. }
  48. }
  49. setTableCols(this.tableCols)
  50. // this.tableColsCopy = this._.cloneDeep(this.tableCols)
  51. this.checkedKeysTemp = [...this.checkedKeys]
  52. },
  53. // 列设置-确定
  54. handleCheck (data, checked) {
  55. this.checkedKeysTemp = [...checked.checkedKeys]
  56. this.halfCheckedKeys = [...checked.halfCheckedKeys]
  57. },
  58. onCheck (tableDataName = 'tableData') {
  59. if (this.dialogFlag === false) {
  60. return
  61. }
  62. this.loading = true
  63. const tableDataTemp = this._.cloneDeep(this[tableDataName])
  64. this[tableDataName] = []
  65. this.dialogFlag = false
  66. this.checkedKeys = [...this.checkedKeysTemp]
  67. const datas = this.colsFilter(this._.cloneDeep(this.tableCols))
  68. const newTableColsCopy = datas.filter((item) => item.needShow)
  69. this.tableColsCopy = _.cloneDeep(newTableColsCopy)
  70. const bagColsMap = {}
  71. bagColsMap.bagColsLists = _.cloneDeep(newTableColsCopy)
  72. bagColsMap.bagColsKeys = [...this.checkedKeysTemp]
  73. localStorage.setItem('bagColsMap', JSON.stringify(bagColsMap))
  74. setTimeout(() => {
  75. if (!this[tableDataName].length) {
  76. this[tableDataName] = tableDataTemp
  77. }
  78. this.loading = false
  79. }, 50)
  80. },
  81. colsFilter (cols) {
  82. const temp = cols.filter(col => {
  83. if (this.halfCheckedKeys.includes(col.queryTemplateColumnSetID)) {
  84. col.children = this.colsFilter(col.children)
  85. return true
  86. } else if (this.checkedKeys.includes(col.queryTemplateColumnSetID)) {
  87. return true
  88. }
  89. return false
  90. })
  91. return temp
  92. },
  93. // 弹框展开
  94. show () {
  95. this.dialogFlag = true
  96. },
  97. // 弹框关闭
  98. hide () {
  99. this.dialogFlag = false
  100. this.checkedKeysTemp = [...this.checkedKeys]
  101. }
  102. }
  103. }