西藏巴青项目

index.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <!-- 资讯详情:展示列表接口返回的全部字段 -->
  3. <view :class="pageRootClass" class="tab-page news-detail-page">
  4. <scroll-view scroll-y class="news-detail-scroll" enable-back-to-top>
  5. <view class="news-detail-inner">
  6. <text class="news-detail-title">{{ resolvedTitle }}</text>
  7. <view class="news-detail-meta">
  8. <text v-if="displayTypeLabel" class="news-detail-meta__tag text-body">{{ displayTypeLabel }}</text>
  9. <text class="text-body news-detail-date">{{ displayDate }}</text>
  10. </view>
  11. <view class="news-detail-section">
  12. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.coverTitle') }}</text>
  13. <image
  14. v-if="hasCover"
  15. class="news-detail-cover"
  16. :src="coverFullUrl"
  17. mode="widthFix"
  18. role="button"
  19. @click="previewCover"
  20. />
  21. <text v-else class="text-body news-detail-muted">{{ $t('newsDetailPage.noCover') }}</text>
  22. </view>
  23. <view class="news-detail-section">
  24. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.introTitle') }}</text>
  25. <text class="text-body news-detail-intro">{{ displayIntro || $t('newsDetailPage.noIntro') }}</text>
  26. </view>
  27. <view v-if="showContentAttachment" class="news-detail-section">
  28. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.attachmentTitle') }}</text>
  29. <image
  30. v-if="attachmentKind === 'image'"
  31. class="news-detail-attach-img"
  32. :src="contentFullUrl"
  33. mode="widthFix"
  34. role="button"
  35. @click="previewImageAttachment"
  36. />
  37. <view v-else-if="attachmentKind === 'video'" class="news-detail-video-wrap">
  38. <video
  39. class="news-detail-video"
  40. :src="contentFullUrl"
  41. controls
  42. object-fit="contain"
  43. :enable-progress-gesture="true"
  44. :show-center-play-btn="true"
  45. />
  46. </view>
  47. <view v-else-if="attachmentKind === 'pdf'" class="news-detail-pdf-wrap">
  48. <!-- #ifdef H5 -->
  49. <iframe
  50. class="news-detail-pdf-frame"
  51. :src="contentFullUrl"
  52. frameborder="0"
  53. />
  54. <!-- #endif -->
  55. <!-- #ifndef H5 -->
  56. <view class="news-detail-attach-card" role="button" @click="openOnlineAttachment">
  57. <up-icon name="file-text" color="#15803d" :size="28" />
  58. <view class="news-detail-attach-card__mid">
  59. <text class="news-detail-attach-card__name">{{ attachmentFileName }}</text>
  60. <text class="text-body news-detail-attach-card__hint">{{ $t('newsDetailPage.viewOnline') }}</text>
  61. </view>
  62. <up-icon name="arrow-right" color="#9ca3af" :size="16" />
  63. </view>
  64. <!-- #endif -->
  65. </view>
  66. <view
  67. v-else
  68. class="news-detail-attach-card"
  69. role="button"
  70. @click="openOnlineAttachment"
  71. >
  72. <up-icon name="file-text" color="#15803d" :size="28" />
  73. <view class="news-detail-attach-card__mid">
  74. <text class="news-detail-attach-card__name">{{ attachmentFileName }}</text>
  75. <text class="text-body news-detail-attach-card__hint">{{ $t('newsDetailPage.viewOnline') }}</text>
  76. </view>
  77. <up-icon name="arrow-right" color="#9ca3af" :size="16" />
  78. </view>
  79. </view>
  80. </view>
  81. </scroll-view>
  82. </view>
  83. </template>
  84. <script>
  85. import UIcon from 'uview-plus/components/u-icon/u-icon.vue'
  86. import tabPage from '@/mixins/tabPage'
  87. import { resolveResourceUrl } from '@/utils/resourceUrl'
  88. import { fileNameFromPath, openOnlinePreview, resolveMediaKind } from '@/utils/filePreview'
  89. import { takeNewsDetailPayload } from '@/utils/newsDetailCache'
  90. function decodeQuery(val) {
  91. if (val == null || val === '') {
  92. return ''
  93. }
  94. try {
  95. return decodeURIComponent(String(val))
  96. } catch (e) {
  97. return String(val)
  98. }
  99. }
  100. function normPath(url) {
  101. return String(url || '')
  102. .trim()
  103. .replace(/\\/g, '/')
  104. .split('?')[0]
  105. .toLowerCase()
  106. }
  107. export default {
  108. components: {
  109. 'up-icon': UIcon
  110. },
  111. mixins: [tabPage],
  112. data() {
  113. return {
  114. navTitleKey: 'newsDetailPage.navTitle',
  115. displayTitle: '',
  116. displayDate: '',
  117. displayIntro: '',
  118. displayType: '',
  119. displayTypeLabel: '',
  120. coverFileUrl: '',
  121. contentFileUrl: '',
  122. titleN: 1,
  123. openingAttachment: false,
  124. /** breeding:养殖资讯;livestock:畜牧资源 */
  125. listKind: 'breeding'
  126. }
  127. },
  128. computed: {
  129. resolvedTitle() {
  130. if (this.displayTitle) {
  131. return this.displayTitle
  132. }
  133. if (this.listKind === 'livestock') {
  134. return this.$t('livestockResourcesPage.titleTpl', { n: this.titleN })
  135. }
  136. return this.$t('breedingNewsPage.titleTpl', { n: this.titleN })
  137. },
  138. hasCover() {
  139. return !!(this.coverFileUrl || '').trim()
  140. },
  141. hasAttachment() {
  142. return !!(this.contentFileUrl || '').trim()
  143. },
  144. coverFullUrl() {
  145. return resolveResourceUrl(this.coverFileUrl)
  146. },
  147. contentFullUrl() {
  148. return resolveResourceUrl(this.contentFileUrl)
  149. },
  150. attachmentKind() {
  151. return resolveMediaKind(this.contentFileUrl)
  152. },
  153. attachmentFileName() {
  154. return fileNameFromPath(this.contentFileUrl)
  155. },
  156. /** 正文附件与封面为同一张图时,封面区已展示,不再重复 */
  157. showContentAttachment() {
  158. if (!this.hasAttachment) {
  159. return false
  160. }
  161. if (!this.hasCover) {
  162. return true
  163. }
  164. if (normPath(this.coverFileUrl) !== normPath(this.contentFileUrl)) {
  165. return true
  166. }
  167. return this.attachmentKind !== 'image'
  168. }
  169. },
  170. onLoad(query) {
  171. this.listKind = query.kind === 'livestock' ? 'livestock' : 'breeding'
  172. const n = parseInt(query.n, 10)
  173. this.titleN = Number.isFinite(n) && n > 0 ? n : 1
  174. const cacheKey = decodeQuery(query.cacheKey)
  175. const cached = takeNewsDetailPayload(cacheKey)
  176. if (cached) {
  177. this.applyArticle(cached)
  178. return
  179. }
  180. this.applyArticle({
  181. title: decodeQuery(query.title),
  182. publishTime: decodeQuery(query.date),
  183. introduction: decodeQuery(query.introduction),
  184. type: decodeQuery(query.type),
  185. typeLabel: decodeQuery(query.typeLabel),
  186. coverFileUrl: decodeQuery(query.coverFileUrl),
  187. contentFileUrl: decodeQuery(query.contentFileUrl),
  188. listKind: this.listKind
  189. })
  190. },
  191. methods: {
  192. applyArticle(data) {
  193. if (!data || typeof data !== 'object') {
  194. return
  195. }
  196. this.displayTitle = data.title || ''
  197. this.displayIntro = data.introduction || ''
  198. this.displayType = data.type || ''
  199. this.displayTypeLabel = data.typeLabel || data.typeName || ''
  200. this.coverFileUrl = data.coverFileUrl || ''
  201. this.contentFileUrl = data.contentFileUrl || ''
  202. this.displayDate = data.publishTime || ''
  203. if (data.listKind === 'livestock' || data.listKind === 'breeding') {
  204. this.listKind = data.listKind
  205. }
  206. if (!this.displayDate) {
  207. const d = new Date()
  208. const y = d.getFullYear()
  209. const m = `${d.getMonth() + 1}`.padStart(2, '0')
  210. const day = `${d.getDate()}`.padStart(2, '0')
  211. this.displayDate = `${y}-${m}-${day}`
  212. }
  213. },
  214. previewCover() {
  215. if (!this.coverFullUrl) {
  216. return
  217. }
  218. uni.previewImage({
  219. urls: [this.coverFullUrl],
  220. current: 0
  221. })
  222. },
  223. previewImageAttachment() {
  224. if (!this.contentFullUrl) {
  225. return
  226. }
  227. uni.previewImage({
  228. urls: [this.contentFullUrl],
  229. current: 0
  230. })
  231. },
  232. openOnlineAttachment() {
  233. if (!this.contentFileUrl || this.openingAttachment) {
  234. return
  235. }
  236. if (this.attachmentKind === 'image') {
  237. this.previewImageAttachment()
  238. return
  239. }
  240. this.openingAttachment = true
  241. openOnlinePreview(this.contentFileUrl, { title: this.attachmentFileName })
  242. .catch(() => {
  243. uni.showToast({
  244. title: this.$t('newsDetailPage.previewFail'),
  245. icon: 'none'
  246. })
  247. })
  248. .finally(() => {
  249. this.openingAttachment = false
  250. })
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. @import '@/styles/morandi.scss';
  257. @import '@/styles/tab-page.scss';
  258. .news-detail-page {
  259. display: flex;
  260. flex-direction: column;
  261. min-width: 0;
  262. min-height: 100%;
  263. box-sizing: border-box;
  264. background: $morandi-bg-page;
  265. }
  266. .news-detail-scroll {
  267. flex: 1;
  268. min-height: 0;
  269. min-width: 0;
  270. }
  271. .news-detail-inner {
  272. display: flex;
  273. flex-direction: column;
  274. align-items: stretch;
  275. gap: 28rpx;
  276. min-width: 0;
  277. padding: 40rpx 32rpx 48rpx;
  278. box-sizing: border-box;
  279. }
  280. .news-detail-title {
  281. display: block;
  282. width: 100%;
  283. text-align: center;
  284. font-size: 38rpx;
  285. font-weight: 700;
  286. line-height: 1.45;
  287. color: #111827;
  288. word-break: break-word;
  289. overflow-wrap: anywhere;
  290. }
  291. .news-detail-meta {
  292. display: flex;
  293. flex-direction: row;
  294. flex-wrap: wrap;
  295. align-items: center;
  296. justify-content: center;
  297. gap: 12rpx 20rpx;
  298. width: 100%;
  299. }
  300. .news-detail-meta__tag {
  301. padding: 6rpx 16rpx;
  302. border-radius: 999rpx;
  303. font-size: 22rpx;
  304. line-height: 1.4;
  305. color: #15803d;
  306. background: rgba(34, 197, 94, 0.12);
  307. border: 1rpx solid rgba(34, 197, 94, 0.25);
  308. }
  309. .news-detail-date {
  310. font-size: 24rpx;
  311. line-height: 1.5;
  312. color: $morandi-text-muted;
  313. }
  314. .news-detail-section {
  315. display: flex;
  316. flex-direction: column;
  317. gap: 16rpx;
  318. min-width: 0;
  319. padding: 24rpx;
  320. box-sizing: border-box;
  321. border-radius: 16rpx;
  322. background: $morandi-bg-card;
  323. border: 1rpx solid $morandi-border;
  324. }
  325. .news-detail-section__label {
  326. font-size: 30rpx;
  327. font-weight: 600;
  328. color: $morandi-text;
  329. }
  330. .news-detail-muted {
  331. font-size: 26rpx;
  332. line-height: 1.5;
  333. color: $morandi-text-muted;
  334. }
  335. .news-detail-intro {
  336. font-size: 28rpx;
  337. line-height: 1.6;
  338. color: $morandi-text-secondary;
  339. word-break: break-word;
  340. overflow-wrap: anywhere;
  341. white-space: pre-wrap;
  342. }
  343. .news-detail-cover,
  344. .news-detail-attach-img {
  345. display: block;
  346. width: 100%;
  347. border-radius: 12rpx;
  348. background: $morandi-bg-card-inner;
  349. }
  350. .news-detail-video-wrap {
  351. width: 100%;
  352. min-width: 0;
  353. border-radius: 12rpx;
  354. overflow: hidden;
  355. background: #1a1a1a;
  356. border: 1rpx solid $morandi-border-soft;
  357. }
  358. .news-detail-video {
  359. display: block;
  360. width: 100%;
  361. height: 400rpx;
  362. background: #1a1a1a;
  363. }
  364. .news-detail-pdf-wrap {
  365. width: 100%;
  366. min-width: 0;
  367. }
  368. .news-detail-pdf-frame {
  369. display: block;
  370. width: 100%;
  371. height: 70vh;
  372. min-height: 480rpx;
  373. border: none;
  374. border-radius: 12rpx;
  375. background: $morandi-bg-card-inner;
  376. }
  377. .news-detail-attach-card {
  378. display: flex;
  379. flex-direction: row;
  380. align-items: center;
  381. gap: 16rpx;
  382. min-width: 0;
  383. padding: 20rpx;
  384. box-sizing: border-box;
  385. border-radius: 12rpx;
  386. background: $morandi-bg-card-inner;
  387. border: 1rpx solid $morandi-border-soft;
  388. }
  389. .news-detail-attach-card__mid {
  390. flex: 1;
  391. min-width: 0;
  392. display: flex;
  393. flex-direction: column;
  394. gap: 8rpx;
  395. }
  396. .news-detail-attach-card__name {
  397. font-size: 28rpx;
  398. font-weight: 500;
  399. line-height: 1.45;
  400. color: $morandi-text;
  401. word-break: break-all;
  402. }
  403. .news-detail-attach-card__hint {
  404. font-size: 24rpx;
  405. color: $morandi-accent-soft;
  406. }
  407. .news-detail-page.lang-bo {
  408. .news-detail-title {
  409. font-size: 34rpx;
  410. line-height: 1.75;
  411. letter-spacing: 2rpx;
  412. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  413. }
  414. .news-detail-date,
  415. .news-detail-intro,
  416. .news-detail-muted {
  417. font-size: 22rpx;
  418. line-height: 1.75;
  419. letter-spacing: 2rpx;
  420. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  421. }
  422. .news-detail-section__label {
  423. font-size: 28rpx;
  424. line-height: 1.75;
  425. letter-spacing: 2rpx;
  426. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  427. }
  428. .news-detail-attach-card__name {
  429. font-size: 26rpx;
  430. line-height: 1.75;
  431. letter-spacing: 2rpx;
  432. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  433. }
  434. }
  435. </style>