import Magix from 'magix' import * as View from '../../../../view' import reportHelper from '../helper' Magix.applyStyle('@./indicator-setting.less') const LOCALSTORAGE_IND_KEYS = '_dmp_reports_indicators_1' export default View.extend({ tmpl: '@indicator-setting.html', mixins: [reportHelper], init (options) { this.options = options }, async render () { // 获取指标 const indicators = await this._getAllIndicators() const defaultIndicators = indicators.filter(ind => ind.default).map(ind => ind.key) let selectedIndicators = defaultIndicators let isCustom = false // 如果localstorage里有,就用localstorage里的配置 if (window.localStorage.getItem(LOCALSTORAGE_IND_KEYS)) { const configKeys = window.localStorage.getItem(LOCALSTORAGE_IND_KEYS).split(',') selectedIndicators = configKeys isCustom = true } const max = this.options.max || 6 const min = this.options.min || 6 this.updater.digest({ isCustom, max, min, selectedIndicators, indicators, defaultIndicators }) }, // 供父view调用获取选中的指标 getIndicators (getDefaultInds) { const { selectedIndicators, indicators, isCustom, defaultIndicators } = this.updater.get() let _selectedIndicators = isCustom ? selectedIndicators : defaultIndicators // 人群列表的报表浮层指标固定用默认指标 if (getDefaultInds) { _selectedIndicators = defaultIndicators } const selected = [] for (const ind of _selectedIndicators) { selected.push(indicators.find(_ind => _ind.key === ind)) } // 配置储存在Localstorage里 window.localStorage.setItem(LOCALSTORAGE_IND_KEYS, selectedIndicators.join(',')) return { selectedIndicators: selected, indicators } } })