Skip to content

Commit 93c3709

Browse files
committed
feat(ui): 临时隐藏 Pro 模式的系统提示词优化选项
- OptimizationModeSelector 组件添加 hideSystemOption prop - useProSubMode 默认值改为 user 并强制切换逻辑 - Web/Extension 应用的 Pro 模式选择器隐藏系统选项 - 切换到 Pro 模式时自动使用用户提示词优化 - 为将来恢复系统模式预留接口
1 parent f0c5caf commit 93c3709

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

packages/extension/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<OptimizationModeSelectorUI
3939
v-if="functionMode === 'pro'"
4040
:modelValue="proSubMode"
41+
:hide-system-option="true"
4142
@change="handleProSubModeChange"
4243
/>
4344

packages/ui/src/components/OptimizationModeSelector.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class="optimization-mode-selector"
88
>
99
<NRadioButton
10+
v-if="!hideSystemOption"
1011
value="system"
1112
:title="t('promptOptimizer.systemPromptHelp')"
1213
>
@@ -30,14 +31,18 @@ const { t } = useI18n()
3031
3132
interface Props {
3233
modelValue: OptimizationMode
34+
/** 是否隐藏系统提示词选项(用于临时禁用功能) */
35+
hideSystemOption?: boolean
3336
}
3437
3538
interface Emits {
3639
(e: 'update:modelValue', value: OptimizationMode): void
3740
(e: 'change', value: OptimizationMode): void
3841
}
3942
40-
const props = defineProps<Props>()
43+
const props = withDefaults(defineProps<Props>(), {
44+
hideSystemOption: false,
45+
})
4146
const emit = defineEmits<Emits>()
4247
4348
/**

packages/ui/src/composables/mode/useProSubMode.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ let singleton: {
2020

2121
/**
2222
* 上下文模式(Pro模式)的子模式单例。读取/写入 PreferenceService。
23-
* - 默认值为 'system'(系统提示词优化)
23+
* - 默认值为 'user'(用户提示词优化)
24+
* - 系统提示词优化暂时隐藏,切换到 Pro 模式时强制使用 'user'
2425
* - 第一次调用时异步初始化
2526
* - 状态独立于基础模式,实现不同功能模式下的子模式状态隔离
2627
*/
2728
export function useProSubMode(services: Ref<AppServices | null>): UseProSubModeApi {
2829
if (!singleton) {
29-
singleton = { mode: ref<ProSubMode>('system'), initialized: false, initializing: null }
30+
singleton = { mode: ref<ProSubMode>('user'), initialized: false, initializing: null }
3031
}
3132

3233
const { getPreference, setPreference } = usePreferences(services)
@@ -39,21 +40,31 @@ export function useProSubMode(services: Ref<AppServices | null>): UseProSubModeA
3940
}
4041
singleton!.initializing = (async () => {
4142
try {
42-
// 读取 pro-sub-mode;若不存在,返回默认 'system'
43-
const saved = await getPreference<ProSubMode>(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'system')
44-
singleton!.mode.value = (saved === 'system' || saved === 'user') ? saved : 'system'
43+
// 读取 pro-sub-mode;若不存在,返回默认 'user'
44+
const saved = await getPreference<ProSubMode>(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'user')
45+
46+
// 强制使用 'user' 模式(临时禁用 'system' 模式)
47+
// 如果之前保存的是 'system',自动切换为 'user'
48+
if (saved === 'system') {
49+
singleton!.mode.value = 'user'
50+
await setPreference(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'user')
51+
console.log('[useProSubMode] 检测到旧的 system 模式,已强制切换为 user')
52+
} else {
53+
singleton!.mode.value = (saved === 'user') ? saved : 'user'
54+
}
55+
4556
console.log(`[useProSubMode] 初始化完成,当前值: ${singleton!.mode.value}`)
4657

47-
// 将默认值持久化(若未设置过
48-
if (saved !== 'system' && saved !== 'user') {
49-
await setPreference(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'system')
50-
console.log('[useProSubMode] 首次初始化,已持久化默认值: system')
58+
// 将默认值持久化(若未设置过或值无效
59+
if (saved !== 'user') {
60+
await setPreference(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'user')
61+
console.log('[useProSubMode] 已持久化默认值: user')
5162
}
5263
} catch (e) {
53-
console.error('[useProSubMode] 初始化失败,使用默认值 system:', e)
54-
// 读取失败则保持默认 'system',并尝试持久化
64+
console.error('[useProSubMode] 初始化失败,使用默认值 user:', e)
65+
// 读取失败则保持默认 'user',并尝试持久化
5566
try {
56-
await setPreference(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'system')
67+
await setPreference(UI_SETTINGS_KEYS.PRO_SUB_MODE, 'user')
5768
} catch {
5869
// 忽略设置失败错误
5970
}

packages/web/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<OptimizationModeSelectorUI
3939
v-if="functionMode === 'pro'"
4040
:modelValue="proSubMode"
41+
:hide-system-option="true"
4142
@change="handleProSubModeChange"
4243
/>
4344

0 commit comments

Comments
 (0)