info.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '学校信息', leftArrow: true, useBar: false },
  5. id: '',
  6. form: {},
  7. },
  8. // 跳转菜单
  9. back(e) {
  10. wx.navigateBack({ delta: 1 })
  11. },
  12. // 预览
  13. toView: function (e) {
  14. const { item } = e.currentTarget.dataset;
  15. wx.previewImage({
  16. current: '',
  17. urls: [item.url]
  18. })
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. const that = this;
  25. that.setData({ id: options.id || null })
  26. // 监听用户是否登录
  27. that.watchLogin();
  28. },
  29. // 监听用户是否登录
  30. watchLogin: async function () {
  31. const that = this;
  32. wx.getStorage({
  33. key: 'user',
  34. success: async res => {
  35. if (that.data.id) {
  36. const arr = await app.$get(`/school/${that.data.id}`);
  37. if (arr.errcode == '0') {
  38. that.setData({ form: arr.data })
  39. } else {
  40. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  41. }
  42. }
  43. },
  44. fail: async res => {
  45. wx.redirectTo({ url: '/pages/index/index' })
  46. }
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () { },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. }
  81. })