重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
+29
View File
@@ -0,0 +1,29 @@
const SESSION_KEY = 'fingertip_manager_session'
function getSession() {
try {
return wx.getStorageSync(SESSION_KEY) || {}
} catch (error) {
return {}
}
}
function setSession(session) {
wx.setStorageSync(SESSION_KEY, session || {})
}
function clearSession() {
wx.removeStorageSync(SESSION_KEY)
}
function getAccessToken() {
const session = getSession()
return session.accessToken || session.token || ''
}
module.exports = {
getSession,
setSession,
clearSession,
getAccessToken
}
+7
View File
@@ -0,0 +1,7 @@
const DEFAULT_DOMAIN = 'http://127.0.0.1:63341'
module.exports = {
API_DOMAIN: DEFAULT_DOMAIN,
ADMIN_API_BASE_URL: `${DEFAULT_DOMAIN}/admin`,
REQUEST_TIMEOUT: 10000
}
+98
View File
@@ -0,0 +1,98 @@
function pad(value) {
return String(value).padStart(2, '0')
}
function toDate(value) {
if (value instanceof Date) {
return new Date(value.getTime())
}
return value ? new Date(String(value).replace(/-/g, '/')) : new Date()
}
function formatDate(value) {
const target = toDate(value)
return `${target.getFullYear()}-${pad(target.getMonth() + 1)}-${pad(target.getDate())}`
}
function formatMonth(value) {
const target = toDate(value)
return `${target.getFullYear()}年${target.getMonth() + 1}月`
}
function formatCnDate(value) {
const target = toDate(value)
return `${target.getMonth() + 1}月${target.getDate()}日`
}
function addDays(value, days) {
const target = toDate(value)
target.setDate(target.getDate() + days)
return target
}
function addMonths(value, months) {
const target = toDate(value)
target.setMonth(target.getMonth() + months)
return target
}
function startOfWeek(value) {
const target = toDate(value)
const day = target.getDay() || 7
target.setDate(target.getDate() - day + 1)
return target
}
function endOfWeek(value) {
return addDays(startOfWeek(value), 6)
}
function startOfMonth(value) {
const target = toDate(value)
return new Date(target.getFullYear(), target.getMonth(), 1)
}
function endOfMonth(value) {
const target = toDate(value)
return new Date(target.getFullYear(), target.getMonth() + 1, 0)
}
function monthGrid(value) {
const first = startOfMonth(value)
const startOffset = (first.getDay() || 7) - 1
const gridStart = addDays(first, -startOffset)
const days = []
for (let i = 0; i < 42; i += 1) {
const current = addDays(gridStart, i)
days.push({
date: formatDate(current),
day: current.getDate(),
isCurrentMonth: current.getMonth() === first.getMonth()
})
}
return days
}
function minutesOfDay(value) {
const parts = String(value || '00:00').split(':').map(Number)
return (parts[0] || 0) * 60 + (parts[1] || 0)
}
function timeFromMinutes(minutes) {
return `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}`
}
module.exports = {
formatDate,
formatMonth,
formatCnDate,
addDays,
addMonths,
startOfWeek,
endOfWeek,
startOfMonth,
endOfMonth,
monthGrid,
minutesOfDay,
timeFromMinutes
}
+87
View File
@@ -0,0 +1,87 @@
const date = require('./date')
const artists = [
{ id: 101, name: '小王', shortName: '王', color: '#7BA7C7', status: 1, statusText: '可预约', rangeCount: 0 },
{ id: 102, name: '小李', shortName: '李', color: '#8FB89A', status: 1, statusText: '可预约', rangeCount: 0 },
{ id: 103, name: '小张', shortName: '张', color: '#A894C7', status: 1, statusText: '可预约', rangeCount: 0 }
]
function countFor(day, index) {
const seed = day.getDate() + index * 2 + day.getMonth()
if (seed % 7 === 0) return 0
return (seed % 4) + 1
}
function buildCalendar(currentDate) {
const start = date.startOfMonth(currentDate)
const end = date.endOfMonth(currentDate)
const daySummaries = []
const appointments = []
let cursor = new Date(start.getTime())
let orderItemId = 1
while (cursor <= end) {
const dateText = date.formatDate(cursor)
const artistCounts = artists.map((artist, index) => {
const count = countFor(cursor, index)
return {
artistId: artist.id,
artistName: artist.name,
shortName: artist.shortName,
color: artist.color,
count,
status: count >= 4 ? 'full' : count > 0 ? 'working' : 'free'
}
})
const totalCount = artistCounts.reduce((sum, item) => sum + item.count, 0)
daySummaries.push({
date: dateText,
totalCount,
artistCounts,
dayStatus: totalCount >= 8 ? 'full' : totalCount > 0 ? 'working' : 'free'
})
artistCounts.forEach((count, artistIndex) => {
for (let i = 0; i < Math.min(count.count, 3); i += 1) {
const startMinute = 10 * 60 + ((artistIndex * 90 + i * 110 + cursor.getDate() * 5) % 620)
const duration = i % 2 === 0 ? 90 : 60
const artist = artists[artistIndex]
appointments.push({
orderId: 9000 + orderItemId,
orderItemId,
customerName: ['王女士', '陈女士', '林女士', '赵女士'][i % 4],
customerPhone: '138****' + String(1000 + orderItemId).slice(-4),
productTitle: ['纯色美甲', '猫眼延长', '手部护理', '法式款'][i % 4],
artistId: artist.id,
artistName: artist.name,
artistColor: artist.color,
date: dateText,
startTime: `${dateText} ${date.timeFromMinutes(startMinute)}:00`,
endTime: `${dateText} ${date.timeFromMinutes(startMinute + duration)}:00`,
startMinute,
durationMinutes: duration,
status: i === 2 ? 0 : 1,
statusText: i === 2 ? '待确认' : '已确认',
remark: ''
})
orderItemId += 1
}
})
cursor = date.addDays(cursor, 1)
}
artists.forEach(artist => {
artist.rangeCount = appointments.filter(item => item.artistId === artist.id).length
})
return {
businessStartTime: '10:00',
businessEndTime: '22:00',
slotMinutes: 30,
artists,
schedules: [],
appointments,
daySummaries
}
}
module.exports = {
artists,
buildCalendar
}
+66
View File
@@ -0,0 +1,66 @@
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT } = require('./config')
const auth = require('./auth')
function buildUrl(url, params) {
const query = Object.keys(params || {})
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.join('&')
const baseUrl = params && params.__baseUrl ? params.__baseUrl : ADMIN_API_BASE_URL
if (params && params.__baseUrl) {
delete params.__baseUrl
}
const target = `${baseUrl}${url}`
return query ? `${target}${target.includes('?') ? '&' : '?'}${query}` : target
}
function normalizeError(message, raw) {
const error = new Error(message || '请求失败')
error.raw = raw
return error
}
function request(options) {
const method = String(options.method || 'GET').toUpperCase()
const token = auth.getAccessToken()
return new Promise((resolve, reject) => {
wx.request({
url: buildUrl(options.url, options.params),
method,
timeout: options.timeout || REQUEST_TIMEOUT,
data: method === 'GET' ? undefined : options.data,
header: {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {}),
...(options.header || {})
},
success(response) {
if (response.statusCode === 401) {
auth.clearSession()
wx.reLaunch({ url: '/pages/login/index' })
reject(normalizeError('登录已失效,请重新登录', response))
return
}
if (response.statusCode >= 400) {
reject(normalizeError((response.data && response.data.message) || '网络请求失败', response))
return
}
const payload = response.data
if (payload && typeof payload === 'object' && Object.prototype.hasOwnProperty.call(payload, 'code')) {
if (payload.code === 200) {
resolve(payload.data)
return
}
reject(normalizeError(payload.message || '请求失败', payload))
return
}
resolve(payload)
},
fail(error) {
reject(normalizeError(error.errMsg || '网络异常', error))
}
})
})
}
module.exports = request