PushAlarm.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div class="push-page">
  3. <el-card :bordered="false" class="proCard" style="position: relative">
  4. <BasicTable
  5. :columns="columns"
  6. :data-source="robotPushList"
  7. :row-key="(row) => row.id"
  8. :action-column="actionColumn"
  9. :loading="loading"
  10. :pagination="{ total: total, pageSize: size, hideOnSinglePage: !robotPushList.length }"
  11. :tableSetting="{
  12. size: false,
  13. redo: false,
  14. fullscreen: false,
  15. striped: false,
  16. setting: false,
  17. }"
  18. :striped="true"
  19. ref="tableRef"
  20. @order-change="orderByItem"
  21. @page-num-change="handlePageNumChange"
  22. @page-size-change="handlePageSizeChange"
  23. >
  24. <template #tableTitle>
  25. <el-button type="primary" :icon="Plus" @click="addDrawer">添加</el-button>
  26. </template>
  27. </BasicTable>
  28. </el-card>
  29. <AddRobot
  30. v-if="showDrawer"
  31. :robot-list="robotList"
  32. @on-close="closeDrawer"
  33. @sub-add="addSubRobot"
  34. @sub-edit="editSubRobot"
  35. />
  36. </div>
  37. </template>
  38. <script setup lang="ts">
  39. import { h, onMounted, reactive, ref } from 'vue';
  40. import { BasicTable, TableActionIcons } from '@/components/Table';
  41. import { BasicColumn } from '@/components/Table';
  42. import { columns } from './constant';
  43. import { Plus } from '@element-plus/icons-vue';
  44. import editIcon from '@/assets/images/table/table-edit.png';
  45. import deleteIcon from '@/assets/images/table/table-delete.png';
  46. import AddRobot from './component/AddRobot.vue';
  47. import { ElMessage, ElMessageBox } from 'element-plus';
  48. import { RobotType } from '@/api/push/push';
  49. import usePush from './usePush';
  50. const usePushRobot = usePush();
  51. const { robotPushList, total, page, size, loading, getRobotList, robotAdd, robotDel, robotEdit } =
  52. usePushRobot;
  53. onMounted(() => {
  54. getRobotList();
  55. });
  56. // 添加弹窗相关
  57. const showDrawer = ref(false);
  58. const robotList = ref<RobotType | null>({});
  59. //关闭drawer
  60. const closeDrawer = () => {
  61. showDrawer.value = false;
  62. };
  63. const addDrawer = () => {
  64. robotList.value = null;
  65. showDrawer.value = true;
  66. };
  67. const addSubRobot = (data) => {
  68. robotAdd(data).then(() => {
  69. ElMessage.success('添加成功');
  70. });
  71. showDrawer.value = false;
  72. };
  73. const editSubRobot = (data) => {
  74. robotEdit(data).then(() => {
  75. ElMessage.success('编辑成功');
  76. });
  77. showDrawer.value = false;
  78. };
  79. //操作列
  80. const actionColumn: BasicColumn = reactive({
  81. width: 200,
  82. title: '操作',
  83. prop: 'action',
  84. key: 'action',
  85. fixed: 'right',
  86. render(record) {
  87. return h(TableActionIcons as any, {
  88. space: 20,
  89. color: '#629bf9',
  90. iconStyle: 'img',
  91. size: 16,
  92. actionIcons: [
  93. {
  94. label: '编辑',
  95. icon: editIcon,
  96. onClick: handleEdit.bind(null, record.row),
  97. },
  98. {
  99. label: '删除',
  100. icon: deleteIcon,
  101. onClick: handleDelete.bind(null, record.row),
  102. },
  103. ],
  104. });
  105. },
  106. });
  107. // 列排序操作
  108. const orderByItem = () => {};
  109. const handlePageNumChange = (pageNum) => {
  110. page.value = pageNum;
  111. getRobotList();
  112. };
  113. const handlePageSizeChange = (pageSize) => {
  114. size.value = pageSize;
  115. getRobotList();
  116. };
  117. const handleDelete = (row) => {
  118. ElMessageBox.confirm(`您想删除机器人${row.robotName}`, '提示', {
  119. confirmButtonText: '确定',
  120. cancelButtonText: '取消',
  121. type: 'warning',
  122. draggable: true,
  123. })
  124. .then(() => {
  125. robotDel(row.id).then(() => {
  126. ElMessage.success('删除成功');
  127. });
  128. })
  129. .catch(() => {});
  130. };
  131. //编辑
  132. const handleEdit = (row) => {
  133. robotList.value = row;
  134. showDrawer.value = true;
  135. };
  136. </script>
  137. <style scoped>
  138. .push-page {
  139. position: relative;
  140. height: calc(100vh - 64px - 12px);
  141. background-color: #ffffff;
  142. }
  143. .camera-list {
  144. padding: 0 21px;
  145. }
  146. .empty-content {
  147. margin: auto;
  148. padding: 125px 0;
  149. }
  150. .empty-img {
  151. width: 396px;
  152. }
  153. .empty-text {
  154. font-size: 22px;
  155. color: #8e8e8e;
  156. line-height: 30px;
  157. text-align: center;
  158. }
  159. .add-tip {
  160. position: absolute;
  161. left: 187px;
  162. top: 64px;
  163. font-size: 16px;
  164. color: red;
  165. }
  166. .add-popover {
  167. position: absolute;
  168. width: calc(100% - 21px);
  169. height: 622px;
  170. top: 0;
  171. bottom: 0;
  172. margin: auto;
  173. z-index: 99;
  174. }
  175. .item {
  176. margin: 0px 40px 0px 15px;
  177. }
  178. </style>