@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.
package/dist/index.umd.js CHANGED
@@ -1244,43 +1244,61 @@
1244
1244
  }
1245
1245
  /**
1246
1246
  * 新增菜单数据
1247
- * @param paramData
1247
+ * @param menuOption
1248
1248
  */
1249
- add(paramData) {
1250
- if (Array.isArray(paramData)) {
1251
- for (const _paramData of paramData) {
1252
- // @ts-ignore
1249
+ __add(menuOption) {
1250
+ if (Array.isArray(menuOption)) {
1251
+ for (let index = 0; index < menuOption.length; index++) {
1252
+ const option = menuOption[index];
1253
1253
  this.MenuHandle.$data.data.push({
1254
- data: _paramData,
1254
+ data: option,
1255
1255
  id: void 0,
1256
1256
  });
1257
1257
  }
1258
1258
  }
1259
1259
  else {
1260
- // @ts-ignore
1261
1260
  this.MenuHandle.$data.data.push({
1262
- data: paramData,
1261
+ data: menuOption,
1263
1262
  id: void 0,
1264
1263
  });
1265
1264
  }
1265
+ }
1266
+ /**
1267
+ * 新增菜单数据
1268
+ *
1269
+ * 自动调用.update()
1270
+ * @param menuOption
1271
+ */
1272
+ add(menuOption) {
1273
+ this.__add(menuOption);
1266
1274
  this.update();
1267
1275
  }
1268
1276
  /**
1269
1277
  * 更新菜单数据
1278
+ *
1279
+ * 实现方式:先取消注册所有已注册的菜单、再依次注册所有菜单项
1280
+ *
1281
+ * 如果菜单不存在,新增菜单项
1282
+ *
1283
+ * 如果菜单已存在,新菜单项覆盖旧的菜单项
1270
1284
  * @param options 数据
1271
1285
  */
1272
1286
  update(options) {
1273
- let optionsList = [];
1287
+ let menuOptionList = [];
1274
1288
  if (Array.isArray(options)) {
1275
- optionsList = [...optionsList, ...options];
1289
+ menuOptionList = [...menuOptionList, ...options];
1276
1290
  }
1277
1291
  else if (options != null) {
1278
- optionsList = [...optionsList, options];
1292
+ menuOptionList = [...menuOptionList, options];
1279
1293
  }
1280
- optionsList.forEach((item) => {
1281
- let targetMenu = this.MenuHandle.getMenuOption(item.key);
1282
- if (targetMenu) {
1283
- Object.assign(targetMenu, item);
1294
+ menuOptionList.forEach((menuOption) => {
1295
+ let oldMenuOption = this.MenuHandle.getMenuOption(menuOption.key);
1296
+ if (oldMenuOption) {
1297
+ // 覆盖
1298
+ Object.assign(oldMenuOption, menuOption);
1299
+ }
1300
+ else {
1301
+ this.__add(menuOption);
1284
1302
  }
1285
1303
  });
1286
1304
  this.MenuHandle.$data.data.forEach((value) => {
@@ -1301,6 +1319,7 @@
1301
1319
  /**
1302
1320
  * 根据键值获取enable值
1303
1321
  * @param menuKey 菜单-键key
1322
+ * @deprecated
1304
1323
  */
1305
1324
  get(menuKey) {
1306
1325
  return this.getEnable(menuKey);
@@ -1324,7 +1343,7 @@
1324
1343
  * @param menuKey 菜单-键key
1325
1344
  */
1326
1345
  getShowTextValue(menuKey) {
1327
- return this.MenuHandle.getMenuHandledOption(menuKey).showText(this.getText(menuKey), this.get(menuKey));
1346
+ return this.MenuHandle.getMenuHandledOption(menuKey).showText(this.getText(menuKey), this.getEnable(menuKey));
1328
1347
  }
1329
1348
  /**
1330
1349
  * 获取当前已注册菜单的id
@@ -4078,7 +4097,7 @@
4078
4097
  this.windowApi = new WindowApi(option);
4079
4098
  }
4080
4099
  /** 版本号 */
4081
- version = "2024.11.1";
4100
+ version = "2024.11.5";
4082
4101
  addStyle(cssText) {
4083
4102
  if (typeof cssText !== "string") {
4084
4103
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -7189,6 +7208,15 @@
7189
7208
  generateUUID = GenerateUUID;
7190
7209
  /**
7191
7210
  * 自定义的动态响应对象
7211
+ * @example
7212
+ * let vue = new Utils.Vue();
7213
+ * let reactive = new vue.reactive({});
7214
+ * vue.watch(()=>reactive["name"], (newValue, oldValue)=>{
7215
+ * console.log("newValue ==> " + newValue);
7216
+ * console.log("oldValue ==> " + oldValue);
7217
+ * })
7218
+ * vue["name"] = "测试";
7219
+ * > "测试"
7192
7220
  */
7193
7221
  Vue = Vue;
7194
7222
  }