优化新增作品表单布局
This commit is contained in:
@@ -93,7 +93,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="product-card__body">
|
<div class="product-card__body">
|
||||||
<strong>{{ product.title }}</strong>
|
<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">
|
<div v-if="product.tagList.length > 0" class="tag-row">
|
||||||
<i v-for="tag in product.tagList" :key="tag">{{ tag }}</i>
|
<i v-for="tag in product.tagList" :key="tag">{{ tag }}</i>
|
||||||
</div>
|
</div>
|
||||||
@@ -117,35 +117,66 @@
|
|||||||
@update:model-value="updateProductCreateModalVisible"
|
@update:model-value="updateProductCreateModalVisible"
|
||||||
>
|
>
|
||||||
<div class="product-create-form">
|
<div class="product-create-form">
|
||||||
<div class="field field--stack">
|
<div class="field product-create-row">
|
||||||
<label class="required">作品名称</label>
|
<label class="required">作品名称</label>
|
||||||
|
<div class="product-create-control">
|
||||||
<input v-model.trim="productCreateForm.title" class="search-input" placeholder="请输入作品名称" />
|
<input v-model.trim="productCreateForm.title" class="search-input" placeholder="请输入作品名称" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
</div>
|
||||||
|
<div class="field product-create-row">
|
||||||
<label class="required">价格</label>
|
<label class="required">价格</label>
|
||||||
|
<div class="product-create-control">
|
||||||
<input v-model.trim="productCreateForm.price" class="search-input" inputmode="decimal" placeholder="请输入价格" />
|
<input v-model.trim="productCreateForm.price" class="search-input" inputmode="decimal" placeholder="请输入价格" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
</div>
|
||||||
|
<div class="field product-create-row">
|
||||||
<label class="required">时长</label>
|
<label class="required">时长</label>
|
||||||
|
<div class="product-create-control">
|
||||||
<input v-model.trim="productCreateForm.durationMinutes" class="search-input" inputmode="numeric" placeholder="请输入分钟数" />
|
<input v-model.trim="productCreateForm.durationMinutes" class="search-input" inputmode="numeric" placeholder="请输入分钟数" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
|
||||||
<label>作品说明</label>
|
|
||||||
<textarea v-model.trim="productCreateForm.description" 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="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 product-create-row product-create-row--top">
|
||||||
<label>适合人群</label>
|
<label>适合人群</label>
|
||||||
|
<div class="product-create-control">
|
||||||
<textarea v-model.trim="productCreateForm.targetAudience" class="search-input textarea" placeholder="请输入适合人群"></textarea>
|
<textarea v-model.trim="productCreateForm.targetAudience" class="search-input textarea" placeholder="请输入适合人群"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
</div>
|
||||||
|
<div class="field product-create-row product-create-row--top">
|
||||||
<label>注意事项</label>
|
<label>注意事项</label>
|
||||||
|
<div class="product-create-control">
|
||||||
<textarea v-model.trim="productCreateForm.precautions" class="search-input textarea" placeholder="请输入注意事项"></textarea>
|
<textarea v-model.trim="productCreateForm.precautions" class="search-input textarea" placeholder="请输入注意事项"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
</div>
|
||||||
|
<div class="field product-create-row product-create-row--top">
|
||||||
<label>作品首图</label>
|
<label>作品首图</label>
|
||||||
|
<div class="product-create-control">
|
||||||
<div class="manual-image-row">
|
<div class="manual-image-row">
|
||||||
<img v-if="productCreateForm.imageUrl" :src="productCreateForm.imageUrl" alt="" />
|
<img v-if="productCreateForm.imageUrl" :src="productCreateForm.imageUrl" alt="" />
|
||||||
<div v-else class="manual-image-placeholder">图</div>
|
<div v-else class="manual-image-placeholder">图</div>
|
||||||
|
<div class="manual-image-actions">
|
||||||
<label class="secondary-btn image-upload">
|
<label class="secondary-btn image-upload">
|
||||||
{{ productImageUploading ? '上传中...' : '上传图片' }}
|
{{ productImageUploading ? '上传中...' : '上传图片' }}
|
||||||
<input type="file" accept="image/*" :disabled="productImageUploading" @change="uploadProductCreateImage" />
|
<input type="file" accept="image/*" :disabled="productImageUploading" @change="uploadProductCreateImage" />
|
||||||
@@ -153,28 +184,38 @@
|
|||||||
<button v-if="productCreateForm.imageUrl" class="text-btn" type="button" @click="removeProductCreateImage">移除</button>
|
<button v-if="productCreateForm.imageUrl" class="text-btn" type="button" @click="removeProductCreateImage">移除</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field product-create-row product-create-row--top">
|
||||||
<label>标签</label>
|
<label>标签</label>
|
||||||
<div class="choice-grid">
|
<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">
|
<label v-for="tag in tagOptions" :key="String(tag.id)" class="choice-chip">
|
||||||
<input v-model="productCreateForm.tagIds" type="checkbox" :value="String(tag.id)" />
|
<input v-model="productCreateForm.tagIds" type="checkbox" :value="String(tag.id)" />
|
||||||
<span>{{ tag.displayName || tag.tagName }}</span>
|
<span>{{ tag.displayName || tag.tagName }}</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="choice-empty">暂无同步标签</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field field--stack">
|
</div>
|
||||||
|
<div class="field product-create-row product-create-row--top">
|
||||||
<label>可预约员工</label>
|
<label>可预约员工</label>
|
||||||
<div class="choice-grid">
|
<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">
|
<label v-for="artist in artists" :key="String(resolveArtistUserId(artist))" class="choice-chip">
|
||||||
<input v-model="productCreateForm.bookableArtistIds" type="checkbox" :value="String(resolveArtistUserId(artist))" />
|
<input v-model="productCreateForm.bookableArtistIds" type="checkbox" :value="String(resolveArtistUserId(artist))" />
|
||||||
<span>{{ artist.name || artist.nickname }}</span>
|
<span>{{ artist.name || artist.nickname }}</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="choice-empty">暂无可预约员工</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="product-create-actions">
|
||||||
<button class="primary-btn" type="button" :disabled="creatingProduct || productImageUploading" @click="createProduct">
|
<button class="primary-btn" type="button" :disabled="creatingProduct || productImageUploading" @click="createProduct">
|
||||||
{{ creatingProduct ? '保存中...' : '保存并选择' }}
|
{{ creatingProduct ? '保存中...' : '保存并选择' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
|
|
||||||
<BaseModal
|
<BaseModal
|
||||||
@@ -222,7 +263,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 { useRoute, useRouter } from 'vue-router'
|
||||||
import BaseModal from '@/components/BaseModal.vue'
|
import BaseModal from '@/components/BaseModal.vue'
|
||||||
import DatePickerField from '@/components/DatePickerField.vue'
|
import DatePickerField from '@/components/DatePickerField.vue'
|
||||||
@@ -256,6 +297,7 @@ import { markPlanningRefresh } from '@/utils/storage'
|
|||||||
|
|
||||||
interface ProductCard extends Product {
|
interface ProductCard extends Product {
|
||||||
coverImage: string
|
coverImage: string
|
||||||
|
descriptionText: string
|
||||||
priceText: string
|
priceText: string
|
||||||
durationText: string
|
durationText: string
|
||||||
artistText: string
|
artistText: string
|
||||||
@@ -383,6 +425,7 @@ const productCreateModalVisible = ref(Boolean(createProductDraft?.open))
|
|||||||
const artists = ref<Artist[]>([])
|
const artists = ref<Artist[]>([])
|
||||||
const tagOptions = ref<ManagerTag[]>([])
|
const tagOptions = ref<ManagerTag[]>([])
|
||||||
const selectedProduct = ref<ProductCard | null>(null)
|
const selectedProduct = ref<ProductCard | null>(null)
|
||||||
|
const descriptionEditor = ref<HTMLElement | null>(null)
|
||||||
const timeSheetVisible = ref(Boolean(modalStateDraft?.open && modalStateDraft.form.timeSheetVisible))
|
const timeSheetVisible = ref(Boolean(modalStateDraft?.open && modalStateDraft.form.timeSheetVisible))
|
||||||
const availableTimeGroups = ref<AvailableTimeGroup[]>([])
|
const availableTimeGroups = ref<AvailableTimeGroup[]>([])
|
||||||
const timeLoading = ref(false)
|
const timeLoading = ref(false)
|
||||||
@@ -560,6 +603,46 @@ const applyProductCreateForm = (value: ProductCreateForm): void => {
|
|||||||
productCreateForm.bookableArtistIds = [...value.bookableArtistIds]
|
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 => {
|
const resetProductCreateForm = (): void => {
|
||||||
applyProductCreateForm(buildEmptyProductCreateForm())
|
applyProductCreateForm(buildEmptyProductCreateForm())
|
||||||
productCreateBaseline.value = buildEmptyProductCreateForm()
|
productCreateBaseline.value = buildEmptyProductCreateForm()
|
||||||
@@ -634,6 +717,7 @@ const normalizeProduct = (product: Product, artistOptions: Artist[]): ProductCar
|
|||||||
return {
|
return {
|
||||||
...product,
|
...product,
|
||||||
coverImage: imageUrls[0] || '',
|
coverImage: imageUrls[0] || '',
|
||||||
|
descriptionText: toPlainText(product.description),
|
||||||
tagList: parseProductTags(product).slice(0, 4),
|
tagList: parseProductTags(product).slice(0, 4),
|
||||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||||
durationText,
|
durationText,
|
||||||
@@ -836,6 +920,7 @@ const openCreateProductModal = (): void => {
|
|||||||
}
|
}
|
||||||
productCreateBaseline.value = snapshotProductCreateForm()
|
productCreateBaseline.value = snapshotProductCreateForm()
|
||||||
productCreateModalVisible.value = true
|
productCreateModalVisible.value = true
|
||||||
|
void nextTick(syncDescriptionEditor)
|
||||||
syncProductCreateDraft()
|
syncProductCreateDraft()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,7 +957,7 @@ const buildProductCreatePayload = (): ProductCreateRequest | null => {
|
|||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
price,
|
price,
|
||||||
description: productCreateForm.description.trim() || undefined,
|
description: normalizeRichText(productCreateForm.description) || undefined,
|
||||||
targetAudience: productCreateForm.targetAudience.trim() || undefined,
|
targetAudience: productCreateForm.targetAudience.trim() || undefined,
|
||||||
precautions: productCreateForm.precautions.trim() || undefined,
|
precautions: productCreateForm.precautions.trim() || undefined,
|
||||||
imageFileIds: productCreateForm.imageFileIds || undefined,
|
imageFileIds: productCreateForm.imageFileIds || undefined,
|
||||||
@@ -1068,7 +1153,16 @@ watch(timeSheetVisible, syncAppointmentModalState)
|
|||||||
watch(createCustomerForm, syncCreateCustomerDraft, { deep: true })
|
watch(createCustomerForm, syncCreateCustomerDraft, { deep: true })
|
||||||
watch(createCustomerModalVisible, syncCreateCustomerDraft)
|
watch(createCustomerModalVisible, syncCreateCustomerDraft)
|
||||||
watch(productCreateForm, syncProductCreateDraft, { deep: true })
|
watch(productCreateForm, syncProductCreateDraft, { deep: true })
|
||||||
watch(productCreateModalVisible, syncProductCreateDraft)
|
watch(productCreateModalVisible, value => {
|
||||||
|
syncProductCreateDraft()
|
||||||
|
if (value) {
|
||||||
|
void nextTick(syncDescriptionEditor)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (productCreateModalVisible.value) {
|
||||||
|
void nextTick(syncDescriptionEditor)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -1331,6 +1425,43 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
|||||||
padding: 14px;
|
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 {
|
.product-modal__actions {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
@@ -1424,17 +1555,72 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
|||||||
font-weight: 700;
|
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 {
|
.manual-image-row {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 72px 1fr auto;
|
grid-template-columns: 64px minmax(0, 1fr);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.manual-image-row img,
|
.manual-image-row img,
|
||||||
.manual-image-placeholder {
|
.manual-image-placeholder {
|
||||||
width: 72px;
|
width: 64px;
|
||||||
height: 72px;
|
height: 64px;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
@@ -1447,6 +1633,14 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
|||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.manual-image-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.image-upload {
|
.image-upload {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
@@ -1474,6 +1668,15 @@ watch(productCreateModalVisible, syncProductCreateDraft)
|
|||||||
gap: 8px;
|
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 {
|
.choice-chip {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
|||||||
Reference in New Issue
Block a user