index.uvue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <view class="body">
  3. <view v-if="pageType == 1" class="content bg-led01">
  4. <view class="distance-container-1">
  5. <view class="total-time-1">总用时: {{durationStr}}</view>
  6. <view class="total-distance-1">{{distanceKm}}KM</view>
  7. </view>
  8. <image class="run" mode="aspectFit" src="/static/led/run.gif"></image>
  9. </view>
  10. <view v-if="pageType == 2" class="content bg-led02">
  11. <view class="pic-container">
  12. <!-- <image class="pic" mode="aspectFill" :src="imageSrc"></image> -->
  13. <swiper class="swiper" autoplay circular :current="picCurIndex" :interval="picInterval"
  14. :duration="picDuration" @change="swiperChange">
  15. <swiper-item v-for="(image, index) in picList" :key="index">
  16. <image class="pic-bg" :src="image"></image>
  17. <image class="pic" mode="aspectFit" :src="image"></image>
  18. </swiper-item>
  19. </swiper>
  20. </view>
  21. <view class="distance-container-2">
  22. <view class="total-time-2">总用时: {{durationStr}}</view>
  23. <view class="total-distance-2">{{distanceKm}}KM</view>
  24. </view>
  25. <image class="mascot" mode="aspectFit" src="/static/led/mascot.png"></image>
  26. <image class="lpzg" mode="aspectFit" src="/static/lpzg.png"></image>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import tools from '../../common/tools';
  32. import { apiGetStatistics, apiGetUploadPic } from '../../common/api';
  33. export default {
  34. data() {
  35. return {
  36. testMode: 0, // 测试模式 0:否 1:是
  37. testDuration: 0,
  38. testDistance: 0,
  39. pageAutoChange: 0, // 有照片是否自动切换背景 0:否 1:是
  40. pageType: 1, // 1: 无照片 2: 有照片
  41. actIdArrStr: "",
  42. SumDuration: 0,
  43. SumDistance: 0,
  44. picCount: 0,
  45. picList: [],
  46. picInterval: 3000, // 自动切换时间间隔
  47. picDuration: 500, // 滑动动画时长
  48. picCurIndex: 0, // swiper当前所在滑块的 index
  49. intervalSta: 0,
  50. // imageSrc: '',
  51. }
  52. },
  53. computed: {
  54. durationStr() {
  55. return tools.convertSecondsToHMS(this.SumDuration);
  56. },
  57. distanceKm() {
  58. if (this.SumDistance < 1000000)
  59. return Math.round(this.SumDistance * 10 / 1000) / 10;
  60. else
  61. return Math.round(this.SumDistance / 1000);
  62. }
  63. },
  64. onLoad(event) { // 类型非必填,可自动推导
  65. // this.SumDuration = 1622;
  66. // this.SumDistance = 999050;
  67. // this.SumDistance = 999949;
  68. // this.SumDistance = 2066869;
  69. // this.imageSrc = "/static/led/pic2.jpg";
  70. this.testMode = event["test"] ?? 0;
  71. this.pageAutoChange = event["pac"] ?? 0;
  72. this.pageType = event["page"] ?? 1;
  73. this.actIdArrStr = event["act"] ?? "175,176,177,178";
  74. this.getUploadPic();
  75. this.getStatistics();
  76. this.intervalSta = setInterval(this.getStatistics, 1000);
  77. },
  78. onUnload() {
  79. console.log("onUnload");
  80. clearInterval(this.intervalSta);
  81. },
  82. methods: {
  83. getStatistics() {
  84. if (this.testMode == 1) {
  85. this.testDuration += 1;
  86. this.testDistance += 100;
  87. this.SumDuration = this.testDuration;
  88. this.SumDistance = this.testDistance;
  89. return;
  90. }
  91. uni.request({
  92. url: apiGetStatistics,
  93. header: {
  94. "Content-Type": "application/x-www-form-urlencoded",
  95. },
  96. method: "POST",
  97. data: {
  98. actIdArrStr: this.actIdArrStr
  99. },
  100. success: (res) => {
  101. // console.log("getStatistics", res)
  102. const data = res.data.data;
  103. this.SumDuration = data.SumDuration;
  104. this.SumDistance = data.SumDistance;
  105. },
  106. fail: (err) => {
  107. console.log("getStatistics err", err)
  108. },
  109. });
  110. },
  111. getUploadPic() {
  112. uni.request({
  113. url: apiGetUploadPic,
  114. header: {
  115. "Content-Type": "application/x-www-form-urlencoded",
  116. },
  117. method: "POST",
  118. data: {
  119. actIdArrStr: this.actIdArrStr
  120. },
  121. success: (res) => {
  122. // console.log("getUploadPic", res);
  123. const data = res.data.data;
  124. const newCount = data.List.length;
  125. console.log("获取到的图片数量:", newCount);
  126. if (newCount > 0) {
  127. if (this.pageAutoChange == 1) {
  128. this.pageType = 2;
  129. }
  130. /* this.picList.length = 0; // 清空数组
  131. for (let i = 0; i < newCount; i++) {
  132. let picUrl = data.Domain + data.List[i];
  133. // console.log("picUrl: " + picUrl);
  134. this.picList.push(picUrl);
  135. }
  136. if (this.picCount > 0) {
  137. this.picCurIndex = this.picCount - 1;
  138. console.log("重定位 index", this.picCurIndex);
  139. } */
  140. } else {
  141. if (this.pageAutoChange == 1) {
  142. if (this.picCount == 0)
  143. this.pageType = 1;
  144. else
  145. this.pageType = 2;
  146. }
  147. }
  148. if (newCount > this.picCount) { // 有新图片
  149. console.log("有 " + (newCount - this.picCount) + " 张新图片");
  150. // 将新增的图片追加到图片队列
  151. for (let i = this.picCount; i < newCount; i++) {
  152. let picUrl = data.Domain + data.List[i];
  153. console.log("[" + i + "] picUrl: " + picUrl);
  154. this.picList.push(picUrl);
  155. }
  156. if (this.picCount > 0) {
  157. this.picCurIndex = this.picCount;
  158. console.log("重定位 index", this.picCurIndex);
  159. }
  160. this.picCount = newCount;
  161. }
  162. if (this.picCount == 0) {
  163. // console.log('this.picCount == 0');
  164. setTimeout(this.getUploadPic, 1000);
  165. }
  166. else if (this.picCount == 1) {
  167. // console.log('this.picCount == 1');
  168. // swiper在只有1张图片的情况下不会触发 @change事件,需要在这里再次获取图片数据
  169. setTimeout(this.getUploadPic, this.picInterval);
  170. }
  171. // console.log("picList", this.picList);
  172. },
  173. fail: (err) => {
  174. console.log("getUploadPic err", err);
  175. setTimeout(this.getUploadPic, 3000);
  176. },
  177. });
  178. },
  179. //当前轮播索引
  180. swiperChange(e) {
  181. console.log("pic index: " + e.detail.current);
  182. const curIndex = e.detail.current;
  183. // 播放完最后一张图片后重新获取图片数据
  184. if (curIndex == this.picCount - 1) {
  185. console.log("播放完毕,重新获取图片数据...");
  186. // this.picCurIndex = curIndex;
  187. this.getUploadPic();
  188. }
  189. },
  190. //点击轮播
  191. swiperClick(e) {
  192. console.log('点击轮播', e);
  193. },
  194. animationfinish() {
  195. console.log('animationfinish');
  196. }
  197. }
  198. }
  199. </script>
  200. <style>
  201. .body {
  202. /* width: 100%; */
  203. /* height: 100vh; */
  204. width: 1920px;
  205. height: 1440px;
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. justify-content: center;
  210. }
  211. .content {
  212. width: 100%;
  213. height: 100%;
  214. flex-direction: row;
  215. align-items: flex-start;
  216. /* justify-content: flex-start; */
  217. }
  218. .bg-led01 {
  219. background-image: url("/static/led/led01.webp");
  220. background-repeat: no-repeat;
  221. background-size: contain;
  222. }
  223. .bg-led02 {
  224. background-image: url("/static/led/led02.webp");
  225. background-repeat: no-repeat;
  226. background-size: contain;
  227. }
  228. .pic-container {
  229. width: 1300px;
  230. height: 850px;
  231. margin-left: 76px;
  232. margin-top: 303px;
  233. background: url("/static/led/pic_border.png");
  234. background-repeat: no-repeat;
  235. background-size: contain;
  236. }
  237. .swiper {
  238. height: 852px;
  239. mask-image: url('/static/led/pic_mask.png');
  240. mask-size: 1298px;
  241. mask-repeat: no-repeat;
  242. }
  243. .pic {
  244. margin: 3px;
  245. width: 1300px;
  246. height: 840px;
  247. }
  248. .pic-bg {
  249. position: absolute;
  250. margin: -10px;
  251. width: 1320px;
  252. height: 860px;
  253. filter: blur(15px);
  254. }
  255. .distance-container-1 {
  256. align-items: center;
  257. justify-content: space-around;
  258. width: 1070px;
  259. height: 450px;
  260. margin-left: 766px;
  261. margin-top: 850px;
  262. }
  263. .total-time-1 {
  264. font-family: 'Arial Black';
  265. font-size: 50px;
  266. color: #ffffff;
  267. margin-left: 390px;
  268. line-height: 100px;
  269. margin-top: 6px;
  270. }
  271. .total-distance-1 {
  272. font-family: 'Arial';
  273. font-size: 330px;
  274. transform: scaleX(0.8);
  275. color: #ffffff;
  276. line-height: 330px;
  277. }
  278. .distance-container-2 {
  279. align-items: center;
  280. justify-content: space-around;
  281. width: 695px;
  282. height: 296px;
  283. margin-left: -253px;
  284. margin-top: 946px;
  285. background: url("/static/led/distance_bg.png") no-repeat;
  286. background-size: cover;
  287. }
  288. .total-time-2 {
  289. font-family: 'Arial Black';
  290. font-size: 36px;
  291. color: #ffffff;
  292. margin-left: 250px;
  293. line-height: 50px;
  294. }
  295. .total-distance-2 {
  296. font-family: 'Arial';
  297. font-size: 200px;
  298. transform: scaleX(0.8);
  299. color: #ffffff;
  300. line-height: 180px;
  301. }
  302. .run {
  303. width: 520px;
  304. height: 520px;
  305. margin-left: -880px;
  306. margin-top: 356px;
  307. }
  308. .mascot {
  309. height: 468px;
  310. margin-left: -495px;
  311. margin-top: 486px;
  312. }
  313. .lpzg {
  314. width: 468px;
  315. margin-left: -1540px;
  316. margin-top: 1072px;
  317. }
  318. </style>