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