index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="swipe-banner" v-if="show">
  3. <swiper class="flex1" style="height: 100vh;" :interval="interval" :show-indicators="true" :autoplay="autoPlay"
  4. @change="swiperChange" :infinite="true" :forbid-slide-animation="true">
  5. <swiper-item class="flex1" v-for="(img, index) in bannerList" :key="index">
  6. <view class="flex1" @tap="countdown2home(true,true)">
  7. <!-- #ifndef APP-PLUS -->
  8. <image class="flex1" mode="aspectFill" :style="{ width: screenWidth+ 'px' }" :src="img.src" />
  9. <!-- #endif -->
  10. <!-- #ifdef APP-PLUS -->
  11. <image class="flex1" resize="contain" :src="img.src" />
  12. <!-- #endif -->
  13. </view>
  14. </swiper-item>
  15. </swiper>
  16. <view class="swiper-to-home" @click="countdown2home(true,false)" v-if="showSkip">
  17. <text class="swiper-to-home-text">跳过<text class="swiper-to-home-delay-second"
  18. v-if="delaySecond>0 && delaySecond<300">{{delaySecond}}s</text></text>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. const SystemInfo = uni.getSystemInfoSync();
  24. export default {
  25. data() {
  26. return {
  27. bannerList: [],
  28. tempList: [
  29. // //引导图列表
  30. // {
  31. // src: '/static/splash_1.png',
  32. // swiper: true
  33. // },
  34. // {
  35. // src: '/static/splash_2.png',
  36. // swiper: true
  37. // },
  38. // {
  39. // src: '/static/splash_3.png',
  40. // swiper: true
  41. // },
  42. // {
  43. // src: '/static/splash_4.png',
  44. // swiper: true
  45. // },
  46. // {
  47. // src: '/static/splash_4.png',
  48. // swiper: false
  49. // }
  50. ],
  51. autoPlay: false,
  52. currIndex: 0,
  53. screenWidth: SystemInfo.screenWidth,
  54. delaySecond: 100000, //默认不自动进入
  55. showSkip: false,
  56. countdown: null,
  57. show: false,
  58. interval: 1000
  59. }
  60. },
  61. onLoad() {
  62. //没用启用引导图或没有引导图
  63. // if(!this.$lln.config('enableSplash') || this.tempList.length==0){
  64. // this.$lln.href('/pages/index/index');
  65. // return false;
  66. // }
  67. this.$u.get('/home/start_up', {
  68. site: 0
  69. }).then(res => {
  70. this.bannerList = res.banner
  71. this.interval = res.time
  72. if (this.bannerList.length == 1) {
  73. setTimeout(() => {
  74. uni.reLaunch({
  75. url: '/pages/index/index'
  76. })
  77. }, 1500)
  78. return false
  79. }
  80. // this.tempList.forEach(item => {
  81. // item.swiper = true
  82. // })
  83. // this.tempList.push({
  84. // show_img: this.tempList[this.tempList.length - 1].show_img,
  85. // swiper: false
  86. // })
  87. // console.log(this.tempList)
  88. })
  89. var splash = uni.getStorageSync('LLNAPI-SPLASH');
  90. if (splash) {
  91. //如果已存在直接跳过,注释当前代码会展示一张倒计时的品牌宣传图片
  92. // this.$lln.href('/pages/index/index?target=redirect');
  93. // return false;
  94. }
  95. this.show = true;
  96. this.showSkip = true;
  97. if (this.tempList.length == 1) {
  98. this.bannerList = this.tempList;
  99. //只有一张计时10秒
  100. this.delaySecond = 1;
  101. this.autoPlay = false;
  102. //倒计时进入首页
  103. this.countdown2home(false);
  104. } else {
  105. if (!splash) {
  106. this.bannerList = this.tempList.filter((x) => {
  107. return x.swiper;
  108. });
  109. this.autoPlay = true;
  110. } else {
  111. var masterBanner = [this.tempList[this.tempList.length - 1]];
  112. for (var i = 0; i < this.tempList.length; i++) {
  113. var item = this.tempList[i];
  114. if (!item.swiper) {
  115. masterBanner = item;
  116. break;
  117. }
  118. }
  119. //引导图已经加载过了,只展示一张图片
  120. this.bannerList = [masterBanner];
  121. //只有一张计时10秒
  122. this.delaySecond = 1;
  123. this.autoPlay = false;
  124. this.countdown2home(false);
  125. }
  126. }
  127. },
  128. methods: {
  129. swiperChange: function(e) {
  130. this.currIndex = e.detail.current;
  131. if (this.bannerList.length == this.currIndex + 1) {
  132. //最后一张暂停轮播
  133. this.autoPlay = false;
  134. this.delaySecond = 1;
  135. if (this.countdown) {
  136. this.showSkip = true;
  137. clearInterval(this.countdown);
  138. }
  139. //倒计时进入首页
  140. this.countdown2home(false);
  141. } else {
  142. console.log(this.delaySecond + '>>>>>>>>>>')
  143. if (this.countdown) {
  144. if (this.delaySecond > 3) {
  145. this.delaySecond = 100000;
  146. //停止倒计时
  147. clearInterval(this.countdown);
  148. }
  149. } else {
  150. this.delaySecond = 100000;
  151. }
  152. }
  153. },
  154. countdown2home: function(direct, isLastBanner) {
  155. var that = this;
  156. //手动进入
  157. if (direct) {
  158. if (!isLastBanner || (this.bannerList.length == this.currIndex + 1)) {
  159. if (this.countdown) {
  160. this.showSkip = false;
  161. clearInterval(this.countdown);
  162. }
  163. uni.setStorage({
  164. key: 'LLNAPI-SPLASH',
  165. data: false,
  166. success() {
  167. uni.reLaunch({
  168. url: '/pages/index/index'
  169. })
  170. }
  171. });
  172. }
  173. return false;
  174. }
  175. if (this.delaySecond == -1) {
  176. //不进入,由用户手动点击进入
  177. return false;
  178. }
  179. //倒计时进入首页
  180. this.countdown = setInterval(() => {
  181. if (that.delaySecond < 2) {
  182. that.showSkip = false;
  183. }
  184. if (that.delaySecond > 300) {
  185. clearInterval(that.countdown);
  186. }
  187. if (that.delaySecond < 1) {
  188. clearInterval(that.countdown);
  189. uni.setStorage({
  190. key: 'LLNAPI-SPLASH',
  191. data: false,
  192. success() {
  193. uni.reLaunch({
  194. url: '/pages/index/index'
  195. })
  196. }
  197. });
  198. return;
  199. }
  200. that.delaySecond--;
  201. }, 1000);
  202. }
  203. }
  204. };
  205. </script>
  206. <style>
  207. .swipe-banner {
  208. /* #ifndef APP-PLUS */
  209. display: flex;
  210. height: 100%;
  211. /* #endif */
  212. flex-direction: column;
  213. flex: 1;
  214. min-height: 100vh;
  215. }
  216. .flex1 {
  217. flex: 1;
  218. height: 100%;
  219. }
  220. .apptestnnnn {
  221. border-width: 1px;
  222. border-color: #4cd964;
  223. border-style: solid;
  224. }
  225. .apptest {
  226. border-width: 1px;
  227. border-color: #007aff;
  228. border-style: solid;
  229. }
  230. .swiper-to-home {
  231. position: absolute;
  232. z-index: 999;
  233. right: 40rpx;
  234. /* #ifndef MP */
  235. top: 80rpx;
  236. /* #endif */
  237. /* #ifdef MP */
  238. top: 168rpx;
  239. /* #endif */
  240. }
  241. .swiper-to-home-text {
  242. color: #ffffff;
  243. text-align: center;
  244. background-color: rgba(0, 0, 0, 0.5);
  245. border-width: 1rpx;
  246. border-color: #ffffff;
  247. border-style: solid;
  248. border-radius: 30rpx;
  249. font-size: 28rpx;
  250. padding-top: 5rpx;
  251. padding-bottom: 5rpx;
  252. padding-left: 25rpx;
  253. padding-right: 25rpx;
  254. }
  255. .swiper-to-home-delay-second {
  256. padding-left: 6rpx;
  257. color: #56eeff;
  258. }
  259. .indicator {
  260. width: 714rpx;
  261. height: 30rpx;
  262. position: absolute;
  263. bottom: 50rpx;
  264. left: 1rpx;
  265. item-color: #f6f6f6;
  266. item-selected-color: #fd575c;
  267. item-size: 20rpx;
  268. }
  269. </style>