detail.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. uni.openDocument({
  81. showMenu: true,
  82. filePath: res.savedFilePath,
  83. success: function (res) {
  84. console.log("res", res);
  85. },
  86. fail: function (error) {
  87. console.log(error);
  88. wx.previewImage({
  89. current: "", // 当前显示图片的http链接
  90. urls: [url], // 需要预览的图片http链接列表
  91. });
  92. },
  93. });
  94. },
  95. });
  96. }
  97. },
  98. fail: (err) => {
  99. uni.showToast({
  100. title: "失败请重新下载",
  101. });
  102. },
  103. });
  104. },
  105. selectById() {
  106. const _this = this;
  107. getParkNoticeById({ id: _this.id }).then((res) => {
  108. const data = res;
  109. _this.title = data.noticeTitle;
  110. _this.createUserDept = data.createUserDept;
  111. // if (
  112. // data.content.indexOf("width") !== -1 &&
  113. // data.content.indexOf("height") !== -1
  114. // ) {
  115. // _this.content = data.noticeContent
  116. // .replace(/width="(\S*)"/, 'width="100%"')
  117. // .replace(/height="(\S*)"/, 'height="100%"');
  118. // }
  119. let content = data.noticeContent;
  120. content = content.replaceAll(`<figure class="image">`, "");
  121. content = content.replaceAll(`</figure>`, "");
  122. content = content.replaceAll(
  123. "<img",
  124. `<img style="max-width:100%;height:auto"`
  125. );
  126. this.content = content;
  127. _this.releaseTime = _this.publishDate;
  128. if (data.noticeFileId && data.noticeFileId.length > 2) {
  129. const themeUrlList = [];
  130. const imgUrlList = [];
  131. const files = data.noticeFileId;
  132. console.log("files", files);
  133. // files.forEach((item) => {
  134. // if (item.url) {
  135. // const ul = {
  136. // name: item.name,
  137. // url: item.url,
  138. // };
  139. // if (
  140. // item.name.indexOf("png") > -1 ||
  141. // item.name.indexOf("jpg") > -1 ||
  142. // item.name.indexOf("jpeg") > -1
  143. // ) {
  144. // imgUrlList.push(ul);
  145. // } else {
  146. // themeUrlList.push(ul);
  147. // }
  148. // }
  149. // });
  150. if (imgUrlList.length > 0) {
  151. _this.imgUrlList = imgUrlList;
  152. }
  153. _this.fileUrlList = themeUrlList;
  154. }
  155. this.fileUrlList = JSON.parse(data.noticeFileId);
  156. console.log(this.fileUrlList);
  157. // 添加用户通知
  158. // const params = {
  159. // userId: auth.currUser().id,
  160. // noticeId: _this.id,
  161. // type: '1'
  162. // }
  163. // addUserNotice(params).then((res) => {
  164. //
  165. // })
  166. });
  167. },
  168. },
  169. };
  170. </script>
  171. <style lang="scss" type="text/scss">
  172. .detail {
  173. box-sizing: border-box;
  174. background-color: #f2f2f2;
  175. padding: 20rpx 30rpx 140rpx;
  176. overflow-y: auto;
  177. .detail-body {
  178. .detail-card {
  179. display: flex;
  180. align-items: center;
  181. font-size: 24rpx;
  182. padding: 20rpx 30rpx;
  183. border-radius: 10rpx;
  184. &:first-child {
  185. margin-bottom: 20rpx;
  186. }
  187. }
  188. .info {
  189. font-size: 24rpx;
  190. color: #333333;
  191. line-height: 1.2;
  192. }
  193. }
  194. }
  195. .detail-card {
  196. img {
  197. width: 80vw !important;
  198. }
  199. }
  200. </style>
  201. <style scoped lang="scss">
  202. .detail-card {
  203. position: relative;
  204. left: 0;
  205. top: 0;
  206. box-sizing: border-box;
  207. border: 1px solid rgba(242, 242, 242, 1);
  208. background: rgba(255, 255, 255, 1);
  209. .card-body {
  210. padding: 10px 30px;
  211. }
  212. }
  213. </style>