@whitesev/utils 2.4.5 → 2.4.6

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 配置
@@ -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
  /**
@@ -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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Utils.ts CHANGED
@@ -29,7 +29,7 @@ class Utils {
29
29
  this.windowApi = new WindowApi(option);
30
30
  }
31
31
  /** 版本号 */
32
- version = "2024.11.1";
32
+ version = "2024.11.5";
33
33
 
34
34
  /**
35
35
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -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
  /**
@@ -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 {