mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 12:02:51 +00:00
feat: 微应用支持iframe模式
This commit is contained in:
parent
4c34fe9b85
commit
750d3429e0
@ -96,7 +96,7 @@ services:
|
|||||||
appstore:
|
appstore:
|
||||||
container_name: "dootask-appstore-${APP_ID}"
|
container_name: "dootask-appstore-${APP_ID}"
|
||||||
privileged: true
|
privileged: true
|
||||||
image: "dootask/appstore:0.1.0"
|
image: "dootask/appstore:0.1.1"
|
||||||
volumes:
|
volumes:
|
||||||
- shared_data:/usr/share/dootask
|
- shared_data:/usr/share/dootask
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
|||||||
67
resources/assets/js/components/MicroApps/iframe.vue
Normal file
67
resources/assets/js/components/MicroApps/iframe.vue
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<iframe
|
||||||
|
ref="iframe"
|
||||||
|
class="micro-app-iframe"
|
||||||
|
:src="src"
|
||||||
|
sandbox="allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.micro-app-iframe {
|
||||||
|
border: none;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "MicroIFrame",
|
||||||
|
props: {
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
src: this.url,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.$refs.iframe.addEventListener('load', this.handleLoad.bind(this))
|
||||||
|
this.$refs.iframe.addEventListener('error', this.handleError.bind(this))
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.$refs.iframe.removeEventListener('load', this.handleLoad.bind(this))
|
||||||
|
this.$refs.iframe.removeEventListener('error', this.handleError.bind(this))
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
handleLoad(e) {
|
||||||
|
this.$emit('mounted', {
|
||||||
|
...e,
|
||||||
|
detail: {
|
||||||
|
name: this.name,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
handleError(e) {
|
||||||
|
this.$emit('error', {
|
||||||
|
...e,
|
||||||
|
detail: {
|
||||||
|
name: this.name,
|
||||||
|
error: e,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@ -9,17 +9,20 @@
|
|||||||
:transparent="app.transparent"
|
:transparent="app.transparent"
|
||||||
:autoDarkTheme="app.auto_dark_theme"
|
:autoDarkTheme="app.auto_dark_theme"
|
||||||
:beforeClose="async () => { await onBeforeClose(app.name) }">
|
:beforeClose="async () => { await onBeforeClose(app.name) }">
|
||||||
|
<MicroIFrame
|
||||||
|
v-if="app.url_type === 'iframe' && app.isOpen && app.url"
|
||||||
|
:name="app.name"
|
||||||
|
:url="app.url"
|
||||||
|
@mounted="mounted"
|
||||||
|
@error="error"/>
|
||||||
<micro-app
|
<micro-app
|
||||||
v-if="app.isOpen && app.url"
|
v-else-if="app.isOpen && app.url"
|
||||||
:name="app.name"
|
:name="app.name"
|
||||||
:url="app.url"
|
:url="app.url"
|
||||||
:keep-alive="app.keep_alive"
|
:keep-alive="app.keep_alive"
|
||||||
:disable-scopecss="app.disable_scope_css"
|
:disable-scopecss="app.disable_scope_css"
|
||||||
:data="appData(app.name)"
|
:data="appData(app.name)"
|
||||||
@created="created"
|
|
||||||
@beforemount="beforemount"
|
|
||||||
@mounted="mounted"
|
@mounted="mounted"
|
||||||
@unmount="unmount"
|
|
||||||
@error="error"/>
|
@error="error"/>
|
||||||
<div v-if="app.isLoading" class="micro-app-loader">
|
<div v-if="app.isLoading" class="micro-app-loader">
|
||||||
<Loading/>
|
<Loading/>
|
||||||
@ -86,11 +89,12 @@ import emitter from "../../store/events";
|
|||||||
import TransferDom from "../../directives/transfer-dom";
|
import TransferDom from "../../directives/transfer-dom";
|
||||||
import store from "../../store";
|
import store from "../../store";
|
||||||
import MicroModal from "./modal.vue";
|
import MicroModal from "./modal.vue";
|
||||||
|
import MicroIFrame from "./iframe.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MicroApps",
|
name: "MicroApps",
|
||||||
directives: {TransferDom},
|
directives: {TransferDom},
|
||||||
components: {MicroModal, UserSelect},
|
components: {MicroModal, UserSelect, MicroIFrame},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
windowType: {
|
windowType: {
|
||||||
@ -149,26 +153,14 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
// 元素被创建
|
|
||||||
created() {
|
|
||||||
},
|
|
||||||
|
|
||||||
// 即将渲染
|
|
||||||
beforemount() {
|
|
||||||
},
|
|
||||||
|
|
||||||
// 已经渲染完成
|
// 已经渲染完成
|
||||||
mounted(e) {
|
mounted(e) {
|
||||||
this.finish(e)
|
this.finish(e.detail.name)
|
||||||
},
|
|
||||||
|
|
||||||
// 已经卸载
|
|
||||||
unmount() {
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 加载出错
|
// 加载出错
|
||||||
error(e) {
|
error(e) {
|
||||||
this.finish(e)
|
this.finish(e.detail.name)
|
||||||
$A.modalError({
|
$A.modalError({
|
||||||
language: false,
|
language: false,
|
||||||
title: this.$L('应用加载失败'),
|
title: this.$L('应用加载失败'),
|
||||||
@ -180,8 +172,8 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 加载结束
|
// 加载结束
|
||||||
finish(e) {
|
finish(name) {
|
||||||
const app = this.apps.find(({name}) => name == e.detail.name);
|
const app = this.apps.find(app => app.name == name);
|
||||||
if (app) {
|
if (app) {
|
||||||
app.isLoading = false
|
app.isLoading = false
|
||||||
}
|
}
|
||||||
|
|||||||
14
resources/assets/js/store/actions.js
vendored
14
resources/assets/js/store/actions.js
vendored
@ -4675,11 +4675,15 @@ export default {
|
|||||||
if (!data.id || !data.name || !data.url) {
|
if (!data.id || !data.name || !data.url) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data.url = data.url.replace(/\{window[._]location[._](\w+)}/ig, (match, property) => {
|
data.url = data.url
|
||||||
if (property in window.location) {
|
.replace(/^\:(\d+)/ig, (_, port) => {
|
||||||
return window.location[property];
|
return window.location.protocol + '//' + window.location.hostname + ':' + port;
|
||||||
}
|
})
|
||||||
})
|
.replace(/\{window[._]location[._](\w+)}/ig, (_, property) => {
|
||||||
|
if (property in window.location) {
|
||||||
|
return window.location[property];
|
||||||
|
}
|
||||||
|
})
|
||||||
const config = {
|
const config = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user