index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. },
  55. });
  56. },
  57. /**
  58. * 生命周期函数--监听页面隐藏
  59. */
  60. onHide() {
  61. },
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload() {
  66. },
  67. /**
  68. * 页面相关事件处理函数--监听用户下拉动作
  69. */
  70. onPullDownRefresh() {
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom() {
  76. },
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage() {
  81. }
  82. })