index.js 3.2 KB

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