统一项目命名并接回MinIO三副本存储
This commit is contained in:
@@ -1,12 +1,31 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const productsApi = require('../../api/products')
|
||||
const mock = require('../../utils/mock')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
function buildClientRequestId(prefix) {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
||||
}
|
||||
|
||||
function getCalendarArtists(calendar) {
|
||||
return calendar && Array.isArray(calendar.artists) ? calendar.artists : []
|
||||
}
|
||||
|
||||
function findArtist(artists, artistId) {
|
||||
return artists.find(item => String(item.id) === String(artistId)) || {}
|
||||
}
|
||||
|
||||
function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
|
||||
if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) {
|
||||
return false
|
||||
}
|
||||
if (schedule.status !== 1 || Number(schedule.capacity || 0) < 1) {
|
||||
return false
|
||||
}
|
||||
const scheduleStartMinute = dateUtil.minutesOfDay(String(schedule.startTime || '').slice(0, 5))
|
||||
const scheduleEndMinute = dateUtil.minutesOfDay(String(schedule.endTime || '').slice(0, 5))
|
||||
return scheduleStartMinute <= startMinute && scheduleEndMinute >= endMinute
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
@@ -20,7 +39,7 @@ Page({
|
||||
remark: ''
|
||||
},
|
||||
products: [],
|
||||
artists: mock.artists,
|
||||
artists: [],
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
conflictTip: '',
|
||||
@@ -49,21 +68,29 @@ Page({
|
||||
} catch (error) {
|
||||
this.setData({ products: fallbackProducts })
|
||||
}
|
||||
if (this.data.form.artistId) {
|
||||
const selectedArtist = this.data.artists.find(item => String(item.id) === String(this.data.form.artistId)) || {}
|
||||
this.setData({ selectedArtist })
|
||||
}
|
||||
await this.loadArtists()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
async loadArtists() {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: this.data.form.appointmentDate,
|
||||
endDate: this.data.form.appointmentDate
|
||||
})
|
||||
const artists = getCalendarArtists(calendar)
|
||||
const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {}
|
||||
this.setData({ artists, selectedArtist })
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
this.setData({
|
||||
[`form.${event.currentTarget.dataset.field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
onDateChange(event) {
|
||||
async onDateChange(event) {
|
||||
this.setData({ 'form.appointmentDate': event.detail.value })
|
||||
await this.loadArtists()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
@@ -106,15 +133,16 @@ Page({
|
||||
return { ok: false, tip }
|
||||
}
|
||||
try {
|
||||
let calendar
|
||||
try {
|
||||
calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
} catch (error) {
|
||||
calendar = mock.buildCalendar(form.appointmentDate)
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
const schedule = (calendar.schedules || []).find(item => isScheduleCoveringTime(item, form, startMinute, endMinute))
|
||||
if (!schedule) {
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} 当前时段无可预约排班`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
const conflicts = (calendar.appointments || []).filter(item => {
|
||||
if (String(item.artistId) !== String(form.artistId) || item.date !== form.appointmentDate) return false
|
||||
@@ -156,8 +184,8 @@ Page({
|
||||
try {
|
||||
const result = await planningApi.createAppointment({
|
||||
...form,
|
||||
productId: Number(form.productId),
|
||||
artistId: Number(form.artistId),
|
||||
productId: String(form.productId),
|
||||
artistId: String(form.artistId),
|
||||
durationMinutes: Number(form.durationMinutes || 0) || undefined,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
})
|
||||
|
||||
@@ -1,12 +1,39 @@
|
||||
const authApi = require('../../api/auth')
|
||||
|
||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
||||
|
||||
function buildSession(data) {
|
||||
return {
|
||||
...data,
|
||||
accessToken: data.accessToken || data.token,
|
||||
userInfo: data.userInfo || data.user || {},
|
||||
shopName: data.shopName || (data.shop && data.shop.shopName)
|
||||
}
|
||||
}
|
||||
|
||||
function getSelectableShopIds(session) {
|
||||
const userInfo = session.userInfo || {}
|
||||
if (Array.isArray(userInfo.shopIds)) {
|
||||
return userInfo.shopIds
|
||||
}
|
||||
return Array.isArray(session.shopIds) ? session.shopIds : []
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loginMode: 'phone',
|
||||
form: {
|
||||
account: '',
|
||||
password: ''
|
||||
password: '',
|
||||
phone: '',
|
||||
code: ''
|
||||
},
|
||||
loading: false
|
||||
loading: false,
|
||||
codeLoading: false,
|
||||
countdown: 0,
|
||||
countdownTimer: null,
|
||||
agreementAccepted: false,
|
||||
agreements: []
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
@@ -16,24 +43,146 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
switchLoginMode(event) {
|
||||
const loginMode = event.currentTarget.dataset.mode
|
||||
if (loginMode === this.data.loginMode) {
|
||||
return
|
||||
}
|
||||
this.setData({ loginMode })
|
||||
},
|
||||
|
||||
async sendLoginCode() {
|
||||
const phone = String(this.data.form.phone || '').trim()
|
||||
if (!PHONE_REGEX.test(phone)) {
|
||||
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (this.data.codeLoading || this.data.countdown > 0) {
|
||||
return
|
||||
}
|
||||
this.setData({ codeLoading: true })
|
||||
try {
|
||||
await authApi.sendLoginCode(phone)
|
||||
wx.showToast({ title: '验证码已发送' })
|
||||
this.startCountdown()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ codeLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
async loadAgreements() {
|
||||
if (this.data.agreements.length) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const agreements = await authApi.getCurrentAgreements()
|
||||
this.setData({ agreements: Array.isArray(agreements) ? agreements : [] })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '协议加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
toggleAgreement() {
|
||||
this.setData({
|
||||
agreementAccepted: !this.data.agreementAccepted
|
||||
})
|
||||
},
|
||||
|
||||
buildAgreementPayload() {
|
||||
const agreementVersions = {}
|
||||
;(this.data.agreements || []).forEach(item => {
|
||||
if (item && item.agreementType && item.version) {
|
||||
agreementVersions[item.agreementType] = item.version
|
||||
}
|
||||
})
|
||||
return {
|
||||
agreementAccepted: !!this.data.agreementAccepted,
|
||||
agreementVersions,
|
||||
clientType: 'WECHAT_MINI'
|
||||
}
|
||||
},
|
||||
|
||||
ensureAgreementAccepted() {
|
||||
if (!this.data.agreementAccepted) {
|
||||
wx.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
const versions = this.buildAgreementPayload().agreementVersions
|
||||
if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
|
||||
wx.showToast({ title: '协议版本加载中,请稍后再试', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
async resolveLoginSession(data) {
|
||||
const session = buildSession(data)
|
||||
const userInfo = session.userInfo || {}
|
||||
const shopIds = getSelectableShopIds(session)
|
||||
if (userInfo.shopId || shopIds.length !== 1) {
|
||||
return session
|
||||
}
|
||||
const app = getApp()
|
||||
app.setSession(session)
|
||||
return buildSession(await authApi.switchShop(shopIds[0]))
|
||||
},
|
||||
|
||||
startCountdown() {
|
||||
if (this.data.countdownTimer) {
|
||||
clearInterval(this.data.countdownTimer)
|
||||
}
|
||||
this.setData({ countdown: 60 })
|
||||
const timer = setInterval(() => {
|
||||
const next = this.data.countdown - 1
|
||||
if (next <= 0) {
|
||||
clearInterval(timer)
|
||||
this.setData({ countdown: 0, countdownTimer: null })
|
||||
return
|
||||
}
|
||||
this.setData({ countdown: next })
|
||||
}, 1000)
|
||||
this.setData({ countdownTimer: timer })
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (this.data.countdownTimer) {
|
||||
clearInterval(this.data.countdownTimer)
|
||||
}
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (!this.data.form.account || !this.data.form.password) {
|
||||
const form = this.data.form
|
||||
if (this.data.loginMode === 'password' && (!form.account || !form.password)) {
|
||||
wx.showToast({ title: '请填写手机号和密码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (this.data.loginMode === 'phone' && (!PHONE_REGEX.test(String(form.phone || '').trim()) || !String(form.code || '').trim())) {
|
||||
wx.showToast({ title: '请输入正确手机号和验证码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (this.data.loginMode === 'phone') {
|
||||
await this.loadAgreements()
|
||||
}
|
||||
if (this.data.loginMode === 'phone' && !this.ensureAgreementAccepted()) {
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const data = await authApi.login({
|
||||
account: this.data.form.account,
|
||||
password: this.data.form.password
|
||||
})
|
||||
const data = this.data.loginMode === 'phone'
|
||||
? await authApi.phoneLogin({
|
||||
phone: String(form.phone || '').trim(),
|
||||
verificationCode: String(form.code || '').trim(),
|
||||
...this.buildAgreementPayload()
|
||||
})
|
||||
: await authApi.login({
|
||||
account: form.account,
|
||||
password: form.password
|
||||
})
|
||||
const app = getApp()
|
||||
app.setSession({
|
||||
...data,
|
||||
accessToken: data.accessToken || data.token,
|
||||
userInfo: data.userInfo || data.user || {},
|
||||
shopName: data.shopName || (data.shop && data.shop.shopName)
|
||||
})
|
||||
const session = await this.resolveLoginSession(data)
|
||||
app.setSession(session)
|
||||
wx.reLaunch({ url: '/pages/planning/index' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '登录失败', icon: 'none' })
|
||||
|
||||
@@ -6,14 +6,36 @@
|
||||
</view>
|
||||
|
||||
<view class="card auth-card">
|
||||
<view class="field">
|
||||
<view class="mode-tabs">
|
||||
<view class="mode-tab {{loginMode === 'password' ? 'active' : ''}}" data-mode="password" bindtap="switchLoginMode">密码登录</view>
|
||||
<view class="mode-tab {{loginMode === 'phone' ? 'active' : ''}}" data-mode="phone" bindtap="switchLoginMode">验证码登录</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loginMode === 'password'}}" class="field">
|
||||
<text class="field-label">手机号</text>
|
||||
<input value="{{form.account}}" data-field="account" bindinput="onInput" placeholder="请输入手机号或账号" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<view wx:if="{{loginMode === 'password'}}" class="field">
|
||||
<text class="field-label">密码</text>
|
||||
<input value="{{form.password}}" data-field="password" bindinput="onInput" password placeholder="请输入密码" />
|
||||
</view>
|
||||
<view wx:if="{{loginMode === 'phone'}}" class="field">
|
||||
<text class="field-label">手机号</text>
|
||||
<input value="{{form.phone}}" data-field="phone" bindinput="onInput" type="number" placeholder="请输入手机号" />
|
||||
</view>
|
||||
<view wx:if="{{loginMode === 'phone'}}" class="field">
|
||||
<text class="field-label">验证码</text>
|
||||
<view class="code-row">
|
||||
<input class="code-input" value="{{form.code}}" data-field="code" bindinput="onInput" type="number" placeholder="请输入验证码" />
|
||||
<button class="code-btn" loading="{{codeLoading}}" disabled="{{codeLoading || countdown > 0}}" bindtap="sendLoginCode">
|
||||
{{countdown > 0 ? countdown + 's' : '获取验证码'}}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{loginMode === 'phone'}}" class="agreement-row" bindtap="toggleAgreement">
|
||||
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
|
||||
<view class="agreement-copy">我已阅读并同意用户协议和隐私政策</view>
|
||||
</view>
|
||||
<button class="primary-btn login-btn" loading="{{loading}}" bindtap="submit">登录</button>
|
||||
<view class="auth-links">
|
||||
<button class="text-btn">忘记密码</button>
|
||||
|
||||
@@ -43,6 +43,89 @@
|
||||
padding: 12rpx 24rpx 26rpx;
|
||||
}
|
||||
|
||||
.mode-tabs {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12rpx;
|
||||
margin: 12rpx 0 10rpx;
|
||||
padding: 8rpx;
|
||||
border-radius: 12px;
|
||||
background: #f3eee7;
|
||||
}
|
||||
|
||||
.mode-tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 64rpx;
|
||||
border-radius: 10px;
|
||||
color: #766f66;
|
||||
font-size: 24rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.mode-tab.active {
|
||||
background: #fffdf8;
|
||||
color: #55786d;
|
||||
box-shadow: 0 8rpx 18rpx rgba(58, 48, 34, 0.08);
|
||||
}
|
||||
|
||||
.code-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.code-btn {
|
||||
width: 160rpx;
|
||||
min-width: 160rpx;
|
||||
max-width: 160rpx;
|
||||
height: 56rpx;
|
||||
padding: 0;
|
||||
color: #6f8f83;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.agreement-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
margin-top: 22rpx;
|
||||
color: #736c63;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.agreement-check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34rpx;
|
||||
min-width: 34rpx;
|
||||
height: 34rpx;
|
||||
border: 1rpx solid #bfb7ad;
|
||||
border-radius: 8rpx;
|
||||
color: #fffdf8;
|
||||
font-size: 22rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.agreement-check.checked {
|
||||
border-color: #6f8f83;
|
||||
background: #6f8f83;
|
||||
}
|
||||
|
||||
.agreement-copy {
|
||||
flex: 1;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
margin-top: 28rpx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user