index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // index.js
  2. let myPro = require("../../utils/wxRequest.js");
  3. let util = require("../../utils/util.js");
  4. Page({
  5. data: {
  6. id: '',
  7. htmlSnip: ''
  8. },
  9. onLoad: function (options) {
  10. // Do some initialize when page load.
  11. let that = this;
  12. that.setData({
  13. id: options.id
  14. });
  15. },
  16. onShow: function () {
  17. // Do something when page show.
  18. let that = this;
  19. that.getContent();
  20. },
  21. onReady: function () {
  22. // Do something when page ready.
  23. },
  24. onHide: function () {
  25. // Do something when page hide.
  26. },
  27. onUnload: function () {
  28. // Do something when page close.
  29. },
  30. onPullDownRefresh: function () {
  31. // Do something when pull down.
  32. },
  33. onReachBottom: function () {
  34. // Do something when page reach bottom.
  35. },
  36. onPageScroll: function () {
  37. // Do something when page scroll
  38. },
  39. onResize: function () {
  40. // Do something when page resize
  41. },
  42. // 获取单页内容
  43. getContent(){
  44. let that = this;
  45. let params = {
  46. id: that.data.id
  47. };
  48. myPro.wxRequest("user/v3/article/detail","GET",params).then(res=>{
  49. let contents = res.result.content;
  50. // 小程序内置,转富文本标签,仅对rich-text 中的 class 生效
  51. contents = contents.replace(/\<img /g, '<img class="richimg" ');
  52. // contents = contents.replace(/\<img src\=\"\/upload/g, '<img class="richimg" src="'+ that.data.domain +'upload');
  53. contents = contents.replace(/\<p/g, '<p class="richtxt" ');
  54. contents = contents.replace(/\<br\>/g, '')
  55. that.setData({
  56. htmlSnip: contents
  57. });
  58. }).catch(err=>{
  59. console.log('报错信息',err);
  60. wx.showToast({
  61. title: err,
  62. icon: "none"
  63. })
  64. })
  65. }
  66. });