123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import BaseModel from '../../../core/base'
- import useSummaryModel from '../transform/summary'
- import useCommonTitleModel from '../transform/content'
- import { replaceKeyword } from '@jy/util'
- class ContentModel extends BaseModel {
- constructor(config) {
- super(config)
- }
- createModel() {
- return {
- content: useCommonTitleModel().createModel(),
- summary: useSummaryModel().createModel()
- }
- }
- formatModel(data, isInit = false) {
- const result = this.createModel()
- // 基础信息
- if (data?.baseInfo) {
- result.content = useCommonTitleModel().transformModel(data)
- }
- // 摘要
- if (data?.abstract) {
- result.summary = useSummaryModel().transformModel(data)
- }
- if (result.content) {
- result.content.titleHighlighted = this.highlightTitleHTML(result.content.title, data, result)
- result.content.contentHighlighted = this.highlightContentHTML(result.content.content, data, result)
- }
- return result
- }
- // 高亮标题
- highlightTitleHTML (title, data, formatted) {
- if (!title) return ''
- const { baseInfo } = data
- const projectName = baseInfo?.projectName
- const projectCode = baseInfo?.projectCode
- // 下划线高亮项目名称编号
- if (projectName && title.toLowerCase().indexOf(projectName.toLowerCase()) > -1) {
- title = replaceKeyword(title, projectName, '<span class="keyword keyword-underline project project-name hide-underline">$1</span>')
- }
- if (projectCode && title.toLowerCase().indexOf(projectCode.toLowerCase()) > -1) {
- title = replaceKeyword(title, projectCode, '<span class="keyword keyword-underline project project-code">$1</span>')
- }
- // ------------------
- // 关键词高亮
- let highlightKeys = []
- if (formatted.content && formatted.content.highlightKeys) {
- highlightKeys = formatted.content.highlightKeys
- }
- highlightKeys.forEach((key) => {
- title = replaceKeyword(title, key, '<span class="keyword highlight-text">$1</span>')
- })
- return title
- }
-
- // 高亮内容文本
- highlightContentHTML(content, data, formatted) {
- if (!content) return ''
- const { baseInfo } = data
- const { summary } = formatted
- const projectName = baseInfo?.projectName
- const projectCode = baseInfo?.projectCode
- content = content.replace(/[^\{\u4e00-\u9fa5]{1,90}{[^\}\u4e00-\u9fa5]+?}/g, '')
- // 高亮第三方服务
- if (content) {
- // content = thirdPartyVerify.replaceKeys(content)
- }
- // 下划线高亮项目名称编号
- if(projectName && content.toLowerCase().indexOf(projectName.toLowerCase()) > -1){
- content = replaceKeyword(content, projectName, '<span class="keyword keyword-underline my-follow project project-name hide-underline">$1</span>')
- }
- if(projectCode && content.toLowerCase().indexOf(projectCode.toLowerCase()) > -1){
- content = replaceKeyword(content, projectCode, '<span class="keyword keyword-underline my-follow project project-code">$1</span>')
- }
- // 下划线高亮中标企业
- const winners = summary.winners
- if (Array.isArray(winners) && winners.length > 0) {
- for (let i = 0; i < winners.length; i++) {
- const winnerName = winners[i].name
- const winnerId = winners[i].id
- if (winnerName && content.toLowerCase().indexOf(winnerName.toLowerCase()) > -1) {
- content = replaceKeyword(content, winnerName, `<span data-eid='${winnerId}' class='keyword keyword-underline winner-name my-follow-ent'>$1</span>`)
- }
- }
- }
- // 表格兼容
- if(content.length > 10 && content.substring(0,6).toLowerCase() === '<tbody' && content.substring(content.length-8).toLowerCase() == '</tbody>'){
- content = '<table>' + content + '</table>'
- }
- // ------------------
- // 关键词高亮
- let highlightKeys = []
- if (formatted.content && formatted.content.highlightKeys) {
- highlightKeys = formatted.content.highlightKeys
- }
- highlightKeys.forEach((key) => {
- content = replaceKeyword(content, key, '<span class="keyword highlight-text">$1</span>')
- })
- return content
- }
- }
- /**
- * /publicapply/detail/baseInfo
- * 基础信息接口数据模型转换
- */
- function useContentModel() {
- return new ContentModel()
- }
- export default useContentModel
|