Skip to content

Commit a97c795

Browse files
committed
feat(web): apply milkdown editor
1 parent e9384df commit a97c795

4 files changed

Lines changed: 100 additions & 59 deletions

File tree

apps/web/app/pages/edit/create.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,9 @@ const handleSubmit = async () => {
470470

471471
<section class="space-y-2">
472472
<h3 class="font-semibold">简介(简体中文)</h3>
473-
<KunTextarea
474-
v-model="submitForm.intro_zh_cn"
475-
:rows="5"
476-
placeholder="支持 Markdown,可选"
473+
<KunMilkdownDualEditorProvider
474+
:value-markdown="submitForm.intro_zh_cn"
475+
@set-markdown="(val) => (submitForm.intro_zh_cn = val)"
477476
/>
478477
</section>
479478

apps/web/app/pages/edit/draft.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,9 @@ const handleSubmit = async () => {
219219

220220
<section class="space-y-2">
221221
<h3 class="font-semibold">简介(简体中文)</h3>
222-
<KunTextarea
223-
v-model="form.intro_zh_cn"
224-
:rows="5"
225-
placeholder="支持 Markdown"
222+
<KunMilkdownDualEditorProvider
223+
:value-markdown="form.intro_zh_cn"
224+
@set-markdown="(val) => (form.intro_zh_cn = val)"
226225
/>
227226
</section>
228227

apps/web/app/pages/edit/rewrite.vue

Lines changed: 86 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,80 @@ const LANG_TABS: { value: LangKey; textValue: string }[] = [
5757
]
5858
const activeLang = ref<LangKey>('zh-cn')
5959
60+
// One name input + one milkdown editor serve all 4 languages: the editor is
61+
// reused, and switching activeLang drives its `:language` prop, which makes
62+
// the editor replaceAll() its content with the new language's intro. We expose
63+
// the active language's name/intro as proxies so the single controls read and
64+
// write the right form field.
65+
const activeName = computed<string>({
66+
get() {
67+
switch (activeLang.value) {
68+
case 'zh-tw':
69+
return form.name_zh_tw
70+
case 'ja-jp':
71+
return form.name_ja_jp
72+
case 'en-us':
73+
return form.name_en_us
74+
default:
75+
return form.name_zh_cn
76+
}
77+
},
78+
set(v) {
79+
switch (activeLang.value) {
80+
case 'zh-tw':
81+
form.name_zh_tw = v
82+
break
83+
case 'ja-jp':
84+
form.name_ja_jp = v
85+
break
86+
case 'en-us':
87+
form.name_en_us = v
88+
break
89+
default:
90+
form.name_zh_cn = v
91+
}
92+
}
93+
})
94+
const activeIntro = computed(() => {
95+
switch (activeLang.value) {
96+
case 'zh-tw':
97+
return form.intro_zh_tw
98+
case 'ja-jp':
99+
return form.intro_ja_jp
100+
case 'en-us':
101+
return form.intro_en_us
102+
default:
103+
return form.intro_zh_cn
104+
}
105+
})
106+
const setActiveIntro = (val: string) => {
107+
switch (activeLang.value) {
108+
case 'zh-tw':
109+
form.intro_zh_tw = val
110+
break
111+
case 'ja-jp':
112+
form.intro_ja_jp = val
113+
break
114+
case 'en-us':
115+
form.intro_en_us = val
116+
break
117+
default:
118+
form.intro_zh_cn = val
119+
}
120+
}
121+
const namePlaceholder = computed(() => {
122+
switch (activeLang.value) {
123+
case 'zh-tw':
124+
return '繁體中文名稱'
125+
case 'ja-jp':
126+
return '日本語タイトル'
127+
case 'en-us':
128+
return 'English title'
129+
default:
130+
return '例如:你和她和她的恋爱'
131+
}
132+
})
133+
60134
interface FormState {
61135
name_en_us: string
62136
name_ja_jp: string
@@ -400,53 +474,18 @@ const handleSubmit = async () => {
400474
color="primary"
401475
size="sm"
402476
/>
403-
<div v-for="lang in LANG_TABS" :key="lang.value">
404-
<div v-show="activeLang === lang.value" class="space-y-3">
405-
<label class="block">
406-
<span class="text-default-700 text-sm">标题</span>
407-
<KunInput
408-
v-if="lang.value === 'zh-cn'"
409-
v-model="form.name_zh_cn"
410-
placeholder="例如:你和她和她的恋爱"
411-
/>
412-
<KunInput
413-
v-else-if="lang.value === 'zh-tw'"
414-
v-model="form.name_zh_tw"
415-
placeholder="繁體中文名稱"
416-
/>
417-
<KunInput
418-
v-else-if="lang.value === 'ja-jp'"
419-
v-model="form.name_ja_jp"
420-
placeholder="日本語タイトル"
421-
/>
422-
<KunInput
423-
v-else
424-
v-model="form.name_en_us"
425-
placeholder="English title"
426-
/>
427-
</label>
428-
<label class="block">
429-
<span class="text-default-700 text-sm">简介 (Markdown)</span>
430-
<KunTextarea
431-
v-if="lang.value === 'zh-cn'"
432-
v-model="form.intro_zh_cn"
433-
:rows="10"
434-
placeholder="支持 Markdown 语法"
435-
/>
436-
<KunTextarea
437-
v-else-if="lang.value === 'zh-tw'"
438-
v-model="form.intro_zh_tw"
439-
:rows="10"
440-
/>
441-
<KunTextarea
442-
v-else-if="lang.value === 'ja-jp'"
443-
v-model="form.intro_ja_jp"
444-
:rows="10"
445-
/>
446-
<KunTextarea v-else v-model="form.intro_en_us" :rows="10" />
447-
</label>
448-
</div>
449-
</div>
477+
<label class="block space-y-1">
478+
<span class="text-default-700 text-sm">标题</span>
479+
<KunInput v-model="activeName" :placeholder="namePlaceholder" />
480+
</label>
481+
<label class="block space-y-1">
482+
<span class="text-default-700 text-sm">简介 (Markdown)</span>
483+
<KunMilkdownDualEditorProvider
484+
:value-markdown="activeIntro"
485+
:language="activeLang"
486+
@set-markdown="setActiveIntro"
487+
/>
488+
</label>
450489
</div>
451490

452491
<!-- ─── 基本信息:rating + language + aliases + is_minor ────── -->

apps/web/app/pages/patch/[id]/comment.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const comments = computed(() => data.value?.items ?? [])
3434
3535
const content = ref('')
3636
const submitting = ref(false)
37+
// KunMilkdownDualEditorProvider is uncontrolled (valueMarkdown is the initial
38+
// value only), so bump this key to remount it empty after a successful post.
39+
const composerKey = ref(0)
3740
3841
const submit = async () => {
3942
if (!userStore.user.id) {
@@ -52,6 +55,7 @@ const submit = async () => {
5255
)
5356
if (res.code === 0) {
5457
content.value = ''
58+
composerKey.value++
5559
useKunMessage('评论发布成功', 'success')
5660
await refresh()
5761
} else {
@@ -97,10 +101,10 @@ const toggleLike = async (c: PatchPageComment) => {
97101
>
98102
<KunAvatar :user="userStore.user" size="sm" :is-navigation="false" />
99103
<div class="min-w-0 flex-1 space-y-3">
100-
<KunTextarea
101-
v-model="content"
102-
placeholder="写下你的评论..."
103-
:rows="3"
104+
<KunMilkdownDualEditorProvider
105+
:key="composerKey"
106+
:value-markdown="content"
107+
@set-markdown="(val) => (content = val)"
104108
/>
105109
<div class="flex justify-end">
106110
<KunButton

0 commit comments

Comments
 (0)