content.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import BaseModel from '../../../core/base'
  2. import { dateFormatter, formatMoney } from '@jy/util'
  3. class CommonContentModel extends BaseModel {
  4. constructor(config) {
  5. super(config)
  6. }
  7. createModel() {
  8. const contentModel = {
  9. id: '',
  10. title: '',
  11. // 项目信息
  12. projectName: '',
  13. projectCode: '',
  14. // 高亮词组
  15. keys: [],
  16. tags: [],
  17. time: '',
  18. // 计算信息
  19. isSelfSite: false,
  20. // TDK
  21. tdk: {
  22. title: '',
  23. keywords: '',
  24. description: ''
  25. }
  26. }
  27. return contentModel
  28. }
  29. formatModel(data, isInit = false) {
  30. const result = this.createModel()
  31. const { baseInfo } = data
  32. result.id = baseInfo.id
  33. result.title = baseInfo.title
  34. result.projectName = baseInfo?.projectName
  35. result.projectCode = baseInfo?.projectCode
  36. result.isSelfSite = baseInfo?.site === '剑鱼信息发布平台'
  37. result.time = baseInfo?.publishTime
  38. ? dateFormatter(baseInfo.publishTime * 1000, 'yyyy-MM-dd')
  39. : ''
  40. // TDK
  41. result.tdk.title = baseInfo.title
  42. result.tdk.description = baseInfo?.description
  43. result.tdk.keywords = baseInfo?.keywords
  44. // Tags
  45. result.tags = this.tranTags(data)
  46. return result
  47. }
  48. tranTags(data) {
  49. const { baseInfo } = data
  50. const defaultURL = 'javascript:volid(0);'
  51. const area = [baseInfo?.area, baseInfo?.city, baseInfo?.district]
  52. .filter((v) => v)
  53. .join('-')
  54. const typeItem = {
  55. label: baseInfo?.topType,
  56. link: defaultURL
  57. }
  58. if (baseInfo?.subType) {
  59. typeItem.label = baseInfo.subType
  60. typeItem.link = baseInfo?.subTypeUrl
  61. }
  62. const amountItem = {
  63. label: formatMoney(baseInfo?.bidAmount ?? baseInfo?.budget ?? ''),
  64. link: defaultURL
  65. }
  66. const tags = [
  67. // 地区
  68. {
  69. label: area,
  70. link: baseInfo?.areaUrl || defaultURL
  71. },
  72. // type
  73. typeItem,
  74. // buyer_class
  75. {
  76. label: baseInfo?.buyerClass,
  77. link: defaultURL
  78. },
  79. // amount
  80. amountItem
  81. ].filter((v) => v.label)
  82. return tags
  83. }
  84. }
  85. function useCommonContentModel() {
  86. return new CommonContentModel()
  87. }
  88. export default useCommonContentModel