//设置cookie
function setCookie(c_name, value, expiredays) {
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) +
		((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}

//取回cookie
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		var c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1
			var c_end = document.cookie.indexOf(";", c_start)
			if (c_end == -1) c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end))
		}
	}
	return ""
}

//删除cookie
function delCookie(name) {
	var exdate = new Date();
	exdate.setTime(exdate.getTime() - 1);
	var cval = getCookie(name);
	if (cval != null)
		document.cookie = name + "=" + escape(cval) + ";expires=" + exdate.toGMTString();
}


const prefix = ''
const engine = window.localStorage

export const get = key => !engine.getItem(prefix + key) ? null : JSON.parse(engine.getItem(prefix + key))

export const set = (key, value) => !value ? remove(key) : engine.setItem(prefix + key, JSON.stringify(value))

export const remove = key => engine.removeItem(prefix + key)


//export const get = key => !getCookie(prefix + key) ? null : JSON.parse(getCookie(prefix + key))

//export const set = (key, value) => !value ? delCookie(key) : setCookie(prefix + key, JSON.stringify(value))

//export const remove = key => delCookie(prefix + key)



export const clear = () => engine.clear()

export const getOpenId = () => get('wx_openid')

export const setOpenId = (data) => set('wx_openid', data)

export const setToken = (token) => set('token', token)

export const getToken = () => get('token')

export const setPersonData = (channel, data) => set(channel + '_person_data', data)

export const getPersonData = (channel) => get(channel + '_person_data')

export const setPersonPopedom = (channel, data) => set(channel + '_person_popedom', data)

export const getPersonPopedom = (channel) => get(channel + '_person_popedom')

export const setPersonTemp = (channel, data) => set(channel + '_person_temp', data)

export const getPersonTemp = (channel) => get(channel + '_person_temp')

export const setMenuList = (channel, data) => set(channel + '_menu_list', data)

export const getMenuList = (channel) => get(channel + '_menu_list')

export const setCommonMenuList = (channel, data) => set(channel + '_common_menu_list', data)

export const getCommonMenuList = (channel) => get(channel + '_common_menu_list')

export const setFunList = (channel, data) => set(channel + '_fun_list', data)

export const getFunList = (channel) => get(channel + '_fun_list')

export const setRegisterFormData = (channel, data) => set(channel + '_register_form_data', data)

export const getRegisterFormData = (channel) => get(channel + '_register_form_data')

export const setAppVersion = (channel, data) => set(channel + '_app_vesion', data)

export const getAppVersion = (channel) => get(channel + '_app_vesion')

export const setPersionHomeModel = (channel, data) => set(channel + '_persion_home_model', data)

export const getPersionHomeModel = (channel) => get(channel + '_persion_home_model')

export const setOldRelationFormData = (channel, data) => set(channel + '_old_relation_form_data', data)

export const getOldRelationFormData = (channel) => get(channel + '_old_relation_form_data')

export const getWxPayBackUrl = (channel) => get(channel + '_wx_pay_back_url')

export const setWxPayBackUrl = (channel, data) => set(channel + '_wx_pay_back_url', data)

export const getWdMessageNum = (channel) => get(channel + '_wd_message_num')

export const setWdMessageNum = (channel, data) => set(channel + '_wd_message_num', data)