EditReport.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <script setup name="ReportEdit">
  2. import {ref,onMounted,onUnmounted} from 'vue'
  3. import {useInitFroalaEditor} from '@/hooks/useFroalaEditor'
  4. // import EditReportBaseInfo from './components/EditReportBaseInfo.vue'
  5. import ReportInsertContent from './components/reportInsert/Index.vue'
  6. import ReportPublishTimeSet from './components/ReportPublishTimeSet.vue'
  7. import apiReport from '@/api/report'
  8. // import {getSystemInfo} from '@/api/common'
  9. import moment from 'moment'
  10. import { showToast,showDialog } from 'vant'
  11. import { useRoute, useRouter } from 'vue-router'
  12. import {useCachedViewsStore} from '@/store/modules/cachedViews'
  13. import {usePublicSettingStore} from '@/store/modules/publicSetting'
  14. import {reportManageBtn,useAuthBtn} from '@/hooks/useAuthBtn'
  15. import {useReportApprove} from '@/hooks/useReportApprove'
  16. import AddReportBaseInfoV2 from './components/AddReportBaseInfoV2.vue'
  17. import { useReportHandles,useChapterRepoprtHandles } from './hooks/useReport'
  18. const cachedViewsStore=useCachedViewsStore()
  19. const publicSettingStore = usePublicSettingStore()
  20. const {isApprove,hasApproveFlow,getEtaConfig,checkClassifyNameArr} = useReportApprove()
  21. const router=useRouter()
  22. const route=useRoute()
  23. const {checkAuthBtn} = useAuthBtn()
  24. const {lastFocusPosition,initFroalaEditor,imgUploadFlag,frolaEditorContentChange}=useInitFroalaEditor()
  25. let reportContentEditorIns=null//报告内容编辑器实例
  26. const { handleRefresh,handlePublishReportHook,handleDSPublish,showDSFBTime } = useReportHandles()
  27. const reportCoopType = ref(Number(route.query.coopType))
  28. let autoSaveTimer=null
  29. onMounted(() => {
  30. const el=document.getElementById('editor')
  31. reportContentEditorIns=initFroalaEditor('#editor',{height:el.offsetHeight-150})
  32. if(reportCoopType.value===1) {//单人报告
  33. getEtaConfig()
  34. getReportDetail()
  35. autoSaveTimer=setInterval(() => {
  36. autoSaveReportContent()
  37. }, 6000);
  38. }else if(reportCoopType.value===2) { //章节报告
  39. getChapterDetail()
  40. autoSaveTimer=setInterval(() => {
  41. autoSaveReportChapter()
  42. }, 6000);
  43. }
  44. })
  45. onUnmounted(()=>{
  46. clearInterval(autoSaveTimer)
  47. })
  48. // 自动保存报告
  49. async function autoSaveReportContent(type="auto"){
  50. if(!imgUploadFlag.value)return
  51. //如果富文本中有未上传完成的图片,去除这个dom
  52. $('.fr-element').find('img.fr-uploading').length&&$('.fr-element').find('img.fr-uploading').remove()
  53. return new Promise(async (resolve,reject)=>{
  54. const res=await apiReport.reportContentSave({
  55. ReportId:Number(route.query.id),
  56. Content:$('.fr-element').html(),
  57. NoChange:frolaEditorContentChange.value?0:1
  58. })
  59. if(res.Ret === 200) {
  60. resolve(true)
  61. type==='save' && showToast("保存成功");
  62. frolaEditorContentChange.value=false
  63. }
  64. })
  65. }
  66. // 获取报告详情
  67. const reportData=ref(null)
  68. async function getReportDetail(){
  69. const res=await apiReport.getReportDetail({
  70. ReportId:Number(route.query.id)
  71. })
  72. if(res.Ret===200){
  73. reportData.value=res.Data
  74. reportBaseInfoData.addType=res.Data.AddType
  75. reportBaseInfoData.classifyName=[
  76. {
  77. id:res.Data.ClassifyIdFirst,
  78. text:res.Data.ClassifyNameFirst,
  79. },
  80. {
  81. id:res.Data.ClassifyIdSecond,
  82. text:res.Data.ClassifyNameSecond,
  83. },
  84. {
  85. id:res.Data.ClassifyIdThird,
  86. text:res.Data.ClassifyNameThird,
  87. }
  88. ]
  89. reportBaseInfoData.author=res.Data.Author ? res.Data.Author.split(',') : ['FICC团队']
  90. reportBaseInfoData.frequency=[res.Data.Frequency]
  91. reportBaseInfoData.createtime=moment(res.Data.CreateTime).format('YYYY-MM-DD')
  92. reportBaseInfoData.title=res.Data.Title
  93. reportBaseInfoData.abstract=res.Data.Abstract
  94. reportBaseInfoData.cooperationType=res.Data.CollaborateType
  95. reportBaseInfoData.cooperationUsers=res.Data.GrandAdminList
  96. ? res.Data.GrandAdminList.map(_ => ({
  97. NodeId: _.AdminId,
  98. NodeName: _.AdminName
  99. }))
  100. : []
  101. reportBaseInfoData.reportLayout=res.Data.ReportLayout
  102. reportBaseInfoData.isPublcPublish=res.Data.IsPublicPublish
  103. reportContentEditorIns.html.set(res.Data.Content);
  104. const classify = reportBaseInfoData.classifyName.map(i=>i.id)
  105. checkClassifyNameArr(1,classify)
  106. }
  107. }
  108. //获取章节详情
  109. async function getChapterDetail() {
  110. const res=await apiReport.getChapterDetail({
  111. ReportChapterId:Number(route.query.chapterId)
  112. })
  113. reportData.value=res.Data;
  114. reportContentEditorIns.html.set(res.Data.Content);
  115. }
  116. // 报告基本内容
  117. const showReportBaseInfo=ref(false)
  118. let reportBaseInfoData={
  119. addType:1,
  120. classifyName:[],
  121. author:['FICC团队'],
  122. frequency: ['日度'],
  123. createtime:moment().format('YYYY-MM-DD'),
  124. title:'',
  125. abstract:'',
  126. cooperationType:1,
  127. cooperationUsers:[],
  128. reportLayout: 1,
  129. isPublcPublish: 1
  130. }
  131. async function handleReportBaseInfoChange(e){
  132. reportBaseInfoData={
  133. ...e,
  134. classifyName:e.classifys,
  135. createtime:e.time,
  136. }
  137. const classify = e.classifys.map(i=>i.id)
  138. checkClassifyNameArr(1,classify)
  139. showReportBaseInfo.value=false
  140. }
  141. // 报告插入数据弹窗
  142. const showReportInsertPop=ref(false)
  143. /**
  144. * list:[UniqueCode] 图表code
  145. * type:iframe/img 插入的为iframe或者图片
  146. * chartType: chart-图表,sheet-表格
  147. */
  148. function handleInsert({list,type,chartType}){
  149. reportContentEditorIns.events.focus()
  150. if(lastFocusPosition.value){
  151. reportContentEditorIns.selection.get().removeAllRanges()
  152. reportContentEditorIns.selection.get().addRange(lastFocusPosition.value)
  153. }
  154. if(type==='iframe'){
  155. let link=publicSettingStore.publicSetting.ChartViewUrl;
  156. if(chartType==='chart'){
  157. // link=import.meta.env.MODE==='production'?'https://chartlib.hzinsights.com/chartshow':'https://charttest.hzinsights.com/chartshow'
  158. link=link+'/chartshow'
  159. list.forEach(item => {
  160. reportContentEditorIns.html.insert(`<p style='text-align:left; margin-top:10px;'>
  161. <iframe src='${link}?code=${item}&fromPage=' width='100%' height='350' style='border-width:0px; min-height:350px;'></iframe>
  162. </p>`,false)
  163. });
  164. }else if(chartType==='sheet'){
  165. // link=import.meta.env.MODE==='production'?'https://chartlib.hzinsights.com/sheetshow':'https://charttest.hzinsights.com/sheetshow'
  166. link=link+'/sheetshow'
  167. list.forEach(item => {
  168. reportContentEditorIns.html.insert(`<p style='text-align:left; margin-top:10px;'>
  169. <iframe src='${link}?code=${item}' class='iframe${item}' width='100%' style='border-width:0px;'></iframe>
  170. </p>`,false)
  171. });
  172. }
  173. }else if(type==='img'){
  174. list.forEach(item=>{
  175. reportContentEditorIns.html.insert(`<img style='width:100%' src='${item}' />`,false)
  176. })
  177. }
  178. showReportInsertPop.value=false
  179. }
  180. // 更新sheet表格高度
  181. function reInitSheetIframe(e){
  182. const { height,code } = e.data;
  183. let iframeDom = document.getElementsByClassName(`iframe${code}`)
  184. Array.prototype.forEach.call(iframeDom, function (ele) {
  185. ele.height = `${height+45}px`;
  186. });
  187. }
  188. onMounted(()=>{
  189. window.addEventListener('message',reInitSheetIframe)
  190. })
  191. onUnmounted(()=>{
  192. window.removeEventListener('message',reInitSheetIframe)
  193. })
  194. // 刷新所有图表
  195. async function handleRefreshAllChart(){
  196. handleRefresh({ id: Number(route.query.id),chapterId:Number(route.query.chapterId) })
  197. }
  198. /* 预览 */
  199. function handlePreviewReport() {
  200. const params={
  201. ReportId:Number(route.query.id),
  202. AddType: reportBaseInfoData.addType,
  203. ClassifyIdFirst: reportBaseInfoData.classifyName[0].id,
  204. ClassifyNameFirst: reportBaseInfoData.classifyName[0].text,
  205. ClassifyIdSecond: reportBaseInfoData.classifyName[1].id,
  206. ClassifyNameSecond: reportBaseInfoData.classifyName[1].text,
  207. Title: reportBaseInfoData.title,
  208. Abstract: reportBaseInfoData.abstract,
  209. Author:reportBaseInfoData.author.join(','),
  210. Frequency: reportBaseInfoData.frequency[0],
  211. Content: $('.fr-element').html(),
  212. CreateTime: reportBaseInfoData.createtime,
  213. ReportVersion: 2,
  214. State:1
  215. }
  216. sessionStorage.setItem('reportPreData',JSON.stringify(params))
  217. router.push({
  218. path:'/report/preview',
  219. query:{
  220. id:-1
  221. }
  222. })
  223. return
  224. }
  225. //发布 定时 提交
  226. async function handlePublishReport(tp) {
  227. cachedViewsStore.removeCaches('ReportList')
  228. const saveRes = await autoSaveReportContent('auto');
  229. if(!saveRes) return
  230. handlePublishReportHook(tp,reportData.value)
  231. }
  232. // 定时发布报告选择时间
  233. function onConfirmDSFBTime(time){
  234. // console.log(time);
  235. handleDSPublish(time,reportData.value)
  236. }
  237. const { handlePublishChapterApi } = useChapterRepoprtHandles()
  238. //预览章节
  239. async function handlePreviewChapter() {
  240. const saveRes = await autoSaveReportChapter('auto');
  241. if(!saveRes) return
  242. router.push({
  243. path:'/report/chapter/preview',
  244. query:{
  245. id:reportData.value.ReportChapterId
  246. }
  247. })
  248. }
  249. // 自动保存章节报告
  250. async function autoSaveReportChapter(type="auto"){
  251. if(!imgUploadFlag.value)return
  252. if(!route.query.chapterId) return
  253. //如果富文本中有未上传完成的图片,去除这个dom
  254. $('.fr-element').find('img.fr-uploading').length&&$('.fr-element').find('img.fr-uploading').remove()
  255. return new Promise(async (resolve,reject)=>{
  256. const res=await apiReport.chapterDetailSave({
  257. ReportChapterId:Number(route.query.chapterId),
  258. Content:$('.fr-element').html(),
  259. })
  260. if(res.Ret === 200) {
  261. resolve(true)
  262. type==='save' && showToast("保存成功");
  263. }
  264. })
  265. }
  266. /* 提交章节 */
  267. async function handlePublishChapter() {
  268. showDialog({
  269. title: '提示',
  270. showCancelButton: true,
  271. message: '章节提交后不可编辑,是否确认提交?',
  272. confirmButtonText: '确认',
  273. cancelButtonText: '取消',
  274. }).then( async() => {
  275. const saveRes = await autoSaveReportChapter('auto');
  276. if(!saveRes) return
  277. handlePublishChapterApi(reportData.value.ReportChapterId)
  278. }).catch(() =>{})
  279. }
  280. </script>
  281. <template>
  282. <div class="add-report-page">
  283. <div class="main-wrap">
  284. <div class="editor-box" id="editor"></div>
  285. </div>
  286. <!-- 底部操作 -->
  287. <div class="bot-action-box">
  288. <div class="left-box" v-if="reportData">
  289. <div class="item" @click="showReportBaseInfo=true" v-if="!reportData.ReportChapterId">
  290. <img src="@/assets/imgs/report/icon_info.png" alt="">
  291. <span>基础信息</span>
  292. </div>
  293. <div class="item" @click="handleRefreshAllChart">
  294. <img src="@/assets/imgs/report/icon_refresh.png" alt="">
  295. <span>刷新</span>
  296. </div>
  297. <div class="item" @click="reportData.ReportChapterId?handlePreviewChapter():handlePreviewReport()" v-permission="reportManageBtn.reportManage_reportView">
  298. <img src="@/assets/imgs/report/icon_preview.png" alt="">
  299. <span>预览</span>
  300. </div>
  301. <div class="item" @click="reportData.ReportChapterId?autoSaveReportChapter('save'):autoSaveReportContent('save')">
  302. <img src="@/assets/imgs/report/icon_save2.png" alt="">
  303. <span>保存</span>
  304. </div>
  305. <!-- 章节报告提交章节 -->
  306. <div
  307. class="item"
  308. @click="handlePublishChapter"
  309. v-permission="reportManageBtn.reportManage_publish"
  310. v-if="reportData.ReportChapterId"
  311. >
  312. <img src="@/assets/imgs/report/icon_publish3.png" alt="">
  313. <span>提交</span>
  314. </div>
  315. <!-- 单人报告提交发布 -->
  316. <template v-else>
  317. <template v-if="!isApprove||!hasApproveFlow">
  318. <div class="item" @click="handlePublishReport('dsfb')" v-permission="reportManageBtn.reportManage_publish">
  319. <img src="@/assets/imgs/report/icon_time.png" alt="">
  320. <span>定时发布</span>
  321. </div>
  322. <div class="item" @click="handlePublishReport('fb')" v-permission="reportManageBtn.reportManage_publish">
  323. <img src="@/assets/imgs/report/icon_publish3.png" alt="">
  324. <span>发布</span>
  325. </div>
  326. </template>
  327. <template v-if="isApprove&&hasApproveFlow">
  328. <div class="item" @click="handlePublishReport('submit')" v-permission="reportManageBtn.reportManage_publish">
  329. <img src="@/assets/imgs/report/icon_publish3.png" alt="">
  330. <span>提交</span>
  331. </div>
  332. </template>
  333. </template>
  334. </div>
  335. <div class="right-btn" @click="showReportInsertPop=true">
  336. <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
  337. <path d="M12.0499 15.9499V27.5H15.9499V15.9499H27.5V12.0499H15.9499V0.5H12.0499V12.0499H0.5V15.9499H12.0499Z" fill="white"/>
  338. </svg>
  339. </div>
  340. </div>
  341. </div>
  342. <!-- 报告基础信息 -->
  343. <van-popup
  344. v-model:show="showReportBaseInfo"
  345. position="bottom"
  346. :style="{ height: '100%' }"
  347. >
  348. <AddReportBaseInfoV2
  349. @close="showReportBaseInfo=false"
  350. :id="Number(route.query.id)"
  351. :defaultData="reportBaseInfoData"
  352. @confirm="handleReportBaseInfoChange"
  353. />
  354. </van-popup>
  355. <!-- 报告插入数据模块 -->
  356. <van-popup
  357. v-model:show="showReportInsertPop"
  358. position="bottom"
  359. round
  360. >
  361. <report-insert-content v-if="showReportInsertPop" @insert="handleInsert"/>
  362. </van-popup>
  363. <!-- 定时发布选择时间 -->
  364. <ReportPublishTimeSet v-model="showDSFBTime" :prePublishTime="reportData?.PrePublishTime" @confirm="onConfirmDSFBTime" />
  365. </template>
  366. <style lang="scss" scoped>
  367. .publish-report-pop-box{
  368. padding: 48px;
  369. .title{
  370. font-size: 36px;
  371. text-align: center;
  372. margin-bottom: 32px;
  373. }
  374. .tips{
  375. color: $font-grey;
  376. margin-bottom: 48px;
  377. }
  378. .btns{
  379. .btn{
  380. line-height: 96px;
  381. border-radius: 12px;
  382. text-align: center;
  383. font-size: 32px;
  384. font-weight: 600;
  385. margin-bottom: 24px;
  386. background-color: #F2F3FF;
  387. color: $theme-color;
  388. }
  389. .blue{
  390. background-color: $theme-color;
  391. color: #fff;
  392. }
  393. .disabled{
  394. background-color: #a8b0fc;
  395. }
  396. }
  397. }
  398. @media screen and (min-width:$media-width){
  399. .publish-report-pop-box{
  400. padding: 24px;
  401. .title{
  402. font-size: 18px;
  403. margin-bottom: 16px;
  404. }
  405. .tips{
  406. margin-bottom: 24px;
  407. }
  408. .btns{
  409. .btn{
  410. line-height: 48px;
  411. border-radius: 12px;
  412. font-size: 16px;
  413. margin-bottom: 12px;
  414. }
  415. }
  416. }
  417. }
  418. .add-report-page{
  419. height: 100dvh;
  420. min-height: 95vh;
  421. display: flex;
  422. flex-direction: column;
  423. overflow: hidden;
  424. }
  425. @media screen and (min-width:$media-width){
  426. .add-report-page{
  427. height: calc(100dvh - 60px);
  428. min-height: calc(95vh - 60px);
  429. }
  430. }
  431. .van-cell{
  432. flex-shrink: 0;
  433. }
  434. .main-wrap{
  435. flex: 1;
  436. width: calc(100% - 32PX);
  437. margin: 0 auto;
  438. margin-top: 30px;
  439. .editor-box{
  440. width: 100%;
  441. height: 100%;
  442. }
  443. }
  444. .bot-action-box{
  445. padding: 20px 16PX;
  446. display: flex;
  447. align-items: center;
  448. .left-box{
  449. flex: 1;
  450. background: #FFFFFF;
  451. box-shadow: 0px 12px 60px 10px rgba(0, 0, 0, 0.05), 0px 32px 48px 4px rgba(0, 0, 0, 0.04), 0px 16px 20px -10px rgba(0, 0, 0, 0.08);
  452. border-radius: 100px;
  453. height: 112px;
  454. display: flex;
  455. align-items: center;
  456. margin-right: 20px;
  457. padding: 0 20px;
  458. .item{
  459. flex: 1;
  460. text-align: center;
  461. font-size: 20px;
  462. img{
  463. width: 40px;
  464. height: 40px;
  465. display: block;
  466. margin: 5px auto;
  467. }
  468. }
  469. }
  470. .right-btn{
  471. flex-shrink: 0;
  472. position: relative;
  473. width: 96px;
  474. height: 96px;
  475. background-color: $theme-color;
  476. border-radius: 50%;
  477. box-shadow: 0px 6px 28px 4px rgba(0, 0, 0, 0.05), 0px 16px 20px 2px rgba(0, 0, 0, 0.06), 0px 10px 10px -6px rgba(0, 0, 0, 0.1);
  478. svg{
  479. width: 27px;
  480. height: 27px;
  481. position: absolute;
  482. top: 50%;
  483. left: 50%;
  484. transform: translate(-50%,-50%);
  485. }
  486. }
  487. }
  488. @media screen and (min-width:$media-width){
  489. .bot-action-box{
  490. margin: 0 auto;
  491. width: 600px;
  492. padding: 10px 16px;
  493. .left-box{
  494. border-radius: 50px;
  495. height: 56px;
  496. margin-right: 10px;
  497. padding: 0 10px;
  498. .item{
  499. font-size: 12px;
  500. img{
  501. width: 20px;
  502. height: 20px;
  503. margin: 3px auto;
  504. }
  505. }
  506. }
  507. .right-btn{
  508. width: 48px;
  509. height: 48px;
  510. svg{
  511. width: 14px;
  512. height: 14px;
  513. }
  514. }
  515. }
  516. }
  517. </style>