e78543a43328e7aefe68af284ce067b238277b90.svn-base 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <span>
  3. <a-popover title="自定义列" trigger="click" placement="leftBottom">
  4. <template slot="content">
  5. <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" >
  6. <a-row style="width:500px">
  7. <template v-for="(item,index) in defColumns">
  8. <template >
  9. <a-col :span="8" :key="index">
  10. <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
  11. </a-col>
  12. </template>
  13. </template>
  14. </a-row>
  15. </a-checkbox-group>
  16. </template>
  17. <a><a-icon type="setting" />设置</a>
  18. </a-popover>
  19. </span>
  20. </template>
  21. <script>
  22. import Vue from 'vue'
  23. export default {
  24. name: 'ColSetting',
  25. props: {
  26. defColumns: {// 默认列
  27. type: Array,
  28. default: []
  29. },
  30. value: { // 必须要使用value
  31. type: Array,
  32. default: []
  33. }
  34. },
  35. data() {
  36. return {
  37. settingColumns: []// 列设置
  38. }
  39. },
  40. mounted() {
  41. this.initColumns()
  42. },
  43. methods: {
  44. // 列设置更改事件
  45. onColSettingsChange(checkedValues) {
  46. var key = this.$route.name + this.$route.params.code + ':colsettings'
  47. Vue.ls.set(key, checkedValues, 300 * 24 * 60 * 60 * 1000)
  48. this.$emit('input', checkedValues)
  49. },
  50. initColumns() {
  51. var key = this.$route.name + this.$route.params.code + ':colsettings'
  52. const colSettings = Vue.ls.get(key)
  53. if (!colSettings || colSettings.length === 0) {
  54. this.settingColumns = []
  55. this.defColumns.forEach(column => {
  56. if (this.settingColumns.indexOf(column['dataIndex']) < 0) {
  57. this.settingColumns.push(column['dataIndex'])
  58. }
  59. })
  60. } else {
  61. this.settingColumns = colSettings
  62. }
  63. this.$emit('input', colSettings)
  64. }
  65. }
  66. }
  67. </script>