detail.vue 7.0 KB

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