index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const app = getApp()
  2. import { examine_status } from '../../utils/dict';
  3. import WxValidate from '../../utils/wxValidate';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '话题', leftArrow: false, useBar: true },
  10. searchInfo: {},
  11. list: [],
  12. },
  13. // 跳转菜单
  14. tabPath(e) {
  15. let { route } = e.detail.detail;
  16. if (route) wx.redirectTo({ url: `/${route}` })
  17. },
  18. toJoin(e) {
  19. let { id } = e.currentTarget.dataset;
  20. wx.navigateTo({ url: `/pages/topic/info?id=${id}` })
  21. },
  22. // 跳转菜单
  23. back(e) {
  24. wx.navigateBack({ delta: 1 })
  25. },
  26. // 查询
  27. search: function (e) {
  28. const that = this;
  29. that.setData({ 'searchInfo.title': e.detail.value });
  30. that.watchLogin()
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. const that = this;
  37. that.watchLogin();
  38. },
  39. // 监听用户是否登录
  40. watchLogin: function () {
  41. const that = this;
  42. let searchInfo = that.data.searchInfo;
  43. wx.getStorage({
  44. key: 'user',
  45. success: async (res) => {
  46. let info = { skip: 0, limit: 1000 };
  47. if (searchInfo && searchInfo.title) info.title = searchInfo.title;
  48. const arr = await app.$get(`/newCourt/api/topic`, { ...info });
  49. if (arr.errcode == '0') {
  50. that.setData({ list: arr.data })
  51. }
  52. else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  53. },
  54. fail: async (res) => {
  55. wx.redirectTo({ url: '/pages/index/index' });
  56. },
  57. });
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload: function () {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh: function () {
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. onReachBottom: function () {
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {
  93. }
  94. })