feat(ProjectManage): 为 AI助手 iframe 添加窗口打开拦截功能
- 在 iframe 上添加 @load 事件处理函数 onIframeLoad - 在 onIframeLoad 中覆盖 iframe 的 window.open 方法 - 提供示例逻辑,拦截并用主窗口打开链接
This commit is contained in:
@@ -205,8 +205,10 @@
|
|||||||
:footer="null"
|
:footer="null"
|
||||||
>
|
>
|
||||||
<iframe
|
<iframe
|
||||||
|
ref="myIframe"
|
||||||
:src="aiAssistantUrlWithToken"
|
:src="aiAssistantUrlWithToken"
|
||||||
style="width: 100%; height: 100%; min-height: 500px"
|
style="width: 100%; height: 100%; min-height: 500px"
|
||||||
|
@load="onIframeLoad"
|
||||||
frameborder="0"
|
frameborder="0"
|
||||||
>
|
>
|
||||||
</iframe>
|
</iframe>
|
||||||
@@ -314,7 +316,7 @@ const professionalCurrentPage = ref(0);
|
|||||||
const conceptTestRef = ref(null);
|
const conceptTestRef = ref(null);
|
||||||
const tasteTestRef = ref(null);
|
const tasteTestRef = ref(null);
|
||||||
const packageTestRef = ref(null);
|
const packageTestRef = ref(null);
|
||||||
|
const myIframe = ref(null)
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
groupId: { type: Number, value: -1 }
|
groupId: { type: Number, value: -1 }
|
||||||
// groupList: {
|
// groupList: {
|
||||||
@@ -656,6 +658,25 @@ function professionalPrev() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onIframeLoad() {
|
||||||
|
console.log('onIframeLoad');
|
||||||
|
const iframeWindow = myIframe.value.contentWindow
|
||||||
|
console.log(iframeWindow);
|
||||||
|
// 覆盖 window.open 方法
|
||||||
|
iframeWindow.open = function (url, target, features) {
|
||||||
|
console.log('拦截到 window.open:', { url, target, features })
|
||||||
|
|
||||||
|
// 自定义逻辑,例如:
|
||||||
|
// return window.open(url, '_blank') // 继续用当前窗口打开
|
||||||
|
// 或者阻止打开
|
||||||
|
// return null
|
||||||
|
|
||||||
|
// 示例:用主窗口打开链接
|
||||||
|
window.open(url, '_blank')
|
||||||
|
return null // 阻止 iframe 的 window.open
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听点击事件,开启或关闭AI iFrame
|
* 监听点击事件,开启或关闭AI iFrame
|
||||||
* @param event
|
* @param event
|
||||||
|
|||||||
Reference in New Issue
Block a user