import { makeObservable, observable, action, autorun } from 'mobx'
import { cache } from '@zenview/micro-utils'
// import _ from 'lodash'

let instance = null
class pageStore {
	constructor() {
		makeObservable(this)
	}
	static getInstance() {
		!instance && (instance = new pageStore())
		return instance
	}
	@observable
	state = {
		isDesensitization: false
	}
	@action
	pageInit = autorun(() => {
		const isDesensitization = cache.getCache('isDesensitization', 'session')
		const desensitizationTime = cache.getCache('desensitizationTime', 'session')
    const isOverdue = Number(desensitizationTime) - new Date().getTime() > 0
		if(isOverdue){ // 时间没有过期，设置默认是否显示缓存
			this.setDesensitizationFun(isDesensitization)
		}else{ // 时间过期，前端禁止看加密信息
			this.setDesensitizationFun(false)
		}
	})
	@action
	setDesensitizationFun(boo){
		this.state.isDesensitization = boo
	}
}
export default pageStore