detail.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: "",
  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. _this.content = data.noticeContent.replaceAll(
  136. "<img",
  137. `<img style="max-width:100%;"`
  138. );
  139. _this.releaseTime = _this.publishDate;
  140. if (data.noticeFileId && data.noticeFileId.length > 2) {
  141. const themeUrlList = [];
  142. const imgUrlList = [];
  143. const files = data.noticeFileId;
  144. console.log("files", files);
  145. // files.forEach((item) => {
  146. // if (item.url) {
  147. // const ul = {
  148. // name: item.name,
  149. // url: item.url,
  150. // };
  151. // if (
  152. // item.name.indexOf("png") > -1 ||
  153. // item.name.indexOf("jpg") > -1 ||
  154. // item.name.indexOf("jpeg") > -1
  155. // ) {
  156. // imgUrlList.push(ul);
  157. // } else {
  158. // themeUrlList.push(ul);
  159. // }
  160. // }
  161. // });
  162. if (imgUrlList.length > 0) {
  163. _this.imgUrlList = imgUrlList;
  164. }
  165. _this.fileUrlList = themeUrlList;
  166. }
  167. this.fileUrlList = JSON.parse(data.noticeFileId);
  168. console.log(this.fileUrlList);
  169. // 添加用户通知
  170. // const params = {
  171. // userId: auth.currUser().id,
  172. // noticeId: _this.id,
  173. // type: '1'
  174. // }
  175. // addUserNotice(params).then((res) => {
  176. //
  177. // })
  178. });
  179. },
  180. },
  181. };
  182. </script>
  183. <style lang="scss" type="text/scss">
  184. .detail {
  185. box-sizing: border-box;
  186. background-color: #f2f2f2;
  187. padding: 20rpx 30rpx 140rpx;
  188. overflow-y: auto;
  189. .detail-body {
  190. .detail-card {
  191. display: flex;
  192. align-items: center;
  193. font-size: 24rpx;
  194. padding: 20rpx 30rpx;
  195. border-radius: 10rpx;
  196. &:first-child {
  197. margin-bottom: 20rpx;
  198. }
  199. }
  200. .info {
  201. font-size: 24rpx;
  202. color: #333333;
  203. line-height: 1.2;
  204. }
  205. }
  206. }
  207. .detail-card {
  208. img {
  209. width: 80vw !important;
  210. }
  211. }
  212. </style>
  213. <style scoped lang="scss">
  214. .detail-card {
  215. position: relative;
  216. left: 0;
  217. top: 0;
  218. box-sizing: border-box;
  219. border: 1px solid rgba(242, 242, 242, 1);
  220. background: rgba(255, 255, 255, 1);
  221. .card-body {
  222. padding: 10px 30px;
  223. }
  224. }
  225. </style>