detail.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. <view class="html" v-html="detailData.contents"></view>
  18. <!-- item -->
  19. <view class="itemBg" v-if="itemArr.length != 0">
  20. <view v-for="(item,index) in itemArr" :key="index" class="twoItem"
  21. :class="{grayLine:index < itemArr.length-1}">
  22. <view class="itemLeftView">
  23. <image src="../../static/mobile/icon_fujian.png" mode="" class="img2"></image>
  24. <view class="title" @click="goUrl(item)">{{item.fileName}}</view>
  25. <!-- <a class="title" :href='item.fileUrl'>{{item.fileName}}</a> -->
  26. </view>
  27. </view>
  28. </view>
  29. <view style="display: flex;">
  30. <view class="category">{{detailData.parentName}}</view>
  31. </view>
  32. <view class="gotop" @click="gotoTop">
  33. <image src="../../static/pcimg/btn_top@2x.png" mode="" class="gotopImg"></image>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. id: '',
  42. detailData: {},
  43. couContent: '',
  44. itemArr: [],
  45. userType: '',
  46. }
  47. },
  48. onLoad(opt) {
  49. console.log('opt', opt);
  50. this.id = opt.id
  51. this.getDetailData()
  52. // uni.setNavigationBarTitle({
  53. // title: this.topName
  54. // })
  55. this.userType = uni.getStorageSync("userType");
  56. console.log('userType', this.userType);
  57. },
  58. methods: {
  59. goUrl(item) {
  60. // console.log('item',item);
  61. if (this.userType == 'app') {
  62. uni.navigateTo({
  63. url: 'accessory_app?fileName=' + item.fileName + '&fileUrl=' + item.fileUrl
  64. })
  65. } else {
  66. window.location.href = item.fileUrl
  67. }
  68. },
  69. gotoTop() {
  70. uni.pageScrollTo({
  71. scrollTop: 0,
  72. duration: 300
  73. });
  74. },
  75. getDetailData() {
  76. uni.showLoading({
  77. title: '加载中'
  78. })
  79. let url = '/trainingOpenApi/articleDetail',
  80. params = {
  81. id: this.id,
  82. }
  83. this.$http(url, params, 'GET').then(res => {
  84. uni.hideLoading();
  85. var data = res.data
  86. if(data.linkType==1){
  87. uni.navigateBack({
  88. })
  89. window.location.href =data.linkUrl
  90. }
  91. // 处理 undefined和null转为空白字符串
  92. for (const key in data) {
  93. data[key] = this.$praseStrEmpty(data[key])
  94. }
  95. this.detailData = data
  96. console.log('contents1111', this.detailData.contents);
  97. if (this.detailData.contents) {
  98. var replaceStr = "application/x-shockwave-flash"
  99. this.detailData.contents=this.detailData.contents.replace(new RegExp(replaceStr,'gm'),'video/webm')//(/''/g,"video/webm")
  100. this.detailData.contents=this.detailData.contents.replace(/<embed([\s\w"-=\/\.:;]+)/ig, '<embed style="width: 100%;" $1');
  101. }
  102. if (this.detailData.contents) {
  103. this.detailData.contents = this.detailData.contents.replace(/<iframe([\s\w"-=\/\.:;]+)/ig,
  104. '<iframe style="width: 100%;height:300px;" $1');
  105. }
  106. if (this.detailData.contents) {
  107. this.detailData.contents = this.detailData.contents.replace(
  108. /<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  109. .replace(/<p>/ig, '<p style="font-size: 15px; line-height: 25px;">')
  110. .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
  111. .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
  112. .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
  113. .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
  114. .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');
  115. }
  116. console.log('contents', this.detailData.contents);
  117. this.itemArr = this.detailData.fileList
  118. })
  119. },
  120. back() {
  121. uni.navigateBack({
  122. })
  123. },
  124. // // 下拉刷新 上拉加载更多
  125. // onPullDownRefresh() {
  126. // this.page = 1;
  127. // this.getItemData()
  128. // this.getDetailData()
  129. // setTimeout(function() {
  130. // uni.stopPullDownRefresh();
  131. // }, 1000);
  132. // },
  133. // onReachBottom() {
  134. // this.page++;
  135. // this.getItemData()
  136. // }
  137. }
  138. }
  139. </script>
  140. <style scoped>
  141. .content {
  142. min-height: 100vh;
  143. background-color: #FFFFFF;
  144. padding-top: 88rpx;
  145. padding-bottom: 10rpx;
  146. margin: 0 24rpx;
  147. }
  148. .nav {
  149. position: fixed;
  150. left: 0;
  151. top: 0;
  152. width: 100vw;
  153. height: 88rpx;
  154. background-color: #FFFFFF;
  155. display: flex;
  156. justify-content: space-between;
  157. align-items: center;
  158. z-index: 999;
  159. border-bottom: #eeeeee 2rpx solid;
  160. }
  161. .navTitle {
  162. font-size: 36rpx;
  163. font-weight: bold;
  164. color: #3c3c3c;
  165. text-align: center;
  166. }
  167. .leftView {
  168. width: 30%;
  169. }
  170. .rightView {
  171. width: 30%;
  172. display: flex;
  173. justify-content: flex-end;
  174. padding-right: 24rpx;
  175. }
  176. .rightImg {
  177. width: 40rpx;
  178. height: 40rpx;
  179. }
  180. .top {
  181. background-color: #FFFFFF;
  182. padding-top: 40rpx;
  183. font-weight: bold;
  184. color: #3c3c3c;
  185. font-size: 32rpx;
  186. text-align: left;
  187. }
  188. .time {
  189. font-size: 24rpx;
  190. color: #999999;
  191. padding-top: 15rpx;
  192. padding-bottom: 30rpx;
  193. border-bottom: #EEEEEE 2rpx solid;
  194. }
  195. .html {
  196. padding-top: 18px;
  197. }
  198. .html img {
  199. width: 100% !important;
  200. }
  201. .itemBg {
  202. background-color: #FFFFFF;
  203. border-radius: 10rpx;
  204. border: #eeeeee 1rpx solid;
  205. }
  206. .twoItem {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. background-color: #FFFFFF;
  211. margin: 0 15rpx;
  212. padding-top: 24rpx;
  213. padding-bottom: 30rpx;
  214. }
  215. .grayLine {
  216. border-bottom: #EEEEEE 1rpx solid;
  217. }
  218. .itemLeftView {
  219. display: flex;
  220. align-items: center;
  221. width: 100%;
  222. }
  223. .title {
  224. font-size: 28rpx;
  225. color: #333333;
  226. width: 100%;
  227. word-break: break-all;
  228. text-decoration:underline;
  229. }
  230. .title2 {
  231. background-color: #3F90F7;
  232. border-radius: 6rpx;
  233. width: 90rpx;
  234. height: 52rpx;
  235. line-height: 52rpx;
  236. text-align: center;
  237. margin-right: 15rpx;
  238. }
  239. .table-btn {
  240. color: #FFFFFF;
  241. font-size: 26rpx;
  242. text-decoration: none;
  243. }
  244. .img2 {
  245. width: 28rpx;
  246. height: 28rpx;
  247. margin-right: 6rpx;
  248. }
  249. .category {
  250. background: rgba(63, 144, 247, 0.1);
  251. font-size: 22rpx;
  252. color: #3F90F7;
  253. height: 36rpx;
  254. line-height: 36rpx;
  255. border-radius: 18rpx;
  256. padding: 3rpx 14rpx;
  257. min-width: 0;
  258. max-width: 138rpx;
  259. margin-bottom: 10rpx;
  260. text-align: center;
  261. margin: 30rpx 0;
  262. /* 隐藏文字显示 ...不换行 */
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. white-space: nowrap;
  266. }
  267. .gotopImg {
  268. width: 100rpx;
  269. height: 100rpx;
  270. }
  271. .gotop {
  272. position: fixed;
  273. right: 15rpx;
  274. bottom: 50rpx;
  275. cursor: pointer;
  276. z-index: 999;
  277. }
  278. </style>