notice_deatil.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. return (
  79. "<img src=" +
  80. getApp().globalData.shareUrl +
  81. capture +
  82. ' style="max-width:100%;height:auto;display:block;margin:10px 0;"/>'
  83. );
  84. }
  85. );
  86. return result;
  87. },
  88. getRich() {
  89. uni.request({
  90. url:
  91. getApp().globalData.shareUrl +
  92. `content/notice/${Math.floor(this.model.id / 1000)}/${
  93. this.model.id
  94. }.html`,
  95. method: "GET",
  96. header: {
  97. "content-type": "application/x-www-form-urlencoded",
  98. },
  99. success: (res) => {
  100. if (res.statusCode === 200) {
  101. this.model.artical = this.replaceImg(res.data);
  102. }
  103. },
  104. fail: () => {
  105. console.log("连接失败");
  106. },
  107. });
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. </style>