Skip to content

Commit

Permalink
Feat: batch reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyCreeper committed Dec 18, 2023
1 parent 442f013 commit dbd16d2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
36 changes: 34 additions & 2 deletions src/hooks/admin/setting/useVendor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ref, reactive } from "vue";
import { ref } from "vue";
import { ElNotification, ElMessage } from "element-plus";
import { userStore } from "@/stores/user";
import {
getVendorsListApi,
addVendorApi,
editVendorApi,
deleteVendorApi
deleteVendorApi,
reconnectVendorApi
} from "@/services/apis/admin";
import type { Backend } from "@/types/Vendor";

Expand Down Expand Up @@ -99,6 +100,35 @@ export const useVendorApi = () => {
return state;
};

const reconnectVendor = async (endpoints: string[], showMsg = false) => {
const { execute } = reconnectVendorApi();
try {
showMsg && ElMessage.info("正在尝试重新连接");
await execute({
headers: {
Authorization: token.value
},
data: {
endpoints
}
});
} catch (err) {
errorCatch(err);
}
};

const batchReconnect = async (e: { info: { backend: { endpoint: string } } }[] | string) => {
if (Array.isArray(e)) {
await reconnectVendor(
e.map((item) => item.info.backend.endpoint),
true
);
} else {
await reconnectVendor([e], true);
}
await getVendorsList();
};

const batchDelete = async (e: { info: { backend: { endpoint: string } } }[] | string) => {
if (Array.isArray(e)) {
await deleteVendor(
Expand Down Expand Up @@ -141,6 +171,8 @@ export const useVendorApi = () => {
editVendor,
deleteVendor,
getVendorsList,
reconnectVendor,
batchReconnect,
vendorsListState,
getVendorsListLoading,
currentPage,
Expand Down
16 changes: 16 additions & 0 deletions src/services/apis/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,19 @@ export const deleteVendorApi = useDefineApi<
url: "/api/admin/vendors",
method: "DELETE"
});

// 重连
export const reconnectVendorApi = useDefineApi<
{
headers: {
Authorization: string;
};
data: {
endpoints: string[];
};
},
null
>({
url: "/api/admin/vendors/reconnect",
method: "POST"
});
23 changes: 22 additions & 1 deletion src/views/admin/settings/VendorManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ref, onMounted } from "vue";
import { useVendorApi, statusList } from "@/hooks/admin/setting/useVendor";
import { getAppIcon } from "@/utils/index";
import VendorEditor from "@/components/admin/dialogs/editVendor.vue";
import { RefreshRight } from "@element-plus/icons-vue";
const props = defineProps<{
title: string;
Expand All @@ -16,7 +17,8 @@ const {
currentPage,
pageSize,
selections,
batchDelete
batchDelete,
batchReconnect
} = useVendorApi();
const handleSelectionChange = (e: { info: { backend: { endpoint: string } } }[]) => {
Expand Down Expand Up @@ -45,6 +47,15 @@ onMounted(async () => {
</template>
</el-popconfirm>

<el-button
v-if="selections.length >= 2"
class="max-xl:mt-3"
type="primary"
@click="batchReconnect(selections)"
>
批量重连
</el-button>

<el-button
class="max-xl:mt-3"
type="primary"
Expand Down Expand Up @@ -89,6 +100,16 @@ onMounted(async () => {
statusList[scope.row.status as 0 | 1 | 2 | 3 | 4].name
}}</el-tag>
<el-tag v-else type="info">无效状态</el-tag>
<el-tooltip v-if="scope.row.status > 0">
<template #content>重新连接</template>
<el-button
class="ml-2"
:icon="RefreshRight"
size="small"
circle
@click="batchReconnect(scope.row.info.backend.endpoint)"
/>
</el-tooltip>
</template>
</el-table-column>

Expand Down

0 comments on commit dbd16d2

Please sign in to comment.