问答 查看内容
返回列表

【产品AI问答助手】内置到BI产品操作指南

1243 5
发表于 2025-4-9 16:29:01 | 查看全部 阅读模式
要求用户环境能够访问互联网,BI版本号在6.6.0及以上,同时需要管理员权限来操作
1、进入管理中心,点击右上角【新建插件】
image.png

                               
登录/注册后可看大图
2、填写相关信息后点击【确定】
image (1).png

                               
登录/注册后可看大图
3、找到刚刚创建的插件,点击【编辑代码】按钮来添加代码
image (2).png

4、拷贝以下代码(最下面有复制按钮)复制到文本框中,点击【确定】。
  1. GD.on('gd-ready', () => {
  2.     // 获取<head>元素的data-version属性
  3.     const version = document.head.getAttribute('data-version');
  4.     if (version) {
  5.         console.log('当前BI产品版本号:', version);
  6.     } else {
  7.         console.warn('未找到 data-version 属性');
  8.     }

  9.     const isMobileUrl = window.location.pathname.startsWith('/m');
  10.     if (isMobileUrl) {
  11.         return;        
  12.     }
  13.     const editorOnly = false;
  14.     const userInfo = GD.getUser();
  15.     if (userInfo.role[0] === 'participant' && editorOnly) {
  16.       return;
  17.     }
  18.     const innerWidth = window.innerWidth;
  19.     const userAgent = navigator.userAgent || navigator.vendor || window.opera;
  20.     const isMobile = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent.toLowerCase()) || innerWidth < 480;
  21.     const isPrintPage = window.location.pathname.includes('/print');
  22.     if (window.self === window.top && !isMobile && !isPrintPage) {
  23.       // Create a button and append it to the document body
  24.       const button = document.createElement('div');
  25.       button.style.position = 'fixed';
  26.       button.style.bottom = '20px';
  27.       button.style.right = '10px';
  28.       button.style.backgroundColor = '#fff';
  29.       button.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
  30.       button.style.cursor = 'pointer';
  31.       button.style.padding = '8px 8px';
  32.       button.style.borderRadius = '30px';
  33.       button.style.display = 'flex';
  34.       button.style.flexDirection = 'column';
  35.       button.style.alignItems = 'center';
  36.       button.style.zIndex = 1000;
  37.       document.body.appendChild(button);
  38.   
  39.       // Modify the button to include an image and text in a vertical layout
  40.       button.innerHTML = '';
  41.       
  42.       const dragSvg = '<svg t="1743060843660" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3628" width="14"><path fill="#00bebe" d="M219.428571 585.142857c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142858-73.142857-36.571429-73.142857-73.142858-73.142857z m585.142858-146.285714c36.571429 0 73.142857-36.571429 73.142857-73.142857s-36.571429-73.142857-73.142857-73.142857-73.142857 36.571429-73.142858 73.142857 36.571429 73.142857 73.142858 73.142857zM219.428571 292.571429c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142858-73.142857-36.571429-73.142857-73.142858-73.142857z m585.142858 292.571428c-36.571429 0-73.142857 36.571429-73.142858 73.142857s36.571429 73.142857 73.142858 73.142857 73.142857-36.571429 73.142857-73.142857-36.571429-73.142857-73.142857-73.142857zM512 292.571429c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142857-73.142857-36.571429-73.142857-73.142857-73.142857z m0 292.571428c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142857-73.142857-36.571429-73.142857-73.142857-73.142857z" p-id="3629"></path></svg>'
  43.    
  44.       const dragContainer = document.createElement('div');
  45.       dragContainer.innerHTML = dragSvg;
  46.       dragContainer.style.display = 'block';
  47.       dragContainer.style.margin = '0 auto';
  48.    
  49.       const text = document.createElement('div');
  50.       text.innerText = 'AI助手';
  51.       text.style.color = '#00bebe';
  52.       text.style.width = '16px';
  53.       text.style.display = 'block';
  54.       text.style.textAlign = 'center';
  55.    
  56.       button.appendChild(dragContainer);
  57.       button.appendChild(text);

  58.        // 添加拖拽功能
  59.       let isDragging = false;
  60.       let currentX;
  61.       let currentY;
  62.       let initialX;
  63.       let initialY;
  64.       let xOffset = 0;
  65.       let yOffset = 0;
  66.       let hasMoved = false;

  67.       button.addEventListener('mousedown', dragStart, { passive: false, capture: true });
  68.       document.addEventListener('mousemove', drag, { passive: false, capture: true });
  69.       document.addEventListener('mouseup', dragEnd);

  70.       function dragStart(e) {
  71.         e.preventDefault();
  72.         e.stopPropagation();
  73.         initialX = e.clientX - xOffset;
  74.         initialY = e.clientY - yOffset;
  75.         hasMoved = false;

  76.         if (e.target === button || button.contains(e.target)) {
  77.           isDragging = true;
  78.           button.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
  79.           button.style.boxShadow = '0 0 15px rgba(0, 190, 190, 0.3)';
  80.           button.style.border = '1px solid #00bebe';
  81.         }
  82.       }

  83.       function drag(e) {
  84.         if (isDragging) {
  85.           e.preventDefault();
  86.           e.stopPropagation();
  87.           currentX = e.clientX - initialX;
  88.           currentY = e.clientY - initialY;
  89.           if (Math.abs(currentX) > 5 || Math.abs(currentY) > 5) {
  90.             hasMoved = true;
  91.           }
  92.           xOffset = currentX;
  93.           yOffset = currentY;

  94.           setTranslate(currentX, currentY, button);
  95.         }
  96.       }

  97.       function setTranslate(xPos, yPos, el) {
  98.         el.style.transform = `translate3d(${xPos}px, ${yPos}px, 0)`;
  99.       }

  100.       function dragEnd(e) {
  101.         if (e) {
  102.           e.preventDefault();
  103.         }
  104.         initialX = currentX;
  105.         initialY = currentY;
  106.         isDragging = false;
  107.         button.style.backgroundColor = '#fff';
  108.         button.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
  109.         button.style.border = 'none';
  110.       }
  111.    
  112.       // Add event listener to the button to show the modal
  113.       button.addEventListener('click', () => {
  114.         if (!hasMoved) {
  115.           modal.style.display = 'block';
  116.         }
  117.       });
  118.     }
  119.   
  120.   // Create a modal container
  121.   const modal = document.createElement('div');
  122.   modal.style.position = 'fixed';
  123.   modal.style.bottom = '0px';
  124.   modal.style.right = '0px';
  125.   modal.style.width = '480px';
  126.   modal.style.height = '100vh';
  127.   modal.style.backgroundColor = 'white';
  128.   modal.style.border = '1px solid #e7e9e8';
  129.   modal.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
  130.   modal.style.zIndex = '1000';
  131.   modal.style.display = 'none'; // Initially hidden
  132.   
  133.   // Create a head container
  134.   const head = document.createElement('div');
  135.   head.style.display = 'flex';
  136.   head.style.justifyContent = 'space-between';
  137.   head.style.alignItems = 'center';
  138.   head.style.height = '48px';
  139.   head.style.padding = '0 12px';
  140.   head.style.borderBottom = '1px solid #e7e9e8';
  141.   head.style.backgroundColor = '#fafafa';
  142.   
  143.   // Create a title for the modal
  144.   const title = document.createElement('span');
  145.   title.innerText = 'AI助手';
  146.   title.style.color = '#00bebe';
  147.   title.style.fontSize = '16px';
  148.   title.style.fontWeight = '500';
  149.   head.appendChild(title);
  150.   
  151.   // Create a close button and append it to the head
  152.   const closeButton = document.createElement('span');
  153.   closeButton.innerText = '关闭';
  154.   closeButton.style.color = '#00bebe';
  155.   closeButton.style.cursor = 'pointer';
  156.   head.appendChild(closeButton);
  157.   
  158.   // Append the head to the modal
  159.   modal.appendChild(head);
  160.   
  161.   // Create an iframe and append it to the modal
  162.   const iframe = document.createElement('iframe');  
  163.   var iframeUrl = 'https://robot.guandata.com/galaxy' + '?cid=' + window.location.host + '&uid=' + userInfo.uId;
  164.   if (version) {
  165.     iframeUrl = iframeUrl + '&version=' + version;
  166.   }

  167.   iframe.src = iframeUrl
  168.   iframe.style.width = '100%';
  169.   iframe.style.height = 'calc(100vh - 48px)'; // Adjust height to account for head
  170.   modal.appendChild(iframe);
  171.   
  172.   // Append the modal to the document body
  173.   document.body.appendChild(modal);
  174.   
  175.   // Add event listener to the close button to hide the modal
  176.   closeButton.addEventListener('click', () => {
  177.     modal.style.display = 'none';
  178.   });
  179. })
复制代码


image (3).png

如果要限制只有编辑者才能看到的话需要把代码中第8行const editorOnly = false; 修改为 const editorOnly = true;
5、通过点击【本地调试】进行本地浏览器测试,测试通过后切换【应用状态】到开启(绿色)即可发布
image (4).png

                               
登录/注册后可看大图
6、效果如图所示,如果页面上没有出现,可以强制刷新、清理缓存或者重启浏览器

                               
登录/注册后可看大图
image (5).png

7、有任何问题或者建议都可以通过点击此处进行反馈
image (6).png

                               
登录/注册后可看大图


评论5

赖兴荣楼主Lv.9 发表于 2025-4-9 16:29:46 | 查看全部
有什么问题可以联系我或者直接评论
Guandata_3b80f8b8Lv.1 发表于 2025-5-15 10:21:40 | 查看全部
需登录,但是无登录地方。 截图202505151021137444.png
赖兴荣楼主Lv.9 发表于 2025-5-15 10:57:29 | 查看全部
Guandata_3b80f8b8 发表于 2025-5-15 10:21
需登录,但是无登录地方。

https://atlas.guandata.com/app/4 ... 6-9739-7f97d1671f54
需要通过这个链接打开,已更新文档
Guandata_bc86635bLv.1 发表于 2025-5-22 16:33:33 | 查看全部
需要互联网环境使用?
赖兴荣楼主Lv.9 发表于 2025-5-27 10:01:27 | 查看全部
Guandata_bc86635b 发表于 2025-5-22 16:33
需要互联网环境使用?

是的,需要能够连接互联网

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

微信服务号
联系我们
电话:400-880-0750
邮箱:hello@guandata.com
Copyright © 2001-2025 观远社区 版权所有 All Rights Reserved. 浙 ICP 备15006424号-3
去回复 去发帖 返回顶部
快速回复 返回顶部 返回列表