btn-1.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div id="btn-1">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <template v-if="vOpera">
  7. <el-button v-opera="{ method: 'add' }" type="primary" plain icon="el-icon-plus" size="mini" @click="toAdd()">新增</el-button>
  8. <el-button v-opera="{ method: 'edit' }" type="success" plain icon="el-icon-edit" size="mini" :disabled="true">修改</el-button>
  9. <el-button v-opera="{ method: 'del' }" type="danger" plain icon="el-icon-delete" size="mini" @click="toDel()">删除</el-button>
  10. <el-button v-opera="{ method: 'others' }" type="warning" plain icon="el-icon-download" size="mini" @click="toExport()">导出</el-button>
  11. </template>
  12. <template v-else>
  13. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="toAdd()">新增</el-button>
  14. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="true">修改</el-button>
  15. <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="toDel()">删除</el-button>
  16. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="toExport()">导出</el-button>
  17. </template>
  18. </el-col>
  19. </el-col>
  20. </el-row>
  21. <e-dialog :dialog="dialog" @toClose="toClose">
  22. <template v-slot:info>
  23. <el-col :span="24" class="dailog_one" v-if="dialog.type == '1'">
  24. <el-col :span="24" class="one_1">
  25. <el-transfer v-model="selectList" :titles="['未选择', '已选择']" :button-texts="['取消', '确认']" :data="columnList" target-order="push">
  26. <el-col :span="24" slot-scope="{ option }">
  27. <el-col :span="24" class="textOver">{{ option.zh }}</el-col>
  28. </el-col>
  29. </el-transfer>
  30. </el-col>
  31. <el-col :span="24" class="one_2">
  32. <el-button type="primary" size="mini" @click="onSubmit()"> 确认导出 </el-button>
  33. </el-col>
  34. </el-col>
  35. </template>
  36. </e-dialog>
  37. </div>
  38. </template>
  39. <script>
  40. import { mapState, createNamespacedHelpers } from 'vuex';
  41. const { mapActions } = createNamespacedHelpers('usual');
  42. export default {
  43. name: 'btn-1',
  44. props: {
  45. table: { type: String },
  46. ids: { type: Array },
  47. vOpera: { type: Boolean, default: true }, // 是否受指令控制
  48. },
  49. components: {},
  50. data: function () {
  51. return {
  52. dialog: { title: '导出列信息管理', show: false, type: '1' },
  53. columnList: [],
  54. selectList: [],
  55. };
  56. },
  57. created() {},
  58. methods: {
  59. ...mapActions(['selectkey', 'selectExp', 'selectDel']),
  60. // 新增
  61. toAdd() {
  62. this.$emit('toAdd');
  63. },
  64. // 删除
  65. async toDel() {
  66. let arr = this.ids.map((i) => i._id);
  67. if (!arr.length > 0) {
  68. this.$message({ type: `error`, message: `暂无数据可批量删除` });
  69. } else {
  70. this.$confirm('是否确认删除数据项?', '警告', {
  71. confirmButtonText: '确定',
  72. cancelButtonText: '取消',
  73. type: 'warning',
  74. })
  75. .then(async () => {
  76. let res = await this.selectDel({ table: this.table, ids: arr });
  77. if (this.$checkRes(res)) {
  78. this.$message({ type: `success`, message: `批量删除成功` });
  79. this.$emit('search');
  80. }
  81. })
  82. .catch(() => {});
  83. }
  84. },
  85. // 导出
  86. async toExport() {
  87. this.$confirm('是否确认导出所有角色数据项?', '警告', {
  88. confirmButtonText: '确定',
  89. cancelButtonText: '取消',
  90. type: 'warning',
  91. })
  92. .then(async () => {
  93. let res = await this.selectkey({ table: this.table });
  94. if (this.$checkRes(res)) {
  95. this.$set(this, `columnList`, res.data);
  96. this.dialog = { title: '导出列信息管理', show: true, type: '1' };
  97. }
  98. })
  99. .catch(() => {});
  100. },
  101. // 确认导出
  102. async onSubmit() {
  103. let dup = { table: this.table, config: [] };
  104. if (this.selectList.length > 0) {
  105. for (const val of this.selectList) {
  106. let p1 = this.columnList.find((i) => i.key == val);
  107. if (p1) dup.config.push(p1);
  108. }
  109. let res = await this.selectExp(dup);
  110. if (this.$checkRes(res)) {
  111. window.open(`${res.data}`, '_blank');
  112. this.toClose();
  113. }
  114. } else {
  115. this.$message({ type: `error`, message: `暂无数据可批量导出` });
  116. }
  117. },
  118. // 关闭
  119. toClose() {
  120. this.dialog = { title: '导出列信息管理', show: false, type: '1' };
  121. },
  122. },
  123. computed: {
  124. ...mapState(['user']),
  125. },
  126. metaInfo() {
  127. return { title: this.$route.meta.title };
  128. },
  129. watch: {
  130. test: {
  131. deep: true,
  132. immediate: true,
  133. handler(val) {},
  134. },
  135. },
  136. };
  137. </script>
  138. <style lang="less" scoped>
  139. .dialog {
  140. /deep/.el-dialog__body {
  141. padding: 10px;
  142. min-height: 30px;
  143. max-height: 400px;
  144. overflow-y: auto;
  145. }
  146. }
  147. .dailog_one {
  148. .one_1 {
  149. padding: 0 70px;
  150. margin: 0 0 10px 0;
  151. }
  152. .one_2 {
  153. text-align: center;
  154. }
  155. }
  156. </style>