mess.js 3.1 KB

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