mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
feat(frontend): enhance SelectField and Tiptap components with improved class handling and word count display
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import type { RuleExpression } from 'vee-validate'
|
||||
type SelectValue = string | number
|
||||
const props = defineProps<{
|
||||
@@ -19,13 +11,14 @@ const props = defineProps<{
|
||||
label?: string
|
||||
value: SelectValue
|
||||
}[]
|
||||
class?: string
|
||||
}>()
|
||||
const { value } = useField<SelectValue>(props.name, props?.rules)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Select v-model="value">
|
||||
<SelectTrigger>
|
||||
<SelectTrigger :class="class">
|
||||
<SelectValue :placeholder="placeholder" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
@@ -37,4 +30,4 @@ const { value } = useField<SelectValue>(props.name, props?.rules)
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
@@ -4,6 +4,7 @@ import StarterKit from '@tiptap/starter-kit'
|
||||
import { Markdown } from 'tiptap-markdown'
|
||||
import Placeholder from '@tiptap/extension-placeholder'
|
||||
import { cx } from 'class-variance-authority'
|
||||
import countWords from '@/lib/countWords'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string
|
||||
@@ -15,6 +16,7 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const editor = ref<Editor | undefined>(undefined)
|
||||
|
||||
onMounted(() => {
|
||||
editor.value = new Editor({
|
||||
content: props.modelValue,
|
||||
@@ -58,4 +60,7 @@ onUnmounted(() => {
|
||||
>
|
||||
</editor-content>
|
||||
<!-- <BubbleMenuView :editor="editor as any" /> -->
|
||||
<div v-if="modelValue?.length && modelValue?.length > 0" class="flex justify-end px-1 pt-1 text-xs text-gray-400 select-none">
|
||||
{{ `${modelValue?.length ?? 0} 长度 · ${countWords(modelValue ?? '')} 字符` }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
9
front/lib/countWords.ts
Normal file
9
front/lib/countWords.ts
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user