@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.
package/dist/index.esm.js CHANGED
@@ -1238,43 +1238,61 @@ class GMMenu {
1238
1238
  }
1239
1239
  /**
1240
1240
  * 新增菜单数据
1241
- * @param paramData
1241
+ * @param menuOption
1242
1242
  */
1243
- add(paramData) {
1244
- if (Array.isArray(paramData)) {
1245
- for (const _paramData of paramData) {
1246
- // @ts-ignore
1243
+ __add(menuOption) {
1244
+ if (Array.isArray(menuOption)) {
1245
+ for (let index = 0; index < menuOption.length; index++) {
1246
+ const option = menuOption[index];
1247
1247
  this.MenuHandle.$data.data.push({
1248
- data: _paramData,
1248
+ data: option,
1249
1249
  id: void 0,
1250
1250
  });
1251
1251
  }
1252
1252
  }
1253
1253
  else {
1254
- // @ts-ignore
1255
1254
  this.MenuHandle.$data.data.push({
1256
- data: paramData,
1255
+ data: menuOption,
1257
1256
  id: void 0,
1258
1257
  });
1259
1258
  }
1259
+ }
1260
+ /**
1261
+ * 新增菜单数据
1262
+ *
1263
+ * 自动调用.update()
1264
+ * @param menuOption
1265
+ */
1266
+ add(menuOption) {
1267
+ this.__add(menuOption);
1260
1268
  this.update();
1261
1269
  }
1262
1270
  /**
1263
1271
  * 更新菜单数据
1272
+ *
1273
+ * 实现方式:先取消注册所有已注册的菜单、再依次注册所有菜单项
1274
+ *
1275
+ * 如果菜单不存在,新增菜单项
1276
+ *
1277
+ * 如果菜单已存在,新菜单项覆盖旧的菜单项
1264
1278
  * @param options 数据
1265
1279
  */
1266
1280
  update(options) {
1267
- let optionsList = [];
1281
+ let menuOptionList = [];
1268
1282
  if (Array.isArray(options)) {
1269
- optionsList = [...optionsList, ...options];
1283
+ menuOptionList = [...menuOptionList, ...options];
1270
1284
  }
1271
1285
  else if (options != null) {
1272
- optionsList = [...optionsList, options];
1286
+ menuOptionList = [...menuOptionList, options];
1273
1287
  }
1274
- optionsList.forEach((item) => {
1275
- let targetMenu = this.MenuHandle.getMenuOption(item.key);
1276
- if (targetMenu) {
1277
- Object.assign(targetMenu, item);
1288
+ menuOptionList.forEach((menuOption) => {
1289
+ let oldMenuOption = this.MenuHandle.getMenuOption(menuOption.key);
1290
+ if (oldMenuOption) {
1291
+ // 覆盖
1292
+ Object.assign(oldMenuOption, menuOption);
1293
+ }
1294
+ else {
1295
+ this.__add(menuOption);
1278
1296
  }
1279
1297
  });
1280
1298
  this.MenuHandle.$data.data.forEach((value) => {
@@ -1295,6 +1313,7 @@ class GMMenu {
1295
1313
  /**
1296
1314
  * 根据键值获取enable值
1297
1315
  * @param menuKey 菜单-键key
1316
+ * @deprecated
1298
1317
  */
1299
1318
  get(menuKey) {
1300
1319
  return this.getEnable(menuKey);
@@ -1318,7 +1337,7 @@ class GMMenu {
1318
1337
  * @param menuKey 菜单-键key
1319
1338
  */
1320
1339
  getShowTextValue(menuKey) {
1321
- return this.MenuHandle.getMenuHandledOption(menuKey).showText(this.getText(menuKey), this.get(menuKey));
1340
+ return this.MenuHandle.getMenuHandledOption(menuKey).showText(this.getText(menuKey), this.getEnable(menuKey));
1322
1341
  }
1323
1342
  /**
1324
1343
  * 获取当前已注册菜单的id
@@ -3805,9 +3824,18 @@ class WindowApi {
3805
3824
  /** 使用的配置 */
3806
3825
  api;
3807
3826
  constructor(option) {
3827
+ if (option) {
3828
+ if (option.globalThis == null) {
3829
+ option.globalThis = option.window;
3830
+ }
3831
+ if (option.self == null) {
3832
+ option.self = option.window;
3833
+ }
3834
+ }
3808
3835
  if (!option) {
3809
3836
  option = Object.assign({}, this.defaultApi);
3810
3837
  }
3838
+ // @ts-ignore
3811
3839
  this.api = Object.assign({}, option);
3812
3840
  }
3813
3841
  get document() {
@@ -4072,7 +4100,7 @@ class Utils {
4072
4100
  this.windowApi = new WindowApi(option);
4073
4101
  }
4074
4102
  /** 版本号 */
4075
- version = "2024.11.1";
4103
+ version = "2024.11.6";
4076
4104
  addStyle(cssText) {
4077
4105
  if (typeof cssText !== "string") {
4078
4106
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -7183,6 +7211,15 @@ class Utils {
7183
7211
  generateUUID = GenerateUUID;
7184
7212
  /**
7185
7213
  * 自定义的动态响应对象
7214
+ * @example
7215
+ * let vue = new Utils.Vue();
7216
+ * let reactive = new vue.reactive({});
7217
+ * vue.watch(()=>reactive["name"], (newValue, oldValue)=>{
7218
+ * console.log("newValue ==> " + newValue);
7219
+ * console.log("oldValue ==> " + oldValue);
7220
+ * })
7221
+ * vue["name"] = "测试";
7222
+ * > "测试"
7186
7223
  */
7187
7224
  Vue = Vue;
7188
7225
  }