isdata-customer-sdk 0.2.31 → 0.2.33

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.
@@ -29612,6 +29612,7 @@ __webpack_require__.d(__webpack_exports__, {
29612
29612
  getUserID: function() { return /* reexport */ getUserID; },
29613
29613
  hasListener: function() { return /* reexport */ hasListener; },
29614
29614
  i18n: function() { return /* reexport */ i18n; },
29615
+ i18nText: function() { return /* reexport */ i18nText; },
29615
29616
  initDomNodeI18NObserver: function() { return /* reexport */ initDomNodeI18NObserver; },
29616
29617
  initDomNodeViewObserver: function() { return /* reexport */ initDomNodeViewObserver; },
29617
29618
  initEventCenter: function() { return /* reexport */ initEventCenter; },
@@ -30084,7 +30085,8 @@ const getPlatformBortherMenusByMenuID = async (menu_id, role_ids, group_id) => {
30084
30085
  app_id: item.datapp_id,
30085
30086
  menu_id: item.id,
30086
30087
  url: item.url || "",
30087
- children: item.children || []
30088
+ children: item.children || [],
30089
+ sort: item.sort || 0
30088
30090
  };
30089
30091
  menuMaps[id] = tempItem;
30090
30092
  }
@@ -30106,6 +30108,12 @@ const getPlatformBortherMenusByMenuID = async (menu_id, role_ids, group_id) => {
30106
30108
  let item = menuMaps[key];
30107
30109
  if (item.children && item.children.length > 0) {
30108
30110
  menuDatas.push(item);
30111
+ let children = item.children;
30112
+ children.sort((data1, data2) => {
30113
+ if (Number.isNaN(data1.sort)) return 1;
30114
+ if (Number.isNaN(data2.sort)) return -1;
30115
+ return data1.sort - data2.sort;
30116
+ });
30109
30117
  }
30110
30118
  }
30111
30119
  //如果没有数据,说明只有一级节点父亲
@@ -30117,7 +30125,12 @@ const getPlatformBortherMenusByMenuID = async (menu_id, role_ids, group_id) => {
30117
30125
  }
30118
30126
  }
30119
30127
  }
30120
- console.log("getPlatformBortherMenusByMenuID", menuDatas);
30128
+ menuDatas.sort((data1, data2) => {
30129
+ if (Number.isNaN(data1.sort)) return 1;
30130
+ if (Number.isNaN(data2.sort)) return -1;
30131
+ return data1.sort - data2.sort;
30132
+ });
30133
+ // console.log("getPlatformBortherMenusByMenuID",menuDatas);
30121
30134
  //获取菜单数据
30122
30135
  return menuDatas;
30123
30136
  };
@@ -32410,977 +32423,553 @@ const getIntegrateAppInfoByID = async appID => {
32410
32423
  // EXTERNAL MODULE: ./node_modules/crypto-js/index.js
32411
32424
  var crypto_js = __webpack_require__(1396);
32412
32425
  var crypto_js_default = /*#__PURE__*/__webpack_require__.n(crypto_js);
32413
- ;// ./src/api/security.js
32414
-
32415
-
32416
-
32417
-
32418
-
32419
- /**
32420
- *
32421
- * @returns 获取登录验证码图片
32422
- */
32423
- const getAuthPic = () => request.get(`/system/authority/getAuthPic?module=loginPassword`, {
32424
- responseType: "arraybuffer"
32425
- });
32426
-
32427
- /**
32428
- * 登出账号
32429
- * @param endside_type 0: web 1:手机
32430
- * @returns {Promise<*>}
32431
- * @param endside_type 0: web 1:手机
32432
- *
32433
- */
32434
- const logoutAccount = async endside_type => {
32435
- let resultData = await request.get(`/system/authority/logout?isMobileLogout=${endside_type}`);
32436
- let response = JSON.parse(resultData.request.response);
32437
- let resultCode = response.code;
32438
- if (resultCode == "10110020") {
32439
- window.sessionStorage.clear();
32440
- return {
32441
- code: resultCode,
32442
- message: `$L{${response.message}}`
32443
- };
32444
- } else {
32445
- return {
32446
- code: resultCode,
32447
- message: `$L{${response.message}}`
32448
- };
32449
- }
32450
- };
32451
-
32452
- /**
32453
- * 解密
32454
- */
32455
- const decrypt = async decryptStr => {
32456
- let secretKey = await getKey();
32457
- const decrypted = crypto_js_default().AES.decrypt(decryptStr, secretKey).toString((crypto_js_default()).enc.Utf8);
32458
- return decrypted;
32459
- };
32460
-
32461
- /**
32462
- * 解密
32463
- */
32464
- const encrypt = async decryptStr => {
32465
- let secretKey = await getKey();
32466
- const encrypted = crypto_js_default().AES.encrypt(decryptStr, secretKey).toString();
32467
- return encrypted;
32468
- };
32426
+ ;// external {"commonjs":"vue","commonjs2":"vue","root":"Vue"}
32427
+ var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue");
32428
+ ;// ./src/api/i18n/smardaten_i18n/table_i18n.js
32469
32429
 
32470
- /**
32471
- * 切换门户登录
32472
- */
32473
- const switchPortalLogin = async (data, appid, endside_type) => {
32474
- let old_key = window.sessionStorage.getItem("iportal_login_user_key");
32475
- old_key = await decrypt(old_key);
32476
- data.password = old_key;
32477
- let resultData = await logoutAccount(endside_type);
32478
- let resultCode = resultData.code;
32479
- let message = resultData.message;
32480
- //退出登录成功
32481
- if (resultCode == "10110020") {
32482
- let loginResult = await loginAccount(data, appid);
32483
- return loginResult;
32484
- } else {
32485
- return {
32486
- code: resultCode,
32487
- message: `$L{${message}}`
32488
- };
32430
+ const check = element => {
32431
+ const checkResult = {
32432
+ result: false,
32433
+ innerHTMLMatch: null
32434
+ };
32435
+ const classes = element.classList;
32436
+ if (!classes) {
32437
+ return checkResult;
32489
32438
  }
32490
- };
32491
- const getUserID = async (acccountName, old_key, group_id) => {
32492
- let queryData = {
32493
- param: {
32494
- accountName: acccountName,
32495
- group_id: group_id,
32496
- account_key: old_key
32439
+ // 检查表格头部 序号 和 操作 列
32440
+ if (classes.contains("ant-table-cell")) {
32441
+ let innerHTML = element.innerHTML;
32442
+ if (innerHTML.includes("序号") || innerHTML.includes("Serial No.")) {
32443
+ // console.log("检查smardaten平台表格 序号 元素:",innerHTML);
32444
+ let tempHTMLMatch = {
32445
+ oldValue: '$L{序号}'
32446
+ };
32447
+ checkResult.result = true;
32448
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32449
+ return checkResult;
32497
32450
  }
32498
- };
32499
- let result = await request.post(`/dataservice/rest/orchestration/getUserID`, queryData);
32500
- let persion_id = result.data.persion_id;
32501
- return persion_id;
32502
- };
32503
-
32504
- /**
32505
- * 登录账号
32506
- * @param data 登录数据
32507
- * @param appid 应用ID
32508
- *
32509
- * @description
32510
- * 登录时需要传入验证码(authPicCode)和应用ID(dataappId),
32511
- * mobileOrWeb参数用于区分是移动端还是网页端登录。
32512
- *
32513
- * @returns
32514
- */
32515
- const loginAccount = async (data, appid) => {
32516
- let result = await getLoginPortalAccountKey(data.account_view, data.groupid);
32517
- let code = result.data.code;
32518
- //获取key成功
32519
- if (code == 10001) {
32520
- //保存的真正一级密码
32521
- let pwd_code = result.data.codeData.key;
32522
- //缓存一级密码
32523
- let old_key = pwd_code;
32524
- //保存的正则2级密码
32525
- let key_code = result.data.codeData.code;
32526
- //反向解析一级密码
32527
- pwd_code = await decrypt(pwd_code);
32528
- //反向解析2级密码
32529
- key_code = await decrypt(key_code);
32530
- //密码匹配
32531
- if (pwd_code == data.password) {
32532
- //平台正向加密2级密码
32533
- pwd_code = window.appSdk.Encrypt(key_code);
32534
- data.password = pwd_code;
32535
- result = await request.post(`/system/authority/loginAccount4Application?authPicCode=${data.imageCode}&dataappId=${appid}&mobileOrWeb=web`, data);
32536
- let response = JSON.parse(result.request.response);
32537
- code = response.code;
32538
- //登录平台成功
32539
- if (code == 10110004) {
32540
- let id = await getUserID(data.account_view, old_key, data.groupid);
32541
- // 初始化解析器
32542
- const parser = new UAParser();
32543
- // 获取浏览器信息
32544
- const browser = parser.getBrowser();
32545
- let timestamp = new Date().getTime();
32546
- let clientID = browser.name + "_" + browser.version + "_" + timestamp;
32547
- window.sessionStorage.setItem("iportal_login_user_id", id);
32548
- window.sessionStorage.setItem("iportal_group_id", data.groupid);
32549
- window.sessionStorage.setItem("iportal_login_user_key", old_key);
32550
- window.sessionStorage.setItem("iportal_client_id", clientID);
32551
- window.sessionStorage.setItem("iportal_app_id", appid);
32552
- return {
32553
- code: code
32554
- };
32555
- } else {
32556
- return {
32557
- code: code,
32558
- message: `$L{${response.message}}`
32559
- };
32560
- }
32561
- } else {
32562
- return {
32563
- code: code,
32564
- message: "$L{账户密码错误}!"
32451
+ if (innerHTML.includes("操作")) {
32452
+ // console.log("检查smardaten平台表格 操作 元素:",innerHTML);
32453
+ let tempHTMLMatch = {
32454
+ oldValue: '$L{操作}'
32565
32455
  };
32456
+ checkResult.result = true;
32457
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32458
+ return checkResult;
32566
32459
  }
32567
32460
  }
32568
- return {
32569
- code: code,
32570
- message: `$L{${result.data.message}}`
32571
- };
32572
- };
32573
-
32574
- /**
32575
- * 获取密钥
32576
- * @returns
32577
- */
32578
- const getKey = async () => {
32579
- let queryData = {
32580
- param: {}
32581
- };
32582
- let resultData = await request.post(`/dataservice/rest/orchestration/getKey`, queryData);
32583
- let key = resultData.data.key;
32584
- return key;
32585
- };
32586
- ;// ./src/api/utils.js
32587
-
32588
-
32589
-
32590
-
32591
- /**
32592
- * 查询资产
32593
- * @param id 资产ID
32594
- *
32595
- */
32596
- const queryAssetById = (id, count = 200) => request.post(`/asset/getAssetData?asset_id=${id}&count=${count}`, {
32597
- filters: []
32598
- });
32599
-
32600
- /**
32601
- * 获取URL参数值
32602
- * @param {} eventName
32603
- * @param {*} actionFun
32604
- */
32605
- const getUrlParamValue = (urlStr, paramName) => {
32606
- try {
32607
- const url = new URL(urlStr);
32608
- const value = url.searchParams.get(paramName);
32609
- // 如果参数值包含#,则只返回#之前的部分
32610
- if (value && value.indexOf("#") !== -1) {
32611
- return value.split("#")[0];
32461
+ // 检查分页组件 导出按钮
32462
+ if (classes.contains("export_menu")) {
32463
+ let innerHTML = element.innerHTML;
32464
+ if (innerHTML.includes("导出进度") || innerHTML.includes("Export progress")) {
32465
+ // console.log("检查smardaten平台表格 导出按钮 元素:",innerHTML);
32466
+ let tempHTMLMatch = {
32467
+ oldValue: '$L{导出进度}'
32468
+ };
32469
+ checkResult.result = true;
32470
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32471
+ return checkResult;
32612
32472
  }
32613
- return value;
32614
- } catch (err) {
32615
- console.error("URL 格式错误:", err);
32616
- return "";
32617
32473
  }
32618
- };
32619
-
32620
- /**
32621
- * 通过 URL 创建 File 对象
32622
- * @param {string} url - 文件的网络 URL
32623
- * @param {string} [filename] - 自定义文件名(可选,不传则从 URL 提取)
32624
- * @returns {Promise<File>} - 返回 Promise 解析为 File 对象
32625
- */
32626
- const createFileFromUrl = async (url, filename) => {
32627
- try {
32628
- // 1. 发起网络请求获取文件
32629
- const response = await fetch(url);
32630
- if (!response.ok) {
32631
- throw new Error(`网络请求失败: ${response.status} ${response.statusText}`);
32632
- }
32633
-
32634
- // 2. 将响应转换为 Blob(保留原始 MIME 类型)
32635
- const blob = await response.blob();
32636
-
32637
- // 3. 确定文件名(若未自定义则从 URL 提取)
32638
- const finalFilename = filename || extractFilenameFromUrl(url);
32639
-
32640
- // 4. 构造 File 对象(Blob + 文件名 + 类型)
32641
- return new File([blob], finalFilename, {
32642
- type: blob.type,
32643
- // 使用 Blob 的 MIME 类型(如 image/png)
32644
- lastModified: Date.now() // 可选:设置最后修改时间
32645
- });
32646
- } catch (error) {
32647
- console.error("创建 File 失败:", error);
32648
- throw error;
32649
- }
32650
- };
32651
-
32652
- /**
32653
- * 从 URL 中提取文件名(如 https://example.com/path/image.png → image.png)
32654
- * @param {string} url - 文件 URL
32655
- * @returns {string} - 提取的文件名
32656
- */
32657
- const extractFilenameFromUrl = url => {
32658
- try {
32659
- const urlObj = new URL(url);
32660
- // 从路径中获取最后一个部分(文件名)
32661
- return urlObj.pathname.split("/").pop() || "downloaded_file";
32662
- } catch (e) {
32663
- return "downloaded_file"; // URL 解析失败时的默认文件名
32664
- }
32665
- };
32666
-
32667
- /**
32668
- * 提取数组中不在另一个数组中的元素
32669
- * @param {*} oldItems 基础比较数组
32670
- * @param {*} newItems 被提取检测的数组
32671
- * @returns
32672
- */
32673
- const extractNewItems = (oldItems, newItems) => {
32674
- return oldItems.filter(item => !newItems.includes(item));
32675
- };
32676
-
32677
- /**
32678
- * 获取远程文件大小(单位:字节)
32679
- * @param {string} url - 文件的URL地址
32680
- * @returns {Promise<number>} 文件大小(字节),失败时返回-1
32681
- */
32682
- const getFileSize = async url => {
32683
- try {
32684
- // 发送HEAD请求(不下载文件内容)
32685
- const response = await fetch(url, {
32686
- method: "GET",
32687
- headers: {
32688
- Range: "bytes=0-0"
32689
- } // 仅请求第 1 个字节
32690
- });
32691
- if (response.status !== 206) throw new Error("不支持 Range 请求");
32692
- const contentRange = response.headers.get("Content-Range");
32693
- const totalSize = contentRange?.match(/\/(\d+)$/)?.[1]; // 解析总大小(如 "bytes 0-0/1000" → 1000)
32694
- return totalSize ? parseInt(totalSize, 10) : -1;
32695
- } catch (error) {
32696
- console.error("获取文件大小失败:", error);
32697
- return -1; // 返回-1表示失败
32698
- }
32699
- };
32700
- // 获取i18n key
32701
- const getI18nKey = text => {
32702
- // 正则表达式匹配 $L{...} 格式
32703
- const regex = /\$L\{([^}]+)\}/g;
32704
- let match = regex.exec(text);
32705
- if (!match) return text;
32706
- let key = match[1];
32707
- return key;
32708
- };
32709
-
32710
- // 查找最近的具有指定 class 的祖先节点
32711
- const findClosestAncestorByClass = (element, className) => {
32712
- let currentElement = element;
32713
- while (currentElement) {
32714
- // 检查当前元素是否包含目标 class
32715
- if (currentElement.classList && currentElement.classList.contains(className)) {
32716
- return currentElement;
32717
- }
32718
- // 向上遍历父节点
32719
- currentElement = currentElement.parentElement;
32720
- }
32721
- // 未找到匹配的祖先节点
32722
- return null;
32723
- };
32724
- // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.some.js
32725
- var es_iterator_some = __webpack_require__(3579);
32726
- ;// ./src/api/iframe.js
32727
-
32728
-
32729
-
32730
- const addWindowTrustedOrigin = origin => {
32731
- let SDATA_WINDOW_TRUSTED_ORIGINS = window.SDATA_WINDOW_TRUSTED_ORIGINS;
32732
- if (!SDATA_WINDOW_TRUSTED_ORIGINS) window.SDATA_WINDOW_TRUSTED_ORIGINS = [];
32733
- if (!SDATA_WINDOW_TRUSTED_ORIGINS.includes(origin)) {
32734
- SDATA_WINDOW_TRUSTED_ORIGINS.push(origin);
32735
- }
32736
- };
32737
- const removeWindowTrustedOrigin = origin => {
32738
- let SDATA_WINDOW_TRUSTED_ORIGINS = window.SDATA_WINDOW_TRUSTED_ORIGINS;
32739
- if (!SDATA_WINDOW_TRUSTED_ORIGINS) window.SDATA_WINDOW_TRUSTED_ORIGINS = [];
32740
- let index = SDATA_WINDOW_TRUSTED_ORIGINS.indexOf(origin); // 查找元素在数组中的索引
32741
- if (index > -1) {
32742
- SDATA_WINDOW_TRUSTED_ORIGINS.splice(index, 1); // 删除元素
32743
- }
32744
- };
32745
- const addEventAction = (eventKey, eventAction) => {
32746
- let sdataEventActions = window.sdataEventActions;
32747
- if (!sdataEventActions) window.sdataEventActions = {};
32748
- window.sdataEventActions[eventKey] = eventAction;
32749
- };
32750
- const removeEventAction = eventKey => {
32751
- let sdataEventActions = window.sdataEventActions;
32752
- if (!sdataEventActions) window.sdataEventActions = {};
32753
- delete window.sdataEventActions[eventKey];
32754
- };
32755
- const initFrameWindowListener = () => {
32756
- if (window.isFrameWindowInited) return;
32757
- let SDATA_WINDOW_TRUSTED_ORIGINS = window.SDATA_WINDOW_TRUSTED_ORIGINS;
32758
- if (!SDATA_WINDOW_TRUSTED_ORIGINS) window.SDATA_WINDOW_TRUSTED_ORIGINS = [];
32759
- let sdataEventActions = window.sdataEventActions;
32760
- if (!sdataEventActions) window.sdataEventActions = {};
32761
- // 监听主页面的消息
32762
- window.addEventListener("message", async event => {
32763
- // 步骤1:验证来源是否在白名单中
32764
- const isTrusted = window.SDATA_WINDOW_TRUSTED_ORIGINS.some(origin => event.origin === origin || new RegExp(origin).test(event.origin));
32765
- if (!isTrusted) {
32766
- console.log("拒绝非可信源消息:", event.origin);
32767
- return; // 直接终止处理
32768
- }
32769
- let eventKey = event.data?.eventKey;
32770
- if (!eventKey) return;
32771
- let eventSourceKey = event.origin;
32772
- console.log(`收到${eventSourceKey}页面消息:`, event.data);
32773
- if (eventKey === "sdata_alllife_event_response") {
32774
- let eventOperateKey = event.data.eventOperateKey;
32775
- let eventAction = window.sdataEventActions[eventOperateKey];
32776
- //删除缓存方法
32777
- delete window.sdataEventActions[eventOperateKey];
32778
- if (eventAction) await eventAction(event.data.data, event);
32779
- } else {
32780
- let eventAction = window.sdataEventActions[eventKey];
32781
- let responseData = {
32782
- eventKey: "sdata_alllife_event_response",
32783
- eventOperateKey: event.data.eventOperateKey,
32784
- data: {}
32785
- };
32786
- if (eventAction) {
32787
- let resultData = await eventAction(event.data.data, event);
32788
- responseData.data = resultData;
32789
- }
32790
- event.source.postMessage(responseData, eventSourceKey);
32791
- }
32792
- });
32793
- window.isFrameWindowInited = true;
32794
- };
32795
- const sendWindowMessage = async (targetWindow, originKey, eventKey, data, callback) => {
32796
- let timestamp = new Date().getTime();
32797
- let randomNum = Math.floor(Math.random() * 10000) + 1;
32798
- let eventOperateKey = `${eventKey}_${timestamp}_${randomNum}`;
32799
- addEventAction(eventOperateKey, callback);
32800
- let postData = {
32801
- eventOperateKey: eventOperateKey,
32802
- eventKey: eventKey,
32803
- data: data
32804
- };
32805
- targetWindow.postMessage(postData, originKey);
32806
- };
32807
- ;// ./src/api/chat/ChatClientMgr.js
32808
-
32809
-
32810
-
32811
- class ChatClientMgr {
32812
- constructor(params, handler) {
32813
- this.handler = handler;
32814
- this.actionKey = params.actionKey;
32815
- this.appSKID = params.appSKID;
32816
- this.imType = params.imType;
32817
- this.groupID = params.groupID;
32818
- this.userID = params.userID;
32819
- this.chatType = params.chatType || 0;
32820
- this.singleChatID = params.singleChatID || "";
32821
- this.customParams = params.customParams || {};
32822
- this.chartOrigin = params.chartOrigin;
32823
- // console.log("ChatClientMgr init:", this.actionKey);
32824
- }
32825
- makeKey(key) {
32826
- return `${key}-${this.actionKey}`;
32827
- }
32828
- async init() {
32829
- this.handler.addChatListener(this.makeKey(`sdata_get_access_token`), async data => {
32830
- return await this.handler.getPortalAccessToken(data);
32831
- });
32832
- this.handler.addChatListener(this.makeKey(`sdata_get_portal_user_info`), async data => {
32833
- return await this.handler.getPortalUserInfo(data);
32834
- });
32835
- this.handler.addChatListener(this.makeKey(`sdata_get_portal_user_sig`), async data => {
32836
- let userID = data.userID;
32837
- let platType = data.im_type;
32838
- let groupID = data.group_id;
32839
- return await this.handler.getPortalUserSig(userID, platType, groupID);
32840
- });
32841
- this.handler.addChatListener(this.makeKey(`sdata_add_im_mapping`), async data => {
32842
- let userID = data.userID;
32843
- let platType = data.im_type;
32844
- let userSig = data.userSig;
32845
- return await this.handler.addIMMapping(userID, platType, userSig, this.groupID);
32846
- });
32847
- this.handler.addChatListener(this.makeKey(`sdata_update_im_mapping`), async data => {
32848
- return await this.handler.updateIMMapping(data);
32849
- });
32850
- this.handler.addChatListener(this.makeKey(`sdata_get_users_by_group_id`), async data => {
32851
- return await this.handler.getAllUserInfosByGroupID(data);
32852
- });
32853
- this.handler.addChatListener(this.makeKey(`sdata_get_dpts_by_group_id`), async data => {
32854
- return await this.handler.getChildrenOfficeInfosByID(data);
32855
- });
32856
- this.handler.addChatListener(this.makeKey(`sdata_get_project_dpts_by_user_group_id`), async data => {
32857
- return await this.handler.getPojectDptsByUserAndGroupID(data);
32858
- });
32859
- this.handler.addChatListener(this.makeKey(`sdata_get_ai_robot_infos`), async data => {
32860
- let groupID = data.groupID;
32861
- let userID = data.userID;
32862
- if (this.userID == userID && this.groupID == groupID) {
32863
- return this.getAIRobotInfos();
32864
- }
32865
- return [];
32866
- });
32867
- this.handler.addChatListener(this.makeKey(`sdata_get_test_user_sig`), async data => {
32868
- let sdkAppID = data.SDKAppID;
32869
- let userID = data.userID;
32870
- let sigIDObject = await this.handler.genTestUserSig({
32871
- SDKAppID: sdkAppID,
32872
- userID: userID
32873
- });
32874
- let sigID = sigIDObject.userSig;
32875
- return sigID;
32876
- });
32877
- this.handler.addChatListener(this.makeKey(`sdata_send_message_to_chat_server`), async (data, event) => {
32878
- let message = data.message;
32879
- let robotID = message.from;
32880
- let result = await this.sendMessageToChatServer(robotID, message);
32881
- return result;
32882
- });
32883
- this.handler.addChatListener(this.makeKey(`sdata_close_frame_window`), async (data, event) => {
32884
- return this.handler.closeWindow();
32885
- });
32886
- this.handler.addChatListener(this.makeKey(`sdata_get_portal_doc_info`), async (data, event) => {
32887
- return this.handler.getPortalDocmentInfo(data);
32888
- });
32889
- this.handler.addChatListener(this.makeKey(`sdata_chat_aiAgent_event`), async (data, event) => {
32890
- return this.handler.onAIAgentEvent(data, event);
32891
- });
32892
- this.handler.addChatListener(this.makeKey(`sdata_alllife_event_regist`), async (data, event) => {
32893
- console.log("recive chat regist event data:", data);
32894
- this.appSKID = data.appid;
32895
- this.imType = data.im_type;
32896
- await this.initChatAIs();
32897
- let charParams = {
32898
- type: this.getChatTypeKey(this.chatType),
32899
- singleChatID: this.singleChatID,
32900
- customParams: this.customParams
32901
- };
32902
- this.handler.fireEventToChatWindow(event, this.chartOrigin, this.makeKey("sdata_alllife_initChat"), charParams, result => {
32903
- if (result) {
32904
- console.log("chat init finished:", result);
32905
- this.handler.onChatInitFinished();
32906
- }
32907
- });
32908
- });
32909
- }
32910
- getChatTypeKey(type) {
32911
- switch (type) {
32912
- case 0:
32913
- return "IM_MULTIPLE_MODE";
32914
- case 1:
32915
- return "IM_SINGLE_MODE";
32916
- case 2:
32917
- return "IM_EMBED_MODE";
32918
- case 3:
32919
- return "IM_MOBILE_MULTIPLE_EMBED_MODE";
32920
- case 4:
32921
- return "IM_MOBILE_SINGLE_EMBED_MODE";
32922
- default:
32923
- return "IM_MULTIPLE_MODE";
32924
- }
32925
- }
32926
- async initChatAIs() {
32927
- if (window.imClient) {
32928
- this.chatAIClient = window.imClient;
32929
- } else {
32930
- let classDatas = await this.handler.getChatClientClasses();
32931
- const {
32932
- TencentCloudChat,
32933
- TIMUploadPlugin
32934
- } = classDatas;
32935
- window.imClient = TencentCloudChat.create({
32936
- SDKAppID: this.appSKID,
32937
- // 替换为你的 SDKAppID
32938
- storage: {
32939
- enable: true // 启用存储(可选,根据需求)
32474
+ // 检查分页组件
32475
+ if (classes.contains("total_pag_num")) {
32476
+ let innerHTML = element.innerHTML;
32477
+ if (innerHTML.includes("共") && innerHTML.includes("条") || innerHTML.includes("Total") && innerHTML.includes("pieces")) {
32478
+ // console.log("检查smardaten平台分页 共xx条 元素:",innerHTML);
32479
+ let scriptFunction = (appID, lang) => {
32480
+ let scriptNode = null;
32481
+ for (let node of element.childNodes) {
32482
+ // 检查是否为文本节点且包含"Total"
32483
+ if (node.tagName === "SPAN") {
32484
+ scriptNode = node;
32485
+ }
32940
32486
  }
32941
- });
32942
- window.imClient.registerPlugin({
32943
- "tim-upload-plugin": TIMUploadPlugin
32944
- });
32945
- window.imClient.on(TencentCloudChat.EVENT.SDK_READY, this.onChatAIReady.bind(this));
32946
- window.imClient.charAIs = {};
32947
- this.chatAIClient = window.imClient;
32948
- }
32949
- if (!this.chatAIClient.charAIs) {
32950
- this.chatAIClient.charAIs = {};
32951
- }
32952
- let robotInfos = await this.handler.getAIRobotInfos(this.userID, this.groupID);
32953
- if (robotInfos && robotInfos.length > 0) {
32954
- robotInfos.forEach(async robot => {
32955
- let robotKey = robot.id;
32956
- if (!this.chatAIClient.charAIs[robotKey]) {
32957
- robot.chatID = robotKey;
32958
- let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
32959
- if (!userSig) {
32960
- userSig = await this.generateUserSigAndAdd(robotKey);
32487
+ let scriptNodes = [{
32488
+ nodeType: Node.TEXT_NODE,
32489
+ key: '共'
32490
+ }, {
32491
+ nodeType: "SCRIPTNODE",
32492
+ node: scriptNode
32493
+ }, {
32494
+ nodeType: Node.TEXT_NODE,
32495
+ key: '条'
32496
+ }];
32497
+ for (let i = 0; i < element.childNodes.length; i++) {
32498
+ let childNode = element.childNodes[i];
32499
+ if (childNode.nodeType === Node.TEXT_NODE) {
32500
+ element.removeChild(childNode);
32501
+ }
32502
+ }
32503
+ for (let i = 0; i < scriptNodes.length; i++) {
32504
+ let scriptNodeItem = scriptNodes[i];
32505
+ if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
32506
+ let textNode = document.createTextNode(i18n(scriptNodeItem.key, appID, lang) || scriptNodeItem.key);
32507
+ element.appendChild(textNode);
32508
+ }
32509
+ if (scriptNodeItem.nodeType === "SCRIPTNODE") {
32510
+ element.appendChild(scriptNodeItem.node);
32961
32511
  }
32962
- robot.userSig = userSig;
32963
- this.chatAIClient.charAIs[robotKey] = {
32964
- robot: robot,
32965
- messageCache: []
32966
- };
32967
32512
  }
32968
- });
32969
- }
32970
- }
32971
- async generateUserSigAndUpdate(robotKey) {
32972
- let sigIDObject = await this.handler.genTestUserSig({
32973
- SDKAppID: this.appSKID,
32974
- userID: robotKey
32975
- });
32976
- let userSig = sigIDObject.userSig;
32977
- if (userSig) {
32978
- await this.chatAIClient.login({
32979
- userID: robotKey,
32980
- userSig: userSig
32981
- });
32982
- await this.chatAIClient.logout();
32983
- let data = {
32984
- userID: robotKey,
32985
- userSig: userSig,
32986
- im_type: this.imType,
32987
- group_id: this.groupID
32988
32513
  };
32989
- await this.handler.updateIMMapping(data);
32514
+ let tempHTMLMatch = {
32515
+ isScriptAction: true,
32516
+ scriptFunction: scriptFunction
32517
+ };
32518
+ checkResult.result = true;
32519
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32520
+ return checkResult;
32990
32521
  }
32991
- return userSig;
32992
32522
  }
32993
- async generateUserSigAndAdd(robotKey) {
32994
- let sigIDObject = await this.handler.genTestUserSig({
32995
- SDKAppID: this.appSKID,
32996
- userID: robotKey
32997
- });
32998
- let userSig = sigIDObject.userSig;
32999
- if (userSig) {
33000
- await this.chatAIClient.login({
33001
- userID: robotKey,
33002
- userSig: userSig
33003
- });
33004
- await this.chatAIClient.logout();
33005
- await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
32523
+ // 检查分页组件 跳至xx页
32524
+ if (classes.contains("ant-pagination-options-quick-jumper")) {
32525
+ let innerHTML = element.innerHTML;
32526
+ if (innerHTML.includes("跳至") && innerHTML.includes("页") || innerHTML.includes("Go to") && innerHTML.includes("Page")) {
32527
+ // console.log("检查smardaten平台分页 跳至xx页 元素:",innerHTML);
32528
+ let scriptFunction = (appID, lang) => {
32529
+ let scriptNode = null;
32530
+ for (let node of element.childNodes) {
32531
+ // 检查是否为文本节点且包含"Total"
32532
+ if (node.tagName === "INPUT") {
32533
+ scriptNode = node;
32534
+ }
32535
+ }
32536
+ let scriptNodes = [{
32537
+ nodeType: Node.TEXT_NODE,
32538
+ key: '跳至'
32539
+ }, {
32540
+ nodeType: "SCRIPTNODE",
32541
+ node: scriptNode
32542
+ }, {
32543
+ nodeType: Node.TEXT_NODE,
32544
+ key: '页'
32545
+ }];
32546
+ for (let i = 0; i < element.childNodes.length; i++) {
32547
+ let childNode = element.childNodes[i];
32548
+ if (childNode.nodeType === Node.TEXT_NODE) {
32549
+ element.removeChild(childNode);
32550
+ }
32551
+ }
32552
+ for (let i = 0; i < scriptNodes.length; i++) {
32553
+ let scriptNodeItem = scriptNodes[i];
32554
+ if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
32555
+ let textNode = document.createTextNode(i18n(scriptNodeItem.key, appID, lang) || scriptNodeItem.key);
32556
+ element.appendChild(textNode);
32557
+ }
32558
+ if (scriptNodeItem.nodeType === "SCRIPTNODE") {
32559
+ element.appendChild(scriptNodeItem.node);
32560
+ }
32561
+ }
32562
+ };
32563
+ let tempHTMLMatch = {
32564
+ isScriptAction: true,
32565
+ scriptFunction: scriptFunction
32566
+ };
32567
+ checkResult.result = true;
32568
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32569
+ return checkResult;
33006
32570
  }
33007
- return userSig;
33008
32571
  }
33009
- onChatAIReady(event) {
33010
- let robotID = this.chatAIClient.lastRobotID;
33011
- let robotInfo = this.getAIRobotInfoByID(robotID);
33012
- console.log(`[AI chat] ${robotInfo.name}已经就绪:`, event);
33013
- if (this.chatAIClient) {
33014
- let messages = this.getAIRobotCacheMessagesByID(robotID);
33015
- console.log(`[AI chat] ${robotInfo.name}就绪后查到的缓存信息:`, messages);
33016
- console.log(`[AI chat] ${robotInfo.name}所有信息仓:`, this.chatAIClient.charAIs);
33017
- if (messages && messages.length > 0) {
33018
- const newMessages = [...messages];
33019
- messages.splice(0, messages.length);
33020
- newMessages.forEach(message => {
33021
- console.log(`[AI chat] ${robotInfo.name}发送缓存消息:`, message);
33022
- this.sendMessageToChatServer(robotID, message);
33023
- });
32572
+ // 检查每页xx条
32573
+ if (classes.contains("ant-select-selection-item") || classes.contains("ant-select-item-option-content")) {
32574
+ let innerHTML = element.innerHTML;
32575
+ // console.log("检查smardaten平台分页 每页xx条 元素:",innerHTML);
32576
+ if (innerHTML.includes("/") && innerHTML.includes("page") || innerHTML.includes("/") && innerHTML.includes("条") && innerHTML.includes("页")) {
32577
+ let oldValue = element.innerHTML;
32578
+ if (innerHTML.includes("page")) {
32579
+ oldValue = oldValue.replace('page', '$L{}');
33024
32580
  }
33025
- }
33026
- }
33027
- getAIRobotInfos() {
33028
- let resultRobots = [];
33029
- for (let key in this.chatAIClient.charAIs) {
33030
- resultRobots.push(this.chatAIClient.charAIs[key].robot);
33031
- }
33032
- return resultRobots;
33033
- }
33034
- getAIRobotInfoByID(robotID) {
33035
- return this.chatAIClient.charAIs[robotID] ? this.chatAIClient.charAIs[robotID].robot : null;
33036
- }
33037
- getAIRobotCacheMessagesByID(robotID) {
33038
- return this.chatAIClient.charAIs[robotID] ? this.chatAIClient.charAIs[robotID].messageCache : [];
33039
- }
33040
- async sendMessageToChatServer(robotID, messageOption) {
33041
- let robotInfo = this.getAIRobotInfoByID(robotID);
33042
- if (this.chatAIClient.lastRobotID != robotID) {
33043
- console.log(`[AI chat]需要新机器人回答,切换到新机器人${robotInfo.name}`);
33044
- if (this.chatAIClient.lastRobotID) {
33045
- await this.chatAIClient.logout();
32581
+ if (innerHTML.includes("页")) {
32582
+ oldValue = oldValue.replace('页', '$L{页}');
33046
32583
  }
33047
- try {
33048
- await this.chatAIClient.login({
33049
- userID: robotID,
33050
- userSig: robotInfo.userSig
33051
- });
33052
- } catch (err) {
33053
- console.log(`[AI chat]${robotInfo.name}登录失败`, err);
33054
- let code = err.code;
33055
- if (code == 70001) {
33056
- console.log(`[AI chat]${robotInfo.name}UserSig过期,重新生成userSig`);
33057
- let newUserSig = await this.generateUserSigAndUpdate(robotID);
33058
- try {
33059
- await this.chatAIClient.login({
33060
- userID: robotID,
33061
- userSig: newUserSig
33062
- });
33063
- this.sendMessageToChatServer(robotID, messageOption);
33064
- return;
33065
- } catch (err) {
33066
- console.log(`[AI chat]${robotInfo.name}重新登录失败`, err);
33067
- return;
33068
- }
33069
- }
32584
+ if (innerHTML.includes("条")) {
32585
+ oldValue = oldValue.replace('条', '$L{条}');
33070
32586
  }
33071
- }
33072
- this.chatAIClient.lastRobotID = robotID;
33073
- if (this.chatAIClient && this.chatAIClient.isReady()) {
33074
- let new_message = await this.chatAIClient.createTextMessage(messageOption);
33075
- this.chatAIClient.sendMessage(new_message).then(res => {
33076
- console.log(`[AI chat]${robotInfo.name}发送信息成功`, res);
33077
- }, err => {
33078
- console.log(`[AI chat]${robotInfo.name}发送失败`, err);
33079
- });
33080
- } else {
33081
- let messageCache = this.getAIRobotCacheMessagesByID(robotID);
33082
- messageCache.push(messageOption);
33083
- console.log(`[AI chat]${robotInfo.name}未就绪,缓存后消息:`, messageCache);
32587
+ let tempHTMLMatch = {
32588
+ oldValue: oldValue
32589
+ };
32590
+ checkResult.result = true;
32591
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32592
+ return checkResult;
33084
32593
  }
33085
32594
  }
33086
- converToAIServerParams(message, robotInfo, param) {
33087
- let prompt = "";
33088
- let type = message.type;
33089
- switch (type) {
33090
- case "TIMTextElem":
33091
- prompt = message.payload?.text || "";
33092
- break;
33093
- case "TIMImageElem":
33094
- break;
33095
- case "TIMSoundElem":
33096
- break;
33097
- case "TIMVideoFileElem":
33098
- break;
33099
- case "TIMFileElem":
33100
- break;
33101
- default:
33102
- break;
32595
+ // 检查删除确认对话框标题
32596
+ if (classes.contains("ant-popover-message-title")) {
32597
+ let innerHTML = element.innerHTML;
32598
+ if (innerHTML.includes("确认执行:") || innerHTML.includes("Confirm Execution:")) {
32599
+ // console.log("检查smardaten平台删除提问对话框:",innerHTML);
32600
+ let tempHTMLMatch = {
32601
+ oldValue: '$L{操作确认:删除?}'
32602
+ };
32603
+ checkResult.result = true;
32604
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32605
+ return checkResult;
33103
32606
  }
33104
- let cloudCustomData = message.cloudCustomData || {};
33105
- let conversation_id = cloudCustomData.conversation_id || "";
33106
- let params = {
33107
- prompt: prompt,
33108
- params: param || {},
33109
- robotKey: robotInfo.password,
33110
- conversation_id: conversation_id || "",
33111
- userID: message.from || ""
33112
- };
33113
- return params;
33114
32607
  }
33115
- abort() {
33116
- this.chatAIClient = null;
32608
+ // 检查删除确认对话框按钮 取消 确认
32609
+ if (classes.contains("ant-btn")) {
32610
+ let innerHTML = element.innerHTML;
32611
+ if (innerHTML.includes("Cancel") || innerHTML.includes("取消")) {
32612
+ // console.log("检查smardaten平台 Tip提问取消删除按钮:",innerHTML);
32613
+ let tempHTMLMatch = {
32614
+ oldValue: '$L{取消}'
32615
+ };
32616
+ checkResult.result = true;
32617
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32618
+ return checkResult;
32619
+ }
32620
+ if (innerHTML.includes("确定") || innerHTML.includes("OK")) {
32621
+ // console.log("检查smardaten平台 Tip提问确认删除按钮:",innerHTML);
32622
+ let tempHTMLMatch = {
32623
+ oldValue: '$L{确定}'
32624
+ };
32625
+ checkResult.result = true;
32626
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32627
+ return checkResult;
32628
+ }
33117
32629
  }
33118
- }
33119
- ;// ./src/api/chat.js
33120
-
33121
-
33122
-
32630
+ return checkResult;
32631
+ };
32632
+ ;// ./src/api/i18n/smardaten_i18n/catalog_i18n.js
33123
32633
 
33124
- const getRobotInfoByID = async (robotID, groupID) => {
33125
- let queryData = {
33126
- "param": {
33127
- "id": robotID,
33128
- "groupID": groupID
33129
- }
32634
+ const catalog_i18n_check = element => {
32635
+ const checkResult = {
32636
+ result: false,
32637
+ innerHTMLMatch: null
33130
32638
  };
33131
- let result = await request.post(`/dataservice/rest/orchestration/getRobotInfoByID`, queryData);
33132
- let robotInfo = result.data.robotInfo;
33133
- return robotInfo;
33134
- };
33135
- const getIMHanlder = customerHanlder => {
33136
- let handler = {
33137
- genTestUserSig: async data => {
33138
- // return genTestUserSig(data);
33139
- },
33140
- getChatClientClasses: async () => {
33141
- return [];
33142
- },
33143
- getAIRobotInfos: async (user_id, groupID) => {
33144
- return getAIRobotInfos(user_id, groupID);
33145
- },
33146
- getPortalUserSig: async (robotKey, platType, groupID) => {
33147
- return getPortalUserSig(robotKey, platType, groupID);
33148
- },
33149
- addIMMapping: async (robotKey, platType, userSig, groupID) => {
33150
- return addIMMapping(robotKey, platType, groupID, userSig);
33151
- },
33152
- updateIMMapping: async data => {
33153
- let robotKey = data.userID;
33154
- let platType = data.im_type;
33155
- let groupID = data.group_id;
33156
- let userSig = data.userSig;
33157
- return updateIMMapping(robotKey, platType, groupID, userSig);
33158
- },
33159
- getPortalAccessToken: async data => {
33160
- let appKey = data.appKey;
33161
- let appSecret = data.appSecret;
33162
- return getPortalAccessToken(appKey, appSecret);
33163
- },
33164
- getPortalUserInfo: async data => {
33165
- let code = data.code;
33166
- let access_token = data.access_token;
33167
- return getPortalUserInfo(code, access_token);
33168
- },
33169
- getAllUserInfosByGroupID: async data => {
33170
- let groupID = data.groupID;
33171
- return getAllUserInfosByGroupID(groupID);
33172
- },
33173
- getChildrenOfficeInfosByID: async data => {
33174
- let groupID = data.groupID;
33175
- return getChildrenOfficeInfosByID(groupID);
33176
- },
33177
- getPojectDptsByUserAndGroupID: async data => {
33178
- let groupID = data.groupID;
33179
- let userID = data.userID;
33180
- return getPojectDptsByUserAndGroupID(userID, groupID);
33181
- },
33182
- closeWindow: () => {
33183
- // this.visable = false;
33184
- return true;
33185
- },
33186
- addChatListener: async (listenerKey, handler) => {
33187
- await addEventAction(listenerKey, handler);
33188
- },
33189
- fireEventToChatWindow: async (event, chart_origin, key, params, handler) => {
33190
- await sendWindowMessage(event.source, chart_origin, key, params, handler);
33191
- },
33192
- onChatInitFinished: async () => {
33193
- // this.chatInitFinish = true;
33194
- },
33195
- onAIAgentEvent: async (data, event) => {
33196
- // this.onAIAgentEvent(data,event);
33197
- },
33198
- getPortalDocmentInfo: async data => {
33199
- let kb_doc_id = data.kb_doc_id;
33200
- let doc_info = await getPortalDocmentInfo(kb_doc_id);
33201
- let urlStr = doc_info?.summary;
33202
- if (urlStr) {
33203
- let urlObj = JSON.parse(urlStr);
33204
- if (urlObj) {
33205
- let url = urlObj[0].url;
33206
- let home_page = window.smardaten_api_context_path;
33207
- let finalUrl = `${home_page}/storage_area/public${url}`;
33208
- let fileSize = await getFileSize(finalUrl);
33209
- doc_info.fileSize = fileSize;
32639
+ const classes = element.classList;
32640
+ if (!classes) {
32641
+ return checkResult;
32642
+ }
32643
+ let innerHTML = element.innerHTML;
32644
+ let oldValue = element.getAttribute("oldValue");
32645
+ if (!oldValue) {
32646
+ oldValue = innerHTML;
32647
+ }
32648
+ // 检查目录列表 名称
32649
+ if (classes.contains("catalog_name_content")) {
32650
+ // console.log("检查smardaten平台目录列表 元素:",innerHTML);
32651
+ let scriptFunction = (appID, lang) => {
32652
+ for (let i = 0; i < element.childNodes.length; i++) {
32653
+ let scriptNodeItem = element.childNodes[i];
32654
+ if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
32655
+ let text = element.getAttribute("oldValue");
32656
+ let isTextMatch = checkTextFormat(text);
32657
+ if (!isTextMatch) {
32658
+ element.appendChild(scriptNodeItem);
32659
+ } else {
32660
+ element.removeChild(scriptNodeItem);
32661
+ let key = isTextMatch.key;
32662
+ let textNode = document.createTextNode(i18n(key, appID, lang) || key);
32663
+ element.appendChild(textNode);
32664
+ }
32665
+ } else {
32666
+ element.appendChild(scriptNodeItem);
33210
32667
  }
33211
32668
  }
33212
- return doc_info;
33213
- }
33214
- };
33215
- handler = {
33216
- ...handler,
33217
- ...customerHanlder
33218
- };
33219
- return handler;
32669
+ };
32670
+ let tempHTMLMatch = {
32671
+ oldValue: oldValue,
32672
+ isScriptAction: true,
32673
+ scriptFunction: scriptFunction
32674
+ };
32675
+ checkResult.result = true;
32676
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32677
+ return checkResult;
32678
+ }
32679
+ if (classes.contains("catalog-tree-search")) {
32680
+ let scriptFunction = (appID, lang) => {
32681
+ for (let i = 0; i < element.childNodes.length; i++) {
32682
+ let scriptNodeItem = element.childNodes[i];
32683
+ if (scriptNodeItem.tagName === 'INPUT') {
32684
+ let oldValue = scriptNodeItem.getAttribute("oldplaceholderValue");
32685
+ if (!oldValue) {
32686
+ let text = scriptNodeItem.getAttribute("placeholder");
32687
+ if (text) {
32688
+ text = `$L{${text}}`;
32689
+ }
32690
+ scriptNodeItem.setAttribute("placeholder", text);
32691
+ processElement(scriptNodeItem, appID, lang);
32692
+ }
32693
+ }
32694
+ }
32695
+ };
32696
+ let tempHTMLMatch = {
32697
+ oldValue: oldValue,
32698
+ isScriptAction: true,
32699
+ scriptFunction: scriptFunction
32700
+ };
32701
+ checkResult.result = true;
32702
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32703
+ return checkResult;
32704
+ }
32705
+ return checkResult;
33220
32706
  };
33221
-
33222
- ;// ./src/api/dify.js
32707
+ ;// ./src/api/i18n/commom_i18n/common_i18n.js
33223
32708
 
33224
32709
 
33225
- const sendPostToAIAgent = async (queryData, successCallback, errorCallback) => {
33226
- let appid = getPoratlAppID();
33227
- let appCustomData = await getAppCustomData(appid);
33228
- let aiAgentServerIP = appCustomData?.aiAgentServerIP || "";
33229
- if (!aiAgentServerIP) {
33230
- console.error("没有配置AI Agent服务地址,请联系管理员");
33231
- if (errorCallback) errorCallback("没有配置AI Agent服务地址,请联系管理员");
33232
- return;
33233
- }
33234
- let serverUrl = `${aiAgentServerIP}/addAndCleanDocument`;
33235
- request.post(serverUrl, JSON.stringify(queryData)).then(res => {
33236
- console.log("发送消息成功:", res);
33237
- if (successCallback) successCallback(res);
33238
- }).catch(error => {
33239
- console.error("发送消息失败:", error);
33240
- if (errorCallback) errorCallback(error);
33241
- });
33242
- };
33243
- const getDifyFileType = fileType => {
33244
- let typeOptions = {
33245
- "DOCX": "document",
33246
- "TXT": "document",
33247
- "MD": "document",
33248
- "MARKDOWN": "document",
33249
- "MDX": "document",
33250
- "PDF": "document",
33251
- "HTML": "document",
33252
- "XLSX": "document",
33253
- "XLS": "document",
33254
- "VTT": "document",
33255
- "DOC": "document",
33256
- "CSV": "document",
33257
- "EML": "document",
33258
- "MSG": "document",
33259
- "PPTX": "document",
33260
- "PPT": "document",
33261
- "XML": "document",
33262
- "EPUB": "document",
33263
- "JPG": "image",
33264
- "JPEG": "image",
33265
- "PNG": "image",
33266
- "GIF": "image",
33267
- "WEBP": "image",
33268
- "MP3": "audio",
33269
- "M4A": "audio",
33270
- "WAV": "audio",
33271
- "WEBM": "audio",
33272
- "MPGA": "audio",
33273
- "MP4": "video",
33274
- "MOV": "video",
33275
- "MPEG": "video"
32710
+ function getOldValueNodeText(innerHTML, index) {
32711
+ const container = document.createElement('div');
32712
+ container.innerHTML = innerHTML;
32713
+ const childNode = container.childNodes[index];
32714
+ return childNode.textContent;
32715
+ }
32716
+ const common_i18n_check = element => {
32717
+ const checkResult = {
32718
+ result: false,
32719
+ innerHTMLMatch: null
33276
32720
  };
33277
- let key = fileType.toUpperCase();
33278
- return typeOptions[key] || "custom";
33279
- };
33280
-
33281
- /**
33282
- * URL 中提取文件名(如 https://example.com/path/image.png → image.png)
33283
- * @param {string} url - 文件 URL
33284
- * @returns {string} - 提取的文件名
33285
- */
33286
- const dify_extractFilenameFromUrl = url => {
33287
- try {
33288
- const urlObj = new URL(url);
33289
- // 从路径中获取最后一个部分(文件名)
33290
- return urlObj.pathname.split("/").pop() || "downloaded_file";
33291
- } catch (e) {
33292
- return "downloaded_file"; // URL 解析失败时的默认文件名
32721
+ // 检查目录列表 名称
32722
+ if (element.tagName === 'BUTTON' || element.tagName === 'P') {
32723
+ //TODO:先检查新的是否需要解析,新的不需要有可能是解析后的再次判断,如果有历史解析值,则解析
32724
+ //如果新的需要解析,更新缓存的历史解析值
32725
+ let innerHTML = element.innerHTML;
32726
+ let oldValue = element.getAttribute("oldValue");
32727
+ if (!oldValue) {
32728
+ oldValue = innerHTML;
32729
+ }
32730
+ let firstCheck = checkTextFormat(oldValue);
32731
+ let firstCheckResult = firstCheck ? true : false;
32732
+ // console.log("检查 button 元素:",innerHTML);
32733
+ // console.log("检查结果:",firstCheckResult);
32734
+ let scriptFunction = (appID, lang) => {
32735
+ let elementsArray = [];
32736
+ for (let i = 0; i < element.childNodes.length; i++) {
32737
+ let scriptNodeItem = element.childNodes[i];
32738
+ if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
32739
+ let oldValue = element.getAttribute("oldValue");
32740
+ // console.log("执行 button 文本节点翻译:", text);
32741
+ // 创建正则表达式匹配所有 $L{...} 格式
32742
+ const regex = /\$L\{([^}]+)\}/g;
32743
+ let isTextMatch = checkTextFormat(oldValue);
32744
+ if (!isTextMatch) {
32745
+ elementsArray.push(scriptNodeItem);
32746
+ } else {
32747
+ // console.log("执行 button 脚本节点翻译isTextMatch:", isTextMatch?true:false);
32748
+ // element.removeChild(scriptNodeItem);
32749
+ // 替换所有 $L{...} 占位符为翻译文本
32750
+ let childNodeText = getOldValueNodeText(oldValue, i);
32751
+ let newValue = childNodeText;
32752
+ let match;
32753
+ while ((match = regex.exec(oldValue)) !== null) {
32754
+ const fullMatch = match[0];
32755
+ const placeholderKey = match[1];
32756
+ const translation = i18n(placeholderKey, appID, lang);
32757
+ newValue = newValue.replace(fullMatch, translation);
32758
+ }
32759
+ let textNode = document.createTextNode(newValue);
32760
+ elementsArray.push(textNode);
32761
+ }
32762
+ } else {
32763
+ elementsArray.push(scriptNodeItem);
32764
+ }
32765
+ }
32766
+ element.innerHTML = '';
32767
+ elementsArray.forEach(el => {
32768
+ element.appendChild(el);
32769
+ });
32770
+ };
32771
+ let tempHTMLMatch = {
32772
+ oldValue: oldValue,
32773
+ isScriptAction: true,
32774
+ scriptFunction: scriptFunction
32775
+ };
32776
+ checkResult.result = firstCheckResult;
32777
+ checkResult.innerHTMLMatch = tempHTMLMatch;
32778
+ return checkResult;
33293
32779
  }
32780
+ return checkResult;
33294
32781
  };
33295
- ;// external {"commonjs":"vue","commonjs2":"vue","root":"Vue"}
33296
- var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue");
33297
- ;// ./src/api/i18n/smardaten_i18n/table_i18n.js
32782
+ ;// ./src/api/i18n/commom_i18n/attribute_i18n.js
33298
32783
 
33299
- const check = element => {
32784
+ const attribute_i18n_check = element => {
33300
32785
  const checkResult = {
33301
32786
  result: false,
33302
32787
  innerHTMLMatch: null
33303
32788
  };
33304
- const classes = element.classList;
33305
- if (!classes) {
32789
+ if (!element) {
33306
32790
  return checkResult;
33307
32791
  }
33308
- // 检查表格头部 序号 操作 列
33309
- if (classes.contains("ant-table-cell")) {
33310
- let innerHTML = element.innerHTML;
33311
- if (innerHTML.includes("序号") || innerHTML.includes("Serial No.")) {
33312
- // console.log("检查smardaten平台表格 序号 元素:",innerHTML);
33313
- let tempHTMLMatch = {
33314
- oldValue: '$L{序号}'
33315
- };
32792
+ const checkAttributes = ["placeholder", "title"];
32793
+ for (let i = 0; i < checkAttributes.length; i++) {
32794
+ let attr = checkAttributes[i];
32795
+ let attrValue = element.getAttribute(attr) || element[attr];
32796
+ const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
32797
+ if (attrMatch) {
32798
+ // console.log("检查元素属性 i18n 元素:", attr, attrValue);
32799
+ element.setAttribute(`old${attr}Value`, attrValue);
33316
32800
  checkResult.result = true;
33317
- checkResult.innerHTMLMatch = tempHTMLMatch;
33318
- return checkResult;
33319
32801
  }
33320
- if (innerHTML.includes("操作")) {
33321
- // console.log("检查smardaten平台表格 操作 元素:",innerHTML);
33322
- let tempHTMLMatch = {
33323
- oldValue: '$L{操作}'
33324
- };
33325
- checkResult.result = true;
33326
- checkResult.innerHTMLMatch = tempHTMLMatch;
33327
- return checkResult;
32802
+ }
32803
+ let scriptFunction = (appID, lang) => {
32804
+ for (let i = 0; i < checkAttributes.length; i++) {
32805
+ let attr = checkAttributes[i];
32806
+ const oldAttrValue = element.getAttribute(`old${attr}Value`);
32807
+ if (oldAttrValue) {
32808
+ // 创建正则表达式匹配所有 $L{...} 格式
32809
+ const regex = /\$L\{([^}]+)\}/g;
32810
+ // 替换所有 $L{...} 占位符为翻译文本
32811
+ let newAttrValue = oldAttrValue;
32812
+ let match;
32813
+ while ((match = regex.exec(oldAttrValue)) !== null) {
32814
+ const fullMatch = match[0];
32815
+ const attrKey = match[1];
32816
+ const translation = i18n(attrKey, appID, lang);
32817
+ newAttrValue = newAttrValue.replace(fullMatch, translation);
32818
+ }
32819
+ // 更新元素的placeholder属性
32820
+ element.setAttribute(attr, newAttrValue);
32821
+ }
33328
32822
  }
32823
+ };
32824
+ checkResult.scriptFunction = scriptFunction;
32825
+ return checkResult;
32826
+ };
32827
+ ;// ./src/api/i18n/smardaten_i18n/calendar_i18n.js
32828
+
32829
+
32830
+ function convertToChineseWeekday(englishInput) {
32831
+ // 清理输入:去除首尾空格并转为小写
32832
+ const input = englishInput.trim().toLowerCase();
32833
+
32834
+ // 定义星期映射关系
32835
+ const weekdayMap = {
32836
+ 'mon': '周一',
32837
+ 'monday': '周一',
32838
+ 'mondays': '周一',
32839
+ 'tue': '周二',
32840
+ 'tues': '周二',
32841
+ 'tuesday': '周二',
32842
+ 'tuesdays': '周二',
32843
+ 'wed': '周三',
32844
+ 'wednesday': '周三',
32845
+ 'wednesdays': '周三',
32846
+ 'thu': '周四',
32847
+ 'thur': '周四',
32848
+ 'thurs': '周四',
32849
+ 'thursday': '周四',
32850
+ 'thursdays': '周四',
32851
+ 'fri': '周五',
32852
+ 'friday': '周五',
32853
+ 'fridays': '周五',
32854
+ 'sat': '周六',
32855
+ 'saturday': '周六',
32856
+ 'saturdays': '周六',
32857
+ 'sun': '周日',
32858
+ 'sunday': '周日',
32859
+ 'sundays': '周日'
32860
+ };
32861
+
32862
+ // 使用正则表达式匹配所有可能的星期格式
32863
+ const pattern = /^(mon(day)?s?\.?|tue(sday)?s?\.?|wed(nesday)?s?\.?|thu(r(sday)?)?s?\.?|fri(day)?s?\.?|sat(urday)?s?\.?|sun(day)?s?\.?)$/i;
32864
+
32865
+ // 测试输入是否匹配星期格式
32866
+ if (!pattern.test(input)) {
32867
+ return '未知日期';
33329
32868
  }
33330
- // 检查分页组件 导出按钮
33331
- if (classes.contains("export_menu")) {
33332
- let innerHTML = element.innerHTML;
33333
- if (innerHTML.includes("导出进度") || innerHTML.includes("Export progress")) {
33334
- // console.log("检查smardaten平台表格 导出按钮 元素:",innerHTML);
33335
- let tempHTMLMatch = {
33336
- oldValue: '$L{导出进度}'
33337
- };
33338
- checkResult.result = true;
33339
- checkResult.innerHTMLMatch = tempHTMLMatch;
33340
- return checkResult;
32869
+
32870
+ // 提取基础名称(去除复数形式和句点)
32871
+ const baseName = input.replace(/\./g, '') // 移除所有句点
32872
+ .replace(/s$/, ''); // 移除结尾的's'(复数形式)
32873
+
32874
+ // 特殊处理周四的多种缩写形式
32875
+ const normalized = baseName.startsWith('thu') ? 'thu' : baseName.slice(0, 3);
32876
+
32877
+ // 映射到中文名称
32878
+ return weekdayMap[normalized] || weekdayMap[baseName] || '未知日期';
32879
+ }
32880
+ function extractYearMonth(str) {
32881
+ const regex = /(\d{4})年(0?[1-9]|1[0-2])月/g;
32882
+ const matches = str.matchAll(regex);
32883
+ const result = [];
32884
+ for (const match of matches) {
32885
+ const year = parseInt(match[1], 10);
32886
+ const month = parseInt(match[2], 10);
32887
+ result.push({
32888
+ year,
32889
+ month
32890
+ });
32891
+ }
32892
+ return result;
32893
+ }
32894
+ function extractDayNumbers(text) {
32895
+ // 匹配两种情况:
32896
+ // 1. "数字+日"格式(如"5日"、"12日")
32897
+ // 2. 独立的1-31数字(前后有边界)
32898
+ const regex = /(?:(\b(0?[1-9]|[12]\d|3[01])\b)(?=日))|(\b(0?[1-9]|[12]\d|3[01])\b)/g;
32899
+ const results = [];
32900
+ let match;
32901
+ while ((match = regex.exec(text)) !== null) {
32902
+ // match[2] 对应第一种情况(带"日"字的数字)
32903
+ // match[4] 对应第二种情况(独立数字)
32904
+ const numStr = match[2] || match[4];
32905
+ if (numStr) {
32906
+ // 转换为整数并验证范围
32907
+ const day = parseInt(numStr, 10);
32908
+ if (day >= 1 && day <= 31) {
32909
+ results.push(day);
32910
+ }
33341
32911
  }
33342
32912
  }
33343
- // 检查分页组件
33344
- if (classes.contains("total_pag_num")) {
33345
- let innerHTML = element.innerHTML;
33346
- if (innerHTML.includes("共") && innerHTML.includes("条") || innerHTML.includes("Total") && innerHTML.includes("pieces")) {
33347
- // console.log("检查smardaten平台分页 共xx条 元素:",innerHTML);
33348
- let scriptFunction = (appID, lang) => {
33349
- let scriptNode = null;
33350
- for (let node of element.childNodes) {
33351
- // 检查是否为文本节点且包含"Total"
33352
- if (node.tagName === "SPAN") {
33353
- scriptNode = node;
33354
- }
33355
- }
33356
- let scriptNodes = [{
33357
- nodeType: Node.TEXT_NODE,
33358
- key: '共'
33359
- }, {
33360
- nodeType: "SCRIPTNODE",
33361
- node: scriptNode
33362
- }, {
33363
- nodeType: Node.TEXT_NODE,
33364
- key: '条'
33365
- }];
33366
- for (let i = 0; i < element.childNodes.length; i++) {
33367
- let childNode = element.childNodes[i];
33368
- if (childNode.nodeType === Node.TEXT_NODE) {
33369
- element.removeChild(childNode);
33370
- }
33371
- }
33372
- for (let i = 0; i < scriptNodes.length; i++) {
33373
- let scriptNodeItem = scriptNodes[i];
33374
- if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33375
- let textNode = document.createTextNode(i18n(scriptNodeItem.key, appID, lang) || scriptNodeItem.key);
33376
- element.appendChild(textNode);
33377
- }
33378
- if (scriptNodeItem.nodeType === "SCRIPTNODE") {
33379
- element.appendChild(scriptNodeItem.node);
33380
- }
32913
+ return results;
32914
+ }
32915
+ function extractNumbersFromScenarios(text) {
32916
+ // 定义两种场景的正则表达式
32917
+ const patterns = [
32918
+ // 场景1: "Other X pieces of data"
32919
+ /Other\s+(\d+)\s+pieces of data/gi,
32920
+ // 场景2: "其他 X 条记录"
32921
+ /其他\s+(\d+)\s+条记录/g];
32922
+ const results = [];
32923
+
32924
+ // 遍历所有模式进行匹配
32925
+ patterns.forEach(pattern => {
32926
+ let match;
32927
+ while ((match = pattern.exec(text)) !== null) {
32928
+ // 提取捕获组中的数字
32929
+ const number = parseInt(match[1], 10);
32930
+ results.push({
32931
+ scenario: match[0],
32932
+ // 完整匹配的字符串
32933
+ number: number,
32934
+ // 提取的数字
32935
+ type: pattern.source.includes('Other') ? 'English' : 'Chinese'
32936
+ });
32937
+ }
32938
+ });
32939
+ return results;
32940
+ }
32941
+ const calendar_i18n_check = element => {
32942
+ const checkResult = {
32943
+ result: false,
32944
+ innerHTMLMatch: null
32945
+ };
32946
+ const classes = element.classList;
32947
+ if (!classes) {
32948
+ return checkResult;
32949
+ }
32950
+ // 检查日历标题
32951
+ if (classes.contains("fc-toolbar-title")) {
32952
+ let scriptFunction = (appID, lang) => {
32953
+ let oldValue = element.getAttribute("oldValue");
32954
+ let yearMonthList = extractYearMonth(oldValue);
32955
+ if (yearMonthList.length > 0) {
32956
+ let yearMonth = yearMonthList[0];
32957
+ let year = yearMonth.year;
32958
+ let month = yearMonth.month;
32959
+ let newInnerHTML = `${year}/${month}`;
32960
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
32961
+ if (lang === "zh-CN") {
32962
+ newInnerHTML = `${year}年${month}月`;
33381
32963
  }
33382
- };
32964
+ element.innerHTML = newInnerHTML;
32965
+ }
32966
+ };
32967
+ let innerHTML = element.innerHTML;
32968
+ let testRule = /^\d{4}年(0?[1-9]|1[0-2])月$/;
32969
+ if (testRule.test(innerHTML)) {
32970
+ // console.log("检查smardaten平台日历标题 元素:",innerHTML);
33383
32971
  let tempHTMLMatch = {
32972
+ oldValue: innerHTML,
33384
32973
  isScriptAction: true,
33385
32974
  scriptFunction: scriptFunction
33386
32975
  };
@@ -33389,1074 +32978,1504 @@ const check = element => {
33389
32978
  return checkResult;
33390
32979
  }
33391
32980
  }
33392
- // 检查分页组件 跳至xx页
33393
- if (classes.contains("ant-pagination-options-quick-jumper")) {
32981
+ // 检查日历今天按钮
32982
+ if (classes.contains("fc-today-button")) {
33394
32983
  let innerHTML = element.innerHTML;
33395
- if (innerHTML.includes("跳至") && innerHTML.includes("页") || innerHTML.includes("Go to") && innerHTML.includes("Page")) {
33396
- // console.log("检查smardaten平台分页 跳至xx页 元素:",innerHTML);
33397
- let scriptFunction = (appID, lang) => {
33398
- let scriptNode = null;
33399
- for (let node of element.childNodes) {
33400
- // 检查是否为文本节点且包含"Total"
33401
- if (node.tagName === "INPUT") {
33402
- scriptNode = node;
33403
- }
33404
- }
33405
- let scriptNodes = [{
33406
- nodeType: Node.TEXT_NODE,
33407
- key: '跳至'
33408
- }, {
33409
- nodeType: "SCRIPTNODE",
33410
- node: scriptNode
33411
- }, {
33412
- nodeType: Node.TEXT_NODE,
33413
- key: '页'
33414
- }];
33415
- for (let i = 0; i < element.childNodes.length; i++) {
33416
- let childNode = element.childNodes[i];
33417
- if (childNode.nodeType === Node.TEXT_NODE) {
33418
- element.removeChild(childNode);
33419
- }
33420
- }
33421
- for (let i = 0; i < scriptNodes.length; i++) {
33422
- let scriptNodeItem = scriptNodes[i];
33423
- if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33424
- let textNode = document.createTextNode(i18n(scriptNodeItem.key, appID, lang) || scriptNodeItem.key);
33425
- element.appendChild(textNode);
33426
- }
33427
- if (scriptNodeItem.nodeType === "SCRIPTNODE") {
33428
- element.appendChild(scriptNodeItem.node);
33429
- }
33430
- }
33431
- };
32984
+ if (innerHTML.includes("今天") || innerHTML.includes("today")) {
32985
+ // console.log("检查smardaten平台日历 今天 元素:",innerHTML);
33432
32986
  let tempHTMLMatch = {
33433
- isScriptAction: true,
33434
- scriptFunction: scriptFunction
32987
+ oldValue: '$L{今天}'
33435
32988
  };
33436
32989
  checkResult.result = true;
33437
32990
  checkResult.innerHTMLMatch = tempHTMLMatch;
33438
32991
  return checkResult;
33439
32992
  }
33440
32993
  }
33441
- // 检查每页xx条
33442
- if (classes.contains("ant-select-selection-item") || classes.contains("ant-select-item-option-content")) {
32994
+ // 检查日历标题
32995
+ if (classes.contains("fullCalendar_title_value")) {
33443
32996
  let innerHTML = element.innerHTML;
33444
- // console.log("检查smardaten平台分页 每页xx条 元素:",innerHTML);
33445
- if (innerHTML.includes("/") && innerHTML.includes("page") || innerHTML.includes("/") && innerHTML.includes("条") && innerHTML.includes("页")) {
33446
- let oldValue = element.innerHTML;
33447
- if (innerHTML.includes("page")) {
33448
- oldValue = oldValue.replace('page', '$L{页}');
33449
- }
33450
- if (innerHTML.includes("页")) {
33451
- oldValue = oldValue.replace('页', '$L{页}');
33452
- }
33453
- if (innerHTML.includes("条")) {
33454
- oldValue = oldValue.replace('条', '$L{条}');
33455
- }
32997
+ const regex = /周[一二三四五六日]/;
32998
+ const regex_en = /^(mon(day)?s?\.?|tue(sday)?s?\.?|wed(nesday)?s?\.?|thu(r(sday)?)?s?\.?|fri(day)?s?\.?|sat(urday)?s?\.?|sun(day)?s?\.?)$/i;
32999
+ let match = innerHTML.match(regex);
33000
+ if (match) {
33001
+ // console.log("检查smardaten平台日历 周 元素:",innerHTML);
33002
+ let day = match[0];
33456
33003
  let tempHTMLMatch = {
33457
- oldValue: oldValue
33004
+ oldValue: `$L{${day}}`
33458
33005
  };
33459
33006
  checkResult.result = true;
33460
33007
  checkResult.innerHTMLMatch = tempHTMLMatch;
33461
33008
  return checkResult;
33462
33009
  }
33463
- }
33464
- // 检查删除确认对话框标题
33465
- if (classes.contains("ant-popover-message-title")) {
33466
- let innerHTML = element.innerHTML;
33467
- if (innerHTML.includes("确认执行:") || innerHTML.includes("Confirm Execution:")) {
33468
- // console.log("检查smardaten平台删除提问对话框:",innerHTML);
33010
+ match = innerHTML.match(regex_en);
33011
+ if (match) {
33012
+ // console.log("检查smardaten平台日历 周 元素:",innerHTML);
33013
+ let day = match[0];
33469
33014
  let tempHTMLMatch = {
33470
- oldValue: '$L{操作确认:删除?}'
33015
+ oldValue: `$L{${convertToChineseWeekday(day)}}`
33471
33016
  };
33472
33017
  checkResult.result = true;
33473
33018
  checkResult.innerHTMLMatch = tempHTMLMatch;
33474
33019
  return checkResult;
33475
33020
  }
33476
33021
  }
33477
- // 检查删除确认对话框按钮 取消 确认
33478
- if (classes.contains("ant-btn")) {
33022
+ //日期单元格
33023
+ if (classes.contains("fc-daygrid-day-number")) {
33024
+ let scriptFunction = (appID, lang) => {
33025
+ let oldValue = element.getAttribute("oldValue");
33026
+ let result = extractDayNumbers(oldValue);
33027
+ if (result && result.length > 0) {
33028
+ let day = result[0];
33029
+ let newInnerHTML = `${day}`;
33030
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33031
+ if (lang === "zh-CN") {
33032
+ newInnerHTML = `${day}日`;
33033
+ }
33034
+ element.innerHTML = newInnerHTML;
33035
+ }
33036
+ };
33479
33037
  let innerHTML = element.innerHTML;
33480
- if (innerHTML.includes("Cancel") || innerHTML.includes("取消")) {
33481
- // console.log("检查smardaten平台 Tip提问取消删除按钮:",innerHTML);
33038
+ let match = extractDayNumbers(innerHTML);
33039
+ if (match.length > 0) {
33040
+ // console.log("检查smardaten平台日历 日 元素:",innerHTML);
33482
33041
  let tempHTMLMatch = {
33483
- oldValue: '$L{取消}'
33042
+ oldValue: innerHTML,
33043
+ isScriptAction: true,
33044
+ scriptFunction: scriptFunction
33484
33045
  };
33485
33046
  checkResult.result = true;
33486
33047
  checkResult.innerHTMLMatch = tempHTMLMatch;
33487
33048
  return checkResult;
33488
33049
  }
33489
- if (innerHTML.includes("确定") || innerHTML.includes("OK")) {
33490
- // console.log("检查smardaten平台 Tip提问确认删除按钮:",innerHTML);
33050
+ }
33051
+ // 日历更多按钮
33052
+ if (classes.contains("fc-daygrid-more-link")) {
33053
+ let scriptFunction = (appID, lang) => {
33054
+ let oldValue = element.getAttribute("oldValue");
33055
+ let result = extractNumbersFromScenarios(oldValue);
33056
+ if (result && result.length > 0) {
33057
+ let day = result[0]["number"];
33058
+ let newInnerHTML = "另外${X}条数据";
33059
+ newInnerHTML = i18n(newInnerHTML, appID, lang);
33060
+ newInnerHTML = newInnerHTML.replace("${X}", day);
33061
+ element.innerHTML = newInnerHTML;
33062
+ }
33063
+ };
33064
+ let innerHTML = element.innerHTML;
33065
+ let match = extractNumbersFromScenarios(innerHTML);
33066
+ if (match.length > 0) {
33067
+ // console.log("检查smardaten平台日历 更多 元素:",innerHTML);
33491
33068
  let tempHTMLMatch = {
33492
- oldValue: '$L{确定}'
33069
+ oldValue: innerHTML,
33070
+ isScriptAction: true,
33071
+ scriptFunction: scriptFunction
33493
33072
  };
33494
33073
  checkResult.result = true;
33495
33074
  checkResult.innerHTMLMatch = tempHTMLMatch;
33496
33075
  return checkResult;
33497
33076
  }
33498
33077
  }
33499
- return checkResult;
33500
- };
33501
- ;// ./src/api/i18n/smardaten_i18n/catalog_i18n.js
33502
-
33503
- const catalog_i18n_check = element => {
33504
- const checkResult = {
33505
- result: false,
33506
- innerHTMLMatch: null
33507
- };
33508
- const classes = element.classList;
33509
- if (!classes) {
33510
- return checkResult;
33511
- }
33512
- let innerHTML = element.innerHTML;
33513
- let oldValue = element.getAttribute("oldValue");
33514
- if (!oldValue) {
33515
- oldValue = innerHTML;
33516
- }
33517
- // 检查目录列表 名称 列
33518
- if (classes.contains("catalog_name_content")) {
33519
- // console.log("检查smardaten平台目录列表 元素:",innerHTML);
33520
- let scriptFunction = (appID, lang) => {
33521
- for (let i = 0; i < element.childNodes.length; i++) {
33522
- let scriptNodeItem = element.childNodes[i];
33523
- if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33524
- let text = element.getAttribute("oldValue");
33525
- let isTextMatch = checkTextFormat(text);
33526
- if (!isTextMatch) {
33527
- element.appendChild(scriptNodeItem);
33528
- } else {
33529
- element.removeChild(scriptNodeItem);
33530
- let key = isTextMatch.key;
33531
- let textNode = document.createTextNode(i18n(key, appID, lang) || key);
33532
- element.appendChild(textNode);
33533
- }
33534
- } else {
33535
- element.appendChild(scriptNodeItem);
33536
- }
33537
- }
33538
- };
33539
- let tempHTMLMatch = {
33540
- oldValue: oldValue,
33541
- isScriptAction: true,
33542
- scriptFunction: scriptFunction
33543
- };
33544
- checkResult.result = true;
33545
- checkResult.innerHTMLMatch = tempHTMLMatch;
33546
- return checkResult;
33547
- }
33548
- if (classes.contains("catalog-tree-search")) {
33078
+ // 日历弹窗标题
33079
+ if (classes.contains("fc-popover-title")) {
33080
+ // 正则表达式匹配中文日期格式
33081
+ const regex = /(\d{4})年(\d{1,2})月(\d{1,2})日/g;
33549
33082
  let scriptFunction = (appID, lang) => {
33550
- for (let i = 0; i < element.childNodes.length; i++) {
33551
- let scriptNodeItem = element.childNodes[i];
33552
- if (scriptNodeItem.tagName === 'INPUT') {
33553
- let oldValue = scriptNodeItem.getAttribute("oldplaceholderValue");
33554
- if (!oldValue) {
33555
- let text = scriptNodeItem.getAttribute("placeholder");
33556
- if (text) {
33557
- text = `$L{${text}}`;
33558
- }
33559
- scriptNodeItem.setAttribute("placeholder", text);
33560
- processElement(scriptNodeItem, appID, lang);
33083
+ let oldValue = element.getAttribute("oldValue");
33084
+ let match = oldValue.match(regex);
33085
+ if (match) {
33086
+ // 替换函数
33087
+ const convertedText = oldValue.replace(regex, function (match, year, month, day) {
33088
+ // 格式化月份和日期为两位数
33089
+ const formattedMonth = month.padStart(2, '0');
33090
+ const formattedDay = day.padStart(2, '0');
33091
+ let result = `${year}/${formattedMonth}/${formattedDay}`;
33092
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33093
+ if (lang === "zh-CN") {
33094
+ result = `${year}年${formattedMonth}月${formattedDay}日`;
33561
33095
  }
33562
- }
33096
+ // 返回新格式的日期
33097
+ return result;
33098
+ });
33099
+ element.innerHTML = convertedText;
33563
33100
  }
33564
33101
  };
33565
- let tempHTMLMatch = {
33566
- oldValue: oldValue,
33567
- isScriptAction: true,
33568
- scriptFunction: scriptFunction
33569
- };
33570
- checkResult.result = true;
33571
- checkResult.innerHTMLMatch = tempHTMLMatch;
33572
- return checkResult;
33102
+ let innerHTML = element.innerHTML;
33103
+ let match = innerHTML.match(regex);
33104
+ if (match && match.length > 0) {
33105
+ // console.log("检查smardaten平台日历 日 元素:",innerHTML);
33106
+ let tempHTMLMatch = {
33107
+ oldValue: innerHTML,
33108
+ isScriptAction: true,
33109
+ scriptFunction: scriptFunction
33110
+ };
33111
+ checkResult.result = true;
33112
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33113
+ return checkResult;
33114
+ }
33573
33115
  }
33574
33116
  return checkResult;
33575
33117
  };
33576
- ;// ./src/api/i18n/commom_i18n/common_i18n.js
33577
-
33578
-
33579
- function getOldValueNodeText(innerHTML, index) {
33580
- const container = document.createElement('div');
33581
- container.innerHTML = innerHTML;
33582
- const childNode = container.childNodes[index];
33583
- return childNode.textContent;
33584
- }
33585
- const common_i18n_check = element => {
33118
+ ;// ./src/api/i18n/smardaten_i18n/dialog_i18n.js
33119
+ const dialog_i18n_check = element => {
33586
33120
  const checkResult = {
33587
33121
  result: false,
33588
33122
  innerHTMLMatch: null
33589
33123
  };
33590
- // 检查目录列表 名称
33591
- if (element.tagName === 'BUTTON' || element.tagName === 'P') {
33592
- //TODO:先检查新的是否需要解析,新的不需要有可能是解析后的再次判断,如果有历史解析值,则解析
33593
- //如果新的需要解析,更新缓存的历史解析值
33124
+ const classes = element.classList;
33125
+ if (!classes) {
33126
+ return checkResult;
33127
+ }
33128
+ let innerHTML = element.innerHTML;
33129
+ let oldValue = element.getAttribute("oldValue");
33130
+ if (!oldValue) {
33131
+ oldValue = innerHTML;
33132
+ }
33133
+ // 检查删除确认对话框按钮 取消 确认
33134
+ if (classes.contains("ant-modal-title")) {
33594
33135
  let innerHTML = element.innerHTML;
33595
- let oldValue = element.getAttribute("oldValue");
33596
- if (!oldValue) {
33597
- oldValue = innerHTML;
33136
+ if (innerHTML.includes("Select Data") || innerHTML.includes("选择数据")) {
33137
+ // console.log("检查smardaten平台 Tip提问取消删除按钮:",innerHTML);
33138
+ let tempHTMLMatch = {
33139
+ oldValue: '$L{选择数据}'
33140
+ };
33141
+ checkResult.result = true;
33142
+ checkResult.innerHTMLMatch = tempHTMLMatch;
33143
+ return checkResult;
33598
33144
  }
33599
- let firstCheck = checkTextFormat(oldValue);
33600
- let firstCheckResult = firstCheck ? true : false;
33601
- // console.log("检查 button 元素:",innerHTML);
33602
- // console.log("检查结果:",firstCheckResult);
33145
+ }
33146
+ return checkResult;
33147
+ };
33148
+ ;// ./src/api/i18n/commom_view.js
33149
+ const commom_view_check = element => {
33150
+ const checkResult = {
33151
+ result: false
33152
+ };
33153
+ const classes = element.classList;
33154
+ if (!classes) {
33155
+ return checkResult;
33156
+ }
33157
+ // 处理容器节点
33158
+ if (element.tagName === "DIV" && classes.contains("template-block")) {
33603
33159
  let scriptFunction = (appID, lang) => {
33604
- let elementsArray = [];
33605
- for (let i = 0; i < element.childNodes.length; i++) {
33606
- let scriptNodeItem = element.childNodes[i];
33607
- if (scriptNodeItem.nodeType === Node.TEXT_NODE) {
33608
- let oldValue = element.getAttribute("oldValue");
33609
- // console.log("执行 button 文本节点翻译:", text);
33610
- // 创建正则表达式匹配所有 $L{...} 格式
33611
- const regex = /\$L\{([^}]+)\}/g;
33612
- let isTextMatch = checkTextFormat(oldValue);
33613
- if (!isTextMatch) {
33614
- elementsArray.push(scriptNodeItem);
33615
- } else {
33616
- // console.log("执行 button 脚本节点翻译isTextMatch:", isTextMatch?true:false);
33617
- // element.removeChild(scriptNodeItem);
33618
- // 替换所有 $L{...} 占位符为翻译文本
33619
- let childNodeText = getOldValueNodeText(oldValue, i);
33620
- let newValue = childNodeText;
33621
- let match;
33622
- while ((match = regex.exec(oldValue)) !== null) {
33623
- const fullMatch = match[0];
33624
- const placeholderKey = match[1];
33625
- const translation = i18n(placeholderKey, appID, lang);
33626
- newValue = newValue.replace(fullMatch, translation);
33160
+ let divDom = element.parentNode;
33161
+ let divDom2;
33162
+ let appBlockDom;
33163
+ let comDom;
33164
+ let renderDom;
33165
+ if (divDom && divDom.tagName === "DIV") {
33166
+ divDom2 = divDom.parentNode;
33167
+ if (divDom2 && divDom2.tagName === "DIV") {
33168
+ appBlockDom = divDom2.parentNode;
33169
+ if (appBlockDom && appBlockDom.tagName === "DIV" && appBlockDom.classList.contains("application-block")) {
33170
+ comDom = appBlockDom.parentNode;
33171
+ if (comDom && comDom.tagName === "DIV" && comDom.classList.contains("componentDiv")) {
33172
+ renderDom = comDom.parentNode;
33173
+ if (renderDom && renderDom.tagName === "DIV" && renderDom.classList.contains("render-all-blocks")) {
33174
+ //隐藏整个组件
33175
+ renderDom.style.height = "100%";
33176
+ comDom.style.height = "100%";
33177
+ appBlockDom.style.height = "100%";
33178
+ divDom2.style.height = "100%";
33179
+ divDom.style.height = "100%";
33180
+ element.style.height = "100%";
33181
+ //标记已经处理过
33182
+ element.setAttribute("viewDomID", generateUniqueId());
33183
+ }
33627
33184
  }
33628
- let textNode = document.createTextNode(newValue);
33629
- elementsArray.push(textNode);
33630
33185
  }
33631
- } else {
33632
- elementsArray.push(scriptNodeItem);
33633
33186
  }
33634
33187
  }
33635
- element.innerHTML = '';
33636
- elementsArray.forEach(el => {
33637
- element.appendChild(el);
33638
- });
33639
- };
33640
- let tempHTMLMatch = {
33641
- oldValue: oldValue,
33642
- isScriptAction: true,
33643
- scriptFunction: scriptFunction
33644
33188
  };
33645
- checkResult.result = firstCheckResult;
33646
- checkResult.innerHTMLMatch = tempHTMLMatch;
33189
+ checkResult.result = true;
33190
+ checkResult.scriptFunction = scriptFunction;
33647
33191
  return checkResult;
33648
33192
  }
33649
33193
  return checkResult;
33650
33194
  };
33651
- ;// ./src/api/i18n/commom_i18n/attribute_i18n.js
33195
+ function generateUniqueId() {
33196
+ return `rjview_${Date.now()}`;
33197
+ }
33198
+ ;// ./src/api/i18n/i18n.js
33652
33199
 
33653
- const attribute_i18n_check = element => {
33654
- const checkResult = {
33655
- result: false,
33656
- innerHTMLMatch: null
33657
- };
33658
- if (!element) {
33659
- return checkResult;
33660
- }
33661
- const checkAttributes = ["placeholder", "title"];
33662
- for (let i = 0; i < checkAttributes.length; i++) {
33663
- let attr = checkAttributes[i];
33664
- let attrValue = element.getAttribute(attr) || element[attr];
33665
- const attrMatch = attrValue ? checkTextFormat(attrValue) : null;
33666
- if (attrMatch) {
33667
- // console.log("检查元素属性 i18n 元素:", attr, attrValue);
33668
- element.setAttribute(`old${attr}Value`, attrValue);
33669
- checkResult.result = true;
33200
+
33201
+
33202
+
33203
+
33204
+
33205
+
33206
+
33207
+
33208
+
33209
+
33210
+
33211
+
33212
+ const getLanguages = async appID => {
33213
+ let queryData = {
33214
+ param: {
33215
+ appID: appID
33670
33216
  }
33671
- }
33672
- let scriptFunction = (appID, lang) => {
33673
- for (let i = 0; i < checkAttributes.length; i++) {
33674
- let attr = checkAttributes[i];
33675
- const oldAttrValue = element.getAttribute(`old${attr}Value`);
33676
- if (oldAttrValue) {
33677
- // 创建正则表达式匹配所有 $L{...} 格式
33678
- const regex = /\$L\{([^}]+)\}/g;
33679
- // 替换所有 $L{...} 占位符为翻译文本
33680
- let newAttrValue = oldAttrValue;
33681
- let match;
33682
- while ((match = regex.exec(oldAttrValue)) !== null) {
33683
- const fullMatch = match[0];
33684
- const attrKey = match[1];
33685
- const translation = i18n(attrKey, appID, lang);
33686
- newAttrValue = newAttrValue.replace(fullMatch, translation);
33687
- }
33688
- // 更新元素的placeholder属性
33689
- element.setAttribute(attr, newAttrValue);
33690
- }
33217
+ };
33218
+ let response = await request.post(`/dataservice/rest/orchestration/getAppLanguages`, queryData);
33219
+ let resultDatas = response.data.resultDatas || [];
33220
+ return resultDatas;
33221
+ };
33222
+ const i18n = (key, appID, localID) => {
33223
+ let result = window.customI18nObject?.get(`${appID}-${key}-${localID}`) || key;
33224
+ return result;
33225
+ };
33226
+ function i18nText(key) {
33227
+ let app_id = getPoratlAppID();
33228
+ let langID = window.localStorage.getItem("iportal_localID") || "zh-CN";
33229
+ return i18n(key, app_id, langID);
33230
+ }
33231
+ const loadi18nTexts = async appID => {
33232
+ let queryData = {
33233
+ param: {
33234
+ appID: appID
33691
33235
  }
33692
33236
  };
33693
- checkResult.scriptFunction = scriptFunction;
33694
- return checkResult;
33237
+ let response = await request.post(`/dataservice/rest/orchestration/getAllTexts`, queryData);
33238
+ let resultDatas = response.data.resultDatas || [];
33239
+ window.customI18nObject = new Map();
33240
+ for (let item of resultDatas) {
33241
+ window.customI18nObject.set(`${appID}-${item.key}-${item.lang}`, item.value);
33242
+ }
33695
33243
  };
33696
- ;// ./src/api/i18n/smardaten_i18n/calendar_i18n.js
33697
33244
 
33245
+ /**
33246
+ * 检查元素是否有子DOM元素
33247
+ * @param {HTMLElement} element - 要检查的DOM元素
33248
+ * @returns {boolean} - 是否有子元素
33249
+ */
33250
+ function hasChildElements(element) {
33251
+ return element && element.children?.length > 0;
33252
+ }
33698
33253
 
33699
- function convertToChineseWeekday(englishInput) {
33700
- // 清理输入:去除首尾空格并转为小写
33701
- const input = englishInput.trim().toLowerCase();
33254
+ /**
33255
+ * 检查文本是否匹配$L{...}格式
33256
+ * @param {string} text - 要检查的文本
33257
+ * @returns {Object|null} - 匹配结果或null
33258
+ */
33259
+ function checkTextFormat(text) {
33260
+ if (!text) return null;
33261
+ const regex = /\$L\{([^}]+)\}/;
33262
+ const match = text.match(regex);
33263
+ if (match) {
33264
+ return {
33265
+ fullMatch: match[0],
33266
+ key: match[1]
33267
+ };
33268
+ }
33269
+ return null;
33270
+ }
33271
+ function i18n_generateUniqueId() {
33272
+ window.idCounter = window.idCounter || 0;
33273
+ return `i18n_${Date.now()}_${window.idCounter++}`;
33274
+ }
33702
33275
 
33703
- // 定义星期映射关系
33704
- const weekdayMap = {
33705
- 'mon': '周一',
33706
- 'monday': '周一',
33707
- 'mondays': '周一',
33708
- 'tue': '周二',
33709
- 'tues': '周二',
33710
- 'tuesday': '周二',
33711
- 'tuesdays': '周二',
33712
- 'wed': '周三',
33713
- 'wednesday': '周三',
33714
- 'wednesdays': '周三',
33715
- 'thu': '周四',
33716
- 'thur': '周四',
33717
- 'thurs': '周四',
33718
- 'thursday': '周四',
33719
- 'thursdays': '周四',
33720
- 'fri': '周五',
33721
- 'friday': '周五',
33722
- 'fridays': '周五',
33723
- 'sat': '周六',
33724
- 'saturday': '周六',
33725
- 'saturdays': '周六',
33726
- 'sun': '周日',
33727
- 'sunday': '周日',
33728
- 'sundays': '周日'
33276
+ /**
33277
+ * 检查平台特定元素并返回匹配结果
33278
+ * @param {*} element
33279
+ * @returns
33280
+ */
33281
+ function checkPlatformElementContent(element) {
33282
+ const checkContentResult = {
33283
+ result: false,
33284
+ innerHTMLMatch: null
33729
33285
  };
33286
+ let checkArr = [check, catalog_i18n_check, calendar_i18n_check, dialog_i18n_check, common_i18n_check];
33287
+ for (let i = 0; i < checkArr.length; i++) {
33288
+ let checkFunc = checkArr[i];
33289
+ let checkContentResult = checkFunc(element);
33290
+ if (checkContentResult.result) {
33291
+ return checkContentResult;
33292
+ }
33293
+ }
33294
+ return checkContentResult;
33295
+ }
33296
+ function processElement(element) {
33297
+ if (!element) {
33298
+ return false;
33299
+ }
33730
33300
 
33731
- // 使用正则表达式匹配所有可能的星期格式
33732
- const pattern = /^(mon(day)?s?\.?|tue(sday)?s?\.?|wed(nesday)?s?\.?|thu(r(sday)?)?s?\.?|fri(day)?s?\.?|sat(urday)?s?\.?|sun(day)?s?\.?)$/i;
33301
+ // 仅处理元素节点
33302
+ if (element && element.nodeType !== Node.ELEMENT_NODE) {
33303
+ return false;
33304
+ }
33733
33305
 
33734
- // 测试输入是否匹配星期格式
33735
- if (!pattern.test(input)) {
33736
- return '未知日期';
33306
+ // 如果元素有子元素,递归处理子元素
33307
+ const hasChildren = hasChildElements(element);
33308
+ if (hasChildren) {
33309
+ let children = element.children;
33310
+ for (let i = 0; i < children.length; i++) {
33311
+ let child = children[i];
33312
+ if (child.nodeType === Node.ELEMENT_NODE) {
33313
+ let childLocalDomID = child.getAttribute("localDomID");
33314
+ // 如果子元素有localDomID但不在缓存中,移除localDomID属性
33315
+ if (childLocalDomID && window.i18nElementsMap && !window.i18nElementsMap.has(childLocalDomID)) {
33316
+ unProcessElement(child);
33317
+ }
33318
+ }
33319
+ processElement(children[i]);
33320
+ }
33737
33321
  }
33738
33322
 
33739
- // 提取基础名称(去除复数形式和句点)
33740
- const baseName = input.replace(/\./g, '') // 移除所有句点
33741
- .replace(/s$/, ''); // 移除结尾的's'(复数形式)
33323
+ // 检查innerHTML是否匹配(仅对没有子元素的元素)
33324
+ let innerHTMLMatch = null;
33325
+ const attrCheckResult = attribute_i18n_check(element);
33326
+ if (attrCheckResult.result) {
33327
+ console.log("检查到属性匹配元素:", element);
33328
+ }
33742
33329
 
33743
- // 特殊处理周四的多种缩写形式
33744
- const normalized = baseName.startsWith('thu') ? 'thu' : baseName.slice(0, 3);
33330
+ //检查是否是smardaten平台元素
33331
+ const checkContentResult = checkPlatformElementContent(element);
33332
+ if (checkContentResult.result) {
33333
+ innerHTMLMatch = checkContentResult.innerHTMLMatch;
33334
+ element.setAttribute("oldValue", innerHTMLMatch.oldValue);
33335
+ } else {
33336
+ if (!hasChildren) {
33337
+ //如果存在历史值,说明之前解析过,有可能是值需要刷新触发
33338
+ let newValue = element.innerHTML;
33339
+ let newMatch = checkTextFormat(newValue);
33340
+ if (newMatch) {
33341
+ innerHTMLMatch = newMatch;
33342
+ } else {
33343
+ newValue = element.getAttribute("oldValue");
33344
+ if (!newValue) {
33345
+ newValue = element.innerHTML;
33346
+ }
33347
+ innerHTMLMatch = checkTextFormat(newValue);
33348
+ }
33349
+ if (innerHTMLMatch) {
33350
+ // console.log("检查到innerHTML匹配元素:",element);
33351
+ element.setAttribute("oldValue", newValue);
33352
+ }
33353
+ }
33354
+ }
33745
33355
 
33746
- // 映射到中文名称
33747
- return weekdayMap[normalized] || weekdayMap[baseName] || '未知日期';
33748
- }
33749
- function extractYearMonth(str) {
33750
- const regex = /(\d{4})年(0?[1-9]|1[0-2])月/g;
33751
- const matches = str.matchAll(regex);
33752
- const result = [];
33753
- for (const match of matches) {
33754
- const year = parseInt(match[1], 10);
33755
- const month = parseInt(match[2], 10);
33756
- result.push({
33757
- year,
33758
- month
33759
- });
33356
+ // 如果没有匹配的内容,则不处理
33357
+ if (!innerHTMLMatch && !checkContentResult.result && !attrCheckResult.result) {
33358
+ return false;
33760
33359
  }
33761
- return result;
33360
+ let elementId = element.getAttribute("localDomID");
33361
+ if (!elementId) {
33362
+ elementId = i18n_generateUniqueId();
33363
+ } else {
33364
+ // 已经处理过的元素跳过
33365
+ return false;
33366
+ }
33367
+ element.setAttribute("localDomID", elementId);
33368
+ if (!window.i18nElementsMap) {
33369
+ window.i18nElementsMap = new Map();
33370
+ }
33371
+ // 添加到Map缓存
33372
+ window.i18nElementsMap.set(elementId, {
33373
+ dom: element,
33374
+ id: elementId,
33375
+ isScriptAction: innerHTMLMatch ? innerHTMLMatch.isScriptAction || false : false,
33376
+ scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null,
33377
+ isAttibuteAction: attrCheckResult.result,
33378
+ attrFunction: attrCheckResult.scriptFunction || null
33379
+ });
33380
+ // console.log("添加后元素缓冲数:",window.i18nElementsMap.size);
33381
+ applyTranslation(element);
33382
+ return true;
33762
33383
  }
33763
- function extractDayNumbers(text) {
33764
- // 匹配两种情况:
33765
- // 1. "数字+日"格式(如"5日"、"12日")
33766
- // 2. 独立的1-31数字(前后有边界)
33767
- const regex = /(?:(\b(0?[1-9]|[12]\d|3[01])\b)(?=日))|(\b(0?[1-9]|[12]\d|3[01])\b)/g;
33768
- const results = [];
33769
- let match;
33770
- while ((match = regex.exec(text)) !== null) {
33771
- // match[2] 对应第一种情况(带"日"字的数字)
33772
- // match[4] 对应第二种情况(独立数字)
33773
- const numStr = match[2] || match[4];
33774
- if (numStr) {
33775
- // 转换为整数并验证范围
33776
- const day = parseInt(numStr, 10);
33777
- if (day >= 1 && day <= 31) {
33778
- results.push(day);
33779
- }
33384
+ function unProcessElement(element) {
33385
+ if (element && element.nodeType !== 1) {
33386
+ return;
33387
+ }
33388
+ let hasChildren = hasChildElements(element);
33389
+ if (hasChildren) {
33390
+ let children = element.children;
33391
+ for (let i = 0; i < children.length; i++) {
33392
+ unProcessElement(children[i]);
33780
33393
  }
33781
33394
  }
33782
- return results;
33395
+ const localDomID = element.getAttribute("localDomID");
33396
+ if (localDomID) {
33397
+ // console.log(`处理元素ID:${localDomID} 移除缓存`);
33398
+ element.removeAttribute("localDomID");
33399
+ }
33400
+ if (localDomID && window.i18nElementsMap.has(localDomID)) {
33401
+ // let oldValue = element.getAttribute("oldValue");
33402
+ // if(oldValue){
33403
+ // element.removeAttribute("oldValue");
33404
+ // 更新元素的innerHTML
33405
+ // element.innerHTML = oldValue;
33406
+ // }
33407
+ window.i18nElementsMap.delete(localDomID);
33408
+ // console.log("移除后元素缓冲数:",window.i18nElementsMap.size);
33409
+ }
33783
33410
  }
33784
- function extractNumbersFromScenarios(text) {
33785
- // 定义两种场景的正则表达式
33786
- const patterns = [
33787
- // 场景1: "Other X pieces of data"
33788
- /Other\s+(\d+)\s+pieces of data/gi,
33789
- // 场景2: "其他 X 条记录"
33790
- /其他\s+(\d+)\s+条记录/g];
33791
- const results = [];
33792
33411
 
33793
- // 遍历所有模式进行匹配
33794
- patterns.forEach(pattern => {
33795
- let match;
33796
- while ((match = pattern.exec(text)) !== null) {
33797
- // 提取捕获组中的数字
33798
- const number = parseInt(match[1], 10);
33799
- results.push({
33800
- scenario: match[0],
33801
- // 完整匹配的字符串
33802
- number: number,
33803
- // 提取的数字
33804
- type: pattern.source.includes('Other') ? 'English' : 'Chinese'
33412
+ /**
33413
+ * 应用翻译到单个元素
33414
+ * @param {HTMLElement} element - 要更新的DOM元素
33415
+ * @param {string} lang - 语言标识符
33416
+ */
33417
+ const applyTranslation = async element => {
33418
+ let parentNode = element.parentNode;
33419
+ if (!parentNode) {
33420
+ unProcessElement(element);
33421
+ console.log("元素已无父节点,移除缓存");
33422
+ return;
33423
+ }
33424
+ let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33425
+ let appID = getPoratlAppID();
33426
+ const elementId = element.getAttribute("localDomID");
33427
+ const cachedItem = window.i18nElementsMap.get(elementId);
33428
+ if (!cachedItem) return;
33429
+ // 处理属性
33430
+ if (cachedItem.isAttibuteAction) {
33431
+ cachedItem.attrFunction(appID, lang);
33432
+ }
33433
+ // 处理innerHTML
33434
+ if (cachedItem.isScriptAction) {
33435
+ cachedItem.scriptFunction(appID, lang);
33436
+ } else {
33437
+ const oldValue = element.getAttribute("oldValue");
33438
+ if (oldValue) {
33439
+ // 创建正则表达式匹配所有 $L{...} 格式
33440
+ const regex = /\$L\{([^}]+)\}/g;
33441
+ // 替换所有 $L{...} 占位符为翻译文本
33442
+ let newValue = oldValue;
33443
+ let match;
33444
+ while ((match = regex.exec(oldValue)) !== null) {
33445
+ const fullMatch = match[0];
33446
+ const placeholderKey = match[1];
33447
+ const translation = i18n(placeholderKey, appID, lang);
33448
+ newValue = newValue.replace(fullMatch, translation);
33449
+ }
33450
+ (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.nextTick)(() => {
33451
+ // 更新元素的innerHTML
33452
+ element.innerHTML = newValue;
33805
33453
  });
33806
33454
  }
33455
+ }
33456
+ };
33457
+ const initDomNodeI18NObserver = () => {
33458
+ if (!window.i18nElementsMap) {
33459
+ window.i18nElementsMap = new Map();
33460
+ } else {
33461
+ window.i18nElementsMap.clear();
33462
+ }
33463
+ registerEventListener("IPORTAL_LANGUAGE_CHANGE_EVENT", async lang => {
33464
+ console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
33465
+ // 遍历Map,更新每个已处理元素的翻译
33466
+ for (const [elementId, item] of window.i18nElementsMap.entries()) {
33467
+ // console.log("更新元素翻译:", elementId, item.dom);
33468
+ applyTranslation(item.dom);
33469
+ }
33807
33470
  });
33808
- return results;
33809
- }
33810
- const calendar_i18n_check = element => {
33811
- const checkResult = {
33812
- result: false,
33813
- innerHTMLMatch: null
33471
+ // 创建观察器实例
33472
+ const observer = new MutationObserver(mutations => {
33473
+ mutations.forEach(mutation => {
33474
+ if (mutation.type === 'childList') {
33475
+ // 节点添加
33476
+ if (mutation.addedNodes.length > 0) {
33477
+ for (let i = 0; i < mutation.addedNodes.length; i++) {
33478
+ let node = mutation.addedNodes[i];
33479
+ // console.log(`处理新增节点:`,node);
33480
+ if (node.nodeType === Node.TEXT_NODE) {
33481
+ node = node.parentNode;
33482
+ }
33483
+ processElement(node);
33484
+ }
33485
+ }
33486
+ // 节点移除
33487
+ if (mutation.removedNodes.length > 0) {
33488
+ for (let i = 0; i < mutation.removedNodes.length; i++) {
33489
+ let node = mutation.removedNodes[i];
33490
+ // console.log(`处理移除节点:`,node);
33491
+ unProcessElement(node);
33492
+ }
33493
+ }
33494
+ } else if (mutation.type === 'characterData') {
33495
+ // 处理文本变化
33496
+ const oldValue = mutation.oldValue;
33497
+ const targetNode = mutation.target;
33498
+ const newValue = targetNode.data;
33499
+ // 创建日志条目并显示
33500
+ console.log(`文本修改: ${oldValue} → ${newValue}`);
33501
+ const parentElement = targetNode.parentNode;
33502
+ if (parentElement) {
33503
+ let localDomID = parentElement.getAttribute("localDomID");
33504
+ // 如果有localDomID,说明之前处理过,先移除缓存
33505
+ if (localDomID) {
33506
+ unProcessElement(parentElement);
33507
+ }
33508
+ }
33509
+ processElement(parentElement);
33510
+ }
33511
+ });
33512
+ });
33513
+
33514
+ // 配置观察选项
33515
+ const config = {
33516
+ childList: true,
33517
+ // 观察子节点变化
33518
+ subtree: true,
33519
+ // 观察所有后代节点
33520
+ attributes: false,
33521
+ // 不观察属性变化
33522
+ characterData: true,
33523
+ // 不观察文本内容变化
33524
+ characterDataOldValue: true
33814
33525
  };
33815
- const classes = element.classList;
33816
- if (!classes) {
33817
- return checkResult;
33818
- }
33819
- // 检查日历标题
33820
- if (classes.contains("fc-toolbar-title")) {
33821
- let scriptFunction = (appID, lang) => {
33822
- let oldValue = element.getAttribute("oldValue");
33823
- let yearMonthList = extractYearMonth(oldValue);
33824
- if (yearMonthList.length > 0) {
33825
- let yearMonth = yearMonthList[0];
33826
- let year = yearMonth.year;
33827
- let month = yearMonth.month;
33828
- let newInnerHTML = `${year}/${month}`;
33829
- let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33830
- if (lang === "zh-CN") {
33831
- newInnerHTML = `${year}年${month}月`;
33526
+ // 开始观察目标节点
33527
+ const targetNode = document.body;
33528
+ processElement(targetNode);
33529
+ observer.observe(targetNode, config);
33530
+ };
33531
+ const initDomNodeViewObserver = () => {
33532
+ // 创建观察器实例
33533
+ const observer = new MutationObserver(mutations => {
33534
+ mutations.forEach(mutation => {
33535
+ if (mutation.type === 'childList') {
33536
+ // 节点添加
33537
+ if (mutation.addedNodes.length > 0) {
33538
+ for (let i = 0; i < mutation.addedNodes.length; i++) {
33539
+ let node = mutation.addedNodes[i];
33540
+ processViewElement(node);
33541
+ }
33832
33542
  }
33833
- element.innerHTML = newInnerHTML;
33834
33543
  }
33835
- };
33836
- let innerHTML = element.innerHTML;
33837
- let testRule = /^\d{4}年(0?[1-9]|1[0-2])月$/;
33838
- if (testRule.test(innerHTML)) {
33839
- // console.log("检查smardaten平台日历标题 元素:",innerHTML);
33840
- let tempHTMLMatch = {
33841
- oldValue: innerHTML,
33842
- isScriptAction: true,
33843
- scriptFunction: scriptFunction
33844
- };
33845
- checkResult.result = true;
33846
- checkResult.innerHTMLMatch = tempHTMLMatch;
33847
- return checkResult;
33848
- }
33544
+ });
33545
+ });
33546
+
33547
+ // 配置观察选项
33548
+ const config = {
33549
+ childList: true,
33550
+ // 观察子节点变化
33551
+ subtree: true,
33552
+ // 观察所有后代节点
33553
+ attributes: false,
33554
+ // 不观察属性变化
33555
+ characterData: true,
33556
+ // 不观察文本内容变化
33557
+ characterDataOldValue: true
33558
+ };
33559
+ // 开始观察目标节点
33560
+ const targetNode = document.body;
33561
+ processViewElement(targetNode);
33562
+ observer.observe(targetNode, config);
33563
+ };
33564
+
33565
+ // 处理单个DOM元素的函数
33566
+ function processViewElement(element) {
33567
+ if (!element) {
33568
+ return false;
33849
33569
  }
33850
- // 检查日历今天按钮
33851
- if (classes.contains("fc-today-button")) {
33852
- let innerHTML = element.innerHTML;
33853
- if (innerHTML.includes("今天") || innerHTML.includes("today")) {
33854
- // console.log("检查smardaten平台日历 今天 元素:",innerHTML);
33855
- let tempHTMLMatch = {
33856
- oldValue: '$L{今天}'
33857
- };
33858
- checkResult.result = true;
33859
- checkResult.innerHTMLMatch = tempHTMLMatch;
33860
- return checkResult;
33861
- }
33570
+ // 仅处理元素节点
33571
+ if (element && element.nodeType !== Node.ELEMENT_NODE) {
33572
+ return false;
33862
33573
  }
33863
- // 检查日历标题
33864
- if (classes.contains("fullCalendar_title_value")) {
33865
- let innerHTML = element.innerHTML;
33866
- const regex = /周[一二三四五六日]/;
33867
- const regex_en = /^(mon(day)?s?\.?|tue(sday)?s?\.?|wed(nesday)?s?\.?|thu(r(sday)?)?s?\.?|fri(day)?s?\.?|sat(urday)?s?\.?|sun(day)?s?\.?)$/i;
33868
- let match = innerHTML.match(regex);
33869
- if (match) {
33870
- // console.log("检查smardaten平台日历 周 元素:",innerHTML);
33871
- let day = match[0];
33872
- let tempHTMLMatch = {
33873
- oldValue: `$L{${day}}`
33874
- };
33875
- checkResult.result = true;
33876
- checkResult.innerHTMLMatch = tempHTMLMatch;
33877
- return checkResult;
33878
- }
33879
- match = innerHTML.match(regex_en);
33880
- if (match) {
33881
- // console.log("检查smardaten平台日历 周 元素:",innerHTML);
33882
- let day = match[0];
33883
- let tempHTMLMatch = {
33884
- oldValue: `$L{${convertToChineseWeekday(day)}}`
33885
- };
33886
- checkResult.result = true;
33887
- checkResult.innerHTMLMatch = tempHTMLMatch;
33888
- return checkResult;
33574
+ // 如果元素有子元素,则不处理innerHTML
33575
+ const hasChildren = hasChildElements(element);
33576
+ if (hasChildren) {
33577
+ let children = element.children;
33578
+ for (let i = 0; i < children.length; i++) {
33579
+ let child = children[i];
33580
+ processViewElement(child);
33889
33581
  }
33890
33582
  }
33891
- //日期单元格
33892
- if (classes.contains("fc-daygrid-day-number")) {
33893
- let scriptFunction = (appID, lang) => {
33894
- let oldValue = element.getAttribute("oldValue");
33895
- let result = extractDayNumbers(oldValue);
33896
- if (result && result.length > 0) {
33897
- let day = result[0];
33898
- let newInnerHTML = `${day}`;
33899
- let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33900
- if (lang === "zh-CN") {
33901
- newInnerHTML = `${day}日`;
33902
- }
33903
- element.innerHTML = newInnerHTML;
33904
- }
33583
+ let checkState = element.getAttribute("viewDomID");
33584
+ // 已经处理过的元素跳过
33585
+ if (checkState) {
33586
+ return false;
33587
+ }
33588
+ const viewCheckResult = commom_view_check(element);
33589
+ // 如果没有匹配的内容,则不处理
33590
+ if (!viewCheckResult.result) {
33591
+ return false;
33592
+ }
33593
+ viewCheckResult.scriptFunction();
33594
+ return true;
33595
+ }
33596
+ ;// ./src/api/security.js
33597
+
33598
+
33599
+
33600
+
33601
+
33602
+
33603
+ /**
33604
+ *
33605
+ * @returns 获取登录验证码图片
33606
+ */
33607
+ const getAuthPic = () => request.get(`/system/authority/getAuthPic?module=loginPassword`, {
33608
+ responseType: "arraybuffer"
33609
+ });
33610
+
33611
+ /**
33612
+ * 登出账号
33613
+ * @param endside_type 0: web 1:手机
33614
+ * @returns {Promise<*>}
33615
+ * @param endside_type 0: web 1:手机
33616
+ *
33617
+ */
33618
+ const logoutAccount = async endside_type => {
33619
+ let resultData = await request.get(`/system/authority/logout?isMobileLogout=${endside_type}`);
33620
+ let response = JSON.parse(resultData.request.response);
33621
+ let resultCode = response.code;
33622
+ if (resultCode == "10110020") {
33623
+ window.sessionStorage.clear();
33624
+ return {
33625
+ code: resultCode,
33626
+ message: i18nText(response.message)
33905
33627
  };
33906
- let innerHTML = element.innerHTML;
33907
- let match = extractDayNumbers(innerHTML);
33908
- if (match.length > 0) {
33909
- // console.log("检查smardaten平台日历 日 元素:",innerHTML);
33910
- let tempHTMLMatch = {
33911
- oldValue: innerHTML,
33912
- isScriptAction: true,
33913
- scriptFunction: scriptFunction
33914
- };
33915
- checkResult.result = true;
33916
- checkResult.innerHTMLMatch = tempHTMLMatch;
33917
- return checkResult;
33918
- }
33919
- }
33920
- // 日历更多按钮
33921
- if (classes.contains("fc-daygrid-more-link")) {
33922
- let scriptFunction = (appID, lang) => {
33923
- let oldValue = element.getAttribute("oldValue");
33924
- let result = extractNumbersFromScenarios(oldValue);
33925
- if (result && result.length > 0) {
33926
- let day = result[0]["number"];
33927
- let newInnerHTML = "另外${X}条数据";
33928
- newInnerHTML = i18n(newInnerHTML, appID, lang);
33929
- newInnerHTML = newInnerHTML.replace("${X}", day);
33930
- element.innerHTML = newInnerHTML;
33931
- }
33628
+ } else {
33629
+ return {
33630
+ code: resultCode,
33631
+ message: i18nText(response.message)
33932
33632
  };
33933
- let innerHTML = element.innerHTML;
33934
- let match = extractNumbersFromScenarios(innerHTML);
33935
- if (match.length > 0) {
33936
- // console.log("检查smardaten平台日历 更多 元素:",innerHTML);
33937
- let tempHTMLMatch = {
33938
- oldValue: innerHTML,
33939
- isScriptAction: true,
33940
- scriptFunction: scriptFunction
33941
- };
33942
- checkResult.result = true;
33943
- checkResult.innerHTMLMatch = tempHTMLMatch;
33944
- return checkResult;
33945
- }
33946
33633
  }
33947
- // 日历弹窗标题
33948
- if (classes.contains("fc-popover-title")) {
33949
- // 正则表达式匹配中文日期格式
33950
- const regex = /(\d{4})年(\d{1,2})月(\d{1,2})日/g;
33951
- let scriptFunction = (appID, lang) => {
33952
- let oldValue = element.getAttribute("oldValue");
33953
- let match = oldValue.match(regex);
33954
- if (match) {
33955
- // 替换函数
33956
- const convertedText = oldValue.replace(regex, function (match, year, month, day) {
33957
- // 格式化月份和日期为两位数
33958
- const formattedMonth = month.padStart(2, '0');
33959
- const formattedDay = day.padStart(2, '0');
33960
- let result = `${year}/${formattedMonth}/${formattedDay}`;
33961
- let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
33962
- if (lang === "zh-CN") {
33963
- result = `${year}年${formattedMonth}月${formattedDay}日`;
33964
- }
33965
- // 返回新格式的日期
33966
- return result;
33967
- });
33968
- element.innerHTML = convertedText;
33969
- }
33634
+ };
33635
+
33636
+ /**
33637
+ * 解密
33638
+ */
33639
+ const decrypt = async decryptStr => {
33640
+ let secretKey = await getKey();
33641
+ const decrypted = crypto_js_default().AES.decrypt(decryptStr, secretKey).toString((crypto_js_default()).enc.Utf8);
33642
+ return decrypted;
33643
+ };
33644
+
33645
+ /**
33646
+ * 解密
33647
+ */
33648
+ const encrypt = async decryptStr => {
33649
+ let secretKey = await getKey();
33650
+ const encrypted = crypto_js_default().AES.encrypt(decryptStr, secretKey).toString();
33651
+ return encrypted;
33652
+ };
33653
+
33654
+ /**
33655
+ * 切换门户登录
33656
+ */
33657
+ const switchPortalLogin = async (data, appid, endside_type) => {
33658
+ let old_key = window.sessionStorage.getItem("iportal_login_user_key");
33659
+ old_key = await decrypt(old_key);
33660
+ data.password = old_key;
33661
+ let resultData = await logoutAccount(endside_type);
33662
+ let resultCode = resultData.code;
33663
+ let message = resultData.message;
33664
+ //退出登录成功
33665
+ if (resultCode == "10110020") {
33666
+ let loginResult = await loginAccount(data, appid);
33667
+ return loginResult;
33668
+ } else {
33669
+ return {
33670
+ code: resultCode,
33671
+ message: i18nText(message)
33970
33672
  };
33971
- let innerHTML = element.innerHTML;
33972
- let match = innerHTML.match(regex);
33973
- if (match && match.length > 0) {
33974
- // console.log("检查smardaten平台日历 日 元素:",innerHTML);
33975
- let tempHTMLMatch = {
33976
- oldValue: innerHTML,
33977
- isScriptAction: true,
33978
- scriptFunction: scriptFunction
33979
- };
33980
- checkResult.result = true;
33981
- checkResult.innerHTMLMatch = tempHTMLMatch;
33982
- return checkResult;
33983
- }
33984
33673
  }
33985
- return checkResult;
33986
33674
  };
33987
- ;// ./src/api/i18n/smardaten_i18n/dialog_i18n.js
33988
- const dialog_i18n_check = element => {
33989
- const checkResult = {
33990
- result: false,
33991
- innerHTMLMatch: null
33992
- };
33993
- const classes = element.classList;
33994
- if (!classes) {
33995
- return checkResult;
33996
- }
33997
- let innerHTML = element.innerHTML;
33998
- let oldValue = element.getAttribute("oldValue");
33999
- if (!oldValue) {
34000
- oldValue = innerHTML;
34001
- }
34002
- // 检查删除确认对话框按钮 取消 确认
34003
- if (classes.contains("ant-modal-title")) {
34004
- let innerHTML = element.innerHTML;
34005
- if (innerHTML.includes("Select Data") || innerHTML.includes("选择数据")) {
34006
- // console.log("检查smardaten平台 Tip提问取消删除按钮:",innerHTML);
34007
- let tempHTMLMatch = {
34008
- oldValue: '$L{选择数据}'
34009
- };
34010
- checkResult.result = true;
34011
- checkResult.innerHTMLMatch = tempHTMLMatch;
34012
- return checkResult;
33675
+ const getUserID = async (acccountName, old_key, group_id) => {
33676
+ let queryData = {
33677
+ param: {
33678
+ accountName: acccountName,
33679
+ group_id: group_id,
33680
+ account_key: old_key
34013
33681
  }
34014
- }
34015
- return checkResult;
34016
- };
34017
- ;// ./src/api/i18n/commom_view.js
34018
- const commom_view_check = element => {
34019
- const checkResult = {
34020
- result: false
34021
33682
  };
34022
- const classes = element.classList;
34023
- if (!classes) {
34024
- return checkResult;
34025
- }
34026
- // 处理容器节点
34027
- if (element.tagName === "DIV" && classes.contains("template-block")) {
34028
- let scriptFunction = (appID, lang) => {
34029
- let divDom = element.parentNode;
34030
- let divDom2;
34031
- let appBlockDom;
34032
- let comDom;
34033
- let renderDom;
34034
- if (divDom && divDom.tagName === "DIV") {
34035
- divDom2 = divDom.parentNode;
34036
- if (divDom2 && divDom2.tagName === "DIV") {
34037
- appBlockDom = divDom2.parentNode;
34038
- if (appBlockDom && appBlockDom.tagName === "DIV" && appBlockDom.classList.contains("application-block")) {
34039
- comDom = appBlockDom.parentNode;
34040
- if (comDom && comDom.tagName === "DIV" && comDom.classList.contains("componentDiv")) {
34041
- renderDom = comDom.parentNode;
34042
- if (renderDom && renderDom.tagName === "DIV" && renderDom.classList.contains("render-all-blocks")) {
34043
- //隐藏整个组件
34044
- renderDom.style.height = "100%";
34045
- comDom.style.height = "100%";
34046
- appBlockDom.style.height = "100%";
34047
- divDom2.style.height = "100%";
34048
- divDom.style.height = "100%";
34049
- element.style.height = "100%";
34050
- //标记已经处理过
34051
- element.setAttribute("viewDomID", generateUniqueId());
34052
- }
34053
- }
34054
- }
34055
- }
33683
+ let result = await request.post(`/dataservice/rest/orchestration/getUserID`, queryData);
33684
+ let persion_id = result.data.persion_id;
33685
+ return persion_id;
33686
+ };
33687
+
33688
+ /**
33689
+ * 登录账号
33690
+ * @param data 登录数据
33691
+ * @param appid 应用ID
33692
+ *
33693
+ * @description
33694
+ * 登录时需要传入验证码(authPicCode)和应用ID(dataappId),
33695
+ * mobileOrWeb参数用于区分是移动端还是网页端登录。
33696
+ *
33697
+ * @returns
33698
+ */
33699
+ const loginAccount = async (data, appid) => {
33700
+ let result = await getLoginPortalAccountKey(data.account_view, data.groupid);
33701
+ let code = result.data.code;
33702
+ //获取key成功
33703
+ if (code == 10001) {
33704
+ //保存的真正一级密码
33705
+ let pwd_code = result.data.codeData.key;
33706
+ //缓存一级密码
33707
+ let old_key = pwd_code;
33708
+ //保存的正则2级密码
33709
+ let key_code = result.data.codeData.code;
33710
+ //反向解析一级密码
33711
+ pwd_code = await decrypt(pwd_code);
33712
+ //反向解析2级密码
33713
+ key_code = await decrypt(key_code);
33714
+ //密码匹配
33715
+ if (pwd_code == data.password) {
33716
+ //平台正向加密2级密码
33717
+ pwd_code = window.appSdk.Encrypt(key_code);
33718
+ data.password = pwd_code;
33719
+ result = await request.post(`/system/authority/loginAccount4Application?authPicCode=${data.imageCode}&dataappId=${appid}&mobileOrWeb=web`, data);
33720
+ let response = JSON.parse(result.request.response);
33721
+ code = response.code;
33722
+ //登录平台成功
33723
+ if (code == 10110004) {
33724
+ let id = await getUserID(data.account_view, old_key, data.groupid);
33725
+ // 初始化解析器
33726
+ const parser = new UAParser();
33727
+ // 获取浏览器信息
33728
+ const browser = parser.getBrowser();
33729
+ let timestamp = new Date().getTime();
33730
+ let clientID = browser.name + "_" + browser.version + "_" + timestamp;
33731
+ window.sessionStorage.setItem("iportal_login_user_id", id);
33732
+ window.sessionStorage.setItem("iportal_group_id", data.groupid);
33733
+ window.sessionStorage.setItem("iportal_login_user_key", old_key);
33734
+ window.sessionStorage.setItem("iportal_client_id", clientID);
33735
+ window.sessionStorage.setItem("iportal_app_id", appid);
33736
+ return {
33737
+ code: code
33738
+ };
33739
+ } else {
33740
+ return {
33741
+ code: code,
33742
+ message: i18nText(response.message)
33743
+ };
34056
33744
  }
34057
- };
34058
- checkResult.result = true;
34059
- checkResult.scriptFunction = scriptFunction;
34060
- return checkResult;
33745
+ } else {
33746
+ return {
33747
+ code: code,
33748
+ message: i18nText("账户密码错误")
33749
+ };
33750
+ }
34061
33751
  }
34062
- return checkResult;
33752
+ return {
33753
+ code: code,
33754
+ message: i18nText(result.data.message)
33755
+ };
34063
33756
  };
34064
- function generateUniqueId() {
34065
- return `rjview_${Date.now()}`;
34066
- }
34067
- ;// ./src/api/i18n/i18n.js
34068
33757
 
33758
+ /**
33759
+ * 获取密钥
33760
+ * @returns
33761
+ */
33762
+ const getKey = async () => {
33763
+ let queryData = {
33764
+ param: {}
33765
+ };
33766
+ let resultData = await request.post(`/dataservice/rest/orchestration/getKey`, queryData);
33767
+ let key = resultData.data.key;
33768
+ return key;
33769
+ };
33770
+ ;// ./src/api/utils.js
34069
33771
 
34070
33772
 
34071
33773
 
34072
33774
 
33775
+ /**
33776
+ * 查询资产
33777
+ * @param id 资产ID
33778
+ *
33779
+ */
33780
+ const queryAssetById = (id, count = 200) => request.post(`/asset/getAssetData?asset_id=${id}&count=${count}`, {
33781
+ filters: []
33782
+ });
34073
33783
 
33784
+ /**
33785
+ * 获取URL参数值
33786
+ * @param {} eventName
33787
+ * @param {*} actionFun
33788
+ */
33789
+ const getUrlParamValue = (urlStr, paramName) => {
33790
+ try {
33791
+ const url = new URL(urlStr);
33792
+ const value = url.searchParams.get(paramName);
33793
+ // 如果参数值包含#,则只返回#之前的部分
33794
+ if (value && value.indexOf("#") !== -1) {
33795
+ return value.split("#")[0];
33796
+ }
33797
+ return value;
33798
+ } catch (err) {
33799
+ console.error("URL 格式错误:", err);
33800
+ return "";
33801
+ }
33802
+ };
34074
33803
 
33804
+ /**
33805
+ * 通过 URL 创建 File 对象
33806
+ * @param {string} url - 文件的网络 URL
33807
+ * @param {string} [filename] - 自定义文件名(可选,不传则从 URL 提取)
33808
+ * @returns {Promise<File>} - 返回 Promise 解析为 File 对象
33809
+ */
33810
+ const createFileFromUrl = async (url, filename) => {
33811
+ try {
33812
+ // 1. 发起网络请求获取文件
33813
+ const response = await fetch(url);
33814
+ if (!response.ok) {
33815
+ throw new Error(`网络请求失败: ${response.status} ${response.statusText}`);
33816
+ }
34075
33817
 
33818
+ // 2. 将响应转换为 Blob(保留原始 MIME 类型)
33819
+ const blob = await response.blob();
34076
33820
 
33821
+ // 3. 确定文件名(若未自定义则从 URL 提取)
33822
+ const finalFilename = filename || extractFilenameFromUrl(url);
34077
33823
 
33824
+ // 4. 构造 File 对象(Blob + 文件名 + 类型)
33825
+ return new File([blob], finalFilename, {
33826
+ type: blob.type,
33827
+ // 使用 Blob 的 MIME 类型(如 image/png)
33828
+ lastModified: Date.now() // 可选:设置最后修改时间
33829
+ });
33830
+ } catch (error) {
33831
+ console.error("创建 File 失败:", error);
33832
+ throw error;
33833
+ }
33834
+ };
34078
33835
 
33836
+ /**
33837
+ * 从 URL 中提取文件名(如 https://example.com/path/image.png → image.png)
33838
+ * @param {string} url - 文件 URL
33839
+ * @returns {string} - 提取的文件名
33840
+ */
33841
+ const extractFilenameFromUrl = url => {
33842
+ try {
33843
+ const urlObj = new URL(url);
33844
+ // 从路径中获取最后一个部分(文件名)
33845
+ return urlObj.pathname.split("/").pop() || "downloaded_file";
33846
+ } catch (e) {
33847
+ return "downloaded_file"; // URL 解析失败时的默认文件名
33848
+ }
33849
+ };
34079
33850
 
33851
+ /**
33852
+ * 提取数组中不在另一个数组中的元素
33853
+ * @param {*} oldItems 基础比较数组
33854
+ * @param {*} newItems 被提取检测的数组
33855
+ * @returns
33856
+ */
33857
+ const extractNewItems = (oldItems, newItems) => {
33858
+ return oldItems.filter(item => !newItems.includes(item));
33859
+ };
34080
33860
 
34081
- const getLanguages = async appID => {
34082
- let queryData = {
34083
- param: {
34084
- appID: appID
34085
- }
34086
- };
34087
- let response = await request.post(`/dataservice/rest/orchestration/getAppLanguages`, queryData);
34088
- let resultDatas = response.data.resultDatas || [];
34089
- return resultDatas;
33861
+ /**
33862
+ * 获取远程文件大小(单位:字节)
33863
+ * @param {string} url - 文件的URL地址
33864
+ * @returns {Promise<number>} 文件大小(字节),失败时返回-1
33865
+ */
33866
+ const getFileSize = async url => {
33867
+ try {
33868
+ // 发送HEAD请求(不下载文件内容)
33869
+ const response = await fetch(url, {
33870
+ method: "GET",
33871
+ headers: {
33872
+ Range: "bytes=0-0"
33873
+ } // 仅请求第 1 个字节
33874
+ });
33875
+ if (response.status !== 206) throw new Error("不支持 Range 请求");
33876
+ const contentRange = response.headers.get("Content-Range");
33877
+ const totalSize = contentRange?.match(/\/(\d+)$/)?.[1]; // 解析总大小(如 "bytes 0-0/1000" → 1000)
33878
+ return totalSize ? parseInt(totalSize, 10) : -1;
33879
+ } catch (error) {
33880
+ console.error("获取文件大小失败:", error);
33881
+ return -1; // 返回-1表示失败
33882
+ }
34090
33883
  };
34091
- const i18n = (key, appID, localID) => {
34092
- let result = window.customI18nObject?.get(`${appID}-${key}-${localID}`) || key;
34093
- return result;
33884
+ // 获取i18n key
33885
+ const getI18nKey = text => {
33886
+ // 正则表达式匹配 $L{...} 格式
33887
+ const regex = /\$L\{([^}]+)\}/g;
33888
+ let match = regex.exec(text);
33889
+ if (!match) return text;
33890
+ let key = match[1];
33891
+ return key;
34094
33892
  };
34095
- const loadi18nTexts = async appID => {
34096
- let queryData = {
34097
- param: {
34098
- appID: appID
33893
+
33894
+ // 查找最近的具有指定 class 的祖先节点
33895
+ const findClosestAncestorByClass = (element, className) => {
33896
+ let currentElement = element;
33897
+ while (currentElement) {
33898
+ // 检查当前元素是否包含目标 class
33899
+ if (currentElement.classList && currentElement.classList.contains(className)) {
33900
+ return currentElement;
34099
33901
  }
34100
- };
34101
- let response = await request.post(`/dataservice/rest/orchestration/getAllTexts`, queryData);
34102
- let resultDatas = response.data.resultDatas || [];
34103
- window.customI18nObject = new Map();
34104
- for (let item of resultDatas) {
34105
- window.customI18nObject.set(`${appID}-${item.key}-${item.lang}`, item.value);
33902
+ // 向上遍历父节点
33903
+ currentElement = currentElement.parentElement;
34106
33904
  }
33905
+ // 未找到匹配的祖先节点
33906
+ return null;
34107
33907
  };
33908
+ // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.some.js
33909
+ var es_iterator_some = __webpack_require__(3579);
33910
+ ;// ./src/api/iframe.js
34108
33911
 
34109
- /**
34110
- * 检查元素是否有子DOM元素
34111
- * @param {HTMLElement} element - 要检查的DOM元素
34112
- * @returns {boolean} - 是否有子元素
34113
- */
34114
- function hasChildElements(element) {
34115
- return element && element.children?.length > 0;
34116
- }
34117
33912
 
34118
- /**
34119
- * 检查文本是否匹配$L{...}格式
34120
- * @param {string} text - 要检查的文本
34121
- * @returns {Object|null} - 匹配结果或null
34122
- */
34123
- function checkTextFormat(text) {
34124
- if (!text) return null;
34125
- const regex = /\$L\{([^}]+)\}/;
34126
- const match = text.match(regex);
34127
- if (match) {
34128
- return {
34129
- fullMatch: match[0],
34130
- key: match[1]
34131
- };
34132
- }
34133
- return null;
34134
- }
34135
- function i18n_generateUniqueId() {
34136
- window.idCounter = window.idCounter || 0;
34137
- return `i18n_${Date.now()}_${window.idCounter++}`;
34138
- }
34139
33913
 
34140
- /**
34141
- * 检查平台特定元素并返回匹配结果
34142
- * @param {*} element
34143
- * @returns
34144
- */
34145
- function checkPlatformElementContent(element) {
34146
- const checkContentResult = {
34147
- result: false,
34148
- innerHTMLMatch: null
34149
- };
34150
- let checkArr = [check, catalog_i18n_check, calendar_i18n_check, dialog_i18n_check, common_i18n_check];
34151
- for (let i = 0; i < checkArr.length; i++) {
34152
- let checkFunc = checkArr[i];
34153
- let checkContentResult = checkFunc(element);
34154
- if (checkContentResult.result) {
34155
- return checkContentResult;
34156
- }
34157
- }
34158
- return checkContentResult;
34159
- }
34160
- function processElement(element) {
34161
- if (!element) {
34162
- return false;
34163
- }
33914
+ const addWindowTrustedOrigin = origin => {
33915
+ let SDATA_WINDOW_TRUSTED_ORIGINS = window.SDATA_WINDOW_TRUSTED_ORIGINS;
33916
+ if (!SDATA_WINDOW_TRUSTED_ORIGINS) window.SDATA_WINDOW_TRUSTED_ORIGINS = [];
33917
+ if (!SDATA_WINDOW_TRUSTED_ORIGINS.includes(origin)) {
33918
+ SDATA_WINDOW_TRUSTED_ORIGINS.push(origin);
33919
+ }
33920
+ };
33921
+ const removeWindowTrustedOrigin = origin => {
33922
+ let SDATA_WINDOW_TRUSTED_ORIGINS = window.SDATA_WINDOW_TRUSTED_ORIGINS;
33923
+ if (!SDATA_WINDOW_TRUSTED_ORIGINS) window.SDATA_WINDOW_TRUSTED_ORIGINS = [];
33924
+ let index = SDATA_WINDOW_TRUSTED_ORIGINS.indexOf(origin); // 查找元素在数组中的索引
33925
+ if (index > -1) {
33926
+ SDATA_WINDOW_TRUSTED_ORIGINS.splice(index, 1); // 删除元素
33927
+ }
33928
+ };
33929
+ const addEventAction = (eventKey, eventAction) => {
33930
+ let sdataEventActions = window.sdataEventActions;
33931
+ if (!sdataEventActions) window.sdataEventActions = {};
33932
+ window.sdataEventActions[eventKey] = eventAction;
33933
+ };
33934
+ const removeEventAction = eventKey => {
33935
+ let sdataEventActions = window.sdataEventActions;
33936
+ if (!sdataEventActions) window.sdataEventActions = {};
33937
+ delete window.sdataEventActions[eventKey];
33938
+ };
33939
+ const initFrameWindowListener = () => {
33940
+ if (window.isFrameWindowInited) return;
33941
+ let SDATA_WINDOW_TRUSTED_ORIGINS = window.SDATA_WINDOW_TRUSTED_ORIGINS;
33942
+ if (!SDATA_WINDOW_TRUSTED_ORIGINS) window.SDATA_WINDOW_TRUSTED_ORIGINS = [];
33943
+ let sdataEventActions = window.sdataEventActions;
33944
+ if (!sdataEventActions) window.sdataEventActions = {};
33945
+ // 监听主页面的消息
33946
+ window.addEventListener("message", async event => {
33947
+ // 步骤1:验证来源是否在白名单中
33948
+ const isTrusted = window.SDATA_WINDOW_TRUSTED_ORIGINS.some(origin => event.origin === origin || new RegExp(origin).test(event.origin));
33949
+ if (!isTrusted) {
33950
+ console.log("拒绝非可信源消息:", event.origin);
33951
+ return; // 直接终止处理
33952
+ }
33953
+ let eventKey = event.data?.eventKey;
33954
+ if (!eventKey) return;
33955
+ let eventSourceKey = event.origin;
33956
+ console.log(`收到${eventSourceKey}页面消息:`, event.data);
33957
+ if (eventKey === "sdata_alllife_event_response") {
33958
+ let eventOperateKey = event.data.eventOperateKey;
33959
+ let eventAction = window.sdataEventActions[eventOperateKey];
33960
+ //删除缓存方法
33961
+ delete window.sdataEventActions[eventOperateKey];
33962
+ if (eventAction) await eventAction(event.data.data, event);
33963
+ } else {
33964
+ let eventAction = window.sdataEventActions[eventKey];
33965
+ let responseData = {
33966
+ eventKey: "sdata_alllife_event_response",
33967
+ eventOperateKey: event.data.eventOperateKey,
33968
+ data: {}
33969
+ };
33970
+ if (eventAction) {
33971
+ let resultData = await eventAction(event.data.data, event);
33972
+ responseData.data = resultData;
33973
+ }
33974
+ event.source.postMessage(responseData, eventSourceKey);
33975
+ }
33976
+ });
33977
+ window.isFrameWindowInited = true;
33978
+ };
33979
+ const sendWindowMessage = async (targetWindow, originKey, eventKey, data, callback) => {
33980
+ let timestamp = new Date().getTime();
33981
+ let randomNum = Math.floor(Math.random() * 10000) + 1;
33982
+ let eventOperateKey = `${eventKey}_${timestamp}_${randomNum}`;
33983
+ addEventAction(eventOperateKey, callback);
33984
+ let postData = {
33985
+ eventOperateKey: eventOperateKey,
33986
+ eventKey: eventKey,
33987
+ data: data
33988
+ };
33989
+ targetWindow.postMessage(postData, originKey);
33990
+ };
33991
+ ;// ./src/api/chat/ChatClientMgr.js
33992
+
33993
+
34164
33994
 
34165
- // 仅处理元素节点
34166
- if (element && element.nodeType !== Node.ELEMENT_NODE) {
34167
- return false;
33995
+ class ChatClientMgr {
33996
+ constructor(params, handler) {
33997
+ this.handler = handler;
33998
+ this.actionKey = params.actionKey;
33999
+ this.appSKID = params.appSKID;
34000
+ this.imType = params.imType;
34001
+ this.groupID = params.groupID;
34002
+ this.userID = params.userID;
34003
+ this.chatType = params.chatType || 0;
34004
+ this.singleChatID = params.singleChatID || "";
34005
+ this.customParams = params.customParams || {};
34006
+ this.chartOrigin = params.chartOrigin;
34007
+ // console.log("ChatClientMgr init:", this.actionKey);
34168
34008
  }
34169
-
34170
- // 如果元素有子元素,递归处理子元素
34171
- const hasChildren = hasChildElements(element);
34172
- if (hasChildren) {
34173
- let children = element.children;
34174
- for (let i = 0; i < children.length; i++) {
34175
- let child = children[i];
34176
- if (child.nodeType === Node.ELEMENT_NODE) {
34177
- let childLocalDomID = child.getAttribute("localDomID");
34178
- // 如果子元素有localDomID但不在缓存中,移除localDomID属性
34179
- if (childLocalDomID && window.i18nElementsMap && !window.i18nElementsMap.has(childLocalDomID)) {
34180
- unProcessElement(child);
34181
- }
34009
+ makeKey(key) {
34010
+ return `${key}-${this.actionKey}`;
34011
+ }
34012
+ async init() {
34013
+ this.handler.addChatListener(this.makeKey(`sdata_get_access_token`), async data => {
34014
+ return await this.handler.getPortalAccessToken(data);
34015
+ });
34016
+ this.handler.addChatListener(this.makeKey(`sdata_get_portal_user_info`), async data => {
34017
+ return await this.handler.getPortalUserInfo(data);
34018
+ });
34019
+ this.handler.addChatListener(this.makeKey(`sdata_get_portal_user_sig`), async data => {
34020
+ let userID = data.userID;
34021
+ let platType = data.im_type;
34022
+ let groupID = data.group_id;
34023
+ return await this.handler.getPortalUserSig(userID, platType, groupID);
34024
+ });
34025
+ this.handler.addChatListener(this.makeKey(`sdata_add_im_mapping`), async data => {
34026
+ let userID = data.userID;
34027
+ let platType = data.im_type;
34028
+ let userSig = data.userSig;
34029
+ return await this.handler.addIMMapping(userID, platType, userSig, this.groupID);
34030
+ });
34031
+ this.handler.addChatListener(this.makeKey(`sdata_update_im_mapping`), async data => {
34032
+ return await this.handler.updateIMMapping(data);
34033
+ });
34034
+ this.handler.addChatListener(this.makeKey(`sdata_get_users_by_group_id`), async data => {
34035
+ return await this.handler.getAllUserInfosByGroupID(data);
34036
+ });
34037
+ this.handler.addChatListener(this.makeKey(`sdata_get_dpts_by_group_id`), async data => {
34038
+ return await this.handler.getChildrenOfficeInfosByID(data);
34039
+ });
34040
+ this.handler.addChatListener(this.makeKey(`sdata_get_project_dpts_by_user_group_id`), async data => {
34041
+ return await this.handler.getPojectDptsByUserAndGroupID(data);
34042
+ });
34043
+ this.handler.addChatListener(this.makeKey(`sdata_get_ai_robot_infos`), async data => {
34044
+ let groupID = data.groupID;
34045
+ let userID = data.userID;
34046
+ if (this.userID == userID && this.groupID == groupID) {
34047
+ return this.getAIRobotInfos();
34182
34048
  }
34183
- processElement(children[i]);
34184
- }
34049
+ return [];
34050
+ });
34051
+ this.handler.addChatListener(this.makeKey(`sdata_get_test_user_sig`), async data => {
34052
+ let sdkAppID = data.SDKAppID;
34053
+ let userID = data.userID;
34054
+ let sigIDObject = await this.handler.genTestUserSig({
34055
+ SDKAppID: sdkAppID,
34056
+ userID: userID
34057
+ });
34058
+ let sigID = sigIDObject.userSig;
34059
+ return sigID;
34060
+ });
34061
+ this.handler.addChatListener(this.makeKey(`sdata_send_message_to_chat_server`), async (data, event) => {
34062
+ let message = data.message;
34063
+ let robotID = message.from;
34064
+ let result = await this.sendMessageToChatServer(robotID, message);
34065
+ return result;
34066
+ });
34067
+ this.handler.addChatListener(this.makeKey(`sdata_close_frame_window`), async (data, event) => {
34068
+ return this.handler.closeWindow();
34069
+ });
34070
+ this.handler.addChatListener(this.makeKey(`sdata_get_portal_doc_info`), async (data, event) => {
34071
+ return this.handler.getPortalDocmentInfo(data);
34072
+ });
34073
+ this.handler.addChatListener(this.makeKey(`sdata_chat_aiAgent_event`), async (data, event) => {
34074
+ return this.handler.onAIAgentEvent(data, event);
34075
+ });
34076
+ this.handler.addChatListener(this.makeKey(`sdata_alllife_event_regist`), async (data, event) => {
34077
+ console.log("recive chat regist event data:", data);
34078
+ this.appSKID = data.appid;
34079
+ this.imType = data.im_type;
34080
+ await this.initChatAIs();
34081
+ let charParams = {
34082
+ type: this.getChatTypeKey(this.chatType),
34083
+ singleChatID: this.singleChatID,
34084
+ customParams: this.customParams
34085
+ };
34086
+ this.handler.fireEventToChatWindow(event, this.chartOrigin, this.makeKey("sdata_alllife_initChat"), charParams, result => {
34087
+ if (result) {
34088
+ console.log("chat init finished:", result);
34089
+ this.handler.onChatInitFinished();
34090
+ }
34091
+ });
34092
+ });
34185
34093
  }
34186
-
34187
- // 检查innerHTML是否匹配(仅对没有子元素的元素)
34188
- let innerHTMLMatch = null;
34189
- const attrCheckResult = attribute_i18n_check(element);
34190
- if (attrCheckResult.result) {
34191
- console.log("检查到属性匹配元素:", element);
34094
+ getChatTypeKey(type) {
34095
+ switch (type) {
34096
+ case 0:
34097
+ return "IM_MULTIPLE_MODE";
34098
+ case 1:
34099
+ return "IM_SINGLE_MODE";
34100
+ case 2:
34101
+ return "IM_EMBED_MODE";
34102
+ case 3:
34103
+ return "IM_MOBILE_MULTIPLE_EMBED_MODE";
34104
+ case 4:
34105
+ return "IM_MOBILE_SINGLE_EMBED_MODE";
34106
+ default:
34107
+ return "IM_MULTIPLE_MODE";
34108
+ }
34192
34109
  }
34193
-
34194
- //检查是否是smardaten平台元素
34195
- const checkContentResult = checkPlatformElementContent(element);
34196
- if (checkContentResult.result) {
34197
- innerHTMLMatch = checkContentResult.innerHTMLMatch;
34198
- element.setAttribute("oldValue", innerHTMLMatch.oldValue);
34199
- } else {
34200
- if (!hasChildren) {
34201
- //如果存在历史值,说明之前解析过,有可能是值需要刷新触发
34202
- let newValue = element.innerHTML;
34203
- let newMatch = checkTextFormat(newValue);
34204
- if (newMatch) {
34205
- innerHTMLMatch = newMatch;
34206
- } else {
34207
- newValue = element.getAttribute("oldValue");
34208
- if (!newValue) {
34209
- newValue = element.innerHTML;
34110
+ async initChatAIs() {
34111
+ if (window.imClient) {
34112
+ this.chatAIClient = window.imClient;
34113
+ } else {
34114
+ let classDatas = await this.handler.getChatClientClasses();
34115
+ const {
34116
+ TencentCloudChat,
34117
+ TIMUploadPlugin
34118
+ } = classDatas;
34119
+ window.imClient = TencentCloudChat.create({
34120
+ SDKAppID: this.appSKID,
34121
+ // 替换为你的 SDKAppID
34122
+ storage: {
34123
+ enable: true // 启用存储(可选,根据需求)
34210
34124
  }
34211
- innerHTMLMatch = checkTextFormat(newValue);
34212
- }
34213
- if (innerHTMLMatch) {
34214
- // console.log("检查到innerHTML匹配元素:",element);
34215
- element.setAttribute("oldValue", newValue);
34216
- }
34125
+ });
34126
+ window.imClient.registerPlugin({
34127
+ "tim-upload-plugin": TIMUploadPlugin
34128
+ });
34129
+ window.imClient.on(TencentCloudChat.EVENT.SDK_READY, this.onChatAIReady.bind(this));
34130
+ window.imClient.charAIs = {};
34131
+ this.chatAIClient = window.imClient;
34132
+ }
34133
+ if (!this.chatAIClient.charAIs) {
34134
+ this.chatAIClient.charAIs = {};
34135
+ }
34136
+ let robotInfos = await this.handler.getAIRobotInfos(this.userID, this.groupID);
34137
+ if (robotInfos && robotInfos.length > 0) {
34138
+ robotInfos.forEach(async robot => {
34139
+ let robotKey = robot.id;
34140
+ if (!this.chatAIClient.charAIs[robotKey]) {
34141
+ robot.chatID = robotKey;
34142
+ let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
34143
+ if (!userSig) {
34144
+ userSig = await this.generateUserSigAndAdd(robotKey);
34145
+ }
34146
+ robot.userSig = userSig;
34147
+ this.chatAIClient.charAIs[robotKey] = {
34148
+ robot: robot,
34149
+ messageCache: []
34150
+ };
34151
+ }
34152
+ });
34217
34153
  }
34218
34154
  }
34219
-
34220
- // 如果没有匹配的内容,则不处理
34221
- if (!innerHTMLMatch && !checkContentResult.result && !attrCheckResult.result) {
34222
- return false;
34223
- }
34224
- let elementId = element.getAttribute("localDomID");
34225
- if (!elementId) {
34226
- elementId = i18n_generateUniqueId();
34227
- } else {
34228
- // 已经处理过的元素跳过
34229
- return false;
34230
- }
34231
- element.setAttribute("localDomID", elementId);
34232
- if (!window.i18nElementsMap) {
34233
- window.i18nElementsMap = new Map();
34234
- }
34235
- // 添加到Map缓存
34236
- window.i18nElementsMap.set(elementId, {
34237
- dom: element,
34238
- id: elementId,
34239
- isScriptAction: innerHTMLMatch ? innerHTMLMatch.isScriptAction || false : false,
34240
- scriptFunction: innerHTMLMatch ? innerHTMLMatch.scriptFunction || null : null,
34241
- isAttibuteAction: attrCheckResult.result,
34242
- attrFunction: attrCheckResult.scriptFunction || null
34243
- });
34244
- // console.log("添加后元素缓冲数:",window.i18nElementsMap.size);
34245
- applyTranslation(element);
34246
- return true;
34247
- }
34248
- function unProcessElement(element) {
34249
- if (element && element.nodeType !== 1) {
34250
- return;
34155
+ async generateUserSigAndUpdate(robotKey) {
34156
+ let sigIDObject = await this.handler.genTestUserSig({
34157
+ SDKAppID: this.appSKID,
34158
+ userID: robotKey
34159
+ });
34160
+ let userSig = sigIDObject.userSig;
34161
+ if (userSig) {
34162
+ await this.chatAIClient.login({
34163
+ userID: robotKey,
34164
+ userSig: userSig
34165
+ });
34166
+ await this.chatAIClient.logout();
34167
+ let data = {
34168
+ userID: robotKey,
34169
+ userSig: userSig,
34170
+ im_type: this.imType,
34171
+ group_id: this.groupID
34172
+ };
34173
+ await this.handler.updateIMMapping(data);
34174
+ }
34175
+ return userSig;
34251
34176
  }
34252
- let hasChildren = hasChildElements(element);
34253
- if (hasChildren) {
34254
- let children = element.children;
34255
- for (let i = 0; i < children.length; i++) {
34256
- unProcessElement(children[i]);
34177
+ async generateUserSigAndAdd(robotKey) {
34178
+ let sigIDObject = await this.handler.genTestUserSig({
34179
+ SDKAppID: this.appSKID,
34180
+ userID: robotKey
34181
+ });
34182
+ let userSig = sigIDObject.userSig;
34183
+ if (userSig) {
34184
+ await this.chatAIClient.login({
34185
+ userID: robotKey,
34186
+ userSig: userSig
34187
+ });
34188
+ await this.chatAIClient.logout();
34189
+ await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
34257
34190
  }
34191
+ return userSig;
34258
34192
  }
34259
- const localDomID = element.getAttribute("localDomID");
34260
- if (localDomID) {
34261
- // console.log(`处理元素ID:${localDomID} 移除缓存`);
34262
- element.removeAttribute("localDomID");
34193
+ onChatAIReady(event) {
34194
+ let robotID = this.chatAIClient.lastRobotID;
34195
+ let robotInfo = this.getAIRobotInfoByID(robotID);
34196
+ console.log(`[AI chat] ${robotInfo.name}已经就绪:`, event);
34197
+ if (this.chatAIClient) {
34198
+ let messages = this.getAIRobotCacheMessagesByID(robotID);
34199
+ console.log(`[AI chat] ${robotInfo.name}就绪后查到的缓存信息:`, messages);
34200
+ console.log(`[AI chat] ${robotInfo.name}所有信息仓:`, this.chatAIClient.charAIs);
34201
+ if (messages && messages.length > 0) {
34202
+ const newMessages = [...messages];
34203
+ messages.splice(0, messages.length);
34204
+ newMessages.forEach(message => {
34205
+ console.log(`[AI chat] ${robotInfo.name}发送缓存消息:`, message);
34206
+ this.sendMessageToChatServer(robotID, message);
34207
+ });
34208
+ }
34209
+ }
34263
34210
  }
34264
- if (localDomID && window.i18nElementsMap.has(localDomID)) {
34265
- // let oldValue = element.getAttribute("oldValue");
34266
- // if(oldValue){
34267
- // element.removeAttribute("oldValue");
34268
- // 更新元素的innerHTML
34269
- // element.innerHTML = oldValue;
34270
- // }
34271
- window.i18nElementsMap.delete(localDomID);
34272
- // console.log("移除后元素缓冲数:",window.i18nElementsMap.size);
34211
+ getAIRobotInfos() {
34212
+ let resultRobots = [];
34213
+ for (let key in this.chatAIClient.charAIs) {
34214
+ resultRobots.push(this.chatAIClient.charAIs[key].robot);
34215
+ }
34216
+ return resultRobots;
34273
34217
  }
34274
- }
34275
-
34276
- /**
34277
- * 应用翻译到单个元素
34278
- * @param {HTMLElement} element - 要更新的DOM元素
34279
- * @param {string} lang - 语言标识符
34280
- */
34281
- const applyTranslation = async element => {
34282
- let parentNode = element.parentNode;
34283
- if (!parentNode) {
34284
- unProcessElement(element);
34285
- console.log("元素已无父节点,移除缓存");
34286
- return;
34218
+ getAIRobotInfoByID(robotID) {
34219
+ return this.chatAIClient.charAIs[robotID] ? this.chatAIClient.charAIs[robotID].robot : null;
34287
34220
  }
34288
- let lang = window.localStorage.getItem("iportal_localID") || "zh-CN";
34289
- let appID = getPoratlAppID();
34290
- const elementId = element.getAttribute("localDomID");
34291
- const cachedItem = window.i18nElementsMap.get(elementId);
34292
- if (!cachedItem) return;
34293
- // 处理属性
34294
- if (cachedItem.isAttibuteAction) {
34295
- cachedItem.attrFunction(appID, lang);
34221
+ getAIRobotCacheMessagesByID(robotID) {
34222
+ return this.chatAIClient.charAIs[robotID] ? this.chatAIClient.charAIs[robotID].messageCache : [];
34296
34223
  }
34297
- // 处理innerHTML
34298
- if (cachedItem.isScriptAction) {
34299
- cachedItem.scriptFunction(appID, lang);
34300
- } else {
34301
- const oldValue = element.getAttribute("oldValue");
34302
- if (oldValue) {
34303
- // 创建正则表达式匹配所有 $L{...} 格式
34304
- const regex = /\$L\{([^}]+)\}/g;
34305
- // 替换所有 $L{...} 占位符为翻译文本
34306
- let newValue = oldValue;
34307
- let match;
34308
- while ((match = regex.exec(oldValue)) !== null) {
34309
- const fullMatch = match[0];
34310
- const placeholderKey = match[1];
34311
- const translation = i18n(placeholderKey, appID, lang);
34312
- newValue = newValue.replace(fullMatch, translation);
34224
+ async sendMessageToChatServer(robotID, messageOption) {
34225
+ let robotInfo = this.getAIRobotInfoByID(robotID);
34226
+ if (this.chatAIClient.lastRobotID != robotID) {
34227
+ console.log(`[AI chat]需要新机器人回答,切换到新机器人${robotInfo.name}`);
34228
+ if (this.chatAIClient.lastRobotID) {
34229
+ await this.chatAIClient.logout();
34313
34230
  }
34314
- (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.nextTick)(() => {
34315
- // 更新元素的innerHTML
34316
- element.innerHTML = newValue;
34317
- });
34318
- }
34319
- }
34320
- };
34321
- const initDomNodeI18NObserver = () => {
34322
- if (!window.i18nElementsMap) {
34323
- window.i18nElementsMap = new Map();
34324
- } else {
34325
- window.i18nElementsMap.clear();
34326
- }
34327
- registerEventListener("IPORTAL_LANGUAGE_CHANGE_EVENT", async lang => {
34328
- console.log("语言切换事件触发,更新已处理元素的翻译:", lang);
34329
- // 遍历Map,更新每个已处理元素的翻译
34330
- for (const [elementId, item] of window.i18nElementsMap.entries()) {
34331
- // console.log("更新元素翻译:", elementId, item.dom);
34332
- applyTranslation(item.dom);
34333
- }
34334
- });
34335
- // 创建观察器实例
34336
- const observer = new MutationObserver(mutations => {
34337
- mutations.forEach(mutation => {
34338
- if (mutation.type === 'childList') {
34339
- // 节点添加
34340
- if (mutation.addedNodes.length > 0) {
34341
- for (let i = 0; i < mutation.addedNodes.length; i++) {
34342
- let node = mutation.addedNodes[i];
34343
- // console.log(`处理新增节点:`,node);
34344
- if (node.nodeType === Node.TEXT_NODE) {
34345
- node = node.parentNode;
34346
- }
34347
- processElement(node);
34348
- }
34349
- }
34350
- // 节点移除
34351
- if (mutation.removedNodes.length > 0) {
34352
- for (let i = 0; i < mutation.removedNodes.length; i++) {
34353
- let node = mutation.removedNodes[i];
34354
- // console.log(`处理移除节点:`,node);
34355
- unProcessElement(node);
34356
- }
34357
- }
34358
- } else if (mutation.type === 'characterData') {
34359
- // 处理文本变化
34360
- const oldValue = mutation.oldValue;
34361
- const targetNode = mutation.target;
34362
- const newValue = targetNode.data;
34363
- // 创建日志条目并显示
34364
- console.log(`文本修改: ${oldValue} → ${newValue}`);
34365
- const parentElement = targetNode.parentNode;
34366
- if (parentElement) {
34367
- let localDomID = parentElement.getAttribute("localDomID");
34368
- // 如果有localDomID,说明之前处理过,先移除缓存
34369
- if (localDomID) {
34370
- unProcessElement(parentElement);
34231
+ try {
34232
+ await this.chatAIClient.login({
34233
+ userID: robotID,
34234
+ userSig: robotInfo.userSig
34235
+ });
34236
+ } catch (err) {
34237
+ console.log(`[AI chat]${robotInfo.name}登录失败`, err);
34238
+ let code = err.code;
34239
+ if (code == 70001) {
34240
+ console.log(`[AI chat]${robotInfo.name}UserSig过期,重新生成userSig`);
34241
+ let newUserSig = await this.generateUserSigAndUpdate(robotID);
34242
+ try {
34243
+ await this.chatAIClient.login({
34244
+ userID: robotID,
34245
+ userSig: newUserSig
34246
+ });
34247
+ this.sendMessageToChatServer(robotID, messageOption);
34248
+ return;
34249
+ } catch (err) {
34250
+ console.log(`[AI chat]${robotInfo.name}重新登录失败`, err);
34251
+ return;
34371
34252
  }
34372
34253
  }
34373
- processElement(parentElement);
34374
34254
  }
34375
- });
34376
- });
34255
+ }
34256
+ this.chatAIClient.lastRobotID = robotID;
34257
+ if (this.chatAIClient && this.chatAIClient.isReady()) {
34258
+ let new_message = await this.chatAIClient.createTextMessage(messageOption);
34259
+ this.chatAIClient.sendMessage(new_message).then(res => {
34260
+ console.log(`[AI chat]${robotInfo.name}发送信息成功`, res);
34261
+ }, err => {
34262
+ console.log(`[AI chat]${robotInfo.name}发送失败`, err);
34263
+ });
34264
+ } else {
34265
+ let messageCache = this.getAIRobotCacheMessagesByID(robotID);
34266
+ messageCache.push(messageOption);
34267
+ console.log(`[AI chat]${robotInfo.name}未就绪,缓存后消息:`, messageCache);
34268
+ }
34269
+ }
34270
+ converToAIServerParams(message, robotInfo, param) {
34271
+ let prompt = "";
34272
+ let type = message.type;
34273
+ switch (type) {
34274
+ case "TIMTextElem":
34275
+ prompt = message.payload?.text || "";
34276
+ break;
34277
+ case "TIMImageElem":
34278
+ break;
34279
+ case "TIMSoundElem":
34280
+ break;
34281
+ case "TIMVideoFileElem":
34282
+ break;
34283
+ case "TIMFileElem":
34284
+ break;
34285
+ default:
34286
+ break;
34287
+ }
34288
+ let cloudCustomData = message.cloudCustomData || {};
34289
+ let conversation_id = cloudCustomData.conversation_id || "";
34290
+ let params = {
34291
+ prompt: prompt,
34292
+ params: param || {},
34293
+ robotKey: robotInfo.password,
34294
+ conversation_id: conversation_id || "",
34295
+ userID: message.from || ""
34296
+ };
34297
+ return params;
34298
+ }
34299
+ abort() {
34300
+ this.chatAIClient = null;
34301
+ }
34302
+ }
34303
+ ;// ./src/api/chat.js
34377
34304
 
34378
- // 配置观察选项
34379
- const config = {
34380
- childList: true,
34381
- // 观察子节点变化
34382
- subtree: true,
34383
- // 观察所有后代节点
34384
- attributes: false,
34385
- // 不观察属性变化
34386
- characterData: true,
34387
- // 不观察文本内容变化
34388
- characterDataOldValue: true
34305
+
34306
+
34307
+
34308
+ const getRobotInfoByID = async (robotID, groupID) => {
34309
+ let queryData = {
34310
+ "param": {
34311
+ "id": robotID,
34312
+ "groupID": groupID
34313
+ }
34389
34314
  };
34390
- // 开始观察目标节点
34391
- const targetNode = document.body;
34392
- processElement(targetNode);
34393
- observer.observe(targetNode, config);
34315
+ let result = await request.post(`/dataservice/rest/orchestration/getRobotInfoByID`, queryData);
34316
+ let robotInfo = result.data.robotInfo;
34317
+ return robotInfo;
34394
34318
  };
34395
- const initDomNodeViewObserver = () => {
34396
- // 创建观察器实例
34397
- const observer = new MutationObserver(mutations => {
34398
- mutations.forEach(mutation => {
34399
- if (mutation.type === 'childList') {
34400
- // 节点添加
34401
- if (mutation.addedNodes.length > 0) {
34402
- for (let i = 0; i < mutation.addedNodes.length; i++) {
34403
- let node = mutation.addedNodes[i];
34404
- processViewElement(node);
34405
- }
34319
+ const getIMHanlder = customerHanlder => {
34320
+ let handler = {
34321
+ genTestUserSig: async data => {
34322
+ // return genTestUserSig(data);
34323
+ },
34324
+ getChatClientClasses: async () => {
34325
+ return [];
34326
+ },
34327
+ getAIRobotInfos: async (user_id, groupID) => {
34328
+ return getAIRobotInfos(user_id, groupID);
34329
+ },
34330
+ getPortalUserSig: async (robotKey, platType, groupID) => {
34331
+ return getPortalUserSig(robotKey, platType, groupID);
34332
+ },
34333
+ addIMMapping: async (robotKey, platType, userSig, groupID) => {
34334
+ return addIMMapping(robotKey, platType, groupID, userSig);
34335
+ },
34336
+ updateIMMapping: async data => {
34337
+ let robotKey = data.userID;
34338
+ let platType = data.im_type;
34339
+ let groupID = data.group_id;
34340
+ let userSig = data.userSig;
34341
+ return updateIMMapping(robotKey, platType, groupID, userSig);
34342
+ },
34343
+ getPortalAccessToken: async data => {
34344
+ let appKey = data.appKey;
34345
+ let appSecret = data.appSecret;
34346
+ return getPortalAccessToken(appKey, appSecret);
34347
+ },
34348
+ getPortalUserInfo: async data => {
34349
+ let code = data.code;
34350
+ let access_token = data.access_token;
34351
+ return getPortalUserInfo(code, access_token);
34352
+ },
34353
+ getAllUserInfosByGroupID: async data => {
34354
+ let groupID = data.groupID;
34355
+ return getAllUserInfosByGroupID(groupID);
34356
+ },
34357
+ getChildrenOfficeInfosByID: async data => {
34358
+ let groupID = data.groupID;
34359
+ return getChildrenOfficeInfosByID(groupID);
34360
+ },
34361
+ getPojectDptsByUserAndGroupID: async data => {
34362
+ let groupID = data.groupID;
34363
+ let userID = data.userID;
34364
+ return getPojectDptsByUserAndGroupID(userID, groupID);
34365
+ },
34366
+ closeWindow: () => {
34367
+ // this.visable = false;
34368
+ return true;
34369
+ },
34370
+ addChatListener: async (listenerKey, handler) => {
34371
+ await addEventAction(listenerKey, handler);
34372
+ },
34373
+ fireEventToChatWindow: async (event, chart_origin, key, params, handler) => {
34374
+ await sendWindowMessage(event.source, chart_origin, key, params, handler);
34375
+ },
34376
+ onChatInitFinished: async () => {
34377
+ // this.chatInitFinish = true;
34378
+ },
34379
+ onAIAgentEvent: async (data, event) => {
34380
+ // this.onAIAgentEvent(data,event);
34381
+ },
34382
+ getPortalDocmentInfo: async data => {
34383
+ let kb_doc_id = data.kb_doc_id;
34384
+ let doc_info = await getPortalDocmentInfo(kb_doc_id);
34385
+ let urlStr = doc_info?.summary;
34386
+ if (urlStr) {
34387
+ let urlObj = JSON.parse(urlStr);
34388
+ if (urlObj) {
34389
+ let url = urlObj[0].url;
34390
+ let home_page = window.smardaten_api_context_path;
34391
+ let finalUrl = `${home_page}/storage_area/public${url}`;
34392
+ let fileSize = await getFileSize(finalUrl);
34393
+ doc_info.fileSize = fileSize;
34406
34394
  }
34407
34395
  }
34408
- });
34409
- });
34410
-
34411
- // 配置观察选项
34412
- const config = {
34413
- childList: true,
34414
- // 观察子节点变化
34415
- subtree: true,
34416
- // 观察所有后代节点
34417
- attributes: false,
34418
- // 不观察属性变化
34419
- characterData: true,
34420
- // 不观察文本内容变化
34421
- characterDataOldValue: true
34396
+ return doc_info;
34397
+ }
34422
34398
  };
34423
- // 开始观察目标节点
34424
- const targetNode = document.body;
34425
- processViewElement(targetNode);
34426
- observer.observe(targetNode, config);
34399
+ handler = {
34400
+ ...handler,
34401
+ ...customerHanlder
34402
+ };
34403
+ return handler;
34427
34404
  };
34428
34405
 
34429
- // 处理单个DOM元素的函数
34430
- function processViewElement(element) {
34431
- if (!element) {
34432
- return false;
34433
- }
34434
- // 仅处理元素节点
34435
- if (element && element.nodeType !== Node.ELEMENT_NODE) {
34436
- return false;
34437
- }
34438
- // 如果元素有子元素,则不处理innerHTML
34439
- const hasChildren = hasChildElements(element);
34440
- if (hasChildren) {
34441
- let children = element.children;
34442
- for (let i = 0; i < children.length; i++) {
34443
- let child = children[i];
34444
- processViewElement(child);
34445
- }
34446
- }
34447
- let checkState = element.getAttribute("viewDomID");
34448
- // 已经处理过的元素跳过
34449
- if (checkState) {
34450
- return false;
34406
+ ;// ./src/api/dify.js
34407
+
34408
+
34409
+ const sendPostToAIAgent = async (queryData, successCallback, errorCallback) => {
34410
+ let appid = getPoratlAppID();
34411
+ let appCustomData = await getAppCustomData(appid);
34412
+ let aiAgentServerIP = appCustomData?.aiAgentServerIP || "";
34413
+ if (!aiAgentServerIP) {
34414
+ console.error("没有配置AI Agent服务地址,请联系管理员");
34415
+ if (errorCallback) errorCallback("没有配置AI Agent服务地址,请联系管理员");
34416
+ return;
34451
34417
  }
34452
- const viewCheckResult = commom_view_check(element);
34453
- // 如果没有匹配的内容,则不处理
34454
- if (!viewCheckResult.result) {
34455
- return false;
34418
+ let serverUrl = `${aiAgentServerIP}/addAndCleanDocument`;
34419
+ request.post(serverUrl, JSON.stringify(queryData)).then(res => {
34420
+ console.log("发送消息成功:", res);
34421
+ if (successCallback) successCallback(res);
34422
+ }).catch(error => {
34423
+ console.error("发送消息失败:", error);
34424
+ if (errorCallback) errorCallback(error);
34425
+ });
34426
+ };
34427
+ const getDifyFileType = fileType => {
34428
+ let typeOptions = {
34429
+ "DOCX": "document",
34430
+ "TXT": "document",
34431
+ "MD": "document",
34432
+ "MARKDOWN": "document",
34433
+ "MDX": "document",
34434
+ "PDF": "document",
34435
+ "HTML": "document",
34436
+ "XLSX": "document",
34437
+ "XLS": "document",
34438
+ "VTT": "document",
34439
+ "DOC": "document",
34440
+ "CSV": "document",
34441
+ "EML": "document",
34442
+ "MSG": "document",
34443
+ "PPTX": "document",
34444
+ "PPT": "document",
34445
+ "XML": "document",
34446
+ "EPUB": "document",
34447
+ "JPG": "image",
34448
+ "JPEG": "image",
34449
+ "PNG": "image",
34450
+ "GIF": "image",
34451
+ "WEBP": "image",
34452
+ "MP3": "audio",
34453
+ "M4A": "audio",
34454
+ "WAV": "audio",
34455
+ "WEBM": "audio",
34456
+ "MPGA": "audio",
34457
+ "MP4": "video",
34458
+ "MOV": "video",
34459
+ "MPEG": "video"
34460
+ };
34461
+ let key = fileType.toUpperCase();
34462
+ return typeOptions[key] || "custom";
34463
+ };
34464
+
34465
+ /**
34466
+ * 从 URL 中提取文件名(如 https://example.com/path/image.png → image.png)
34467
+ * @param {string} url - 文件 URL
34468
+ * @returns {string} - 提取的文件名
34469
+ */
34470
+ const dify_extractFilenameFromUrl = url => {
34471
+ try {
34472
+ const urlObj = new URL(url);
34473
+ // 从路径中获取最后一个部分(文件名)
34474
+ return urlObj.pathname.split("/").pop() || "downloaded_file";
34475
+ } catch (e) {
34476
+ return "downloaded_file"; // URL 解析失败时的默认文件名
34456
34477
  }
34457
- viewCheckResult.scriptFunction();
34458
- return true;
34459
- }
34478
+ };
34460
34479
  ;// ./src/main.js
34461
34480
 
34462
34481