attract_deatil.vue 2.9 KB

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