detail.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="content">
  3. <!-- 导航 -->
  4. <view class="nav">
  5. <view class="leftView" @click="back">
  6. <image src="../../static/mobile/backBtn.png" mode=""
  7. style="width: 22rpx; height: 40rpx; padding-left: 24rpx;"></image>
  8. </view>
  9. <view class="navTitle">详情</view>
  10. <view class="rightView">
  11. </view>
  12. </view>
  13. <!-- content -->
  14. <view class="commend">
  15. <view class="top">{{detailData.title}}</view>
  16. <view class="time">{{detailData.createTime}}</view>
  17. </view>
  18. <rich-text :nodes="couContent"></rich-text>
  19. <!-- item -->
  20. <view class="itemBg" v-if="itemArr.length != 0">
  21. <view v-for="(item,index) in itemArr" :key="index" class="twoItem"
  22. :class="{grayLine:index < itemArr.length-1}">
  23. <view class="itemLeftView">
  24. <image src="../../static/mobile/icon_fujian.png" mode="" class="img2"></image>
  25. <view class="title">{{item.fileName}}</view>
  26. </view>
  27. <view class="title2">
  28. <a class="table-btn" :href='item.fileUrl' target='_blank'>下载</a>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="category">{{detailData.name}}</view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. id: '',
  40. detailData: {},
  41. couContent: '',
  42. itemArr: [],
  43. }
  44. },
  45. onLoad(opt) {
  46. console.log('opt', opt);
  47. this.id = opt.id
  48. this.getDetailData()
  49. // uni.setNavigationBarTitle({
  50. // title: this.topName
  51. // })
  52. },
  53. methods: {
  54. // 下载文件
  55. downLoad(urlStr) {
  56. console.log('urls', urlStr);
  57. // uni.showLoading({
  58. // title:'下载中'
  59. // })
  60. // let dload = document.createElement("a");
  61. //   dload.download = '';// 设置下载的文件名,默认是'下载'
  62. //   dload.href = urlStr;
  63. //   document.body.appendChild(dload);
  64. //   dload.click();
  65. //   dload.remove(); // 下载之后把创建的元素删除
  66. // window.open(urlStr)
  67. // window.location.href='urlStr'
  68. /*
  69. let url = encodeURI(urlStr); //注意中文文件名的网络地址需要encodeURI
  70. uni.downloadFile({
  71. url: url,
  72. success: (res) => {
  73. if (res.statusCode === 200) {
  74. uni.saveFile({
  75. tempFilePath: res.tempFilePath,
  76. success: (resData) => {
  77. uni.openDocument({
  78. filePath: resData.savedFilePath,
  79. success: (res) => console.log('成功打开文档')
  80. });
  81. console.log('bbb', res);
  82. },
  83. fail() {
  84. console.log('打开失败')
  85. }
  86. });
  87. console.log('aaa', res);
  88. }
  89. },
  90. fail() {
  91. console.log('下载失败')
  92. }
  93. });
  94. */
  95. },
  96. getDetailData() {
  97. uni.showLoading({
  98. title: '加载中'
  99. })
  100. let url = '/trainingOpenApi/articleDetail',
  101. params = {
  102. id: this.id,
  103. }
  104. this.$http(url, params, 'GET').then(res => {
  105. uni.hideLoading();
  106. var data = res.data
  107. // 处理 undefined和null转为空白字符串
  108. for (const key in data) {
  109. data[key] = this.$praseStrEmpty(data[key])
  110. }
  111. this.detailData = data
  112. if (this.detailData.contents) {
  113. this.couContent = this.detailData.contents.replace(
  114. /<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  115. .replace(/<p>/ig, '<p style="font-size: 15px; line-height: 25px;">')
  116. .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
  117. .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
  118. .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
  119. .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
  120. .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');
  121. }
  122. this.itemArr = this.detailData.fileList
  123. })
  124. },
  125. back() {
  126. uni.navigateBack({
  127. })
  128. },
  129. // // 下拉刷新 上拉加载更多
  130. // onPullDownRefresh() {
  131. // this.page = 1;
  132. // this.getItemData()
  133. // this.getDetailData()
  134. // setTimeout(function() {
  135. // uni.stopPullDownRefresh();
  136. // }, 1000);
  137. // },
  138. // onReachBottom() {
  139. // this.page++;
  140. // this.getItemData()
  141. // }
  142. }
  143. }
  144. </script>
  145. <style scoped>
  146. .content {
  147. min-height: 100vh;
  148. background-color: #FFFFFF;
  149. padding-top: 88rpx;
  150. padding-bottom: 10rpx;
  151. margin: 0 24rpx;
  152. }
  153. .nav {
  154. position: fixed;
  155. left: 0;
  156. top: 0;
  157. width: 100vw;
  158. height: 88rpx;
  159. background-color: #FFFFFF;
  160. display: flex;
  161. justify-content: space-between;
  162. align-items: center;
  163. z-index: 999;
  164. border-bottom: #eeeeee 2rpx solid;
  165. }
  166. .navTitle {
  167. font-size: 36rpx;
  168. font-weight: bold;
  169. color: #3c3c3c;
  170. text-align: center;
  171. }
  172. .leftView {
  173. width: 30%;
  174. }
  175. .rightView {
  176. width: 30%;
  177. display: flex;
  178. justify-content: flex-end;
  179. padding-right: 24rpx;
  180. }
  181. .rightImg {
  182. width: 40rpx;
  183. height: 40rpx;
  184. }
  185. .commend {
  186. background-color: #FFFFFF;
  187. padding-bottom: 30rpx;
  188. height: 220rpx;
  189. border-bottom: #EEEEEE 1rpx solid;
  190. }
  191. .top {
  192. padding-top: 40rpx;
  193. text-align: left;
  194. height: 80rpx;
  195. color: #3C3C3C;
  196. font-size: 32rpx;
  197. font-weight: bold;
  198. //超过固定行数 隐藏
  199. display: -webkit-box;
  200. overflow: hidden;
  201. text-overflow: ellipsis;
  202. word-wrap: break-word;
  203. white-space: normal !important;
  204. -webkit-line-clamp: 2;
  205. -webkit-box-orient: vertical;
  206. line-height: 20px;
  207. margin-bottom: 20rpx;
  208. }
  209. .time {
  210. font-size: 24rpx;
  211. color: #999999;
  212. height: 60rpx;
  213. line-height: 60rpx;
  214. }
  215. .itemBg {
  216. background-color: #FFFFFF;
  217. border-radius: 10rpx;
  218. border: #eeeeee 1rpx solid;
  219. }
  220. .twoItem {
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. background-color: #FFFFFF;
  225. margin: 0 15rpx;
  226. padding-top: 24rpx;
  227. padding-bottom: 30rpx;
  228. }
  229. .grayLine {
  230. border-bottom: #EEEEEE 1rpx solid;
  231. }
  232. .itemLeftView {
  233. display: flex;
  234. align-items: center;
  235. width: 80%;
  236. }
  237. .title {
  238. font-size: 28rpx;
  239. color: #333333;
  240. width: 90%;
  241. word-break:break-all;
  242. }
  243. .title2 {
  244. background-color: #3F90F7;
  245. border-radius: 6rpx;
  246. width: 90rpx;
  247. height: 52rpx;
  248. line-height: 52rpx;
  249. text-align: center;
  250. margin-right: 15rpx;
  251. }
  252. .table-btn {
  253. color: #FFFFFF;
  254. font-size: 26rpx;
  255. text-decoration: none;
  256. }
  257. .img2 {
  258. width: 28rpx;
  259. height: 28rpx;
  260. margin-right: 6rpx;
  261. }
  262. .category {
  263. background: rgba(63, 144, 247, 0.1);
  264. font-size: 22rpx;
  265. color: #3F90F7;
  266. height: 36rpx;
  267. line-height: 36rpx;
  268. border-radius: 18rpx;
  269. padding: 3rpx 14rpx;
  270. width: 138rpx;
  271. margin: 30rpx 0;
  272. text-align: center;
  273. /* 隐藏文字显示 ...不换行 */
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. white-space: nowrap;
  277. }
  278. </style>