Spaces:
Running
Running
File size: 10,967 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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
<script setup>
import { useDashboardStore } from '../../../stores/dashboard'
import { ref, reactive, watch } from 'vue'
const dashboardStore = useDashboardStore()
// Initialize localConfig with default structure
const localConfig = reactive({
searchMode: false,
searchPrompt: '',
maxRetryNum: 0,
fakeStreaming: false,
fakeStreamingInterval: 0,
randomString: false,
randomStringLength: 0,
concurrentRequests: 1, // Default to 1 or a sensible minimum
increaseConcurrentOnFailure: 0,
maxConcurrentRequests: 1, // Default to 1 or a sensible minimum
maxEmptyResponses: 0
})
const populatedFromStore = ref(false);
// Watch for store changes to populate localConfig ONCE when config is loaded
watch(
() => ({
storeSearchMode: dashboardStore.config.searchMode,
storeSearchPrompt: dashboardStore.config.searchPrompt,
storeMaxRetryNum: dashboardStore.config.maxRetryNum,
storeFakeStreaming: dashboardStore.config.fakeStreaming,
storeFakeStreamingInterval: dashboardStore.config.fakeStreamingInterval,
storeRandomString: dashboardStore.config.randomString,
storeRandomStringLength: dashboardStore.config.randomStringLength,
storeConcurrentRequests: dashboardStore.config.concurrentRequests,
storeIncreaseConcurrentOnFailure: dashboardStore.config.increaseConcurrentOnFailure,
storeMaxConcurrentRequests: dashboardStore.config.maxConcurrentRequests,
storeMaxEmptyResponses: dashboardStore.config.maxEmptyResponses,
configIsActuallyLoaded: dashboardStore.isConfigLoaded, // 观察加载状态
}),
(newValues) => {
if (newValues.configIsActuallyLoaded && !populatedFromStore.value) {
localConfig.searchMode = newValues.storeSearchMode;
localConfig.searchPrompt = newValues.storeSearchPrompt;
localConfig.maxRetryNum = newValues.storeMaxRetryNum;
localConfig.fakeStreaming = newValues.storeFakeStreaming;
localConfig.fakeStreamingInterval = newValues.storeFakeStreamingInterval;
localConfig.randomString = newValues.storeRandomString;
localConfig.randomStringLength = newValues.storeRandomStringLength;
localConfig.concurrentRequests = newValues.storeConcurrentRequests;
localConfig.increaseConcurrentOnFailure = newValues.storeIncreaseConcurrentOnFailure;
localConfig.maxConcurrentRequests = newValues.storeMaxConcurrentRequests;
localConfig.maxEmptyResponses = newValues.storeMaxEmptyResponses;
populatedFromStore.value = true;
}
},
{ deep: true, immediate: true }
)
// 保存组件配置
async function saveComponentConfigs(passwordFromParent) {
if (!passwordFromParent) {
return { success: false, message: '功能配置: 密码未提供' }
}
let allSucceeded = true;
let individualMessages = [];
// 逐个保存配置项
const configKeys = Object.keys(localConfig);
for (const key of configKeys) {
if (localConfig[key] !== dashboardStore.config[key]) {
try {
await dashboardStore.updateConfig(key, localConfig[key], passwordFromParent);
// 更新store中的值 - 仅在API调用成功后
dashboardStore.config[key] = localConfig[key];
individualMessages.push(`${key} 保存成功`);
} catch (error) {
allSucceeded = false;
individualMessages.push(`${key} 保存失败: ${error.message || '未知错误'}`);
}
}
}
if (allSucceeded && individualMessages.length === 0) {
// 如果没有任何更改,也算成功,但提示用户
return { success: true, message: '功能配置: 无更改需要保存' };
}
return {
success: allSucceeded,
message: `功能配置: ${individualMessages.join('; ')}`
};
}
// 获取布尔值显示文本
function getBooleanText(value) {
return value ? '启用' : '禁用'
}
defineExpose({
saveComponentConfigs,
localConfig
})
</script>
<template>
<div class="features-config">
<h3 class="section-title">功能配置</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="searchMode" v-model="localConfig.searchMode">
<label for="searchMode" class="toggle-label">
<span class="toggle-text">{{ getBooleanText(localConfig.searchMode) }}</span>
</label>
</div>
</div>
<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">伪装信息</label>
<div class="toggle-wrapper">
<input type="checkbox" class="toggle" id="randomString" v-model="localConfig.randomString">
<label for="randomString" class="toggle-label">
<span class="toggle-text">{{ getBooleanText(localConfig.randomString) }}</span>
</label>
</div>
</div>
</div>
<!-- 字符串配置项 -->
<div class="config-row">
<div class="config-group full-width">
<label class="config-label">联网搜索提示</label>
<input
type="text"
class="config-input"
v-model="localConfig.searchPrompt"
placeholder="请输入联网搜索提示"
>
</div>
</div>
<!-- 数值配置项第一行 -->
<div class="config-row">
<div class="config-group">
<label class="config-label">最大重试次数</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.maxRetryNum"
min="0"
>
</div>
<div class="config-group">
<label class="config-label">假流式间隔(秒)</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.fakeStreamingInterval"
min="0"
step="0.1"
>
</div>
<div class="config-group">
<label class="config-label">伪装信息长度</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.randomStringLength"
min="0"
>
</div>
</div>
<!-- 数值配置项第二行 -->
<div class="config-row">
<div class="config-group">
<label class="config-label">默认并发请求数</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.concurrentRequests"
min="1"
>
</div>
<div class="config-group">
<label class="config-label">失败时增加并发数</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.increaseConcurrentOnFailure"
min="0"
>
</div>
<div class="config-group">
<label class="config-label">最大并发请求数</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.maxConcurrentRequests"
min="1"
>
</div>
</div>
<!-- 数值配置项第三行 -->
<div class="config-row">
<div class="config-group">
<label class="config-label">空响应重试限制</label>
<input
type="number"
class="config-input"
v-model.number="localConfig.maxEmptyResponses"
min="0"
>
</div>
<!-- 可以根据需要在此行添加更多配置项 -->
<div class="config-group"></div>
<div class="config-group"></div>
</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);
}
.features-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);
}
/* 开关样式 */
.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);
}
/* 移动端优化 */
@media (max-width: 768px) {
.config-row {
gap: 10px;
}
.config-group {
min-width: 100px;
}
}
/* 小屏幕手机进一步优化 */
@media (max-width: 480px) {
.config-row {
flex-direction: column;
gap: 10px;
}
.config-group {
width: 100%;
}
.config-form {
padding: 15px;
}
}
</style> |