detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="currentTitleText" />
  4. <uni-loading v-if="loading" />
  5. <view v-else id="News_Content" class="news-content">
  6. <!-- 观点分析 / 新闻资讯 / 公告 / 新闻资讯(通讯) -->
  7. <view class="content crm-border-radius" v-if="[1, 2, 3, 5].includes(type)">
  8. <view class="img" v-if="imgContentIf">
  9. <image :src="imgContent" mode="widthFix" @click="previewImage(imgContent)" />
  10. </view>
  11. <cwg-rich-text :nodes="Content" />
  12. </view>
  13. <!-- 视频评论(WebTV 视频) -->
  14. <view class="content crm-border-radius" v-if="type === 4">
  15. <view class="con-title">{{ info.title }}</view>
  16. <view class="con-time" style="display: flex; justify-content: space-between;">
  17. <text>{{ info.createTime }}</text>
  18. <image src="/static/acc_logo.png" style="height: 80rpx;" mode="heightFix" />
  19. </view>
  20. <view class="my_video" style="width: 100%">
  21. <video :id="`dplayer-${title}`" :src="info.url" controls class="video-player" />
  22. </view>
  23. <text class="con-des">{{ info.description }}</text>
  24. </view>
  25. <!-- 视频评论(另一种) -->
  26. <view class="content crm-border-radius" v-if="type === 6">
  27. <view class="con-title">{{ info.title }}</view>
  28. <text class="con-time">{{ info.subTitle }}</text>
  29. <view class="my_video" style="width: 100%">
  30. <video :id="`dplayer-${type}`" :src="imgContent" controls class="video-player" />
  31. </view>
  32. <view class="rich-text-wrapper">
  33. <cwg-rich-text :nodes="info.content" />
  34. </view>
  35. </view>
  36. <!-- 公告详情 -->
  37. <view class="content crm-border-radius" v-if="type === 7">
  38. <view class="con-title">{{ info.subject }}</view>
  39. <view class="rich-text-wrapper">
  40. <cwg-rich-text :nodes="info.content1" />
  41. </view>
  42. </view>
  43. <!-- 交易观点 / 财经日历(内嵌网页) -->
  44. <view class="content crm-border-radius" v-if="[8, 9].includes(title)">
  45. <web-view :src="imgContent" class="webview" />
  46. </view>
  47. <!-- 电子书 -->
  48. <view class="content crm-border-radius" v-if="type === 10">
  49. <view class="ebookBox">
  50. <image :src="imgUrl + info.coverImage" mode="widthFix" class="ebook-cover" />
  51. <view>
  52. <text class="news-title">{{ info.title }}</text>
  53. <view class="rich-text-wrapper">
  54. <cwg-rich-text :nodes="info.content" />
  55. </view>
  56. <view class="news-status">
  57. <cwg-link type="html" title="blockchain.item12" :url="htmlUrl + info.bookUrl"
  58. target="_blank" />
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 视频评论(iframe 嵌入) -->
  64. <view class="content crm-border-radius" v-if="type === 11">
  65. <view style="display: flex; justify-content: end; margin-bottom: 30rpx;">
  66. <image src="/static/acc_logo.png" style="height: 80rpx;" mode="heightFix" />
  67. </view>
  68. <view style="width: 80%; margin: auto;">
  69. <web-view v-if="isZh" src="https://videos.tradingcentral.cn/players/H5QuTuut-iodula4l.html" />
  70. <web-view v-else src="https://videos.tradingcentral.cn/players/SHILp3nA-iodula4l.html" />
  71. </view>
  72. </view>
  73. </view>
  74. </cwg-page-wrapper>
  75. </template>
  76. <script setup>
  77. import { ref, onMounted, onUnmounted, computed } from 'vue'
  78. import { onLoad } from '@dcloudio/uni-app'
  79. import { useI18n } from 'vue-i18n'
  80. import { newsApi } from '@/service/news'
  81. import Config from '@/config/index'
  82. import { adaptCWGEmailForUniApp } from '@/utils/emailAdapter.js';
  83. const { t } = useI18n()
  84. const { Code, Host80, Host05 } = Config
  85. // 路由参数
  86. const type = ref(null)
  87. const id = ref(null)
  88. const loading = ref(false)
  89. const currentTitleText = computed(() => {
  90. const map = {
  91. 1: t('News.ViewAnalysis'),
  92. 2: t('News.NewsInformation'),
  93. 3: t('News.Announcement'),
  94. 4: t('News.VideoCommentary'),
  95. 5: t('News.NewsInformation'),
  96. 6: t('News.VideoCommentary'),
  97. 7: t('News.Notice'),
  98. 8: t('News.TradeIdeas'),
  99. 9: t('News.FinancialCalendar'),
  100. 10: t('News.Ebook'),
  101. 11: t('News.VideoCommentary')
  102. }
  103. return map[type.value] || ''
  104. })
  105. // 数据
  106. const Content = ref('')
  107. const imgContent = ref('')
  108. const imgContentIf = ref(false)
  109. const info = ref({})
  110. const imgUrl = Host05
  111. const htmlUrl = Host05
  112. // 语言判断
  113. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  114. // 图片预览
  115. const previewImage = (url) => {
  116. uni.previewImage({
  117. urls: [url]
  118. })
  119. }
  120. // 获取详情(根据 title 调用不同接口)
  121. const getNewsSingle = async () => {
  122. if (!type.value) {
  123. loading.value = false
  124. return
  125. }
  126. switch (type.value) {
  127. case 1: // 观点分析
  128. const analysisRes = await newsApi.newsAnalysisSingle({ id: id.value })
  129. if (analysisRes.code === Code.StatusOK && analysisRes.data) {
  130. imgContent.value = analysisRes.data.media
  131. Content.value = analysisRes.data.content
  132. imgContentIf.value = !!analysisRes.data.media
  133. } else {
  134. uni.showToast({ title: analysisRes.msg, icon: 'none' })
  135. }
  136. break
  137. case 3: // 公告
  138. const infoRes = await newsApi.newsInformationSingle({ id: id.value })
  139. if (infoRes.code === Code.StatusOK && infoRes.data) {
  140. imgContent.value = Host05 + infoRes.data.coverImage
  141. Content.value = infoRes.data.content
  142. imgContentIf.value = !!infoRes.data.coverImage
  143. } else {
  144. uni.showToast({ title: infoRes.msg, icon: 'none' })
  145. }
  146. break
  147. case 7: // 通知
  148. const noticeRes = await newsApi.newsNoticeSingle({ id: id.value })
  149. if (noticeRes.code === Code.StatusOK && noticeRes.data) {
  150. info.value = { ...noticeRes.data, content1: adaptCWGEmailForUniApp(noticeRes.data.content) }
  151. console.log(info.value);
  152. uni.$emit('open-notice')
  153. } else {
  154. uni.showToast({ title: noticeRes.msg, icon: 'none' })
  155. }
  156. break
  157. case 4: // WebTV 视频
  158. const webTvRes = await newsApi.newsWebTvSearchSingle({ id: id.value })
  159. if (webTvRes.code === Code.StatusOK && webTvRes.data) {
  160. info.value = webTvRes.data
  161. // 视频通过 video 组件自动播放,无需手动初始化 DPlayer
  162. } else {
  163. uni.showToast({ title: webTvRes.msg, icon: 'none' })
  164. }
  165. break
  166. case 5: // 新闻通讯
  167. const newsletterRes = await newsApi.newsInformationNewsletterSingle({ id: id.value })
  168. if (newsletterRes.code === Code.StatusOK && newsletterRes.data) {
  169. imgContent.value = Host05 + newsletterRes.data.coverImage
  170. Content.value = newsletterRes.data.content
  171. imgContentIf.value = !!newsletterRes.data.coverImage
  172. } else {
  173. uni.showToast({ title: newsletterRes.msg, icon: 'none' })
  174. }
  175. break
  176. case 6: // 视频评论
  177. const videoRes = await newsApi.newsVideoSingle({ id: id.value })
  178. if (videoRes.code === Code.StatusOK && videoRes.data) {
  179. info.value = videoRes.data
  180. imgContent.value = videoRes.data.videoUrl.includes('http')
  181. ? videoRes.data.videoUrl
  182. : Host80 + videoRes.data.videoUrl
  183. } else {
  184. uni.showToast({ title: videoRes.msg, icon: 'none' })
  185. }
  186. break
  187. case 8: // 交易观点
  188. const shakeRes = await newsApi.handShakeGet({})
  189. if (shakeRes.code === Code.StatusOK) {
  190. imgContent.value = shakeRes.msg
  191. } else {
  192. uni.showToast({ title: shakeRes.msg, icon: 'none' })
  193. }
  194. break
  195. case 9: // 财经日历
  196. const calRes = await newsApi.handFinancialCalendar({})
  197. if (calRes.code === Code.StatusOK) {
  198. imgContent.value = calRes.msg
  199. } else {
  200. uni.showToast({ title: calRes.msg, icon: 'none' })
  201. }
  202. break
  203. case 10: // 电子书
  204. const ebookRes = await newsApi.newsEbookSingle({ id: id.value })
  205. if (ebookRes.code === Code.StatusOK && ebookRes.data) {
  206. info.value = ebookRes.data
  207. } else {
  208. uni.showToast({ title: ebookRes.msg, icon: 'none' })
  209. }
  210. break
  211. default:
  212. break
  213. }
  214. loading.value = false
  215. }
  216. // 页面生命周期:获取路由参数
  217. onLoad((options) => {
  218. loading.value = true
  219. type.value = Number(options.type)
  220. id.value = options.id
  221. getNewsSingle()
  222. })
  223. // 如果需要在页面卸载时做一些清理(原组件无,可留空)
  224. onUnmounted(() => {
  225. // 清理可能的视频播放器
  226. })
  227. </script>
  228. <style lang="scss" scoped>
  229. @import "@/uni.scss";
  230. #News_Content {
  231. height: 100%;
  232. .crm-title-box {
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. padding: px2rpx(10) px2rpx(15);
  237. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  238. border-bottom: 1px solid #eee;
  239. .tit {
  240. font-size: px2rpx(16);
  241. font-weight: bold;
  242. }
  243. .btn {
  244. display: flex;
  245. align-items: center;
  246. .icon-back {
  247. font-size: px2rpx(18);
  248. margin-right: px2rpx(4);
  249. }
  250. }
  251. }
  252. .content {
  253. width: 100%;
  254. height: calc(100% - 50px);
  255. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  256. overflow: hidden;
  257. text-align: left;
  258. padding: px2rpx(10) px2rpx(15);
  259. box-sizing: border-box;
  260. line-height: 1.8;
  261. .img {
  262. margin-bottom: px2rpx(10);
  263. image {
  264. width: 100%;
  265. }
  266. }
  267. .con-title {
  268. font-size: px2rpx(18);
  269. font-weight: bold;
  270. margin: px2rpx(10) 0;
  271. text-align: center;
  272. }
  273. .con-time {
  274. margin-bottom: px2rpx(10);
  275. font-size: px2rpx(12);
  276. color: var(--bs-heading-color);
  277. }
  278. .con-des {
  279. margin: px2rpx(10) 0;
  280. font-size: px2rpx(14);
  281. }
  282. .video-player {
  283. width: 100%;
  284. height: px2rpx(400);
  285. }
  286. .webview {
  287. width: 100%;
  288. height: 100%;
  289. min-height: px2rpx(1200);
  290. }
  291. .ebookBox {
  292. display: flex;
  293. flex-direction: column;
  294. @media (min-width: 768px) {
  295. flex-direction: row;
  296. align-items: center;
  297. }
  298. .ebook-cover {
  299. width: 100%;
  300. max-width: px2rpx(360);
  301. height: auto;
  302. margin-right: 0;
  303. margin-bottom: px2rpx(15);
  304. @media (min-width: 768px) {
  305. margin-right: px2rpx(25);
  306. margin-bottom: 0;
  307. }
  308. }
  309. .news-title {
  310. color: #EB3F57;
  311. font-size: px2rpx(44);
  312. font-weight: bold;
  313. margin-bottom: px2rpx(10);
  314. }
  315. .news-status {
  316. margin-top: px2rpx(10);
  317. a {
  318. display: inline-block;
  319. background-color: #EB3F57;
  320. color: var(--bs-emphasis-color);
  321. padding: px2rpx(8) px2rpx(30);
  322. border-radius: px2rpx(8);
  323. font-weight: bold;
  324. }
  325. }
  326. }
  327. }
  328. img,
  329. uni-image {
  330. max-width: 100% !important;
  331. height: auto;
  332. margin-bottom: px2rpx(10);
  333. }
  334. :deep(img) {
  335. max-width: 100% !important;
  336. height: auto;
  337. margin-bottom: px2rpx(10);
  338. }
  339. }
  340. // 富文本表格样式(保留)
  341. :deep(.con-des) {
  342. table {
  343. border-collapse: collapse !important;
  344. width: 100% !important;
  345. margin: px2rpx(10) 0 !important;
  346. }
  347. th,
  348. td {
  349. border: 1px solid #dcdfe6 !important;
  350. padding: px2rpx(8) !important;
  351. text-align: left !important;
  352. }
  353. th {
  354. background-color: #f5f7fa !important;
  355. }
  356. }
  357. .rich-text-wrapper {
  358. width: 100%;
  359. overflow-x: auto; // 允许横向滚动
  360. -webkit-overflow-scrolling: touch; // 在 iOS 上提供惯性滚动
  361. }
  362. // 可选:让 rich-text 内的内容不换行(但不一定需要)
  363. .rich-text-wrapper rich-text {
  364. display: block;
  365. width: 100%;
  366. }
  367. </style>
  368. <style>
  369. /* 覆盖 rich-text 内所有段落样式 */
  370. uni-rich-text p {
  371. margin: 12rpx 0 !important;
  372. font-size: px2rpx(14) !important;
  373. /* 对应 14px */
  374. line-height: 1.6 !important;
  375. color: var(--bs-heading-color);
  376. }
  377. /* 覆盖 span 样式,移除固定字体和大小 */
  378. uni-rich-text span {
  379. font-size: px2rpx(14) !important;
  380. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
  381. }
  382. /* 图片自适应 */
  383. uni-rich-text img {
  384. max-width: 100% !important;
  385. height: auto !important;
  386. }
  387. </style>