index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="device-tels-container layout-padding">
  3. <div class="layout-padding-auto layout-padding-view pd20">
  4. <div class="flex-center-between mb20">
  5. <p class="table-title">信息列表</p>
  6. <div>
  7. <el-button type="primary" @click="asyncDevice" v-waves v-auth="'300101'"> <SvgIcon name="ele-Refresh" class="mr5" />同步 </el-button>
  8. <el-button type="primary" v-waves @click="onImportTable" :disabled="!state.multipleSelection.length">
  9. <SvgIcon name="iconfont icon-daochu" class="mr5" />导出
  10. </el-button>
  11. </div>
  12. </div>
  13. <!-- 表格 -->
  14. <el-table :data="tableData" v-loading="loading" row-key="id" @selection-change="handleSelectionChange">
  15. <el-table-column type="selection" width="55" :reserve-selection="true" />
  16. <el-table-column prop="no" label="分机编号" show-overflow-tooltip></el-table-column>
  17. <el-table-column prop="groupNames" label="所属分机组" show-overflow-tooltip></el-table-column>
  18. <el-table-column prop="registerIP" label="注册IP" show-overflow-tooltip></el-table-column>
  19. <el-table-column label="分机状态" show-overflow-tooltip prop="telStatusText"></el-table-column>
  20. <el-table-column label="创建时间" show-overflow-tooltip width="170">
  21. <template #default="scope">
  22. <span>{{ formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}</span>
  23. </template>
  24. </el-table-column>
  25. <template #empty>
  26. <Empty />
  27. </template>
  28. </el-table>
  29. </div>
  30. </div>
  31. </template>
  32. <script lang="ts" name="tels" setup>
  33. import { onMounted, reactive, toRefs } from 'vue';
  34. import { ElMessage, ElMessageBox } from 'element-plus';
  35. import { formatDate } from '/@/utils/formatTime';
  36. import table2excel from 'js-table2excel';
  37. // 引入api
  38. import { getTelsList, syncTel } from '/@/api/device/tels';
  39. // 定义接口来定义对象的类型
  40. interface TelsState {
  41. loading: boolean;
  42. tableData: Array<any>;
  43. multipleSelection: Array<any>;
  44. }
  45. // 定义变量内容
  46. const state = reactive<TelsState>({
  47. loading: false,
  48. tableData: [],
  49. multipleSelection: [],
  50. });
  51. const { loading, tableData } = toRefs(state);
  52. /** 获取分机列表 */
  53. const getList = () => {
  54. state.loading = true;
  55. getTelsList()
  56. .then((response: any) => {
  57. state.tableData = response.result ?? [];
  58. state.loading = false;
  59. })
  60. .catch(() => {
  61. state.loading = false;
  62. });
  63. };
  64. // 同步
  65. const asyncDevice = () => {
  66. ElMessageBox.confirm(`确定要将设备信息同步到数据库,是否继续?`, '提示', {
  67. confirmButtonText: '确认',
  68. cancelButtonText: '取消',
  69. type: 'warning',
  70. draggable: true,
  71. cancelButtonClass: 'default-button',
  72. })
  73. .then(() => {
  74. syncTel()
  75. .then(() => {
  76. getList();
  77. ElMessage.success('同步成功');
  78. })
  79. .catch((err: any) => {
  80. console.log(err, '同步失败');
  81. });
  82. })
  83. .catch(() => {});
  84. };
  85. // 表格多选
  86. const handleSelectionChange = (val: any) => {
  87. state.multipleSelection = val;
  88. };
  89. // 导出表格
  90. const onImportTable = () => {
  91. const tabeHeader = [
  92. { key: 'no', colWidth: '', title: '分机编号', type: 'text', isCheck: true },
  93. { key: 'groupNames', colWidth: '', title: '所属分机组', type: 'text', isCheck: true },
  94. { key: 'registerIP', colWidth: '', title: '注册IP', type: 'text', isCheck: true },
  95. { key: '分机状态', colWidth: '', title: '分机状态', type: 'text', isCheck: true },
  96. { key: '创建时间', colWidth: '', title: '创建时间', type: 'text', isCheck: true },
  97. ];
  98. table2excel(tabeHeader, state.multipleSelection, `话机管理 ${formatDate(new Date(), 'YYYY-mm-dd HH-MM')}`);
  99. };
  100. onMounted(() => {
  101. getList();
  102. });
  103. </script>
  104. <style lang="scss" scoped>
  105. .device-tels-container {
  106. .el-table {
  107. flex: 1;
  108. }
  109. }
  110. </style>