isdata-customer-sdk 0.2.30 → 0.2.32

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