西藏巴青项目

index.vue 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <template>
  2. <!-- 资讯详情:从上页携带 id + type,请求 /app/farmingNews/{id}?type= 展示源表字段 -->
  3. <view :class="pageRootClass" class="tab-page news-detail-page">
  4. <view v-if="loading" class="news-detail-state">
  5. <text class="text-body news-detail-state__txt">{{ $t('newsDetailPage.loading') }}</text>
  6. </view>
  7. <view v-else-if="loadError" class="news-detail-state">
  8. <text class="text-body news-detail-state__txt">{{ loadError }}</text>
  9. </view>
  10. <scroll-view v-else scroll-y class="news-detail-scroll" enable-back-to-top>
  11. <view class="news-detail-inner">
  12. <text class="news-detail-title">{{ resolvedTitle }}</text>
  13. <view class="news-detail-meta">
  14. <text v-if="displayTypeLabel" class="news-detail-meta__tag text-body">{{ displayTypeLabel }}</text>
  15. <text v-if="displayDate" class="text-body news-detail-date">{{ displayDate }}</text>
  16. </view>
  17. <view class="news-detail-section">
  18. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.coverTitle') }}</text>
  19. <image
  20. v-if="hasCover"
  21. class="news-detail-cover"
  22. :src="coverFullUrl"
  23. mode="widthFix"
  24. role="button"
  25. @click="previewCover"
  26. />
  27. <text v-else class="text-body news-detail-muted">{{ $t('newsDetailPage.noCover') }}</text>
  28. </view>
  29. <view class="news-detail-section">
  30. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.introTitle') }}</text>
  31. <text class="text-body news-detail-intro">{{ displayIntro || $t('newsDetailPage.noIntro') }}</text>
  32. </view>
  33. <view v-if="detailRows.length" class="news-detail-section">
  34. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.sectionInfo') }}</text>
  35. <view v-for="(row, idx) in detailRows" :key="idx" class="news-detail-kv">
  36. <text class="news-detail-kv__label text-body">{{ row.label }}</text>
  37. <text class="news-detail-kv__value text-body">{{ row.value }}</text>
  38. </view>
  39. </view>
  40. <view v-if="isCommonProsperity" class="news-detail-section">
  41. <text class="news-detail-section__label text-title">{{ $t('newsDetailPage.cpOpImages') }}</text>
  42. <view v-if="opImageUrls.length" class="news-detail-op-grid">
  43. <image
  44. v-for="(url, idx) in opImageUrls"
  45. :key="idx"
  46. class="news-detail-op-img"
  47. :src="url"
  48. mode="aspectFill"
  49. role="button"
  50. @click="previewOpImages(idx)"
  51. />
  52. </view>
  53. <text v-else class="text-body news-detail-muted">{{ $t('newsDetailPage.dash') }}</text>
  54. </view>
  55. <view v-if="showContentAttachment" class="news-detail-section">
  56. <text class="news-detail-section__label text-title">
  57. {{ isCommonProsperity ? $t('newsDetailPage.cpVideo') : $t('newsDetailPage.attachmentTitle') }}
  58. </text>
  59. <image
  60. v-if="attachmentKind === 'image'"
  61. class="news-detail-attach-img"
  62. :src="contentFullUrl"
  63. mode="widthFix"
  64. role="button"
  65. @click="previewImageAttachment"
  66. />
  67. <view v-else-if="attachmentKind === 'video'" class="news-detail-video-wrap">
  68. <video
  69. class="news-detail-video"
  70. :src="contentFullUrl"
  71. :poster="hasCover ? coverFullUrl : ''"
  72. controls
  73. object-fit="contain"
  74. :enable-progress-gesture="true"
  75. :show-center-play-btn="true"
  76. />
  77. </view>
  78. <view v-else-if="attachmentKind === 'pdf'" class="news-detail-pdf-wrap">
  79. <!-- #ifdef H5 -->
  80. <iframe
  81. class="news-detail-pdf-frame"
  82. :src="contentFullUrl"
  83. frameborder="0"
  84. />
  85. <!-- #endif -->
  86. <!-- #ifndef H5 -->
  87. <view class="news-detail-attach-card" role="button" @click="openOnlineAttachment">
  88. <up-icon name="file-text" color="#15803d" :size="28" />
  89. <view class="news-detail-attach-card__mid">
  90. <text class="news-detail-attach-card__name">{{ attachmentFileName }}</text>
  91. <text class="text-body news-detail-attach-card__hint">{{ $t('newsDetailPage.viewOnline') }}</text>
  92. </view>
  93. <up-icon name="arrow-right" color="#9ca3af" :size="16" />
  94. </view>
  95. <!-- #endif -->
  96. </view>
  97. <view
  98. v-else
  99. class="news-detail-attach-card"
  100. role="button"
  101. @click="openOnlineAttachment"
  102. >
  103. <up-icon name="file-text" color="#15803d" :size="28" />
  104. <view class="news-detail-attach-card__mid">
  105. <text class="news-detail-attach-card__name">{{ attachmentFileName }}</text>
  106. <text class="text-body news-detail-attach-card__hint">{{ $t('newsDetailPage.viewOnline') }}</text>
  107. </view>
  108. <up-icon name="arrow-right" color="#9ca3af" :size="16" />
  109. </view>
  110. </view>
  111. </view>
  112. </scroll-view>
  113. </view>
  114. </template>
  115. <script>
  116. import UIcon from 'uview-plus/components/u-icon/u-icon.vue'
  117. import tabPage from '@/mixins/tabPage'
  118. import { resolveResourceUrl } from '@/utils/resourceUrl'
  119. import { fileNameFromPath, openOnlinePreview, resolveMediaKind } from '@/utils/filePreview'
  120. import { getFarmingNewsDetail } from '@/api/farmingNews'
  121. import {
  122. buildFarmingDetailRows,
  123. formatPublishTime,
  124. resolveDetailContent,
  125. resolveDetailCover,
  126. resolveDetailIntro,
  127. resolveDetailTitle,
  128. resolveOpImageUrls
  129. } from '@/utils/farmingNewsDetail'
  130. const COMMON_PROSPERITY_TYPE = '003004'
  131. function decodeQuery(val) {
  132. if (val == null || val === '') {
  133. return ''
  134. }
  135. try {
  136. return decodeURIComponent(String(val))
  137. } catch (e) {
  138. return String(val)
  139. }
  140. }
  141. function normPath(url) {
  142. return String(url || '')
  143. .trim()
  144. .replace(/\\/g, '/')
  145. .split('?')[0]
  146. .toLowerCase()
  147. }
  148. export default {
  149. components: {
  150. 'up-icon': UIcon
  151. },
  152. mixins: [tabPage],
  153. data() {
  154. return {
  155. navTitleKey: 'newsDetailPage.navTitle',
  156. newsId: '',
  157. newsType: '',
  158. displayTypeLabel: '',
  159. displayTitle: '',
  160. displayDate: '',
  161. displayIntro: '',
  162. coverFileUrl: '',
  163. contentFileUrl: '',
  164. detail: null,
  165. detailRows: [],
  166. opImageUrls: [],
  167. loading: false,
  168. loadError: '',
  169. openingAttachment: false
  170. }
  171. },
  172. computed: {
  173. isCommonProsperity() {
  174. return this.newsType === COMMON_PROSPERITY_TYPE
  175. },
  176. resolvedTitle() {
  177. return this.displayTitle || this.$t('newsDetailPage.titleFallback')
  178. },
  179. hasCover() {
  180. return !!(this.coverFileUrl || '').trim()
  181. },
  182. hasAttachment() {
  183. return !!(this.contentFileUrl || '').trim()
  184. },
  185. coverFullUrl() {
  186. return resolveResourceUrl(this.coverFileUrl)
  187. },
  188. contentFullUrl() {
  189. return resolveResourceUrl(this.contentFileUrl)
  190. },
  191. attachmentKind() {
  192. return resolveMediaKind(this.contentFileUrl)
  193. },
  194. attachmentFileName() {
  195. return fileNameFromPath(this.contentFileUrl)
  196. },
  197. showContentAttachment() {
  198. if (!this.hasAttachment) {
  199. return false
  200. }
  201. if (!this.hasCover) {
  202. return true
  203. }
  204. if (normPath(this.coverFileUrl) !== normPath(this.contentFileUrl)) {
  205. return true
  206. }
  207. return this.attachmentKind !== 'image'
  208. }
  209. },
  210. onLoad(query) {
  211. this.newsId = decodeQuery(query.id)
  212. this.newsType = decodeQuery(query.type)
  213. this.displayTypeLabel = decodeQuery(query.typeLabel)
  214. this.loadDetail()
  215. },
  216. methods: {
  217. loadDetail() {
  218. if (!this.newsId || !this.newsType) {
  219. this.loadError = this.$t('newsDetailPage.invalidParams')
  220. return
  221. }
  222. this.loading = true
  223. this.loadError = ''
  224. getFarmingNewsDetail(this.newsId, this.newsType)
  225. .then((res) => {
  226. const data = res.data || null
  227. if (!data) {
  228. this.loadError = this.$t('newsDetailPage.notFound')
  229. return
  230. }
  231. this.applyDetail(data)
  232. })
  233. .catch((e) => {
  234. this.detail = null
  235. this.loadError = (e && e.message) || this.$t('newsDetailPage.loadFail')
  236. })
  237. .finally(() => {
  238. this.loading = false
  239. })
  240. },
  241. applyDetail(data) {
  242. this.detail = data
  243. this.displayTitle = resolveDetailTitle(data)
  244. this.displayIntro = resolveDetailIntro(data)
  245. this.coverFileUrl = resolveDetailCover(data)
  246. this.contentFileUrl = resolveDetailContent(data)
  247. this.displayDate = formatPublishTime(data.publishTime)
  248. this.detailRows = buildFarmingDetailRows(data, this.newsType, (key) => this.$t(key))
  249. this.opImageUrls = resolveOpImageUrls(data, resolveResourceUrl)
  250. if (this.displayTitle) {
  251. uni.setNavigationBarTitle({ title: this.displayTitle })
  252. }
  253. },
  254. previewCover() {
  255. if (!this.coverFullUrl) {
  256. return
  257. }
  258. uni.previewImage({
  259. urls: [this.coverFullUrl],
  260. current: 0
  261. })
  262. },
  263. previewOpImages(index) {
  264. if (!this.opImageUrls.length) {
  265. return
  266. }
  267. uni.previewImage({
  268. urls: this.opImageUrls,
  269. current: typeof index === 'number' ? index : 0
  270. })
  271. },
  272. previewImageAttachment() {
  273. if (!this.contentFullUrl) {
  274. return
  275. }
  276. uni.previewImage({
  277. urls: [this.contentFullUrl],
  278. current: 0
  279. })
  280. },
  281. openOnlineAttachment() {
  282. if (!this.contentFileUrl || this.openingAttachment) {
  283. return
  284. }
  285. if (this.attachmentKind === 'image') {
  286. this.previewImageAttachment()
  287. return
  288. }
  289. this.openingAttachment = true
  290. openOnlinePreview(this.contentFileUrl, { title: this.attachmentFileName })
  291. .catch(() => {
  292. uni.showToast({
  293. title: this.$t('newsDetailPage.previewFail'),
  294. icon: 'none'
  295. })
  296. })
  297. .finally(() => {
  298. this.openingAttachment = false
  299. })
  300. }
  301. }
  302. }
  303. </script>
  304. <style lang="scss" scoped>
  305. @import '@/styles/morandi.scss';
  306. @import '@/styles/tab-page.scss';
  307. .news-detail-page {
  308. display: flex;
  309. flex-direction: column;
  310. min-width: 0;
  311. min-height: 100%;
  312. box-sizing: border-box;
  313. background: $morandi-bg-page;
  314. }
  315. .news-detail-state {
  316. display: flex;
  317. flex: 1;
  318. align-items: center;
  319. justify-content: center;
  320. min-height: 40vh;
  321. padding: 48rpx 32rpx;
  322. box-sizing: border-box;
  323. }
  324. .news-detail-state__txt {
  325. font-size: 28rpx;
  326. line-height: 1.6;
  327. color: $morandi-text-muted;
  328. text-align: center;
  329. }
  330. .news-detail-scroll {
  331. flex: 1;
  332. min-height: 0;
  333. min-width: 0;
  334. }
  335. .news-detail-inner {
  336. display: flex;
  337. flex-direction: column;
  338. align-items: stretch;
  339. gap: 28rpx;
  340. min-width: 0;
  341. padding: 40rpx 32rpx 48rpx;
  342. box-sizing: border-box;
  343. }
  344. .news-detail-title {
  345. display: block;
  346. width: 100%;
  347. text-align: center;
  348. font-size: 38rpx;
  349. font-weight: 700;
  350. line-height: 1.45;
  351. color: #111827;
  352. word-break: break-word;
  353. overflow-wrap: anywhere;
  354. }
  355. .news-detail-meta {
  356. display: flex;
  357. flex-direction: row;
  358. flex-wrap: wrap;
  359. align-items: center;
  360. justify-content: center;
  361. gap: 12rpx 20rpx;
  362. width: 100%;
  363. }
  364. .news-detail-meta__tag {
  365. padding: 6rpx 16rpx;
  366. border-radius: 999rpx;
  367. font-size: 22rpx;
  368. line-height: 1.4;
  369. color: #15803d;
  370. background: rgba(34, 197, 94, 0.12);
  371. border: 1rpx solid rgba(34, 197, 94, 0.25);
  372. }
  373. .news-detail-date {
  374. font-size: 24rpx;
  375. line-height: 1.5;
  376. color: $morandi-text-muted;
  377. }
  378. .news-detail-section {
  379. display: flex;
  380. flex-direction: column;
  381. gap: 16rpx;
  382. min-width: 0;
  383. padding: 24rpx;
  384. box-sizing: border-box;
  385. border-radius: 16rpx;
  386. background: $morandi-bg-card;
  387. border: 1rpx solid $morandi-border;
  388. }
  389. .news-detail-section__label {
  390. font-size: 30rpx;
  391. font-weight: 600;
  392. color: $morandi-text;
  393. }
  394. .news-detail-muted {
  395. font-size: 26rpx;
  396. line-height: 1.5;
  397. color: $morandi-text-muted;
  398. }
  399. .news-detail-intro {
  400. font-size: 28rpx;
  401. line-height: 1.6;
  402. color: $morandi-text-secondary;
  403. word-break: break-word;
  404. overflow-wrap: anywhere;
  405. white-space: pre-wrap;
  406. }
  407. .news-detail-kv {
  408. display: flex;
  409. flex-direction: row;
  410. align-items: flex-start;
  411. gap: 16rpx;
  412. min-width: 0;
  413. padding: 8rpx 0;
  414. border-bottom: 1rpx solid $morandi-border-soft;
  415. &:last-child {
  416. border-bottom: none;
  417. }
  418. }
  419. .news-detail-kv__label {
  420. flex-shrink: 0;
  421. width: 180rpx;
  422. font-size: 26rpx;
  423. line-height: 1.5;
  424. color: $morandi-text-muted;
  425. }
  426. .news-detail-kv__value {
  427. flex: 1;
  428. min-width: 0;
  429. font-size: 26rpx;
  430. line-height: 1.5;
  431. color: $morandi-text-secondary;
  432. word-break: break-word;
  433. overflow-wrap: anywhere;
  434. white-space: pre-wrap;
  435. }
  436. .news-detail-op-grid {
  437. display: flex;
  438. flex-direction: row;
  439. flex-wrap: wrap;
  440. gap: 16rpx;
  441. }
  442. .news-detail-op-img {
  443. width: 200rpx;
  444. height: 200rpx;
  445. border-radius: 12rpx;
  446. background: $morandi-bg-card-inner;
  447. }
  448. .news-detail-cover,
  449. .news-detail-attach-img {
  450. display: block;
  451. width: 100%;
  452. border-radius: 12rpx;
  453. background: $morandi-bg-card-inner;
  454. }
  455. .news-detail-video-wrap {
  456. width: 100%;
  457. min-width: 0;
  458. border-radius: 12rpx;
  459. overflow: hidden;
  460. background: #1a1a1a;
  461. border: 1rpx solid $morandi-border-soft;
  462. }
  463. .news-detail-video {
  464. display: block;
  465. width: 100%;
  466. height: 400rpx;
  467. background: #1a1a1a;
  468. }
  469. .news-detail-pdf-wrap {
  470. width: 100%;
  471. min-width: 0;
  472. }
  473. .news-detail-pdf-frame {
  474. display: block;
  475. width: 100%;
  476. height: 70vh;
  477. min-height: 480rpx;
  478. border: none;
  479. border-radius: 12rpx;
  480. background: $morandi-bg-card-inner;
  481. }
  482. .news-detail-attach-card {
  483. display: flex;
  484. flex-direction: row;
  485. align-items: center;
  486. gap: 16rpx;
  487. min-width: 0;
  488. padding: 20rpx;
  489. box-sizing: border-box;
  490. border-radius: 12rpx;
  491. background: $morandi-bg-card-inner;
  492. border: 1rpx solid $morandi-border-soft;
  493. }
  494. .news-detail-attach-card__mid {
  495. flex: 1;
  496. min-width: 0;
  497. display: flex;
  498. flex-direction: column;
  499. gap: 8rpx;
  500. }
  501. .news-detail-attach-card__name {
  502. font-size: 28rpx;
  503. font-weight: 500;
  504. line-height: 1.45;
  505. color: $morandi-text;
  506. word-break: break-all;
  507. }
  508. .news-detail-attach-card__hint {
  509. font-size: 24rpx;
  510. color: $morandi-accent-soft;
  511. }
  512. .news-detail-page.lang-bo {
  513. .news-detail-title {
  514. font-size: 34rpx;
  515. line-height: 1.75;
  516. letter-spacing: 2rpx;
  517. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  518. }
  519. .news-detail-date,
  520. .news-detail-intro,
  521. .news-detail-muted,
  522. .news-detail-kv__label,
  523. .news-detail-kv__value,
  524. .news-detail-state__txt {
  525. font-size: 22rpx;
  526. line-height: 1.75;
  527. letter-spacing: 2rpx;
  528. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  529. }
  530. .news-detail-section__label {
  531. font-size: 28rpx;
  532. line-height: 1.75;
  533. letter-spacing: 2rpx;
  534. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  535. }
  536. .news-detail-attach-card__name {
  537. font-size: 26rpx;
  538. line-height: 1.75;
  539. letter-spacing: 2rpx;
  540. font-family: 'Noto Sans Tibetan', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  541. }
  542. .news-detail-kv__label {
  543. width: 220rpx;
  544. }
  545. }
  546. </style>