forked from natuka/web.puabadge.com
修改:京东下单页面优化
This commit is contained in:
1 parent
007c675603
commit
9124c07ad2
7 files changed
+600
-39
No files matched your search
@@ -11,29 +11,60 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div ref="boxRef" class="composer__box">
|
||||
<p v-if="statusTip" class="composer__tip" :class="{ 'is-warn': tipWarn }">{{ statusTip }}</p>
|
||||
|
||||
<div ref="boxRef" class="composer__box" :class="{ 'is-editing': editing, 'is-disabled': disabled }">
|
||||
<div v-if="previewUrl" ref="previewRef" class="composer__preview">
|
||||
<img class="composer__preview-img" :src="previewUrl" alt="已选图片" />
|
||||
<button class="composer__preview-close" type="button" aria-label="移除图片" @click="emit('clear-preview')">
|
||||
<span v-if="inspecting" class="composer__preview-mask">识别中</span>
|
||||
<button
|
||||
v-else
|
||||
class="composer__preview-close"
|
||||
type="button"
|
||||
aria-label="移除图片"
|
||||
@click="emit('clear-preview')"
|
||||
>
|
||||
<el-icon :size="10" color="#fff"><Close /></el-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="titleSpec" class="composer__title" :class="{ 'is-invalid': titleInvalid }">
|
||||
<label class="composer__title-label" :for="titleInputId">{{ titleSpec.label }}</label>
|
||||
<div class="composer__title-field">
|
||||
<input
|
||||
:id="titleInputId"
|
||||
class="composer__title-input"
|
||||
type="text"
|
||||
:value="productTitle"
|
||||
:maxlength="titleSpec.max"
|
||||
:placeholder="titleSpec.placeholder"
|
||||
:disabled="disabled"
|
||||
:aria-invalid="titleInvalid"
|
||||
@input="onTitleInput"
|
||||
/>
|
||||
<span class="composer__title-count">{{ productTitleLength }} / {{ titleSpec.max }}</span>
|
||||
</div>
|
||||
<p v-if="titleInvalid" class="composer__title-error" role="alert">
|
||||
请填写{{ titleSpec.label }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
ref="textareaRef"
|
||||
class="composer__input"
|
||||
rows="2"
|
||||
:value="modelValue"
|
||||
:placeholder="placeholder"
|
||||
:placeholder="resolvedPlaceholder"
|
||||
:disabled="disabled"
|
||||
@input="onInput"
|
||||
@keydown="onKeydown"
|
||||
/>
|
||||
|
||||
<div class="composer__toolbar">
|
||||
<button
|
||||
class="composer__upload"
|
||||
type="button"
|
||||
aria-label="上传图片"
|
||||
:aria-label="editing ? '编辑中不可更换照片' : '上传图片'"
|
||||
:disabled="disabled || editing || inspecting"
|
||||
@click="emit('upload')"
|
||||
>
|
||||
@@ -65,6 +96,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { Close, EditPen, Loading, Picture, Present, Star, Top, User } from '@element-plus/icons-vue'
|
||||
import type { ProductTitleSpec } from '@/utils/jingdong-product-title'
|
||||
|
||||
export type ComposerTag = {
|
||||
key: string
|
||||
@@ -76,6 +108,9 @@ const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: string
|
||||
placeholder?: string
|
||||
placeholderNeedPhoto?: string
|
||||
placeholderEditing?: string
|
||||
placeholderCartoon?: string
|
||||
previewUrl?: string
|
||||
tags?: ComposerTag[]
|
||||
editing?: boolean
|
||||
@@ -85,10 +120,23 @@ const props = withDefaults(
|
||||
canSend?: boolean
|
||||
/** 图片识别 / 主体识别进行中 */
|
||||
inspecting?: boolean
|
||||
/** 当前预览图是否为卡通效果图 */
|
||||
cartoonEffect?: boolean
|
||||
/** 底部状态提示 */
|
||||
statusTip?: string
|
||||
tipWarn?: boolean
|
||||
/** 产品标题规则(有值时展示标题输入) */
|
||||
titleSpec?: ProductTitleSpec | null
|
||||
productTitle?: string
|
||||
/** 标题未填时高亮错误 */
|
||||
titleInvalid?: boolean
|
||||
}>(),
|
||||
{
|
||||
modelValue: '',
|
||||
placeholder: '',
|
||||
placeholderNeedPhoto: '请先点击左侧按钮上传照片',
|
||||
placeholderEditing: '说说想怎么改…',
|
||||
placeholderCartoon: '已识别为效果图,可直接发送',
|
||||
previewUrl: '',
|
||||
tags: () => [],
|
||||
editing: false,
|
||||
@@ -97,17 +145,27 @@ const props = withDefaults(
|
||||
disabled: false,
|
||||
canSend: false,
|
||||
inspecting: false,
|
||||
cartoonEffect: false,
|
||||
statusTip: '',
|
||||
tipWarn: false,
|
||||
titleSpec: null,
|
||||
productTitle: '',
|
||||
titleInvalid: false,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void
|
||||
(e: 'update:productTitle', value: string): void
|
||||
(e: 'upload'): void
|
||||
(e: 'clear-preview'): void
|
||||
(e: 'send'): void
|
||||
(e: 'exit-edit'): void
|
||||
}>()
|
||||
|
||||
const titleInputId = 'jd-composer-product-title'
|
||||
const productTitleLength = computed(() => String(props.productTitle || '').length)
|
||||
|
||||
const iconMap = {
|
||||
user: User,
|
||||
star: Star,
|
||||
@@ -124,13 +182,40 @@ const tagItems = computed(() =>
|
||||
})),
|
||||
)
|
||||
|
||||
const resolvedPlaceholder = computed(() => {
|
||||
if (props.editing) return props.placeholderEditing || props.placeholder
|
||||
if (!props.previewUrl) return props.placeholderNeedPhoto || props.placeholder
|
||||
if (props.cartoonEffect) return props.placeholderCartoon || props.placeholder
|
||||
return props.placeholder
|
||||
})
|
||||
|
||||
const textareaRef = ref<HTMLTextAreaElement | null>(null)
|
||||
const boxRef = ref<HTMLElement | null>(null)
|
||||
const previewRef = ref<HTMLElement | null>(null)
|
||||
|
||||
function autosize() {
|
||||
const el = textareaRef.value
|
||||
if (!el) return
|
||||
el.style.height = 'auto'
|
||||
el.style.height = `${Math.min(el.scrollHeight, 96)}px`
|
||||
}
|
||||
|
||||
function onInput(e: Event) {
|
||||
const target = e.target as HTMLTextAreaElement
|
||||
emit('update:modelValue', target.value)
|
||||
autosize()
|
||||
}
|
||||
|
||||
function onTitleInput(e: Event) {
|
||||
const target = e.target as HTMLInputElement
|
||||
emit('update:productTitle', target.value)
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.key !== 'Enter' || e.shiftKey) return
|
||||
// 移动端/桌面:Enter 发送,Shift+Enter 换行
|
||||
e.preventDefault()
|
||||
if (!props.disabled && props.canSend) emit('send')
|
||||
}
|
||||
|
||||
function focus() {
|
||||
@@ -155,6 +240,18 @@ defineExpose({ focus, getPreviewEl, getFlyTargetEl })
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.composer__tip {
|
||||
margin: 0 2px 8px;
|
||||
padding: 0 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
color: #888;
|
||||
|
||||
&.is-warn {
|
||||
color: #c45c26;
|
||||
}
|
||||
}
|
||||
|
||||
.composer__edit-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -194,6 +291,16 @@ defineExpose({ focus, getPreviewEl, getFlyTargetEl })
|
||||
background: #ffffff;
|
||||
border: 1px solid #ebebeb;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
|
||||
&.is-editing {
|
||||
border-color: rgba(58, 142, 77, 0.45);
|
||||
box-shadow: 0 4px 16px rgba(58, 142, 77, 0.08);
|
||||
}
|
||||
|
||||
&.is-disabled {
|
||||
opacity: 0.92;
|
||||
}
|
||||
}
|
||||
|
||||
.composer__preview {
|
||||
@@ -213,12 +320,24 @@ defineExpose({ focus, getPreviewEl, getFlyTargetEl })
|
||||
}
|
||||
}
|
||||
|
||||
.composer__preview-mask {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.composer__preview-close {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 2px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
@@ -229,6 +348,73 @@ defineExpose({ focus, getPreviewEl, getFlyTargetEl })
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.composer__title {
|
||||
margin: 0 0 10px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 12px;
|
||||
background: #f7f8f7;
|
||||
border: 1px solid transparent;
|
||||
|
||||
&.is-invalid {
|
||||
border-color: rgba(196, 92, 38, 0.45);
|
||||
background: #fff8f4;
|
||||
}
|
||||
}
|
||||
|
||||
.composer__title-label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #3a8e4d;
|
||||
}
|
||||
|
||||
.composer__title-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.composer__title-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 32px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid #e6e6e6;
|
||||
border-radius: 8px;
|
||||
outline: none;
|
||||
background: #fff;
|
||||
font-size: 13px;
|
||||
color: #1a1a1a;
|
||||
font-family: inherit;
|
||||
|
||||
&::placeholder {
|
||||
color: #b0b0b0;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
border-color: rgba(58, 142, 77, 0.55);
|
||||
}
|
||||
}
|
||||
|
||||
.composer__title-count {
|
||||
flex-shrink: 0;
|
||||
font-size: 11px;
|
||||
color: #999;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.composer__title-error {
|
||||
margin: 6px 0 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.3;
|
||||
color: #c45c26;
|
||||
}
|
||||
|
||||
.composer__input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
Reference in new issue
Block a user