stroage.js 740 Bytes
function setItem(key, value, module_name) {
	if (module_name) {
		let module_name_info = getItem(module_name) || {};
		module_name_info[key] = value;
		try {
			wx.setStorageSync(module_name, module_name_info);
		} catch (e) {
			wx.setStorage({
				key: module_name,
				data: module_name_info
			})
		}
	} else {
		try {
			wx.setStorageSync(key, value);
		} catch (e) {
			wx.setStorage({
				key: key,
				data: value
			})
		}
	}
}

function getItem(key, module_name) {
	if (module_name) {
		let val = getItem(module_name);
		if (val) return val[key];
		return '';
	}
	return wx.getStorageSync(key)
}

function clear(name) {
	name ? wx.removeStorageSync(name) : wx.clearStorageSync()
}

module.exports = {
	setItem,
	getItem,
	clear
}