index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view class="container">
  3. <navBar title="" :navImg="navImg" :back="false" color="#333333" background="#FFFFFF" />
  4. <loadingPage v-if="showLoadingPage" />
  5. <!-- 轮播图 -->
  6. <view class="swiperBox">
  7. <u-swiper height="572rpx" imgMode="" :autoplay="true" interval="5000" :list="list1" @click="toPage" circular
  8. @change="swiperChange">
  9. </u-swiper>
  10. <!-- <u-swiper height="572rpx" imgMode="aspectFill" :autoplay="false" :list="list1" @click="" circular>
  11. </u-swiper> -->
  12. <view class='swiperDot'>
  13. <view :class="[currSwiperIndex==index?'dotA':'dot']" v-for="(item,index) in list1" :key="index">
  14. </view>
  15. </view>
  16. </view>
  17. <view class="mainContent" :style="{'background-image':`url(${picBase+'indexBg.png'})`}">
  18. <view class="topBox" :style="{'background-image':`url(${picBase+'indexCardBg.png'})`}" @click="toGen">
  19. <view class="top">
  20. 即 刻 生 成
  21. </view>
  22. <view class="bot">
  23. <view class="center">
  24. 给孩子一个
  25. </view>
  26. <view class="slogn">
  27. 独一无二的故事礼物
  28. <image class="wArr" :src="picBase+'wArr.png'" mode=""></image>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="botBox" :style="{'background-image':`url(${picBase+'indexBg2.png'})`}">
  33. <view class="title">
  34. 绘本广场
  35. <image class="bookIcon" :src="picBase+'indexBook.png'">
  36. </image>
  37. </view>
  38. <view class="empty" style="margin-top: 50%;" v-if="jingxuanList.length==0">
  39. <u-empty mode="data" />
  40. </view>
  41. <!-- <view class="" v-else>
  42. </view> -->
  43. <view class="list" v-else>
  44. <view v-if="index % 2==0" class="item" v-for="(item,index) in jingxuanList"
  45. @click="toHuibenDetail(item)" :key="index">
  46. <image class="pic" :src="'https://'+item.sd_image" mode="widthFix">
  47. </image>
  48. <view class="des">
  49. {{item.title}}
  50. </view>
  51. </view>
  52. <view v-if="index % 2==1" class="item" v-for="(item,index) in jingxuanList"
  53. @click="toHuibenDetail(item)" :key="index">
  54. <image class="pic" :src="'https://'+item.sd_image" mode="widthFix">
  55. </image>
  56. <view class="des">
  57. {{item.title}}
  58. </view>
  59. </view>
  60. </view>
  61. <u-loadmore :status="status" />
  62. <tabBar :tabBarList="tabBarList" :routePath="routePath" @onTabBar="onTabBar" />
  63. <!-- 隐私弹框 -->
  64. <privacy-popup @confirmP="confirmP" :urlTitle="urlTitle" @cancleP="cancleP"
  65. :showPrivateBox="showPop"></privacy-popup>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. getJingxuan,
  73. getbanner,
  74. addTeam,
  75. getPosterBg,
  76. login
  77. } from '@/api/index/index.js'
  78. import PrivacyPopup from "@/components/privacyPopup/index.vue";
  79. import uploadUrl from '@/common/config.js'
  80. export default {
  81. components: {
  82. PrivacyPopup
  83. },
  84. data() {
  85. return {
  86. showLoadingPage: true,
  87. currSwiperIndex: 0,
  88. // adListSwiper: [],
  89. status: 'nomore',
  90. picBase: this.$picBase,
  91. baseUrl: uploadUrl.baseUrl,
  92. jingxuanList: [],
  93. navImg: this.$picBase + 'logo.png',
  94. showPop: false,
  95. urlTitle: '',
  96. list1: [
  97. // 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  98. // 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  99. // 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  100. ],
  101. tabBarList: [{
  102. "pagePath": "pages/index/index",
  103. "iconPath": "../../static/tabbar/index.png",
  104. "selectedIconPath": "../../static/tabbar/index_a.png",
  105. "text": "首页"
  106. },
  107. {
  108. "pagePath": "pages/my/index",
  109. "iconPath": "../../static/tabbar/my.png",
  110. "selectedIconPath": "../../static/tabbar/my_a.png",
  111. "text": "我的"
  112. }
  113. ],
  114. routePath: '',
  115. // bannerList: [],
  116. total: 0,
  117. page: 1,
  118. shareTitle: null,
  119. shareImg: '',
  120. bannerList: []
  121. }
  122. },
  123. async onLoad(o) {
  124. setTimeout(() => {
  125. this.showLoadingPage = false
  126. }, 1100)
  127. // 处理团队推广逻辑
  128. console.log('index----onload参数', o);
  129. // o.scene = 9999
  130. if (o.scene) {
  131. uni.setStorageSync('inviteInfo', o.scene)
  132. // this.addTeam({
  133. // id: o.scen
  134. // })
  135. }
  136. // this.login()
  137. // else {
  138. // uni.setStorageSync('inviteInfo', o.scen)
  139. // }
  140. uni.hideTabBar()
  141. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  142. let curRoute = routes[routes.length - 1].route // 获取当前页面路由,也就是最后一个打开的页面路由
  143. this.routePath = curRoute;
  144. console.log('routePath', this.routePath);
  145. this.getJingxuan()
  146. },
  147. onShareAppMessage(params) {
  148. if (params.from === 'button' || params.from === 'menu') {
  149. return {
  150. // title: this.shareTitle,
  151. // imageUrl: this.$ossBaseUrl + this.shareImg,
  152. path: '/pages/index/index',
  153. mpId: this.$appId,
  154. type: this.$shareType,
  155. }
  156. }
  157. },
  158. onShow() {
  159. this.handlePrivate()
  160. this.getbanner()
  161. this.getShare()
  162. },
  163. onReachBottom() {
  164. console.log('onReachBottom()------------------------');
  165. if (this.jingxuanList.length < this.total) {
  166. this.status = 'loading'
  167. this.getJingxuan()
  168. }
  169. },
  170. methods: {
  171. toPage(e) {
  172. console.log('e', this.bannerList[e].url);
  173. if (this.bannerList[e].url) {
  174. uni.navigateTo({
  175. url: this.bannerList[e].url
  176. })
  177. }
  178. },
  179. login() {
  180. let _this = this
  181. uni.login({
  182. provider: 'weixin',
  183. success: async (res) => {
  184. if (res.errMsg == 'login:ok') {
  185. let parmas = {
  186. code: res.code,
  187. helpId: uni.getStorageSync('inviteInfo') ? uni.getStorageSync(
  188. 'inviteInfo') : ''
  189. }
  190. console.log('登录所传的parmas参数:', parmas);
  191. let res1 = await login(parmas)
  192. console.log('登录返回值--------', res1);
  193. if (res1.code == 0) {
  194. uni.setStorageSync('token', res1.data.token)
  195. uni.setStorageSync('userInfo', res1.data.user_info)
  196. uni.removeStorageSync('inviteInfo')
  197. } else {
  198. _this.$toast(res1.message)
  199. }
  200. }
  201. }
  202. });
  203. },
  204. swiperChange(e) {
  205. // console.log('swiper---e', e);
  206. this.currSwiperIndex = e.current
  207. },
  208. async getShare() {
  209. let res1 = await getPosterBg({
  210. key: 'share_title'
  211. })
  212. console.log('分享信息返回值--------1', res1);
  213. if (res1.code == 0) {
  214. this.shareTitle = res1.data.value
  215. } else {
  216. this.$toast(res1.message)
  217. }
  218. let res2 = await getPosterBg({
  219. key: 'share_image'
  220. })
  221. console.log('分享信息返回值--------2', res2);
  222. if (res2.code == 0) {
  223. this.shareImg = res2.data.value
  224. } else {
  225. this.$toast(res2.message)
  226. }
  227. //
  228. },
  229. toGen() {
  230. uni.navigateTo({
  231. url: '/pages/index/genHuiBen/index'
  232. })
  233. },
  234. toHuibenDetail(item) {
  235. getApp().huibenDetail = item
  236. uni.navigateTo({
  237. url: '/pages/index/genRes/index'
  238. })
  239. },
  240. async addTeam(p) {
  241. let res1 = await addTeam(p)
  242. console.log('加入团队返回值--------2', res1);
  243. if (res1.code == 0) {
  244. console.log('加入团队成功--------------------------------');
  245. } else {
  246. this.$toast(res1.message)
  247. }
  248. },
  249. async getbanner() {
  250. let res1 = await getbanner()
  251. console.log('首页轮播图返回值--------2', res1);
  252. if (res1.code == 0) {
  253. this.bannerList = res1.data
  254. let tempList = []
  255. res1.data.forEach((item, index) => {
  256. tempList.push(item.image_path)
  257. })
  258. this.list1 = tempList
  259. // this.adListSwiper = tempList
  260. console.log('list1', this.list1);
  261. } else {
  262. this.$toast(res1.message)
  263. }
  264. },
  265. async getJingxuan() {
  266. let res1 = await getJingxuan({
  267. page: this.page,
  268. // size: 2
  269. })
  270. console.log('首页精选返回值--------2', res1.data.data);
  271. if (res1.code == 0) {
  272. this.total = res1.data.total
  273. // this.jingxuanList = [1]
  274. this.jingxuanList = this.jingxuanList.concat(res1.data.data)
  275. this.status = 'nomore'
  276. console.log('page', this.page, 'this.jingxuanList', this.jingxuanList);
  277. this.page++
  278. } else {
  279. this.$toast(res1.message)
  280. }
  281. },
  282. toGen() {
  283. if (!uni.getStorageSync('token')) {
  284. this.$toast('请登录后操作')
  285. setTimeout(() => {
  286. uni.switchTab({
  287. url: '/pages/my/index'
  288. })
  289. }, 1500)
  290. return
  291. }
  292. uni.navigateTo({
  293. url: '/pages/index/genHuiBen/index'
  294. })
  295. },
  296. handlePrivate() {
  297. let _this = this
  298. if (uni.getPrivacySetting) {
  299. uni.getPrivacySetting({
  300. success: res => {
  301. console.log("是否需要授权--首页:", res.needAuthorization, "隐私协议的名称为:", res
  302. .privacyContractName)
  303. _this.urlTitle = res
  304. .privacyContractName
  305. if (res.needAuthorization) {
  306. getApp().globalData.showPrivacy = true;
  307. _this.showPop = true
  308. } else {
  309. getApp().globalData.showPrivacy = false;
  310. }
  311. },
  312. fail: () => {},
  313. complete: () => {},
  314. })
  315. }
  316. },
  317. confirmP() {
  318. this.showPop = false
  319. },
  320. cancleP() {
  321. let _this = this
  322. uni.showModal({
  323. title: '提示',
  324. content: '拒绝将退出小程序,确定退出?',
  325. success: function(res) {
  326. if (res.confirm) {
  327. _this.showPop = false
  328. wx.exitMiniProgram({
  329. success: function() {
  330. // uni.removeStorageSync('iv'); //清除缓存
  331. }
  332. })
  333. } else if (res.cancel) {
  334. }
  335. }
  336. });
  337. },
  338. onTabBar(e) {
  339. console.log('e------------', e);
  340. uni.switchTab({
  341. url: '/' + e
  342. })
  343. },
  344. async testReq() {
  345. console.log('testStore()111111', this.$store.getters['user/testInfo']);
  346. console.log('testStore()111111', this.$store.getters['user/testInfo2']);
  347. // let res = await getValidateCode({
  348. // phone: '15609038521',
  349. // event: 'register'
  350. // })
  351. // uni.showToast({
  352. // title: res.msg,
  353. // icon: 'none'
  354. // })
  355. // console.log('发送短信验证码返回值', res);
  356. // if (res.code == 0) {}
  357. },
  358. testStore() {
  359. this.$store.dispatch('user/testAct', '6666666')
  360. console.log('testStore()', this.$store.getters['user/testInfo']);
  361. // this.$store.dispatch('testAct', '66666');
  362. // console.log('存入仓库后', this.$store.getters.testInfo);
  363. },
  364. async testLogin() {
  365. let res = await this.$store.dispatch('user/testAct2', {
  366. phone: '15609038533',
  367. event: 'register'
  368. })
  369. console.log('测试登录返回值:', res);
  370. },
  371. testLogout() {
  372. this.$store.dispatch('user/testAct3')
  373. console.log('测试退出登录返回值:', this.$store.getters['user/testInfo3']);
  374. },
  375. },
  376. }
  377. </script>
  378. <style lang="scss" scoped>
  379. @import "./index.scss";
  380. </style>