createPPTContent.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import {formatPPTDate} from '../utils/index'
  2. import {bgList} from '../utils/config'
  3. import {ref} from 'vue'
  4. import Cover from '../template/Cover.vue'
  5. import Footer from '../template/Footer.vue'
  6. import FormatOne from '../template/FormatOne.vue'
  7. import FormatTwo from '../template/FormatTwo.vue'
  8. import FormatThree from '../template/FormatThree.vue'
  9. import FormatFour from '../template/FormatFour.vue'
  10. import FormatFive from '../template/FormatFive.vue'
  11. import FormatSix from '../template/FormatSix.vue'
  12. import FormatSeven from '../template/FormatSeven.vue'
  13. import FormatEight from '../template/FormatEight.vue'
  14. import FormatNine from '../template/FormatNine.vue'
  15. import ChartWrap from '../components/ChartWrap.vue'
  16. import RichText from '../components/RichText.vue'
  17. import ImageWrap from '../components/ImageWrap.vue'
  18. import SheetWrap from '../components/SheetWrap.vue'
  19. import RectShape from '../components/layers/RectShape.vue'
  20. import LineShape from '../components/layers/LineShape.vue'
  21. import TextShape from '../components/layers/TextShape.vue'
  22. /**
  23. * 格式化ppt内容
  24. * @param params ppt详情接口返回的数据
  25. * modelId 模板1-9 0代表封面 -1代表尾页
  26. */
  27. export function createPPTContent(params){
  28. const lang=window.location.pathname.startsWith('/ppten')?'en':'zh'
  29. const {
  30. Content,
  31. Title,
  32. ReportType,
  33. BackgroundImg,
  34. PptDate,
  35. TemplateType,
  36. ReportId,
  37. ModifyTime,
  38. PublishTime
  39. }=params
  40. let arr=[]//ppt内容数组
  41. // 封面页数据
  42. const coverPageData={
  43. Title,
  44. ReportType,
  45. BackgroundImg,
  46. PptDate:formatPPTDate('zh',PptDate),
  47. TemplateType,
  48. BackIndex:TemplateType-1,
  49. imgLocalUrl:bgList[lang][TemplateType-1],
  50. modelId:0,
  51. id:0,
  52. }
  53. arr.push(coverPageData)
  54. // ppt内容页数据
  55. const conArr=JSON.parse(Content)
  56. arr.push(...conArr)
  57. //ppt尾页数据
  58. const lastPageData={
  59. name:'back',
  60. modelId:-1,
  61. id:-1,
  62. //英文地址:https://hzstatic.hzinsights.com/static/ppt_m/ppt_last__img_en.png
  63. bgImg:lang=='zh'?'/pptImg/ppt_last_img.png':'/pptImg/ppt_last_img_en.png',
  64. }
  65. arr.push(lastPageData)
  66. return arr
  67. }
  68. /**
  69. * ppt模板Map
  70. * 根据modelId获取是哪个模板组件
  71. */
  72. export function getTemplate(modelId){
  73. const modelMap=new Map([
  74. [0,Cover],
  75. [1,FormatOne],
  76. [2,FormatTwo],
  77. [3,FormatThree],
  78. [4,FormatFour],
  79. [5,FormatFive],
  80. [6,FormatSix],
  81. [7,FormatSeven],
  82. [8,FormatEight],
  83. [9,FormatNine],
  84. [-1,Footer],
  85. ])
  86. return modelMap.get(modelId)
  87. }
  88. /**
  89. * 获取ppt页面内部是哪种组件
  90. * @param position 该模板中哪个位置
  91. * @param list 该ppt页的element数据
  92. */
  93. export function getPPTContentType(position,list){
  94. const typeMap=new Map([
  95. ['chart',ChartWrap],
  96. ['text',RichText],
  97. ['image',ImageWrap],
  98. ['sheet',SheetWrap]
  99. ])
  100. // 查找出list中的position和position对应的类型
  101. let type=''
  102. list.forEach(item => {
  103. if(item.position===position){
  104. type=item.type
  105. }
  106. });
  107. return typeMap.get(type)
  108. }
  109. /**
  110. * 获取ppt页面中某模块的数据
  111. * @param position 该模板中哪个位置
  112. * @param data 该ppt页的数据
  113. */
  114. export function getPPTContentItemData(position,data){
  115. let obj={}
  116. data.elements.forEach(item => {
  117. if(item.position===position){
  118. obj=item
  119. }
  120. });
  121. return {...obj,pptPageIndex:data.pptPageIndex}
  122. }
  123. /**
  124. * 设置ppt每页中的layer图层类型
  125. */
  126. export function getPPTLayerType(data){
  127. const typeMap=new Map([
  128. ['shape',RectShape],
  129. ['line',LineShape],
  130. ['text',TextShape]
  131. ])
  132. return typeMap.get(data.type)
  133. }