isdata-customer-sdk 0.2.7 → 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.
- package/dist/index.common.js +114 -15
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +114 -15
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -33158,7 +33158,7 @@ const check = element => {
|
|
|
33158
33158
|
if (classes.contains("total_pag_num")) {
|
|
33159
33159
|
let innerHTML = element.innerHTML;
|
|
33160
33160
|
if (innerHTML.includes("共") && innerHTML.includes("条") || innerHTML.includes("Total") && innerHTML.includes("pieces")) {
|
|
33161
|
-
console.log("检查smardaten平台分页 共xx条 元素:",
|
|
33161
|
+
// console.log("检查smardaten平台分页 共xx条 元素:",innerHTML);
|
|
33162
33162
|
let scriptFunction = (appID, lang) => {
|
|
33163
33163
|
let scriptNode = null;
|
|
33164
33164
|
for (let node of element.childNodes) {
|
|
@@ -33207,7 +33207,7 @@ const check = element => {
|
|
|
33207
33207
|
if (classes.contains("ant-pagination-options-quick-jumper")) {
|
|
33208
33208
|
let innerHTML = element.innerHTML;
|
|
33209
33209
|
if (innerHTML.includes("跳至") && innerHTML.includes("页") || innerHTML.includes("Go to") && innerHTML.includes("Page")) {
|
|
33210
|
-
console.log("检查smardaten平台分页 跳至xx页 元素:",
|
|
33210
|
+
// console.log("检查smardaten平台分页 跳至xx页 元素:",innerHTML);
|
|
33211
33211
|
let scriptFunction = (appID, lang) => {
|
|
33212
33212
|
let scriptNode = null;
|
|
33213
33213
|
for (let node of element.childNodes) {
|
|
@@ -33255,7 +33255,7 @@ const check = element => {
|
|
|
33255
33255
|
// 检查每页xx条
|
|
33256
33256
|
if (classes.contains("ant-select-selection-item") || classes.contains("ant-select-item-option-content")) {
|
|
33257
33257
|
let innerHTML = element.innerHTML;
|
|
33258
|
-
console.log("检查smardaten平台分页 每页xx条 元素:",
|
|
33258
|
+
// console.log("检查smardaten平台分页 每页xx条 元素:",innerHTML);
|
|
33259
33259
|
if (innerHTML.includes("/") && innerHTML.includes("page") || innerHTML.includes("/") && innerHTML.includes("条") && innerHTML.includes("页")) {
|
|
33260
33260
|
let oldValue = element.innerHTML;
|
|
33261
33261
|
if (innerHTML.includes("page")) {
|
|
@@ -33377,8 +33377,8 @@ const common_i18n_check = element => {
|
|
|
33377
33377
|
}
|
|
33378
33378
|
let firstCheck = checkTextFormat(oldValue);
|
|
33379
33379
|
let firstCheckResult = firstCheck ? true : false;
|
|
33380
|
-
console.log("检查 button 元素:",
|
|
33381
|
-
console.log("检查结果:",
|
|
33380
|
+
// console.log("检查 button 元素:",innerHTML);
|
|
33381
|
+
// console.log("检查结果:",firstCheckResult);
|
|
33382
33382
|
let scriptFunction = (appID, lang) => {
|
|
33383
33383
|
let elementsArray = [];
|
|
33384
33384
|
element.childNodes.forEach(node => {
|
|
@@ -33423,13 +33423,16 @@ const attribute_i18n_check = element => {
|
|
|
33423
33423
|
result: false,
|
|
33424
33424
|
innerHTMLMatch: null
|
|
33425
33425
|
};
|
|
33426
|
+
if (!element) {
|
|
33427
|
+
return checkResult;
|
|
33428
|
+
}
|
|
33426
33429
|
const checkAttributes = ["placeholder", "title"];
|
|
33427
33430
|
for (let i = 0; i < checkAttributes.length; i++) {
|
|
33428
33431
|
let attr = checkAttributes[i];
|
|
33429
33432
|
let attrValue = element.getAttribute(attr) || element[attr];
|
|
33430
33433
|
const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
|
|
33431
33434
|
if (attrMatch) {
|
|
33432
|
-
console.log("检查元素属性 i18n 元素:", attr, attrValue);
|
|
33435
|
+
// console.log("检查元素属性 i18n 元素:", attr, attrValue);
|
|
33433
33436
|
element.setAttribute(`old${attr}Value`, attrValue);
|
|
33434
33437
|
checkResult.result = true;
|
|
33435
33438
|
}
|
|
@@ -33458,6 +33461,61 @@ const attribute_i18n_check = element => {
|
|
|
33458
33461
|
checkResult.scriptFunction = scriptFunction;
|
|
33459
33462
|
return checkResult;
|
|
33460
33463
|
};
|
|
33464
|
+
;// ./src/api/i18n/smardaten_i18n/calendar_i18n.js
|
|
33465
|
+
|
|
33466
|
+
|
|
33467
|
+
function extractYearMonth(str) {
|
|
33468
|
+
const regex = /(\d{4})年(0?[1-9]|1[0-2])月/g;
|
|
33469
|
+
const matches = str.matchAll(regex);
|
|
33470
|
+
const result = [];
|
|
33471
|
+
for (const match of matches) {
|
|
33472
|
+
const year = parseInt(match[1], 10);
|
|
33473
|
+
const month = parseInt(match[2], 10);
|
|
33474
|
+
result.push({
|
|
33475
|
+
year,
|
|
33476
|
+
month
|
|
33477
|
+
});
|
|
33478
|
+
}
|
|
33479
|
+
return result;
|
|
33480
|
+
}
|
|
33481
|
+
const calendar_i18n_check = element => {
|
|
33482
|
+
const checkResult = {
|
|
33483
|
+
result: false,
|
|
33484
|
+
innerHTMLMatch: null
|
|
33485
|
+
};
|
|
33486
|
+
const classes = element.classList;
|
|
33487
|
+
if (!classes) {
|
|
33488
|
+
return checkResult;
|
|
33489
|
+
}
|
|
33490
|
+
// 检查日历标题
|
|
33491
|
+
if (classes.contains("fc-toolbar-title")) {
|
|
33492
|
+
let scriptFunction = (appID, lang) => {
|
|
33493
|
+
let oldValue = element.getAttribute("oldValue");
|
|
33494
|
+
let yearMonthList = extractYearMonth(oldValue);
|
|
33495
|
+
if (yearMonthList.length > 0) {
|
|
33496
|
+
let yearMonth = yearMonthList[0];
|
|
33497
|
+
let year = yearMonth.year;
|
|
33498
|
+
let month = yearMonth.month;
|
|
33499
|
+
let newInnerHTML = `${year}/${month}`;
|
|
33500
|
+
element.innerHTML = newInnerHTML;
|
|
33501
|
+
}
|
|
33502
|
+
};
|
|
33503
|
+
let innerHTML = element.innerHTML;
|
|
33504
|
+
let testRule = /^\d{4}年(0?[1-9]|1[0-2])月$/;
|
|
33505
|
+
if (testRule.test(innerHTML)) {
|
|
33506
|
+
console.log("检查smardaten平台日历标题 元素:", innerHTML);
|
|
33507
|
+
let tempHTMLMatch = {
|
|
33508
|
+
oldValue: innerHTML,
|
|
33509
|
+
isScriptAction: true,
|
|
33510
|
+
scriptFunction: scriptFunction
|
|
33511
|
+
};
|
|
33512
|
+
checkResult.result = true;
|
|
33513
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33514
|
+
return checkResult;
|
|
33515
|
+
}
|
|
33516
|
+
}
|
|
33517
|
+
return checkResult;
|
|
33518
|
+
};
|
|
33461
33519
|
;// ./src/api/i18n/i18n.js
|
|
33462
33520
|
|
|
33463
33521
|
|
|
@@ -33469,6 +33527,7 @@ const attribute_i18n_check = element => {
|
|
|
33469
33527
|
|
|
33470
33528
|
|
|
33471
33529
|
|
|
33530
|
+
|
|
33472
33531
|
const getLanguages = async appID => {
|
|
33473
33532
|
let queryData = {
|
|
33474
33533
|
param: {
|
|
@@ -33503,7 +33562,7 @@ const loadi18nTexts = async appID => {
|
|
|
33503
33562
|
* @returns {boolean} - 是否有子元素
|
|
33504
33563
|
*/
|
|
33505
33564
|
function hasChildElements(element) {
|
|
33506
|
-
return element.children
|
|
33565
|
+
return element && element.children?.length > 0;
|
|
33507
33566
|
}
|
|
33508
33567
|
|
|
33509
33568
|
/**
|
|
@@ -33538,7 +33597,7 @@ function checkPlatformElementContent(element) {
|
|
|
33538
33597
|
result: false,
|
|
33539
33598
|
innerHTMLMatch: null
|
|
33540
33599
|
};
|
|
33541
|
-
let checkArr = [check, catalog_i18n_check, common_i18n_check];
|
|
33600
|
+
let checkArr = [check, catalog_i18n_check, calendar_i18n_check, common_i18n_check];
|
|
33542
33601
|
for (let i = 0; i < checkArr.length; i++) {
|
|
33543
33602
|
let checkFunc = checkArr[i];
|
|
33544
33603
|
let checkContentResult = checkFunc(element);
|
|
@@ -33549,6 +33608,10 @@ function checkPlatformElementContent(element) {
|
|
|
33549
33608
|
return checkContentResult;
|
|
33550
33609
|
}
|
|
33551
33610
|
function processElement(element) {
|
|
33611
|
+
if (!element) {
|
|
33612
|
+
return false;
|
|
33613
|
+
}
|
|
33614
|
+
|
|
33552
33615
|
// 仅处理元素节点
|
|
33553
33616
|
if (element && element.nodeType != 1) {
|
|
33554
33617
|
return false;
|
|
@@ -33559,6 +33622,14 @@ function processElement(element) {
|
|
|
33559
33622
|
if (hasChildren) {
|
|
33560
33623
|
let children = element.children;
|
|
33561
33624
|
for (let i = 0; i < children.length; i++) {
|
|
33625
|
+
let child = children[i];
|
|
33626
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
33627
|
+
let childLocalDomID = child.getAttribute("localDomID");
|
|
33628
|
+
// 如果子元素有localDomID但不在缓存中,移除localDomID属性
|
|
33629
|
+
if (childLocalDomID && window.i18nElementsMap && !window.i18nElementsMap.has(childLocalDomID)) {
|
|
33630
|
+
unProcessElement(child);
|
|
33631
|
+
}
|
|
33632
|
+
}
|
|
33562
33633
|
processElement(children[i]);
|
|
33563
33634
|
}
|
|
33564
33635
|
}
|
|
@@ -33567,7 +33638,7 @@ function processElement(element) {
|
|
|
33567
33638
|
let innerHTMLMatch = null;
|
|
33568
33639
|
const attrCheckResult = attribute_i18n_check(element);
|
|
33569
33640
|
if (attrCheckResult.result) {
|
|
33570
|
-
console.log("检查到属性匹配元素:",
|
|
33641
|
+
// console.log("检查到属性匹配元素:",element);
|
|
33571
33642
|
}
|
|
33572
33643
|
|
|
33573
33644
|
//检查是否是smardaten平台元素
|
|
@@ -33577,10 +33648,14 @@ function processElement(element) {
|
|
|
33577
33648
|
element.setAttribute("oldValue", innerHTMLMatch.oldValue);
|
|
33578
33649
|
} else {
|
|
33579
33650
|
if (!hasChildren) {
|
|
33580
|
-
|
|
33581
|
-
|
|
33651
|
+
//如果存在历史值,说明之前解析过,有可能是值需要刷新触发
|
|
33652
|
+
let oldValue = element.getAttribute("oldValue");
|
|
33653
|
+
if (!oldValue) {
|
|
33654
|
+
oldValue = element.innerHTML;
|
|
33655
|
+
}
|
|
33656
|
+
innerHTMLMatch = checkTextFormat(oldValue);
|
|
33582
33657
|
if (innerHTMLMatch) {
|
|
33583
|
-
element.setAttribute("oldValue",
|
|
33658
|
+
element.setAttribute("oldValue", oldValue);
|
|
33584
33659
|
}
|
|
33585
33660
|
}
|
|
33586
33661
|
}
|
|
@@ -33609,6 +33684,7 @@ function processElement(element) {
|
|
|
33609
33684
|
isAttibuteAction: attrCheckResult.result,
|
|
33610
33685
|
attrFunction: attrCheckResult.scriptFunction || null
|
|
33611
33686
|
});
|
|
33687
|
+
console.log("添加后元素缓冲数:", window.i18nElementsMap.size);
|
|
33612
33688
|
applyTranslation(element);
|
|
33613
33689
|
return true;
|
|
33614
33690
|
}
|
|
@@ -33616,7 +33692,7 @@ function unProcessElement(element) {
|
|
|
33616
33692
|
if (element && element.nodeType !== 1) {
|
|
33617
33693
|
return;
|
|
33618
33694
|
}
|
|
33619
|
-
|
|
33695
|
+
let hasChildren = hasChildElements(element);
|
|
33620
33696
|
if (hasChildren) {
|
|
33621
33697
|
let children = element.children;
|
|
33622
33698
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -33624,9 +33700,19 @@ function unProcessElement(element) {
|
|
|
33624
33700
|
}
|
|
33625
33701
|
}
|
|
33626
33702
|
const localDomID = element.getAttribute("localDomID");
|
|
33703
|
+
if (localDomID) {
|
|
33704
|
+
console.log(`处理元素ID:${localDomID} 移除缓存`);
|
|
33705
|
+
element.removeAttribute("localDomID");
|
|
33706
|
+
}
|
|
33627
33707
|
if (localDomID && window.i18nElementsMap.has(localDomID)) {
|
|
33708
|
+
// let oldValue = element.getAttribute("oldValue");
|
|
33709
|
+
// if(oldValue){
|
|
33710
|
+
// element.removeAttribute("oldValue");
|
|
33711
|
+
// 更新元素的innerHTML
|
|
33712
|
+
// element.innerHTML = oldValue;
|
|
33713
|
+
// }
|
|
33628
33714
|
window.i18nElementsMap.delete(localDomID);
|
|
33629
|
-
console.log("
|
|
33715
|
+
console.log("移除后元素缓冲数:", window.i18nElementsMap.size);
|
|
33630
33716
|
}
|
|
33631
33717
|
}
|
|
33632
33718
|
|
|
@@ -33636,6 +33722,12 @@ function unProcessElement(element) {
|
|
|
33636
33722
|
* @param {string} lang - 语言标识符
|
|
33637
33723
|
*/
|
|
33638
33724
|
const applyTranslation = async element => {
|
|
33725
|
+
let parentNode = element.parentNode;
|
|
33726
|
+
if (!parentNode) {
|
|
33727
|
+
unProcessElement(element);
|
|
33728
|
+
console.log("元素已无父节点,移除缓存");
|
|
33729
|
+
return;
|
|
33730
|
+
}
|
|
33639
33731
|
let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
|
|
33640
33732
|
let appID = getPoratlAppID();
|
|
33641
33733
|
const elementId = element.getAttribute("localDomID");
|
|
@@ -33679,7 +33771,7 @@ const initDomNodeI18NObserver = () => {
|
|
|
33679
33771
|
console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
|
|
33680
33772
|
// 遍历Map,更新每个已处理元素的翻译
|
|
33681
33773
|
for (const [elementId, item] of window.i18nElementsMap.entries()) {
|
|
33682
|
-
console.log("更新元素翻译:", elementId, item.dom);
|
|
33774
|
+
// console.log("更新元素翻译:", elementId, item.dom);
|
|
33683
33775
|
applyTranslation(item.dom);
|
|
33684
33776
|
}
|
|
33685
33777
|
});
|
|
@@ -33714,6 +33806,13 @@ const initDomNodeI18NObserver = () => {
|
|
|
33714
33806
|
// 创建日志条目并显示
|
|
33715
33807
|
console.log(`文本修改: ${oldValue} → ${newValue}`);
|
|
33716
33808
|
const parentElement = targetNode.parentNode;
|
|
33809
|
+
if (parentElement) {
|
|
33810
|
+
let localDomID = parentElement.getAttribute("localDomID");
|
|
33811
|
+
// 如果有localDomID,说明之前处理过,先移除缓存
|
|
33812
|
+
if (localDomID) {
|
|
33813
|
+
unProcessElement(parentElement);
|
|
33814
|
+
}
|
|
33815
|
+
}
|
|
33717
33816
|
processElement(parentElement);
|
|
33718
33817
|
}
|
|
33719
33818
|
});
|