1 Star 1 Fork 1

aiv367 / aiv367-browser-config

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

aiv367-browser-config

介绍

通过浏览器本地存储(localStorage)存储用户设置,实现用户前端数据持久化功能。通常应用于带有用户设置功能的web系统。比如:软件设置,皮肤设置,页面大小设置等这类的功能。

配置模块采用 默认设置 和 用户设置 两部分,默认设置配置在开发代码中,用户设置会保存到本地存储中。实际开发过程中,也可以将用户配置一同保存到服务端存储。

安装

npm i aiv367-browser-config --save

示例

ES6 Module:

import config from 'aiv367-browser-config';

// 设置保存到本地存储的主键值,默认是appConfig
config.setting.localStorageName = 'myConfig'; 

// 默认设置数据,根据自己业务需求定义内部数据
config.setting.defaultConfig = {
	lang: 'zh-cn',
	app: {
		name: 'xxx 管理系统',
		skin: 'default',
		zoom: 1
	},
	dataset: {
		gender: [
			{value: 0, label: ''},
			{value: 1, label: ''},
			{value: 2, label: '其它'}
		]
	}
};

//修改设置(存储到本地)
config.set({lang: 'en'});
config.get();
/**
返回下面数据
{
	lang: 'en',
	app: {
		name: 'xxx 管理系统',
		skin: 'default',
		zoom: 1
	},
	dataset: {
		gender: [
			{value: 0, label: '男'},
			{value: 1, label: '女'},
			{value: 2, label: '其它'},
		]
	}
}
其中保存到本地存储的数据是
{lang: 'en'}
*/

config.set({
	dataset: genter[
		{value: 0, label: ''},
		{value: 1, label: ''}
	]
});
config.get();
/**
返回下面数据
{
	lang: 'en',
	app: {
		name: 'xxx 管理系统',
		skin: 'default',
		zoom: 1
	},
	dataset: {
		gender: [
			{value: 0, label: '雄'},
			{value: 1, label: '雌'}
		]
	}
}
其中保存到本地存储的数据是
{
	lang: 'en',
	dataset: {
		gender: [
			{value: 0, label: '雄'},
			{value: 1, label: '雌'}
		]
	}
}
*/

// 删除用户设置(user)中的设置
config.remove(userConfig => {
    delete userConfig.lang
})

一般开发时可以在外层再封装个模块,见如下:

// src/commonents/config.js
import config from 'aiv367-browser-config';

config.setting.localStorageName = 'myConfig';
config.setting.defaultConfig = {
    lang: 'zh-cn'
};

export default config;

文档

// 基本设置
config.setting = {
	localStorageName: 'appConfig',
	defaultConfig: {}
}

// 获取配置
// type = merge: 用户配置和默认配置融合结果 | user:用户配置 | default:默认配置
config.get(type = 'merge');

// 设置配置
config.set(obj);

// 重置默认配置(清除本地用户配置)
config.reset();
MIT License Copyright (c) 2022 aiv367 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

通过浏览器本地存储(localStorage)存储用户设置,实现用户前端持久化功能。通常应用于带有用户设置功能的web系统。比如:软件设置,皮肤设置,页面大小设置等这类的功能。 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/aiv367/aiv367-browser-config.git
git@gitee.com:aiv367/aiv367-browser-config.git
aiv367
aiv367-browser-config
aiv367-browser-config
master

搜索帮助