dataease/frontend/src/views/system/plugin/PluginCom.vue

76 lines
1.6 KiB
Vue
Raw Normal View History

2021-09-14 18:47:33 +08:00
<template>
<div>
<async-component v-if="showAsync" :url="url" :obj="obj" @execute-axios="executeAxios"
@on-add-languanges="addLanguages" @plugin-call-back="pluginCallBack"/>
2021-09-14 18:47:33 +08:00
<div v-else>
<h1>未知组件无法展示</h1>
</div>
</div>
</template>
<script>
import AsyncComponent from '@/components/AsyncComponent'
import i18n from '@/lang'
import bus from '@/utils/bus'
import {execute} from '@/api/system/dynamic'
2021-09-14 18:47:33 +08:00
export default {
name: 'PluginCom',
components: {
AsyncComponent
},
props: {
componentName: {
type: String,
default: null
2021-12-27 16:26:59 +08:00
},
obj: {
type: Object,
default: () => {}
2021-09-14 18:47:33 +08:00
}
},
data() {
return {
showAsync: false,
baseUrl: '/api/pluginCommon/component/',
url: null
}
},
created() {
if (this.componentName) {
this.showAsync = true
this.url = this.baseUrl + this.componentName
} else {
this.showAsync = false
}
},
methods: {
// hasLicense
executeAxios(options) {
execute(options).then(res => {
if (options.callBack) {
options.callBack(res)
}
}).catch(e => {
if (options.callBack) {
options.callBack(e)
}
})
},
addLanguages(options) {
for (const key in i18n.messages) {
if (Object.hasOwnProperty.call(i18n.messages, key)) {
const element = options[key]
i18n.mergeLocaleMessage(key, element)
}
}
},
pluginCallBack(param) {
const {eventName, eventParam} = param
2021-09-14 18:47:33 +08:00
bus.$emit(eventName, eventParam)
}
}
}
</script>