list.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <el-table v-loading="loading" :data="data" style="width: 100%">
  3. <el-table-column align="center" prop="id" v-col="'id'" label="ID" width="100" />
  4. <el-table-column align="center" prop="name" v-col="'name'" label="名称" />
  5. <el-table-column align="center" prop="types" v-col="'type'" label="类型" :formatter="(a: any) => typesFormat(a.types)" />
  6. <el-table-column align="center" prop="addr" v-col="'address'" min-width="120" label="地址" />
  7. <el-table-column show-overflow-tooltip align="center" v-col="'createTime'" prop="createdAt" label="创建时间" width="170" />
  8. <el-table-column align="center" prop="types" v-col="'status'" label="状态">
  9. <template #default="scope">
  10. <el-tag size="medium" v-if="!scope.row.status" class="ml-2" type="info">未启动</el-tag>
  11. <el-tag size="medium" v-else class="ml-2" type="success">启动</el-tag>
  12. </template>
  13. </el-table-column>
  14. <el-table-column align="center" label="操作" v-col="'auth'" width="160">
  15. <template #default="scope">
  16. <el-button @click="toDetail(scope.row.id)" size="small" v-auth="'detail'" text type="primary">详情</el-button>
  17. <el-button size="small" link key="info" type="info" v-auth="'edit'" @click="toEdit(scope.row.id)">编辑</el-button>
  18. <el-popover placement="bottom" :width="160" trigger="click">
  19. <template #reference>
  20. <el-button size="small" text type="primary" v-auth="'more'" class="more-btn" @click="isShowMore = !isShowMore">更多
  21. <i style="margin-left: 2px;" :class="isShowMore ? 'fa fa-angle-down' : 'fa fa-angle-up'"></i>
  22. </el-button>
  23. </template>
  24. <div class="more-opearte-wrap">
  25. <el-button @click="onChangeStatus(scope.row.id, 1)" :disabled="scope.row.status" v-auth="'on'" link size="small" key="success" type="success">启 用</el-button>
  26. <el-divider direction="vertical" />
  27. <el-button @click="onChangeStatus(scope.row.id, 0)" :disabled="!scope.row.status" v-auth="'off'" link size="small" key="warning" type="warning">禁 用</el-button>
  28. <el-divider direction="vertical" />
  29. <el-button @click="onRowDel(scope.row)" link size="small" key="danger" v-auth="'off'" type="danger">删 除</el-button>
  30. </div>
  31. </el-popover>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. <el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15" :pager-count="5" :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]" v-model:current-page="param.page" background v-model:page-size="param.pageSize"
  36. layout="total, sizes, prev, pager, next, jumper" :total="total">
  37. </el-pagination>
  38. </template>
  39. <script lang="ts">
  40. import { toRefs, reactive, onMounted, getCurrentInstance, unref, defineComponent } from 'vue';
  41. import { ElMessageBox, ElMessage } from 'element-plus';
  42. import { useRouter } from 'vue-router';
  43. import api from '/@/api/network';
  44. // 定义接口来定义对象的类型
  45. interface TableDataForm {
  46. id: number;
  47. server: string;
  48. name: string;
  49. }
  50. interface TableData {
  51. data: Array<TableDataForm>;
  52. total: number;
  53. loading: boolean;
  54. param: {
  55. page: number;
  56. pageSize: number;
  57. };
  58. isShowMore: boolean
  59. }
  60. export default defineComponent({
  61. name: 'tunnel',
  62. props: {
  63. // 输入框前置内容
  64. keyWord: {
  65. type: String,
  66. default: '',
  67. },
  68. },
  69. setup(props, { emit }) {
  70. const { proxy } = getCurrentInstance() as any;
  71. const { network_tunnel_type } = proxy.useDict('network_tunnel_type');
  72. const typesFormat = (types: string) => {
  73. return proxy.selectDictLabel(unref(network_tunnel_type), types);
  74. };
  75. const router = useRouter();
  76. const state = reactive<TableData>({
  77. data: [],
  78. total: 0,
  79. loading: false,
  80. param: {
  81. page: 1,
  82. pageSize: 20,
  83. },
  84. isShowMore: true
  85. });
  86. // 改变状态
  87. const onChangeStatus = (id: number, status: number) => {
  88. api.tunnel.changeTunnelStatus({ id: id, status: status }).then((res: any) => {
  89. ElMessage.success(status ? '已开启' : '已关闭');
  90. fetchList();
  91. })
  92. };
  93. // 分页改变
  94. const onHandleSizeChange = (val: number) => {
  95. state.param.pageSize = val;
  96. fetchList()
  97. };
  98. // 分页改变
  99. const onHandleCurrentChange = (val: number) => {
  100. state.param.page = val;
  101. fetchList()
  102. };
  103. // 初始化表格数据
  104. const initTableData = () => {
  105. fetchList()
  106. };
  107. // 获取数据
  108. const fetchList = () => {
  109. state.loading = true
  110. let params = {
  111. keyWord: props.keyWord,
  112. pageNum: state.param.page,
  113. PageSize: state.param.pageSize
  114. }
  115. api.tunnel.getList(params).then((res: any) => {
  116. const { list, total, page } = res
  117. state.data = list
  118. state.total = total
  119. state.param.page = page
  120. state.loading = false
  121. });
  122. };
  123. // 删除
  124. const onRowDel = (row: TableDataForm) => {
  125. ElMessageBox.confirm(`此操作将永久删除“${row.name}”,是否继续?`, '提示', {
  126. confirmButtonText: '确认',
  127. cancelButtonText: '取消',
  128. type: 'warning',
  129. })
  130. .then(() => {
  131. api.tunnel.deleteItem({ ids: [row.id] }).then((res: any) => {
  132. fetchList()
  133. ElMessage.success('删除成功');
  134. });
  135. })
  136. .catch(() => { });
  137. };
  138. const toDetail = (id: number) => {
  139. router.push(`/iotmanager/network/tunnel/detail/${id}`)
  140. };
  141. const toEdit = (id: number) => {
  142. router.push(`/iotmanager/network/tunnel/edit/${id}`)
  143. };
  144. // 页面加载时
  145. onMounted(() => {
  146. initTableData();
  147. });
  148. return {
  149. fetchList,
  150. toDetail,
  151. toEdit,
  152. onChangeStatus,
  153. onRowDel,
  154. onHandleSizeChange,
  155. onHandleCurrentChange,
  156. typesFormat,
  157. ...toRefs(state),
  158. };
  159. }
  160. });
  161. </script>
  162. <style lang="scss" scoped>
  163. :deep(div.more-opearte-wrap) {
  164. flex-direction: row;
  165. background-color: pink;
  166. }
  167. </style>