perf: iframe嵌入式编辑资源

This commit is contained in:
fit2cloud-chenyw 2024-03-20 14:05:58 +08:00
parent 7adbecbc64
commit 2a2d419f1c
6 changed files with 32 additions and 34 deletions

View File

@ -59,6 +59,7 @@ const loadComponent = () => {
importProxy(byteArray) importProxy(byteArray)
}) })
.catch(() => { .catch(() => {
emits('loadFail')
showNolic() showNolic()
}) })
.finally(() => { .finally(() => {
@ -77,6 +78,7 @@ const pluginProxy = ref(null)
const invokeMethod = param => { const invokeMethod = param => {
pluginProxy.value['invokeMethod'](param) pluginProxy.value['invokeMethod'](param)
} }
const emits = defineEmits(['loadFail'])
defineExpose({ defineExpose({
invokeMethod invokeMethod
}) })

View File

@ -189,6 +189,10 @@ service.interceptors.response.use(
} }
router.push(`/login?redirect=${queryRedirectPath}`) router.push(`/login?redirect=${queryRedirectPath}`)
} }
} else if (response?.config?.url.startsWith('/xpackComponent/content')) {
console.error(
"never mind this error about '/xpackComponent/content', just a reminder to support the official license"
)
} }
return Promise.reject(response.data.msg) return Promise.reject(response.data.msg)
@ -209,6 +213,10 @@ service.interceptors.response.use(
message: error.message, message: error.message,
showClose: true showClose: true
}) })
} else if (error?.config?.url.startsWith('/xpackComponent/content')) {
console.error(
"never mind this error about '/xpackComponent/content', just a reminder to support the official license"
)
} }
error.config.loading && tryHideLoading(permissionStore.getCurrentPath) error.config.loading && tryHideLoading(permissionStore.getCurrentPath)
@ -225,7 +233,7 @@ service.interceptors.response.use(
if (header.has('DE-FORBIDDEN-FLAG')) { if (header.has('DE-FORBIDDEN-FLAG')) {
showMsg('当前用户权限配置已变更请刷新页面', '-changed-') showMsg('当前用户权限配置已变更请刷新页面', '-changed-')
} }
return Promise.reject(error) return Promise.resolve()
} }
) )

View File

@ -23,13 +23,8 @@ const { start, done } = useNProgress()
const { loadStart, loadDone } = usePageLoading() const { loadStart, loadDone } = usePageLoading()
const whiteList = ['/login', '/de-link', '/chart-view'] // 不重定向白名单 const whiteList = ['/login', '/de-link', '/chart-view'] // 不重定向白名单
const embeddedWhiteList = [ const embeddedWindowWhiteList = ['/dvCanvas', '/dashboard']
'/dvCanvas', const embeddedRouteWhiteList = ['/dataset-embedded', '/dataset-form', '/dataset-embedded-form']
'/dashboard',
'/dataset-embedded',
'/dataset-form',
'/dataset-embedded-form'
]
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
start() start()
loadStart() loadStart()
@ -106,14 +101,22 @@ router.beforeEach(async (to, from, next) => {
} }
} else { } else {
const embeddedStore = useEmbedded() const embeddedStore = useEmbedded()
if (embeddedStore.getToken && appStore.getIsIframe && embeddedWhiteList.includes(to.path)) { if (
embeddedStore.getToken &&
appStore.getIsIframe &&
embeddedRouteWhiteList.includes(to.path)
) {
if (to.path.includes('/dataset-form')) { if (to.path.includes('/dataset-form')) {
next({ path: '/dataset-embedded-form', query: to.query }) next({ path: '/dataset-embedded-form', query: to.query })
return return
} }
permissionStore.setCurrentPath(to.path) permissionStore.setCurrentPath(to.path)
next() next()
} else if (whiteList.indexOf(to.path) !== -1 || to.path.startsWith('/de-link/')) { } else if (
embeddedWindowWhiteList.includes(to.path) ||
whiteList.includes(to.path) ||
to.path.startsWith('/de-link/')
) {
permissionStore.setCurrentPath(to.path) permissionStore.setCurrentPath(to.path)
next() next()
} else { } else {

View File

@ -56,7 +56,8 @@ export const userStore = defineStore('embedded', {
type: this.type, type: this.type,
dvId: this.dvId, dvId: this.dvId,
chartId: this.chartId, chartId: this.chartId,
pid: this.pid pid: this.pid,
resourceId: this.resourceId
} }
} }
}, },
@ -92,6 +93,7 @@ export const userStore = defineStore('embedded', {
this.dvId = data['dvId'] this.dvId = data['dvId']
this.chartId = data['chartId'] this.chartId = data['chartId']
this.pid = data['pid'] this.pid = data['pid']
this.resourceId = data['resourceId']
} }
} }
}) })

View File

@ -96,20 +96,11 @@ const onMobileConfig = () => {
} }
const loadFinish = ref(false) const loadFinish = ref(false)
const newWindowHandler = ref(null)
let p = null let p = null
const XpackLoaded = () => { const XpackLoaded = () => p(true)
p(true)
}
// //
onMounted(async () => { onMounted(async () => {
await new Promise(r => { await new Promise(r => (p = r))
if (!newWindowHandler?.value) {
return r(null)
}
p = r
})
loadFinish.value = true loadFinish.value = true
useEmitt({ useEmitt({
name: 'mobileConfig', name: 'mobileConfig',
@ -254,9 +245,9 @@ onUnmounted(() => {
v-else-if="loadFinish && mobileConfig" v-else-if="loadFinish && mobileConfig"
></MobileConfigPanel> ></MobileConfigPanel>
<XpackComponent <XpackComponent
ref="newWindowHandler"
jsname="L2NvbXBvbmVudC9lbWJlZGRlZC1pZnJhbWUvTmV3V2luZG93SGFuZGxlcg==" jsname="L2NvbXBvbmVudC9lbWJlZGRlZC1pZnJhbWUvTmV3V2luZG93SGFuZGxlcg=="
@loaded="XpackLoaded" @loaded="XpackLoaded"
@load-fail="XpackLoaded"
/> />
</template> </template>

View File

@ -200,19 +200,11 @@ const checkPer = async resourceId => {
} }
const loadFinish = ref(false) const loadFinish = ref(false)
const newWindowHandler = ref(null)
let p = null let p = null
const XpackLoaded = () => { const XpackLoaded = () => p(true)
p(true)
}
onMounted(async () => { onMounted(async () => {
await new Promise(r => { await new Promise(r => (p = r))
if (!newWindowHandler?.value) {
return r(null)
}
p = r
})
loadFinish.value = true loadFinish.value = true
window.addEventListener('blur', releaseAttachKey) window.addEventListener('blur', releaseAttachKey)
if (editMode.value === 'edit') { if (editMode.value === 'edit') {
@ -389,9 +381,9 @@ eventBus.on('handleNew', handleNew)
</el-container> </el-container>
</div> </div>
<XpackComponent <XpackComponent
ref="newWindowHandler"
jsname="L2NvbXBvbmVudC9lbWJlZGRlZC1pZnJhbWUvTmV3V2luZG93SGFuZGxlcg==" jsname="L2NvbXBvbmVudC9lbWJlZGRlZC1pZnJhbWUvTmV3V2luZG93SGFuZGxlcg=="
@loaded="XpackLoaded" @loaded="XpackLoaded"
@load-fail="XpackLoaded"
/> />
</template> </template>