NewsType1.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div>
  3. <div style="width: 1200px;padding: 20px;margin: 0 auto;">
  4. <a-breadcrumb>
  5. <a-breadcrumb-item><a href="/index">首页</a></a-breadcrumb-item>
  6. <a-breadcrumb-item v-if="ismeunName">{{ismeunName}}</a-breadcrumb-item>
  7. <a-breadcrumb-item>详情</a-breadcrumb-item>
  8. </a-breadcrumb>
  9. </div>
  10. <div class="indexMain">
  11. <!-- 直接展示富文本 -->
  12. <div style="width: 100%;" v-if="!showVideo">
  13. <div v-if="title">
  14. <div class="fwbtitle">{{ title }}</div>
  15. <div class="fwbtitle2">
  16. {{ ArticleDetail.columnIdName }}
  17. {{ ArticleDetail.time }}
  18. </div>
  19. </div>
  20. <div v-html="newsHtml" class="right">
  21. </div>
  22. </div>
  23. <!-- 展示视频详情页 -->
  24. <div style="width: 100%;" v-else>
  25. <div class="nether">
  26. <div class="nether_left">
  27. <div v-if="videoInfo" class="left_title">
  28. <div class="left_title_1">{{videoInfo.title}}</div>
  29. <div class="left_title_2">
  30. <div>{{ ArticleDetail.columnIdName }}</div>
  31. <div>{{videoInfo.time}}</div>
  32. <div>{{videoInfo.readNum}}次播放</div>
  33. </div>
  34. </div>
  35. <div class="videoBox">
  36. <video id="myVideo" v-if="videoUrl!=''" style="height:100%;width: 100%;" controls>
  37. <source :src="videoUrl"
  38. type="video/mp4">
  39. <source :src="videoUrl" type="video/ogg">
  40. 您的浏览器不支持 HTML5 video 标签。
  41. </video>
  42. </div>
  43. <div>
  44. <CommentList />
  45. </div>
  46. </div>
  47. <div class="nether_right">
  48. <div class="fontsw">更多推荐</div>
  49. <a-divider />
  50. <div @click="openDetail(item)" class="nether_right_item" v-for="(item,index) in imglist" :key="index">
  51. <div><img class="nether_right_img" :src="item.coverList[0].fileUrl" alt=""></div>
  52. <div class="nether_right_text">{{ item.title }}</div>
  53. <div class="nether_right_text">{{ item.subTitle }}</div>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </template>
  61. <script setup>
  62. import { ref,onMounted, watch } from "vue";
  63. import {getMenuDetailByOpen,
  64. getArticleDetailByOpen,
  65. saveReadArticleNum,
  66. relatedArticles} from '@/http/api/common.js'
  67. import CommentList from './base/comment-list.vue'
  68. //定义路由
  69. import {useRouter,useRoute} from 'vue-router'
  70. const router=useRouter()
  71. const route=useRoute()
  72. //使用pinia缓存数据
  73. import { useCounterStore } from '@/stores/counter'
  74. const counter = useCounterStore()
  75. const ismeunName = ref('')
  76. const newsHtml = ref('请稍后')
  77. const showVideo = ref(false)
  78. const imglist = ref([])
  79. const data = ref(null)
  80. const title = ref('')
  81. const videoInfo = ref('')
  82. const videoUrl = ref('')
  83. watch(()=>counter.menuName,(newVal)=>{
  84. ismeunName.value = newVal
  85. })
  86. watch(
  87. () => route.query,
  88. async(routeQuery) => {
  89. if (routeQuery?.ismeun == '1') {
  90. //如果是从导航栏过来的
  91. let res = await getMenuDetailByOpen({
  92. id:route?.query?.muenId
  93. })
  94. title.value = ''
  95. newsHtml.value = res.data.content
  96. }else{
  97. //判断打开的是富文本还是视频详情页
  98. //bodyType 正文类型1=富文本;2=视频;3=xxx 4取counter中数据
  99. if (route?.query?.bodyType == '4') {
  100. newsHtml.value = counter.detailsContent
  101. } else {
  102. showVideo.value = route?.query?.bodyType == '1'? false:true
  103. //添加阅读记录
  104. await saveReadArticleNum({
  105. id:route?.query?.id
  106. })
  107. //获取文章详情
  108. let res = await getArticleDetailByOpen({
  109. id:route?.query?.id
  110. })
  111. ArticleDetail.value = res.data
  112. console.log('videoUrl',videoUrl.value);
  113. if (!showVideo.value) {
  114. // 如果是富文本 获取内容和标题
  115. newsHtml.value = res.data.content
  116. title.value = res.data.title
  117. }else{
  118. videoInfo.value = res.data
  119. //视频
  120. videoUrl.value = res.data.videoList[0].fileUrl
  121. document.getElementById("myVideo").load();
  122. }
  123. await getrelatedArticles(res.data.subId)
  124. }
  125. }
  126. }
  127. )
  128. const ArticleDetail = ref({
  129. time:'',
  130. columnIdName:''
  131. })
  132. const getrelatedArticles = async(id) =>{
  133. let res = await relatedArticles({
  134. "pageNum": 1,
  135. "pageSize": 3,
  136. "subId": id
  137. })
  138. imglist.value = res.data.rows
  139. }
  140. onMounted(async() => {
  141. ismeunName.value = counter.menuName
  142. // console.log(route.query);
  143. if (route?.query?.ismeun == '1') {
  144. //如果是从导航栏过来的
  145. let res = await getMenuDetailByOpen({
  146. id:route?.query?.muenId
  147. })
  148. newsHtml.value = res.data.content
  149. return
  150. }
  151. //判断打开的是富文本还是视频详情页
  152. //bodyType 正文类型1=富文本;2=视频;3=xxx 4取counter中数据
  153. if (route?.query?.bodyType == '4') {
  154. newsHtml.value = counter.detailsContent
  155. } else {
  156. showVideo.value = route?.query?.bodyType == '1'? false:true
  157. //添加阅读记录
  158. await saveReadArticleNum({
  159. id:route?.query?.id
  160. })
  161. //获取文章详情
  162. let res = await getArticleDetailByOpen({
  163. id:route?.query?.id
  164. })
  165. ArticleDetail.value = res.data
  166. if (!showVideo.value) {
  167. // 如果是富文本 获取内容和标题
  168. newsHtml.value = res.data.content
  169. title.value = res.data.title
  170. }else{
  171. videoInfo.value = res.data
  172. //视频
  173. videoUrl.value = res.data.videoList[0].fileUrl
  174. }
  175. await getrelatedArticles(res.data.subId)
  176. }
  177. });
  178. function openDetail (e){
  179. //回到顶部
  180. const targetElement = document.getElementById('top');
  181. if (targetElement) {
  182. targetElement.scrollIntoView();
  183. }
  184. //bodyType 正文类型1=富文本;2=视频;3=xxx
  185. router.push({
  186. path:'/CompanyNews',
  187. query:{
  188. openType:'1',
  189. bodyType:route?.query?.bodyType,
  190. id:e.id
  191. }
  192. })
  193. }
  194. </script>
  195. <style scoped>
  196. .indexMain{
  197. width: 1200px;
  198. margin: 0 auto;
  199. padding: 20px;
  200. display: flex;
  201. background-color: #fff;
  202. min-height: 300px;
  203. overflow: auto;
  204. flex-direction: column;
  205. }
  206. .right{
  207. margin-top: 20px;
  208. }
  209. /* .right >>> img{
  210. width: 100%;
  211. height: auto;
  212. } */
  213. .fwbtitle{
  214. font-size: 28px;
  215. text-align: left;
  216. font-weight: bold;
  217. /* height: 60px; */
  218. line-height: 60px;
  219. }
  220. .fwbtitle2{
  221. font-size: 16px;
  222. text-align: left;
  223. color: #999;
  224. height: 40px;
  225. line-height: 40px;
  226. }
  227. .nether{
  228. margin-top: 20px;
  229. display: flex;
  230. }
  231. .nether_left{
  232. width: 75%;
  233. background-color: #fff;
  234. }
  235. .nether_right{
  236. margin-left: 50px;
  237. width: 19%;
  238. background-color: #fff;
  239. }
  240. .nether_right_item{
  241. display: flex;
  242. flex-direction: column;
  243. align-items: center;
  244. margin: 5px;
  245. }
  246. .nether_right_text{
  247. cursor: pointer;
  248. }
  249. .nether_right_img{
  250. width: 100%;
  251. height: 180px;
  252. }
  253. .videoBox{
  254. width: 100%;
  255. height: 450px;
  256. background-color: #000;
  257. text-align: center
  258. }
  259. .left_title_1{
  260. font-size: 24px;
  261. }
  262. .left_title_2{
  263. display: flex;
  264. color: #999090;
  265. width: 300px;
  266. justify-content: space-between;
  267. margin: 10px 0;
  268. }
  269. </style>