isdata-customer-sdk 0.1.100 → 0.2.1
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 +137 -130
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +137 -130
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +3 -3
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.common.js
CHANGED
|
@@ -33089,7 +33089,7 @@ const dify_extractFilenameFromUrl = url => {
|
|
|
33089
33089
|
};
|
|
33090
33090
|
;// external {"commonjs":"vue","commonjs2":"vue","root":"Vue"}
|
|
33091
33091
|
var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue");
|
|
33092
|
-
;// ./src/api/smardaten_i18n/table_i18n.js
|
|
33092
|
+
;// ./src/api/i18n/smardaten_i18n/table_i18n.js
|
|
33093
33093
|
|
|
33094
33094
|
const check = element => {
|
|
33095
33095
|
const checkResult = {
|
|
@@ -33160,7 +33160,7 @@ const check = element => {
|
|
|
33160
33160
|
}
|
|
33161
33161
|
};
|
|
33162
33162
|
let tempHTMLMatch = {
|
|
33163
|
-
|
|
33163
|
+
isScriptAction: true,
|
|
33164
33164
|
scriptFunction: scriptFunction
|
|
33165
33165
|
};
|
|
33166
33166
|
checkResult.result = true;
|
|
@@ -33209,7 +33209,7 @@ const check = element => {
|
|
|
33209
33209
|
}
|
|
33210
33210
|
};
|
|
33211
33211
|
let tempHTMLMatch = {
|
|
33212
|
-
|
|
33212
|
+
isScriptAction: true,
|
|
33213
33213
|
scriptFunction: scriptFunction
|
|
33214
33214
|
};
|
|
33215
33215
|
checkResult.result = true;
|
|
@@ -33277,7 +33277,7 @@ const check = element => {
|
|
|
33277
33277
|
}
|
|
33278
33278
|
return checkResult;
|
|
33279
33279
|
};
|
|
33280
|
-
;// ./src/api/smardaten_i18n/catalog_i18n.js
|
|
33280
|
+
;// ./src/api/i18n/smardaten_i18n/catalog_i18n.js
|
|
33281
33281
|
|
|
33282
33282
|
const catalog_i18n_check = element => {
|
|
33283
33283
|
const checkResult = {
|
|
@@ -33311,7 +33311,7 @@ const catalog_i18n_check = element => {
|
|
|
33311
33311
|
};
|
|
33312
33312
|
let tempHTMLMatch = {
|
|
33313
33313
|
oldValue: oldValue,
|
|
33314
|
-
|
|
33314
|
+
isScriptAction: true,
|
|
33315
33315
|
scriptFunction: scriptFunction
|
|
33316
33316
|
};
|
|
33317
33317
|
checkResult.result = true;
|
|
@@ -33320,7 +33320,93 @@ const catalog_i18n_check = element => {
|
|
|
33320
33320
|
}
|
|
33321
33321
|
return checkResult;
|
|
33322
33322
|
};
|
|
33323
|
-
;// ./src/api/i18n.js
|
|
33323
|
+
;// ./src/api/i18n/commom_i18n/common_i18n.js
|
|
33324
|
+
|
|
33325
|
+
const common_i18n_check = element => {
|
|
33326
|
+
const checkResult = {
|
|
33327
|
+
result: false,
|
|
33328
|
+
innerHTMLMatch: null
|
|
33329
|
+
};
|
|
33330
|
+
// 检查目录列表 名称 列
|
|
33331
|
+
if (element.tagName === 'BUTTON') {
|
|
33332
|
+
let innerHTML = element.innerHTML;
|
|
33333
|
+
let oldValue = innerHTML;
|
|
33334
|
+
console.log("检查 button 元素:", innerHTML);
|
|
33335
|
+
let scriptFunction = (appID, lang) => {
|
|
33336
|
+
for (let i = 0; i < element.childNodes.length; i++) {
|
|
33337
|
+
let scriptNodeItem = element.childNodes[i];
|
|
33338
|
+
if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
|
|
33339
|
+
let text = element.getAttribute("oldValue");
|
|
33340
|
+
let isTextMatch = checkTextFormat(text);
|
|
33341
|
+
if (!isTextMatch) {
|
|
33342
|
+
element.appendChild(scriptNodeItem);
|
|
33343
|
+
} else {
|
|
33344
|
+
element.removeChild(scriptNodeItem);
|
|
33345
|
+
let key = isTextMatch.key;
|
|
33346
|
+
let textNode = document.createTextNode(i18n(key, appID, lang) || key);
|
|
33347
|
+
element.appendChild(textNode);
|
|
33348
|
+
}
|
|
33349
|
+
} else {
|
|
33350
|
+
element.appendChild(scriptNodeItem);
|
|
33351
|
+
}
|
|
33352
|
+
}
|
|
33353
|
+
};
|
|
33354
|
+
let tempHTMLMatch = {
|
|
33355
|
+
oldValue: oldValue,
|
|
33356
|
+
isScriptAction: true,
|
|
33357
|
+
scriptFunction: scriptFunction
|
|
33358
|
+
};
|
|
33359
|
+
checkResult.result = true;
|
|
33360
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33361
|
+
return checkResult;
|
|
33362
|
+
}
|
|
33363
|
+
return checkResult;
|
|
33364
|
+
};
|
|
33365
|
+
;// ./src/api/i18n/commom_i18n/attribute_i18n.js
|
|
33366
|
+
|
|
33367
|
+
const attribute_i18n_check = element => {
|
|
33368
|
+
const checkResult = {
|
|
33369
|
+
result: false,
|
|
33370
|
+
innerHTMLMatch: null
|
|
33371
|
+
};
|
|
33372
|
+
const checkAttributes = ["placeholder", "title"];
|
|
33373
|
+
for (let i = 0; i < checkAttributes.length; i++) {
|
|
33374
|
+
let attr = checkAttributes[i];
|
|
33375
|
+
let attrValue = element.getAttribute(attr) || element[attr];
|
|
33376
|
+
const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
|
|
33377
|
+
if (attrMatch) {
|
|
33378
|
+
console.log("检查元素属性 i18n 元素:", attr, attrValue);
|
|
33379
|
+
element.setAttribute(`old${attr}Value`, attrValue);
|
|
33380
|
+
checkResult.result = true;
|
|
33381
|
+
}
|
|
33382
|
+
}
|
|
33383
|
+
let scriptFunction = (appID, lang) => {
|
|
33384
|
+
for (let i = 0; i < checkAttributes.length; i++) {
|
|
33385
|
+
let attr = checkAttributes[i];
|
|
33386
|
+
const oldAttrValue = element.getAttribute(`old${attr}Value`);
|
|
33387
|
+
if (oldAttrValue) {
|
|
33388
|
+
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33389
|
+
const regex = /\$L\{([^}]+)\}/g;
|
|
33390
|
+
// 替换所有 $L{...} 占位符为翻译文本
|
|
33391
|
+
let newAttrValue = oldAttrValue;
|
|
33392
|
+
let match;
|
|
33393
|
+
while ((match = regex.exec(oldAttrValue)) !== null) {
|
|
33394
|
+
const fullMatch = match[0];
|
|
33395
|
+
const attrKey = match[1];
|
|
33396
|
+
const translation = i18n(attrKey, appID, lang);
|
|
33397
|
+
newAttrValue = newAttrValue.replace(fullMatch, translation);
|
|
33398
|
+
}
|
|
33399
|
+
// 更新元素的placeholder属性
|
|
33400
|
+
element.setAttribute(attr, newAttrValue);
|
|
33401
|
+
}
|
|
33402
|
+
}
|
|
33403
|
+
};
|
|
33404
|
+
checkResult.scriptFunction = scriptFunction;
|
|
33405
|
+
return checkResult;
|
|
33406
|
+
};
|
|
33407
|
+
;// ./src/api/i18n/i18n.js
|
|
33408
|
+
|
|
33409
|
+
|
|
33324
33410
|
|
|
33325
33411
|
|
|
33326
33412
|
|
|
@@ -33393,41 +33479,20 @@ function generateUniqueId() {
|
|
|
33393
33479
|
* @param {*} element
|
|
33394
33480
|
* @returns
|
|
33395
33481
|
*/
|
|
33396
|
-
function
|
|
33397
|
-
const
|
|
33482
|
+
function checkPlatformElementContent(element) {
|
|
33483
|
+
const checkContentResult = {
|
|
33398
33484
|
result: false,
|
|
33399
33485
|
innerHTMLMatch: null
|
|
33400
33486
|
};
|
|
33401
|
-
let checkArr = [check, catalog_i18n_check];
|
|
33487
|
+
let checkArr = [check, catalog_i18n_check, common_i18n_check];
|
|
33402
33488
|
for (let i = 0; i < checkArr.length; i++) {
|
|
33403
33489
|
let checkFunc = checkArr[i];
|
|
33404
|
-
let
|
|
33405
|
-
if (
|
|
33406
|
-
return
|
|
33490
|
+
let checkContentResult = checkFunc(element);
|
|
33491
|
+
if (checkContentResult.result) {
|
|
33492
|
+
return checkContentResult;
|
|
33407
33493
|
}
|
|
33408
33494
|
}
|
|
33409
|
-
return
|
|
33410
|
-
}
|
|
33411
|
-
function checkParantNodeNeedFiller(element) {
|
|
33412
|
-
const filterTags = ["BUTTON"];
|
|
33413
|
-
for (let tag of filterTags) {
|
|
33414
|
-
if (element.tagName === tag) {
|
|
33415
|
-
return false;
|
|
33416
|
-
}
|
|
33417
|
-
}
|
|
33418
|
-
//当为目录列表时catalog_name_content
|
|
33419
|
-
//当为表格单元格时ant-table-cell
|
|
33420
|
-
//当为分页总数时total_pag_num
|
|
33421
|
-
//当为分页每页条数选择时ant-pagination-options-quick-jumper
|
|
33422
|
-
//当为分页下拉选择时ant-select-selection-item
|
|
33423
|
-
//当为分页下拉选项时ant-select-item-option-content
|
|
33424
|
-
const classes = ["catalog_name_content", "ant-table-cell", "total_pag_num", "ant-pagination-options-quick-jumper", "ant-select-selection-item", "ant-select-item-option-content", "catalog_name_content", "catalog_tree_node"];
|
|
33425
|
-
for (let cls of classes) {
|
|
33426
|
-
if (element.classList.contains(cls)) {
|
|
33427
|
-
return false;
|
|
33428
|
-
}
|
|
33429
|
-
}
|
|
33430
|
-
return true;
|
|
33495
|
+
return checkContentResult;
|
|
33431
33496
|
}
|
|
33432
33497
|
|
|
33433
33498
|
// 处理DOM元素的函数
|
|
@@ -33442,33 +33507,32 @@ function processElement(element) {
|
|
|
33442
33507
|
for (let i = 0; i < children.length; i++) {
|
|
33443
33508
|
processElement(children[i]);
|
|
33444
33509
|
}
|
|
33445
|
-
|
|
33446
|
-
// 检查父亲性质节点是否需要被过滤
|
|
33447
|
-
const isParentNodeNeedFilter = checkParantNodeNeedFiller(element);
|
|
33448
|
-
if (isParentNodeNeedFilter) {
|
|
33449
|
-
return false;
|
|
33450
|
-
}
|
|
33451
33510
|
}
|
|
33452
|
-
// element.setAttribute("i18nProcessed", "true"); // 标记元素已被处理
|
|
33453
|
-
// 检查placeholder是否匹配
|
|
33454
|
-
const placeholder = element.getAttribute("placeholder") || element.placeholder;
|
|
33455
|
-
const placeholderMatch = placeholder ? checkTextFormat(placeholder) : null;
|
|
33456
|
-
const title = element.getAttribute("title") || element.title;
|
|
33457
|
-
const titleMatch = title ? checkTextFormat(title) : null;
|
|
33458
33511
|
|
|
33459
33512
|
// 检查innerHTML是否匹配(仅对没有子元素的元素)
|
|
33460
33513
|
let innerHTMLMatch = null;
|
|
33461
|
-
const
|
|
33462
|
-
|
|
33514
|
+
const attrCheckResult = attribute_i18n_check(element);
|
|
33515
|
+
if (attrCheckResult.result) {
|
|
33516
|
+
console.log("检查到属性匹配元素:", element);
|
|
33517
|
+
}
|
|
33463
33518
|
|
|
33464
33519
|
//检查是否是smardaten平台元素
|
|
33465
|
-
const
|
|
33466
|
-
if (
|
|
33467
|
-
innerHTMLMatch =
|
|
33520
|
+
const checkContentResult = checkPlatformElementContent(element);
|
|
33521
|
+
if (checkContentResult.result) {
|
|
33522
|
+
innerHTMLMatch = checkContentResult.innerHTMLMatch;
|
|
33523
|
+
element.setAttribute("oldValue", innerHTMLMatch.oldValue);
|
|
33524
|
+
} else {
|
|
33525
|
+
if (!hasChildren) {
|
|
33526
|
+
const innerHTML = element.innerHTML;
|
|
33527
|
+
innerHTMLMatch = checkTextFormat(innerHTML);
|
|
33528
|
+
if (innerHTMLMatch) {
|
|
33529
|
+
element.setAttribute("oldValue", element.innerHTML);
|
|
33530
|
+
}
|
|
33531
|
+
}
|
|
33468
33532
|
}
|
|
33469
33533
|
|
|
33470
33534
|
// 如果没有匹配的内容,则不处理
|
|
33471
|
-
if (!
|
|
33535
|
+
if (!innerHTMLMatch && !checkContentResult.result && !attrCheckResult.result) {
|
|
33472
33536
|
return false;
|
|
33473
33537
|
}
|
|
33474
33538
|
let elementId = element.getAttribute("localDomID");
|
|
@@ -33477,36 +33541,14 @@ function processElement(element) {
|
|
|
33477
33541
|
}
|
|
33478
33542
|
element.setAttribute("localDomID", elementId);
|
|
33479
33543
|
|
|
33480
|
-
// console.log("处理元素:", element, {
|
|
33481
|
-
// placeholderMatch,
|
|
33482
|
-
// valueMatch,
|
|
33483
|
-
// innerHTMLMatch,
|
|
33484
|
-
// });
|
|
33485
|
-
// 处理placeholder
|
|
33486
|
-
if (placeholderMatch) {
|
|
33487
|
-
element.setAttribute("oldPlaceholderValue", placeholder);
|
|
33488
|
-
}
|
|
33489
|
-
if (titleMatch) {
|
|
33490
|
-
element.setAttribute("oldTitleValue", title);
|
|
33491
|
-
}
|
|
33492
|
-
|
|
33493
|
-
// 处理innerHTML(仅对没有子元素的元素)
|
|
33494
|
-
if (!hasChildren && innerHTMLMatch) {
|
|
33495
|
-
element.setAttribute("oldValue", element.innerHTML);
|
|
33496
|
-
}
|
|
33497
|
-
if (checkResult.result) {
|
|
33498
|
-
element.setAttribute("oldValue", innerHTMLMatch.oldValue);
|
|
33499
|
-
}
|
|
33500
|
-
|
|
33501
33544
|
// 添加到Map缓存
|
|
33502
33545
|
window.i18nElementsMap.set(elementId, {
|
|
33503
33546
|
dom: element,
|
|
33504
33547
|
id: elementId,
|
|
33505
|
-
|
|
33506
|
-
|
|
33507
|
-
|
|
33508
|
-
|
|
33509
|
-
scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null
|
|
33548
|
+
isScriptAction: innerHTMLMatch ? innerHTMLMatch.isScriptAction || false : false,
|
|
33549
|
+
scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null,
|
|
33550
|
+
isAttibuteAction: attrCheckResult.result,
|
|
33551
|
+
attrFunction: attrCheckResult.scriptFunction || null
|
|
33510
33552
|
});
|
|
33511
33553
|
applyTranslation(element);
|
|
33512
33554
|
return true;
|
|
@@ -33540,66 +33582,31 @@ const applyTranslation = async element => {
|
|
|
33540
33582
|
const elementId = element.getAttribute("localDomID");
|
|
33541
33583
|
const cachedItem = window.i18nElementsMap.get(elementId);
|
|
33542
33584
|
if (!cachedItem) return;
|
|
33543
|
-
//
|
|
33544
|
-
if (cachedItem.
|
|
33545
|
-
|
|
33546
|
-
|
|
33585
|
+
// 处理属性
|
|
33586
|
+
if (cachedItem.isAttibuteAction) {
|
|
33587
|
+
cachedItem.attrFunction(appID, lang);
|
|
33588
|
+
}
|
|
33589
|
+
// 处理innerHTML
|
|
33590
|
+
if (cachedItem.isScriptAction) {
|
|
33591
|
+
cachedItem.scriptFunction(appID, lang);
|
|
33592
|
+
} else {
|
|
33593
|
+
const oldValue = element.getAttribute("oldValue");
|
|
33594
|
+
if (oldValue) {
|
|
33547
33595
|
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33548
33596
|
const regex = /\$L\{([^}]+)\}/g;
|
|
33549
33597
|
// 替换所有 $L{...} 占位符为翻译文本
|
|
33550
|
-
let
|
|
33598
|
+
let newValue = oldValue;
|
|
33551
33599
|
let match;
|
|
33552
|
-
while ((match = regex.exec(
|
|
33600
|
+
while ((match = regex.exec(oldValue)) !== null) {
|
|
33553
33601
|
const fullMatch = match[0];
|
|
33554
33602
|
const placeholderKey = match[1];
|
|
33555
33603
|
const translation = i18n(placeholderKey, appID, lang);
|
|
33556
|
-
|
|
33557
|
-
}
|
|
33558
|
-
// 更新元素的placeholder属性
|
|
33559
|
-
element.setAttribute("placeholder", newPlaceholderValue);
|
|
33560
|
-
}
|
|
33561
|
-
}
|
|
33562
|
-
if (cachedItem.oldTitleValue) {
|
|
33563
|
-
const oldTitleValue = element.getAttribute("oldTitleValue");
|
|
33564
|
-
if (oldTitleValue) {
|
|
33565
|
-
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33566
|
-
const regex = /\$L\{([^}]+)\}/g;
|
|
33567
|
-
// 替换所有 $L{...} 占位符为翻译文本
|
|
33568
|
-
let newTitleValue = oldTitleValue;
|
|
33569
|
-
let match;
|
|
33570
|
-
while ((match = regex.exec(oldTitleValue)) !== null) {
|
|
33571
|
-
const fullMatch = match[0];
|
|
33572
|
-
const titleKey = match[1];
|
|
33573
|
-
const translation = i18n(titleKey, appID, lang);
|
|
33574
|
-
newTitleValue = newTitleValue.replace(fullMatch, translation);
|
|
33575
|
-
// 更新元素的title属性
|
|
33576
|
-
element.setAttribute("title", newTitleValue);
|
|
33577
|
-
}
|
|
33578
|
-
}
|
|
33579
|
-
}
|
|
33580
|
-
// console.log("更新innerHTML翻译:", element);
|
|
33581
|
-
if (cachedItem.isScriptOldValue) {
|
|
33582
|
-
cachedItem.scriptFunction(appID, lang);
|
|
33583
|
-
} else {
|
|
33584
|
-
if (cachedItem.oldValue) {
|
|
33585
|
-
const oldValue = element.getAttribute("oldValue");
|
|
33586
|
-
if (oldValue) {
|
|
33587
|
-
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33588
|
-
const regex = /\$L\{([^}]+)\}/g;
|
|
33589
|
-
// 替换所有 $L{...} 占位符为翻译文本
|
|
33590
|
-
let newValue = oldValue;
|
|
33591
|
-
let match;
|
|
33592
|
-
while ((match = regex.exec(oldValue)) !== null) {
|
|
33593
|
-
const fullMatch = match[0];
|
|
33594
|
-
const placeholderKey = match[1];
|
|
33595
|
-
const translation = i18n(placeholderKey, appID, lang);
|
|
33596
|
-
newValue = newValue.replace(fullMatch, translation);
|
|
33597
|
-
}
|
|
33598
|
-
(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.nextTick)(() => {
|
|
33599
|
-
// 更新元素的innerHTML
|
|
33600
|
-
element.innerHTML = newValue;
|
|
33601
|
-
});
|
|
33604
|
+
newValue = newValue.replace(fullMatch, translation);
|
|
33602
33605
|
}
|
|
33606
|
+
(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.nextTick)(() => {
|
|
33607
|
+
// 更新元素的innerHTML
|
|
33608
|
+
element.innerHTML = newValue;
|
|
33609
|
+
});
|
|
33603
33610
|
}
|
|
33604
33611
|
}
|
|
33605
33612
|
};
|