index.vue 10 KB

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