detail.vue 6.7 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="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 = '/trainingOpenApiV2/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. // 处理 undefined和null转为空白字符串
  87. for (const key in data) {
  88. data[key] = this.$praseStrEmpty(data[key])
  89. }
  90. this.detailData = data
  91. console.log('contents1111', this.detailData.contents);
  92. if (this.detailData.contents) {
  93. var replaceStr = "application/x-shockwave-flash"
  94. this.detailData.contents=this.detailData.contents.replace(new RegExp(replaceStr,'gm'),'video/webm')//(/''/g,"video/webm")
  95. this.detailData.contents=this.detailData.contents.replace(/<embed([\s\w"-=\/\.:;]+)/ig, '<embed style="width: 100%;" $1');
  96. }
  97. if (this.detailData.contents) {
  98. this.detailData.contents = this.detailData.contents.replace(/<iframe([\s\w"-=\/\.:;]+)/ig,
  99. '<iframe style="width: 100%;height:300px;" $1');
  100. }
  101. if (this.detailData.contents) {
  102. this.detailData.contents = this.detailData.contents.replace(
  103. /<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  104. .replace(/<p>/ig, '<p style="font-size: 15px; line-height: 25px;">')
  105. .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
  106. .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
  107. .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
  108. .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
  109. .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');
  110. }
  111. console.log('contents', this.detailData.contents);
  112. this.itemArr = this.detailData.fileList
  113. })
  114. },
  115. back() {
  116. uni.navigateBack({
  117. })
  118. },
  119. // // 下拉刷新 上拉加载更多
  120. // onPullDownRefresh() {
  121. // this.page = 1;
  122. // this.getItemData()
  123. // this.getDetailData()
  124. // setTimeout(function() {
  125. // uni.stopPullDownRefresh();
  126. // }, 1000);
  127. // },
  128. // onReachBottom() {
  129. // this.page++;
  130. // this.getItemData()
  131. // }
  132. }
  133. }
  134. </script>
  135. <style scoped>
  136. .content {
  137. min-height: 100vh;
  138. background-color: #FFFFFF;
  139. padding-top: 88rpx;
  140. padding-bottom: 10rpx;
  141. margin: 0 24rpx;
  142. }
  143. .nav {
  144. position: fixed;
  145. left: 0;
  146. top: 0;
  147. width: 100vw;
  148. height: 88rpx;
  149. background-color: #FFFFFF;
  150. display: flex;
  151. justify-content: space-between;
  152. align-items: center;
  153. z-index: 999;
  154. border-bottom: #eeeeee 2rpx solid;
  155. }
  156. .navTitle {
  157. font-size: 36rpx;
  158. font-weight: bold;
  159. color: #3c3c3c;
  160. text-align: center;
  161. }
  162. .leftView {
  163. width: 30%;
  164. }
  165. .rightView {
  166. width: 30%;
  167. display: flex;
  168. justify-content: flex-end;
  169. padding-right: 24rpx;
  170. }
  171. .rightImg {
  172. width: 40rpx;
  173. height: 40rpx;
  174. }
  175. .top {
  176. background-color: #FFFFFF;
  177. padding-top: 40rpx;
  178. font-weight: bold;
  179. color: #3c3c3c;
  180. font-size: 32rpx;
  181. text-align: left;
  182. }
  183. .time {
  184. font-size: 24rpx;
  185. color: #999999;
  186. padding-top: 15rpx;
  187. padding-bottom: 30rpx;
  188. border-bottom: #EEEEEE 2rpx solid;
  189. }
  190. .html {
  191. padding-top: 18px;
  192. }
  193. .html img {
  194. width: 100% !important;
  195. }
  196. .itemBg {
  197. background-color: #FFFFFF;
  198. border-radius: 10rpx;
  199. border: #eeeeee 1rpx solid;
  200. }
  201. .twoItem {
  202. display: flex;
  203. justify-content: space-between;
  204. align-items: center;
  205. background-color: #FFFFFF;
  206. margin: 0 15rpx;
  207. padding-top: 24rpx;
  208. padding-bottom: 30rpx;
  209. }
  210. .grayLine {
  211. border-bottom: #EEEEEE 1rpx solid;
  212. }
  213. .itemLeftView {
  214. display: flex;
  215. align-items: center;
  216. width: 100%;
  217. }
  218. .title {
  219. font-size: 28rpx;
  220. color: #333333;
  221. width: 100%;
  222. word-break: break-all;
  223. text-decoration:underline;
  224. }
  225. .title2 {
  226. background-color: #3F90F7;
  227. border-radius: 6rpx;
  228. width: 90rpx;
  229. height: 52rpx;
  230. line-height: 52rpx;
  231. text-align: center;
  232. margin-right: 15rpx;
  233. }
  234. .table-btn {
  235. color: #FFFFFF;
  236. font-size: 26rpx;
  237. text-decoration: none;
  238. }
  239. .img2 {
  240. width: 28rpx;
  241. height: 28rpx;
  242. margin-right: 6rpx;
  243. }
  244. .category {
  245. background: rgba(63, 144, 247, 0.1);
  246. font-size: 22rpx;
  247. color: #3F90F7;
  248. height: 36rpx;
  249. line-height: 36rpx;
  250. border-radius: 18rpx;
  251. padding: 3rpx 14rpx;
  252. min-width: 0;
  253. max-width: 138rpx;
  254. margin-bottom: 10rpx;
  255. text-align: center;
  256. margin: 30rpx 0;
  257. /* 隐藏文字显示 ...不换行 */
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. white-space: nowrap;
  261. }
  262. .gotopImg {
  263. width: 100rpx;
  264. height: 100rpx;
  265. }
  266. .gotop {
  267. position: fixed;
  268. right: 15rpx;
  269. bottom: 50rpx;
  270. cursor: pointer;
  271. z-index: 999;
  272. }
  273. </style>