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