|
69 | 69 | const getChatContainerHtml = (data) => { |
70 | 70 | return ` |
71 | 71 | <div id="sqlbot-assistant-chat-container"> |
72 | | - <iframe id="sqlbot-assistant-chat-iframe-${data.id}" allow="microphone;clipboard-read 'src'; clipboard-write 'src'" src="${data.domain_url}/#/assistant?id=${data.id}&online=${!!data.online}&name=${encodeURIComponent(data.name)}"></iframe> |
| 72 | + <iframe id="sqlbot-assistant-chat-iframe-${data.id}" allow="microphone;clipboard-read 'src'; clipboard-write 'src'" src="${data.domain_url}/#/assistant?id=${data.id}&online=${!!data.online}&name=${encodeURIComponent(data.name)}&userFlag=${data.userFlag || ''}"></iframe> |
73 | 73 | <div class="sqlbot-assistant-operate"> |
74 | 74 | <div class="sqlbot-assistant-closeviewport sqlbot-assistant-viewportnone"> |
75 | 75 | <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none"> |
|
498 | 498 | function loadScript(src, id) { |
499 | 499 | const domain_url = getDomain(src) |
500 | 500 | const online = getParam(src, 'online') |
| 501 | + const userFlag = getParam(src, 'userFlag') |
501 | 502 | let url = `${domain_url}/api/v1/system/assistant/info/${id}` |
502 | 503 | if (domain_url.includes('5173')) { |
503 | 504 | url = url.replace('5173', '8000') |
|
534 | 535 | } |
535 | 536 |
|
536 | 537 | tempData['online'] = online && online.toString().toLowerCase() == 'true' |
| 538 | + tempData['userFlag'] = userFlag |
537 | 539 | initsqlbot_assistant(tempData) |
538 | 540 | if (data.type == 1) { |
539 | 541 | registerMessageEvent(id, tempData) |
|
708 | 710 | contentWindow.postMessage(params, url) |
709 | 711 | } |
710 | 712 | } |
711 | | - window.sqlbot_assistant_handler[id]['refresh'] = (online) => { |
| 713 | + window.sqlbot_assistant_handler[id]['refresh'] = (online, userFlag) => { |
712 | 714 | if (online != null && typeof online != 'boolean') { |
713 | 715 | throw new Error('The parameter can only be of type boolean') |
714 | 716 | } |
|
719 | 721 | if (online != null) { |
720 | 722 | new_url = updateParam(new_url, 'online', online) |
721 | 723 | } |
| 724 | + if (userFlag != null) { |
| 725 | + new_url = updateParam(new_url, 'userFlag', userFlag) |
| 726 | + } |
722 | 727 | iframe.src = 'about:blank' |
723 | 728 | setTimeout(() => { |
724 | 729 | iframe.src = new_url |
725 | 730 | }, 500) |
726 | 731 | } |
727 | 732 | } |
| 733 | + window.sqlbot_assistant_handler[id]['destroy'] = () => { |
| 734 | + const sqlbot_root_id = 'sqlbot-assistant-root-' + id |
| 735 | + const container_div = document.getElementById(sqlbot_root_id) |
| 736 | + if (container_div) { |
| 737 | + const root_div = container_div.parentNode |
| 738 | + if (root_div?.parentNode) { |
| 739 | + root_div.parentNode.removeChild(root_div) |
| 740 | + } |
| 741 | + } |
| 742 | + |
| 743 | + const scriptDom = document.getElementById(`sqlbot-assistant-float-script-${id}`) |
| 744 | + if (scriptDom) { |
| 745 | + scriptDom.parentNode.removeChild(scriptDom) |
| 746 | + } |
| 747 | + const propName = script_id_prefix + id + '-state' |
| 748 | + if (window[propName]) { |
| 749 | + delete window[propName] |
| 750 | + } |
| 751 | + delete window.sqlbot_assistant_handler[id] |
| 752 | + } |
728 | 753 | } |
729 | 754 | // window.addEventListener('load', init) |
730 | 755 | const executeWhenReady = (fn) => { |
|
0 commit comments