m-tool-store 1.0.23 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,80 +1,80 @@
1
- import f from "dayjs";
2
- import { default as T } from "dayjs";
3
- import x from "lodash";
4
- import b from "axios";
1
+ import h from "dayjs";
2
+ import { default as N } from "dayjs";
3
+ import _ from "lodash";
4
+ import x from "axios";
5
5
  class R {
6
6
  //金额格式化 , 千分位
7
7
  static formatMoney(t, r) {
8
8
  if (t == null) return "";
9
9
  let e = Number(t);
10
10
  if (isNaN(e)) return t;
11
- let a = /([\-\+]?)(\d*)(\.\d+)?/g.exec("" + e), l = a && a[1] || "", n = (a && a[2] || "").split(""), o = a && a[3] || "", i = n.length % 3, c = n.reduce(function(u, h, g) {
12
- return g + 1 === i || (g + 1 - i) % 3 === 0 ? u + h + "," : u + h;
11
+ let a = /([\-\+]?)(\d*)(\.\d+)?/g.exec("" + e), l = a && a[1] || "", n = (a && a[2] || "").split(""), s = a && a[3] || "", i = n.length % 3, c = n.reduce(function(u, f, d) {
12
+ return d + 1 === i || (d + 1 - i) % 3 === 0 ? u + f + "," : u + f;
13
13
  }, "").replace(/\,$/g, "");
14
- return c === "" && (c = "0"), r != null && (r == 0 ? o && parseFloat(o) > 0.5 ? (o = "", c = parseInt(c) + 1 + "") : o = "" : r > 0 && (!o || o == "0" || o == ".0" ? o = "." + "0".repeat(r) : (o = parseFloat(o).toFixed(2), o >= "1" && (c = parseInt(c) + 1 + "", o = "." + "0".repeat(r)))), o = (o || "").replace("0.", ".")), l + c + o;
14
+ return c === "" && (c = "0"), r != null && (r == 0 ? s && parseFloat(s) > 0.5 ? (s = "", c = parseInt(c) + 1 + "") : s = "" : r > 0 && (!s || s == "0" || s == ".0" ? s = "." + "0".repeat(r) : (s = parseFloat(s).toFixed(2), s >= "1" && (c = parseInt(c) + 1 + "", s = "." + "0".repeat(r)))), s = (s || "").replace("0.", ".")), l + c + s;
15
15
  }
16
16
  }
17
- var d = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
18
- function Y(s) {
19
- return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
17
+ var g = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
18
+ function Y(o) {
19
+ return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
20
20
  }
21
21
  var p = { exports: {} };
22
- (function(s, t) {
22
+ (function(o, t) {
23
23
  (function(r, e) {
24
- s.exports = e();
25
- })(d, function() {
24
+ o.exports = e();
25
+ })(g, function() {
26
26
  return function(r, e) {
27
27
  e.prototype.weekday = function(a) {
28
- var l = this.$locale().weekStart || 0, n = this.$W, o = (n < l ? n + 7 : n) - l;
29
- return this.$utils().u(a) ? o : this.subtract(o, "day").add(a, "day");
28
+ var l = this.$locale().weekStart || 0, n = this.$W, s = (n < l ? n + 7 : n) - l;
29
+ return this.$utils().u(a) ? s : this.subtract(s, "day").add(a, "day");
30
30
  };
31
31
  };
32
32
  });
33
33
  })(p);
34
34
  var y = p.exports;
35
- const M = /* @__PURE__ */ Y(y);
36
- var k = { exports: {} };
37
- (function(s, t) {
35
+ const k = /* @__PURE__ */ Y(y);
36
+ var M = { exports: {} };
37
+ (function(o, t) {
38
38
  (function(r, e) {
39
- s.exports = e(f);
40
- })(d, function(r) {
39
+ o.exports = e(h);
40
+ })(g, function(r) {
41
41
  function e(n) {
42
42
  return n && typeof n == "object" && "default" in n ? n : { default: n };
43
43
  }
44
- var a = e(r), l = { name: "zh-cn", weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"), weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"), weekdaysMin: "日_一_二_三_四_五_六".split("_"), months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"), monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"), ordinal: function(n, o) {
45
- return o === "W" ? n + "周" : n + "日";
46
- }, weekStart: 1, yearStart: 4, formats: { LT: "HH:mm", LTS: "HH:mm:ss", L: "YYYY/MM/DD", LL: "YYYY年M月D日", LLL: "YYYY年M月D日Ah点mm分", LLLL: "YYYY年M月D日ddddAh点mm分", l: "YYYY/M/D", ll: "YYYY年M月D日", lll: "YYYY年M月D日 HH:mm", llll: "YYYY年M月D日dddd HH:mm" }, relativeTime: { future: "%s内", past: "%s前", s: "几秒", m: "1 分钟", mm: "%d 分钟", h: "1 小时", hh: "%d 小时", d: "1 天", dd: "%d 天", M: "1 个月", MM: "%d 个月", y: "1 年", yy: "%d 年" }, meridiem: function(n, o) {
47
- var i = 100 * n + o;
44
+ var a = e(r), l = { name: "zh-cn", weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"), weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"), weekdaysMin: "日_一_二_三_四_五_六".split("_"), months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"), monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"), ordinal: function(n, s) {
45
+ return s === "W" ? n + "周" : n + "日";
46
+ }, weekStart: 1, yearStart: 4, formats: { LT: "HH:mm", LTS: "HH:mm:ss", L: "YYYY/MM/DD", LL: "YYYY年M月D日", LLL: "YYYY年M月D日Ah点mm分", LLLL: "YYYY年M月D日ddddAh点mm分", l: "YYYY/M/D", ll: "YYYY年M月D日", lll: "YYYY年M月D日 HH:mm", llll: "YYYY年M月D日dddd HH:mm" }, relativeTime: { future: "%s内", past: "%s前", s: "几秒", m: "1 分钟", mm: "%d 分钟", h: "1 小时", hh: "%d 小时", d: "1 天", dd: "%d 天", M: "1 个月", MM: "%d 个月", y: "1 年", yy: "%d 年" }, meridiem: function(n, s) {
47
+ var i = 100 * n + s;
48
48
  return i < 600 ? "凌晨" : i < 900 ? "早上" : i < 1100 ? "上午" : i < 1300 ? "中午" : i < 1800 ? "下午" : "晚上";
49
49
  } };
50
50
  return a.default.locale(l, null, !0), l;
51
51
  });
52
- })(k);
53
- f.extend(M);
54
- f.locale("zh-cn");
55
- const D = (s, t = "YYYY-MM-DD") => f(s).format(t), L = (s) => (console.log("🌸 信息输出 ~ testFunc ~ record:", s), "testFunc");
56
- function q() {
57
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(s) {
52
+ })(M);
53
+ h.extend(k);
54
+ h.locale("zh-cn");
55
+ const L = (o, t = "YYYY-MM-DD") => h(o).format(t), D = (o) => (console.log("🌸 信息输出 ~ testFunc ~ record:", o), "testFunc");
56
+ function U() {
57
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(o) {
58
58
  const t = Math.random() * 16 | 0;
59
- return (s == "x" ? t : t & 3 | 8).toString(16);
59
+ return (o == "x" ? t : t & 3 | 8).toString(16);
60
60
  });
61
61
  }
62
- function v() {
62
+ function q() {
63
63
  return Date.now().toString(36) + Math.random().toString(36).substr(2);
64
64
  }
65
- function H() {
65
+ function v() {
66
66
  return "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
67
67
  }
68
- function I(s = 1) {
68
+ function I(o = 1) {
69
69
  const t = Math.floor(Math.random() * 256), r = Math.floor(Math.random() * 256), e = Math.floor(Math.random() * 256);
70
- return `rgba(${t}, ${r}, ${e}, ${s})`;
70
+ return `rgba(${t}, ${r}, ${e}, ${o})`;
71
71
  }
72
- const j = x;
72
+ const H = _;
73
73
  class m {
74
74
  constructor(t) {
75
75
  this.globalCallbacks = {};
76
76
  const { callbacks: r, ...e } = t || {};
77
- this.globalCallbacks = r || {}, this.instance = b.create({
77
+ this.globalCallbacks = r || {}, this.instance = x.create({
78
78
  baseURL: (e == null ? void 0 : e.baseURL) || "",
79
79
  timeout: 1e4,
80
80
  // 默认超时时间
@@ -95,14 +95,14 @@ class m {
95
95
  }
96
96
  ), this.instance.interceptors.response.use(
97
97
  (t) => {
98
- var e, a, l, n, o, i, c, u;
98
+ var e, a, l, n, s, i, c, u;
99
99
  (a = (e = this.globalCallbacks).onRequestEnd) == null || a.call(e, t.config);
100
100
  const r = t.config;
101
- return (n = (l = r.callbacks) == null ? void 0 : l.onRequestEnd) == null || n.call(l, t.config), (i = (o = this.globalCallbacks).onResponseSuccess) == null || i.call(o, t), (u = (c = r.callbacks) == null ? void 0 : c.onResponseSuccess) == null || u.call(c, t), t;
101
+ return (n = (l = r.callbacks) == null ? void 0 : l.onRequestEnd) == null || n.call(l, t.config), (i = (s = this.globalCallbacks).onResponseSuccess) == null || i.call(s, t), (u = (c = r.callbacks) == null ? void 0 : c.onResponseSuccess) == null || u.call(c, t), t == null ? void 0 : t.data;
102
102
  },
103
103
  (t) => {
104
- var r, e, a, l, n, o, i, c;
105
- return t.config && ((e = (r = this.globalCallbacks).onRequestEnd) == null || e.call(r, t.config), (l = (a = t.config.callbacks) == null ? void 0 : a.onRequestEnd) == null || l.call(a, t.config)), (o = (n = this.globalCallbacks).onResponseError) == null || o.call(n, t), t.config && ((c = (i = t.config.callbacks) == null ? void 0 : i.onResponseError) == null || c.call(i, t)), Promise.reject(t);
104
+ var r, e, a, l, n, s, i, c;
105
+ return t.config && ((e = (r = this.globalCallbacks).onRequestEnd) == null || e.call(r, t.config), (l = (a = t.config.callbacks) == null ? void 0 : a.onRequestEnd) == null || l.call(a, t.config)), (s = (n = this.globalCallbacks).onResponseError) == null || s.call(n, t), t.config && ((c = (i = t.config.callbacks) == null ? void 0 : i.onResponseError) == null || c.call(i, t)), Promise.reject(t);
106
106
  }
107
107
  );
108
108
  }
@@ -125,9 +125,32 @@ class m {
125
125
  patch(t, r, e) {
126
126
  return this.instance.patch(t, r, e);
127
127
  }
128
+ /**
129
+ * 更新全局配置
130
+ * @param config 新的配置
131
+ */
132
+ updateConfig(t) {
133
+ const { callbacks: r, ...e } = t;
134
+ r && (this.globalCallbacks = { ...this.globalCallbacks, ...r }), e.baseURL && (this.instance.defaults.baseURL = e.baseURL), e.timeout && (this.instance.defaults.timeout = e.timeout), e.headers && (this.instance.defaults.headers = {
135
+ ...this.instance.defaults.headers,
136
+ ...e.headers
137
+ });
138
+ }
139
+ setToken(t, r = "Authorization", e = "Bearer ") {
140
+ this.instance.defaults.headers[r] = e + t;
141
+ }
142
+ removeToken(t = "Authorization") {
143
+ delete this.instance.defaults.headers[t];
144
+ }
145
+ updateGlobalCallbacks(t) {
146
+ this.globalCallbacks = { ...this.globalCallbacks, ...t };
147
+ }
148
+ getInstance() {
149
+ return this.instance;
150
+ }
128
151
  }
129
- const E = new m(), U = (s) => new m(s);
130
- class _ {
152
+ const j = new m(), E = (o) => new m(o);
153
+ class b {
131
154
  constructor(t = "local") {
132
155
  this.storage = t === "local" ? localStorage : sessionStorage;
133
156
  }
@@ -207,21 +230,21 @@ class _ {
207
230
  return this.storage.length;
208
231
  }
209
232
  }
210
- const $ = new _("local"), F = new _("session");
233
+ const $ = new b("local"), F = new b("session");
211
234
  export {
212
235
  R as FormatterUtils,
213
236
  m as Http,
214
- _ as StorageUtil,
215
- U as createHttp,
216
- T as dayjs,
217
- D as formatDate,
218
- q as generateUUID,
219
- v as generateUniqueId,
220
- H as getRandomColor,
237
+ b as StorageUtil,
238
+ E as createHttp,
239
+ N as dayjs,
240
+ L as formatDate,
241
+ U as generateUUID,
242
+ q as generateUniqueId,
243
+ v as getRandomColor,
221
244
  I as getRandomRgbaColor,
222
- E as http,
245
+ j as http,
223
246
  $ as localStorageUtil,
224
- j as lodash,
247
+ H as lodash,
225
248
  F as sessionStorageUtil,
226
- L as testFunc
249
+ D as testFunc
227
250
  };
@@ -1 +1 @@
1
- (function(s,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("dayjs"),require("lodash"),require("axios")):typeof define=="function"&&define.amd?define(["exports","dayjs","lodash","axios"],f):(s=typeof globalThis<"u"?globalThis:s||self,f(s.MToolStore={},s.dayjs,s._,s.axios))})(this,function(s,f,y,Y){"use strict";class S{static formatMoney(t,n){if(t==null)return"";let e=Number(t);if(isNaN(e))return t;let l=/([\-\+]?)(\d*)(\.\d+)?/g.exec(""+e),i=l&&l[1]||"",o=(l&&l[2]||"").split(""),r=l&&l[3]||"",c=o.length%3,u=o.reduce(function(d,_,b){return b+1===c||(b+1-c)%3===0?d+_+",":d+_},"").replace(/\,$/g,"");return u===""&&(u="0"),n!=null&&(n==0?r&&parseFloat(r)>.5?(r="",u=parseInt(u)+1+""):r="":n>0&&(!r||r=="0"||r==".0"?r="."+"0".repeat(n):(r=parseFloat(r).toFixed(2),r>="1"&&(u=parseInt(u)+1+"",r="."+"0".repeat(n)))),r=(r||"").replace("0.",".")),i+u+r}}var m=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function x(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var p={exports:{}};(function(a,t){(function(n,e){a.exports=e()})(m,function(){return function(n,e){e.prototype.weekday=function(l){var i=this.$locale().weekStart||0,o=this.$W,r=(o<i?o+7:o)-i;return this.$utils().u(l)?r:this.subtract(r,"day").add(l,"day")}}})})(p);var M=p.exports;const k=x(M);var C={exports:{}};(function(a,t){(function(n,e){a.exports=e(f)})(m,function(n){function e(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var l=e(n),i={name:"zh-cn",weekdays:"星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),weekdaysShort:"周日_周一_周二_周三_周四_周五_周六".split("_"),weekdaysMin:"日_一_二_三_四_五_六".split("_"),months:"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),monthsShort:"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),ordinal:function(o,r){return r==="W"?o+"周":o+"日"},weekStart:1,yearStart:4,formats:{LT:"HH:mm",LTS:"HH:mm:ss",L:"YYYY/MM/DD",LL:"YYYY年M月D日",LLL:"YYYY年M月D日Ah点mm分",LLLL:"YYYY年M月D日ddddAh点mm分",l:"YYYY/M/D",ll:"YYYY年M月D日",lll:"YYYY年M月D日 HH:mm",llll:"YYYY年M月D日dddd HH:mm"},relativeTime:{future:"%s内",past:"%s前",s:"几秒",m:"1 分钟",mm:"%d 分钟",h:"1 小时",hh:"%d 小时",d:"1 天",dd:"%d 天",M:"1 个月",MM:"%d 个月",y:"1 年",yy:"%d 年"},meridiem:function(o,r){var c=100*o+r;return c<600?"凌晨":c<900?"早上":c<1100?"上午":c<1300?"中午":c<1800?"下午":"晚上"}};return l.default.locale(i,null,!0),i})})(C),f.extend(k),f.locale("zh-cn");const w=(a,t="YYYY-MM-DD")=>f(a).format(t),R=a=>(console.log("🌸 信息输出 ~ testFunc ~ record:",a),"testFunc");function D(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){const t=Math.random()*16|0;return(a=="x"?t:t&3|8).toString(16)})}function U(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}function q(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function L(a=1){const t=Math.floor(Math.random()*256),n=Math.floor(Math.random()*256),e=Math.floor(Math.random()*256);return`rgba(${t}, ${n}, ${e}, ${a})`}const H=y;class h{constructor(t){this.globalCallbacks={};const{callbacks:n,...e}=t||{};this.globalCallbacks=n||{},this.instance=Y.create({baseURL:(e==null?void 0:e.baseURL)||"",timeout:1e4,...e}),this.setupInterceptors()}setupInterceptors(){this.instance.interceptors.request.use(t=>{var e,l,i,o;return(l=(e=this.globalCallbacks).onRequestStart)==null||l.call(e,t),(o=(i=t.callbacks)==null?void 0:i.onRequestStart)==null||o.call(i,t),t},t=>{var n,e;return(e=(n=this.globalCallbacks).onRequestError)==null||e.call(n,t),Promise.reject(t)}),this.instance.interceptors.response.use(t=>{var e,l,i,o,r,c,u,d;(l=(e=this.globalCallbacks).onRequestEnd)==null||l.call(e,t.config);const n=t.config;return(o=(i=n.callbacks)==null?void 0:i.onRequestEnd)==null||o.call(i,t.config),(c=(r=this.globalCallbacks).onResponseSuccess)==null||c.call(r,t),(d=(u=n.callbacks)==null?void 0:u.onResponseSuccess)==null||d.call(u,t),t},t=>{var n,e,l,i,o,r,c,u;return t.config&&((e=(n=this.globalCallbacks).onRequestEnd)==null||e.call(n,t.config),(i=(l=t.config.callbacks)==null?void 0:l.onRequestEnd)==null||i.call(l,t.config)),(r=(o=this.globalCallbacks).onResponseError)==null||r.call(o,t),t.config&&((u=(c=t.config.callbacks)==null?void 0:c.onResponseError)==null||u.call(c,t)),Promise.reject(t)})}request(t){return this.instance.request(t)}get(t,n){return this.instance.get(t,n)}post(t,n,e){return this.instance.post(t,n,e)}put(t,n,e){return this.instance.put(t,n,e)}delete(t,n){return this.instance.delete(t,n)}patch(t,n,e){return this.instance.patch(t,n,e)}}const I=new h,v=a=>new h(a);class g{constructor(t="local"){this.storage=t==="local"?localStorage:sessionStorage}set(t,n){try{const e=typeof n=="string"?n:JSON.stringify(n);this.storage.setItem(t,e)}catch(e){console.error("Storage set error:",e)}}get(t,n=null){try{const e=this.storage.getItem(t);if(e===null)return n;try{return JSON.parse(e)}catch{return e}}catch(e){return console.error("Storage get error:",e),n}}remove(t){try{this.storage.removeItem(t)}catch(n){console.error("Storage remove error:",n)}}clear(){try{this.storage.clear()}catch(t){console.error("Storage clear error:",t)}}has(t){return this.storage.getItem(t)!==null}keys(){return Object.keys(this.storage)}length(){return this.storage.length}}const F=new g("local"),j=new g("session");s.dayjs=f,s.FormatterUtils=S,s.Http=h,s.StorageUtil=g,s.createHttp=v,s.formatDate=w,s.generateUUID=D,s.generateUniqueId=U,s.getRandomColor=q,s.getRandomRgbaColor=L,s.http=I,s.localStorageUtil=F,s.lodash=H,s.sessionStorageUtil=j,s.testFunc=R,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("dayjs"),require("lodash"),require("axios")):typeof define=="function"&&define.amd?define(["exports","dayjs","lodash","axios"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.MToolStore={},s.dayjs,s._,s.axios))})(this,function(s,h,y,Y){"use strict";class k{static formatMoney(t,n){if(t==null)return"";let e=Number(t);if(isNaN(e))return t;let i=/([\-\+]?)(\d*)(\.\d+)?/g.exec(""+e),l=i&&i[1]||"",o=(i&&i[2]||"").split(""),a=i&&i[3]||"",c=o.length%3,u=o.reduce(function(d,b,_){return _+1===c||(_+1-c)%3===0?d+b+",":d+b},"").replace(/\,$/g,"");return u===""&&(u="0"),n!=null&&(n==0?a&&parseFloat(a)>.5?(a="",u=parseInt(u)+1+""):a="":n>0&&(!a||a=="0"||a==".0"?a="."+"0".repeat(n):(a=parseFloat(a).toFixed(2),a>="1"&&(u=parseInt(u)+1+"",a="."+"0".repeat(n)))),a=(a||"").replace("0.",".")),l+u+a}}var m=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function S(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var p={exports:{}};(function(r,t){(function(n,e){r.exports=e()})(m,function(){return function(n,e){e.prototype.weekday=function(i){var l=this.$locale().weekStart||0,o=this.$W,a=(o<l?o+7:o)-l;return this.$utils().u(i)?a:this.subtract(a,"day").add(i,"day")}}})})(p);var x=p.exports;const M=S(x);var C={exports:{}};(function(r,t){(function(n,e){r.exports=e(h)})(m,function(n){function e(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var i=e(n),l={name:"zh-cn",weekdays:"星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),weekdaysShort:"周日_周一_周二_周三_周四_周五_周六".split("_"),weekdaysMin:"日_一_二_三_四_五_六".split("_"),months:"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),monthsShort:"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),ordinal:function(o,a){return a==="W"?o+"周":o+"日"},weekStart:1,yearStart:4,formats:{LT:"HH:mm",LTS:"HH:mm:ss",L:"YYYY/MM/DD",LL:"YYYY年M月D日",LLL:"YYYY年M月D日Ah点mm分",LLLL:"YYYY年M月D日ddddAh点mm分",l:"YYYY/M/D",ll:"YYYY年M月D日",lll:"YYYY年M月D日 HH:mm",llll:"YYYY年M月D日dddd HH:mm"},relativeTime:{future:"%s内",past:"%s前",s:"几秒",m:"1 分钟",mm:"%d 分钟",h:"1 小时",hh:"%d 小时",d:"1 天",dd:"%d 天",M:"1 个月",MM:"%d 个月",y:"1 年",yy:"%d 年"},meridiem:function(o,a){var c=100*o+a;return c<600?"凌晨":c<900?"早上":c<1100?"上午":c<1300?"中午":c<1800?"下午":"晚上"}};return i.default.locale(l,null,!0),l})})(C),h.extend(M),h.locale("zh-cn");const R=(r,t="YYYY-MM-DD")=>h(r).format(t),w=r=>(console.log("🌸 信息输出 ~ testFunc ~ record:",r),"testFunc");function U(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const t=Math.random()*16|0;return(r=="x"?t:t&3|8).toString(16)})}function D(){return Date.now().toString(36)+Math.random().toString(36).substr(2)}function L(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function q(r=1){const t=Math.floor(Math.random()*256),n=Math.floor(Math.random()*256),e=Math.floor(Math.random()*256);return`rgba(${t}, ${n}, ${e}, ${r})`}const I=y;class f{constructor(t){this.globalCallbacks={};const{callbacks:n,...e}=t||{};this.globalCallbacks=n||{},this.instance=Y.create({baseURL:(e==null?void 0:e.baseURL)||"",timeout:1e4,...e}),this.setupInterceptors()}setupInterceptors(){this.instance.interceptors.request.use(t=>{var e,i,l,o;return(i=(e=this.globalCallbacks).onRequestStart)==null||i.call(e,t),(o=(l=t.callbacks)==null?void 0:l.onRequestStart)==null||o.call(l,t),t},t=>{var n,e;return(e=(n=this.globalCallbacks).onRequestError)==null||e.call(n,t),Promise.reject(t)}),this.instance.interceptors.response.use(t=>{var e,i,l,o,a,c,u,d;(i=(e=this.globalCallbacks).onRequestEnd)==null||i.call(e,t.config);const n=t.config;return(o=(l=n.callbacks)==null?void 0:l.onRequestEnd)==null||o.call(l,t.config),(c=(a=this.globalCallbacks).onResponseSuccess)==null||c.call(a,t),(d=(u=n.callbacks)==null?void 0:u.onResponseSuccess)==null||d.call(u,t),t==null?void 0:t.data},t=>{var n,e,i,l,o,a,c,u;return t.config&&((e=(n=this.globalCallbacks).onRequestEnd)==null||e.call(n,t.config),(l=(i=t.config.callbacks)==null?void 0:i.onRequestEnd)==null||l.call(i,t.config)),(a=(o=this.globalCallbacks).onResponseError)==null||a.call(o,t),t.config&&((u=(c=t.config.callbacks)==null?void 0:c.onResponseError)==null||u.call(c,t)),Promise.reject(t)})}request(t){return this.instance.request(t)}get(t,n){return this.instance.get(t,n)}post(t,n,e){return this.instance.post(t,n,e)}put(t,n,e){return this.instance.put(t,n,e)}delete(t,n){return this.instance.delete(t,n)}patch(t,n,e){return this.instance.patch(t,n,e)}updateConfig(t){const{callbacks:n,...e}=t;n&&(this.globalCallbacks={...this.globalCallbacks,...n}),e.baseURL&&(this.instance.defaults.baseURL=e.baseURL),e.timeout&&(this.instance.defaults.timeout=e.timeout),e.headers&&(this.instance.defaults.headers={...this.instance.defaults.headers,...e.headers})}setToken(t,n="Authorization",e="Bearer "){this.instance.defaults.headers[n]=e+t}removeToken(t="Authorization"){delete this.instance.defaults.headers[t]}updateGlobalCallbacks(t){this.globalCallbacks={...this.globalCallbacks,...t}}getInstance(){return this.instance}}const v=new f,H=r=>new f(r);class g{constructor(t="local"){this.storage=t==="local"?localStorage:sessionStorage}set(t,n){try{const e=typeof n=="string"?n:JSON.stringify(n);this.storage.setItem(t,e)}catch(e){console.error("Storage set error:",e)}}get(t,n=null){try{const e=this.storage.getItem(t);if(e===null)return n;try{return JSON.parse(e)}catch{return e}}catch(e){return console.error("Storage get error:",e),n}}remove(t){try{this.storage.removeItem(t)}catch(n){console.error("Storage remove error:",n)}}clear(){try{this.storage.clear()}catch(t){console.error("Storage clear error:",t)}}has(t){return this.storage.getItem(t)!==null}keys(){return Object.keys(this.storage)}length(){return this.storage.length}}const T=new g("local"),F=new g("session");s.dayjs=h,s.FormatterUtils=k,s.Http=f,s.StorageUtil=g,s.createHttp=H,s.formatDate=R,s.generateUUID=U,s.generateUniqueId=D,s.getRandomColor=L,s.getRandomRgbaColor=q,s.http=v,s.localStorageUtil=T,s.lodash=I,s.sessionStorageUtil=F,s.testFunc=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "m-tool-store",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "JavaScript 工具库",
5
5
  "type": "module",
6
6
  "author": "Mmm",
package/types/utils.d.ts CHANGED
@@ -161,6 +161,38 @@ export declare class Http {
161
161
  * @returns Promise<T>
162
162
  */
163
163
  patch<T = any>(url: string, data?: any, config?: HttpConfig): Promise<T>
164
+
165
+ /**
166
+ * 更新全局配置
167
+ * @param config 新的配置
168
+ */
169
+ updateConfig(config: Partial<HttpConfig>): void
170
+
171
+ /**
172
+ * 设置认证token
173
+ * @param token 认证token
174
+ * @param headerName token在请求头中的名称,默认为'Authorization'
175
+ * @param tokenPrefix token前缀,默认为'Bearer '
176
+ */
177
+ setToken(token: string, headerName?: string, tokenPrefix?: string): void
178
+
179
+ /**
180
+ * 移除认证token
181
+ * @param headerName token在请求头中的名称,默认为'Authorization'
182
+ */
183
+ removeToken(headerName?: string): void
184
+
185
+ /**
186
+ * 更新全局回调函数
187
+ * @param callbacks 回调函数配置
188
+ */
189
+ updateGlobalCallbacks(callbacks: Partial<HttpCallbacks>): void
190
+
191
+ /**
192
+ * 获取axios实例
193
+ * @returns AxiosInstance
194
+ */
195
+ getInstance(): AxiosInstance
164
196
  }
165
197
 
166
198
  /**