notice_deatil.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view>
  3. <artical-deatil :model="model"></artical-deatil>
  4. <view class="closure-font" v-if="enClosureList.length">
  5. 附件:
  6. </view>
  7. <view class="enClosure-box" v-for="(item,index) in enClosureList" :key="item.id">
  8. <view @click="showEnclosure(item.url)">{{index + 1}}.{{item.name}}</view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import md5 from "@/common/md5.js";
  14. import ArticalDeatil from "../../components/artical-deatil/index";
  15. export default {
  16. data() {
  17. return {
  18. model: {
  19. title: "",
  20. way: "",
  21. time: "",
  22. artical: "",
  23. id: "",
  24. },
  25. enClosureList:[],
  26. shareUrl:getApp().globalData.shareUrl
  27. };
  28. },
  29. components: {
  30. ArticalDeatil,
  31. },
  32. onLoad(op) {
  33. this.model.id = op.id;
  34. this.getNotice();
  35. },
  36. methods: {
  37. getNotice() {
  38. let md5Sign = md5(
  39. "method=" +
  40. "common" +
  41. "&timestamp=" +
  42. getApp().globalData.globalTimestamp +
  43. "&secret=" +
  44. getApp().globalData.secret
  45. );
  46. let url =
  47. getApp().globalData.shareUrl +
  48. "api/api.php" +
  49. "?method=common&source=notice&action=info_by_id&timestamp=" +
  50. getApp().globalData.globalTimestamp +
  51. "&sign=" +
  52. md5Sign;
  53. let postData = {
  54. id: this.model.id,
  55. };
  56. //获取文章
  57. uni.request({
  58. url: url,
  59. method: "POST",
  60. header: {
  61. "content-type": "application/x-www-form-urlencoded",
  62. },
  63. data: postData,
  64. success: (res) => {
  65. if (res.data.code === 200) {
  66. let data = res.data.data;
  67. this.model.title = data.title;
  68. this.model.way = data.sponsor;
  69. let time = this.$options.filters["globalTime"](data.publish_time);
  70. let timeSecond = this.$options.filters["globalTimeSecond"](
  71. data.publish_time
  72. );
  73. this.model.time = time + " " + timeSecond;
  74. this.getRich();
  75. if(data.attach_ids){
  76. this.getEnclosure(data.attach_ids)
  77. }
  78. }
  79. },
  80. fail: () => {
  81. console.log("连接失败");
  82. },
  83. });
  84. },
  85. showEnclosure(url){
  86. uni.showLoading({
  87. title:'加载中...'
  88. })
  89. let urls = this.shareUrl + url;
  90. uni.downloadFile({
  91. url: urls,
  92. success: function (res) {
  93. var filePath = res.tempFilePath;
  94. uni.openDocument({
  95. filePath: filePath,
  96. showMenu: true,
  97. success: function (res) {
  98. uni.hideLoading();
  99. }
  100. });
  101. }
  102. });
  103. },
  104. getEnclosure(athId){
  105. let md5Sign = md5(
  106. "method=" +"common" +"&timestamp=" + getApp().globalData.globalTimestamp +"&secret=" +getApp().globalData.secret
  107. );
  108. let url =
  109. getApp().globalData.shareUrl + "api/api.php" +"?method=common&action=attach_ids&timestamp=" +
  110. getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
  111. let postData = {
  112. attach_ids: athId,
  113. };
  114. //获取文章
  115. uni.request({
  116. url: url,
  117. method: "POST",
  118. header: {
  119. "content-type": "application/x-www-form-urlencoded",
  120. },
  121. data: postData,
  122. success: (res) => {
  123. if (res.data.code === 200) {
  124. this.enClosureList = res.data.data;
  125. }
  126. },
  127. fail: () => {
  128. console.log("连接失败");
  129. },
  130. });
  131. },
  132. replaceImg(html) {
  133. let result = html.replace(
  134. /<img [^>]*src=['"]([^'"]+)[^>]*>/gi,
  135. function (match, capture) {
  136. if(capture.includes('http')){
  137. return (
  138. "<img src=" +
  139. capture +
  140. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  141. );
  142. }else {
  143. return (
  144. "<img src=" +
  145. getApp().globalData.shareUrl +
  146. capture +
  147. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  148. );
  149. }
  150. }
  151. );
  152. return result;
  153. },
  154. getRich() {
  155. uni.request({
  156. url:getApp().globalData.shareUrl + `content/notice/${Math.floor(this.model.id / 1000)}/${this.model.id}.html`+'?version='+ Math.random(),
  157. method: "GET",
  158. header: {
  159. "content-type": "application/x-www-form-urlencoded",
  160. },
  161. success: (res) => {
  162. if (res.statusCode === 200) {
  163. this.model.artical = this.replaceImg(res.data);
  164. }
  165. },
  166. fail: () => {
  167. console.log("连接失败");
  168. },
  169. });
  170. },
  171. },
  172. };
  173. </script>
  174. <style lang="scss" scoped>
  175. .closure-font {
  176. font-size: 28rpx;
  177. padding-left: 40rpx;
  178. margin-bottom: 20rpx;
  179. }
  180. .enClosure-box {
  181. width: 100%;
  182. display: flex;
  183. flex-direction: column;
  184. font-size: 26rpx;
  185. padding-left: 40rpx;
  186. color: cornflowerblue;
  187. cursor: pointer;
  188. margin-bottom: 20rpx;
  189. }
  190. </style>