Browse Source

调整数据格式,计算日期

live_lh
lenghui 7 months ago
parent
commit
59a00a994a
  1. 81
      vueHomilyLink/src/views/LiveView.vue

81
vueHomilyLink/src/views/LiveView.vue

@ -10,8 +10,8 @@
即将开播</div>
<div
v-if="live.status == 1"
style="position:absolute; z-index:2;text-align:center;top:60%;left:50%;transform:translate(-50%,-50%);color:#ffffffaf;font-size:15px;">
明天{{ live.startTime.slice(11, 16)}}开播</div>
style="position:absolute; z-index:2;text-align:center;top:60%;left:50%;transform:translate(-50%,-50%);color:#ffffffaf;font-size:15px;width: 120px;">
{{getDateDay(live.startTime)}} {{ live.startTime.slice(11, 16)}}开播</div>
</div>
<div class="card-content">
<div class="card-title">{{ live.liveName }}</div>
@ -22,7 +22,7 @@
<!-- 用户昵称与头像同行显示 -->
<div class="card-info">{{ live.user.userName }}</div>
<!-- 预约按钮,如果预约过了按钮变灰色文字变灰色按钮文字为已预约 -->
<a v-if="!isBooking(live.id)" href="#" class="card-button" @click="booking(live.id, live.user.userId)">预约</a>
<a v-if="live.reservation == 0" href="#" class="card-button" @click="booking(live.id, live.user.userId)">预约</a>
<a v-else href="#" class="card-button" style="background-color: #ccc;">已预约</a>
</div>
</div>
@ -51,8 +51,9 @@ function getLive() {
avatar: "src/assets/live.jpg"
},
liveName: "猎庄之顶级波段",
startTime: "2023-05-01 09:55",
status: 0
startTime: "2024-12-01 09:55",
reservation: 1, //01
status: 1 //01
},
{
id: 2,
@ -63,8 +64,9 @@ function getLive() {
avatar: "src/assets/live.jpg"
},
liveName: "猎庄之顶级波段",
startTime: "2023-05-01 09:55",
status: 0
startTime: "2024-12-01 09:55",
reservation: 1, //01
status: 1
},
{
id: 3,
@ -75,7 +77,8 @@ function getLive() {
avatar: "src/assets/live.jpg"
},
liveName: "猎庄之顶级波段",
startTime: "2023-05-01 09:55",
startTime: "2024-11-30 12:55",
reservation: 1, //01
status: 1
},
{
@ -87,7 +90,8 @@ function getLive() {
avatar: "src/assets/live.jpg"
},
liveName: "猎庄之顶级波段",
startTime: "2023-05-01 09:55",
startTime: "2024-12-30 12:55",
reservation: 0, //01
status: 1
},
{
@ -99,37 +103,52 @@ function getLive() {
avatar: "src/assets/live.jpg"
},
liveName: "猎庄之顶级波段",
startTime: "2023-05-01 09:55",
status: 1
startTime: "2024-12-30 12:55",
reservation: 0, //01
status: 1,
}
]
}
getLive();
//
const userInfo = ref([]);
function getUserInfo() {
userInfo.value = {
userId: 1,
userName: "冷辉老师",
avatar: "src/assets/live.jpg",
//
reservationList: [1,2,3]
//
function getDateDay(startTime) {
const now = new Date();
const start = new Date(startTime);
const oneDay = 24 * 60 * 60 * 1000; //
if (now.toDateString() == start.toDateString()) {
return "今天";
} else if (now.getTime() + oneDay >= start.getTime()) {
return "明天";
} else {
return startTime.slice(5, 10);
}
}
getUserInfo();
console.log(userInfo.value);
// //
// const userInfo = ref([]);
// function getUserInfo() {
// userInfo.value = {
// userId: 1,
// userName: "",
// avatar: "src/assets/live.jpg",
// //
// reservationList: [1,2,3]
// }
// }
// getUserInfo();
/* 判断预约状态 */
function isBooking(liveId) {
for (let i = 0; i < userInfo.value.reservationList.length; i++) {
if (userInfo.value.reservationList[i] == liveId) {
return true;
}
}
return false;
}
// console.log(userInfo.value);
// /* */
// function isBooking(liveId) {
// for (let i = 0; i < userInfo.value.reservationList.length; i++) {
// if (userInfo.value.reservationList[i] == liveId) {
// return true;
// }
// }
// return false;
// }

Loading…
Cancel
Save