feat(notebook): lock material source to notebook when studioToken is provided

- Auto-switch materialSource to 'notebook' on mount when initialNotebookId is set
- Replace material source dropdown with static label when studioToken is present

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
xuhdandClaude Sonnet 4.6 committed 2026-06-05 13:45:24 +08:00
1 parent 0e7149eec3
commit d57bcd9aa2
1 file changed
+32 -17
@@ -97,6 +97,14 @@ export function AIWritingForm({
[models, modelName],
);
// initialNotebookId 存在时自动切换素材来源为「我的笔记」
useEffect(() => {
if (initialNotebookId != null) {
setMaterialSource('notebook');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// 初始化时加载文章类型
useEffect(() => {
refreshTypes();
@@ -276,23 +284,30 @@ export function AIWritingForm({
<div className="mt-4 space-y-2">
<label className={FIELD_LABEL_CLASS}>素材来源</label>
<Select
value={materialSource}
onValueChange={(v) => handleMaterialSourceChange(v as MaterialSource)}
disabled={disabled}
>
<SelectTrigger className={FIELD_TRIGGER_CLASS}>
<SelectValue placeholder="选择素材来源" />
</SelectTrigger>
<SelectContent>
{MATERIAL_SOURCE_OPTIONS.map((opt) => (
<SelectItem key={opt.value} value={opt.value} className="text-sm">
{opt.label}
<span className="ml-1 text-xs text-muted-foreground">— {opt.desc}</span>
</SelectItem>
))}
</SelectContent>
</Select>
{/* studioToken 模式:素材来源已锁定为「我的笔记」,不可切换 */}
{studioToken ? (
<div className={`${FIELD_TRIGGER_CLASS} flex items-center px-3 border rounded-xl bg-white text-sm text-muted-foreground`}>
我的笔记
</div>
) : (
<Select
value={materialSource}
onValueChange={(v) => handleMaterialSourceChange(v as MaterialSource)}
disabled={disabled}
>
<SelectTrigger className={FIELD_TRIGGER_CLASS}>
<SelectValue placeholder="选择素材来源" />
</SelectTrigger>
<SelectContent>
{MATERIAL_SOURCE_OPTIONS.map((opt) => (
<SelectItem key={opt.value} value={opt.value} className="text-sm">
{opt.label}
<span className="ml-1 text-xs text-muted-foreground">— {opt.desc}</span>
</SelectItem>
))}
</SelectContent>
</Select>
)}
{/* 选了"我的笔记"才展示笔记本 / 文档选择器 */}
{materialSource === 'notebook' && (