mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
no message
This commit is contained in:
parent
a10bc74de1
commit
1c0271f55e
@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
php:
|
php:
|
||||||
container_name: "dootask-php-${APP_ID}"
|
container_name: "dootask-php-${APP_ID}"
|
||||||
image: "kuaifan/php:swoole-8.0.rc20"
|
image: "kuaifan/php:swoole-8.0.rc21"
|
||||||
shm_size: 2G
|
shm_size: 2G
|
||||||
ulimits:
|
ulimits:
|
||||||
core:
|
core:
|
||||||
@ -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.3"
|
image: "dootask/appstore:0.1.4"
|
||||||
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
|
||||||
|
|||||||
@ -42,12 +42,14 @@ export default {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.injectMicroApp()
|
this.injectMicroApp()
|
||||||
|
window.addEventListener('message', this.handleMessage.bind(this))
|
||||||
this.$refs.iframe.addEventListener('load', this.handleLoad.bind(this))
|
this.$refs.iframe.addEventListener('load', this.handleLoad.bind(this))
|
||||||
this.$refs.iframe.addEventListener('error', this.handleError.bind(this))
|
this.$refs.iframe.addEventListener('error', this.handleError.bind(this))
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.cleanupMicroApp()
|
this.cleanupMicroApp()
|
||||||
|
window.removeEventListener('message', this.handleMessage.bind(this))
|
||||||
this.$refs.iframe.removeEventListener('load', this.handleLoad.bind(this))
|
this.$refs.iframe.removeEventListener('load', this.handleLoad.bind(this))
|
||||||
this.$refs.iframe.removeEventListener('error', this.handleError.bind(this))
|
this.$refs.iframe.removeEventListener('error', this.handleError.bind(this))
|
||||||
},
|
},
|
||||||
@ -76,17 +78,72 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 处理 iframe 消息
|
||||||
|
handleMessage(e) {
|
||||||
|
if (!this.isFromCurrentIframe(e)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const {type, message} = e.data;
|
||||||
|
switch (type) {
|
||||||
|
case 'MICRO_APP_METHOD':
|
||||||
|
if (!this.data || !this.data.methods) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const {id, method, args} = message;
|
||||||
|
if (this.data.methods[method]) {
|
||||||
|
const postMessage = (result) => {
|
||||||
|
this.$refs.iframe.contentWindow.postMessage({
|
||||||
|
type: 'MICRO_APP_METHOD_RESULT',
|
||||||
|
message: {id, result: $A.cloneJSON(result)}
|
||||||
|
}, '*')
|
||||||
|
}
|
||||||
|
const before = this.data.methods[method](...args)
|
||||||
|
if (before && before.then) {
|
||||||
|
before.then(postMessage).catch(postMessage)
|
||||||
|
} else {
|
||||||
|
postMessage(before)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 验证消息是否来自当前 iframe
|
||||||
|
isFromCurrentIframe(event) {
|
||||||
|
try {
|
||||||
|
const { source } = event
|
||||||
|
return this.$refs.iframe && source === this.$refs.iframe.contentWindow
|
||||||
|
} catch (error) {
|
||||||
|
// console.error('Failed to validate message from current iframe:', error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// 注入 microApp 对象到 iframe
|
// 注入 microApp 对象到 iframe
|
||||||
injectMicroApp() {
|
injectMicroApp() {
|
||||||
try {
|
try {
|
||||||
const iframeWindow = this.$refs.iframe.contentWindow
|
const iframeWindow = this.$refs.iframe.contentWindow
|
||||||
if (iframeWindow && this.data) {
|
if (iframeWindow && this.data) {
|
||||||
iframeWindow.microApp = {
|
try {
|
||||||
getData: () => this.data
|
// 直接注入 microApp 对象
|
||||||
|
iframeWindow.microApp = {
|
||||||
|
getData: () => this.data
|
||||||
|
}
|
||||||
|
} catch (crossOriginError) {
|
||||||
|
// 跨域情况,使用 postMessage 发送 microApp 对象
|
||||||
|
iframeWindow.postMessage({
|
||||||
|
type: 'MICRO_APP_INJECT',
|
||||||
|
message: {
|
||||||
|
type: this.data.type,
|
||||||
|
props: this.data.props
|
||||||
|
}
|
||||||
|
}, '*')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to inject microApp object:', error)
|
// console.error('Failed to inject microApp object:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -98,7 +155,7 @@ export default {
|
|||||||
delete iframeWindow.microApp
|
delete iframeWindow.microApp
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to cleanup microApp object:', error)
|
// console.error('Failed to cleanup microApp object:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -237,28 +237,6 @@ export default {
|
|||||||
back: () => {
|
back: () => {
|
||||||
this.closeByName(name)
|
this.closeByName(name)
|
||||||
},
|
},
|
||||||
nextZIndex: () => {
|
|
||||||
if (typeof window.modalTransferIndex === 'number') {
|
|
||||||
return window.modalTransferIndex++;
|
|
||||||
}
|
|
||||||
return 1000;
|
|
||||||
},
|
|
||||||
selectUsers: async (params) => {
|
|
||||||
if (!$A.isJson(params)) {
|
|
||||||
params = {value: params}
|
|
||||||
}
|
|
||||||
if ($A.isArray(params.value)) {
|
|
||||||
params.value = params.value ? [params.value] : []
|
|
||||||
}
|
|
||||||
this.userSelectOptions.value = params.value
|
|
||||||
delete params.value
|
|
||||||
this.userSelectOptions.config = params
|
|
||||||
return await new Promise(resolve => {
|
|
||||||
this.$refs.userSelect.onSelection((res) => {
|
|
||||||
return resolve(res)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
popoutWindow: async (windowConfig = null) => {
|
popoutWindow: async (windowConfig = null) => {
|
||||||
const app = this.apps.find(item => item.name == name);
|
const app = this.apps.find(item => item.name == name);
|
||||||
if (!app) {
|
if (!app) {
|
||||||
@ -294,6 +272,31 @@ export default {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
requestAPI: async(params) => {
|
||||||
|
return await store.dispatch('call', params);
|
||||||
|
},
|
||||||
|
selectUsers: async (params) => {
|
||||||
|
if (!$A.isJson(params)) {
|
||||||
|
params = {value: params}
|
||||||
|
}
|
||||||
|
if ($A.isArray(params.value)) {
|
||||||
|
params.value = params.value ? [params.value] : []
|
||||||
|
}
|
||||||
|
this.userSelectOptions.value = params.value
|
||||||
|
delete params.value
|
||||||
|
this.userSelectOptions.config = params
|
||||||
|
return await new Promise(resolve => {
|
||||||
|
this.$refs.userSelect.onSelection((res) => {
|
||||||
|
return resolve(res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
nextZIndex: () => {
|
||||||
|
if (typeof window.modalTransferIndex === 'number') {
|
||||||
|
return window.modalTransferIndex++;
|
||||||
|
}
|
||||||
|
return 1000;
|
||||||
|
},
|
||||||
extraCallA: (...args) => {
|
extraCallA: (...args) => {
|
||||||
if (args.length > 0 && typeof args[0] === 'string') {
|
if (args.length > 0 && typeof args[0] === 'string') {
|
||||||
const methodName = args[0];
|
const methodName = args[0];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user