home.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="container">
  3. <!-- 选择发车时间区域 -->
  4. <view class="time">
  5. <view class="time-title">
  6. 选择发车时间 <span>/ 开启校车之旅</span>
  7. </view>
  8. <view class="time-list">
  9. <view :class="currentIndex1 === index?'active':'time-list-item'" v-for="(item,index) in timeList"
  10. :key="index" @click="handleChangeCurrentIndex(index,1,item)">
  11. {{item}}
  12. </view>
  13. </view>
  14. </view>
  15. <!-- 选择预约车辆区域 -->
  16. <view class="bus">
  17. <view class="bus-title">
  18. 选择预约车辆 <span>/ 墨轩湖 - 综合楼</span>
  19. </view>
  20. <view class="bus-list">
  21. <view :class="currentIndex2 === index?'active':'bus-list-item'" v-for="(item,index) in busList"
  22. :key="index" @click="handleChangeCurrentIndex(index,2,item)">
  23. {{item}}
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 立即预约按钮区域 -->
  28. <view class="btn">
  29. <view class="btn-clock">
  30. <img src="../../static/clock.png">
  31. </view>
  32. <view class="btn-info">
  33. <view class="btn-info-title">
  34. 预约截止时间
  35. </view>
  36. <view class="btn-info-time">
  37. 2023-10-03 15:15:15
  38. </view>
  39. </view>
  40. <view class="btn-button" @click="handleSub">
  41. 立即预约
  42. </view>
  43. </view>
  44. <!-- 预约截止时间区域 -->
  45. <view class="info">
  46. <view class="info-title">
  47. 预约说明
  48. </view>
  49. <view class="info-detail">
  50. 预约成功后请提前5分钟到校车地点,若迟到需重新排队或预约;如有疑问请联系后勤。后勤电话:13689545487
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script setup>
  56. import {
  57. ref
  58. } from "vue"
  59. import {
  60. onLoad
  61. } from "@dcloudio/uni-app"
  62. const wxCode = ref('')
  63. const access_token = ref('')
  64. onLoad(() => {
  65. const busUserInfo = uni.getStorageSync('busUserInfo');
  66. if (!busUserInfo) {
  67. wxCode.value = getQueryString('wxcode')
  68. get_access_token(wxCode.value)
  69. }
  70. })
  71. // 通过wxcode换取access_token
  72. const get_access_token = (wxCode) => {
  73. uni.request({
  74. url: 'open.wecard.qq.com/connect/oauth2/token',
  75. method: 'POST',
  76. // header: {
  77. // 'content-type': 'application/json'
  78. // },
  79. data: {
  80. "wxcode": wxCode,
  81. "app_key": "4AA7B3944BDF3739",
  82. "app_secret": "69E762653EF393C0122278F21754B6CF",
  83. "grant_type": "authorization_code",
  84. "redirect_uri": "http://192.168.161.125:5173/#/pages/home/home"
  85. },
  86. success: (res) => {
  87. alert(JSON.stringify(res))
  88. // access_token.value = res.data.access_token
  89. // alert(access_token.value)
  90. // getUserInfo(access_token.value)
  91. }
  92. });
  93. }
  94. // 通过access_token换取用户信息
  95. const getUserInfo = (access_token) => {
  96. uni.request({
  97. url: 'open.wecard.qq.com/connect/oauth/get-user-info',
  98. method: "POST",
  99. data: {
  100. "access_token": access_token
  101. },
  102. header: {
  103. 'content-type': 'application/json'
  104. },
  105. success: (res) => {
  106. alert(JSON.stringify(res))
  107. }
  108. });
  109. }
  110. //获取当前URL指定参数
  111. const getQueryString = (name) => {
  112. // 获取URL
  113. let url = window.location.href;
  114. // 正则匹配URL
  115. let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i");
  116. let matcher = pattern.exec(url);
  117. if (matcher == null || matcher.length < 1) {
  118. return false;
  119. }
  120. // 输出指定的参数值
  121. return decodeURIComponent(matcher[1]);
  122. }
  123. const currentIndex1 = ref(null)
  124. const currentIndex2 = ref(null)
  125. const currentTime = ref(null)
  126. const currentBus = ref(null)
  127. // 发车时间列表
  128. const timeList = ref([
  129. '2023-10-10 15:15:15', '2023-10-10 16:15:15', '2023-10-10 18:15:15'
  130. ])
  131. // 发车车辆列表
  132. const busList = ref(['车牌尾号:6601(63/63)', '车牌尾号:6661(63/63)', '车牌尾号:6001(63/63)'])
  133. // 改变选中项回调
  134. const handleChangeCurrentIndex = (index, type, value) => {
  135. if (type === 1) {
  136. currentIndex1.value = index
  137. currentTime.value = value
  138. } else {
  139. currentIndex2.value = index
  140. currentBus.value = value
  141. }
  142. }
  143. // 立即预约按钮回调
  144. const handleSub = () => {
  145. if (!currentTime.value) {
  146. uni.showToast({
  147. title: '请先选择发车时间',
  148. icon: "none"
  149. })
  150. return
  151. }
  152. if (!currentBus.value) {
  153. uni.showToast({
  154. title: '请先选择预约车辆',
  155. icon: "none"
  156. })
  157. return
  158. }
  159. uni.showModal({
  160. title: '提示',
  161. content: '确定预约吗?',
  162. success: (res) => {
  163. if (res.confirm) {
  164. console.log(123);
  165. } else if (res.cancel) {
  166. }
  167. }
  168. });
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .container {
  173. padding: 0 30rpx;
  174. .time {
  175. .time-title {
  176. height: 128rpx;
  177. line-height: 128rpx;
  178. font-size: 30rpx;
  179. font-weight: bold;
  180. span {
  181. font-size: 24rpx;
  182. font-weight: 400;
  183. color: #B3B3B3;
  184. }
  185. }
  186. .time-list {
  187. display: grid;
  188. grid-template-columns: 1fr 1fr;
  189. grid-auto-rows: 100rpx;
  190. grid-gap: 30rpx 20rpx;
  191. .time-list-item {
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. font-size: 26rpx;
  196. border: 1rpx solid #CCCCCC;
  197. border-radius: 12rpx;
  198. }
  199. .active {
  200. display: flex;
  201. justify-content: center;
  202. align-items: center;
  203. font-size: 26rpx;
  204. border: 1rpx solid #CCCCCC;
  205. border-radius: 12rpx;
  206. color: #fff;
  207. background-image: linear-gradient(#8684FF, #3D50E7);
  208. }
  209. .disable {
  210. background: #E6E6E6;
  211. }
  212. }
  213. }
  214. .bus {
  215. .bus-title {
  216. height: 128rpx;
  217. line-height: 128rpx;
  218. font-size: 30rpx;
  219. font-weight: bold;
  220. span {
  221. font-size: 24rpx;
  222. font-weight: 400;
  223. }
  224. }
  225. .bus-list {
  226. display: flex;
  227. flex-direction: column;
  228. }
  229. .bus-list-item {
  230. display: flex;
  231. justify-content: center;
  232. align-items: center;
  233. margin-bottom: 30rpx;
  234. height: 100rpx;
  235. font-size: 26rpx;
  236. border: 1rpx solid #CCCCCC;
  237. border-radius: 12rpx;
  238. }
  239. .active {
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. margin-bottom: 30rpx;
  244. height: 100rpx;
  245. font-size: 26rpx;
  246. border: 1rpx solid #CCCCCC;
  247. border-radius: 12rpx;
  248. color: #fff;
  249. background-image: linear-gradient(#8684FF, #3D50E7);
  250. }
  251. .disable {
  252. background: #E6E6E6;
  253. }
  254. }
  255. .btn {
  256. position: relative;
  257. display: flex;
  258. margin-top: 50rpx;
  259. padding: 24rpx 30rpx;
  260. box-sizing: border-box;
  261. height: 115rpx;
  262. border-radius: 15rpx;
  263. box-shadow: 0px 0px 12rpx rgba(0, 0, 0, .12);
  264. .btn-clock {
  265. width: 61rpx;
  266. height: 61rpx;
  267. img {
  268. width: 100%;
  269. }
  270. }
  271. .btn-info {
  272. margin-left: 18rpx;
  273. flex: 1;
  274. display: flex;
  275. flex-direction: column;
  276. justify-content: center;
  277. .btn-info-title {
  278. font-size: 28rpx;
  279. color: #5863F1;
  280. }
  281. .btn-info-time {
  282. font-size: 24rpx;
  283. color: #B3B3B3;
  284. }
  285. }
  286. .btn-button {
  287. position: absolute;
  288. right: 0;
  289. top: -7rpx;
  290. width: 257rpx;
  291. height: 130rpx;
  292. line-height: 130rpx;
  293. text-align: center;
  294. font-size: 30rpx;
  295. color: #fff;
  296. background: url(../../static/box.png);
  297. background-size: 100% 100%;
  298. }
  299. }
  300. .info {
  301. margin: 40rpx 0;
  302. .info-title {
  303. height: 41rpx;
  304. font-size: 28rpx;
  305. }
  306. .info-detail {
  307. margin-top: 5rpx;
  308. height: 70rpx;
  309. color: #B3B3B3;
  310. font-size: 24rpx;
  311. }
  312. }
  313. }
  314. </style>