customSvg.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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() == 'color' || arr[1].trim() == 'color1'){
  105. var value = this.getColor(arr[0].trim(),arr[1].trim())
  106. }else if(arr[1].trim() == 'icon'){
  107. var value = this.getIcon(arr[0].trim(),arr[1].trim())
  108. }else if(arr[1].trim() == 'css'){
  109. var value = this.getCss(arr[0].trim(),arr[1].trim())
  110. }
  111. else{
  112. var value = this.getTotal(arr[0].trim(),arr[1].trim())
  113. }
  114. data = data.replace(item, value);
  115. })
  116. }
  117. this.html = data;
  118. },
  119. //查看单个事件流程图
  120. getQuestion(val){
  121. }
  122. },
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .customSvg{
  127. position: relative;
  128. width: 100%;
  129. height:calc(100% - 10px);
  130. .svgDiv{
  131. position: absolute;
  132. left: 0;
  133. top: 0;
  134. bottom:0;
  135. right:0;
  136. margin:auto;
  137. width: 100%;
  138. height: 100%;
  139. }
  140. }
  141. </style>
  142. <style lang="scss">
  143. #SvgjsImage1116{
  144. filter: brightness(100);
  145. }
  146. </style>