3 Commits

Author SHA1 Message Date
曾文豪
d7049f646f feat(utils): 添加存储前缀配置并更新存储逻辑 2025-09-02 09:16:43 +08:00
曾文豪
f2ff19f17b feat(utils): 添加存储前缀配置并更新存储逻辑 2025-09-02 09:10:53 +08:00
曾文豪
eb89dd4a48 chore:1.0.17 2025-08-28 13:51:55 +08:00
4 changed files with 33 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@tiesheng/npm-tool",
"version": "1.0.16",
"version": "1.0.20",
"description": "npm tool package",
"main": "index.js",
"scripts": {

View File

@@ -77,13 +77,15 @@ const dealParamsBody = (options) => {
* @returns {Promise<<any>>}
*/
async function req(url, options) {
let {prefix} = GlobalConfig.getConfig();
let {prefix, urlDeal} = GlobalConfig.getConfig();
if (typeof prefix === "function") {
prefix = prefix(url);
}
if (prefix) {
url = prefix + url;
}
url = urlDeal(url)
return new Promise((resolve, reject) => {
request(url, {
...dealParamsBody(options),

View File

@@ -5,6 +5,12 @@
const defaultConfig = {
base64Key: "WmdUzPJXbngVNiaSsQrihg==",
prefix: "",
storePrefix: () => {
return "";
},
urlDeal: (url) => {
return url;
},
onHttpError: (res) => {
}
}

View File

@@ -1,4 +1,5 @@
const Common = require("./Common");
const GlobalConfig = require("./GlobalConfig");
///////////////////////////////////////// 用户token
@@ -22,6 +23,19 @@ const getEncryptBody = () => {
return get("encrypt_body", true)
}
/**
* 重构key
* @param key
* @returns {*}
*/
const wrapKey = (key) => {
const {storePrefix} = GlobalConfig.getConfig()
if (typeof storePrefix == 'function') {
key = storePrefix(key) + key
}
return key
}
/**
* 保存数据
@@ -29,7 +43,7 @@ const getEncryptBody = () => {
* @param value
*/
const save = (key, value) => {
localStorage.setItem(key, JSON.stringify({data: value}));
localStorage.setItem(wrapKey(key), JSON.stringify({data: value}));
};
/**
@@ -39,7 +53,7 @@ const save = (key, value) => {
* @returns {string}
*/
const get = (key, def = "") => {
return Common.parseJSON(localStorage.getItem(key), {data: def}).data;
return Common.parseJSON(localStorage.getItem(wrapKey(key)), {data: def}).data;
};
///////////////////////////////////////// 导出模块