index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. logo: ''
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. async onLoad(options) {},
  13. /**
  14. * 生命周期函数--监听页面初次渲染完成
  15. */
  16. onReady() {
  17. },
  18. /**
  19. * 生命周期函数--监听页面显示
  20. */
  21. async onShow() {
  22. const that = this;
  23. wx.showLoading({ title: '加载中', mask: true })
  24. await that.searchConfig()
  25. // 获取Openid
  26. await that.searchOpenid();
  27. wx.hideLoading()
  28. },
  29. async searchConfig() {
  30. const that = this;
  31. const res = await app.$api('config', 'GET', {});
  32. if (res.errcode == '0') {
  33. // logo
  34. if (res.data && res.data.logo_url && res.data.logo_url.length > 0) {
  35. let logo = res.data.logo_url[0].url
  36. that.setData({ logo })
  37. }
  38. wx.setStorage({ key: "config", data: res.data })
  39. }
  40. },
  41. // 监听用户是否登录
  42. searchOpenid: async function () {
  43. wx.login({
  44. success: async (arr) => {
  45. const { code: js_code } = arr;
  46. const { wx_config } = app.globalData;
  47. const aee = await app.$api('token/app', 'GET', { js_code: js_code, config: wx_config.config });
  48. if (aee.errcode == '0') {
  49. wx.setStorage({ key: "openid", data: aee.data.openid })
  50. wx.redirectTo({ url: '/pagesHome/home/index' })
  51. } else {
  52. wx.showToast({ title: `${aee.errmsg}`, icon: 'none' });
  53. }
  54. // wx.getStorage({
  55. // key: 'openid',
  56. // success(res) {
  57. // if (res.data) wx.redirectTo({ url: '/pagesHome/home/index' })
  58. // },
  59. // async fail(err) {
  60. // const aee = await app.$api('token/app', 'GET', { js_code: js_code, config: wx_config.config });
  61. // if (aee.errcode == '0') {
  62. // wx.setStorage({ key: "openid", data: aee.data.openid })
  63. // wx.redirectTo({ url: '/pagesHome/home/index' })
  64. // } else {
  65. // wx.showToast({ title: `${aee.errmsg}`, icon: 'none' });
  66. // }
  67. // }
  68. // })
  69. },
  70. });
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide() {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload() {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh() {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom() {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage() {
  96. }
  97. })