index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. const aee = await app.$api('token/app', 'GET', { js_code: js_code, config: wx_config.config });
  57. if (aee.errcode == '0') {
  58. wx.setStorage({ key: "openid", data: aee.data.openid })
  59. wx.redirectTo({ url: '/pagesCommon/login/index' })
  60. } else {
  61. wx.showToast({ title: `${aee.errmsg}`, icon: 'none' });
  62. }
  63. }
  64. })
  65. },
  66. });
  67. },
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide() {
  72. },
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload() {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh() {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom() {
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage() {
  92. }
  93. })