优化新增作品表单布局
This commit is contained in:
@@ -93,7 +93,7 @@
|
||||
</div>
|
||||
<div class="product-card__body">
|
||||
<strong>{{ product.title }}</strong>
|
||||
<p v-if="product.description">{{ product.description }}</p>
|
||||
<p v-if="product.descriptionText">{{ product.descriptionText }}</p>
|
||||
<div v-if="product.tagList.length > 0" class="tag-row">
|
||||
<i v-for="tag in product.tagList" :key="tag">{{ tag }}</i>
|
||||
</div>
|
||||
@@ -117,63 +117,104 @@
|
||||
@update:model-value="updateProductCreateModalVisible"
|
||||
>
|
||||
<div class="product-create-form">
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row">
|
||||
<label class="required">作品名称</label>
|
||||
<input v-model.trim="productCreateForm.title" class="search-input" placeholder="请输入作品名称" />
|
||||
<div class="product-create-control">
|
||||
<input v-model.trim="productCreateForm.title" class="search-input" placeholder="请输入作品名称" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row">
|
||||
<label class="required">价格</label>
|
||||
<input v-model.trim="productCreateForm.price" class="search-input" inputmode="decimal" placeholder="请输入价格" />
|
||||
<div class="product-create-control">
|
||||
<input v-model.trim="productCreateForm.price" class="search-input" inputmode="decimal" placeholder="请输入价格" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row">
|
||||
<label class="required">时长</label>
|
||||
<input v-model.trim="productCreateForm.durationMinutes" class="search-input" inputmode="numeric" placeholder="请输入分钟数" />
|
||||
<div class="product-create-control">
|
||||
<input v-model.trim="productCreateForm.durationMinutes" class="search-input" inputmode="numeric" placeholder="请输入分钟数" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row product-create-row--top">
|
||||
<label>作品说明</label>
|
||||
<textarea v-model.trim="productCreateForm.description" class="search-input textarea" placeholder="请输入作品说明"></textarea>
|
||||
<div class="product-create-control">
|
||||
<div class="rich-editor">
|
||||
<div class="rich-editor__toolbar" aria-label="作品说明格式">
|
||||
<button class="rich-tool rich-tool--bold" type="button" aria-label="加粗" @mousedown.prevent @click="runDescriptionCommand('bold')">B</button>
|
||||
<button class="rich-tool rich-tool--italic" type="button" aria-label="斜体" @mousedown.prevent @click="runDescriptionCommand('italic')">I</button>
|
||||
<button class="rich-tool rich-tool--underline" type="button" aria-label="下划线" @mousedown.prevent @click="runDescriptionCommand('underline')">U</button>
|
||||
<button class="rich-tool" type="button" aria-label="列表" @mousedown.prevent @click="runDescriptionCommand('insertUnorderedList')">•</button>
|
||||
</div>
|
||||
<div
|
||||
ref="descriptionEditor"
|
||||
class="rich-editor__content"
|
||||
contenteditable="true"
|
||||
role="textbox"
|
||||
aria-label="作品说明"
|
||||
data-placeholder="请输入作品说明"
|
||||
@input="syncDescriptionFromEditor"
|
||||
@blur="syncDescriptionFromEditor"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row product-create-row--top">
|
||||
<label>适合人群</label>
|
||||
<textarea v-model.trim="productCreateForm.targetAudience" class="search-input textarea" placeholder="请输入适合人群"></textarea>
|
||||
<div class="product-create-control">
|
||||
<textarea v-model.trim="productCreateForm.targetAudience" class="search-input textarea" placeholder="请输入适合人群"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row product-create-row--top">
|
||||
<label>注意事项</label>
|
||||
<textarea v-model.trim="productCreateForm.precautions" class="search-input textarea" placeholder="请输入注意事项"></textarea>
|
||||
<div class="product-create-control">
|
||||
<textarea v-model.trim="productCreateForm.precautions" class="search-input textarea" placeholder="请输入注意事项"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row product-create-row--top">
|
||||
<label>作品首图</label>
|
||||
<div class="manual-image-row">
|
||||
<img v-if="productCreateForm.imageUrl" :src="productCreateForm.imageUrl" alt="" />
|
||||
<div v-else class="manual-image-placeholder">图</div>
|
||||
<label class="secondary-btn image-upload">
|
||||
{{ productImageUploading ? '上传中...' : '上传图片' }}
|
||||
<input type="file" accept="image/*" :disabled="productImageUploading" @change="uploadProductCreateImage" />
|
||||
</label>
|
||||
<button v-if="productCreateForm.imageUrl" class="text-btn" type="button" @click="removeProductCreateImage">移除</button>
|
||||
<div class="product-create-control">
|
||||
<div class="manual-image-row">
|
||||
<img v-if="productCreateForm.imageUrl" :src="productCreateForm.imageUrl" alt="" />
|
||||
<div v-else class="manual-image-placeholder">图</div>
|
||||
<div class="manual-image-actions">
|
||||
<label class="secondary-btn image-upload">
|
||||
{{ productImageUploading ? '上传中...' : '上传图片' }}
|
||||
<input type="file" accept="image/*" :disabled="productImageUploading" @change="uploadProductCreateImage" />
|
||||
</label>
|
||||
<button v-if="productCreateForm.imageUrl" class="text-btn" type="button" @click="removeProductCreateImage">移除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row product-create-row--top">
|
||||
<label>标签</label>
|
||||
<div class="choice-grid">
|
||||
<label v-for="tag in tagOptions" :key="String(tag.id)" class="choice-chip">
|
||||
<input v-model="productCreateForm.tagIds" type="checkbox" :value="String(tag.id)" />
|
||||
<span>{{ tag.displayName || tag.tagName }}</span>
|
||||
</label>
|
||||
<div class="product-create-control">
|
||||
<div v-if="tagOptions.length > 0" class="choice-grid">
|
||||
<label v-for="tag in tagOptions" :key="String(tag.id)" class="choice-chip">
|
||||
<input v-model="productCreateForm.tagIds" type="checkbox" :value="String(tag.id)" />
|
||||
<span>{{ tag.displayName || tag.tagName }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div v-else class="choice-empty">暂无同步标签</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field field--stack">
|
||||
<div class="field product-create-row product-create-row--top">
|
||||
<label>可预约员工</label>
|
||||
<div class="choice-grid">
|
||||
<label v-for="artist in artists" :key="String(resolveArtistUserId(artist))" class="choice-chip">
|
||||
<input v-model="productCreateForm.bookableArtistIds" type="checkbox" :value="String(resolveArtistUserId(artist))" />
|
||||
<span>{{ artist.name || artist.nickname }}</span>
|
||||
</label>
|
||||
<div class="product-create-control">
|
||||
<div v-if="artists.length > 0" class="choice-grid">
|
||||
<label v-for="artist in artists" :key="String(resolveArtistUserId(artist))" class="choice-chip">
|
||||
<input v-model="productCreateForm.bookableArtistIds" type="checkbox" :value="String(resolveArtistUserId(artist))" />
|
||||
<span>{{ artist.name || artist.nickname }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div v-else class="choice-empty">暂无可预约员工</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="primary-btn" type="button" :disabled="creatingProduct || productImageUploading" @click="createProduct">
|
||||
{{ creatingProduct ? '保存中...' : '保存并选择' }}
|
||||
</button>
|
||||
<div class="product-create-actions">
|
||||
<button class="primary-btn" type="button" :disabled="creatingProduct || productImageUploading" @click="createProduct">
|
||||
{{ creatingProduct ? '保存中...' : '保存并选择' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</BaseModal>
|
||||
|
||||
@@ -222,7 +263,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import DatePickerField from '@/components/DatePickerField.vue'
|
||||
@@ -256,6 +297,7 @@ import { markPlanningRefresh } from '@/utils/storage'
|
||||
|
||||
interface ProductCard extends Product {
|
||||
coverImage: string
|
||||
descriptionText: string
|
||||
priceText: string
|
||||
durationText: string
|
||||
artistText: string
|
||||
@@ -383,6 +425,7 @@ const productCreateModalVisible = ref(Boolean(createProductDraft?.open))
|
||||
const artists = ref<Artist[]>([])
|
||||
const tagOptions = ref<ManagerTag[]>([])
|
||||
const selectedProduct = ref<ProductCard | null>(null)
|
||||
const descriptionEditor = ref<HTMLElement | null>(null)
|
||||
const timeSheetVisible = ref(Boolean(modalStateDraft?.open && modalStateDraft.form.timeSheetVisible))
|
||||
const availableTimeGroups = ref<AvailableTimeGroup[]>([])
|
||||
const timeLoading = ref(false)
|
||||
@@ -560,6 +603,46 @@ const applyProductCreateForm = (value: ProductCreateForm): void => {
|
||||
productCreateForm.bookableArtistIds = [...value.bookableArtistIds]
|
||||
}
|
||||
|
||||
const normalizeRichText = (value: string): string => {
|
||||
const content = value.trim()
|
||||
const plainText = content
|
||||
.replace(/<[^>]*>/g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
return plainText ? content : ''
|
||||
}
|
||||
|
||||
const toPlainText = (value: string | undefined): string => {
|
||||
return normalizeRichText(value || '')
|
||||
.replace(/<[^>]*>/g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
}
|
||||
|
||||
const syncDescriptionEditor = (): void => {
|
||||
const editor = descriptionEditor.value
|
||||
if (!editor) {
|
||||
return
|
||||
}
|
||||
editor.innerHTML = productCreateForm.description
|
||||
}
|
||||
|
||||
const syncDescriptionFromEditor = (): void => {
|
||||
productCreateForm.description = normalizeRichText(descriptionEditor.value?.innerHTML || '')
|
||||
}
|
||||
|
||||
const runDescriptionCommand = (command: string): void => {
|
||||
const editor = descriptionEditor.value
|
||||
if (!editor) {
|
||||
return
|
||||
}
|
||||
editor.focus()
|
||||
document.execCommand(command)
|
||||
syncDescriptionFromEditor()
|
||||
}
|
||||
|
||||
const resetProductCreateForm = (): void => {
|
||||
applyProductCreateForm(buildEmptyProductCreateForm())
|
||||
productCreateBaseline.value = buildEmptyProductCreateForm()
|
||||
@@ -634,6 +717,7 @@ const normalizeProduct = (product: Product, artistOptions: Artist[]): ProductCar
|
||||
return {
|
||||
...product,
|
||||
coverImage: imageUrls[0] || '',
|
||||
descriptionText: toPlainText(product.description),
|
||||
tagList: parseProductTags(product).slice(0, 4),
|
||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||
durationText,
|
||||
@@ -836,6 +920,7 @@ const openCreateProductModal = (): void => {
|
||||
}
|
||||
productCreateBaseline.value = snapshotProductCreateForm()
|
||||
productCreateModalVisible.value = true
|
||||
void nextTick(syncDescriptionEditor)
|
||||
syncProductCreateDraft()
|
||||
}
|
||||
|
||||
@@ -872,7 +957,7 @@ const buildProductCreatePayload = (): ProductCreateRequest | null => {
|
||||
return {
|
||||
title,
|
||||
price,
|
||||
description: productCreateForm.description.trim() || undefined,
|
||||
description: normalizeRichText(productCreateForm.description) || undefined,
|
||||
targetAudience: productCreateForm.targetAudience.trim() || undefined,
|
||||
precautions: productCreateForm.precautions.trim() || undefined,
|
||||
imageFileIds: productCreateForm.imageFileIds || undefined,
|
||||
@@ -1068,7 +1153,16 @@ watch(timeSheetVisible, syncAppointmentModalState)
|
||||
watch(createCustomerForm, syncCreateCustomerDraft, { deep: true })
|
||||
watch(createCustomerModalVisible, syncCreateCustomerDraft)
|
||||
watch(productCreateForm, syncProductCreateDraft, { deep: true })
|
||||
watch(productCreateModalVisible, syncProductCreateDraft)
|
||||
watch(productCreateModalVisible, value => {
|
||||
syncProductCreateDraft()
|
||||
if (value) {
|
||||
void nextTick(syncDescriptionEditor)
|
||||
}
|
||||
})
|
||||
|
||||
if (productCreateModalVisible.value) {
|
||||
void nextTick(syncDescriptionEditor)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -1331,6 +1425,43 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.product-create-form {
|
||||
gap: 0;
|
||||
padding: 4px 14px 14px;
|
||||
}
|
||||
|
||||
.product-create-row {
|
||||
align-items: flex-start;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.product-create-row > label {
|
||||
padding-top: 11px;
|
||||
}
|
||||
|
||||
.product-create-control {
|
||||
display: grid;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.product-create-control .search-input {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.product-create-control .textarea {
|
||||
min-height: 92px;
|
||||
}
|
||||
|
||||
.product-create-actions {
|
||||
padding-top: 14px;
|
||||
}
|
||||
|
||||
.product-create-actions .primary-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.product-modal__actions {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
@@ -1424,17 +1555,72 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.rich-editor {
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.rich-editor__toolbar {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
padding: 8px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--subtle);
|
||||
}
|
||||
|
||||
.rich-tool {
|
||||
display: grid;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
place-items: center;
|
||||
border-radius: 8px;
|
||||
background: var(--card-bg);
|
||||
color: var(--ink);
|
||||
font-size: 13px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.rich-tool--italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.rich-tool--underline {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.rich-editor__content {
|
||||
min-height: 116px;
|
||||
padding: 10px 12px;
|
||||
outline: 0;
|
||||
color: var(--ink);
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.rich-editor__content:empty::before {
|
||||
color: var(--muted);
|
||||
content: attr(data-placeholder);
|
||||
}
|
||||
|
||||
.rich-editor__content ul,
|
||||
.rich-editor__content ol {
|
||||
margin: 6px 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.manual-image-row {
|
||||
display: grid;
|
||||
grid-template-columns: 72px 1fr auto;
|
||||
grid-template-columns: 64px minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.manual-image-row img,
|
||||
.manual-image-placeholder {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border-radius: 12px;
|
||||
object-fit: cover;
|
||||
}
|
||||
@@ -1447,6 +1633,14 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.manual-image-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.image-upload {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
@@ -1474,6 +1668,15 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.choice-empty {
|
||||
padding: 10px 12px;
|
||||
border: 1px dashed var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--subtle);
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.choice-chip {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
|
||||
Reference in New Issue
Block a user