fix: bug#18886

This commit is contained in:
XieYongHong 2023-10-07 17:14:43 +08:00
parent 14bc5cf16f
commit 24a669adc6
2 changed files with 36 additions and 7 deletions

View File

@ -131,7 +131,7 @@ export const postStream = function(url: string, data = {}, params = {}) {
})
}
const showNotification = (message: string, description: string, key?: string, show: boolean = true) => {
export const showNotification = (message: string, description: string, key?: string, show: boolean = true) => {
if (show) {
Notification.error({
style: {
@ -144,13 +144,17 @@ const showNotification = (message: string, description: string, key?: string, sh
}
}
export const TokenLose = () => {
showNotification('Unauthorized', '用户未登录', '401')
}
/**
*
* @param {Object} error
* @returns {Promise<never>}
*/
const errorHandler = (error: any) => {
if (error.response) {
const data = error.response.data
const status = error.response.status
@ -182,7 +186,7 @@ const errorHandler = (error: any) => {
} else if (status === 400) {
showNotification('Request Error', (data.message + '').substr(0, 90), '400')
} else if (status === 401) {
showNotification('Unauthorized', '用户未登录', '401')
TokenLose()
setTimeout(() => {
cleanToken()
router.replace({
@ -257,4 +261,4 @@ export default {
remove,
getStream,
postStream
}
}

View File

@ -14,10 +14,14 @@
<script lang="ts" name="IframgePage" setup>
import { TOKEN_KEY } from '@/utils/variable';
import { LocalStore, getToken } from '@/utils/comm';
import {LocalStore, getToken, cleanToken} from '@/utils/comm';
import { getAppInfo_api } from '@/api/system/apply';
import { lowCodeUrl } from '@/api/comm'
import FullPage from "components/Layout/FullPage.vue";
import {onUnmounted} from "vue";
import router from "@/router";
import {LoginPath} from "@/router/menu";
import { TokenLose} from "@/utils/request";
const iframeUrl = ref<string>('');
const route = useRoute()
@ -47,8 +51,8 @@ const handle = async (appId: string, url: string) => {
const lowCode = () => {
lowCodeUrl().then(res => {
if (res.success && res.result) {
const url = res.result['ui-addr']
// const url = 'http://localhost:8080'
// const url = res.result['ui-addr']
const url = 'http://localhost:8080'
iframeUrl.value = url + '/#' + route.path + '?&token=' + getToken()
console.log(iframeUrl.value)
loading.value = true
@ -56,6 +60,27 @@ const lowCode = () => {
})
}
const onMessage = (msg: any) => {
console.log('onMessage',msg)
if (msg?.data?.token === 'LOSE') {
TokenLose()
setTimeout(() => {
cleanToken()
router.replace({
path: LoginPath
})
}, 0)
}
}
onMounted(() => {
window.addEventListener('message', onMessage)
})
onUnmounted(() => {
window.removeEventListener('message', onMessage)
})
watchEffect(() => {
const matchedItem: any = route.matched?.[0]
if (route.meta?.isApp) {