attract_deatil.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. return (
  34. "<img src=" +
  35. getApp().globalData.shareUrl +
  36. capture +
  37. ' style="max-width:100%;height:auto;display:block;margin:10px 0;"/>'
  38. );
  39. }
  40. );
  41. return result;
  42. },
  43. getAttractDeatil() {
  44. let md5Sign = md5(
  45. "method=" +
  46. "common" +
  47. "&timestamp=" +
  48. getApp().globalData.globalTimestamp +
  49. "&secret=" +
  50. getApp().globalData.secret
  51. );
  52. let url =
  53. getApp().globalData.shareUrl +
  54. "api/api.php" +
  55. "?method=common&source=business&action=info_by_id&timestamp=" +
  56. getApp().globalData.globalTimestamp +
  57. "&sign=" +
  58. md5Sign;
  59. let postData = {
  60. id: this.model.id,
  61. };
  62. //获取文章
  63. uni.request({
  64. url: url,
  65. method: "POST",
  66. header: {
  67. "content-type": "application/x-www-form-urlencoded",
  68. },
  69. data: postData,
  70. success: (res) => {
  71. // console.log(res);
  72. if (res.data.code === 200) {
  73. let data = res.data.data;
  74. this.model.title = data.title;
  75. let time = this.$options.filters["globalTime"](data.addtime);
  76. let timeSecond = this.$options.filters["globalTimeSecond"](
  77. data.addtime
  78. );
  79. this.model.time = time + " " + timeSecond;
  80. this.getRich();
  81. }
  82. },
  83. fail: () => {
  84. console.log("连接失败");
  85. },
  86. });
  87. },
  88. getRich() {
  89. uni.request({
  90. url:
  91. getApp().globalData.shareUrl +
  92. `content/business/${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. console.log(res);
  101. if (res.statusCode === 200) {
  102. this.model.artical = this.replaceImg(res.data);
  103. }
  104. },
  105. fail: () => {
  106. console.log("连接失败");
  107. },
  108. });
  109. },
  110. },
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. </style>