支持外链接

This commit is contained in:
liqiang
2025-01-30 12:40:30 +08:00
parent 3271f00f87
commit e15a49a2bd
5 changed files with 27 additions and 3 deletions

View File

@@ -23,6 +23,7 @@
<script setup lang="ts" name="layoutIframeView">
import { computed, watch, ref, nextTick } from 'vue';
import { useRoute } from 'vue-router';
import {cookie} from "xe-utils";
// 定义父组件传过来的值
const props = defineProps({
@@ -49,7 +50,15 @@ const route = useRoute();
// 处理 list 列表,当打开时,才进行加载
const setIframeList = computed(() => {
return (<RouteItems>props.list).filter((v: RouteItem) => v.meta?.isIframeOpen);
return (<RouteItems>props.list).filter((v: RouteItem) => {
if (v.meta?.isIframeOpen) {
const isLink = v.meta?.isLink || '';
if (isLink.includes("{{token}}")) {
v.meta.isLink = isLink.replace("{{token}}", cookie.get('token'))
}
}
return v.meta?.isIframeOpen
});
});
// 获取 iframe 当前路由 path
const getRoutePath = computed(() => {

View File

@@ -17,19 +17,31 @@
import { reactive, watch } from 'vue';
import { useRoute } from 'vue-router';
import { verifyUrl } from '/@/utils/toolsValidate';
import {cookie} from "xe-utils";
// 定义变量内容
const route = useRoute();
const state = reactive<LinkViewState>({
title: '',
isLink: '',
query: null
});
// 立即前往
const onGotoFullPage = () => {
const { origin, pathname } = window.location;
if (state.isLink.includes("{{token}}")) {
state.isLink = state.isLink.replace("{{token}}", cookie.get('token'))
}
if (verifyUrl(<string>state.isLink)) window.open(state.isLink);
else window.open(`${origin}${pathname}#${state.isLink}`);
else {
function objectToUrlParams(obj: { [key: string]: string | number }): string {
return Object.keys(obj)
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
.join('&');
}
window.open(`${origin}${pathname}#${state.isLink}?${objectToUrlParams(state.query)}`)
};
};
// 监听路由的变化,设置内容
watch(
@@ -37,6 +49,7 @@ watch(
() => {
state.title = <string>route.meta.title;
state.isLink = <string>route.meta.isLink;
state.query = <any>route.query;
},
{
immediate: true,

View File

@@ -56,4 +56,5 @@ declare type ParentViewState<T = any> = {
declare type LinkViewState = {
title: string;
isLink: string;
query: any;
};

View File

@@ -85,6 +85,7 @@
<el-form-item v-if="!menuFormData.is_catalog && menuFormData.is_link" label="外链接" prop="link_url">
<el-input v-model="menuFormData.link_url" placeholder="请输入外链接地址" />
<el-alert :title="`输入{{token}}可自动替换系统 token `" type="info" />
</el-form-item>
<el-form-item v-if="!menuFormData.is_catalog" label="缓存">