西藏巴青项目

farmingNewsDetail.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * 养殖资讯详情展示辅助(对接 GET /app/farmingNews/{id}?type=)
  3. */
  4. function pickText(val) {
  5. if (val == null) return ''
  6. return String(val).trim()
  7. }
  8. function isEmpty(val) {
  9. if (val == null) return true
  10. if (typeof val === 'string') return val.trim() === ''
  11. if (Array.isArray(val)) return !val.length
  12. return false
  13. }
  14. export function formatPublishTime(val) {
  15. const s = pickText(val)
  16. if (!s) return ''
  17. return s.length >= 10 ? s.slice(0, 10) : s
  18. }
  19. export function resolveDetailTitle(d) {
  20. if (!d) return ''
  21. return (
  22. pickText(d.standardName) ||
  23. pickText(d.projectName) ||
  24. pickText(d.policyName) ||
  25. pickText(d.subsidyName) ||
  26. pickText(d.title) ||
  27. ''
  28. )
  29. }
  30. export function resolveDetailIntro(d) {
  31. if (!d) return ''
  32. return pickText(d.introduction) || pickText(d.projectIntro) || ''
  33. }
  34. export function resolveDetailCover(d) {
  35. if (!d) return ''
  36. return pickText(d.coverFileUrl)
  37. }
  38. /** 正文附件 / 政策文件 / 视频等 */
  39. export function resolveDetailContent(d) {
  40. if (!d) return ''
  41. return (
  42. pickText(d.contentFileUrl) ||
  43. pickText(d.attachmentFileUrl) ||
  44. pickText(d.policyFileUrl) ||
  45. pickText(d.detailFileUrl) ||
  46. pickText(d.videoFileUrl) ||
  47. ''
  48. )
  49. }
  50. export function resolveOpImageUrls(d, resolveUrl) {
  51. const list = d && Array.isArray(d.operationImages) ? d.operationImages : []
  52. return list
  53. .map((img) => {
  54. const raw = img && (img.fileUrl || img.url)
  55. return raw ? resolveUrl(raw) : ''
  56. })
  57. .filter(Boolean)
  58. }
  59. function pushRow(rows, label, value) {
  60. const v = pickText(value)
  61. if (!v) return
  62. rows.push({ label, value: v })
  63. }
  64. function formatMoney(val) {
  65. if (val == null || val === '') return ''
  66. const n = Number(val)
  67. if (Number.isNaN(n)) return pickText(val)
  68. return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 })
  69. }
  70. const CP_TYPE_KEYS = {
  71. 1: 'cpType1',
  72. 2: 'cpType2',
  73. 3: 'cpType3'
  74. }
  75. /**
  76. * @param {object} d 详情 data(源表全字段)
  77. * @param {string} type 资讯类别编码
  78. * @param {(key:string)=>string} t i18n:$t 包装
  79. */
  80. export function buildFarmingDetailRows(d, type, t) {
  81. if (!d) return []
  82. const rows = []
  83. const p = 'newsDetailPage'
  84. const typeCode = pickText(type)
  85. if (typeCode === '003004') {
  86. const typeKey = CP_TYPE_KEYS[d.projectType] || CP_TYPE_KEYS[String(d.projectType)]
  87. pushRow(rows, t(`${p}.cpProjectType`), typeKey ? t(`${p}.${typeKey}`) : d.projectType)
  88. pushRow(rows, t(`${p}.cpContent`), d.projectContent)
  89. if (!isEmpty(d.investmentAmount)) {
  90. pushRow(rows, t(`${p}.cpInvestment`), `${formatMoney(d.investmentAmount)}${t(`${p}.cpUnitWanYuan`)}`)
  91. }
  92. pushRow(rows, t(`${p}.cpImplYear`), d.implYear != null ? String(d.implYear) : '')
  93. pushRow(rows, t(`${p}.cpImplStatus`), d.implStatus)
  94. return rows
  95. }
  96. // 标准类 / 科技 / 政策 / 补贴:补充常用业务字段
  97. pushRow(rows, t(`${p}.fieldProjectContent`), d.projectContent)
  98. pushRow(rows, t(`${p}.fieldRemark`), d.remark)
  99. if (d.implYear != null) {
  100. pushRow(rows, t(`${p}.cpImplYear`), String(d.implYear))
  101. }
  102. if (!isEmpty(d.investmentAmount)) {
  103. pushRow(rows, t(`${p}.cpInvestment`), `${formatMoney(d.investmentAmount)}${t(`${p}.cpUnitWanYuan`)}`)
  104. }
  105. pushRow(rows, t(`${p}.cpImplStatus`), d.implStatus)
  106. return rows
  107. }