(undefined)
+
onMounted(() => {
editor.value = new Editor({
content: props.modelValue,
@@ -58,4 +60,7 @@ onUnmounted(() => {
>
+
+ {{ `${modelValue?.length ?? 0} 长度 · ${countWords(modelValue ?? '')} 字符` }}
+
diff --git a/front/lib/countWords.ts b/front/lib/countWords.ts
new file mode 100644
index 0000000..b6fdd61
--- /dev/null
+++ b/front/lib/countWords.ts
@@ -0,0 +1,9 @@
+function countWords(text: string): number {
+ const trimmed = text?.trim()
+ if (!trimmed) return 0
+ const cjk = trimmed.match(/[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/g)?.length ?? 0
+ const latin = trimmed.replace(/[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/g, ' ').match(/\S+/g)?.length ?? 0
+ return cjk + latin
+}
+
+export default countWords