diff --git a/common/server/getReservationList.json b/common/server/getReservationList.json new file mode 100644 index 0000000..b8b0a2d --- /dev/null +++ b/common/server/getReservationList.json @@ -0,0 +1,36 @@ +{ + "participants": [ + { + "id": 7, + "reservation_id": 3, + "user_id": 3796, + "role": 1, + "join_time": "2025/09/03 04:05:40", + "status": 0, + "userName": "闪光大帕鲁", + "avatarImage": "https://admin-1308826010.cos.ap-shanghai.myqcloud.com/users20250908/20250908152502_6366.png", + "userBlackStatus": 0 + } + ], + "id": 3, + "title": "测试1", + "room_id": 3, + "room_name": "306小包间", + "start_time": "2025/09/13 21:09:43", + "end_time": "2025/09/13 21:34:43", + "duration_minutes": 25, + "player_count": 4, + "game_type": "扑克", + "game_rule": "跑得快", + "extra_info": "11", // 备注 + "is_smoking": 1, //是否禁烟:0=不禁烟,1=禁烟 + "gender_limit": 2, // 性别限制:0=不限,1=男,2=女 + "credit_limit": 0, // 最低信誉分 + "min_age": 0, //最小年龄 + "max_age": 0, //最大年龄限制,0=不限 + "deposit_fee": 0, //鸽子费(保证金) + "status": 0, //状态:0=待开始,1=进行中,2=已结束,3=取消 + "created_at": "2025/09/03 00:21:16", + "updated_at": "2025/09/03 21:10:21", + "remarks": "" // 备注 + } \ No newline at end of file diff --git a/common/server/index.js b/common/server/index.js index 23fb155..65dafd0 100644 --- a/common/server/index.js +++ b/common/server/index.js @@ -4,7 +4,8 @@ import { import { ref } from 'vue'; - +import { getReservationList } from '@/common/server/interface/sq' +import { parseTimeString, formatTime, calculateTimeRange } from '@/common/system/timeUtile' // 响应式数据定义 // 首页核心数据(banner + 通知) export const homeData = ref(null); @@ -62,5 +63,93 @@ export const preloadHomeData = async () => { // 私有工具函数 const shouldUseCache = () => { - return homeData.value && Date.now() - lastLoadTime < CACHE_TIMEOUT; -}; \ No newline at end of file + return homeData.value && Date.now() - lastLoadTime < CACHE_TIMEOUT; +}; + +/** + * 获取预约记录 + * @param {*} index + * @returns + */ +export const getReservation = async (index = 1, size = 20) => { + const res = await getReservationList(index, size); + if (res != null && res.length > 0) { + // { + // id: '', + // status: '', + // description: '', + // time: '', + // room: '', + // requirements: '', + // personCount: 4, //总人数 + // joinPerson: [{ + // id: 1, + // name: '张三', + // avatar: '', + // phone: '', + // }], //已加入人 + // } + //[{"participants":[{"id":7,"reservation_id":3,"user_id":3796,"role":1,"join_time":"2025/09/03 04:05:40", + // "status":0,"userName":"闪光大帕鲁","avatarImage":"https://admin-1308826010.cos.ap-shanghai.myqcloud.com/ + // users20250908/20250908152502_6366.png","userBlackStatus":0}], + // "id":3,"title":"测试1","room_id":3,"room_name":"306小包间", + // "start_time":"2025/09/13 21:09:43","end_time":"2025/09/13 21:34:43", + // "duration_minutes":25,"player_count":4,"game_type":"扑克","game_rule":"跑得快", + // "extra_info":"11","is_smoking":1,"gender_limit":2,"credit_limit":0.0,"min_age":0,"max_age":0,"deposit_fee":0.00,"status":0,"created_at":"2025/09/03 00:21:16","updated_at":"2025/09/03 21:10:21","remarks":""}] + console.log("记录", res); + var list = res.map(item => { + let start_time = parseTimeString(item.start_time); + let end_time = parseTimeString(item.end_time); + let timeStr = calculateTimeRange(start_time, end_time); + let time = formatTime(start_time, "HH:MM") + " ~ " + formatTime(end_time, "HH:MM") + " 共" + timeStr; + let requirementsList = [item.game_type, item.game_rule]; + if (item.is_smoking == 1) { + requirementsList.push("禁烟"); + } + if (item.gender_limit == 1) { + requirementsList.push("男性"); + } + if (item.gender_limit == 2) { + requirementsList.push("女性"); + } + if (item.credit_limit > 0) { + requirementsList.push("信誉分≧" + item.credit_limit); + } + if (item.min_age > 0) { + requirementsList.push("最小年龄≧" + item.min_age); + } + if (item.max_age > 0) { + requirementsList.push("最大年龄≦" + item.max_age); + } + if (item.deposit_fee > 0) { + requirementsList.push("鸽子费≧" + item.deposit_fee); + } + let requirements = requirementsList.join(","); + return { + id: item.id, + status: item.status, + description: item.title, + dateStr: formatTime(start_time, "yyyy-MM-dd"), + time: time, + room: item.room_name, + requirements: requirements, + extra_info: item.extra_info, + personCount: item.player_count, + joinPerson: item.participants.map(participant => { + return { + id: participant.id, + name: participant.userName, + avatar: participant.avatarImage, + userBlackStatus: participant.userBlackStatus, + joinTime: participant.join_time, + role: participant.role, + }; + }), + }; + + }); + + return list; + } + return []; +} diff --git a/common/server/interface/sq.js b/common/server/interface/sq.js new file mode 100644 index 0000000..0a12a79 --- /dev/null +++ b/common/server/interface/sq.js @@ -0,0 +1,17 @@ +import request from '@/common/system/request'; + +/** + * 获取预约记录 + * @param {number} index + * @param {number} size + * @returns + */ +export const getReservationList = async (index = 1, size = 20) => { + console.log('getReservationList', index, size); + + const res = await request.get("sq/GetReservationList", { pageIndex: index, pageSize: size }); + if (res.code == 0) { + return res.data; + } + return null; +} \ No newline at end of file diff --git a/common/system/timeUtile.js b/common/system/timeUtile.js new file mode 100644 index 0000000..a71d0a2 --- /dev/null +++ b/common/system/timeUtile.js @@ -0,0 +1,75 @@ +/** + * 将时间字符串格式化为时间对象 + * @param {string} timeStr - 时间字符串,格式:2025/09/03 04:05:40 + * @returns {Date} 时间对象 + */ +function parseTimeString(timeStr) { + // 支持多种分隔符 + const normalizedStr = timeStr.replace(/[\/\-]/g, '/'); + return new Date(normalizedStr); +} + +/** + * 将时间对象格式化为指定格式的字符串 + * @param {Date} date - 时间对象 + * @param {string} format - 格式字符串,如:yyyy-mm-dd HH:MM:ss + * @returns {string} 格式化后的时间字符串 + */ +function formatTime(date, format) { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + const seconds = String(date.getSeconds()).padStart(2, '0'); + + return format + .replace('yyyy', year) + .replace('mm', month) + .replace('dd', day) + .replace('HH', hours) + .replace('MM', minutes) + .replace('ss', seconds); +} + +/** + * 计算两个时间对象的时间差(不返回秒) + * @param {Date} time1 - 开始时间 + * @param {Date} time2 - 结束时间 + * @returns {string} 时间差描述,如:4小时 或 4小时10分钟 + */ +function calculateTimeRange(time1, time2) { + // 确保time2晚于time1,否则交换 + let startTime = time1; + let endTime = time2; + + if (time1 > time2) { + startTime = time2; + endTime = time1; + } + + const diffMs = endTime - startTime; + const diffMinutes = Math.floor(diffMs / (1000 * 60)); + const diffHours = Math.floor(diffMinutes / 60); + const remainingMinutes = diffMinutes % 60; + + let result = ''; + + if (diffHours > 0) { + result += `${diffHours}小时`; + } + + if (remainingMinutes > 0) { + if (result) result += ' '; + result += `${remainingMinutes}分钟`; + } + + // 如果时间差为0,返回0分钟 + if (!result) { + return '0分钟'; + } + + return result; +} + +export { parseTimeString, formatTime, calculateTimeRange } diff --git a/components/index/MahjongCard.vue b/components/index/MahjongCard.vue index 610a7cb..fec9612 100644 --- a/components/index/MahjongCard.vue +++ b/components/index/MahjongCard.vue @@ -1,333 +1,417 @@ \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index c1e22b0..de733a3 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -187,7 +187,8 @@ import zPaging from '@/uni_modules/z-paging/components/z-paging/z-paging.vue' import MahjongCard from '@/components/index/MahjongCard.vue' import { homeData, - preloadHomeData + preloadHomeData, + getReservation } from '@/common/server/index' import { configData, @@ -222,7 +223,7 @@ const userInfo = ref(null) // 初始化模拟数据 const initMockData = () => { mockData.value = [] - for (let i = 1; i <= 50; i++) { + for (let i = 1; i <= 20; i++) { // 随机生成不同人数的麻将局 const personCount = [2, 3, 4][Math.floor(Math.random() * 3)] const joinedCount = Math.floor(Math.random() * (personCount + 1)) @@ -233,7 +234,7 @@ const initMockData = () => { joinPerson.push({ id: j + 1, name: `玩家${j + 1}`, - avatar: '', + avatar: 'https://admin-1308826010.cos.ap-shanghai.myqcloud.com/app/static/userlogo.png', phone: `138****${String(j + 1).padStart(4, '0')}` }) } @@ -254,26 +255,15 @@ const initMockData = () => { // 分页查询方法 const queryList = (pageNo, pageSize) => { - console.log(`加载第${pageNo}页,每页${pageSize}条数据`) + console.log(`加载第${pageNo}页,每页${pageSize}条数据333`) + getReservation(pageNo, pageSize).then(res => { + if (res != null && res.length > 0) { + pagePaging.value.complete(res) + } else { + pagePaging.value.complete([]) + } + }); - // 模拟网络请求延迟 - setTimeout(() => { - const startIndex = (pageNo - 1) * pageSize - const endIndex = startIndex + pageSize - const pageData = mockData.value.slice(startIndex, endIndex) - - // 调用 z-paging 的完成方法 - pagePaging.value.complete(pageData) - - // 如果是第一页,显示加载完成提示 - // if (pageNo === 1) { - // uni.showToast({ - // title: '刷新成功', - // icon: 'success', - // duration: 1500 - // }) - // } - }, 100) // 模拟1秒网络延迟 } // 手动刷新 @@ -321,12 +311,14 @@ const handleJoin = (item) => { // 生命周期 onMounted(() => { // 初始化模拟数据 - initMockData() + }) onLoad(async () => { if (!homeData.value) preloadHomeData(); if (!configData.value) preloadConfigData(); + // initMockData(); + // initMockData(); });