优化首页返回定位与发布在线时间表单
移动端首页用列表缓存和内部滚动恢复浏览位置;发布页在线时间改为全天+起止时间单行布局。
This commit is contained in:
@@ -33,12 +33,7 @@ import {
|
||||
} from '@/features/seller/composables/usePublishDraft'
|
||||
import type { PublishForm } from '@/shared/types/publish'
|
||||
import { yuanToCent } from '@/shared/utils/money'
|
||||
import {
|
||||
commonOnlineTimes,
|
||||
dailyLossOptions,
|
||||
formatNumber,
|
||||
roundRatio,
|
||||
} from '@/shared/utils/pricing'
|
||||
import { dailyLossOptions, formatNumber, roundRatio } from '@/shared/utils/pricing'
|
||||
|
||||
const draftSaveDelay = 400
|
||||
const multiScreenshotLimit = 3
|
||||
@@ -104,13 +99,6 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
sellerAgreementChecked.value &&
|
||||
passwordAndDeviceConfirmed.value
|
||||
)
|
||||
const disabledOnlineStartOptions = computed(() =>
|
||||
commonOnlineTimes.filter(time => !canUseOnlineStart(time))
|
||||
)
|
||||
const disabledOnlineEndOptions = computed(() =>
|
||||
commonOnlineTimes.filter(time => !canUseOnlineEnd(time))
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
if (!isEditMode.value) restoreDraft()
|
||||
if (options.persistBeforeUnload) window.addEventListener('beforeunload', handleBeforeUnload)
|
||||
@@ -360,37 +348,11 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
return form.online_start === '00:00' && form.online_end === '23:59'
|
||||
}
|
||||
|
||||
function isOnlineStartPresetActive(value: string) {
|
||||
return !isAllDayOnline() && form.online_start === value
|
||||
}
|
||||
|
||||
function isOnlineEndPresetActive(value: string) {
|
||||
return !isAllDayOnline() && form.online_end === value
|
||||
}
|
||||
|
||||
function selectAllDayOnline() {
|
||||
form.online_start = '00:00'
|
||||
form.online_end = '23:59'
|
||||
}
|
||||
|
||||
function selectOnlineStart(value: string | number) {
|
||||
const time = String(value)
|
||||
if (!canUseOnlineStart(time)) {
|
||||
options.notifyWarning('开始时间必须早于结束时间')
|
||||
return
|
||||
}
|
||||
form.online_start = time
|
||||
}
|
||||
|
||||
function selectOnlineEnd(value: string | number) {
|
||||
const time = String(value)
|
||||
if (!canUseOnlineEnd(time)) {
|
||||
options.notifyWarning('结束时间必须晚于开始时间')
|
||||
return
|
||||
}
|
||||
form.online_end = time
|
||||
}
|
||||
|
||||
function handleOnlineStartChange(value: string | number | null | undefined) {
|
||||
const time = normalizeOnlineTimeValue(value)
|
||||
form.online_start = time
|
||||
@@ -427,22 +389,6 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
function canUseOnlineStart(value: string) {
|
||||
const start = parseOnlineTime(value)
|
||||
const lastTime = parseOnlineTime('23:59')
|
||||
if (start === null || lastTime === null || start >= lastTime) return false
|
||||
const end = parseOnlineTime(form.online_end)
|
||||
return end === null || start < end
|
||||
}
|
||||
|
||||
function canUseOnlineEnd(value: string) {
|
||||
const end = parseOnlineTime(value)
|
||||
const firstTime = parseOnlineTime('00:00')
|
||||
if (end === null || firstTime === null || end <= firstTime) return false
|
||||
const start = parseOnlineTime(form.online_start)
|
||||
return start === null || end > start
|
||||
}
|
||||
|
||||
function validateOnlineTime() {
|
||||
const start = parseOnlineTime(form.online_start)
|
||||
const end = parseOnlineTime(form.online_end)
|
||||
@@ -944,7 +890,6 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
return {
|
||||
...pricing,
|
||||
dailyLossOptions,
|
||||
commonOnlineTimes,
|
||||
formatNumber,
|
||||
router,
|
||||
loading,
|
||||
@@ -969,19 +914,13 @@ export function usePublishForm(options: UsePublishFormOptions) {
|
||||
pageTitle,
|
||||
submitButtonText,
|
||||
submitLoadingText,
|
||||
disabledOnlineStartOptions,
|
||||
disabledOnlineEndOptions,
|
||||
loadPublishOptions,
|
||||
saveDraft,
|
||||
handleSaveDraft,
|
||||
resetDraftState,
|
||||
handleResetDraft,
|
||||
isAllDayOnline,
|
||||
isOnlineStartPresetActive,
|
||||
isOnlineEndPresetActive,
|
||||
selectAllDayOnline,
|
||||
selectOnlineStart,
|
||||
selectOnlineEnd,
|
||||
handleOnlineStartChange,
|
||||
handleOnlineEndChange,
|
||||
toggleSkin,
|
||||
@@ -1025,5 +964,9 @@ function parseOnlineTime(value: string) {
|
||||
|
||||
function normalizeOnlineTimeValue(value: string | number | null | undefined) {
|
||||
if (value === null || value === undefined) return ''
|
||||
return String(value)
|
||||
const raw = String(value).trim()
|
||||
// 兼容原生 time 可能带秒:08:00:00 -> 08:00
|
||||
const match = /^(\d{1,2}):(\d{2})(?::\d{2})?/.exec(raw)
|
||||
if (!match?.[1] || !match[2]) return raw
|
||||
return `${match[1].padStart(2, '0')}:${match[2]}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user