forked from github/dataease
feat: 封装条件组件
This commit is contained in:
parent
5fcc97565d
commit
ab2a840bd5
32
frontend/src/components/widget/DeWidget/index.vue
Normal file
32
frontend/src/components/widget/DeWidget/index.vue
Normal 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>
|
8
frontend/src/components/widget/bean/widget.js
Normal file
8
frontend/src/components/widget/bean/widget.js
Normal 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
|
||||
}
|
||||
}
|
10
frontend/src/components/widget/index.js
Normal file
10
frontend/src/components/widget/index.js
Normal 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
|
17
frontend/src/components/widget/service/WidgetService.js
Normal file
17
frontend/src/components/widget/service/WidgetService.js
Normal 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')
|
||||
}
|
||||
}
|
@ -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
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
25
frontend/src/store/modules/application.js
Normal file
25
frontend/src/store/modules/application.js
Normal 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
|
||||
}
|
||||
|
10
frontend/src/utils/ApplicationContext.js
Normal file
10
frontend/src/utils/ApplicationContext.js
Normal 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
|
||||
}
|
||||
}
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user