isdata-customer-sdk 0.1.98 → 0.1.99
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 +358 -76
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +358 -76
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +4 -4
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -29566,6 +29566,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29566
29566
|
addIMMapping: function() { return /* reexport */ addIMMapping; },
|
|
29567
29567
|
addObjectUsedTimes: function() { return /* reexport */ addObjectUsedTimes; },
|
|
29568
29568
|
addWindowTrustedOrigin: function() { return /* reexport */ addWindowTrustedOrigin; },
|
|
29569
|
+
checkTextFormat: function() { return /* reexport */ checkTextFormat; },
|
|
29569
29570
|
createFileFromUrl: function() { return /* reexport */ createFileFromUrl; },
|
|
29570
29571
|
decrypt: function() { return /* reexport */ decrypt; },
|
|
29571
29572
|
destroyEventCenter: function() { return /* reexport */ destroyEventCenter; },
|
|
@@ -33096,12 +33097,245 @@ const dify_extractFilenameFromUrl = url => {
|
|
|
33096
33097
|
return "downloaded_file"; // URL 解析失败时的默认文件名
|
|
33097
33098
|
}
|
|
33098
33099
|
};
|
|
33100
|
+
;// ./src/api/smardaten_i18n/table_i18n.js
|
|
33101
|
+
|
|
33102
|
+
const check = element => {
|
|
33103
|
+
const checkResult = {
|
|
33104
|
+
result: false,
|
|
33105
|
+
innerHTMLMatch: null
|
|
33106
|
+
};
|
|
33107
|
+
const classes = element.classList;
|
|
33108
|
+
// 检查表格头部 序号 和 操作 列
|
|
33109
|
+
if (classes.contains("ant-table-cell")) {
|
|
33110
|
+
let innerHTML = element.innerHTML;
|
|
33111
|
+
if (innerHTML.includes("序号") || innerHTML.includes("Serial No.")) {
|
|
33112
|
+
console.log("检查smardaten平台表格 序号 元素:", innerHTML);
|
|
33113
|
+
let tempHTMLMatch = {
|
|
33114
|
+
oldValue: '$L{PLATFORM_SERIAL_NO}'
|
|
33115
|
+
};
|
|
33116
|
+
checkResult.result = true;
|
|
33117
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33118
|
+
return checkResult;
|
|
33119
|
+
}
|
|
33120
|
+
if (innerHTML.includes("操作")) {
|
|
33121
|
+
console.log("检查smardaten平台表格 操作 元素:", innerHTML);
|
|
33122
|
+
let tempHTMLMatch = {
|
|
33123
|
+
oldValue: '$L{PLATFORM_OPERATE}'
|
|
33124
|
+
};
|
|
33125
|
+
checkResult.result = true;
|
|
33126
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33127
|
+
return checkResult;
|
|
33128
|
+
}
|
|
33129
|
+
}
|
|
33130
|
+
// 检查分页组件
|
|
33131
|
+
if (classes.contains("total_pag_num")) {
|
|
33132
|
+
let innerHTML = element.innerHTML;
|
|
33133
|
+
if (innerHTML.includes("共") && innerHTML.includes("条") || innerHTML.includes("Total") && innerHTML.includes("pieces")) {
|
|
33134
|
+
console.log("检查smardaten平台分页 共xx条 元素:", innerHTML);
|
|
33135
|
+
let scriptFunction = (appID, lang) => {
|
|
33136
|
+
let scriptNode = null;
|
|
33137
|
+
for (let node of element.childNodes) {
|
|
33138
|
+
// 检查是否为文本节点且包含"Total"
|
|
33139
|
+
if (node.tagName === "SPAN") {
|
|
33140
|
+
scriptNode = node;
|
|
33141
|
+
}
|
|
33142
|
+
}
|
|
33143
|
+
let scriptNodes = [{
|
|
33144
|
+
nodeType: Node.TEXT_NODE,
|
|
33145
|
+
key: 'PLATFORM_TOTAL'
|
|
33146
|
+
}, {
|
|
33147
|
+
nodeType: "SCRIPTNODE",
|
|
33148
|
+
node: scriptNode
|
|
33149
|
+
}, {
|
|
33150
|
+
nodeType: Node.TEXT_NODE,
|
|
33151
|
+
key: 'PLATFORM_PIECES'
|
|
33152
|
+
}];
|
|
33153
|
+
for (let i = 0; i < element.childNodes.length; i++) {
|
|
33154
|
+
let childNode = element.childNodes[i];
|
|
33155
|
+
if (childNode.nodeType === Node.TEXT_NODE) {
|
|
33156
|
+
element.removeChild(childNode);
|
|
33157
|
+
}
|
|
33158
|
+
}
|
|
33159
|
+
for (let i = 0; i < scriptNodes.length; i++) {
|
|
33160
|
+
let scriptNodeItem = scriptNodes[i];
|
|
33161
|
+
if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
|
|
33162
|
+
let textNode = document.createTextNode(i18n(scriptNodeItem.key, appID, lang) || scriptNodeItem.key);
|
|
33163
|
+
element.appendChild(textNode);
|
|
33164
|
+
}
|
|
33165
|
+
if (scriptNodeItem.nodeType === "SCRIPTNODE") {
|
|
33166
|
+
element.appendChild(scriptNodeItem.node);
|
|
33167
|
+
}
|
|
33168
|
+
}
|
|
33169
|
+
};
|
|
33170
|
+
let tempHTMLMatch = {
|
|
33171
|
+
isScriptOldValue: true,
|
|
33172
|
+
scriptFunction: scriptFunction
|
|
33173
|
+
};
|
|
33174
|
+
checkResult.result = true;
|
|
33175
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33176
|
+
return checkResult;
|
|
33177
|
+
}
|
|
33178
|
+
}
|
|
33179
|
+
// 检查分页组件 跳至xx页
|
|
33180
|
+
if (classes.contains("ant-pagination-options-quick-jumper")) {
|
|
33181
|
+
let innerHTML = element.innerHTML;
|
|
33182
|
+
if (innerHTML.includes("跳至") && innerHTML.includes("页") || innerHTML.includes("Go to") && innerHTML.includes("Page")) {
|
|
33183
|
+
console.log("检查smardaten平台分页 跳至xx页 元素:", innerHTML);
|
|
33184
|
+
let scriptFunction = (appID, lang) => {
|
|
33185
|
+
let scriptNode = null;
|
|
33186
|
+
for (let node of element.childNodes) {
|
|
33187
|
+
// 检查是否为文本节点且包含"Total"
|
|
33188
|
+
if (node.tagName === "INPUT") {
|
|
33189
|
+
scriptNode = node;
|
|
33190
|
+
}
|
|
33191
|
+
}
|
|
33192
|
+
let scriptNodes = [{
|
|
33193
|
+
nodeType: Node.TEXT_NODE,
|
|
33194
|
+
key: 'PLATFORM_JUNPTO'
|
|
33195
|
+
}, {
|
|
33196
|
+
nodeType: "SCRIPTNODE",
|
|
33197
|
+
node: scriptNode
|
|
33198
|
+
}, {
|
|
33199
|
+
nodeType: Node.TEXT_NODE,
|
|
33200
|
+
key: 'PLATFORM_PAGE'
|
|
33201
|
+
}];
|
|
33202
|
+
for (let i = 0; i < element.childNodes.length; i++) {
|
|
33203
|
+
let childNode = element.childNodes[i];
|
|
33204
|
+
if (childNode.nodeType === Node.TEXT_NODE) {
|
|
33205
|
+
element.removeChild(childNode);
|
|
33206
|
+
}
|
|
33207
|
+
}
|
|
33208
|
+
for (let i = 0; i < scriptNodes.length; i++) {
|
|
33209
|
+
let scriptNodeItem = scriptNodes[i];
|
|
33210
|
+
if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
|
|
33211
|
+
let textNode = document.createTextNode(i18n(scriptNodeItem.key, appID, lang) || scriptNodeItem.key);
|
|
33212
|
+
element.appendChild(textNode);
|
|
33213
|
+
}
|
|
33214
|
+
if (scriptNodeItem.nodeType === "SCRIPTNODE") {
|
|
33215
|
+
element.appendChild(scriptNodeItem.node);
|
|
33216
|
+
}
|
|
33217
|
+
}
|
|
33218
|
+
};
|
|
33219
|
+
let tempHTMLMatch = {
|
|
33220
|
+
isScriptOldValue: true,
|
|
33221
|
+
scriptFunction: scriptFunction
|
|
33222
|
+
};
|
|
33223
|
+
checkResult.result = true;
|
|
33224
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33225
|
+
return checkResult;
|
|
33226
|
+
}
|
|
33227
|
+
}
|
|
33228
|
+
// 检查每页xx条
|
|
33229
|
+
if (classes.contains("ant-select-selection-item") || classes.contains("ant-select-item-option-content")) {
|
|
33230
|
+
let innerHTML = element.innerHTML;
|
|
33231
|
+
console.log("检查smardaten平台分页 每页xx条 元素:", innerHTML);
|
|
33232
|
+
if (innerHTML.includes("/") && innerHTML.includes("page") || innerHTML.includes("/") && innerHTML.includes("条") && innerHTML.includes("页")) {
|
|
33233
|
+
let oldValue = element.innerHTML;
|
|
33234
|
+
if (innerHTML.includes("page")) {
|
|
33235
|
+
oldValue = oldValue.replace('page', '$L{PLATFORM_PAGE}');
|
|
33236
|
+
}
|
|
33237
|
+
if (innerHTML.includes("页")) {
|
|
33238
|
+
oldValue = oldValue.replace('页', '$L{PLATFORM_PAGE}');
|
|
33239
|
+
}
|
|
33240
|
+
if (innerHTML.includes("条")) {
|
|
33241
|
+
oldValue = oldValue.replace('条', '$L{PLATFORM_PIECES}');
|
|
33242
|
+
}
|
|
33243
|
+
let tempHTMLMatch = {
|
|
33244
|
+
oldValue: oldValue
|
|
33245
|
+
};
|
|
33246
|
+
checkResult.result = true;
|
|
33247
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33248
|
+
return checkResult;
|
|
33249
|
+
}
|
|
33250
|
+
}
|
|
33251
|
+
// 检查删除确认对话框标题
|
|
33252
|
+
if (classes.contains("ant-popover-message-title")) {
|
|
33253
|
+
let innerHTML = element.innerHTML;
|
|
33254
|
+
if (innerHTML.includes("确认执行:") || innerHTML.includes("Confirm Execution:")) {
|
|
33255
|
+
console.log("检查smardaten平台删除提问对话框:", innerHTML);
|
|
33256
|
+
let tempHTMLMatch = {
|
|
33257
|
+
oldValue: '$L{PLATFORM_DELETE_CONFIRM_TITLE}'
|
|
33258
|
+
};
|
|
33259
|
+
checkResult.result = true;
|
|
33260
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33261
|
+
return checkResult;
|
|
33262
|
+
}
|
|
33263
|
+
}
|
|
33264
|
+
// 检查删除确认对话框按钮 取消 确认
|
|
33265
|
+
if (classes.contains("ant-btn-sm")) {
|
|
33266
|
+
let innerHTML = element.innerHTML;
|
|
33267
|
+
if (innerHTML.includes("Cancel") || innerHTML.includes("取消")) {
|
|
33268
|
+
console.log("检查smardaten平台 Tip提问取消删除按钮:", innerHTML);
|
|
33269
|
+
let tempHTMLMatch = {
|
|
33270
|
+
oldValue: '$L{PLATFORM_CANCEL}'
|
|
33271
|
+
};
|
|
33272
|
+
checkResult.result = true;
|
|
33273
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33274
|
+
return checkResult;
|
|
33275
|
+
}
|
|
33276
|
+
if (innerHTML.includes("确认") || innerHTML.includes("OK")) {
|
|
33277
|
+
console.log("检查smardaten平台 Tip提问确认删除按钮:", innerHTML);
|
|
33278
|
+
let tempHTMLMatch = {
|
|
33279
|
+
oldValue: '$L{PLATFORM_OK}'
|
|
33280
|
+
};
|
|
33281
|
+
checkResult.result = true;
|
|
33282
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33283
|
+
return checkResult;
|
|
33284
|
+
}
|
|
33285
|
+
}
|
|
33286
|
+
return checkResult;
|
|
33287
|
+
};
|
|
33288
|
+
;// ./src/api/smardaten_i18n/catalog_i18n.js
|
|
33289
|
+
|
|
33290
|
+
const catalog_i18n_check = element => {
|
|
33291
|
+
const checkResult = {
|
|
33292
|
+
result: false,
|
|
33293
|
+
innerHTMLMatch: null
|
|
33294
|
+
};
|
|
33295
|
+
const classes = element.classList;
|
|
33296
|
+
// 检查目录列表 名称 列
|
|
33297
|
+
if (classes.contains("catalog_name_content")) {
|
|
33298
|
+
let innerHTML = element.innerHTML;
|
|
33299
|
+
let oldValue = innerHTML;
|
|
33300
|
+
console.log("检查smardaten平台目录列表 元素:", innerHTML);
|
|
33301
|
+
let scriptFunction = (appID, lang) => {
|
|
33302
|
+
for (let i = 0; i < element.childNodes.length; i++) {
|
|
33303
|
+
let scriptNodeItem = element.childNodes[i];
|
|
33304
|
+
if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
|
|
33305
|
+
let text = element.getAttribute("oldValue");
|
|
33306
|
+
let isTextMatch = checkTextFormat(text);
|
|
33307
|
+
if (!isTextMatch) {
|
|
33308
|
+
element.appendChild(scriptNodeItem);
|
|
33309
|
+
} else {
|
|
33310
|
+
element.removeChild(scriptNodeItem);
|
|
33311
|
+
let key = isTextMatch.key;
|
|
33312
|
+
let textNode = document.createTextNode(i18n(key, appID, lang) || key);
|
|
33313
|
+
element.appendChild(textNode);
|
|
33314
|
+
}
|
|
33315
|
+
} else {
|
|
33316
|
+
element.appendChild(scriptNodeItem);
|
|
33317
|
+
}
|
|
33318
|
+
}
|
|
33319
|
+
};
|
|
33320
|
+
let tempHTMLMatch = {
|
|
33321
|
+
oldValue: oldValue,
|
|
33322
|
+
isScriptOldValue: true,
|
|
33323
|
+
scriptFunction: scriptFunction
|
|
33324
|
+
};
|
|
33325
|
+
checkResult.result = true;
|
|
33326
|
+
checkResult.innerHTMLMatch = tempHTMLMatch;
|
|
33327
|
+
return checkResult;
|
|
33328
|
+
}
|
|
33329
|
+
return checkResult;
|
|
33330
|
+
};
|
|
33099
33331
|
;// ./src/api/i18n.js
|
|
33100
33332
|
|
|
33101
33333
|
|
|
33102
33334
|
|
|
33103
33335
|
|
|
33104
33336
|
|
|
33337
|
+
|
|
33338
|
+
|
|
33105
33339
|
const getLanguages = async appID => {
|
|
33106
33340
|
let queryData = {
|
|
33107
33341
|
param: {
|
|
@@ -33161,7 +33395,49 @@ function generateUniqueId() {
|
|
|
33161
33395
|
return `i18n_${Date.now()}_${window.idCounter++}`;
|
|
33162
33396
|
}
|
|
33163
33397
|
|
|
33164
|
-
|
|
33398
|
+
/**
|
|
33399
|
+
* 检查平台特定元素并返回匹配结果
|
|
33400
|
+
* @param {*} element
|
|
33401
|
+
* @returns
|
|
33402
|
+
*/
|
|
33403
|
+
function checkPlatformElement(element) {
|
|
33404
|
+
const checkResult = {
|
|
33405
|
+
result: false,
|
|
33406
|
+
innerHTMLMatch: null
|
|
33407
|
+
};
|
|
33408
|
+
let checkArr = [check, catalog_i18n_check];
|
|
33409
|
+
for (let i = 0; i < checkArr.length; i++) {
|
|
33410
|
+
let checkFunc = checkArr[i];
|
|
33411
|
+
let checkResult = checkFunc(element);
|
|
33412
|
+
if (checkResult.result) {
|
|
33413
|
+
return checkResult;
|
|
33414
|
+
}
|
|
33415
|
+
}
|
|
33416
|
+
return checkResult;
|
|
33417
|
+
}
|
|
33418
|
+
function checkParantNodeNeedFiller(element) {
|
|
33419
|
+
const filterTags = ["BUTTON"];
|
|
33420
|
+
for (let tag of filterTags) {
|
|
33421
|
+
if (element.tagName === tag) {
|
|
33422
|
+
return false;
|
|
33423
|
+
}
|
|
33424
|
+
}
|
|
33425
|
+
//当为目录列表时catalog_name_content
|
|
33426
|
+
//当为表格单元格时ant-table-cell
|
|
33427
|
+
//当为分页总数时total_pag_num
|
|
33428
|
+
//当为分页每页条数选择时ant-pagination-options-quick-jumper
|
|
33429
|
+
//当为分页下拉选择时ant-select-selection-item
|
|
33430
|
+
//当为分页下拉选项时ant-select-item-option-content
|
|
33431
|
+
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"];
|
|
33432
|
+
for (let cls of classes) {
|
|
33433
|
+
if (element.classList.contains(cls)) {
|
|
33434
|
+
return false;
|
|
33435
|
+
}
|
|
33436
|
+
}
|
|
33437
|
+
return true;
|
|
33438
|
+
}
|
|
33439
|
+
|
|
33440
|
+
// 处理DOM元素的函数
|
|
33165
33441
|
function processElement(element) {
|
|
33166
33442
|
if (element.nodeType != 1) {
|
|
33167
33443
|
return false;
|
|
@@ -33173,71 +33449,71 @@ function processElement(element) {
|
|
|
33173
33449
|
for (let i = 0; i < children.length; i++) {
|
|
33174
33450
|
processElement(children[i]);
|
|
33175
33451
|
}
|
|
33176
|
-
|
|
33177
|
-
|
|
33178
|
-
|
|
33452
|
+
|
|
33453
|
+
// 检查父亲性质节点是否需要被过滤
|
|
33454
|
+
const isParentNodeNeedFilter = checkParantNodeNeedFiller(element);
|
|
33455
|
+
if (isParentNodeNeedFilter) {
|
|
33179
33456
|
return false;
|
|
33180
33457
|
}
|
|
33181
33458
|
}
|
|
33182
33459
|
// element.setAttribute("i18nProcessed", "true"); // 标记元素已被处理
|
|
33183
|
-
// 检查是否是input元素
|
|
33184
|
-
const isInputElement = element.tagName === "INPUT";
|
|
33185
33460
|
// 检查placeholder是否匹配
|
|
33186
33461
|
const placeholder = element.getAttribute("placeholder") || element.placeholder;
|
|
33187
|
-
const placeholderMatch =
|
|
33188
|
-
|
|
33189
|
-
|
|
33190
|
-
const value = element.getAttribute("value") || element.value;
|
|
33191
|
-
const valueMatch = isInputElement && value ? checkTextFormat(value) : null;
|
|
33462
|
+
const placeholderMatch = placeholder ? checkTextFormat(placeholder) : null;
|
|
33463
|
+
const title = element.getAttribute("title") || element.title;
|
|
33464
|
+
const titleMatch = title ? checkTextFormat(title) : null;
|
|
33192
33465
|
|
|
33193
33466
|
// 检查innerHTML是否匹配(仅对没有子元素的元素)
|
|
33194
33467
|
let innerHTMLMatch = null;
|
|
33195
|
-
// if (!hasChildren) {
|
|
33196
33468
|
const innerHTML = element.innerHTML;
|
|
33197
33469
|
innerHTMLMatch = checkTextFormat(innerHTML);
|
|
33198
|
-
|
|
33470
|
+
|
|
33471
|
+
//检查是否是smardaten平台元素
|
|
33472
|
+
const checkResult = checkPlatformElement(element);
|
|
33473
|
+
if (checkResult.result) {
|
|
33474
|
+
innerHTMLMatch = checkResult.innerHTMLMatch;
|
|
33475
|
+
}
|
|
33199
33476
|
|
|
33200
33477
|
// 如果没有匹配的内容,则不处理
|
|
33201
|
-
if (!placeholderMatch && !
|
|
33478
|
+
if (!placeholderMatch && !innerHTMLMatch && !checkResult.result && !titleMatch) {
|
|
33202
33479
|
return false;
|
|
33203
33480
|
}
|
|
33204
|
-
|
|
33481
|
+
let elementId = element.getAttribute("localDomID");
|
|
33482
|
+
if (!elementId) {
|
|
33483
|
+
elementId = generateUniqueId();
|
|
33484
|
+
}
|
|
33205
33485
|
element.setAttribute("localDomID", elementId);
|
|
33206
|
-
|
|
33207
|
-
|
|
33208
|
-
|
|
33209
|
-
|
|
33210
|
-
|
|
33486
|
+
|
|
33487
|
+
// console.log("处理元素:", element, {
|
|
33488
|
+
// placeholderMatch,
|
|
33489
|
+
// valueMatch,
|
|
33490
|
+
// innerHTMLMatch,
|
|
33491
|
+
// });
|
|
33211
33492
|
// 处理placeholder
|
|
33212
33493
|
if (placeholderMatch) {
|
|
33213
|
-
element.setAttribute("localPlaceholderKey", placeholderMatch.key);
|
|
33214
33494
|
element.setAttribute("oldPlaceholderValue", placeholder);
|
|
33215
33495
|
}
|
|
33216
|
-
|
|
33217
|
-
|
|
33218
|
-
if (valueMatch) {
|
|
33219
|
-
element.setAttribute("localValueKey", valueMatch.key);
|
|
33220
|
-
element.setAttribute("oldValueValue", value);
|
|
33496
|
+
if (titleMatch) {
|
|
33497
|
+
element.setAttribute("oldTitleValue", title);
|
|
33221
33498
|
}
|
|
33222
33499
|
|
|
33223
33500
|
// 处理innerHTML(仅对没有子元素的元素)
|
|
33224
|
-
if (innerHTMLMatch) {
|
|
33225
|
-
element.setAttribute("localKey", innerHTMLMatch.key);
|
|
33501
|
+
if (!hasChildren && innerHTMLMatch) {
|
|
33226
33502
|
element.setAttribute("oldValue", element.innerHTML);
|
|
33227
33503
|
}
|
|
33504
|
+
if (checkResult.result) {
|
|
33505
|
+
element.setAttribute("oldValue", innerHTMLMatch.oldValue);
|
|
33506
|
+
}
|
|
33228
33507
|
|
|
33229
33508
|
// 添加到Map缓存
|
|
33230
33509
|
window.i18nElementsMap.set(elementId, {
|
|
33231
33510
|
dom: element,
|
|
33232
33511
|
id: elementId,
|
|
33233
|
-
key: innerHTMLMatch ? innerHTMLMatch.key : null,
|
|
33234
|
-
placeholderKey: placeholderMatch ? placeholderMatch.key : null,
|
|
33235
|
-
valueKey: valueMatch ? valueMatch.key : null,
|
|
33236
33512
|
oldValue: innerHTMLMatch ? element.innerHTML : null,
|
|
33237
33513
|
oldPlaceholderValue: placeholderMatch ? placeholder : null,
|
|
33238
|
-
|
|
33239
|
-
|
|
33240
|
-
|
|
33514
|
+
oldTitleValue: titleMatch ? title : null,
|
|
33515
|
+
isScriptOldValue: innerHTMLMatch ? innerHTMLMatch.isScriptOldValue || false : false,
|
|
33516
|
+
scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null
|
|
33241
33517
|
});
|
|
33242
33518
|
applyTranslation(element);
|
|
33243
33519
|
return true;
|
|
@@ -33272,10 +33548,9 @@ const applyTranslation = async element => {
|
|
|
33272
33548
|
const cachedItem = window.i18nElementsMap.get(elementId);
|
|
33273
33549
|
if (!cachedItem) return;
|
|
33274
33550
|
// 处理placeholder(如果是input元素)
|
|
33275
|
-
if (cachedItem.
|
|
33276
|
-
const placeholderKey = element.getAttribute("localPlaceholderKey");
|
|
33551
|
+
if (cachedItem.oldPlaceholderValue) {
|
|
33277
33552
|
const oldPlaceholderValue = element.getAttribute("oldPlaceholderValue");
|
|
33278
|
-
if (
|
|
33553
|
+
if (oldPlaceholderValue) {
|
|
33279
33554
|
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33280
33555
|
const regex = /\$L\{([^}]+)\}/g;
|
|
33281
33556
|
// 替换所有 $L{...} 占位符为翻译文本
|
|
@@ -33291,50 +33566,47 @@ const applyTranslation = async element => {
|
|
|
33291
33566
|
element.setAttribute("placeholder", newPlaceholderValue);
|
|
33292
33567
|
}
|
|
33293
33568
|
}
|
|
33294
|
-
|
|
33295
|
-
|
|
33296
|
-
|
|
33297
|
-
const valueKey = element.getAttribute("localValueKey");
|
|
33298
|
-
const oldValueValue = element.getAttribute("oldValueValue");
|
|
33299
|
-
if (valueKey && oldValueValue) {
|
|
33569
|
+
if (cachedItem.oldTitleValue) {
|
|
33570
|
+
const oldTitleValue = element.getAttribute("oldTitleValue");
|
|
33571
|
+
if (oldTitleValue) {
|
|
33300
33572
|
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33301
33573
|
const regex = /\$L\{([^}]+)\}/g;
|
|
33302
|
-
|
|
33303
33574
|
// 替换所有 $L{...} 占位符为翻译文本
|
|
33304
|
-
let
|
|
33575
|
+
let newTitleValue = oldTitleValue;
|
|
33305
33576
|
let match;
|
|
33306
|
-
while ((match = regex.exec(
|
|
33577
|
+
while ((match = regex.exec(oldTitleValue)) !== null) {
|
|
33307
33578
|
const fullMatch = match[0];
|
|
33308
|
-
const
|
|
33309
|
-
const translation = i18n(
|
|
33310
|
-
|
|
33579
|
+
const titleKey = match[1];
|
|
33580
|
+
const translation = i18n(titleKey, appID, lang);
|
|
33581
|
+
newTitleValue = newTitleValue.replace(fullMatch, translation);
|
|
33582
|
+
// 更新元素的title属性
|
|
33583
|
+
element.setAttribute("title", newTitleValue);
|
|
33311
33584
|
}
|
|
33312
|
-
|
|
33313
|
-
// 更新元素的value属性
|
|
33314
|
-
element.setAttribute("value", newValueValue);
|
|
33315
33585
|
}
|
|
33316
33586
|
}
|
|
33317
|
-
|
|
33318
|
-
|
|
33319
|
-
|
|
33320
|
-
|
|
33321
|
-
|
|
33322
|
-
|
|
33323
|
-
|
|
33324
|
-
|
|
33325
|
-
|
|
33326
|
-
|
|
33327
|
-
|
|
33328
|
-
|
|
33329
|
-
|
|
33330
|
-
|
|
33331
|
-
|
|
33332
|
-
|
|
33333
|
-
|
|
33587
|
+
// console.log("更新innerHTML翻译:", element);
|
|
33588
|
+
if (cachedItem.isScriptOldValue) {
|
|
33589
|
+
cachedItem.scriptFunction(appID, lang);
|
|
33590
|
+
} else {
|
|
33591
|
+
if (cachedItem.oldValue) {
|
|
33592
|
+
const oldValue = element.getAttribute("oldValue");
|
|
33593
|
+
if (oldValue) {
|
|
33594
|
+
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33595
|
+
const regex = /\$L\{([^}]+)\}/g;
|
|
33596
|
+
// 替换所有 $L{...} 占位符为翻译文本
|
|
33597
|
+
let newValue = oldValue;
|
|
33598
|
+
let match;
|
|
33599
|
+
while ((match = regex.exec(oldValue)) !== null) {
|
|
33600
|
+
const fullMatch = match[0];
|
|
33601
|
+
const placeholderKey = match[1];
|
|
33602
|
+
const translation = i18n(placeholderKey, appID, lang);
|
|
33603
|
+
newValue = newValue.replace(fullMatch, translation);
|
|
33604
|
+
}
|
|
33605
|
+
nextTick(() => {
|
|
33606
|
+
// 更新元素的innerHTML
|
|
33607
|
+
element.innerHTML = newValue;
|
|
33608
|
+
});
|
|
33334
33609
|
}
|
|
33335
|
-
|
|
33336
|
-
// 更新元素的innerHTML
|
|
33337
|
-
element.innerHTML = newValue;
|
|
33338
33610
|
}
|
|
33339
33611
|
}
|
|
33340
33612
|
};
|
|
@@ -33344,8 +33616,7 @@ const initDomNodeI18NObserver = () => {
|
|
|
33344
33616
|
} else {
|
|
33345
33617
|
window.i18nElementsMap.clear();
|
|
33346
33618
|
}
|
|
33347
|
-
registerEventListener("IPORTAL_LANGUAGE_CHANGE_EVENT", async
|
|
33348
|
-
const lang = data.lang;
|
|
33619
|
+
registerEventListener("IPORTAL_LANGUAGE_CHANGE_EVENT", async lang => {
|
|
33349
33620
|
console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
|
|
33350
33621
|
// 遍历Map,更新每个已处理元素的翻译
|
|
33351
33622
|
for (const [elementId, item] of window.i18nElementsMap.entries()) {
|
|
@@ -33363,7 +33634,6 @@ const initDomNodeI18NObserver = () => {
|
|
|
33363
33634
|
processElement(node);
|
|
33364
33635
|
}
|
|
33365
33636
|
}
|
|
33366
|
-
|
|
33367
33637
|
// 节点移除
|
|
33368
33638
|
if (mutation.removedNodes.length > 0) {
|
|
33369
33639
|
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
@@ -33371,6 +33641,16 @@ const initDomNodeI18NObserver = () => {
|
|
|
33371
33641
|
unProcessElement(node);
|
|
33372
33642
|
}
|
|
33373
33643
|
}
|
|
33644
|
+
if (mutation.type === 'characterData') {
|
|
33645
|
+
// 处理文本变化
|
|
33646
|
+
// const oldValue = mutation.oldValue;
|
|
33647
|
+
const targetNode = mutation.target;
|
|
33648
|
+
// const newValue = targetNode.data;
|
|
33649
|
+
// 创建日志条目并显示
|
|
33650
|
+
// console.log(`文本修改: ${oldValue} → ${newValue}`);
|
|
33651
|
+
const parentElement = targetNode.parentNode;
|
|
33652
|
+
processElement(parentElement);
|
|
33653
|
+
}
|
|
33374
33654
|
});
|
|
33375
33655
|
});
|
|
33376
33656
|
|
|
@@ -33382,7 +33662,9 @@ const initDomNodeI18NObserver = () => {
|
|
|
33382
33662
|
// 观察所有后代节点
|
|
33383
33663
|
attributes: false,
|
|
33384
33664
|
// 不观察属性变化
|
|
33385
|
-
characterData:
|
|
33665
|
+
characterData: true,
|
|
33666
|
+
// 不观察文本内容变化
|
|
33667
|
+
characterDataOldValue: true
|
|
33386
33668
|
};
|
|
33387
33669
|
// 开始观察目标节点
|
|
33388
33670
|
const targetNode = document.body;
|