newDetail.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="content2">
  3. <view style="height: 72px;"></view>
  4. <view class="top">
  5. <view class="topline" @click="goIndex">首页</view>
  6. <view class="topjt">></view>
  7. <view class="topline" :class="{'c999':!twoName}" @click="goList()">{{topName}}</view>
  8. <view class="topjt" v-if="twoName">></view>
  9. <view class="topline" :class="{'c999':twoName}">{{twoName}}</view>
  10. </view>
  11. <view class="htmlBox">
  12. <view class="htmlTitle">{{detailData.name}}</view>
  13. <view class="time">{{detailData.publishTime}}</view>
  14. <view class="html" v-html="detailData.contents"></view>
  15. </view>
  16. <view class="itemArr" v-if="itemArr.length>0">
  17. <view class="itemArrLine" :class="{'itemArrLineBottom':itemArr.length!=(index+1)}" v-for="(item,index) in itemArr">
  18. <view class="itemArrLeft" >
  19. <image src="../../static/pcimg/icon_fujian@2x.png" mode="" class="fileIcon"></image>
  20. <view class="fileName" @click="gofile(item.fileUrl)">{{item.fileName}}</view>
  21. </view>
  22. <!-- <view class="dload">
  23. <a class="dloadbtn" :href="item.fileUrl" target='_blank' >下载</a>
  24. </view> -->
  25. </view>
  26. </view>
  27. <view class="lbel" v-if="topName">
  28. <view class="topName" @click="goList">{{topName}}</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. props: ['newid','data'],
  35. data() {
  36. return {
  37. id: '',
  38. detailData: {},
  39. couContent: '',
  40. itemArr: [],
  41. topName:'',
  42. twoName:'',
  43. comment:'',
  44. parentCode:'',
  45. }
  46. },
  47. watch:{
  48. newid(newValue, oldValue){
  49. console.log(newValue);
  50. console.log(this.data)
  51. this.id = newValue
  52. this.topName=this.data.categoryName;
  53. this.twoName=this.data.twoName;
  54. this.comment=this.data.comment;
  55. this.parentCode=this.data.code
  56. this.getDetailData()
  57. // uni.setNavigationBarTitle({
  58. // title: this.topName
  59. // })
  60. uni.pageScrollTo({
  61.    scrollTop: 0, duration: 100
  62. });
  63. }
  64. },
  65. onLoad(opt) {
  66. console.log('opt', opt);
  67. /* this.id = opt.id
  68. this.topName=opt.topName;
  69. this.twoName=opt.twoName;
  70. this.comment=opt.comment;
  71. this.parentCode=opt.parentCode
  72. this.getDetailData() */
  73. // uni.setNavigationBarTitle({
  74. // title: this.topName
  75. // })
  76. },
  77. created() {
  78. this.newidfn()
  79. },
  80. methods: {
  81. newidfn(){
  82. this.id = this.data.id
  83. this.topName=this.data.categoryName;
  84. this.twoName=this.data.twoName;
  85. this.comment=this.data.comment;
  86. this.parentCode=this.data.code
  87. this.getDetailData()
  88. uni.pageScrollTo({
  89.    scrollTop: 0, duration: 100
  90. });
  91. },
  92. test(){
  93. console.log(55)
  94. },
  95. gofile(url){
  96. window.location.href=url
  97. },
  98. goList(){
  99. /* var code=this.parentCode.substring(0,3)
  100. uni.navigateTo({
  101. url:'list?code='+code+'&topName='+this.topName+'&comment='+this.comment
  102. }) */
  103. console.log(this.parentCode)
  104. var code=this.parentCode.substring(0,3)
  105. var data={
  106. code:code,
  107. name:this.topName,
  108. comment:this.comment
  109. }
  110. this.$emit("getChildList",data)
  111. },
  112. goIndex(){
  113. this.$emit("getIndexList")
  114. },
  115. getDetailData() {
  116. uni.showLoading({
  117. title: '加载中'
  118. })
  119. let url = '/trainingOpenApiV2/articleDetail',
  120. params = {
  121. id: this.id,
  122. }
  123. this.$http(url, params, 'GET').then(res => {
  124. uni.hideLoading();
  125. var data = res.data
  126. // 处理 undefined和null转为空白字符串
  127. for (const key in data) {
  128. data[key] = this.$praseStrEmpty(data[key])
  129. }
  130. this.detailData = data;
  131. uni.setNavigationBarTitle({
  132. title: this.detailData.title
  133. });
  134. console.log()
  135. if (this.detailData.contents) {
  136. var replaceStr = "application/x-shockwave-flash"
  137. this.detailData.contents=this.detailData.contents.replace(new RegExp(replaceStr,'gm'),'video/webm')//(/''/g,"video/webm")
  138. this.detailData.contents=this.detailData.contents.replace(/<embed([\s\w"-=\/\.:;]+)/ig, '<embed style="width: 100%;height:500px;" $1');
  139. }
  140. if (this.detailData.contents) {
  141. this.detailData.contents = this.detailData.contents.replace(
  142. /<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  143. .replace(/<p>/ig, '<p style="font-size: 15px; line-height: 25px;">')
  144. .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
  145. .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
  146. .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
  147. .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
  148. .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');
  149. this.detailData.contents = this.detailData.contents.replace(
  150. /<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  151. .replace(/<p>/ig, '<p style="font-size: 15px; line-height: 25px;">')
  152. .replace(/<iframe([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<iframe$1')
  153. .replace(/<iframe([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<iframe$1')
  154. .replace(/<iframe([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<iframe$1')
  155. .replace(/<iframe([\s\w"-=\/\.:;]+)/ig, '<iframe style="width: 100%;height:500px;" $1');
  156. }
  157. this.itemArr = this.detailData.fileList
  158. console.log(this.itemArr)
  159. })
  160. },
  161. // }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. .top{
  167. width: 1200px;
  168. margin: 0 auto;
  169. display: flex;
  170. padding: 30px 0;
  171. font-size: 14px;
  172. }
  173. .content2{
  174. font-family: PingFangSC-Regular, PingFang SC;background: #FFFFFF;
  175. min-height: 100vh;
  176. }
  177. .htmlBox{
  178. width: 720px;
  179. margin: 0 auto;
  180. }
  181. .topline{
  182. padding-right: 10px;
  183. cursor: pointer;
  184. color: #3C3C3C;
  185. }
  186. .topjt{
  187. color: #AAAAAA;
  188. padding-right: 10px;
  189. }
  190. .htmlTitle{
  191. font-size: 24px;
  192. font-weight: 500;
  193. color: #3C3C3C;
  194. line-height: 33px;
  195. font-family: PingFangSC-Medium, PingFang SC;
  196. }
  197. .time{
  198. font-size: 14px;
  199. padding-top: 16px;
  200. color: #999999;
  201. line-height: 20px;
  202. border-bottom: 1px solid #EEEEEE;
  203. padding-bottom: 19px;
  204. }
  205. .html{
  206. padding-top: 18px;
  207. }
  208. .fileIcon{
  209. width: 14px;
  210. height: 14px;
  211. margin-top: 4px;
  212. margin-right: 4px;
  213. }
  214. .itemArrLeft{
  215. display: flex;
  216. }
  217. .itemArrLine{
  218. display: flex;
  219. justify-content: space-between;
  220. padding: 16px 0;
  221. color: #333333;
  222. line-height: 22px;
  223. font-size: 16px;
  224. width: 720px;
  225. }
  226. .itemArrLineBottom{
  227. border-bottom: 1px solid #EEEEEE;
  228. }
  229. .itemArr{
  230. width: 686px;
  231. margin: 0 auto;
  232. margin-top: 30px;
  233. border-radius: 6px;
  234. border: 1px solid #EEEEEE;
  235. padding: 0 16px;
  236. }
  237. .dloadbtn{
  238. display: block;
  239. width: 68px;
  240. height: 28px;
  241. background: #3F90F7;
  242. border-radius: 6px;
  243. color: #FFFFFF;
  244. text-align: center;
  245. line-height:28px ;
  246. font-size: 14px;
  247. text-decoration:none;
  248. }
  249. .lbel{
  250. width: 720px;
  251. margin: 0 auto;
  252. margin-top: 30px;
  253. padding-bottom: 30px;
  254. display: flex;
  255. }
  256. .topName{
  257. /* width: 84px; */
  258. height: 24px;
  259. background: rgba(63, 144, 247, 0.1);
  260. border-radius: 14px;
  261. font-size: 14px;
  262. color: #3F90F7;
  263. line-height: 24px;
  264. text-align: center;
  265. cursor: pointer;
  266. padding: 0 20rpx;
  267. }
  268. .fileName{
  269. text-decoration:underline;
  270. color: #3F90F7;
  271. }
  272. .c999{
  273. color: #999999;
  274. }
  275. </style>