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