修复:时间输入改为选择器
This commit is contained in:
@@ -116,7 +116,29 @@
|
||||
<a-input v-model:value="formState.address" placeholder="请输入店铺地址" />
|
||||
</a-form-item>
|
||||
<a-form-item label="营业时间" name="businessHours">
|
||||
<a-input v-model:value="formState.businessHours" placeholder="例如:09:00-21:00" />
|
||||
<div class="business-hours-picker">
|
||||
<a-date-picker
|
||||
v-model:value="businessStartTime"
|
||||
picker="time"
|
||||
value-format="HH:mm"
|
||||
format="HH:mm"
|
||||
placeholder="开始时间"
|
||||
input-read-only
|
||||
style="width: calc(50% - 14px)"
|
||||
@change="handleBusinessHoursChange"
|
||||
/>
|
||||
<span class="business-hours-separator">至</span>
|
||||
<a-date-picker
|
||||
v-model:value="businessEndTime"
|
||||
picker="time"
|
||||
value-format="HH:mm"
|
||||
format="HH:mm"
|
||||
placeholder="结束时间"
|
||||
input-read-only
|
||||
style="width: calc(50% - 14px)"
|
||||
@change="handleBusinessHoursChange"
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="Banner图片">
|
||||
<div class="upload-tip">首页轮播图,建议尺寸 750x300 像素</div>
|
||||
@@ -267,6 +289,8 @@ const viewImageUrls = ref<string[]>([])
|
||||
const viewBannerUrls = ref<string[]>([])
|
||||
const previewVisible = ref(false)
|
||||
const previewImage = ref('')
|
||||
const businessStartTime = ref('')
|
||||
const businessEndTime = ref('')
|
||||
|
||||
// 查看店铺相关状态
|
||||
const viewFormState = reactive({
|
||||
@@ -300,7 +324,18 @@ const formRules: any = {
|
||||
shopName: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
|
||||
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
|
||||
businessHours: [{ required: true, message: '请输入营业时间', trigger: 'blur' }]
|
||||
businessHours: [{
|
||||
validator: async () => {
|
||||
if (!businessStartTime.value || !businessEndTime.value) {
|
||||
return Promise.reject('请选择营业开始和结束时间')
|
||||
}
|
||||
if (businessStartTime.value >= businessEndTime.value) {
|
||||
return Promise.reject('营业结束时间必须晚于开始时间')
|
||||
}
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: 'change'
|
||||
}]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
@@ -540,6 +575,24 @@ const handleRemove = (file: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const syncBusinessHoursValue = () => {
|
||||
formState.businessHours = businessStartTime.value && businessEndTime.value
|
||||
? `${businessStartTime.value}-${businessEndTime.value}`
|
||||
: ''
|
||||
}
|
||||
|
||||
const setBusinessHoursValue = (value?: string) => {
|
||||
const matched = (value || '').match(/(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/)
|
||||
businessStartTime.value = matched?.[1] || ''
|
||||
businessEndTime.value = matched?.[2] || ''
|
||||
syncBusinessHoursValue()
|
||||
}
|
||||
|
||||
const handleBusinessHoursChange = async () => {
|
||||
syncBusinessHoursValue()
|
||||
await formRef.value?.validateFields?.(['businessHours']).catch(() => undefined)
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
@@ -550,6 +603,7 @@ const showAddModal = () => {
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
setBusinessHoursValue('')
|
||||
bannerFileList.value = []
|
||||
uploadedBannerIds.value = []
|
||||
imageFileList.value = []
|
||||
@@ -568,6 +622,7 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
setBusinessHoursValue(formState.businessHours)
|
||||
|
||||
// 加载Banner图片
|
||||
const coverImageFileId = 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId
|
||||
@@ -715,6 +770,7 @@ const handleViewModalCancel = () => {
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
syncBusinessHoursValue()
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
@@ -738,6 +794,7 @@ const handleModalOk = async () => {
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
setBusinessHoursValue('')
|
||||
bannerFileList.value = []
|
||||
uploadedBannerIds.value = []
|
||||
imageFileList.value = []
|
||||
@@ -790,4 +847,16 @@ onMounted(async () => {
|
||||
font-size: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.business-hours-picker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.business-hours-separator {
|
||||
color: #666;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user