info.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. id: '',
  10. form: {},
  11. typeList: news_type,
  12. },
  13. // 返回
  14. back: function () {
  15. wx.navigateBack({ delta: 1 })
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. const that = this;
  22. that.setData({ id: options.id || '' })
  23. // 监听用户是否登录
  24. that.watchLogin();
  25. },
  26. // 监听用户是否登录
  27. watchLogin: async function () {
  28. const that = this;
  29. wx.getStorage({
  30. key: 'user',
  31. success: async res => {
  32. if (that.data.id) {
  33. const arr = await app.$get(`/newCourt/api/news/${that.data.id}`);
  34. if (arr.errcode == '0') {
  35. that.setData({ form: arr.data });
  36. let content = arr.data.content.replace(/\<img/gi, '<img style="width:100%;height:auto;margin: 5px 0"');
  37. that.setData({ 'form.content': content });
  38. }
  39. }
  40. },
  41. fail: res => {
  42. wx.redirectTo({ url: '/pages/index/index', })
  43. }
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload: function () {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom: function () {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. }
  81. })