list.vue 6.3 KB

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