index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="container">
  3. <navBar title="" :navImg="navImg" :back="false" color="#333333" background="#FFFFFF" />
  4. <tabBar :tabBarList="tabBarList" :routePath="routePath" @onTabBar="onTabBar" />
  5. <view class="topBox">
  6. <view class="userBox">
  7. <image class="avatar" @click="toUserInfo" :src="!userInfo?picBase+'defaultAvatar.png':userInfo.avatar" mode=""></image>
  8. <view class="nickname" @click="toUserInfo" v-if="userInfo">
  9. {{!userInfo.name?'默认用户':userInfo.name}}
  10. </view>
  11. <view class="nickname" @click="login" v-else>
  12. 立即登录
  13. </view>
  14. <image class="icon" @click="toUserInfo" :src="picBase+'edit.png'" mode="" v-if="userInfo"></image>
  15. </view>
  16. <view class="infoBox">
  17. <view class="left">
  18. <image class="icon" :src="picBase+'edit.png'" mode=""></image>
  19. 当前剩余次数:2
  20. </view>
  21. <view class="btn" @click="toCharge">
  22. 立即充值
  23. </view>
  24. </view>
  25. </view>
  26. <view class="contentBox">
  27. <view class="tabBox">
  28. <view class="item" @click="toHuibenJilu">
  29. <image class="icon" :src="picBase+'edit.png'" mode=""></image>
  30. <view class="right">
  31. <view class="t1">
  32. 绘本记录
  33. </view>
  34. <view class="t2">
  35. 绘本历史记录
  36. </view>
  37. </view>
  38. </view>
  39. <view class="item" @click="toTuguangDashi">
  40. <image class="icon" :src="picBase+'edit.png'" mode=""></image>
  41. <view class="right">
  42. <view class="t1">
  43. 推广大使
  44. </view>
  45. <view class="t2">
  46. 推广大使招募
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="serListBox">
  52. <view class="item" v-for="(item,index) in serList" @click="toPage(index)">
  53. <view class="left">
  54. <image class="icon" src="../../static/other/edit.png" mode=""></image>
  55. {{item.name}}
  56. </view>
  57. <image class="icon_r" src="../../static/other/arrR.png" mode=""></image>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. login,
  66. getUserInfo
  67. } from '@/api/index/index.js'
  68. // import navBar from '@/components/navBar/index.vue'
  69. export default {
  70. // components: {
  71. // navBar
  72. // },
  73. data() {
  74. return {
  75. userInfo:null,
  76. picBase: this.$picBase,
  77. navImg: require('@/static/other/logo.png'),
  78. tabBarList: [{
  79. "pagePath": "pages/index/index",
  80. "iconPath": "../../static/tabbar/index.png",
  81. "selectedIconPath": "../../static/tabbar/index_a.png",
  82. "text": "首页"
  83. },
  84. {
  85. "pagePath": "pages/my/index",
  86. "iconPath": "../../static/tabbar/my.png",
  87. "selectedIconPath": "../../static/tabbar/my_a.png",
  88. "text": "我的"
  89. }
  90. ],
  91. routePath: '',
  92. serList: [{
  93. name: '推荐奖励',
  94. icon: this.$picBase + 'edit.png',
  95. },
  96. {
  97. name: '消费记录',
  98. icon: this.$picBase + 'edit.png',
  99. },
  100. {
  101. name: '客服中心',
  102. icon: this.$picBase + 'edit.png',
  103. },
  104. {
  105. name: '关于我们',
  106. icon: this.$picBase + 'edit.png',
  107. },
  108. ]
  109. }
  110. },
  111. onLoad() {
  112. uni.hideTabBar()
  113. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  114. let curRoute = routes[routes.length - 1].route // 获取当前页面路由,也就是最后一个打开的页面路由
  115. this.routePath = curRoute;
  116. console.log('routePath', this.routePath);
  117. },
  118. async onShow(){
  119. if(uni.getStorageSync('token')){
  120. this.getUserInfo()
  121. }
  122. },
  123. methods: {
  124. async getUserInfo() {
  125. let res1 = await getUserInfo()
  126. console.log('用户信息返回值--------', res1);
  127. if (res1.code == 0) {
  128. uni.setStorageSync('userInfo', res1.data)
  129. this.userInfo=res1.data
  130. } else {
  131. this.$toast(res1.message)
  132. }
  133. },
  134. login() {
  135. let _this = this
  136. uni.showLoading({
  137. title: '登录中...'
  138. })
  139. uni.login({
  140. provider: 'weixin',
  141. success: async (res) => {
  142. if (res.errMsg == 'login:ok') {
  143. let parmas = {
  144. code: res.code,
  145. }
  146. console.log('登录所传的parmas参数:', parmas);
  147. let res1 = await login(parmas)
  148. console.log('登录返回值--------', res1);
  149. if (res1.code == 0) {
  150. uni.hideLoading()
  151. uni.setStorageSync('token', res1.data.token)
  152. uni.setStorageSync('userInfo', res1.data.user_info)
  153. _this.userInfo=res1.data.user_info
  154. _this.$toast('登录成功')
  155. // setTimeout(() => {
  156. // uni.reLaunch({
  157. // url: '/pages/my'
  158. // })
  159. // }, 1500)
  160. } else {
  161. uni.hideLoading()
  162. _this.$toast(res1.message)
  163. }
  164. }
  165. }
  166. });
  167. },
  168. toPage(i) {
  169. if (i == 0) {
  170. uni.navigateTo({
  171. url: '/pages/my/jiangli/index'
  172. })
  173. } else if (i == 1) {
  174. uni.navigateTo({
  175. url: '/pages/my/myRecord/index?tabIndex=1'
  176. })
  177. }
  178. },
  179. toTuguangDashi() {
  180. uni.navigateTo({
  181. url: '/pages/my/tuiguangDashi/index'
  182. })
  183. },
  184. toTuguangCenter() {
  185. uni.navigateTo({
  186. url: '/pages/my/pubCenter/index'
  187. })
  188. },
  189. onTabBar(e) {
  190. console.log('e------------', e);
  191. uni.switchTab({
  192. url: '/' + e
  193. })
  194. },
  195. toCharge() {
  196. uni.navigateTo({
  197. url: '/pages/my/charge/index'
  198. })
  199. },
  200. toHuibenJilu() {
  201. uni.navigateTo({
  202. url: '/pages/my/huiBen_record/index'
  203. })
  204. },
  205. toUserInfo() {
  206. uni.navigateTo({
  207. url: '/pages/my/userInfo/index'
  208. })
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. @import "./index.scss";
  215. </style>