dodo hold il y a 1 jour
Parent
commit
b06edbb686
2 fichiers modifiés avec 68 ajouts et 1 suppressions
  1. 15 0
      src/api/proxy.ts
  2. 53 1
      src/views/settings/proxyNodes.vue

+ 15 - 0
src/api/proxy.ts

@@ -57,6 +57,12 @@ export interface ProxyCheckResponse extends FormRes {
     check?: ProxyCheckChannelResult;
 }
 
+export interface ChangePublicIpResponse {
+    success?: string;
+    code?: number;
+    msg?: string;
+}
+
 export function queryProxyNodeList(data: ProxyNodeListParams) {
     return axios.post<ProxyNodeListData>('/api/proxy/list', data);
 }
@@ -71,6 +77,15 @@ export function checkProxyNode(id: number, target: ProxyCheckTarget) {
     );
 }
 
+// This endpoint is public and must not receive the authenticated API headers.
+const publicIpClient = axios.create();
+
+export function changePublicIp(id: number) {
+    return publicIpClient.get<ChangePublicIpResponse>(
+        `https://adminapi.molilian.com/Test/changepublicip?id=${id}`
+    );
+}
+
 export function changePublicIpByName(nodeName: string) {
     return axios.get<FormRes>(
         `/api/proxy/changePublicIpByName?nodeName=${encodeURIComponent(

+ 53 - 1
src/views/settings/proxyNodes.vue

@@ -576,6 +576,19 @@
                             </div>
                         </template>
                     </a-table-column>
+
+                    <a-table-column title="操作" :width="140" fixed="right">
+                        <template #cell="{ record }">
+                            <a-button
+                                type="primary"
+                                size="small"
+                                :loading="isChangingPublicIp(record.id)"
+                                @click="handleChangePublicIp(record)"
+                            >
+                                更换公网IP
+                            </a-button>
+                        </template>
+                    </a-table-column>
                 </template>
             </a-table>
         </a-card>
@@ -585,7 +598,7 @@
 <script lang="ts" setup>
     import { computed, reactive, ref } from 'vue';
     import dayjs from 'dayjs';
-    import { Message, Modal } from '@arco-design/web-vue';
+    import { Message, Modal, Notification } from '@arco-design/web-vue';
     import useLoading from '@/hooks/loading';
     import {
         ProxyCheckChannelResult,
@@ -594,6 +607,7 @@
         ProxyNodeRecord,
         ProxyNodeUsageAccount,
         checkProxyNode,
+        changePublicIp,
         queryProxyNodeList,
         updateProxyNode,
     } from '@/api/proxy';
@@ -622,6 +636,7 @@
     const expandedIds = ref<number[]>([]);
     const checkingKeys = ref<string[]>([]);
     const updatingIds = ref<number[]>([]);
+    const changingPublicIpIds = ref<number[]>([]);
     const checkResults = ref<Record<number, ProxyCheckState>>({});
 
     const statusOptions = [
@@ -886,6 +901,43 @@
     const removeLoadingId = (ids: number[], id: number) =>
         ids.filter((item) => item !== id);
 
+    const isChangingPublicIp = (id: number) =>
+        changingPublicIpIds.value.includes(id);
+
+    const handleChangePublicIp = async (record: ProxyNodeRecord) => {
+        if (isChangingPublicIp(record.id)) return;
+
+        changingPublicIpIds.value = addLoadingId(
+            changingPublicIpIds.value,
+            record.id
+        );
+        try {
+            const response = await changePublicIp(record.id);
+            const result = response.data;
+            if (result.success === 'ok' && result.code === 200) {
+                Notification.success({
+                    title: '更换公网IP成功',
+                    content: `节点 ${record.id} 的公网IP已更换`,
+                });
+            } else {
+                Notification.error({
+                    title: '更换公网IP失败',
+                    content: result.msg || '接口返回异常',
+                });
+            }
+        } catch {
+            Notification.error({
+                title: '更换公网IP失败',
+                content: '请求失败,请稍后重试',
+            });
+        } finally {
+            changingPublicIpIds.value = removeLoadingId(
+                changingPublicIpIds.value,
+                record.id
+            );
+        }
+    };
+
     const getCheckKey = (id: number, target: ProxyCheckTarget) =>
         `${id}-${target}`;