index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <lay-card class="custom-card">
  3. <template v-slot:title>
  4. <span class="card-title">服务器管理</span>
  5. </template>
  6. <template v-slot:extra>
  7. <lay-button class="card-button" v-if="apiList?.includes('/serverAuth/getPage')" @click="handlePem()">PEM管理</lay-button>
  8. <lay-button class="card-button" v-if="apiList?.includes('/userServer/execute')" @click="handleCommand()">批量执行指令</lay-button>
  9. <lay-button class="card-button" v-if="apiList?.includes('/userServer/save')" @click="handleBatch()">批量添加服务器</lay-button>
  10. <lay-button class="card-button" v-if="apiList?.includes('/userServer/save')" @click="handleUpdate(0)">添加服务器</lay-button>
  11. </template>
  12. <template v-slot:body>
  13. <div class="custom-form-layout">
  14. <lay-form class="form-wp" :model="pageParams" mode="inline" size="sm">
  15. <lay-form-item label="名称" prop="title">
  16. <lay-input v-model="pageParams.title" />
  17. </lay-form-item>
  18. <lay-form-item label="IP" prop="ip">
  19. <lay-input v-model="pageParams.ip" />
  20. </lay-form-item>
  21. <div class="form-button-wp">
  22. <lay-button @click="getPageInfo(true)">搜索</lay-button>
  23. </div>
  24. </lay-form>
  25. </div>
  26. <div>
  27. <lay-table
  28. :page="tablePage"
  29. :columns="columns"
  30. resize
  31. id="userServerId"
  32. :data-source="dataSource"
  33. v-model:selected-keys="selectedKeys"
  34. :loading="pageConfig.loading"
  35. @change="handleCurrentChange"
  36. >
  37. <template v-slot:status="{ row }">
  38. {{ row.status ? "已配置" : "未配置" }}
  39. </template>
  40. <template v-slot:lastReportTime="{ row }">
  41. <span :class="{ 'danger-color': timeConverts(row.lastReportTime).indexOf('秒') == -1 }">{{ row.lastReportTime ? timeConverts(row.lastReportTime) : "未通讯" }}</span>
  42. </template>
  43. <template v-slot:operator="{ row }">
  44. <lay-space>
  45. <TableButton v-if="apiList?.includes('/userServer/testConnect')" text="测试连接" @click="handleTest(row)" />
  46. <TableButton v-if="apiList?.includes('/userServer/execute')" text="指令" @click="handleCommand(row)" />
  47. <TableButton v-if="apiList?.includes('/userServer/update')" text="编辑" @click="handleUpdate(1, row)" />
  48. <TableButton v-if="apiList?.includes('/userServer/save')" text="复制" @click="handleUpdate(2, row)" />
  49. <TableButton v-if="apiList?.includes('/userServer/delete')" type="danger" text="删除" @click="handleDelete(row)" />
  50. </lay-space>
  51. </template>
  52. </lay-table>
  53. </div>
  54. </template>
  55. </lay-card>
  56. <Update ref="updateRef" />
  57. <Batch ref="batchRef" />
  58. <Pem ref="pemRef" />
  59. <Command ref="commandRef" />
  60. </template>
  61. <script lang="ts" setup name="ServerManage">
  62. import { ref, reactive, getCurrentInstance, onBeforeUnmount } from "vue";
  63. import Pem from "./components/Pem.vue";
  64. import Update from "./components/Update.vue";
  65. import Batch from "./components/Batch.vue";
  66. import Command from "./components/Command.vue";
  67. import TableButton from "@/components/TableButton.vue";
  68. import { timeConverts } from "@/utils/index";
  69. import { get_server_list, delete_server, test_connect_server } from "@/api";
  70. const { proxy }: any = getCurrentInstance();
  71. const updateRef = ref();
  72. const batchRef = ref();
  73. const pemRef = ref();
  74. const commandRef = ref();
  75. const apiList = ref(window.sessionStorage.getItem("_4L_API_LIST"));
  76. interface PageConfig {
  77. loading: boolean;
  78. }
  79. let pageConfig: PageConfig = reactive({
  80. loading: false,
  81. });
  82. interface FormItem {
  83. pageNum?: Number;
  84. pageSize?: Number;
  85. title?: String;
  86. ip?: String;
  87. }
  88. const pageParams: FormItem = reactive({ pageNum: 1, pageSize: 20 });
  89. interface TablePage {
  90. current: number;
  91. limit: number;
  92. total: number;
  93. }
  94. const tablePage: TablePage = reactive({ current: 1, limit: 20, total: 0, limits: [20, 50, 100, 200, 500] });
  95. const columns = ref([
  96. { title: "选项", width: "44px", type: "checkbox" },
  97. { title: "名称", key: "name" },
  98. { title: "IP", width: "120px", key: "ipAddrComplex" },
  99. { title: "端口号", width: "80px", key: "portComplex" },
  100. { title: "状态", width: "80px", key: "status", customSlot: "status" },
  101. { title: "通讯", width: "80px", key: "lastReportTime", customSlot: "lastReportTime" },
  102. { title: "更新时间", width: "160px", key: "updateTime" },
  103. { title: "备注", key: "remark", ellipsisTooltip: true },
  104. {
  105. title: "操作",
  106. customSlot: "operator",
  107. key: "operator",
  108. ignoreExport: true,
  109. },
  110. ]);
  111. let dataSource = ref([]);
  112. let selectedKeys = ref([]);
  113. // 请求交易所列表
  114. const getPageInfo = (isSearch?: boolean) => {
  115. if (isSearch) {
  116. pageParams.pageNum = 1;
  117. selectedKeys.value = [];
  118. }
  119. pageConfig.loading = true;
  120. get_server_list(pageParams, (data: any) => {
  121. pageConfig.loading = false;
  122. if (data.code == 200) {
  123. dataSource.value = data.data.list;
  124. tablePage.total = data.data.total;
  125. }
  126. });
  127. };
  128. getPageInfo();
  129. const refreshInterval = setInterval(() => {
  130. get_server_list(pageParams, (data: any) => {
  131. if (data.code == 200) {
  132. dataSource.value = data.data.list;
  133. tablePage.total = data.data.total;
  134. }
  135. });
  136. }, 2000);
  137. const handlePem = async () => {
  138. const result = await pemRef.value.show();
  139. if (result) getPageInfo();
  140. };
  141. const handleBatch = async () => {
  142. const result = await batchRef.value.show();
  143. if (result) getPageInfo();
  144. };
  145. const handleUpdate = async (type: number, value?: any) => {
  146. const result = await updateRef.value.show(type, value);
  147. if (result) getPageInfo();
  148. };
  149. const handleCommand = async (value?: any) => {
  150. let userServerId;
  151. if (value) {
  152. userServerId = [value.userServerId];
  153. } else {
  154. userServerId = selectedKeys.value;
  155. }
  156. if (userServerId.length <= 0) return proxy.$message(`请先选择要执行命令服务器!`, 7);
  157. await commandRef.value.show(userServerId);
  158. };
  159. // 测试连接
  160. const handleTest = async (value: any) => {
  161. let params = { ...value };
  162. pageConfig.loading = true;
  163. test_connect_server(params, (data: any) => {
  164. pageConfig.loading = false;
  165. if (data.code == 200) {
  166. data.data ? proxy.$message(`连接成功!`) : proxy.$message(`连接失败!`, 2);
  167. }
  168. });
  169. };
  170. // 删除交易所
  171. const handleDelete = async (value: any) => {
  172. let result = await proxy.$waitingConfirm("是否确认删除该服务器?");
  173. if (!result) return;
  174. let params = [value.userServerId];
  175. pageConfig.loading = true;
  176. delete_server(params, (data: any) => {
  177. pageConfig.loading = false;
  178. if (data.code == 200) {
  179. proxy.$message(`删除成功!`);
  180. getPageInfo();
  181. }
  182. });
  183. };
  184. // 分页设置
  185. const handleCurrentChange = (val: any) => {
  186. pageParams.pageNum = val.current;
  187. pageParams.pageSize = val.limit;
  188. getPageInfo();
  189. };
  190. onBeforeUnmount(() => {
  191. clearInterval(refreshInterval);
  192. });
  193. </script>
  194. <style lang="scss" scoped>
  195. .primary-color {
  196. color: var(--primary-color);
  197. }
  198. .normal-color {
  199. color: var(--normal-color);
  200. }
  201. .danger-color {
  202. color: var(--danger-color);
  203. }
  204. </style>