isdata-customer-sdk 0.2.8 → 0.2.10
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 +124 -21
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +124 -21
- 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")) {
|
|
@@ -33370,6 +33370,8 @@ const common_i18n_check = element => {
|
|
|
33370
33370
|
};
|
|
33371
33371
|
// 检查目录列表 名称 列
|
|
33372
33372
|
if (element.tagName === 'BUTTON') {
|
|
33373
|
+
//TODO:先检查新的是否需要解析,新的不需要有可能是解析后的再次判断,如果有历史解析值,则解析
|
|
33374
|
+
//如果新的需要解析,更新缓存的历史解析值
|
|
33373
33375
|
let innerHTML = element.innerHTML;
|
|
33374
33376
|
let oldValue = element.getAttribute("oldValue");
|
|
33375
33377
|
if (!oldValue) {
|
|
@@ -33377,8 +33379,8 @@ const common_i18n_check = element => {
|
|
|
33377
33379
|
}
|
|
33378
33380
|
let firstCheck = checkTextFormat(oldValue);
|
|
33379
33381
|
let firstCheckResult = firstCheck ? true : false;
|
|
33380
|
-
console.log("检查 button 元素:",
|
|
33381
|
-
console.log("检查结果:",
|
|
33382
|
+
// console.log("检查 button 元素:",innerHTML);
|
|
33383
|
+
// console.log("检查结果:",firstCheckResult);
|
|
33382
33384
|
let scriptFunction = (appID, lang) => {
|
|
33383
33385
|
let elementsArray = [];
|
|
33384
33386
|
element.childNodes.forEach(node => {
|
|
@@ -33423,13 +33425,16 @@ const attribute_i18n_check = element => {
|
|
|
33423
33425
|
result: false,
|
|
33424
33426
|
innerHTMLMatch: null
|
|
33425
33427
|
};
|
|
33428
|
+
if (!element) {
|
|
33429
|
+
return checkResult;
|
|
33430
|
+
}
|
|
33426
33431
|
const checkAttributes = ["placeholder", "title"];
|
|
33427
33432
|
for (let i = 0; i < checkAttributes.length; i++) {
|
|
33428
33433
|
let attr = checkAttributes[i];
|
|
33429
33434
|
let attrValue = element.getAttribute(attr) || element[attr];
|
|
33430
33435
|
const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
|
|
33431
33436
|
if (attrMatch) {
|
|
33432
|
-
console.log("检查元素属性 i18n 元素:", attr, attrValue);
|
|
33437
|
+
// console.log("检查元素属性 i18n 元素:", attr, attrValue);
|
|
33433
33438
|
element.setAttribute(`old${attr}Value`, attrValue);
|
|
33434
33439
|
checkResult.result = true;
|
|
33435
33440
|
}
|
|
@@ -33458,6 +33463,61 @@ const attribute_i18n_check = element => {
|
|
|
33458
33463
|
checkResult.scriptFunction = scriptFunction;
|
|
33459
33464
|
return checkResult;
|
|
33460
33465
|
};
|
|
33466
|
+
;// ./src/api/i18n/smardaten_i18n/calendar_i18n.js
|
|
33467
|
+
|
|
33468
|
+
|
|
33469
|
+
function extractYearMonth(str) {
|
|
33470
|
+
const regex = /(\d{4})年(0?[1-9]|1[0-2])月/g;
|
|
33471
|
+
const matches = str.matchAll(regex);
|
|
33472
|
+
const result = [];
|
|
33473
|
+
for (const match of matches) {
|
|
33474
|
+
const year = parseInt(match[1], 10);
|
|
33475
|
+
const month = parseInt(match[2], 10);
|
|
33476
|
+
result.push({
|
|
33477
|
+
year,
|
|
33478
|
+
month
|
|
33479
|
+
});
|
|
33480
|
+
}
|
|
33481
|
+
return result;
|
|
33482
|
+
}
|
|
33483
|
+
const calendar_i18n_check = element => {
|
|
33484
|
+
const checkResult = {
|
|
33485
|
+
result: false,
|
|
33486
|
+
innerHTMLMatch: null
|
|
33487
|
+
};
|
|
33488
|
+
const classes = element.classList;
|
|
33489
|
+
if (!classes) {
|
|
33490
|
+
return checkResult;
|
|
33491
|
+
}
|
|
33492
|
+
// 检查日历标题
|
|
33493
|
+
if (classes.contains("fc-toolbar-title")) {
|
|
33494
|
+
let scriptFunction = (appID, lang) => {
|
|
33495
|
+
let oldValue = element.getAttribute("oldValue");
|
|
33496
|
+
let yearMonthList = extractYearMonth(oldValue);
|
|
33497
|
+
if (yearMonthList.length > 0) {
|
|
33498
|
+
let yearMonth = yearMonthList[0];
|
|
33499
|
+
let year = yearMonth.year;
|
|
33500
|
+
let month = yearMonth.month;
|
|
33501
|
+
let newInnerHTML = `${year}/${month}`;
|
|
33502
|
+
element.innerHTML = newInnerHTML;
|
|
33503
|
+
}
|
|
33504
|
+
};
|
|
33505
|
+
let innerHTML = element.innerHTML;
|
|
33506
|
+
let testRule = /^\d{4}年(0?[1-9]|1[0-2])月$/;
|
|
33507
|
+
if (testRule.test(innerHTML)) {
|
|
33508
|
+
console.log("检查smardaten平台日历标题 元素:", innerHTML);
|
|
33509
|
+
let tempHTMLMatch = {
|
|
33510
|
+
oldValue: innerHTML,
|
|
33511
|
+
isScriptAction: true,
|
|
33512
|
+
scriptFunction: scriptFunction
|
|
33513
|
+
};
|
|
33514
|
+
checkResult.result = true;
|
|
33515
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33516
|
+
return checkResult;
|
|
33517
|
+
}
|
|
33518
|
+
}
|
|
33519
|
+
return checkResult;
|
|
33520
|
+
};
|
|
33461
33521
|
;// ./src/api/i18n/i18n.js
|
|
33462
33522
|
|
|
33463
33523
|
|
|
@@ -33469,6 +33529,7 @@ const attribute_i18n_check = element => {
|
|
|
33469
33529
|
|
|
33470
33530
|
|
|
33471
33531
|
|
|
33532
|
+
|
|
33472
33533
|
const getLanguages = async appID => {
|
|
33473
33534
|
let queryData = {
|
|
33474
33535
|
param: {
|
|
@@ -33503,7 +33564,7 @@ const loadi18nTexts = async appID => {
|
|
|
33503
33564
|
* @returns {boolean} - 是否有子元素
|
|
33504
33565
|
*/
|
|
33505
33566
|
function hasChildElements(element) {
|
|
33506
|
-
return element.children
|
|
33567
|
+
return element && element.children?.length > 0;
|
|
33507
33568
|
}
|
|
33508
33569
|
|
|
33509
33570
|
/**
|
|
@@ -33538,7 +33599,7 @@ function checkPlatformElementContent(element) {
|
|
|
33538
33599
|
result: false,
|
|
33539
33600
|
innerHTMLMatch: null
|
|
33540
33601
|
};
|
|
33541
|
-
let checkArr = [check, catalog_i18n_check, common_i18n_check];
|
|
33602
|
+
let checkArr = [check, catalog_i18n_check, calendar_i18n_check, common_i18n_check];
|
|
33542
33603
|
for (let i = 0; i < checkArr.length; i++) {
|
|
33543
33604
|
let checkFunc = checkArr[i];
|
|
33544
33605
|
let checkContentResult = checkFunc(element);
|
|
@@ -33549,6 +33610,10 @@ function checkPlatformElementContent(element) {
|
|
|
33549
33610
|
return checkContentResult;
|
|
33550
33611
|
}
|
|
33551
33612
|
function processElement(element) {
|
|
33613
|
+
if (!element) {
|
|
33614
|
+
return false;
|
|
33615
|
+
}
|
|
33616
|
+
|
|
33552
33617
|
// 仅处理元素节点
|
|
33553
33618
|
if (element && element.nodeType != 1) {
|
|
33554
33619
|
return false;
|
|
@@ -33559,6 +33624,14 @@ function processElement(element) {
|
|
|
33559
33624
|
if (hasChildren) {
|
|
33560
33625
|
let children = element.children;
|
|
33561
33626
|
for (let i = 0; i < children.length; i++) {
|
|
33627
|
+
let child = children[i];
|
|
33628
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
33629
|
+
let childLocalDomID = child.getAttribute("localDomID");
|
|
33630
|
+
// 如果子元素有localDomID但不在缓存中,移除localDomID属性
|
|
33631
|
+
if (childLocalDomID && window.i18nElementsMap && !window.i18nElementsMap.has(childLocalDomID)) {
|
|
33632
|
+
unProcessElement(child);
|
|
33633
|
+
}
|
|
33634
|
+
}
|
|
33562
33635
|
processElement(children[i]);
|
|
33563
33636
|
}
|
|
33564
33637
|
}
|
|
@@ -33567,7 +33640,7 @@ function processElement(element) {
|
|
|
33567
33640
|
let innerHTMLMatch = null;
|
|
33568
33641
|
const attrCheckResult = attribute_i18n_check(element);
|
|
33569
33642
|
if (attrCheckResult.result) {
|
|
33570
|
-
console.log("检查到属性匹配元素:",
|
|
33643
|
+
// console.log("检查到属性匹配元素:",element);
|
|
33571
33644
|
}
|
|
33572
33645
|
|
|
33573
33646
|
//检查是否是smardaten平台元素
|
|
@@ -33577,10 +33650,16 @@ function processElement(element) {
|
|
|
33577
33650
|
element.setAttribute("oldValue", innerHTMLMatch.oldValue);
|
|
33578
33651
|
} else {
|
|
33579
33652
|
if (!hasChildren) {
|
|
33580
|
-
|
|
33581
|
-
|
|
33653
|
+
//如果存在历史值,说明之前解析过,有可能是值需要刷新触发
|
|
33654
|
+
//TODO:先检查新的是否需要解析,新的不需要有可能是解析后的再次判断,如果有历史解析值,则解析
|
|
33655
|
+
//如果新的需要解析,更新缓存的历史解析值
|
|
33656
|
+
let oldValue = element.getAttribute("oldValue");
|
|
33657
|
+
if (!oldValue) {
|
|
33658
|
+
oldValue = element.innerHTML;
|
|
33659
|
+
}
|
|
33660
|
+
innerHTMLMatch = checkTextFormat(oldValue);
|
|
33582
33661
|
if (innerHTMLMatch) {
|
|
33583
|
-
element.setAttribute("oldValue",
|
|
33662
|
+
element.setAttribute("oldValue", oldValue);
|
|
33584
33663
|
}
|
|
33585
33664
|
}
|
|
33586
33665
|
}
|
|
@@ -33609,6 +33688,7 @@ function processElement(element) {
|
|
|
33609
33688
|
isAttibuteAction: attrCheckResult.result,
|
|
33610
33689
|
attrFunction: attrCheckResult.scriptFunction || null
|
|
33611
33690
|
});
|
|
33691
|
+
console.log("添加后元素缓冲数:", window.i18nElementsMap.size);
|
|
33612
33692
|
applyTranslation(element);
|
|
33613
33693
|
return true;
|
|
33614
33694
|
}
|
|
@@ -33616,17 +33696,27 @@ function unProcessElement(element) {
|
|
|
33616
33696
|
if (element && element.nodeType !== 1) {
|
|
33617
33697
|
return;
|
|
33618
33698
|
}
|
|
33619
|
-
|
|
33620
|
-
|
|
33621
|
-
|
|
33622
|
-
|
|
33623
|
-
|
|
33624
|
-
|
|
33625
|
-
|
|
33699
|
+
let hasChildren = hasChildElements(element);
|
|
33700
|
+
if (hasChildren) {
|
|
33701
|
+
let children = element.children;
|
|
33702
|
+
for (let i = 0; i < children.length; i++) {
|
|
33703
|
+
unProcessElement(children[i]);
|
|
33704
|
+
}
|
|
33705
|
+
}
|
|
33626
33706
|
const localDomID = element.getAttribute("localDomID");
|
|
33707
|
+
if (localDomID) {
|
|
33708
|
+
console.log(`处理元素ID:${localDomID} 移除缓存`);
|
|
33709
|
+
element.removeAttribute("localDomID");
|
|
33710
|
+
}
|
|
33627
33711
|
if (localDomID && window.i18nElementsMap.has(localDomID)) {
|
|
33712
|
+
// let oldValue = element.getAttribute("oldValue");
|
|
33713
|
+
// if(oldValue){
|
|
33714
|
+
// element.removeAttribute("oldValue");
|
|
33715
|
+
// 更新元素的innerHTML
|
|
33716
|
+
// element.innerHTML = oldValue;
|
|
33717
|
+
// }
|
|
33628
33718
|
window.i18nElementsMap.delete(localDomID);
|
|
33629
|
-
console.log("
|
|
33719
|
+
console.log("移除后元素缓冲数:", window.i18nElementsMap.size);
|
|
33630
33720
|
}
|
|
33631
33721
|
}
|
|
33632
33722
|
|
|
@@ -33636,6 +33726,12 @@ function unProcessElement(element) {
|
|
|
33636
33726
|
* @param {string} lang - 语言标识符
|
|
33637
33727
|
*/
|
|
33638
33728
|
const applyTranslation = async element => {
|
|
33729
|
+
let parentNode = element.parentNode;
|
|
33730
|
+
if (!parentNode) {
|
|
33731
|
+
unProcessElement(element);
|
|
33732
|
+
console.log("元素已无父节点,移除缓存");
|
|
33733
|
+
return;
|
|
33734
|
+
}
|
|
33639
33735
|
let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
|
|
33640
33736
|
let appID = getPoratlAppID();
|
|
33641
33737
|
const elementId = element.getAttribute("localDomID");
|
|
@@ -33679,7 +33775,7 @@ const initDomNodeI18NObserver = () => {
|
|
|
33679
33775
|
console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
|
|
33680
33776
|
// 遍历Map,更新每个已处理元素的翻译
|
|
33681
33777
|
for (const [elementId, item] of window.i18nElementsMap.entries()) {
|
|
33682
|
-
console.log("更新元素翻译:", elementId, item.dom);
|
|
33778
|
+
// console.log("更新元素翻译:", elementId, item.dom);
|
|
33683
33779
|
applyTranslation(item.dom);
|
|
33684
33780
|
}
|
|
33685
33781
|
});
|
|
@@ -33714,6 +33810,13 @@ const initDomNodeI18NObserver = () => {
|
|
|
33714
33810
|
// 创建日志条目并显示
|
|
33715
33811
|
console.log(`文本修改: ${oldValue} → ${newValue}`);
|
|
33716
33812
|
const parentElement = targetNode.parentNode;
|
|
33813
|
+
if (parentElement) {
|
|
33814
|
+
let localDomID = parentElement.getAttribute("localDomID");
|
|
33815
|
+
// 如果有localDomID,说明之前处理过,先移除缓存
|
|
33816
|
+
if (localDomID) {
|
|
33817
|
+
unProcessElement(parentElement);
|
|
33818
|
+
}
|
|
33819
|
+
}
|
|
33717
33820
|
processElement(parentElement);
|
|
33718
33821
|
}
|
|
33719
33822
|
});
|