detail.vue 7.1 KB

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