3328350766
6 天以前 761eb03d6b3bebd0b197179564c84d89d3d12a0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { mapMutations, mapState } from 'vuex'
import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
import cloneDeep from 'lodash/cloneDeep'
const dataVMixins = {
  props: {
    // 卡片的属性
    config: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      updateKey: 0,
      borderBgId: null
    }
  },
  computed: {
    ...mapState({
      customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme,
      activeCode: state => state.bigScreen.activeCode
    }),
    code () {
      return this.config.code
    },
    color () {
      return this.config.customize.borderMainColor ||
        this.config.customize.borderSecondaryColor
        ? [
            this.config.customize.borderMainColor,
            this.config.customize.borderSecondaryColor
          ]
        : null
    },
    backgroundColor () {
      return this.config.customize.backgroundColor
        ? this.config.customize.backgroundColor
        : 'transparent'
    },
    colorType () {
      return this.config.customize.colorType
    },
    Data () {
      return JSON.parse(JSON.stringify(this.config))
    }
  },
  watch: {
    config: {
      handler: function (val) {
        if (val && val.customize && val.customize.colorType) {
          this.changeBorderStyle(this.config)
          if (val.customize.colorType === 'single') {
            this.borderBgId = null
            this.$nextTick(() => {
              this.updateKey = new Date().getTime()
            })
          } else {
            this.borderBgId = `borderBg${this.config.code}`
          }
        }
      },
      deep: true
    },
    Data: {
      handler (newVal, oldVal) {
        this.$nextTick(() => {
          if ((newVal.w !== oldVal.w) || (newVal.h !== oldVal.h)) {
            this.$nextTick(() => {
              this.updateKey = new Date().getTime()
            })
          }
        })
      },
      deep: true
    }
  },
  mounted () {
    this.changeBorderStyle(this.config)
  },
  methods: {
    ...mapMutations({
      changeChartConfig: 'bigScreen/changeChartConfig',
      changeActiveItemConfig: 'bigScreen/changeActiveItemConfig'
    }),
    changeStyle (config) {
      config = { ...this.config, ...config }
      // 样式改变时更新主题配置
      config.theme = settingToTheme(cloneDeep(config), this.customTheme)
      this.changeChartConfig(config)
      if (config.code === this.activeCode) {
        this.changeActiveItemConfig(config)
      }
      this.changeBorderStyle(config)
    },
    changeBorderStyle (config) {
      this.borderBgId = `borderBg${config.code}`
      if (document.querySelector(`#dataV${config.code}`)) {
        const borderElement = document.querySelector(`#dataV${config.code}`).querySelector('.border') || document.querySelector(`#dataV${config.code}`)?.querySelector('.dv-border-svg-container')
        if (borderElement) {
          let isBorder7 = false
          borderElement.childNodes.forEach(e => {
            if (e._prevClass === 'dv-bb7-line-width-2') {
              isBorder7 = true
            }
          })
          borderElement.style.opacity = (config.customize.opacity / 100)
          if (this.colorType === 'gradient') {
            if (!isBorder7) {
              let gradientDirection = ''
              switch (config.customize.gradientDirection) {
                case 'to right':
                  gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="0%"'
                  break
                case 'to left':
                  gradientDirection = 'x1="100%" y1="0%" x2="0%" y2="0%"'
                  break
                case 'to bottom':
                  gradientDirection = 'x1="0%" y1="0%" x2="0%" y2="100%"'
                  break
                case 'to top':
                  gradientDirection = 'x1="0%" y1="100%" x2="0%" y2="0%"'
                  break
                case 'to bottom right':
                  gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="100%"'
                  break
                case 'to bottom left':
                  gradientDirection = 'x1="100%" y1="0%" x2="0%" y2="100%"'
                  break
                case 'to top right':
                  gradientDirection = 'x1="0%" y1="100%" x2="100%" y2="0%"'
                  break
                case 'to top left':
                  gradientDirection = 'x1="100%" y1="100%" x2="0%" y2="0%"'
                  break
                default:
                  gradientDirection = 'x1="0%" y1="0%" x2="100%" y2="0%"'
                  break
              }
              // 在目标元素内的第一个位置插入 <defs> 和其中的内容
              borderElement.insertAdjacentHTML(
                'afterbegin',
                `<defs>
                      <linearGradient id="${this.borderBgId}" ${gradientDirection}>
                        <stop offset="0%" stop-color="${config.customize.gradientColor0}" />
                        <stop offset="100%" stop-color="${config.customize.gradientColor1}" />
                      </linearGradient>
                </defs>`
              )
            } else {
              borderElement.style.background = `linear-gradient(${config.customize.gradientDirection},${config.customize.gradientColor0}, ${config.customize.gradientColor1})`
              isBorder7 = false
            }
          }
        }
      }
    }
  }
}
 
export { dataVMixins }