isdata-customer-sdk 0.2.9 → 0.2.11

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.
@@ -33105,7 +33105,7 @@ const check = element => {
33105
33105
  if (classes.contains("ant-table-cell")) {
33106
33106
  let innerHTML = element.innerHTML;
33107
33107
  if (innerHTML.includes("序号") || innerHTML.includes("Serial No.")) {
33108
- console.log("检查smardaten平台表格 序号 元素:", innerHTML);
33108
+ // console.log("检查smardaten平台表格 序号 元素:",innerHTML);
33109
33109
  let tempHTMLMatch = {
33110
33110
  oldValue: '$L{序号}'
33111
33111
  };
@@ -33114,7 +33114,7 @@ const check = element => {
33114
33114
  return checkResult;
33115
33115
  }
33116
33116
  if (innerHTML.includes("操作")) {
33117
- console.log("检查smardaten平台表格 操作 元素:", innerHTML);
33117
+ // console.log("检查smardaten平台表格 操作 元素:",innerHTML);
33118
33118
  let tempHTMLMatch = {
33119
33119
  oldValue: '$L{操作}'
33120
33120
  };
@@ -33127,7 +33127,7 @@ const check = element => {
33127
33127
  if (classes.contains("export_menu")) {
33128
33128
  let innerHTML = element.innerHTML;
33129
33129
  if (innerHTML.includes("导出进度") || innerHTML.includes("Export progress")) {
33130
- console.log("检查smardaten平台表格 导出按钮 元素:", innerHTML);
33130
+ // console.log("检查smardaten平台表格 导出按钮 元素:",innerHTML);
33131
33131
  let tempHTMLMatch = {
33132
33132
  oldValue: '$L{导出进度}'
33133
33133
  };
@@ -33261,7 +33261,7 @@ const check = element => {
33261
33261
  if (classes.contains("ant-popover-message-title")) {
33262
33262
  let innerHTML = element.innerHTML;
33263
33263
  if (innerHTML.includes("确认执行:") || innerHTML.includes("Confirm Execution:")) {
33264
- console.log("检查smardaten平台删除提问对话框:", innerHTML);
33264
+ // console.log("检查smardaten平台删除提问对话框:",innerHTML);
33265
33265
  let tempHTMLMatch = {
33266
33266
  oldValue: '$L{操作确认:删除?}'
33267
33267
  };
@@ -33274,7 +33274,7 @@ const check = element => {
33274
33274
  if (classes.contains("ant-btn-sm")) {
33275
33275
  let innerHTML = element.innerHTML;
33276
33276
  if (innerHTML.includes("Cancel") || innerHTML.includes("取消")) {
33277
- console.log("检查smardaten平台 Tip提问取消删除按钮:", innerHTML);
33277
+ // console.log("检查smardaten平台 Tip提问取消删除按钮:",innerHTML);
33278
33278
  let tempHTMLMatch = {
33279
33279
  oldValue: '$L{取消}'
33280
33280
  };
@@ -33283,7 +33283,7 @@ const check = element => {
33283
33283
  return checkResult;
33284
33284
  }
33285
33285
  if (innerHTML.includes("确定") || innerHTML.includes("OK")) {
33286
- console.log("检查smardaten平台 Tip提问确认删除按钮:", innerHTML);
33286
+ // console.log("检查smardaten平台 Tip提问确认删除按钮:",innerHTML);
33287
33287
  let tempHTMLMatch = {
33288
33288
  oldValue: '$L{确定}'
33289
33289
  };
@@ -33343,15 +33343,21 @@ const catalog_i18n_check = element => {
33343
33343
  ;// ./src/api/i18n/commom_i18n/common_i18n.js
33344
33344
 
33345
33345
 
33346
-
33347
-
33346
+ function getOldValueNodeText(innerHTML, index) {
33347
+ const container = document.createElement('div');
33348
+ container.innerHTML = innerHTML;
33349
+ const childNode = container.childNodes[index];
33350
+ return childNode.textContent;
33351
+ }
33348
33352
  const common_i18n_check = element => {
33349
33353
  const checkResult = {
33350
33354
  result: false,
33351
33355
  innerHTMLMatch: null
33352
33356
  };
33353
33357
  // 检查目录列表 名称 列
33354
- if (element.tagName === 'BUTTON') {
33358
+ if (element.tagName === 'BUTTON' || element.tagName === 'P') {
33359
+ //TODO:先检查新的是否需要解析,新的不需要有可能是解析后的再次判断,如果有历史解析值,则解析
33360
+ //如果新的需要解析,更新缓存的历史解析值
33355
33361
  let innerHTML = element.innerHTML;
33356
33362
  let oldValue = element.getAttribute("oldValue");
33357
33363
  if (!oldValue) {
@@ -33363,25 +33369,36 @@ const common_i18n_check = element => {
33363
33369
  // console.log("检查结果:",firstCheckResult);
33364
33370
  let scriptFunction = (appID, lang) => {
33365
33371
  let elementsArray = [];
33366
- element.childNodes.forEach(node => {
33367
- let scriptNodeItem = node;
33372
+ for (let i = 0; i < element.childNodes.length; i++) {
33373
+ let scriptNodeItem = element.childNodes[i];
33368
33374
  if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33369
- let text = element.getAttribute("oldValue");
33370
- console.log("执行 button 文本节点翻译:", text);
33371
- let isTextMatch = checkTextFormat(text);
33375
+ let oldValue = element.getAttribute("oldValue");
33376
+ // console.log("执行 button 文本节点翻译:", text);
33377
+ // 创建正则表达式匹配所有 $L{...} 格式
33378
+ const regex = /\$L\{([^}]+)\}/g;
33379
+ let isTextMatch = checkTextFormat(oldValue);
33372
33380
  if (!isTextMatch) {
33373
33381
  elementsArray.push(scriptNodeItem);
33374
33382
  } else {
33375
- console.log("执行 button 脚本节点翻译isTextMatch:", isTextMatch ? true : false);
33383
+ // console.log("执行 button 脚本节点翻译isTextMatch:", isTextMatch?true:false);
33376
33384
  // element.removeChild(scriptNodeItem);
33377
- let key = isTextMatch.key;
33378
- let textNode = document.createTextNode(i18n(key, appID, lang) || key);
33385
+ // 替换所有 $L{...} 占位符为翻译文本
33386
+ let childNodeText = getOldValueNodeText(oldValue, i);
33387
+ let newValue = childNodeText;
33388
+ let match;
33389
+ while ((match = regex.exec(oldValue)) !== null) {
33390
+ const fullMatch = match[0];
33391
+ const placeholderKey = match[1];
33392
+ const translation = i18n(placeholderKey, appID, lang);
33393
+ newValue = newValue.replace(fullMatch, translation);
33394
+ }
33395
+ let textNode = document.createTextNode(newValue);
33379
33396
  elementsArray.push(textNode);
33380
33397
  }
33381
33398
  } else {
33382
33399
  elementsArray.push(scriptNodeItem);
33383
33400
  }
33384
- });
33401
+ }
33385
33402
  element.innerHTML = '';
33386
33403
  elementsArray.forEach(el => {
33387
33404
  element.appendChild(el);
@@ -33446,6 +33463,56 @@ const attribute_i18n_check = element => {
33446
33463
  ;// ./src/api/i18n/smardaten_i18n/calendar_i18n.js
33447
33464
 
33448
33465
 
33466
+ function convertToChineseWeekday(englishInput) {
33467
+ // 清理输入:去除首尾空格并转为小写
33468
+ const input = englishInput.trim().toLowerCase();
33469
+
33470
+ // 定义星期映射关系
33471
+ const weekdayMap = {
33472
+ 'mon': '周一',
33473
+ 'monday': '周一',
33474
+ 'mondays': '周一',
33475
+ 'tue': '周二',
33476
+ 'tues': '周二',
33477
+ 'tuesday': '周二',
33478
+ 'tuesdays': '周二',
33479
+ 'wed': '周三',
33480
+ 'wednesday': '周三',
33481
+ 'wednesdays': '周三',
33482
+ 'thu': '周四',
33483
+ 'thur': '周四',
33484
+ 'thurs': '周四',
33485
+ 'thursday': '周四',
33486
+ 'thursdays': '周四',
33487
+ 'fri': '周五',
33488
+ 'friday': '周五',
33489
+ 'fridays': '周五',
33490
+ 'sat': '周六',
33491
+ 'saturday': '周六',
33492
+ 'saturdays': '周六',
33493
+ 'sun': '周日',
33494
+ 'sunday': '周日',
33495
+ 'sundays': '周日'
33496
+ };
33497
+
33498
+ // 使用正则表达式匹配所有可能的星期格式
33499
+ const pattern = /^(mon(day)?s?\.?|tue(sday)?s?\.?|wed(nesday)?s?\.?|thu(r(sday)?)?s?\.?|fri(day)?s?\.?|sat(urday)?s?\.?|sun(day)?s?\.?)$/i;
33500
+
33501
+ // 测试输入是否匹配星期格式
33502
+ if (!pattern.test(input)) {
33503
+ return '未知日期';
33504
+ }
33505
+
33506
+ // 提取基础名称(去除复数形式和句点)
33507
+ const baseName = input.replace(/\./g, '') // 移除所有句点
33508
+ .replace(/s$/, ''); // 移除结尾的's'(复数形式)
33509
+
33510
+ // 特殊处理周四的多种缩写形式
33511
+ const normalized = baseName.startsWith('thu') ? 'thu' : baseName.slice(0, 3);
33512
+
33513
+ // 映射到中文名称
33514
+ return weekdayMap[normalized] || weekdayMap[baseName] || '未知日期';
33515
+ }
33449
33516
  function extractYearMonth(str) {
33450
33517
  const regex = /(\d{4})年(0?[1-9]|1[0-2])月/g;
33451
33518
  const matches = str.matchAll(regex);
@@ -33460,6 +33527,53 @@ function extractYearMonth(str) {
33460
33527
  }
33461
33528
  return result;
33462
33529
  }
33530
+ function extractDayNumbers(text) {
33531
+ // 匹配两种情况:
33532
+ // 1. "数字+日"格式(如"5日"、"12日")
33533
+ // 2. 独立的1-31数字(前后有边界)
33534
+ const regex = /(?:(\b(0?[1-9]|[12]\d|3[01])\b)(?=日))|(\b(0?[1-9]|[12]\d|3[01])\b)/g;
33535
+ const results = [];
33536
+ let match;
33537
+ while ((match = regex.exec(text)) !== null) {
33538
+ // match[2] 对应第一种情况(带"日"字的数字)
33539
+ // match[4] 对应第二种情况(独立数字)
33540
+ const numStr = match[2] || match[4];
33541
+ if (numStr) {
33542
+ // 转换为整数并验证范围
33543
+ const day = parseInt(numStr, 10);
33544
+ if (day >= 1 && day <= 31) {
33545
+ results.push(day);
33546
+ }
33547
+ }
33548
+ }
33549
+ return results;
33550
+ }
33551
+ function extractNumbersFromScenarios(text) {
33552
+ // 定义两种场景的正则表达式
33553
+ const patterns = [
33554
+ // 场景1: "Other X pieces of data"
33555
+ /Other\s+(\d+)\s+pieces of data/gi,
33556
+ // 场景2: "其他 X 条记录"
33557
+ /其他\s+(\d+)\s+条记录/g];
33558
+ const results = [];
33559
+
33560
+ // 遍历所有模式进行匹配
33561
+ patterns.forEach(pattern => {
33562
+ let match;
33563
+ while ((match = pattern.exec(text)) !== null) {
33564
+ // 提取捕获组中的数字
33565
+ const number = parseInt(match[1], 10);
33566
+ results.push({
33567
+ scenario: match[0],
33568
+ // 完整匹配的字符串
33569
+ number: number,
33570
+ // 提取的数字
33571
+ type: pattern.source.includes('Other') ? 'English' : 'Chinese'
33572
+ });
33573
+ }
33574
+ });
33575
+ return results;
33576
+ }
33463
33577
  const calendar_i18n_check = element => {
33464
33578
  const checkResult = {
33465
33579
  result: false,
@@ -33479,13 +33593,152 @@ const calendar_i18n_check = element => {
33479
33593
  let year = yearMonth.year;
33480
33594
  let month = yearMonth.month;
33481
33595
  let newInnerHTML = `${year}/${month}`;
33596
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33597
+ if (lang === "zh-CN") {
33598
+ newInnerHTML = `${year}年${month}月`;
33599
+ }
33482
33600
  element.innerHTML = newInnerHTML;
33483
33601
  }
33484
33602
  };
33485
33603
  let innerHTML = element.innerHTML;
33486
33604
  let testRule = /^\d{4}年(0?[1-9]|1[0-2])月$/;
33487
33605
  if (testRule.test(innerHTML)) {
33488
- console.log("检查smardaten平台日历标题 元素:", innerHTML);
33606
+ // console.log("检查smardaten平台日历标题 元素:",innerHTML);
33607
+ let tempHTMLMatch = {
33608
+ oldValue: innerHTML,
33609
+ isScriptAction: true,
33610
+ scriptFunction: scriptFunction
33611
+ };
33612
+ checkResult.result = true;
33613
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33614
+ return checkResult;
33615
+ }
33616
+ }
33617
+ // 检查日历今天按钮
33618
+ if (classes.contains("fc-today-button")) {
33619
+ let innerHTML = element.innerHTML;
33620
+ if (innerHTML.includes("今天") || innerHTML.includes("today")) {
33621
+ // console.log("检查smardaten平台日历 今天 元素:",innerHTML);
33622
+ let tempHTMLMatch = {
33623
+ oldValue: '$L{今天}'
33624
+ };
33625
+ checkResult.result = true;
33626
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33627
+ return checkResult;
33628
+ }
33629
+ }
33630
+ // 检查日历标题
33631
+ if (classes.contains("fullCalendar_title_value")) {
33632
+ let innerHTML = element.innerHTML;
33633
+ const regex = /周[一二三四五六日]/;
33634
+ const regex_en = /^(mon(day)?s?\.?|tue(sday)?s?\.?|wed(nesday)?s?\.?|thu(r(sday)?)?s?\.?|fri(day)?s?\.?|sat(urday)?s?\.?|sun(day)?s?\.?)$/i;
33635
+ let match = innerHTML.match(regex);
33636
+ if (match) {
33637
+ // console.log("检查smardaten平台日历 周 元素:",innerHTML);
33638
+ let day = match[0];
33639
+ let tempHTMLMatch = {
33640
+ oldValue: `$L{${day}}`
33641
+ };
33642
+ checkResult.result = true;
33643
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33644
+ return checkResult;
33645
+ }
33646
+ match = innerHTML.match(regex_en);
33647
+ if (match) {
33648
+ // console.log("检查smardaten平台日历 周 元素:",innerHTML);
33649
+ let day = match[0];
33650
+ let tempHTMLMatch = {
33651
+ oldValue: `$L{${convertToChineseWeekday(day)}}`
33652
+ };
33653
+ checkResult.result = true;
33654
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33655
+ return checkResult;
33656
+ }
33657
+ }
33658
+ //日期单元格
33659
+ if (classes.contains("fc-daygrid-day-number")) {
33660
+ let scriptFunction = (appID, lang) => {
33661
+ let oldValue = element.getAttribute("oldValue");
33662
+ let result = extractDayNumbers(oldValue);
33663
+ if (result && result.length > 0) {
33664
+ let day = result[0];
33665
+ let newInnerHTML = `${day}`;
33666
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33667
+ if (lang === "zh-CN") {
33668
+ newInnerHTML = `${day}日`;
33669
+ }
33670
+ element.innerHTML = newInnerHTML;
33671
+ }
33672
+ };
33673
+ let innerHTML = element.innerHTML;
33674
+ let match = extractDayNumbers(innerHTML);
33675
+ if (match.length > 0) {
33676
+ // console.log("检查smardaten平台日历 日 元素:",innerHTML);
33677
+ let tempHTMLMatch = {
33678
+ oldValue: innerHTML,
33679
+ isScriptAction: true,
33680
+ scriptFunction: scriptFunction
33681
+ };
33682
+ checkResult.result = true;
33683
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33684
+ return checkResult;
33685
+ }
33686
+ }
33687
+ // 日历更多按钮
33688
+ if (classes.contains("fc-daygrid-more-link")) {
33689
+ let scriptFunction = (appID, lang) => {
33690
+ let oldValue = element.getAttribute("oldValue");
33691
+ let result = extractNumbersFromScenarios(oldValue);
33692
+ if (result && result.length > 0) {
33693
+ let day = result[0]["number"];
33694
+ let newInnerHTML = "另外${X}条数据";
33695
+ newInnerHTML = i18n(newInnerHTML, appID, lang);
33696
+ newInnerHTML = newInnerHTML.replace("${X}", day);
33697
+ element.innerHTML = newInnerHTML;
33698
+ }
33699
+ };
33700
+ let innerHTML = element.innerHTML;
33701
+ let match = extractNumbersFromScenarios(innerHTML);
33702
+ if (match.length > 0) {
33703
+ // console.log("检查smardaten平台日历 更多 元素:",innerHTML);
33704
+ let tempHTMLMatch = {
33705
+ oldValue: innerHTML,
33706
+ isScriptAction: true,
33707
+ scriptFunction: scriptFunction
33708
+ };
33709
+ checkResult.result = true;
33710
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33711
+ return checkResult;
33712
+ }
33713
+ }
33714
+ // 日历弹窗标题
33715
+ if (classes.contains("fc-popover-title")) {
33716
+ // 正则表达式匹配中文日期格式
33717
+ const regex = /(\d{4})年(\d{1,2})月(\d{1,2})日/g;
33718
+ let scriptFunction = (appID, lang) => {
33719
+ let oldValue = element.getAttribute("oldValue");
33720
+ let match = oldValue.match(regex);
33721
+ if (match) {
33722
+ // 替换函数
33723
+ const convertedText = oldValue.replace(regex, function (match, year, month, day) {
33724
+ // 格式化月份和日期为两位数
33725
+ const formattedMonth = month.padStart(2, '0');
33726
+ const formattedDay = day.padStart(2, '0');
33727
+ let result = `${year}/${formattedMonth}/${formattedDay}`;
33728
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33729
+ if (lang === "zh-CN") {
33730
+ result = `${year}年${formattedMonth}月${formattedDay}日`;
33731
+ }
33732
+ // 返回新格式的日期
33733
+ return result;
33734
+ });
33735
+ element.innerHTML = convertedText;
33736
+ }
33737
+ };
33738
+ let innerHTML = element.innerHTML;
33739
+ let match = innerHTML.match(regex);
33740
+ if (match.length > 0) {
33741
+ // console.log("检查smardaten平台日历 日 元素:",innerHTML);
33489
33742
  let tempHTMLMatch = {
33490
33743
  oldValue: innerHTML,
33491
33744
  isScriptAction: true,
@@ -33595,7 +33848,7 @@ function processElement(element) {
33595
33848
  }
33596
33849
 
33597
33850
  // 仅处理元素节点
33598
- if (element && element.nodeType != 1) {
33851
+ if (element && element.nodeType !== Node.ELEMENT_NODE) {
33599
33852
  return false;
33600
33853
  }
33601
33854
 
@@ -33620,7 +33873,7 @@ function processElement(element) {
33620
33873
  let innerHTMLMatch = null;
33621
33874
  const attrCheckResult = attribute_i18n_check(element);
33622
33875
  if (attrCheckResult.result) {
33623
- // console.log("检查到属性匹配元素:",element);
33876
+ console.log("检查到属性匹配元素:", element);
33624
33877
  }
33625
33878
 
33626
33879
  //检查是否是smardaten平台元素
@@ -33630,14 +33883,21 @@ function processElement(element) {
33630
33883
  element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33631
33884
  } else {
33632
33885
  if (!hasChildren) {
33633
- //如果存在历史值,说明之前解析过,有可能是值需要刷新触发
33634
- let oldValue = element.getAttribute("oldValue");
33635
- if (!oldValue) {
33636
- oldValue = element.innerHTML;
33886
+ //如果存在历史值,说明之前解析过,有可能是值需要刷新触发
33887
+ let newValue = element.innerHTML;
33888
+ let newMatch = checkTextFormat(newValue);
33889
+ if (newMatch) {
33890
+ innerHTMLMatch = newMatch;
33891
+ } else {
33892
+ newValue = element.getAttribute("oldValue");
33893
+ if (!newValue) {
33894
+ newValue = element.innerHTML;
33895
+ }
33896
+ innerHTMLMatch = checkTextFormat(newValue);
33637
33897
  }
33638
- innerHTMLMatch = checkTextFormat(oldValue);
33639
33898
  if (innerHTMLMatch) {
33640
- element.setAttribute("oldValue", oldValue);
33899
+ // console.log("检查到innerHTML匹配元素:",element);
33900
+ element.setAttribute("oldValue", newValue);
33641
33901
  }
33642
33902
  }
33643
33903
  }
@@ -33666,7 +33926,7 @@ function processElement(element) {
33666
33926
  isAttibuteAction: attrCheckResult.result,
33667
33927
  attrFunction: attrCheckResult.scriptFunction || null
33668
33928
  });
33669
- console.log("添加后元素缓冲数:", window.i18nElementsMap.size);
33929
+ // console.log("添加后元素缓冲数:",window.i18nElementsMap.size);
33670
33930
  applyTranslation(element);
33671
33931
  return true;
33672
33932
  }
@@ -33683,7 +33943,7 @@ function unProcessElement(element) {
33683
33943
  }
33684
33944
  const localDomID = element.getAttribute("localDomID");
33685
33945
  if (localDomID) {
33686
- console.log(`处理元素ID:${localDomID} 移除缓存`);
33946
+ // console.log(`处理元素ID:${localDomID} 移除缓存`);
33687
33947
  element.removeAttribute("localDomID");
33688
33948
  }
33689
33949
  if (localDomID && window.i18nElementsMap.has(localDomID)) {
@@ -33694,7 +33954,7 @@ function unProcessElement(element) {
33694
33954
  // element.innerHTML = oldValue;
33695
33955
  // }
33696
33956
  window.i18nElementsMap.delete(localDomID);
33697
- console.log("移除后元素缓冲数:", window.i18nElementsMap.size);
33957
+ // console.log("移除后元素缓冲数:",window.i18nElementsMap.size);
33698
33958
  }
33699
33959
  }
33700
33960