notice_deatil.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view>
  3. <artical-deatil :model="model" :enclosureIds="enclosureId"></artical-deatil>
  4. </view>
  5. </template>
  6. <script>
  7. import md5 from "@/common/md5.js";
  8. import ArticalDeatil from "../../components/artical-deatil/index";
  9. export default {
  10. data() {
  11. return {
  12. model: {
  13. title: "",
  14. way: "",
  15. time: "",
  16. artical: "",
  17. id: "",
  18. },
  19. enclosureId:'',
  20. };
  21. },
  22. components: {
  23. ArticalDeatil,
  24. },
  25. onLoad(op) {
  26. this.model.id = op.id;
  27. this.getNotice();
  28. },
  29. methods: {
  30. getNotice() {
  31. let md5Sign = md5(
  32. "method=" +
  33. "common" +
  34. "&timestamp=" +
  35. getApp().globalData.globalTimestamp +
  36. "&secret=" +
  37. getApp().globalData.secret
  38. );
  39. let url =
  40. getApp().globalData.shareUrl +
  41. "api/api.php" +
  42. "?method=common&source=notice&action=info_by_id&timestamp=" +
  43. getApp().globalData.globalTimestamp +
  44. "&sign=" +
  45. md5Sign;
  46. let postData = {
  47. id: this.model.id,
  48. };
  49. //获取文章
  50. uni.request({
  51. url: url,
  52. method: "POST",
  53. header: {
  54. "content-type": "application/x-www-form-urlencoded",
  55. },
  56. data: postData,
  57. success: (res) => {
  58. if (res.data.code === 200) {
  59. let data = res.data.data;
  60. this.model.title = data.title;
  61. this.model.way = data.sponsor;
  62. this.enclosureId = data.attach_ids;
  63. console.log(this.enclosureId)
  64. let time = this.$options.filters["globalTime"](data.publish_time);
  65. let timeSecond = this.$options.filters["globalTimeSecond"](
  66. data.publish_time
  67. );
  68. this.model.time = time + " " + timeSecond;
  69. this.getRich();
  70. }
  71. },
  72. fail: () => {
  73. console.log("连接失败");
  74. },
  75. });
  76. },
  77. replaceImg(html) {
  78. let result = html.replace(
  79. /<img [^>]*src=['"]([^'"]+)[^>]*>/gi,
  80. function (match, capture) {
  81. if(capture.includes('http')){
  82. return (
  83. "<img src=" +
  84. capture +
  85. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  86. );
  87. }else {
  88. return (
  89. "<img src=" +
  90. getApp().globalData.shareUrl +
  91. capture +
  92. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  93. );
  94. }
  95. }
  96. );
  97. return result;
  98. },
  99. getRich() {
  100. uni.request({
  101. url:getApp().globalData.shareUrl + `content/notice/${Math.floor(this.model.id / 1000)}/${this.model.id}.html`+'?version='+ Math.random(),
  102. method: "GET",
  103. header: {
  104. "content-type": "application/x-www-form-urlencoded",
  105. },
  106. success: (res) => {
  107. if (res.statusCode === 200) {
  108. this.model.artical = this.replaceImg(res.data);
  109. }
  110. },
  111. fail: () => {
  112. console.log("连接失败");
  113. },
  114. });
  115. },
  116. },
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. </style>