isdata-customer-sdk 0.2.8 → 0.2.9

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.
@@ -33140,7 +33140,7 @@ const check = element => {
33140
33140
  if (classes.contains("total_pag_num")) {
33141
33141
  let innerHTML = element.innerHTML;
33142
33142
  if (innerHTML.includes("共") && innerHTML.includes("条") || innerHTML.includes("Total") && innerHTML.includes("pieces")) {
33143
- console.log("检查smardaten平台分页 共xx条 元素:", innerHTML);
33143
+ // console.log("检查smardaten平台分页 共xx条 元素:",innerHTML);
33144
33144
  let scriptFunction = (appID, lang) => {
33145
33145
  let scriptNode = null;
33146
33146
  for (let node of element.childNodes) {
@@ -33189,7 +33189,7 @@ const check = element => {
33189
33189
  if (classes.contains("ant-pagination-options-quick-jumper")) {
33190
33190
  let innerHTML = element.innerHTML;
33191
33191
  if (innerHTML.includes("跳至") && innerHTML.includes("页") || innerHTML.includes("Go to") && innerHTML.includes("Page")) {
33192
- console.log("检查smardaten平台分页 跳至xx页 元素:", innerHTML);
33192
+ // console.log("检查smardaten平台分页 跳至xx页 元素:",innerHTML);
33193
33193
  let scriptFunction = (appID, lang) => {
33194
33194
  let scriptNode = null;
33195
33195
  for (let node of element.childNodes) {
@@ -33237,7 +33237,7 @@ const check = element => {
33237
33237
  // 检查每页xx条
33238
33238
  if (classes.contains("ant-select-selection-item") || classes.contains("ant-select-item-option-content")) {
33239
33239
  let innerHTML = element.innerHTML;
33240
- console.log("检查smardaten平台分页 每页xx条 元素:", innerHTML);
33240
+ // console.log("检查smardaten平台分页 每页xx条 元素:",innerHTML);
33241
33241
  if (innerHTML.includes("/") && innerHTML.includes("page") || innerHTML.includes("/") && innerHTML.includes("条") && innerHTML.includes("页")) {
33242
33242
  let oldValue = element.innerHTML;
33243
33243
  if (innerHTML.includes("page")) {
@@ -33359,8 +33359,8 @@ const common_i18n_check = element => {
33359
33359
  }
33360
33360
  let firstCheck = checkTextFormat(oldValue);
33361
33361
  let firstCheckResult = firstCheck ? true : false;
33362
- console.log("检查 button 元素:", innerHTML);
33363
- console.log("检查结果:", firstCheckResult);
33362
+ // console.log("检查 button 元素:",innerHTML);
33363
+ // console.log("检查结果:",firstCheckResult);
33364
33364
  let scriptFunction = (appID, lang) => {
33365
33365
  let elementsArray = [];
33366
33366
  element.childNodes.forEach(node => {
@@ -33405,13 +33405,16 @@ const attribute_i18n_check = element => {
33405
33405
  result: false,
33406
33406
  innerHTMLMatch: null
33407
33407
  };
33408
+ if (!element) {
33409
+ return checkResult;
33410
+ }
33408
33411
  const checkAttributes = ["placeholder", "title"];
33409
33412
  for (let i = 0; i < checkAttributes.length; i++) {
33410
33413
  let attr = checkAttributes[i];
33411
33414
  let attrValue = element.getAttribute(attr) || element[attr];
33412
33415
  const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
33413
33416
  if (attrMatch) {
33414
- console.log("检查元素属性 i18n 元素:", attr, attrValue);
33417
+ // console.log("检查元素属性 i18n 元素:", attr, attrValue);
33415
33418
  element.setAttribute(`old${attr}Value`, attrValue);
33416
33419
  checkResult.result = true;
33417
33420
  }
@@ -33440,6 +33443,61 @@ const attribute_i18n_check = element => {
33440
33443
  checkResult.scriptFunction = scriptFunction;
33441
33444
  return checkResult;
33442
33445
  };
33446
+ ;// ./src/api/i18n/smardaten_i18n/calendar_i18n.js
33447
+
33448
+
33449
+ function extractYearMonth(str) {
33450
+ const regex = /(\d{4})年(0?[1-9]|1[0-2])月/g;
33451
+ const matches = str.matchAll(regex);
33452
+ const result = [];
33453
+ for (const match of matches) {
33454
+ const year = parseInt(match[1], 10);
33455
+ const month = parseInt(match[2], 10);
33456
+ result.push({
33457
+ year,
33458
+ month
33459
+ });
33460
+ }
33461
+ return result;
33462
+ }
33463
+ const calendar_i18n_check = element => {
33464
+ const checkResult = {
33465
+ result: false,
33466
+ innerHTMLMatch: null
33467
+ };
33468
+ const classes = element.classList;
33469
+ if (!classes) {
33470
+ return checkResult;
33471
+ }
33472
+ // 检查日历标题
33473
+ if (classes.contains("fc-toolbar-title")) {
33474
+ let scriptFunction = (appID, lang) => {
33475
+ let oldValue = element.getAttribute("oldValue");
33476
+ let yearMonthList = extractYearMonth(oldValue);
33477
+ if (yearMonthList.length > 0) {
33478
+ let yearMonth = yearMonthList[0];
33479
+ let year = yearMonth.year;
33480
+ let month = yearMonth.month;
33481
+ let newInnerHTML = `${year}/${month}`;
33482
+ element.innerHTML = newInnerHTML;
33483
+ }
33484
+ };
33485
+ let innerHTML = element.innerHTML;
33486
+ let testRule = /^\d{4}年(0?[1-9]|1[0-2])月$/;
33487
+ if (testRule.test(innerHTML)) {
33488
+ console.log("检查smardaten平台日历标题 元素:", innerHTML);
33489
+ let tempHTMLMatch = {
33490
+ oldValue: innerHTML,
33491
+ isScriptAction: true,
33492
+ scriptFunction: scriptFunction
33493
+ };
33494
+ checkResult.result = true;
33495
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33496
+ return checkResult;
33497
+ }
33498
+ }
33499
+ return checkResult;
33500
+ };
33443
33501
  ;// ./src/api/i18n/i18n.js
33444
33502
 
33445
33503
 
@@ -33451,6 +33509,7 @@ const attribute_i18n_check = element => {
33451
33509
 
33452
33510
 
33453
33511
 
33512
+
33454
33513
  const getLanguages = async appID => {
33455
33514
  let queryData = {
33456
33515
  param: {
@@ -33485,7 +33544,7 @@ const loadi18nTexts = async appID => {
33485
33544
  * @returns {boolean} - 是否有子元素
33486
33545
  */
33487
33546
  function hasChildElements(element) {
33488
- return element.children.length > 0;
33547
+ return element && element.children?.length > 0;
33489
33548
  }
33490
33549
 
33491
33550
  /**
@@ -33520,7 +33579,7 @@ function checkPlatformElementContent(element) {
33520
33579
  result: false,
33521
33580
  innerHTMLMatch: null
33522
33581
  };
33523
- let checkArr = [check, catalog_i18n_check, common_i18n_check];
33582
+ let checkArr = [check, catalog_i18n_check, calendar_i18n_check, common_i18n_check];
33524
33583
  for (let i = 0; i < checkArr.length; i++) {
33525
33584
  let checkFunc = checkArr[i];
33526
33585
  let checkContentResult = checkFunc(element);
@@ -33531,6 +33590,10 @@ function checkPlatformElementContent(element) {
33531
33590
  return checkContentResult;
33532
33591
  }
33533
33592
  function processElement(element) {
33593
+ if (!element) {
33594
+ return false;
33595
+ }
33596
+
33534
33597
  // 仅处理元素节点
33535
33598
  if (element && element.nodeType != 1) {
33536
33599
  return false;
@@ -33541,6 +33604,14 @@ function processElement(element) {
33541
33604
  if (hasChildren) {
33542
33605
  let children = element.children;
33543
33606
  for (let i = 0; i < children.length; i++) {
33607
+ let child = children[i];
33608
+ if (child.nodeType === Node.ELEMENT_NODE) {
33609
+ let childLocalDomID = child.getAttribute("localDomID");
33610
+ // 如果子元素有localDomID但不在缓存中,移除localDomID属性
33611
+ if (childLocalDomID && window.i18nElementsMap && !window.i18nElementsMap.has(childLocalDomID)) {
33612
+ unProcessElement(child);
33613
+ }
33614
+ }
33544
33615
  processElement(children[i]);
33545
33616
  }
33546
33617
  }
@@ -33549,7 +33620,7 @@ function processElement(element) {
33549
33620
  let innerHTMLMatch = null;
33550
33621
  const attrCheckResult = attribute_i18n_check(element);
33551
33622
  if (attrCheckResult.result) {
33552
- console.log("检查到属性匹配元素:", element);
33623
+ // console.log("检查到属性匹配元素:",element);
33553
33624
  }
33554
33625
 
33555
33626
  //检查是否是smardaten平台元素
@@ -33559,10 +33630,14 @@ function processElement(element) {
33559
33630
  element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33560
33631
  } else {
33561
33632
  if (!hasChildren) {
33562
- const innerHTML = element.innerHTML;
33563
- innerHTMLMatch = checkTextFormat(innerHTML);
33633
+ //如果存在历史值,说明之前解析过,有可能是值需要刷新触发
33634
+ let oldValue = element.getAttribute("oldValue");
33635
+ if (!oldValue) {
33636
+ oldValue = element.innerHTML;
33637
+ }
33638
+ innerHTMLMatch = checkTextFormat(oldValue);
33564
33639
  if (innerHTMLMatch) {
33565
- element.setAttribute("oldValue", element.innerHTML);
33640
+ element.setAttribute("oldValue", oldValue);
33566
33641
  }
33567
33642
  }
33568
33643
  }
@@ -33591,6 +33666,7 @@ function processElement(element) {
33591
33666
  isAttibuteAction: attrCheckResult.result,
33592
33667
  attrFunction: attrCheckResult.scriptFunction || null
33593
33668
  });
33669
+ console.log("添加后元素缓冲数:", window.i18nElementsMap.size);
33594
33670
  applyTranslation(element);
33595
33671
  return true;
33596
33672
  }
@@ -33598,17 +33674,27 @@ function unProcessElement(element) {
33598
33674
  if (element && element.nodeType !== 1) {
33599
33675
  return;
33600
33676
  }
33601
- // const hasChildren = hasChildElements(element);
33602
- // if (hasChildren) {
33603
- // let children = element.children;
33604
- // for (let i = 0; i < children.length; i++) {
33605
- // unProcessElement(children[i]);
33606
- // }
33607
- // }
33677
+ let hasChildren = hasChildElements(element);
33678
+ if (hasChildren) {
33679
+ let children = element.children;
33680
+ for (let i = 0; i < children.length; i++) {
33681
+ unProcessElement(children[i]);
33682
+ }
33683
+ }
33608
33684
  const localDomID = element.getAttribute("localDomID");
33685
+ if (localDomID) {
33686
+ console.log(`处理元素ID:${localDomID} 移除缓存`);
33687
+ element.removeAttribute("localDomID");
33688
+ }
33609
33689
  if (localDomID && window.i18nElementsMap.has(localDomID)) {
33690
+ // let oldValue = element.getAttribute("oldValue");
33691
+ // if(oldValue){
33692
+ // element.removeAttribute("oldValue");
33693
+ // 更新元素的innerHTML
33694
+ // element.innerHTML = oldValue;
33695
+ // }
33610
33696
  window.i18nElementsMap.delete(localDomID);
33611
- console.log("移除元素缓存:", localDomID);
33697
+ console.log("移除后元素缓冲数:", window.i18nElementsMap.size);
33612
33698
  }
33613
33699
  }
33614
33700
 
@@ -33618,6 +33704,12 @@ function unProcessElement(element) {
33618
33704
  * @param {string} lang - 语言标识符
33619
33705
  */
33620
33706
  const applyTranslation = async element => {
33707
+ let parentNode = element.parentNode;
33708
+ if (!parentNode) {
33709
+ unProcessElement(element);
33710
+ console.log("元素已无父节点,移除缓存");
33711
+ return;
33712
+ }
33621
33713
  let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33622
33714
  let appID = getPoratlAppID();
33623
33715
  const elementId = element.getAttribute("localDomID");
@@ -33661,7 +33753,7 @@ const initDomNodeI18NObserver = () => {
33661
33753
  console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
33662
33754
  // 遍历Map,更新每个已处理元素的翻译
33663
33755
  for (const [elementId, item] of window.i18nElementsMap.entries()) {
33664
- console.log("更新元素翻译:", elementId, item.dom);
33756
+ // console.log("更新元素翻译:", elementId, item.dom);
33665
33757
  applyTranslation(item.dom);
33666
33758
  }
33667
33759
  });
@@ -33696,6 +33788,13 @@ const initDomNodeI18NObserver = () => {
33696
33788
  // 创建日志条目并显示
33697
33789
  console.log(`文本修改: ${oldValue} → ${newValue}`);
33698
33790
  const parentElement = targetNode.parentNode;
33791
+ if (parentElement) {
33792
+ let localDomID = parentElement.getAttribute("localDomID");
33793
+ // 如果有localDomID,说明之前处理过,先移除缓存
33794
+ if (localDomID) {
33795
+ unProcessElement(parentElement);
33796
+ }
33797
+ }
33699
33798
  processElement(parentElement);
33700
33799
  }
33701
33800
  });