优化:规划日期快捷新增预约

This commit is contained in:
2026-10-12 17:15:27 +08:00
parent e4aff0803a
commit 2714bd7201
4 changed files with 82 additions and 16 deletions
+22 -13
View File
@@ -51,9 +51,9 @@ Page({
data: {
viewMode: 'month',
viewModes: [
{ value: 'day', label: '日' },
{ value: 'month', label: '月' },
{ value: 'week', label: '周' },
{ value: 'month', label: '月' }
{ value: 'day', label: '日' }
],
monthDisplayMode: 'count',
monthDisplayModes: [
@@ -234,14 +234,17 @@ Page({
this.loadCalendar()
},
selectDate(event) {
const currentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
this.setData({
currentDate,
currentDateText: currentDate,
viewMode: this.data.viewMode === 'month' ? 'day' : this.data.viewMode
})
this.prepareView()
quickCreateAppointment(event) {
if (!this.data.canCreateAppointment) {
wx.showToast({ title: '当前账号仅支持查看预约', icon: 'none' })
return
}
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
if (appointmentDate < dateUtil.formatDate(new Date())) {
wx.showToast({ title: '不能为历史日期新增预约', icon: 'none' })
return
}
this.openAppointmentForm(appointmentDate)
},
prevRange() {
@@ -545,9 +548,15 @@ Page({
wx.showToast({ title: '当前账号仅支持查看预约', icon: 'none' })
return
}
wx.navigateTo({
url: `/pages/appointment-form/index?date=${this.data.currentDateText}&artistId=${this.data.selectedArtistId || ''}`
})
this.openAppointmentForm(this.data.currentDateText)
},
openAppointmentForm(appointmentDate) {
const query = [`date=${encodeURIComponent(appointmentDate)}`]
if (this.data.selectedArtistId) {
query.push(`artistId=${encodeURIComponent(this.data.selectedArtistId)}`)
}
wx.navigateTo({ url: `/pages/appointment-form/index?${query.join('&')}` })
},
openAppointment(event) {
+36 -1
View File
@@ -1,5 +1,6 @@
const assert = require('assert')
const planningApi = require('../../api/planning')
const dateUtil = require('../../utils/date')
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
@@ -9,7 +10,8 @@ global.wx = {
removeStorageSync: () => {},
showToast: () => {},
showModal: ({ success }) => success({ confirm: false }),
switchTab: () => {}
switchTab: () => {},
navigateTo: () => {}
}
const appMock = { globalData: { userInfo: {} } }
global.getApp = () => appMock
@@ -41,6 +43,9 @@ function createPage(data = {}) {
}
async function run() {
assert.deepStrictEqual(definition.data.viewModes.map(item => item.value), ['month', 'week', 'day'])
assert.strictEqual(definition.data.viewMode, 'month')
const page = createPage({ viewMode: 'week' })
let monthBuilds = 0
let weekBuilds = 0
@@ -85,6 +90,36 @@ async function run() {
assert.strictEqual(switched, true)
assert.strictEqual(appMock.globalData.reviewNoticeShown, true)
assert.strictEqual(appMock.globalData.openEmployeeReview, true)
const navigations = []
const toasts = []
global.wx.navigateTo = options => navigations.push(options.url)
global.wx.showToast = options => toasts.push(options.title)
const quickCreatePage = createPage({ canCreateAppointment: true, selectedArtistId: '88' })
const today = dateUtil.formatDate(new Date())
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: today } } })
assert.strictEqual(navigations.pop(), `/pages/appointment-form/index?date=${today}&artistId=88`)
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } })
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2099-12-31&artistId=88')
quickCreatePage.data.selectedArtistId = ''
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-11-30' } } })
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2099-11-30')
quickCreatePage.quickCreateAppointment({ currentTarget: { dataset: { date: '2000-01-01' } } })
assert.strictEqual(navigations.length, 0)
assert.strictEqual(toasts.pop(), '不能为历史日期新增预约')
const readonlyPage = createPage({ canCreateAppointment: false, selectedArtistId: '88' })
readonlyPage.quickCreateAppointment({ currentTarget: { dataset: { date: '2099-12-31' } } })
assert.strictEqual(navigations.length, 0)
assert.strictEqual(toasts.pop(), '当前账号仅支持查看预约')
const fabPage = createPage({ canCreateAppointment: true, currentDateText: '2026-10-12', selectedArtistId: '99' })
fabPage.createAppointment()
assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-10-12&artistId=99')
}
run().catch(error => {
+2 -2
View File
@@ -99,7 +99,7 @@
<view wx:if="{{viewMode === 'week'}}" class="section">
<scroll-view class="week-strip" scroll-x enable-flex>
<view wx:for="{{weekDays}}" wx:key="date" class="week-day-card card {{item.date === currentDateText ? 'active' : ''}}" data-date="{{item.date}}" bindtap="selectDate">
<view wx:for="{{weekDays}}" wx:key="date" class="week-day-card card {{item.date === currentDateText ? 'active' : ''}}" data-date="{{item.date}}" bindtap="quickCreateAppointment">
<text class="week-name">{{item.weekName}}</text>
<text class="week-date">{{item.day}}</text>
<text class="week-total">{{item.totalCount}}单</text>
@@ -140,7 +140,7 @@
<text wx:for="{{weekLabels}}" wx:key="*this">{{item}}</text>
</view>
<view class="month-grid">
<view wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.date === currentDateText ? 'selected' : ''}}" data-date="{{item.date}}" bindtap="selectDate">
<view wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.date === currentDateText ? 'selected' : ''}}" data-date="{{item.date}}" bindtap="quickCreateAppointment">
<view class="month-cell-head">
<text class="month-day">{{item.day}}</text>
<text wx:if="{{!item.isPast && item.dayStatus === 'full'}}" class="day-mark full">满</text>