king
2023-08-18 57266ee8c62f0fddb42c18c705507fc0dc2416f6
src/mob/colorsketch/index.jsx
@@ -4,6 +4,7 @@
import { Popover } from 'antd'
import { CloseCircleFilled } from '@ant-design/icons'
import Api from '@/api'
import './index.scss'
const presetColors = [
@@ -12,6 +13,7 @@
  '#adc6ff', '#EBE9E9', '#d9d9d9', 'rgba(0, 0, 0, 0.65)', 'rgba(0, 0, 0, 0.85)', '#000000', '#ffffff', 'transparent'
]
const _href = window.location.href.split('#')[0]
let loading = false
class ColorSketch extends Component {
  static propTpyes = {
@@ -38,7 +40,39 @@
      initVal = value
    }
    let _colors = sessionStorage.getItem('app_colors')
    this.setState({color: initVal, initVal, allowClear: allowClear === true}, () => {
      this.checkcolors()
    })
  }
  checkcolors = () => {
    let app_colors = window.GLOB.app_colors
    if (app_colors) {
      this.getColors(app_colors)
    } else {
      if (loading) {
        this.getColors([])
      } else {
        loading = true
        let param = {
          func: 's_url_db_adduptdel',
          PageIndex: 0,  // 0 代表全部
          PageSize: 0,   // 0 代表全部
          typecharone: 'color',
          type: 'search'
        }
        Api.getCloudConfig(param).then(res => {
          loading = false
          window.GLOB.app_colors = res.data || []
          this.getColors(res.data || [])
        })
      }
    }
  }
  getColors = (appColors) => {
    let colors = JSON.parse(JSON.stringify(presetColors))
    let normal_colors = localStorage.getItem(_href + 'normal_colors')
@@ -56,19 +90,11 @@
      normal_colors = []
    }
    if (_colors) {
      try {
        _colors = JSON.parse(_colors)
      } catch (e) {
        _colors = []
      }
    appColors.forEach(item => {
      if (normal_colors.includes(item.linkurl)) return
      
      _colors.forEach(item => {
        if (normal_colors.includes(item.linkurl)) return
        colors.push({color: item.linkurl, title: '系统色:' + item.linkurl})
      })
    }
      colors.push({color: item.linkurl, title: '系统色:' + item.linkurl})
    })
    if (colors.length < 40) {
      for (let i = colors.length; i < 40; i++) {
@@ -76,7 +102,7 @@
      }
    }
    this.setState({color: initVal, initVal, allowClear: allowClear === true, colors})
    this.setState({colors})
  }
  handleChange = (color) => {
@@ -126,8 +152,6 @@
      localStorage.setItem(_href + 'normal_colors', JSON.stringify(normal_colors))
    }
  }
  render() {
    const { color, allowClear, colors } = this.state