mess.js 3.2 KB

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