forked from natuka/web.puabadge.com
修改:场景道具bug处理
This commit is contained in:
1 parent
31754ef398
commit
3c3c71ebee
3 files changed
+102
-14
No files matched your search
@@ -36,14 +36,15 @@
|
||||
class="composer__title-input"
|
||||
type="text"
|
||||
:value="productTitle"
|
||||
:maxlength="titleSpec.max"
|
||||
:maxlength="titleInputMaxlength"
|
||||
:placeholder="titleSpec.placeholder"
|
||||
:disabled="disabled"
|
||||
:aria-invalid="titleInvalid"
|
||||
@input="onTitleInput"
|
||||
/>
|
||||
<span class="composer__title-count">{{ productTitleLength }} / {{ titleSpec.max }}</span>
|
||||
<span class="composer__title-count">{{ titleCount }} / {{ titleSpec.max }}</span>
|
||||
</div>
|
||||
<p v-if="titleSpec.hint" class="composer__title-hint">{{ titleSpec.hint }}</p>
|
||||
<p v-if="titleInvalid" class="composer__title-error" role="alert">
|
||||
请填写{{ titleSpec.label }}
|
||||
</p>
|
||||
@@ -96,7 +97,11 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { Close, EditPen, Loading, Lock, Picture, Top } from '@element-plus/icons-vue'
|
||||
import type { ProductTitleSpec } from '@/utils/jingdong-product-title'
|
||||
import {
|
||||
clampSceneProps,
|
||||
splitSceneProps,
|
||||
type ProductTitleSpec,
|
||||
} from '@/utils/jingdong-product-title'
|
||||
|
||||
export type ComposerTag = {
|
||||
key: string
|
||||
@@ -159,7 +164,20 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const titleInputId = 'jd-composer-product-title'
|
||||
const productTitleLength = computed(() => String(props.productTitle || '').length)
|
||||
const isPropsTitle = computed(() => props.titleSpec?.mode === 'props')
|
||||
|
||||
/** 道具模式不按字符截断;字符模式仍用 max */
|
||||
const titleInputMaxlength = computed(() => {
|
||||
if (!props.titleSpec) return undefined
|
||||
if (props.titleSpec.mode === 'props') return undefined
|
||||
return props.titleSpec.max
|
||||
})
|
||||
|
||||
const titleCount = computed(() => {
|
||||
const text = String(props.productTitle || '')
|
||||
if (isPropsTitle.value) return splitSceneProps(text).length
|
||||
return text.length
|
||||
})
|
||||
|
||||
const iconMap = {
|
||||
lock: Lock,
|
||||
@@ -200,7 +218,14 @@ function onInput(e: Event) {
|
||||
|
||||
function onTitleInput(e: Event) {
|
||||
const target = e.target as HTMLInputElement
|
||||
emit('update:productTitle', target.value)
|
||||
const raw = target.value
|
||||
if (props.titleSpec?.mode === 'props') {
|
||||
const next = clampSceneProps(raw, props.titleSpec.max)
|
||||
if (next !== raw) target.value = next
|
||||
emit('update:productTitle', next)
|
||||
return
|
||||
}
|
||||
emit('update:productTitle', raw)
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
@@ -400,6 +425,13 @@ defineExpose({ focus, getPreviewEl, getFlyTargetEl })
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.composer__title-hint {
|
||||
margin: 6px 0 0;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.composer__title-error {
|
||||
margin: 6px 0 0;
|
||||
font-size: 12px;
|
||||
|
||||
Reference in new issue
Block a user