PageBusinessScene.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="business-scene">
  3. <header class="header">
  4. <el-button class="header__button" type="primary" :icon="Plus"
  5. @click="openDrawer('添加业务场景')">添加业务场景</el-button>
  6. </header>
  7. <main class="main">
  8. <BasicTable :columns="columns" :action-column="actionColumn" :data-source="tableData" :tableSetting="{
  9. size: false,
  10. redo: false,
  11. fullscreen: false,
  12. striped: false,
  13. setting: false,
  14. }" />
  15. </main>
  16. <InfoDrawer :title="drawerTitle" :data="tableInfo" @close-drawer="drawerVisiable = false"
  17. @fetch-table="getTableData()" v-if="drawerVisiable" />
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. import { onMounted, ref, h, reactive } from 'vue';
  22. import { ElTag } from 'element-plus';
  23. import { Plus } from '@element-plus/icons-vue'
  24. import { BasicTable } from '@/components/Table';
  25. import { useTableHook } from './useTableHook.ts';
  26. import { SceneListInfo } from '@/types/business-scene/type.ts'
  27. import { BasicColumn, TableActionIcons } from '@/components/Table';
  28. import InfoDrawer from './components/InfoDrawer.vue';
  29. import { openMessageBox, getMessage } from './components/MessageBox.ts'
  30. import Up from '@/assets/icons/up.png';
  31. import Down from '@/assets/icons/down.png';
  32. import Edit from '@/assets/icons/edit.png';
  33. import Delete from '@/assets/icons/delete.png';
  34. const { orderNums, tableData, getTableData, deleteTableData, sortTableData } = useTableHook()
  35. const drawerVisiable = ref(false);
  36. const drawerTitle = ref('添加业务场景')
  37. const openDrawer = (title: string) => {
  38. drawerVisiable.value = true;
  39. drawerTitle.value = title;
  40. tableInfo.value = { name: '', viewTemplateList: [], remark: '', isDisabled: 0 }
  41. }
  42. const columns: BasicColumn[] = [
  43. {
  44. label: '场景名称',
  45. prop: 'name',
  46. width: 150
  47. },
  48. {
  49. label: '关联模板',
  50. prop: 'viewTemplateList',
  51. minWidth: 300,
  52. render(record) {
  53. const template = record.row.viewTemplateList.map(item => item.name);
  54. const tags = template.map((item) => h(ElTag, { type: 'info' }, item));
  55. return h(
  56. 'div',
  57. {
  58. class: 'div__container--tag',
  59. },
  60. tags,
  61. );
  62. },
  63. },
  64. {
  65. label: '状态',
  66. prop: 'isDisabled',
  67. width: 140,
  68. align: 'center',
  69. render(record) {
  70. const status = record.row.isDisabled;
  71. return h(
  72. ElTag,
  73. { type: status === 0 ? 'success' : 'danger' },
  74. status === 0 ? '启用' : '停用',
  75. );
  76. },
  77. },
  78. {
  79. label: '备注',
  80. prop: 'remark',
  81. width: 160
  82. },
  83. {
  84. label: '创建时间',
  85. prop: 'createdAt',
  86. width: 180
  87. },
  88. ];
  89. const tableInfo = ref<SceneListInfo>();
  90. const actionColumn: BasicColumn = reactive({
  91. width: 240,
  92. title: '操作',
  93. prop: 'action',
  94. fixed: 'right',
  95. render(record) {
  96. return h(TableActionIcons as any, {
  97. space: 20,
  98. style: 'img',
  99. size: 16,
  100. actionIcons: [
  101. {
  102. label: '编辑',
  103. icon: Edit,
  104. onClick: () => {
  105. openDrawer('编辑业务场景');
  106. tableInfo.value = record.row;
  107. },
  108. },
  109. {
  110. label: '删除',
  111. icon: Delete,
  112. onClick: () => {
  113. openMessageBox(undefined, undefined, () => deleteTableData(record.row.id))
  114. },
  115. },
  116. {
  117. label: '升序',
  118. icon: Up,
  119. disabled: record.row.orderNum === orderNums.value[0],
  120. onClick: () => {
  121. sortTableData(record.row.id, 'increase')
  122. getMessage('success', '升序成功');
  123. },
  124. },
  125. {
  126. label: '降序',
  127. icon: Down,
  128. disabled: record.row.orderNum === orderNums.value[1],
  129. onClick: () => {
  130. sortTableData(record.row.id, 'decrease')
  131. getMessage('success', '降序成功');
  132. },
  133. },
  134. ],
  135. class: 'table__action--enabled',
  136. });
  137. },
  138. });
  139. onMounted(() => {
  140. getTableData();
  141. })
  142. </script>
  143. <style lang="scss" scoped>
  144. .business-scene {
  145. display: flex;
  146. flex-direction: column;
  147. background: #ffffff;
  148. box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.12);
  149. border-radius: 6px;
  150. width: 100%;
  151. height: calc(100vh - 64px - 12px);
  152. padding: 24px 44px 0 21px;
  153. }
  154. .header {
  155. display: flex;
  156. justify-content: space-between;
  157. width: inherit;
  158. height: 32px;
  159. }
  160. .main {
  161. position: relative;
  162. margin-top: 16px;
  163. width: inherit;
  164. flex: 1;
  165. }
  166. :deep(.div__container--tag) {
  167. display: flex;
  168. flex-wrap: wrap;
  169. gap: 4px;
  170. }
  171. :deep(.div__container--tag)::-webkit-scrollbar {
  172. height: 6px;
  173. }
  174. </style>