index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.getStorage({
  47. key: 'token',
  48. success: async res => {
  49. wx.redirectTo({ url: '/pagesHome/home/index' })
  50. },
  51. fail: res => {
  52. return wx.redirectTo({ url: '/pagesCommon/login/index' })
  53. }
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide() {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload() {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh() {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom() {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage() {
  80. }
  81. })