修复规划页接口失败展示假数据
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const dateUtil = require('../../utils/date')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
function canCreateAppointment() {
|
||||
const app = getApp()
|
||||
@@ -8,6 +7,18 @@ function canCreateAppointment() {
|
||||
return Number(userInfo.type) !== 3
|
||||
}
|
||||
|
||||
function buildEmptyCalendar() {
|
||||
return {
|
||||
artists: [],
|
||||
appointments: [],
|
||||
daySummaries: []
|
||||
}
|
||||
}
|
||||
|
||||
function resolveCalendarErrorMessage(error) {
|
||||
return error && error.message ? error.message : '规划数据加载失败'
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
viewMode: 'month',
|
||||
@@ -47,7 +58,8 @@ Page({
|
||||
freeArtistCount: 0,
|
||||
pendingCount: 0,
|
||||
canCreateAppointment: true,
|
||||
loading: false
|
||||
loading: false,
|
||||
calendarError: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -139,8 +151,18 @@ Page({
|
||||
artistId: this.data.selectedArtistId || undefined
|
||||
})
|
||||
this.applyCalendar(data)
|
||||
this.setData({ calendarError: '' })
|
||||
} catch (error) {
|
||||
this.applyCalendar(mock.buildCalendar(this.data.currentDateText))
|
||||
this.applyCalendar(buildEmptyCalendar())
|
||||
this.setData({
|
||||
calendarError: resolveCalendarErrorMessage(error),
|
||||
selectedArtistId: '',
|
||||
selectedArtistName: '全部员工'
|
||||
})
|
||||
wx.showToast({
|
||||
title: '规划数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{calendarError}}" class="calendar-error-card">
|
||||
<view class="calendar-error-copy">
|
||||
<text class="calendar-error-title">规划数据加载失败</text>
|
||||
<text class="calendar-error-message">{{calendarError}}</text>
|
||||
</view>
|
||||
<button class="calendar-error-action" bindtap="loadCalendar">重试</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{viewMode === 'day'}}" class="section">
|
||||
<view class="day-summary">
|
||||
<view class="summary-item card">
|
||||
|
||||
@@ -24,6 +24,54 @@
|
||||
padding: 18rpx;
|
||||
}
|
||||
|
||||
.calendar-error-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
margin-top: 18rpx;
|
||||
padding: 18rpx;
|
||||
border: 1rpx solid #f1d4c4;
|
||||
border-radius: 8px;
|
||||
background: #fff8f3;
|
||||
}
|
||||
|
||||
.calendar-error-copy {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 6rpx;
|
||||
}
|
||||
|
||||
.calendar-error-title {
|
||||
color: #9b3d22;
|
||||
font-size: 26rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.calendar-error-message {
|
||||
color: #b06a52;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.calendar-error-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 96rpx;
|
||||
min-width: 96rpx;
|
||||
height: 52rpx;
|
||||
padding: 0;
|
||||
border-radius: 999rpx;
|
||||
background: #fffdf8;
|
||||
color: #8b4b35;
|
||||
font-size: 24rpx;
|
||||
font-weight: 800;
|
||||
line-height: 52rpx;
|
||||
}
|
||||
|
||||
.date-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user