isdata-customer-sdk 0.1.94 → 0.1.96
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 +293 -0
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +293 -0
- 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.umd.js
CHANGED
|
@@ -29588,6 +29588,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29588
29588
|
getIMHanlder: function() { return /* reexport */ getIMHanlder; },
|
|
29589
29589
|
getIntegrateAppInfoByID: function() { return /* reexport */ getIntegrateAppInfoByID; },
|
|
29590
29590
|
getKey: function() { return /* reexport */ getKey; },
|
|
29591
|
+
getLanguages: function() { return /* reexport */ getLanguages; },
|
|
29591
29592
|
getLoginPageNotices: function() { return /* reexport */ getLoginPageNotices; },
|
|
29592
29593
|
getLoginPortalAccountKey: function() { return /* reexport */ getLoginPortalAccountKey; },
|
|
29593
29594
|
getMappingAppInfoByID: function() { return /* reexport */ getMappingAppInfoByID; },
|
|
@@ -29613,8 +29614,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29613
29614
|
getUserAllMappngPortal: function() { return /* reexport */ getUserAllMappngPortal; },
|
|
29614
29615
|
getUserID: function() { return /* reexport */ getUserID; },
|
|
29615
29616
|
hasListener: function() { return /* reexport */ hasListener; },
|
|
29617
|
+
i18n: function() { return /* reexport */ i18n; },
|
|
29618
|
+
initDomNodeI18NObserver: function() { return /* reexport */ initDomNodeI18NObserver; },
|
|
29616
29619
|
initEventCenter: function() { return /* reexport */ initEventCenter; },
|
|
29617
29620
|
initFrameWindowListener: function() { return /* reexport */ initFrameWindowListener; },
|
|
29621
|
+
loadi18nTexts: function() { return /* reexport */ loadi18nTexts; },
|
|
29618
29622
|
loginAccount: function() { return /* reexport */ loginAccount; },
|
|
29619
29623
|
logoutAccount: function() { return /* reexport */ logoutAccount; },
|
|
29620
29624
|
queryAndStoreAppVariable: function() { return /* reexport */ queryAndStoreAppVariable; },
|
|
@@ -33092,6 +33096,294 @@ const dify_extractFilenameFromUrl = url => {
|
|
|
33092
33096
|
return "downloaded_file"; // URL 解析失败时的默认文件名
|
|
33093
33097
|
}
|
|
33094
33098
|
};
|
|
33099
|
+
;// ./src/api/i18n.js
|
|
33100
|
+
|
|
33101
|
+
|
|
33102
|
+
|
|
33103
|
+
|
|
33104
|
+
|
|
33105
|
+
const getLanguages = async appID => {
|
|
33106
|
+
let queryData = {
|
|
33107
|
+
param: {
|
|
33108
|
+
appID: appID
|
|
33109
|
+
}
|
|
33110
|
+
};
|
|
33111
|
+
let response = await request.post(`/dataservice/rest/orchestration/getAppLanguages`, queryData);
|
|
33112
|
+
let resultDatas = response.data.resultDatas || [];
|
|
33113
|
+
return resultDatas;
|
|
33114
|
+
};
|
|
33115
|
+
const i18n = (key, appID, localID) => {
|
|
33116
|
+
let result = window.customI18nObject?.get(`${appID}-${key}-${localID}`) || key;
|
|
33117
|
+
return result;
|
|
33118
|
+
};
|
|
33119
|
+
const loadi18nTexts = async appID => {
|
|
33120
|
+
let queryData = {
|
|
33121
|
+
param: {
|
|
33122
|
+
appID: appID
|
|
33123
|
+
}
|
|
33124
|
+
};
|
|
33125
|
+
let response = await request.post(`/dataservice/rest/orchestration/getAllTexts`, queryData);
|
|
33126
|
+
let resultDatas = response.data.resultDatas || [];
|
|
33127
|
+
window.customI18nObject = new Map();
|
|
33128
|
+
for (let item of resultDatas) {
|
|
33129
|
+
window.customI18nObject.set(`${appID}-${item.key}-${item.lang}`, item.value);
|
|
33130
|
+
}
|
|
33131
|
+
};
|
|
33132
|
+
|
|
33133
|
+
/**
|
|
33134
|
+
* 检查元素是否有子DOM元素
|
|
33135
|
+
* @param {HTMLElement} element - 要检查的DOM元素
|
|
33136
|
+
* @returns {boolean} - 是否有子元素
|
|
33137
|
+
*/
|
|
33138
|
+
function hasChildElements(element) {
|
|
33139
|
+
return element.children.length > 0;
|
|
33140
|
+
}
|
|
33141
|
+
|
|
33142
|
+
/**
|
|
33143
|
+
* 检查文本是否匹配$L{...}格式
|
|
33144
|
+
* @param {string} text - 要检查的文本
|
|
33145
|
+
* @returns {Object|null} - 匹配结果或null
|
|
33146
|
+
*/
|
|
33147
|
+
function checkTextFormat(text) {
|
|
33148
|
+
if (!text) return null;
|
|
33149
|
+
const regex = /\$L\{([^}]+)\}/;
|
|
33150
|
+
const match = text.match(regex);
|
|
33151
|
+
if (match) {
|
|
33152
|
+
return {
|
|
33153
|
+
fullMatch: match[0],
|
|
33154
|
+
key: match[1]
|
|
33155
|
+
};
|
|
33156
|
+
}
|
|
33157
|
+
return null;
|
|
33158
|
+
}
|
|
33159
|
+
function generateUniqueId() {
|
|
33160
|
+
window.idCounter = window.idCounter || 0;
|
|
33161
|
+
return `i18n_${Date.now()}_${window.idCounter++}`;
|
|
33162
|
+
}
|
|
33163
|
+
|
|
33164
|
+
// 处理单个DOM元素的函数
|
|
33165
|
+
function processElement(element) {
|
|
33166
|
+
if (element.nodeType != 1) {
|
|
33167
|
+
return false;
|
|
33168
|
+
}
|
|
33169
|
+
// 如果元素有子元素,则不处理innerHTML
|
|
33170
|
+
const hasChildren = hasChildElements(element);
|
|
33171
|
+
if (hasChildren) {
|
|
33172
|
+
let children = element.children;
|
|
33173
|
+
for (let i = 0; i < children.length; i++) {
|
|
33174
|
+
processElement(children[i]);
|
|
33175
|
+
}
|
|
33176
|
+
return false;
|
|
33177
|
+
}
|
|
33178
|
+
element.setAttribute("i18nProcessed", "true"); // 标记元素已被处理
|
|
33179
|
+
// 检查是否是input元素
|
|
33180
|
+
const isInputElement = element.tagName === "INPUT";
|
|
33181
|
+
// 检查placeholder是否匹配
|
|
33182
|
+
const placeholder = element.getAttribute("placeholder") || element.placeholder;
|
|
33183
|
+
const placeholderMatch = isInputElement && placeholder ? checkTextFormat(placeholder) : null;
|
|
33184
|
+
|
|
33185
|
+
// 检查value是否匹配(仅对按钮类型的input)
|
|
33186
|
+
const value = element.getAttribute("value") || element.value;
|
|
33187
|
+
const valueMatch = isInputElement && value ? checkTextFormat(value) : null;
|
|
33188
|
+
|
|
33189
|
+
// 检查innerHTML是否匹配(仅对没有子元素的元素)
|
|
33190
|
+
let innerHTMLMatch = null;
|
|
33191
|
+
if (!hasChildren) {
|
|
33192
|
+
const innerHTML = element.innerHTML;
|
|
33193
|
+
innerHTMLMatch = checkTextFormat(innerHTML);
|
|
33194
|
+
}
|
|
33195
|
+
|
|
33196
|
+
// 如果没有匹配的内容,则不处理
|
|
33197
|
+
if (!placeholderMatch && !valueMatch && !innerHTMLMatch) {
|
|
33198
|
+
return false;
|
|
33199
|
+
}
|
|
33200
|
+
const elementId = generateUniqueId();
|
|
33201
|
+
element.setAttribute("localDomID", elementId);
|
|
33202
|
+
console.log("处理元素:", element, {
|
|
33203
|
+
placeholderMatch,
|
|
33204
|
+
valueMatch,
|
|
33205
|
+
innerHTMLMatch
|
|
33206
|
+
});
|
|
33207
|
+
// 处理placeholder
|
|
33208
|
+
if (placeholderMatch) {
|
|
33209
|
+
element.setAttribute("localPlaceholderKey", placeholderMatch.key);
|
|
33210
|
+
element.setAttribute("oldPlaceholderValue", placeholder);
|
|
33211
|
+
}
|
|
33212
|
+
|
|
33213
|
+
// 处理value
|
|
33214
|
+
if (valueMatch) {
|
|
33215
|
+
element.setAttribute("localValueKey", valueMatch.key);
|
|
33216
|
+
element.setAttribute("oldValueValue", value);
|
|
33217
|
+
}
|
|
33218
|
+
|
|
33219
|
+
// 处理innerHTML(仅对没有子元素的元素)
|
|
33220
|
+
if (innerHTMLMatch) {
|
|
33221
|
+
element.setAttribute("localKey", innerHTMLMatch.key);
|
|
33222
|
+
element.setAttribute("oldValue", element.innerHTML);
|
|
33223
|
+
}
|
|
33224
|
+
|
|
33225
|
+
// 添加到Map缓存
|
|
33226
|
+
window.i18nElementsMap.set(elementId, {
|
|
33227
|
+
dom: element,
|
|
33228
|
+
id: elementId,
|
|
33229
|
+
key: innerHTMLMatch ? innerHTMLMatch.key : null,
|
|
33230
|
+
placeholderKey: placeholderMatch ? placeholderMatch.key : null,
|
|
33231
|
+
valueKey: valueMatch ? valueMatch.key : null,
|
|
33232
|
+
oldValue: innerHTMLMatch ? element.innerHTML : null,
|
|
33233
|
+
oldPlaceholderValue: placeholderMatch ? placeholder : null,
|
|
33234
|
+
oldValueValue: valueMatch ? value : null,
|
|
33235
|
+
isInputElement: isInputElement,
|
|
33236
|
+
hasChildren: hasChildren
|
|
33237
|
+
});
|
|
33238
|
+
applyTranslation(element);
|
|
33239
|
+
return true;
|
|
33240
|
+
}
|
|
33241
|
+
function unProcessElement(node) {
|
|
33242
|
+
if (node.nodeType !== 1) {
|
|
33243
|
+
return;
|
|
33244
|
+
}
|
|
33245
|
+
const hasChildren = hasChildElements(element);
|
|
33246
|
+
if (hasChildren) {
|
|
33247
|
+
let children = element.children;
|
|
33248
|
+
for (let i = 0; i < children.length; i++) {
|
|
33249
|
+
unProcessElement(children[i]);
|
|
33250
|
+
}
|
|
33251
|
+
}
|
|
33252
|
+
const localDomID = node.getAttribute("localDomID");
|
|
33253
|
+
if (localDomID && window.i18nElementsMap.has(localDomID)) {
|
|
33254
|
+
window.i18nElementsMap.delete(localDomID);
|
|
33255
|
+
console.log("移除元素缓存:", localDomID);
|
|
33256
|
+
}
|
|
33257
|
+
}
|
|
33258
|
+
|
|
33259
|
+
/**
|
|
33260
|
+
* 应用翻译到单个元素
|
|
33261
|
+
* @param {HTMLElement} element - 要更新的DOM元素
|
|
33262
|
+
* @param {string} lang - 语言标识符
|
|
33263
|
+
*/
|
|
33264
|
+
const applyTranslation = async element => {
|
|
33265
|
+
let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
|
|
33266
|
+
let appID = getPoratlAppID();
|
|
33267
|
+
const elementId = element.getAttribute("localDomID");
|
|
33268
|
+
const cachedItem = window.i18nElementsMap.get(elementId);
|
|
33269
|
+
if (!cachedItem) return;
|
|
33270
|
+
// 处理placeholder(如果是input元素)
|
|
33271
|
+
if (cachedItem.isInputElement && cachedItem.placeholderKey) {
|
|
33272
|
+
const placeholderKey = element.getAttribute("localPlaceholderKey");
|
|
33273
|
+
const oldPlaceholderValue = element.getAttribute("oldPlaceholderValue");
|
|
33274
|
+
if (placeholderKey && oldPlaceholderValue) {
|
|
33275
|
+
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33276
|
+
const regex = /\$L\{([^}]+)\}/g;
|
|
33277
|
+
// 替换所有 $L{...} 占位符为翻译文本
|
|
33278
|
+
let newPlaceholderValue = oldPlaceholderValue;
|
|
33279
|
+
let match;
|
|
33280
|
+
while ((match = regex.exec(oldPlaceholderValue)) !== null) {
|
|
33281
|
+
const fullMatch = match[0];
|
|
33282
|
+
const placeholderKey = match[1];
|
|
33283
|
+
const translation = i18n(placeholderKey, appID, lang);
|
|
33284
|
+
newPlaceholderValue = newPlaceholderValue.replace(fullMatch, translation);
|
|
33285
|
+
}
|
|
33286
|
+
// 更新元素的placeholder属性
|
|
33287
|
+
element.setAttribute("placeholder", newPlaceholderValue);
|
|
33288
|
+
}
|
|
33289
|
+
}
|
|
33290
|
+
|
|
33291
|
+
// 处理value(如果是input元素)
|
|
33292
|
+
if (cachedItem.isInputElement && cachedItem.valueKey) {
|
|
33293
|
+
const valueKey = element.getAttribute("localValueKey");
|
|
33294
|
+
const oldValueValue = element.getAttribute("oldValueValue");
|
|
33295
|
+
if (valueKey && oldValueValue) {
|
|
33296
|
+
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33297
|
+
const regex = /\$L\{([^}]+)\}/g;
|
|
33298
|
+
|
|
33299
|
+
// 替换所有 $L{...} 占位符为翻译文本
|
|
33300
|
+
let newValueValue = oldValueValue;
|
|
33301
|
+
let match;
|
|
33302
|
+
while ((match = regex.exec(oldValueValue)) !== null) {
|
|
33303
|
+
const fullMatch = match[0];
|
|
33304
|
+
const valueKey = match[1];
|
|
33305
|
+
const translation = i18n(valueKey, appID, lang);
|
|
33306
|
+
newValueValue = newValueValue.replace(fullMatch, translation);
|
|
33307
|
+
}
|
|
33308
|
+
|
|
33309
|
+
// 更新元素的value属性
|
|
33310
|
+
element.setAttribute("value", newValueValue);
|
|
33311
|
+
}
|
|
33312
|
+
}
|
|
33313
|
+
|
|
33314
|
+
// 处理innerHTML(如果没有子元素)
|
|
33315
|
+
if (!cachedItem.hasChildren && cachedItem.key) {
|
|
33316
|
+
const key = element.getAttribute("localKey");
|
|
33317
|
+
const oldValue = element.getAttribute("oldValue");
|
|
33318
|
+
if (key && oldValue) {
|
|
33319
|
+
// 创建正则表达式匹配所有 $L{...} 格式
|
|
33320
|
+
const regex = /\$L\{([^}]+)\}/g;
|
|
33321
|
+
|
|
33322
|
+
// 替换所有 $L{...} 占位符为翻译文本
|
|
33323
|
+
let newValue = oldValue;
|
|
33324
|
+
let match;
|
|
33325
|
+
while ((match = regex.exec(oldValue)) !== null) {
|
|
33326
|
+
const fullMatch = match[0];
|
|
33327
|
+
const placeholderKey = match[1];
|
|
33328
|
+
const translation = i18n(placeholderKey, appID, lang);
|
|
33329
|
+
newValue = newValue.replace(fullMatch, translation);
|
|
33330
|
+
}
|
|
33331
|
+
|
|
33332
|
+
// 更新元素的innerHTML
|
|
33333
|
+
element.innerHTML = newValue;
|
|
33334
|
+
}
|
|
33335
|
+
}
|
|
33336
|
+
};
|
|
33337
|
+
const initDomNodeI18NObserver = () => {
|
|
33338
|
+
if (!window.i18nElementsMap) {
|
|
33339
|
+
window.i18nElementsMap = new Map();
|
|
33340
|
+
} else {
|
|
33341
|
+
window.i18nElementsMap.clear();
|
|
33342
|
+
}
|
|
33343
|
+
registerEventListener("IPORTAL_LANGUAGE_CHANGE_EVENT", async lang => {
|
|
33344
|
+
console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
|
|
33345
|
+
// 遍历Map,更新每个已处理元素的翻译
|
|
33346
|
+
for (const [elementId, item] of window.i18nElementsMap.entries()) {
|
|
33347
|
+
applyTranslation(item.dom);
|
|
33348
|
+
}
|
|
33349
|
+
});
|
|
33350
|
+
// 创建观察器实例
|
|
33351
|
+
const observer = new MutationObserver(mutations => {
|
|
33352
|
+
mutations.forEach(mutation => {
|
|
33353
|
+
// 节点添加
|
|
33354
|
+
if (mutation.addedNodes.length > 0) {
|
|
33355
|
+
// console.log("检测到新增节点:", mutation.addedNodes);
|
|
33356
|
+
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
33357
|
+
const node = mutation.addedNodes[i];
|
|
33358
|
+
processElement(node);
|
|
33359
|
+
}
|
|
33360
|
+
}
|
|
33361
|
+
|
|
33362
|
+
// 节点移除
|
|
33363
|
+
if (mutation.removedNodes.length > 0) {
|
|
33364
|
+
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
|
33365
|
+
const node = mutation.removedNodes[i];
|
|
33366
|
+
unProcessElement(node);
|
|
33367
|
+
}
|
|
33368
|
+
}
|
|
33369
|
+
});
|
|
33370
|
+
});
|
|
33371
|
+
|
|
33372
|
+
// 配置观察选项
|
|
33373
|
+
const config = {
|
|
33374
|
+
childList: true,
|
|
33375
|
+
// 观察子节点变化
|
|
33376
|
+
subtree: true,
|
|
33377
|
+
// 观察所有后代节点
|
|
33378
|
+
attributes: false,
|
|
33379
|
+
// 不观察属性变化
|
|
33380
|
+
characterData: false // 不观察文本内容变化
|
|
33381
|
+
};
|
|
33382
|
+
// 开始观察目标节点
|
|
33383
|
+
const targetNode = document.body;
|
|
33384
|
+
processElement(targetNode);
|
|
33385
|
+
observer.observe(targetNode, config);
|
|
33386
|
+
};
|
|
33095
33387
|
;// ./src/main.js
|
|
33096
33388
|
|
|
33097
33389
|
|
|
@@ -33100,6 +33392,7 @@ const dify_extractFilenameFromUrl = url => {
|
|
|
33100
33392
|
|
|
33101
33393
|
|
|
33102
33394
|
|
|
33395
|
+
|
|
33103
33396
|
;// ./node_modules/@vue/cli-service/lib/commands/build/entry-lib-no-default.js
|
|
33104
33397
|
|
|
33105
33398
|
|