feat: 前端远程异步动态组件,渲染插件模块用

This commit is contained in:
fit2cloud-chenyw 2021-05-30 20:25:58 +08:00
parent ae733b0776
commit 5f267e7723
2 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import request from '@/utils/request'
export function get(url) {
return request({
url: url,
method: 'get'
})
}
export function execute(options) {
if (!options || !options.url) {
return null
}
options.type = options.type || 'post'
return request({
url: options.url,
method: options.type,
loading: true,
data: options.data
})
}

View File

@ -0,0 +1,84 @@
<template>
<layout-content v-loading="$store.getters.loadingMap[$store.getters.currentPath]" :header="header" :back-name="backName">
<async-component v-if="showAsync" :url="url" @execute-axios="executeAxios" @on-add-languanges="addLanguages" @on-plugin-layout="setLayoutInfo" />
<div v-else>
<h1>未知组件无法展示</h1>
</div>
</layout-content>
</template>
<script>
import LayoutContent from '@/components/business/LayoutContent'
import AsyncComponent from '@/components/AsyncComponent'
import i18n from '@/lang'
import { execute } from '@/api/system/dynamic'
export default {
name: 'Dynamic',
components: {
LayoutContent,
AsyncComponent
},
props: {
jsname: {
type: String,
default: null
},
menuid: {
type: Number,
default: null
}
},
data() {
return {
showAsync: false,
header: null,
backName: null,
baseUrl: '/api/pluginCommon/async/',
url: null
}
},
created() {
if (this.jsname && this.menuid) {
this.showAsync = true
console.log(this.jsname)
this.url = this.baseUrl + this.menuid
// this.url = 'http://localhost:8081/PluginDemo.js'
// this.url = 'http://localhost:8081/SystemParam.js'
} 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)
}
}
},
setLayoutInfo(param) {
const { header, backName } = param
this.header = header
this.backName = backName
}
}
}
</script>
<style scoped>
</style>