import {url} from '../request' Page({ data: { myyuyue:[], yuyue:[ { name:'佳佳温馨提示:', neirong:'您预约的小德美甲店铺-纯色半贴甲片款式订单…', time:'13:00-14:00', meijiashi:'梨儿', data:'2024/06/18', status:'正在进行中...' }, { name:'佳佳温馨提示:', neirong:'您预约的小德美甲店铺-纯色半贴甲片款式订单…', time:'13:00-14:00', meijiashi:'梨儿', data:'2024/06/18', status:'正在进行中...' }, { name:'佳佳温馨提示:', neirong:'您预约的小德美甲店铺-纯色半贴甲片款式订单…', time:'13:00-14:00', meijiashi:'梨儿', data:'2024/06/18', status:'正在进行中...' }, { name:'佳佳温馨提示:', neirong:'您预约的小德美甲店铺-纯色半贴甲片款式订单…', time:'13:00-14:00', meijiashi:'梨儿', data:'2024/06/18', status:'正在进行中...' }, { name:'佳佳温馨提示:', neirong:'您预约的小德美甲店铺-纯色半贴甲片款式订单…', time:'13:00-14:00', meijiashi:'梨儿', data:'2024/06/18', status:'正在进行中...' } ] }, onShow() { my.getStorage({ key: 'userInfo', success: (res) => { const userInfo = res.data; if (userInfo && userInfo.cookie) { my.request({ url: url + '/api/appointments/query', method: 'POST', data: { id: userInfo.id }, headers: { 'content-type': 'application/json', 'Cookie': userInfo.cookie, }, dataType: 'json', success: (res) => { console.log(res); // 在这里处理后端返回的时间字段 const appointments = res.data.data.map(item => { const appointmentTime = new Date(item.appointmentTime); // 将时间字符串转换为 Date 对象 // 格式化日期为 'YYYY-MM-DD HH:mm' 形式 const formattedDate = appointmentTime.getFullYear() + '-' + ('0' + (appointmentTime.getMonth() + 1)).slice(-2) + '-' + ('0' + appointmentTime.getDate()).slice(-2) + ' ' + ('0' + appointmentTime.getHours()).slice(-2) + ':' + ('0' + appointmentTime.getMinutes()).slice(-2); // 返回新的数组,带有格式化后的日期 return { ...item, formattedAppointmentTime: formattedDate }; }); this.setData({ myyuyue: appointments }); console.log(this.data.myyuyue); }, fail: (error) => { console.error('请求失败: ', JSON.stringify(error)); my.alert({ content: '请求失败,请稍后重试' }); }, }); } else { my.alert({ content: '您未登录,请先登录' }); my.navigateTo({ url: '/pages/denglu/denglu' }); } }, }); }, });