notice_deatil.vue 2.9 KB

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