chartSettingMixins.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import _ from 'lodash'
  2. import ColorSelect from 'packages/ColorMultipleSelect/index.vue'
  3. const chartSettingMixins = {
  4. components: {
  5. ColorSelect
  6. },
  7. data () {
  8. return {
  9. customRules: {},
  10. colorScheme: [],
  11. colors: []
  12. }
  13. },
  14. computed: {
  15. },
  16. watch: {
  17. },
  18. mounted () {
  19. this.initColor()
  20. },
  21. methods: {
  22. initColor () {
  23. const colorSetting = this.config?.setting?.find(item => item.type === 'colorSelect')
  24. if (colorSetting && colorSetting.value && colorSetting.value.length) {
  25. this.colorScheme = _.cloneDeep(colorSetting.value)
  26. this.colors = _.cloneDeep(colorSetting.value)
  27. }
  28. },
  29. // 清空颜色
  30. delColor () {
  31. this.colors = []
  32. this.config.setting.forEach((set) => {
  33. if (set && set.type === 'colorSelect' && set.value && set.value.length) {
  34. set.value = []
  35. }
  36. })
  37. },
  38. addColor () {
  39. this.colors.push('')
  40. },
  41. updateColorScheme (colors) {
  42. this.colors = [...colors]
  43. this.config.setting.forEach((set) => {
  44. if (set && set.type === 'colorSelect') {
  45. set.value = [...colors]
  46. }
  47. })
  48. }
  49. }
  50. }
  51. export { chartSettingMixins }