123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <template>
- <!-- 自定义组件 -->
- <div class="customSvg" >
- <!-- 用来存放svg -->
- <div class="svgDiv" v-html="html">
- </div>
- <myPopover :QuestionTotal="QuestionTotal" @questionId="getQuestion"></myPopover>
- </div>
- </template>
- <script>
- import mixins from "./mixins";
- import MyPopover from './Popover.vue'
- export default {
- components: {
- MyPopover
- },
- mixins: [mixins],
- props: {
- title: {
- type: String,
- default: '竞争对手威胁应对'
- },
- },
- watch: {
- 'QuestionTotal'(val) {
- if (val && Object.keys(this.total).length > 0 && Object.keys(this.QuestionTotal).length > 0) {
- this.getHtml()
- }
- },
- 'total'(val) {
- if (val && Object.keys(this.total).length > 0 && Object.keys(this.QuestionTotal).length > 0) {
- this.getHtml()
- }
- }
- },
- data() {
- return {
- svgData: [
- {
- title: '专利培育布局',
- value: '../专利培育布局A1.svg'
- },
- {
- title: '产品上市/出口风险控制',
- value: '../产品上市出口风险控制A2.svg'
- },
- {
- title: '侵权纠纷',
- value: '../侵权纠纷A3.svg'
- },
- {
- title: '专利维权',
- value: '../专利维权A4.svg'
- },
- {
- title: 'IPO上市',
- value: '../IPO上市A5.svg'
- },
- {
- title: '专利盘点与运维',
- value: '../专利盘点与运维A6.svg'
- },
- {
- title: '科技与重大立项专利导航',
- value: '../科技与重大立项专利导航A7.svg'
- },
- {
- title: '竞争对手威胁应对',
- value: '../竞争对手威胁应对A8.svg'
- },
- ],
- html: '',
- fileContent:''
- }
- },
- async mounted() {
- await this.init()
- },
- methods: {
- async init() {
- // 需要显示哪一个svg文件
- let show = this.svgData.find(item => {
- return item.title == this.title
- });
- // 展示svg文件
- await fetch(show.value).then(res => res.text()).then(data => {
- this.fileContent = data
- if (Object.keys(this.total).length > 0 && Object.keys(this.QuestionTotal).length > 0) {
- this.getHtml()
- }
- })
- },
- //获取svg内容
- getHtml() {
- var data = this.fileContent
- let reg = new RegExp("\{\{(.+?)\}\}", "g");
- let a = data.match(reg);
- let reg1 = new RegExp("(?<=\{\{)(.*)?(?=\}\})",'g')
- if(a){
- a.forEach(item => {
- var arr = item.match(reg1)[0].split(/\,|\,/)
- if (arr[1].trim() == 1) {
- var value = this.getQuestionTotal(arr[0].trim())
- } else if (arr[1].trim() == 2) {
- var value = this.getTotal(arr[0].trim())
- } else {
- var num = this.getTotal(arr[0].trim())
- var value = num>0?arr[1].trim():'#63769b69'
- }
- data = data.replace(item, value);
- })
- }
-
- this.html = data;
- },
- //查看单个事件流程图
- getQuestion(val){
- console.log(val)
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .customSvg{
- position: relative;
- width: 100%;
- height: 100%;
- .svgDiv{
- position: absolute;
- left: 0;
- top: 0;
- bottom:0;
- right:0;
- margin:auto;
- width: 100%;
- height: 100%;
- }
- }
- </style>
|