index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="top-right-btn" :style="style">
  3. <el-row>
  4. <!-- <el-tooltip class="item" effect="dark" :content="showOrgTree ? '隐藏机构':'显示机构'" placement="top" v-if="orgTree">
  5. <el-button size="mini" circle :icon="showOrgTree ? 'el-icon-s-fold': 'el-icon-s-unfold'" @click="toggleOrgTree()" />
  6. </el-tooltip> -->
  7. <el-tooltip class="item" effect="dark" :content="showSearch ? '折叠搜索' : '展开搜索'" placement="top" v-if="search">
  8. <el-button size="mini" circle :icon="showSearch ? 'el-icon-top':'el-icon-bottom'" @click="toggleSearch()" />
  9. </el-tooltip>
  10. <el-tooltip class="item" effect="dark" content="刷新" placement="top">
  11. <el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" />
  12. </el-tooltip>
  13. <el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="columns">
  14. <el-button size="mini" circle icon="el-icon-menu" @click="showColumn()" />
  15. </el-tooltip>
  16. </el-row>
  17. <DialogCom :title="title" :visible.sync="open" width="550px" append-to-body>
  18. <el-transfer
  19. :titles="['显示', '隐藏']"
  20. v-model="value"
  21. :data="columns"
  22. @change="dataChange">
  23. </el-transfer>
  24. </DialogCom>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. name: "RightToolbar",
  30. data() {
  31. return {
  32. // 显隐数据
  33. value: [],
  34. // 弹出层标题
  35. title: "显示/隐藏",
  36. // 是否显示弹出层
  37. open: false,
  38. };
  39. },
  40. props: {
  41. showOrgTree: {
  42. type: Boolean,
  43. default: true,
  44. },
  45. showSearch: {
  46. type: Boolean,
  47. default: true,
  48. },
  49. columns: {
  50. type: Array,
  51. },
  52. orgTree: {
  53. type: Boolean,
  54. default: true,
  55. },
  56. search: {
  57. type: Boolean,
  58. default: true,
  59. },
  60. gutter: {
  61. type: Number,
  62. default: 10,
  63. },
  64. },
  65. computed: {
  66. style() {
  67. const ret = {};
  68. if (this.gutter) {
  69. ret.marginRight = `${this.gutter / 2}px`;
  70. }
  71. return ret;
  72. }
  73. },
  74. created() {
  75. // 显隐列初始默认隐藏列
  76. for (let item in this.columns) {
  77. if (this.columns[item].visible === false) {
  78. this.value.push(parseInt(item));
  79. }
  80. }
  81. },
  82. methods: {
  83. toggleOrgTree(){
  84. this.$emit("update:showOrgTree", !this.showOrgTree);
  85. },
  86. // 搜索
  87. toggleSearch() {
  88. this.$emit("update:showSearch", !this.showSearch);
  89. },
  90. // 刷新
  91. refresh() {
  92. this.$emit("queryTable");
  93. },
  94. // 右侧列表元素变化
  95. dataChange(data) {
  96. for (let item in this.columns) {
  97. const key = this.columns[item].key;
  98. this.columns[item].visible = !data.includes(key);
  99. }
  100. },
  101. // 打开显隐列dialog
  102. showColumn() {
  103. this.open = true;
  104. },
  105. },
  106. };
  107. </script>
  108. <style lang="scss" scoped>
  109. ::v-deep .el-transfer__button {
  110. border-radius: 50%;
  111. padding: 12px;
  112. display: block;
  113. margin-left: 0px;
  114. }
  115. ::v-deep .el-transfer__button:first-child {
  116. margin-bottom: 10px;
  117. }
  118. </style>