index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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" :style="{'background-image':`url(${picBase+'my_bg.png'})`}">
  6. <view class="userBox">
  7. <image class="avatar" @click="toUserInfo"
  8. :src="!userInfo.avatar?picBase+'defaultAvatar.png':userInfo.avatar" mode=""></image>
  9. <view class="nickname" @click="toUserInfo" v-if="userInfo">
  10. {{!userInfo.name?'默认用户':userInfo.name}}
  11. </view>
  12. <view class="nickname" @click="login" v-else>
  13. 立即登录
  14. </view>
  15. <image class="icon" @click="toUserInfo" :src="picBase+'edit.png'" mode="" v-if="userInfo"></image>
  16. </view>
  17. <view class="infoBox" :style="{'background-image':`url(${picBase+'user_bg.png'})`}">
  18. <view class="left">
  19. <image class="icon" :src="picBase+'charge_yibiao.png'" mode=""></image>
  20. 当前剩余次数:{{userInfo.diamond?userInfo.diamond:0}}
  21. </view>
  22. <view class="btn" @click="toCharge">
  23. 立即充值
  24. </view>
  25. </view>
  26. </view>
  27. <view class="contentBox" :style="{'background-image':`url(${picBase+'my_b_bg.png'})`}">
  28. <view class="tabBox">
  29. <view class="item" @click="toHuibenJilu">
  30. <image class="icon" :src="picBase+'my_hbjl.png'" mode=""></image>
  31. <view class="right">
  32. <view class="t1">
  33. 绘本记录
  34. </view>
  35. <view class="t2">
  36. 绘本历史记录
  37. </view>
  38. </view>
  39. </view>
  40. <view class="item" @click="toTuguangDashi">
  41. <image class="icon" :src="picBase+'my_tgds.png'" mode=""></image>
  42. <view class="right">
  43. <view class="t1">
  44. 推广大使
  45. </view>
  46. <view class="t2">
  47. 推广大使招募
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="serListBox">
  53. <view class="item" v-for="(item,index) in serList" @click="toPage(index)">
  54. <view class="left">
  55. <image class="icon" :src="item.icon" mode=""></image>
  56. {{item.name}}
  57. </view>
  58. <image class="icon_r" :src="picBase+'arrR.png'" mode=""></image>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. // import navBar from '@/components/navBar/index.vue'
  66. import {
  67. getUserInfo,
  68. login,
  69. addTeam,
  70. getPosterBg
  71. } from '@/api/index/index.js'
  72. export default {
  73. // components: {
  74. // navBar
  75. // },
  76. data() {
  77. return {
  78. userInfo: null,
  79. picBase: this.$picBase,
  80. navImg: this.$picBase + 'logo.png',
  81. tabBarList: [
  82. {
  83. "pagePath": "pages/index/index",
  84. "iconPath": "../../static/tabbar/index.png",
  85. "selectedIconPath": "../../static/tabbar/index_a.png",
  86. "text": "首页"
  87. },
  88. {
  89. "pagePath": "pages/my/index",
  90. "iconPath": "../../static/tabbar/my.png",
  91. "selectedIconPath": "../../static/tabbar/my_a.png",
  92. "text": "我的"
  93. }
  94. ],
  95. routePath: '',
  96. serList: [{
  97. name: '推广中心',
  98. icon: this.$picBase + 'my_jl.png',
  99. },
  100. {
  101. name: '推荐奖励',
  102. icon: this.$picBase + 'my_jl.png',
  103. },
  104. {
  105. name: '消费记录',
  106. icon: this.$picBase + 'my_xfjl.png',
  107. },
  108. {
  109. name: '主角管理',
  110. icon: this.$picBase + 'my_xfjl.png',
  111. },
  112. {
  113. name: '客服中心',
  114. icon: this.$picBase + 'my_kfzx.png',
  115. },
  116. {
  117. name: '关于我们',
  118. icon: this.$picBase + 'my_gywm.png',
  119. },
  120. ]
  121. }
  122. },
  123. onLoad() {
  124. // console.log(this.picBase + 'defaultAvatar.png');
  125. uni.hideTabBar()
  126. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  127. let curRoute = routes[routes.length - 1].route // 获取当前页面路由,也就是最后一个打开的页面路由
  128. this.routePath = curRoute;
  129. console.log('routePath', this.routePath);
  130. },
  131. async onShow() {
  132. if (uni.getStorageSync('token')) {
  133. this.getUserInfo()
  134. this.getShare()
  135. }
  136. },
  137. onShareAppMessage(params) {
  138. if (params.from === 'button' || params.from === 'menu') {
  139. return {
  140. // title: this.shareTitle,
  141. // imageUrl: this.$ossBaseUrl + this.shareImg,
  142. path: '/pages/my/index',
  143. mpId: this.$appId,
  144. type: this.$shareType,
  145. }
  146. }
  147. },
  148. methods: {
  149. async getShare() {
  150. let res1 = await getPosterBg({
  151. key: 'share_title'
  152. })
  153. console.log('分享信息返回值--------1', res1);
  154. if (res1.code == 0) {
  155. this.shareTitle = res1.data.value
  156. } else {
  157. this.$toast(res1.message)
  158. }
  159. let res2 = await getPosterBg({
  160. key: 'share_image'
  161. })
  162. console.log('分享信息返回值--------2', res2);
  163. if (res2.code == 0) {
  164. this.shareImg = res2.data.value
  165. } else {
  166. this.$toast(res2.message)
  167. }
  168. //
  169. },
  170. async addTeam(p) {
  171. let res1 = await addTeam(p)
  172. console.log('我的-加入团队返回值--------2', res1);
  173. if (res1.code == 0) {
  174. console.log('我的--加入团队成功--------------------------------');
  175. } else {
  176. this.$toast(res1.message)
  177. }
  178. },
  179. async getUserInfo() {
  180. let res1 = await getUserInfo()
  181. console.log('用户信息返回值--------', res1);
  182. if (res1.code == 0) {
  183. uni.setStorageSync('userInfo', res1.data)
  184. this.userInfo = res1.data
  185. } else {
  186. this.$toast(res1.message)
  187. }
  188. },
  189. login() {
  190. let _this = this
  191. uni.showLoading({
  192. title: '登录中...'
  193. })
  194. uni.login({
  195. provider: 'weixin',
  196. success: async (res) => {
  197. if (res.errMsg == 'login:ok') {
  198. let parmas = {
  199. code: res.code,
  200. helpId: uni.getStorageSync('inviteInfo') ? uni.getStorageSync(
  201. 'inviteInfo') : ''
  202. }
  203. console.log('登录所传的parmas参数:', parmas);
  204. let res1 = await login(parmas)
  205. console.log('登录返回值--------', res1);
  206. if (res1.code == 0) {
  207. // 处理加入团队逻辑
  208. // _this.addTeam({
  209. // id: uni.getStorageSync('inviteInfo')
  210. // })
  211. uni.hideLoading()
  212. uni.setStorageSync('token', res1.data.token)
  213. uni.setStorageSync('userInfo', res1.data.user_info)
  214. _this.userInfo = res1.data.user_info
  215. _this.$toast('登录成功')
  216. // setTimeout(() => {
  217. // uni.reLaunch({
  218. // url: '/pages/my'
  219. // })
  220. // }, 1500)
  221. } else {
  222. uni.hideLoading()
  223. _this.$toast(res1.message)
  224. }
  225. }
  226. }
  227. });
  228. },
  229. toPage(i) {
  230. if (i == 0) {
  231. if (!uni.getStorageSync('token')) {
  232. return this.$toast('请登录后操作')
  233. }
  234. if (this.userInfo.is_share == 0) {
  235. uni.navigateTo({
  236. url: '/pages/my/jiangli/index'
  237. })
  238. } else {
  239. uni.navigateTo({
  240. url: '/pages/my/pubCenter/index'
  241. })
  242. }
  243. } else if (i == 1) {
  244. if (!uni.getStorageSync('token')) {
  245. return this.$toast('请登录后操作')
  246. }
  247. uni.navigateTo({
  248. url: '/pages/my/jiangli/index'
  249. })
  250. } else if (i == 3) {
  251. if (!uni.getStorageSync('token')) {
  252. return this.$toast('请登录后操作')
  253. }
  254. uni.navigateTo({
  255. url: '/pages/my/roleManage/index'
  256. })
  257. } else if (i == 2) {
  258. if (!uni.getStorageSync('token')) {
  259. return this.$toast('请登录后操作')
  260. }
  261. uni.navigateTo({
  262. url: '/pages/my/myRecord/index?tabIndex=1'
  263. })
  264. } else if (i == 4) {
  265. uni.navigateTo({
  266. url: '/pages/my/kefu/index'
  267. })
  268. } else if (i == 5) {
  269. uni.navigateTo({
  270. url: '/pages/my/aboutUs/index'
  271. })
  272. }
  273. },
  274. toTuguangDashi() {
  275. if (!uni.getStorageSync('token')) {
  276. return this.$toast('请登录后操作')
  277. }
  278. if (this.userInfo.is_share) {
  279. uni.navigateTo({
  280. url: '/pages/my/pubCenter/index'
  281. })
  282. } else {
  283. uni.navigateTo({
  284. url: '/pages/my/tuiguangDashi/index'
  285. })
  286. }
  287. },
  288. toTuguangCenter() {
  289. if (!uni.getStorageSync('token')) {
  290. return this.$toast('请登录后操作')
  291. }
  292. uni.navigateTo({
  293. url: '/pages/my/pubCenter/index'
  294. })
  295. },
  296. onTabBar(e) {
  297. console.log('e------------', e);
  298. uni.switchTab({
  299. url: '/' + e
  300. })
  301. },
  302. toCharge() {
  303. if (!uni.getStorageSync('token')) {
  304. return this.$toast('请登录后操作')
  305. }
  306. let res = wx.getSystemInfoSync();
  307. console.log('wx.getSystemInfoSync()', res.platform);
  308. if (res.platform == 'ios') {
  309. return wx.showModal({
  310. title: '提示',
  311. content: '【由于相关规范,iOS功能暂不可用】',
  312. success(res) {
  313. if (res.confirm) {
  314. console.log('用户点击确定')
  315. } else if (res.cancel) {
  316. console.log('用户点击取消')
  317. }
  318. }
  319. })
  320. }
  321. uni.navigateTo({
  322. url: '/pages/my/charge/index'
  323. })
  324. },
  325. toHuibenJilu() {
  326. if (!uni.getStorageSync('token')) {
  327. return this.$toast('请登录后操作')
  328. }
  329. uni.navigateTo({
  330. url: '/pages/my/huiBen_record/index'
  331. })
  332. },
  333. toUserInfo() {
  334. if (!uni.getStorageSync('token')) {
  335. return this.$toast('请登录后操作')
  336. }
  337. uni.navigateTo({
  338. url: '/pages/my/userInfo/index'
  339. })
  340. }
  341. }
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. @import "./index.scss";
  346. </style>