feat: 封装条件组件

This commit is contained in:
fit2cloud-chenyw 2021-03-29 21:24:33 +08:00
parent 5fcc97565d
commit ab2a840bd5
12 changed files with 131 additions and 3 deletions

View File

@ -0,0 +1,32 @@
<template>
<div>de-widget</div>
</template>
<script>
import { ApplicationContext } from '@/utils/ApplicationContext'
export default {
props: {
options: {
type: Object,
default: null
}
},
data() {
return {
widget: null
}
},
computed() {
this.widget = ApplicationContext.getService(this.options.name)
console.log(this.widget.name)
},
methods: {
onDraw() {
}
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -0,0 +1,8 @@
export class Widget {
constructor(options = {}) {
this.type = options.type
this.default_style = options.default_style
this.icon = options.icon
this.lable = options.label
}
}

View File

@ -0,0 +1,10 @@
// import store from '@/store'
const req = require.context('./serviceImpl', false, /\.js$/)
const requireAll = requireContext => requireContext.keys()
const widgets = {}
requireAll(req).forEach(key => {
widgets[key.replace(/(\.\/|\.js)/g, '')] = req(key).default
})
export default widgets

View File

@ -0,0 +1,17 @@
import store from '@/store'
export class WidgetService {
constructor(options) {
this.name = options.name
console.log('init parent class WidgetService')
this.storeWidget()
}
storeWidget() {
store.dispatch('application/loadBean', { key: this.name, value: this })
}
initWidget() {
console.log('this is initWidget')
}
toDrawWidget() {
console.log('this is toDrawWidget')
}
}

View File

@ -0,0 +1,16 @@
import { WidgetService } from '../service/WidgetService'
class WidgetServiceImpl extends WidgetService {
constructor(options) {
super(options)
console.log('init child class WidgetServiceImpl')
}
initWidget() {
console.log('this is first initWidget')
}
toDrawWidget() {
console.log('this is first toDrawWidget')
}
}
const widgetServiceImpl = new WidgetServiceImpl({ name: 'testWidget' })
export default widgetServiceImpl

View File

@ -15,11 +15,12 @@ import api from '@/api/index.js'
import filter from '@/filter/filter'
import directives from './directive'
import VueClipboard from 'vue-clipboard2'
import widgets from '@/components/widget'
import '@/custom-component' // 注册自定义组件
Vue.config.productionTip = false
Vue.use(VueClipboard)
Vue.use(widgets)
Vue.prototype.$api = api
import * as echarts from 'echarts'

View File

@ -17,6 +17,7 @@ const getters = {
table: state => state.dataset.table,
loadingMap: state => state.request.loadingMap,
currentPath: state => state.permission.currentPath,
permissions: state => state.user.permissions
permissions: state => state.user.permissions,
beanMap: state => state.application.beanMap
}
export default getters

View File

@ -9,6 +9,7 @@ import dataset from './modules/dataset'
import chart from './modules/chart'
import request from './modules/request'
import panel from './modules/panel'
import application from './modules/application'
import animation from './animation'
import compose from './compose'
import contextmenu from './contextmenu'
@ -111,7 +112,8 @@ const data = {
dataset,
chart,
request,
panel
panel,
application
},
getters
}

View File

@ -0,0 +1,25 @@
const state = {
beanMap: {}
}
const mutations = {
ADD_BEAN: (state, { key, value }) => {
state.beanMap[key] = value
}
}
const actions = {
loadBean({ commit }, data) {
commit('ADD_BEAN', data)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@ -0,0 +1,10 @@
import store from '@/store'
export class ApplicationContext {
static getService(name) {
if (!name) {
return null
}
const bean = store.getters.beanMap[name]
return bean
}
}

View File

@ -24,6 +24,7 @@
</template>
<script>import componentList from '@/custom-component/component-list'
import { ApplicationContext } from '@/utils/ApplicationContext'
export default {
name: 'FilterGroup',
data() {
@ -31,6 +32,11 @@ export default {
componentList
}
},
mounted() {
const wid = ApplicationContext.getService('testWidget')
console.log(wid)
},
methods: {
handleDragStart(ev) {
ev.dataTransfer.effectAllowed = 'copy'