detail.vue 6.1 KB

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