refreshComponent.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { mapMutations, mapState } from 'vuex'
  2. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  3. import _ from 'lodash'
  4. const refreshComponentMixin = {
  5. data () {
  6. return {
  7. updateKey: 0
  8. }
  9. },
  10. computed: {
  11. ...mapState({
  12. customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme,
  13. activeCode: state => state.bigScreen.activeCode
  14. }),
  15. Data () {
  16. return JSON.parse(JSON.stringify(this.config))
  17. }
  18. },
  19. watch: {
  20. Data: {
  21. handler (newVal, oldVal) {
  22. this.$nextTick(() => {
  23. if ((newVal.w !== oldVal.w) || (newVal.h !== oldVal.h)) {
  24. this.updateKey = new Date().getTime()
  25. }
  26. })
  27. },
  28. deep: true
  29. }
  30. },
  31. methods: {
  32. ...mapMutations({
  33. changeChartConfig: 'bigScreen/changeChartConfig',
  34. changeActiveItemConfig: 'bigScreen/changeActiveItemConfig'
  35. }),
  36. // 修改样式
  37. changeStyle (config) {
  38. config = { ...this.config, ...config }
  39. // 样式改变时更新主题配置
  40. config.theme = settingToTheme(_.cloneDeep(config), this.customTheme)
  41. this.changeChartConfig(config)
  42. if (config.code === this.activeCode) {
  43. this.changeActiveItemConfig(config)
  44. }
  45. }
  46. }
  47. }
  48. export { refreshComponentMixin }