index.js 2.6 KB

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