no message

This commit is contained in:
kuaifan 2025-07-04 23:17:59 +08:00
parent a10bc74de1
commit 1c0271f55e
3 changed files with 88 additions and 28 deletions

View File

@ -1,7 +1,7 @@
services:
php:
container_name: "dootask-php-${APP_ID}"
image: "kuaifan/php:swoole-8.0.rc20"
image: "kuaifan/php:swoole-8.0.rc21"
shm_size: 2G
ulimits:
core:
@ -96,7 +96,7 @@ services:
appstore:
container_name: "dootask-appstore-${APP_ID}"
privileged: true
image: "dootask/appstore:0.1.3"
image: "dootask/appstore:0.1.4"
volumes:
- shared_data:/usr/share/dootask
- /var/run/docker.sock:/var/run/docker.sock

View File

@ -42,12 +42,14 @@ export default {
mounted() {
this.injectMicroApp()
window.addEventListener('message', this.handleMessage.bind(this))
this.$refs.iframe.addEventListener('load', this.handleLoad.bind(this))
this.$refs.iframe.addEventListener('error', this.handleError.bind(this))
},
beforeDestroy() {
this.cleanupMicroApp()
window.removeEventListener('message', this.handleMessage.bind(this))
this.$refs.iframe.removeEventListener('load', this.handleLoad.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
injectMicroApp() {
try {
const iframeWindow = this.$refs.iframe.contentWindow
if (iframeWindow && this.data) {
iframeWindow.microApp = {
getData: () => this.data
try {
// 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) {
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
}
} catch (error) {
console.error('Failed to cleanup microApp object:', error)
// console.error('Failed to cleanup microApp object:', error)
}
},
}

View File

@ -237,28 +237,6 @@ export default {
back: () => {
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) => {
const app = this.apps.find(item => item.name == name);
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) => {
if (args.length > 0 && typeof args[0] === 'string') {
const methodName = args[0];