@whitesev/utils 2.4.5 → 2.4.7

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.
@@ -101,7 +101,7 @@ declare class Httpx {
101
101
  * @param url 网址
102
102
  * @param details 配置
103
103
  */
104
- post<T extends HttpxRequestOption>(url: string, details: T): HttpxPromise<HttpxResponse<T>>;
104
+ post<T = HttpxRequestOption>(url: string, details: T): HttpxPromise<HttpxResponse<T>>;
105
105
  /**
106
106
  * HEAD 请求
107
107
  * @param details 配置
@@ -13,10 +13,10 @@ import type { DOMUtils_EventType } from "./types/Event";
13
13
  import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
14
14
  import { Vue } from "./Vue";
15
15
  import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
16
- import type { UtilsWindowApiOption } from "./types/WindowApi";
16
+ import type { WindowApiOption } from "./types/WindowApi";
17
17
  declare class Utils {
18
18
  private windowApi;
19
- constructor(option?: UtilsWindowApiOption);
19
+ constructor(option?: WindowApiOption);
20
20
  /** 版本号 */
21
21
  version: string;
22
22
  /**
@@ -1720,7 +1720,7 @@ declare class Utils {
1720
1720
  * @param option
1721
1721
  * @returns
1722
1722
  */
1723
- createUtils(option?: UtilsWindowApiOption): Utils;
1723
+ createUtils(option?: WindowApiOption): Utils;
1724
1724
  /**
1725
1725
  * 将对象转换为FormData
1726
1726
  * @param data 待转换的对象
@@ -1751,6 +1751,15 @@ declare class Utils {
1751
1751
  generateUUID: () => string;
1752
1752
  /**
1753
1753
  * 自定义的动态响应对象
1754
+ * @example
1755
+ * let vue = new Utils.Vue();
1756
+ * let reactive = new vue.reactive({});
1757
+ * vue.watch(()=>reactive["name"], (newValue, oldValue)=>{
1758
+ * console.log("newValue ==> " + newValue);
1759
+ * console.log("oldValue ==> " + oldValue);
1760
+ * })
1761
+ * vue["name"] = "测试";
1762
+ * > "测试"
1754
1763
  */
1755
1764
  Vue: typeof Vue;
1756
1765
  }
@@ -5,11 +5,24 @@ declare class GMMenu {
5
5
  constructor(details: UtilsGMMenuConstructorOptions);
6
6
  /**
7
7
  * 新增菜单数据
8
- * @param paramData
8
+ * @param menuOption
9
9
  */
10
- add(paramData: UtilsGMMenuOption[] | UtilsGMMenuOption): void;
10
+ private __add;
11
+ /**
12
+ * 新增菜单数据
13
+ *
14
+ * 自动调用.update()
15
+ * @param menuOption
16
+ */
17
+ add(menuOption: UtilsGMMenuOption[] | UtilsGMMenuOption): void;
11
18
  /**
12
19
  * 更新菜单数据
20
+ *
21
+ * 实现方式:先取消注册所有已注册的菜单、再依次注册所有菜单项
22
+ *
23
+ * 如果菜单不存在,新增菜单项
24
+ *
25
+ * 如果菜单已存在,新菜单项覆盖旧的菜单项
13
26
  * @param options 数据
14
27
  */
15
28
  update(options?: UtilsGMMenuOption[] | UtilsGMMenuOption): void;
@@ -21,6 +34,7 @@ declare class GMMenu {
21
34
  /**
22
35
  * 根据键值获取enable值
23
36
  * @param menuKey 菜单-键key
37
+ * @deprecated
24
38
  */
25
39
  get(menuKey: string): boolean;
26
40
  /**
@@ -1,10 +1,10 @@
1
- import type { UtilsWindowApiOption } from "./types/WindowApi";
1
+ import type { WindowApiOption } from "./types/WindowApi";
2
2
  declare class WindowApi {
3
3
  /** 默认的配置 */
4
4
  private defaultApi;
5
5
  /** 使用的配置 */
6
6
  private api;
7
- constructor(option?: UtilsWindowApiOption);
7
+ constructor(option?: WindowApiOption);
8
8
  get document(): Document;
9
9
  get window(): Window & typeof globalThis;
10
10
  get globalThis(): typeof globalThis | Window;
@@ -58,7 +58,7 @@ export interface UtilsGMMenuOptionData {
58
58
  * 对isStoreValue进行处理,如果未赋值,按默认的true赋值
59
59
  * 新增一个deleteMenu
60
60
  */
61
- handleData: UtilsGMMenuHandledOption;
61
+ handleData?: UtilsGMMenuHandledOption;
62
62
  }
63
63
 
64
64
  export interface UtilsGMMenuConstructorOptions {
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * 配置类型
3
3
  */
4
- export type UtilsWindowApiOption = {
4
+ export type WindowApiOption = {
5
5
  document: Document;
6
6
  window: Window & typeof globalThis;
7
- globalThis: typeof globalThis | Window;
8
- self: Window & typeof globalThis;
7
+ globalThis?: typeof globalThis | Window;
8
+ self?: Window & typeof globalThis;
9
9
  top: Window;
10
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.4.5",
3
+ "version": "2.4.7",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Utils.ts CHANGED
@@ -21,15 +21,15 @@ import {
21
21
  type JSTypeNames,
22
22
  type UtilsOwnObject,
23
23
  } from "./types/global";
24
- import type { UtilsWindowApiOption } from "./types/WindowApi";
24
+ import type { WindowApiOption } from "./types/WindowApi";
25
25
 
26
26
  class Utils {
27
- private windowApi: WindowApi;
28
- constructor(option?: UtilsWindowApiOption) {
27
+ private windowApi: typeof WindowApi.prototype;
28
+ constructor(option?: WindowApiOption) {
29
29
  this.windowApi = new WindowApi(option);
30
30
  }
31
31
  /** 版本号 */
32
- version = "2024.11.1";
32
+ version = "2024.11.6";
33
33
 
34
34
  /**
35
35
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -4978,7 +4978,7 @@ class Utils {
4978
4978
  * @param option
4979
4979
  * @returns
4980
4980
  */
4981
- createUtils(option?: UtilsWindowApiOption) {
4981
+ createUtils(option?: WindowApiOption) {
4982
4982
  return new Utils(option);
4983
4983
  }
4984
4984
 
@@ -5052,6 +5052,15 @@ class Utils {
5052
5052
  generateUUID = GenerateUUID;
5053
5053
  /**
5054
5054
  * 自定义的动态响应对象
5055
+ * @example
5056
+ * let vue = new Utils.Vue();
5057
+ * let reactive = new vue.reactive({});
5058
+ * vue.watch(()=>reactive["name"], (newValue, oldValue)=>{
5059
+ * console.log("newValue ==> " + newValue);
5060
+ * console.log("oldValue ==> " + oldValue);
5061
+ * })
5062
+ * vue["name"] = "测试";
5063
+ * > "测试"
5055
5064
  */
5056
5065
  Vue = Vue;
5057
5066
  }
@@ -262,41 +262,58 @@ class GMMenu {
262
262
  }
263
263
  /**
264
264
  * 新增菜单数据
265
- * @param paramData
265
+ * @param menuOption
266
266
  */
267
- add(paramData: UtilsGMMenuOption[] | UtilsGMMenuOption) {
268
- if (Array.isArray(paramData)) {
269
- for (const _paramData of paramData) {
270
- // @ts-ignore
267
+ private __add(menuOption: UtilsGMMenuOption[] | UtilsGMMenuOption) {
268
+ if (Array.isArray(menuOption)) {
269
+ for (let index = 0; index < menuOption.length; index++) {
270
+ const option = menuOption[index];
271
271
  this.MenuHandle.$data.data.push({
272
- data: _paramData,
272
+ data: option,
273
273
  id: void 0,
274
274
  });
275
275
  }
276
276
  } else {
277
- // @ts-ignore
278
277
  this.MenuHandle.$data.data.push({
279
- data: paramData,
278
+ data: menuOption,
280
279
  id: void 0,
281
280
  });
282
281
  }
282
+ }
283
+ /**
284
+ * 新增菜单数据
285
+ *
286
+ * 自动调用.update()
287
+ * @param menuOption
288
+ */
289
+ add(menuOption: UtilsGMMenuOption[] | UtilsGMMenuOption) {
290
+ this.__add(menuOption);
283
291
  this.update();
284
292
  }
285
293
  /**
286
294
  * 更新菜单数据
295
+ *
296
+ * 实现方式:先取消注册所有已注册的菜单、再依次注册所有菜单项
297
+ *
298
+ * 如果菜单不存在,新增菜单项
299
+ *
300
+ * 如果菜单已存在,新菜单项覆盖旧的菜单项
287
301
  * @param options 数据
288
302
  */
289
303
  update(options?: UtilsGMMenuOption[] | UtilsGMMenuOption) {
290
- let optionsList: UtilsGMMenuOption[] = [];
304
+ let menuOptionList: UtilsGMMenuOption[] = [];
291
305
  if (Array.isArray(options)) {
292
- optionsList = [...optionsList, ...options];
306
+ menuOptionList = [...menuOptionList, ...options];
293
307
  } else if (options != null) {
294
- optionsList = [...optionsList, options];
308
+ menuOptionList = [...menuOptionList, options];
295
309
  }
296
- optionsList.forEach((item) => {
297
- let targetMenu = this.MenuHandle.getMenuOption(item.key);
298
- if (targetMenu) {
299
- Object.assign(targetMenu, item);
310
+ menuOptionList.forEach((menuOption) => {
311
+ let oldMenuOption = this.MenuHandle.getMenuOption(menuOption.key);
312
+ if (oldMenuOption) {
313
+ // 覆盖
314
+ Object.assign(oldMenuOption, menuOption);
315
+ } else {
316
+ this.__add(menuOption);
300
317
  }
301
318
  });
302
319
  this.MenuHandle.$data.data.forEach((value) => {
@@ -317,6 +334,7 @@ class GMMenu {
317
334
  /**
318
335
  * 根据键值获取enable值
319
336
  * @param menuKey 菜单-键key
337
+ * @deprecated
320
338
  */
321
339
  get(menuKey: string): boolean {
322
340
  return this.getEnable(menuKey);
@@ -342,7 +360,7 @@ class GMMenu {
342
360
  getShowTextValue(menuKey: string): string {
343
361
  return this.MenuHandle.getMenuHandledOption(menuKey)!.showText(
344
362
  this.getText(menuKey),
345
- this.get(menuKey)
363
+ this.getEnable(menuKey)
346
364
  );
347
365
  }
348
366
  /**
package/src/WindowApi.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { UtilsWindowApiOption } from "./types/WindowApi";
1
+ import type { WindowApiOption } from "./types/WindowApi";
2
2
 
3
3
  class WindowApi {
4
4
  /** 默认的配置 */
5
- private defaultApi: UtilsWindowApiOption = {
5
+ private defaultApi: Required<WindowApiOption> = {
6
6
  document: document,
7
7
  window: window,
8
8
  globalThis: globalThis,
@@ -10,11 +10,20 @@ class WindowApi {
10
10
  top: top!,
11
11
  };
12
12
  /** 使用的配置 */
13
- private api: UtilsWindowApiOption;
14
- constructor(option?: UtilsWindowApiOption) {
13
+ private api: Required<WindowApiOption>;
14
+ constructor(option?: WindowApiOption) {
15
+ if (option) {
16
+ if (option.globalThis == null) {
17
+ option.globalThis = option.window;
18
+ }
19
+ if (option.self == null) {
20
+ option.self = option.window;
21
+ }
22
+ }
15
23
  if (!option) {
16
24
  option = Object.assign({}, this.defaultApi);
17
25
  }
26
+ // @ts-ignore
18
27
  this.api = Object.assign({}, option);
19
28
  }
20
29
  get document() {
@@ -58,7 +58,7 @@ export interface UtilsGMMenuOptionData {
58
58
  * 对isStoreValue进行处理,如果未赋值,按默认的true赋值
59
59
  * 新增一个deleteMenu
60
60
  */
61
- handleData: UtilsGMMenuHandledOption;
61
+ handleData?: UtilsGMMenuHandledOption;
62
62
  }
63
63
 
64
64
  export interface UtilsGMMenuConstructorOptions {
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * 配置类型
3
3
  */
4
- export type UtilsWindowApiOption = {
4
+ export type WindowApiOption = {
5
5
  document: Document;
6
6
  window: Window & typeof globalThis;
7
- globalThis: typeof globalThis | Window;
8
- self: Window & typeof globalThis;
7
+ globalThis?: typeof globalThis | Window;
8
+ self?: Window & typeof globalThis;
9
9
  top: Window;
10
10
  };