Merge pull request '肖帆' (#9) from xiaofan_branch into master

pfqxe4nai 2 years ago
commit 1471a3c19e

@ -1,142 +0,0 @@
<template>
<view class="search">
<view class="search-header">
<text class="title">Mini-12306 查询车次</text>
</view>
<view class="search-form">
<view class="form-item">
<text class="label">出发地</text>
<input class="input" v-model="departure" type="text" placeholder="请输入出发地" />
</view>
<view class="form-item">
<text class="label">目的地</text>
<input class="input" v-model="destination" type="text" placeholder="请输入目的地" />
</view>
<view class="form-item">
<text class="label">出发日期</text>
<input class="input" v-model="date" type="date" />
</view>
<view class="form-item">
<button class="search-btn" @click="search"></button>
</view>
</view>
<view class="search-result">
<text v-if="searched" class="result-text"></text>
<view v-if="searched && trainList.length === 0" class="empty-result">
<text class="empty-text">暂无车次信息</text>
</view>
<view v-for="(train, index) in trainList" :key="index" class="train-item">
<text class="train-info">{{ train.trainNumber }}</text>
<text class="train-info">{{ train.departureTime }}</text>
<text class="train-info">{{ train.destinationTime }}</text>
<text class="train-info">{{ train.duration }}</text>
<text class="train-info">{{ train.price }}</text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
departure: '',
destination: '',
date: '',
searched: false,
trainList: []
};
},
methods: {
search() {
//
if (!this.departure || !this.destination || !this.date) {
uni.showToast({
title: '请输入完整信息',
icon: 'none'
});
return;
}
//
this.trainList = [
{ trainNumber: 'G123', departureTime: '08:00', destinationTime: '11:00', duration: '3小时', price: '¥300' },
{ trainNumber: 'D456', departureTime: '10:00', destinationTime: '13:00', duration: '3小时', price: '¥250' },
{ trainNumber: 'K789', departureTime: '12:00', destinationTime: '15:00', duration: '3小时', price: '¥200' }
];
this.searched = true;
}
}
};
</script>
<style>
.search {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.search-header {
margin-bottom: 20px;
}
.title {
font-size: 24px;
font-weight: bold;
}
.search-form {
width: 80%;
}
.form-item {
margin-bottom: 20px;
}
.label {
font-size: 16px;
}
.input {
width: 100%;
height: 40px;
border: 1px solid #ccc;
border-radius: 5px;
padding: 0 10px;
}
.search-btn {
width: 100%;
height: 40px;
background-color: #007aff;
color: #fff;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
.search-result {
width: 80%;
margin-top: 20px;
}
.result-text {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.train-item {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.train-info {
font-size: 16px;
}
</style>

@ -1,94 +0,0 @@
<template>
<view class="ticket-search-result">
<view class="header">车票查询结果</view>
<view class="ticket-list">
<!-- 在这里循环渲染车票列表 -->
<view v-for="ticket in ticketList" :key="ticket.id" class="ticket" @click="buyTicket(ticket)">
<view class="ticket-header">
<text>{{ ticket.departure }} - {{ ticket.destination }}</text>
<text>{{ ticket.departureTime }} - {{ ticket.arrivalTime }}</text>
</view>
<view class="ticket-body">
<view class="ticket-info">
<text>车次</text>
<text>{{ ticket.trainNumber }}</text>
</view>
<view class="ticket-info">
<text>座位类型</text>
<text>{{ ticket.seatType }}</text>
</view>
<view class="ticket-info">
<text>剩余票数</text>
<text>{{ ticket.remainingTickets }}</text>
</view>
<view class="ticket-info">
<text>价格</text>
<text>{{ ticket.price }}</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
ticketList: [
{ id: 1, departure: '北京', destination: '上海', departureTime: '08:00', arrivalTime: '14:00', trainNumber: 'G101', seatType: '二等座', remainingTickets: 20, price: '200元' },
{ id: 2, departure: '北京', destination: '广州', departureTime: '09:00', arrivalTime: '18:00', trainNumber: 'G102', seatType: '一等座', remainingTickets: 10, price: '300元' },
{ id: 3, departure: '北京', destination: '深圳', departureTime: '10:00', arrivalTime: '20:00', trainNumber: 'G103', seatType: '商务座', remainingTickets: 5, price: '400元' }
]
};
},
method:{
buyTikect(ticket){
uni.navigateTo({
url: '/pages/index/Buy-ticket'
});
}
}
};
</script>
<style>
.ticket-search-result {
padding: 20px;
}
.header {
font-size: 24px;
text-align: center;
margin-bottom: 20px;
}
.ticket {
margin-bottom: 10px;
border: 1px solid #ccc;
padding: 10px;
}
.ticket-header {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.ticket-header text {
font-size: 18px;
}
.ticket-body {
display: flex;
justify-content: space-between;
}
.ticket-info {
display: flex;
flex-direction: column;
}
.ticket-info text {
font-size: 16px;
margin-bottom: 5px;
}
</style>

@ -44,26 +44,16 @@ export default {
},
methods: {
handleDepartureClick() {
uni.navigateTo({
url: '/pages/index/Station?type=departure'
});
},
handleDestinationClick() {
uni.navigateTo({
url: '/pages/index/Station?type=destination'
});
},
onShow() {
const type = this.$route.query.type;
if (type === 'departure') {
//
this.departure = this.$route.query.station || '';
} else if (type === 'destination') {
//
this.destination = this.$route.query.station || '';
}
},
// handleDepartureClick() {
// uni.navigateTo({
// url: '/pages/index/Station?type=departure'
// });
// },
// handleDestinationClick() {
// uni.navigateTo({
// url: '/pages/index/Station?type=destination'
// });
// },
goToHome() {
//
uni.navigateTo({
@ -84,11 +74,57 @@ export default {
},
searchTickets() {
//
console.log('出发地:', this.departure);
console.log('目的地:', this.destination);
uni.navigateTo({
url: '/pages/index/search-results'
});
// console.log(':', this.departure);
// console.log(':', this.destination);
const formData = {
departure: this.departure,
destination: this.destination,
date:this.date,
};
// POSTformDataJSON
uni.request({
url: 'http://192.168.251.7:8000/search_train/', //
method: 'POST',
data: JSON.stringify(formData), // formDataJSON
header: {
'content-type': 'application/json' // JSON
},
success: (res) => {
//
if (res.statusCode === 200) { // 200
const data = res.data;
const ticketInfo = { };
this.ticketInfo = data.trains;
localStorage.setItem('ticketInfo', JSON.stringify(ticketInfo));
if (data.message === '查询成功') {
console.log('请求成功',data);
uni.showToast({
title: '查询成功',
icon: 'success'
});
uni.navigateTo({
url: '/pages/index/search-results'
});
} else {
//
const data = res.data;
console.log('请求成功', data);
uni.showToast({
title: data.message + (data.reason ? ': ' + data.reason : ''),
icon: 'none'
});
}
}
},
fail: (err) => {
//
console.error('请求失败', err);
uni.showToast({
title: '请求失败,请重试',
icon: 'none'
});
}
});
//
// ticketList
},

@ -76,17 +76,10 @@ export default {
});
}
}
// else {
// // 200
// uni.showToast({
// title: '',
// icon: 'none'
// });
// }
},
fail: (err) => {
//
console.err('请求失败', err);
console.error('请求失败', err);
uni.showToast({
title: '请求失败,请重试',
icon: 'none'

@ -125,7 +125,6 @@ export default {
// POSTformDataJSON
uni.request({
// url: 'http://192.168.251.7:8000/register_view/', //
url: 'http://192.168.251.7:8000/save_passenger/',
method: 'POST',
data: JSON.stringify(formData), // formDataJSON
@ -155,17 +154,10 @@ export default {
});
}
}
// else {
// // 200
// uni.showToast({
// title: '',
// icon: 'none'
// });
// }
},
fail: (err) => {
//
console.err('请求失败', err);
console.error('请求失败', err);
uni.showToast({
title: '请求失败,请重试',
icon: 'none'

@ -1,11 +1,6 @@
<template>
<div class="page-background">
<view class="content">
<!-- <image class="logo" src="/static/logo.png"></image> -->
<!-- <view class="text-area"> -->
<!-- <view :style="{ textAlign: 'center' }">
<text class="title">{{title}}</text>
</view> -->
<div style="display: flex; justify-content: space-between; position: fixed; bottom: 10%; width: 100%;">
<button style="margin-right: 20px; color: #000000; background-color: transparent;" @click="button1"></button>
<button style="margin-left: 20px; color: #000000; background-color: transparent;" @click="button2"></button>
@ -47,29 +42,7 @@
width: 100%; /* 宽度100%填充整个容器 */
height: 100vh; /* 高度100vh填充整个视口 */
}
/* .content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
} */
/* .logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-bottom: 50rpx;
} */
/*
.text-area {
display: flex;
justify-content: center;
} */
/* .title {
font-size: 36rpx;
color: #8f8f94;
} */
</style>

@ -0,0 +1,39 @@
<template>
<div>
<h1>火车票信息</h1>
<ul>
<li v-for="train in ticketInfo" :key="train.id">
<!-- 假设 train 对象中有相应的属性来显示火车票信息 -->
<p>{{ train.name }} - {{ train.departure }} to {{ train.destination }}</p>
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
ticketInfo: [] //
};
},
mounted() {
// localStorage
const ticketInfoString = localStorage.getItem('ticketInfo');
if (ticketInfoString) {
// JSON JavaScript
this.ticketInfo = JSON.parse(ticketInfoString);
} else {
console.log('未在 localStorage 中找到火车票信息');
}
}
};
</script>
<style scoped>
/* 这里是样式部分 */
h1 {
color: blue;
}
</style>

@ -0,0 +1,8 @@
{
"hash": "1d9cd2f2",
"configHash": "8f0d262f",
"lockfileHash": "e3b0c442",
"browserHash": "780b15fb",
"optimized": {},
"chunks": {}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save