better-staridc-MNBT
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-key-variant"></i>API 设置</h3>
6 <p class="td-page-subtitle">接口密钥、建站目录与外部调用开关</p>
7 </div>
8 </div>
9
10 <div class="td-set-card">
11 <div class="td-set-card-hd">
12 <div class="td-set-icon"><i class="mdi mdi-key-variant"></i></div>
13 <div>
14 <h4>API 设置</h4>
15 <p>接口密钥、建站目录与外部调用开关</p>
16 </div>
17 </div>
18 <div class="td-set-card-bd">
19 <t-loading :loading="loading" text="保存中…" size="small">
20 <div class="td-form">
21 <div class="td-form-row">
22 <label>API 密钥</label>
23 <div class="api-key-row">
24 <t-input v-model="form.api" placeholder="API密钥(推荐随机生成)" clearable>
25 <template #prefix-icon><i class="mdi mdi-key"></i></template>
26 </t-input>
27 <t-button theme="default" variant="outline" @click="genApiKey">
28 <i class="mdi mdi-shuffle-variant"></i> 随机生成
29 </t-button>
30 </div>
31 <div class="td-form-hint">用于监控 URL 与外部系统对接,请妥善保管</div>
32 </div>
33
34 <div class="td-form-row">
35 <label>Linux 建站目录</label>
36 <t-input v-model="form.hxi" placeholder="Linux宝塔面板的建站目录">
37 <template #prefix-icon><i class="mdi mdi-linux"></i></template>
38 </t-input>
39 <div class="td-form-hint">默认 /www/wwwroot</div>
40 </div>
41
42 <div class="td-form-row">
43 <label>Windows 建站目录</label>
44 <t-input v-model="form.hxo" placeholder="Windows宝塔面板的建站目录">
45 <template #prefix-icon><i class="mdi mdi-microsoft-windows"></i></template>
46 </t-input>
47 <div class="td-form-hint">默认 D:/wwwroot</div>
48 </div>
49
50 <div class="td-form-switch">
51 <div class="td-form-switch-txt">
52 <strong>API 接口开关</strong>
53 <span>关闭后外部系统将无法调用接口</span>
54 </div>
55 <t-switch v-model="form.apiqk" />
56 </div>
57
58 <div class="td-form-note">
59 <b>注意:</b> 建站目录请勿随意修改,已开通主机可能受影响。API 密钥修改后,监控 URL 与外部对接均需同步更新。
60 </div>
61
62 <div class="td-form-actions">
63 <t-button theme="primary" :loading="loading" @click="save">
64 <i class="mdi mdi-content-save-outline"></i> 保存修改
65 </t-button>
66 </div>
67 </div>
68 </t-loading>
69 </div>
70 </div>
71 </div>
72</template>
73
74<script setup>
75import { reactive, ref } from 'vue'
76import { MessagePlugin } from 'tdesign-vue-next'
77import { setApi } from '@/admin/api/settings'
78
79const boot = window.__TD_BOOT__ || {}
80const conf = boot.conf || {}
81const loading = ref(false)
82
83const form = reactive({
84 api: conf.api || '',
85 hxi: conf.hxi || '/www/wwwroot',
86 hxo: conf.hxo || 'D:/wwwroot',
87 apiqk: conf.apiqk === 'true',
88})
89
90function genApiKey() {
91 form.api = Math.random().toString(36).slice(2) + Date.now().toString(36)
92 MessagePlugin.success('已生成新密钥,请记得保存')
93}
94
95async function save() {
96 if (!form.api || !form.hxi || !form.hxo) {
97 MessagePlugin.warning('请将表单填写完整')
98 return
99 }
100 loading.value = true
101 const r = await setApi({
102 apikey: form.api,
103 linux: form.hxi,
104 windows: form.hxo,
105 apiqk: form.apiqk ? 'true' : 'false',
106 })
107 loading.value = false
108 if (r.ok) MessagePlugin.success('保存成功')
109}
110</script>
111
112<style scoped>
113.api-key-row {
114 display: flex;
115 gap: 8px;
116 align-items: center;
117}
118.api-key-row :deep(.t-input) {
119 flex: 1;
120 min-width: 0;
121}
122</style>