customSvg.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <!-- 自定义组件 -->
  3. <div class="customSvg" >
  4. <!-- 用来存放svg -->
  5. <div class="svgDiv" v-html="html">
  6. </div>
  7. <myPopover :QuestionTotal="QuestionTotal" @questionId="getQuestion"></myPopover>
  8. </div>
  9. </template>
  10. <script>
  11. import mixins from "./mixins";
  12. import MyPopover from './Popover.vue'
  13. export default {
  14. components: {
  15. MyPopover
  16. },
  17. mixins: [mixins],
  18. props: {
  19. title: {
  20. type: String,
  21. default: '竞争对手威胁应对'
  22. },
  23. },
  24. watch: {
  25. 'QuestionTotal'(val) {
  26. if (val && Object.keys(this.total).length > 0 && Object.keys(this.QuestionTotal).length > 0) {
  27. this.getHtml()
  28. }
  29. },
  30. 'total'(val) {
  31. if (val && Object.keys(this.total).length > 0 && Object.keys(this.QuestionTotal).length > 0) {
  32. this.getHtml()
  33. }
  34. }
  35. },
  36. data() {
  37. return {
  38. svgData: [
  39. {
  40. title: '专利培育布局',
  41. value: '../专利培育布局A1.svg'
  42. },
  43. {
  44. title: '产品上市/出口风险控制',
  45. value: '../产品上市出口风险控制A2.svg'
  46. },
  47. {
  48. title: '侵权纠纷',
  49. value: '../侵权纠纷A3.svg'
  50. },
  51. {
  52. title: '专利维权',
  53. value: '../专利维权A4.svg'
  54. },
  55. {
  56. title: 'IPO上市',
  57. value: '../IPO上市A5.svg'
  58. },
  59. {
  60. title: '专利盘点与运维',
  61. value: '../专利盘点与运维A6.svg'
  62. },
  63. {
  64. title: '科技与重大立项专利导航',
  65. value: '../科技与重大立项专利导航A7.svg'
  66. },
  67. {
  68. title: '竞争对手威胁应对',
  69. value: '../竞争对手威胁应对A8.svg'
  70. },
  71. ],
  72. html: '',
  73. fileContent:''
  74. }
  75. },
  76. async mounted() {
  77. await this.init()
  78. },
  79. methods: {
  80. async init() {
  81. // 需要显示哪一个svg文件
  82. let show = this.svgData.find(item => {
  83. return item.title == this.title
  84. });
  85. // 展示svg文件
  86. await fetch(show.value).then(res => res.text()).then(data => {
  87. this.fileContent = data
  88. if (Object.keys(this.total).length > 0 && Object.keys(this.QuestionTotal).length > 0) {
  89. this.getHtml()
  90. }
  91. })
  92. },
  93. //获取svg内容
  94. getHtml() {
  95. var data = this.fileContent
  96. let reg = new RegExp("\{\{(.+?)\}\}", "g");
  97. let a = data.match(reg);
  98. let reg1 = new RegExp("(?<=\{\{)(.*)?(?=\}\})",'g')
  99. if(a){
  100. a.forEach(item => {
  101. var arr = item.match(reg1)[0].split(/\,|\,/)
  102. if (arr[1].trim() == 1) {
  103. var value = this.getQuestionTotal(arr[0].trim())
  104. } else if (arr[1].trim() == 2) {
  105. var value = this.getTotal(arr[0].trim())
  106. } else {
  107. var num = this.getTotal(arr[0].trim())
  108. var value = num>0?arr[1].trim():'#63769b69'
  109. }
  110. data = data.replace(item, value);
  111. })
  112. }
  113. this.html = data;
  114. },
  115. //查看单个事件流程图
  116. getQuestion(val){
  117. console.log(val)
  118. }
  119. },
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .customSvg{
  124. position: relative;
  125. width: 100%;
  126. height: 100%;
  127. .svgDiv{
  128. position: absolute;
  129. left: 0;
  130. top: 0;
  131. bottom:0;
  132. right:0;
  133. margin:auto;
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. </style>