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