index3.uvue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <!-- LED分辨率: 1920 * 1080 -->
  2. <template>
  3. <view class="body">
  4. <view v-if="pageType == 1" class="content bg-led01">
  5. <view class="distance-container-1">
  6. <view class="total-time-1">总用时: {{durationStr}}</view>
  7. <view class="total-distance-1">{{distanceKm}}KM</view>
  8. </view>
  9. <!-- <image class="run" mode="aspectFit" src="/static/led/run.png"></image> -->
  10. </view>
  11. <view v-if="pageType == 2" class="content bg-led02">
  12. <view class="pic-container">
  13. <!-- <image class="pic" mode="aspectFill" :src="imageSrc"></image> -->
  14. <swiper ref="swiper" class="swiper" :autoplay="autoplay" circular :current="swiperCurrent" :interval="picInterval"
  15. :duration="picDuration" @change="swiperChange" @animationfinish="animationfinish">
  16. <swiper-item v-for="(image, index) in swiperData" :key="index">
  17. <image class="pic-bg" :src="image"></image>
  18. <image class="pic" mode="aspectFit" :src="image"></image>
  19. </swiper-item>
  20. </swiper>
  21. </view>
  22. <view class="distance-container-2">
  23. <view class="total-time-2">总用时: {{durationStr}}</view>
  24. <view class="total-distance-2">{{distanceKm}}KM</view>
  25. </view>
  26. <image class="mascot" mode="aspectFit" src="/static/led/mascot-2.png"></image>
  27. <!-- <image class="lpzg" mode="aspectFit" src="/static/lpzg.png"></image> -->
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import tools from '../../common/tools';
  33. import { apiGetStatistics, apiGetUploadPic } from '../../common/api';
  34. export default {
  35. data() {
  36. return {
  37. testMode: 0, // 测试模式 0:否 1:是
  38. testDuration: 0,
  39. testDistance: 0,
  40. pageAutoChange: 0, // 有照片是否自动切换背景 0:否 1:是
  41. pageType: 1, // 1: 无照片 2: 有照片
  42. actIdArrStr: "",
  43. SumDuration: 0,
  44. SumDistance: 0,
  45. picCount: 0,
  46. autoplay: true,
  47. swiperData: [], // swiper控件的数据
  48. swiperCurrent: 0, // swiper当前所在滑块的 index
  49. picGroupSize: 30, // 图片分组 每组最大图片数量
  50. picGroupNum: 0, // 图片分组 分组数量
  51. picGroupCurIndex: 0,// 图片分组 当前播放的分组序号
  52. picSwiperIndex: 0, // 图片分组 当前播放的分组内的图片序号
  53. picList: [], // 图片列表 存放从服务器获取的所有图片
  54. jumpFlag: false, // 图片分组跳转标志 每组图片播放完都会请求新数据,有则直接跳转到新图片所在组
  55. jumpGroupIndex: 0, // 跳转前所在图片分组序号
  56. jumpPicIndex: 0, // 跳转前所在图片分组内的图片序号
  57. picInterval: 3000, // 自动切换时间间隔
  58. picDuration: 500, // 滑动动画时长
  59. intervalSta: 0,
  60. intervalGrpSw: 0,
  61. }
  62. },
  63. computed: {
  64. durationStr() {
  65. return tools.convertSecondsToHMS(this.SumDuration);
  66. },
  67. distanceKm() {
  68. if (this.SumDistance < 1000000)
  69. return Math.round(this.SumDistance * 10 / 1000) / 10;
  70. else
  71. return Math.round(this.SumDistance / 1000);
  72. }
  73. },
  74. onLoad(event) { // 类型非必填,可自动推导
  75. console.log("图片组容量:" + this.picGroupSize);
  76. console.log("图片显示时长(ms):" + this.picInterval);
  77. this.swiperData = this.picList[0];
  78. this.testMode = event["test"] ?? 0;
  79. this.pageAutoChange = event["pac"] ?? 0;
  80. this.pageType = event["page"] ?? 1;
  81. this.actIdArrStr = event["act"] ?? "175,176,177,178";
  82. this.getUploadPic();
  83. this.getStatistics();
  84. this.handleGroupSwitch();
  85. this.intervalSta = setInterval(this.getStatistics, 1000);
  86. },
  87. onUnload() {
  88. console.log("onUnload");
  89. clearInterval(this.intervalSta);
  90. },
  91. methods: {
  92. handleGroupSwitch() {
  93. // console.log("[handleGroupSwitch] pic group: " + this.picGroupCurIndex + " / pic index: " + this.picSwiperIndex);
  94. if (this.swiperData == undefined) {
  95. setTimeout(this.handleGroupSwitch, 1000);
  96. return;
  97. }
  98. // 当前组已播完
  99. if (this.picSwiperIndex == this.swiperData.length - 1) {
  100. this.picSwiperIndex = 0;
  101. this.autoplay = false;
  102. setTimeout(() => {
  103. // 每播放完一组图片后都向服务器请求一次新图片数据
  104. console.log("组 " + this.picGroupCurIndex + " 播放完毕,获取新图片数据...");
  105. this.getUploadPic();
  106. this.autoplay = true;
  107. setTimeout(this.handleGroupSwitch, 1000);
  108. }, this.picInterval - 100); // 时间-100ms,防止swiper滑动到下一个图片
  109. }
  110. else {
  111. setTimeout(this.handleGroupSwitch, 1000);
  112. }
  113. },
  114. setSwiperData(res) {
  115. // console.log("[setSwiperData] res:", res);
  116. if (res == undefined) {
  117. return;
  118. }
  119. // this.swiperData = res;
  120. this.swiperData = [];
  121. for (let n=0; n<res.length; n++) {
  122. this.swiperData.push(res[n]);
  123. // console.log("[setSwiperData] swiperData.push", res[n]);
  124. }
  125. },
  126. getStatistics() {
  127. if (this.testMode == 1) {
  128. this.testDuration += 1;
  129. this.testDistance += 100;
  130. // this.testDistance = 999949;
  131. this.SumDuration = this.testDuration;
  132. this.SumDistance = this.testDistance;
  133. return;
  134. }
  135. uni.request({
  136. url: apiGetStatistics,
  137. header: {
  138. "Content-Type": "application/x-www-form-urlencoded",
  139. },
  140. method: "POST",
  141. data: {
  142. actIdArrStr: this.actIdArrStr
  143. },
  144. success: (res) => {
  145. // console.log("getStatistics", res)
  146. const data = res.data.data;
  147. this.SumDuration = data.SumDuration;
  148. this.SumDistance = data.SumDistance;
  149. },
  150. fail: (err) => {
  151. console.log("getStatistics err", err)
  152. },
  153. });
  154. },
  155. getUploadPic() {
  156. uni.request({
  157. url: apiGetUploadPic,
  158. header: {
  159. "Content-Type": "application/x-www-form-urlencoded",
  160. },
  161. method: "POST",
  162. data: {
  163. actIdArrStr: this.actIdArrStr
  164. },
  165. success: (res) => {
  166. // console.log("getUploadPic", res);
  167. const data = res.data.data;
  168. const newCount = data.List.length;
  169. console.log("获取到的图片数量:", newCount);
  170. if (newCount > 0) {
  171. if (this.pageAutoChange == 1) {
  172. this.pageType = 2;
  173. }
  174. } else {
  175. if (this.pageAutoChange == 1) {
  176. if (this.picCount == 0)
  177. this.pageType = 1;
  178. else
  179. this.pageType = 2;
  180. }
  181. }
  182. if (newCount > this.picCount) { // 有新图片
  183. console.log("有 " + (newCount - this.picCount) + " 张新图片");
  184. let firstNewPicGroupIndex = 0; // 第一张新图片的组序号
  185. let firstNewPicIndex = 0; // 第一张新图片所属组内的序号
  186. // 将新增的图片追加到图片队列
  187. for (let i = this.picCount; i < newCount; i++) {
  188. let picUrl = data.Domain + data.List[i];
  189. if (this.picList.length == 0) {
  190. this.picGroupNum = 1;
  191. this.picList[this.picGroupNum-1] = new Array();
  192. console.log("新增图片分组: " + (this.picGroupNum-1));
  193. }
  194. if (this.picList[this.picGroupNum-1].length >= this.picGroupSize) {
  195. this.picGroupNum++;
  196. this.picList[this.picGroupNum-1] = new Array();
  197. console.log("新增图片分组: " + (this.picGroupNum-1));
  198. }
  199. if (i == this.picCount) { // 第一张新图片
  200. firstNewPicGroupIndex = this.picGroupNum-1;
  201. firstNewPicIndex = this.picList[this.picGroupNum-1].length;
  202. }
  203. this.picList[this.picGroupNum-1].push(picUrl);
  204. }
  205. // console.log("*** picList 总数量", this.picList.length);
  206. this.picCount = newCount;
  207. // 有新图片,将跳转到新图片所在组, 先保存跳转位置,用于新图片播放完后的回跳
  208. this.jumpFlag = true;
  209. this.jumpGroupIndex = this.picGroupCurIndex;
  210. this.jumpPicIndex = this.picSwiperIndex;
  211. // 跳转到第一张新图片所在的组
  212. this.setSwiperData(this.picList[firstNewPicGroupIndex]);
  213. this.picGroupCurIndex = firstNewPicGroupIndex;
  214. this.swiperCurrent = firstNewPicIndex;
  215. this.picSwiperIndex = firstNewPicIndex;
  216. console.log("==> 新图片跳转 pic group: " + this.picGroupCurIndex + " / pic index: " + this.picSwiperIndex);
  217. }
  218. else { // 没有新图片
  219. // 当前播放组不是最后一组
  220. if (this.picGroupCurIndex < this.picGroupNum - 1) {
  221. // 继续播放下一组图片
  222. this.picGroupCurIndex++;
  223. this.swiperCurrent = 0;
  224. this.picSwiperIndex = 0;
  225. console.log("没有新图片,继续播放下一组图片 pic group: " + this.picGroupCurIndex);
  226. }
  227. // 当前播放组是最后一组
  228. else {
  229. // 判断是否需要回跳
  230. if (this.jumpFlag) {
  231. this.jumpFlag = false;
  232. // 回跳组不是最后一组
  233. if (this.jumpGroupIndex < this.picGroupNum - 1) {
  234. // 回跳到原先发生跳转组的下一个组
  235. this.picGroupCurIndex = this.jumpGroupIndex + 1;
  236. }
  237. // 回跳组是最后一组
  238. else {
  239. // 回跳到第一组
  240. this.picGroupCurIndex = 0;
  241. }
  242. this.swiperCurrent = 0;
  243. this.picSwiperIndex = 0;
  244. // 回跳到原先发生跳转的组
  245. // this.picGroupCurIndex = this.jumpGroupIndex;
  246. // this.swiperCurrent = this.jumpPicIndex;
  247. // this.picSwiperIndex = this.jumpPicIndex;
  248. console.log("==> 全部播放完毕,没有新图片,回跳播放 pic group: " + this.picGroupCurIndex);
  249. }
  250. else { // 从第1组重新开始播放图片
  251. this.picGroupCurIndex = 0;
  252. this.swiperCurrent = 0;
  253. this.picSwiperIndex = 0;
  254. console.log("全部播放完毕,没有新图片,开始重播 pic group: " + this.picGroupCurIndex);
  255. }
  256. }
  257. this.setSwiperData(this.picList[this.picGroupCurIndex]);
  258. // console.log("picList", this.picList);
  259. // console.log("swiperData", this.swiperData);
  260. }
  261. if (this.picCount == 0) {
  262. // console.log('this.picCount == 0');
  263. setTimeout(this.getUploadPic, 1000);
  264. }
  265. else if (this.picCount == 1) {
  266. // console.log('this.picCount == 1');
  267. // swiper在只有1张图片的情况下不会触发 @change事件,需要在这里再次获取图片数据
  268. setTimeout(this.getUploadPic, this.picInterval);
  269. }
  270. // console.log("picList", this.picList);
  271. },
  272. fail: (err) => {
  273. console.log("getUploadPic err", err);
  274. setTimeout(this.getUploadPic, 3000);
  275. },
  276. });
  277. },
  278. //当前轮播索引
  279. swiperChange(e) {
  280. console.log("pic group: " + this.picGroupCurIndex + " / pic index: " + e.detail.current);
  281. // console.log("picGroupNum: " + this.picGroupNum);
  282. const curIndex = e.detail.current;
  283. this.picSwiperIndex = curIndex;
  284. // 当前组已播完
  285. if (curIndex == this.swiperData.length - 1) {
  286. this.autoplay = false;
  287. }
  288. },
  289. //点击轮播
  290. swiperClick(e) {
  291. console.log('点击轮播', e);
  292. },
  293. animationfinish(e) {
  294. // console.log('animationfinish');
  295. // console.log("pic group: " + this.picGroupCurIndex + " / pic index: " + e.detail.current);
  296. }
  297. }
  298. }
  299. </script>
  300. <style>
  301. .body {
  302. /* width: 100%; */
  303. /* height: 100vh; */
  304. width: 1920px;
  305. height: 1080px;
  306. display: flex;
  307. flex-direction: column;
  308. align-items: center;
  309. justify-content: center;
  310. }
  311. .content {
  312. width: 100%;
  313. height: 100%;
  314. flex-direction: row;
  315. align-items: flex-start;
  316. /* justify-content: flex-start; */
  317. }
  318. .bg-led01 {
  319. background-image: url("/static/led/led01-3.webp");
  320. background-repeat: no-repeat;
  321. background-size: contain;
  322. }
  323. .bg-led02 {
  324. background-image: url("/static/led/led02-3.webp");
  325. background-repeat: no-repeat;
  326. background-size: contain;
  327. }
  328. .pic-container {
  329. width: 1220px;
  330. height: 810px;
  331. margin-left: 100px;
  332. margin-top: 100px;
  333. background: url("/static/led/pic_border-3.png");
  334. background-repeat: no-repeat;
  335. background-size: contain;
  336. }
  337. .swiper {
  338. height: 812px;
  339. mask-image: url('/static/led/pic_mask-3.png');
  340. mask-size: 1218px;
  341. mask-repeat: no-repeat;
  342. }
  343. .pic {
  344. margin: 3px;
  345. width: 1218px;
  346. height: 810px;
  347. }
  348. .pic-bg {
  349. position: absolute;
  350. margin: -10px;
  351. width: 1240px;
  352. height: 830px;
  353. filter: blur(15px);
  354. }
  355. .distance-container-1 {
  356. align-items: center;
  357. justify-content: space-around;
  358. width: 1130px;
  359. height: 476px;
  360. margin-left: 175px;
  361. margin-top: 165px;
  362. }
  363. .total-time-1 {
  364. font-family: 'Arial Black';
  365. font-size: 50px;
  366. color: #ffffff;
  367. margin-left: 390px;
  368. line-height: 90px;
  369. margin-top: 0px;
  370. }
  371. .total-distance-1 {
  372. font-family: 'Arial';
  373. font-size: 330px;
  374. transform: scaleX(0.8);
  375. color: #ffffff;
  376. line-height: 300px;
  377. }
  378. .distance-container-2 {
  379. align-items: center;
  380. justify-content: space-around;
  381. width: 660px;
  382. height: 280px;
  383. margin-left: -163px;
  384. margin-top: 366px;
  385. background: url("/static/led/distance_bg.png") no-repeat;
  386. background-size: cover;
  387. }
  388. .total-time-2 {
  389. font-family: 'Arial Black';
  390. font-size: 36px;
  391. transform: scaleX(0.9);
  392. color: #ffffff;
  393. margin-left: 320px;
  394. line-height: 50px;
  395. }
  396. .total-distance-2 {
  397. font-family: 'Arial';
  398. font-size: 200px;
  399. transform: scaleX(0.78);
  400. color: #ffffff;
  401. line-height: 180px;
  402. }
  403. .run {
  404. width: 468px;
  405. height: 468px;
  406. margin-left: -840px;
  407. margin-top: 130px;
  408. }
  409. .mascot {
  410. height: 358px;
  411. margin-left: -525px;
  412. margin-top: 80px;
  413. }
  414. .lpzg {
  415. width: 468px;
  416. margin-left: -1510px;
  417. margin-top: 832px;
  418. }
  419. </style>