detail.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="detail">
  3. <div class="detail-body">
  4. <div class="detail-card top-tit-card">
  5. <div class="left">
  6. <van-icon
  7. name="bell"
  8. style="font-size: 6.4vw; color: #60f"
  9. custom-class="iconfont"
  10. />
  11. </div>
  12. <div class="right">
  13. <div class="top">
  14. {{ title }}
  15. </div>
  16. <div class="bottom">
  17. <span> {{ releaseTime }}</span>
  18. <span>{{ createUserDept }}</span>
  19. </div>
  20. </div>
  21. <div></div>
  22. </div>
  23. <div class="detail-card info" v-html="content"></div>
  24. <div
  25. style="width: 100%; height: 100%"
  26. class="img-list"
  27. v-if="imgUrlList.length > 0"
  28. >
  29. <img
  30. style="width: 100%; height: 100%"
  31. v-for="item in imgUrlList"
  32. :src="item.url"
  33. alt=""
  34. />
  35. </div>
  36. <div
  37. v-for="item in fileUrlList"
  38. style="font-size: 16px; margin: 10rpx; color: #0000ff"
  39. @click="jumpFile(item.url)"
  40. >
  41. {{ item.name }}
  42. </div>
  43. </div>
  44. <!-- <div class="white-bottom"></div>-->
  45. </div>
  46. </template>
  47. <script>
  48. import { getParkNoticeById, updateReadStatus } from "@/js_sdk/api_park_notice";
  49. // import { addUserNotice } from "@/service/api_user_notice";
  50. // import auth from "@/service/auth";
  51. // import wx from "weixin-js-sdk";
  52. export default {
  53. data() {
  54. return {
  55. type: "", // 1 园区 2 物业
  56. id: "",
  57. title: "",
  58. readStatus: "",
  59. content: null,
  60. releaseTime: "",
  61. parkName: "",
  62. fileUrlList: [],
  63. imgUrlList: [],
  64. createUserDept: "",
  65. reader: {
  66. // companyId: auth.currUser().id,
  67. id: "",
  68. },
  69. };
  70. },
  71. onLoad(option) {
  72. this.readStatus = option.readStatus;
  73. this.id = option.id;
  74. this.reader.id = this.id;
  75. this.selectById();
  76. if (this.readStatus === "0") {
  77. this.getRead();
  78. }
  79. },
  80. methods: {
  81. getRead() {
  82. updateReadStatus(this.reader).then((res) => {});
  83. },
  84. jumpFile(url) {
  85. uni.downloadFile({
  86. url: url, // 网络文档地址
  87. success: (data) => {
  88. if (data.statusCode === 200) {
  89. uni.saveFile({
  90. tempFilePath: data.tempFilePath, //临时路径
  91. success: function (res) {
  92. // 保存路径
  93. console.log(res);
  94. setTimeout(() => {
  95. //打开文档查看
  96. uni.openDocument({
  97. filePath: res.savedFilePath,
  98. success: function (res) {
  99. console.log("res", res);
  100. },
  101. fail: function (error) {
  102. console.log(error);
  103. wx.previewImage({
  104. current: "", // 当前显示图片的http链接
  105. urls: [url], // 需要预览的图片http链接列表
  106. });
  107. },
  108. });
  109. }, 3000);
  110. },
  111. });
  112. }
  113. },
  114. fail: (err) => {
  115. uni.showToast({
  116. title: "失败请重新下载",
  117. });
  118. },
  119. });
  120. },
  121. selectById() {
  122. const _this = this;
  123. getParkNoticeById({ id: _this.id }).then((res) => {
  124. const data = res;
  125. _this.title = data.noticeTitle;
  126. _this.createUserDept = data.createUserDept;
  127. // if (
  128. // data.content.indexOf("width") !== -1 &&
  129. // data.content.indexOf("height") !== -1
  130. // ) {
  131. // _this.content = data.noticeContent
  132. // .replace(/width="(\S*)"/, 'width="100%"')
  133. // .replace(/height="(\S*)"/, 'height="100%"');
  134. // }
  135. let content = data.noticeContent;
  136. content = content.replaceAll(`<figure class="image">`, "");
  137. content = content.replaceAll(`</figure>`, "");
  138. content = content.replaceAll(
  139. "<img",
  140. `<img style="max-width:100%;height:auto"`
  141. );
  142. this.content = content;
  143. _this.releaseTime = _this.publishDate;
  144. if (data.noticeFileId && data.noticeFileId.length > 2) {
  145. const themeUrlList = [];
  146. const imgUrlList = [];
  147. const files = data.noticeFileId;
  148. console.log("files", files);
  149. // files.forEach((item) => {
  150. // if (item.url) {
  151. // const ul = {
  152. // name: item.name,
  153. // url: item.url,
  154. // };
  155. // if (
  156. // item.name.indexOf("png") > -1 ||
  157. // item.name.indexOf("jpg") > -1 ||
  158. // item.name.indexOf("jpeg") > -1
  159. // ) {
  160. // imgUrlList.push(ul);
  161. // } else {
  162. // themeUrlList.push(ul);
  163. // }
  164. // }
  165. // });
  166. if (imgUrlList.length > 0) {
  167. _this.imgUrlList = imgUrlList;
  168. }
  169. _this.fileUrlList = themeUrlList;
  170. }
  171. this.fileUrlList = JSON.parse(data.noticeFileId);
  172. console.log(this.fileUrlList);
  173. // 添加用户通知
  174. // const params = {
  175. // userId: auth.currUser().id,
  176. // noticeId: _this.id,
  177. // type: '1'
  178. // }
  179. // addUserNotice(params).then((res) => {
  180. //
  181. // })
  182. });
  183. },
  184. },
  185. };
  186. </script>
  187. <style lang="scss" type="text/scss">
  188. .detail {
  189. box-sizing: border-box;
  190. background-color: #f2f2f2;
  191. padding: 20rpx 30rpx 140rpx;
  192. overflow-y: auto;
  193. .detail-body {
  194. .detail-card {
  195. display: flex;
  196. align-items: center;
  197. font-size: 24rpx;
  198. padding: 20rpx 30rpx;
  199. border-radius: 10rpx;
  200. &:first-child {
  201. margin-bottom: 20rpx;
  202. }
  203. }
  204. .info {
  205. font-size: 24rpx;
  206. color: #333333;
  207. line-height: 1.2;
  208. }
  209. }
  210. }
  211. .detail-card {
  212. img {
  213. width: 80vw !important;
  214. }
  215. }
  216. </style>
  217. <style scoped lang="scss">
  218. .detail-card {
  219. position: relative;
  220. left: 0;
  221. top: 0;
  222. box-sizing: border-box;
  223. border: 1px solid rgba(242, 242, 242, 1);
  224. background: rgba(255, 255, 255, 1);
  225. .card-body {
  226. padding: 10px 30px;
  227. }
  228. }
  229. </style>