Spaces:
Running
Running
File size: 7,950 Bytes
d0dd276 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
<script setup>
import { useDashboardStore } from '../../../stores/dashboard'
import { ref, reactive } from 'vue'
const dashboardStore = useDashboardStore()
// 创建本地配置副本用于编辑
const localConfig = reactive({
fakeStreaming: dashboardStore.config.fakeStreaming,
enableVertexExpress: dashboardStore.config.enableVertexExpress,
vertexExpressApiKey: dashboardStore.config.vertexExpressApiKey || '',
googleCredentialsJson: dashboardStore.config.googleCredentialsJson || ''
})
// 密码和错误信息
const password = ref('')
const errorMsg = ref('')
const successMsg = ref('')
const isSaving = ref(false)
// 保存所有配置
async function saveAllConfigs() {
if (!password.value) {
errorMsg.value = '请输入密码'
return
}
isSaving.value = true
errorMsg.value = ''
successMsg.value = ''
try {
// 逐个保存配置项
const configKeys = Object.keys(localConfig)
for (const key of configKeys) {
// 如果配置有变化才更新
if (localConfig[key] !== dashboardStore.config[key]) {
await dashboardStore.updateConfig(key, localConfig[key], password.value)
// 更新store中的值
dashboardStore.config[key] = localConfig[key]
}
}
successMsg.value = '所有配置已保存'
} catch (error) {
errorMsg.value = error.message || '保存失败'
} finally {
isSaving.value = false
}
}
// 获取布尔值显示文本
function getBooleanText(value) {
return value ? '启用' : '禁用'
}
</script>
<template>
<div class="vertex-config">
<h3 class="section-title">Vertex 配置</h3>
<div class="config-form">
<!-- 布尔值配置项 -->
<div class="config-row">
<div class="config-group">
<label class="config-label">假流式响应</label>
<div class="toggle-wrapper">
<input type="checkbox" class="toggle" id="fakeStreaming" v-model="localConfig.fakeStreaming">
<label for="fakeStreaming" class="toggle-label">
<span class="toggle-text">{{ getBooleanText(localConfig.fakeStreaming) }}</span>
</label>
</div>
</div>
<div class="config-group">
<label class="config-label">Vertex Express</label>
<div class="toggle-wrapper">
<input type="checkbox" class="toggle" id="enableVertexExpress" v-model="localConfig.enableVertexExpress">
<label for="enableVertexExpress" class="toggle-label">
<span class="toggle-text">{{ getBooleanText(localConfig.enableVertexExpress) }}</span>
</label>
</div>
</div>
</div>
<!-- API Key 配置项 -->
<div class="config-row">
<div class="config-group full-width">
<label class="config-label">Vertex Express API密钥</label>
<input
type="password"
class="config-input"
v-model="localConfig.vertexExpressApiKey"
placeholder="请输入 Vertex Express API密钥"
>
</div>
</div>
<!-- Google Credentials JSON 配置项 -->
<div class="config-row">
<div class="config-group full-width">
<label class="config-label">Google Credentials JSON</label>
<textarea
class="config-input text-area"
v-model="localConfig.googleCredentialsJson"
placeholder="请输入 Google Credentials JSON"
></textarea>
</div>
</div>
<!-- 保存区域 -->
<div class="save-section">
<div class="password-input">
<input
type="password"
v-model="password"
placeholder="请输入管理密码"
class="config-input"
>
</div>
<button
class="save-button"
@click="saveAllConfigs"
:disabled="isSaving"
>
{{ isSaving ? '保存中...' : '保存所有配置' }}
</button>
</div>
<!-- 消息提示 -->
<div v-if="errorMsg" class="error-message">{{ errorMsg }}</div>
<div v-if="successMsg" class="success-message">{{ successMsg }}</div>
</div>
</div>
</template>
<style scoped>
.section-title {
color: var(--color-heading);
border-bottom: 1px solid var(--color-border);
padding-bottom: 10px;
margin-bottom: 20px;
transition: all 0.3s ease;
position: relative;
font-weight: 600;
}
.section-title::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
width: 50px;
height: 2px;
background: var(--gradient-primary);
}
.vertex-config {
margin-bottom: 25px;
}
.config-form {
background-color: var(--stats-item-bg);
border-radius: var(--radius-lg);
padding: 20px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--card-border);
}
.config-row {
display: flex;
gap: 15px;
margin-bottom: 15px;
flex-wrap: wrap;
}
.config-group {
flex: 1;
min-width: 120px;
}
.full-width {
flex-basis: 100%;
}
.config-label {
display: block;
font-size: 14px;
margin-bottom: 5px;
color: var(--color-text);
font-weight: 500;
}
.config-input {
width: 100%;
padding: 8px 12px;
border: 1px solid var(--color-border);
border-radius: var(--radius-md);
background-color: var(--color-background);
color: var(--color-text);
font-size: 14px;
transition: all 0.3s ease;
}
.config-input:focus {
outline: none;
border-color: var(--button-primary);
box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}
.text-area {
resize: vertical;
min-height: 80px;
font-family: inherit;
line-height: 1.5;
}
/* 开关样式 */
.toggle-wrapper {
position: relative;
}
.toggle {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.toggle-label {
display: flex;
align-items: center;
cursor: pointer;
user-select: none;
}
.toggle-label::before {
content: '';
display: inline-block;
width: 36px;
height: 20px;
background-color: var(--color-border);
border-radius: 10px;
margin-right: 8px;
position: relative;
transition: all 0.3s ease;
}
.toggle-label::after {
content: '';
position: absolute;
left: 3px;
width: 14px;
height: 14px;
background-color: white;
border-radius: 50%;
transition: all 0.3s ease;
}
.toggle:checked + .toggle-label::before {
background-color: var(--button-primary);
}
.toggle:checked + .toggle-label::after {
left: 19px;
}
.toggle-text {
font-size: 14px;
color: var(--color-text);
}
/* 保存区域样式 */
.save-section {
display: flex;
gap: 10px;
margin-top: 20px;
align-items: center;
}
.password-input {
flex: 1;
}
.save-button {
padding: 8px 16px;
background: var(--button-primary);
color: white;
border: none;
border-radius: var(--radius-md);
cursor: pointer;
font-weight: 500;
transition: all 0.3s ease;
}
.save-button:hover {
background: var(--button-primary-hover);
transform: translateY(-2px);
}
.save-button:disabled {
opacity: 0.7;
cursor: not-allowed;
transform: none;
}
.error-message {
color: var(--color-error);
margin-top: 10px;
font-size: 14px;
padding: 8px;
background-color: var(--color-error-bg);
border-radius: var(--radius-md);
}
.success-message {
color: var(--color-success);
margin-top: 10px;
font-size: 14px;
padding: 8px;
background-color: var(--color-success-bg);
border-radius: var(--radius-md);
}
/* 移动端优化 */
@media (max-width: 768px) {
.config-row {
gap: 10px;
}
.config-group {
min-width: 100px;
}
.save-section {
flex-direction: column;
}
.password-input {
width: 100%;
margin-bottom: 10px;
}
.save-button {
width: 100%;
}
}
/* 小屏幕手机进一步优化 */
@media (max-width: 480px) {
.config-row {
flex-direction: column;
gap: 10px;
}
.config-group {
width: 100%;
}
.config-form {
padding: 15px;
}
}
</style> |