detail.vue 8.2 KB

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