feat: 优化过滤组件

This commit is contained in:
fit2cloud-chenyw 2021-04-15 10:33:22 +08:00
parent 4d3e20126a
commit fea7ceec9b
12 changed files with 512 additions and 281 deletions

View File

@ -1,14 +1,14 @@
<template> <template>
<div class="mark-line"> <div class="mark-line">
<div <div
v-for="line in lines" v-for="line in lines"
:key="line" v-show="lineStatus[line] || false"
class="line" :key="line"
:class="line.includes('x')? 'xline' : 'yline'" :ref="line"
:ref="line" class="line"
v-show="lineStatus[line] || false" :class="line.includes('x')? 'xline' : 'yline'"
></div> />
</div> </div>
</template> </template>
<script> <script>
@ -17,215 +17,215 @@ import { mapState } from 'vuex'
import { getComponentRotatedStyle } from '@/components/canvas/utils/style' import { getComponentRotatedStyle } from '@/components/canvas/utils/style'
export default { export default {
data() { data() {
return { return {
lines: ['xt', 'xc', 'xb', 'yl', 'yc', 'yr'], // 线线 lines: ['xt', 'xc', 'xb', 'yl', 'yc', 'yr'], // 线线
diff: 3, // dff diff: 3, // dff
lineStatus: { lineStatus: {
xt: false, xt: false,
xc: false, xc: false,
xb: false, xb: false,
yl: false, yl: false,
yc: false, yc: false,
yr: false, yr: false
}
}
},
computed: mapState([
'curComponent',
'componentData'
]),
mounted() {
//
eventBus.$on('move', (isDownward, isRightward) => {
this.showLine(isDownward, isRightward)
})
eventBus.$on('unmove', () => {
this.hideLine()
})
},
methods: {
hideLine() {
Object.keys(this.lineStatus).forEach(line => {
this.lineStatus[line] = false
})
},
showLine(isDownward, isRightward) {
const lines = this.$refs
const components = this.componentData
const curComponentStyle = getComponentRotatedStyle(this.curComponent.style)
const curComponentHalfwidth = curComponentStyle.width / 2
const curComponentHalfHeight = curComponentStyle.height / 2
this.hideLine()
components.forEach(component => {
if (component == this.curComponent) return
const componentStyle = getComponentRotatedStyle(component.style)
const { top, left, bottom, right } = componentStyle
const componentHalfwidth = componentStyle.width / 2
const componentHalfHeight = componentStyle.height / 2
const conditions = {
top: [
{
isNearly: this.isNearly(curComponentStyle.top, top),
lineNode: lines.xt[0], // xt
line: 'xt',
dragShift: top,
lineShift: top
}, },
{
isNearly: this.isNearly(curComponentStyle.bottom, top),
lineNode: lines.xt[0], // xt
line: 'xt',
dragShift: top - curComponentStyle.height,
lineShift: top
},
{
//
isNearly: this.isNearly(curComponentStyle.top + curComponentHalfHeight, top + componentHalfHeight),
lineNode: lines.xc[0], // xc
line: 'xc',
dragShift: top + componentHalfHeight - curComponentHalfHeight,
lineShift: top + componentHalfHeight
},
{
isNearly: this.isNearly(curComponentStyle.top, bottom),
lineNode: lines.xb[0], // xb
line: 'xb',
dragShift: bottom,
lineShift: bottom
},
{
isNearly: this.isNearly(curComponentStyle.bottom, bottom),
lineNode: lines.xb[0], // xb
line: 'xb',
dragShift: bottom - curComponentStyle.height,
lineShift: bottom
}
],
left: [
{
isNearly: this.isNearly(curComponentStyle.left, left),
lineNode: lines.yl[0], // yl
line: 'yl',
dragShift: left,
lineShift: left
},
{
isNearly: this.isNearly(curComponentStyle.right, left),
lineNode: lines.yl[0], // yl
line: 'yl',
dragShift: left - curComponentStyle.width,
lineShift: left
},
{
//
isNearly: this.isNearly(curComponentStyle.left + curComponentHalfwidth, left + componentHalfwidth),
lineNode: lines.yc[0], // yc
line: 'yc',
dragShift: left + componentHalfwidth - curComponentHalfwidth,
lineShift: left + componentHalfwidth
},
{
isNearly: this.isNearly(curComponentStyle.left, right),
lineNode: lines.yr[0], // yr
line: 'yr',
dragShift: right,
lineShift: right
},
{
isNearly: this.isNearly(curComponentStyle.right, right),
lineNode: lines.yr[0], // yr
line: 'yr',
dragShift: right - curComponentStyle.width,
lineShift: right
}
]
} }
},
computed: mapState([ const needToShow = []
'curComponent', const { rotate } = this.curComponent.style
'componentData', Object.keys(conditions).forEach(key => {
]), //
mounted() { conditions[key].forEach((condition) => {
// if (!condition.isNearly) return
eventBus.$on('move', (isDownward, isRightward) => { //
this.showLine(isDownward, isRightward) this.$store.commit('setShapeSingleStyle', {
key,
value: rotate !== 0 ? this.translatecurComponentShift(key, condition, curComponentStyle) : condition.dragShift
})
condition.lineNode && (condition.lineNode.style[key] = `${condition.lineShift}px`)
needToShow.push(condition.line)
})
}) })
eventBus.$on('unmove', () => { // 线
this.hideLine() // 线线
}) if (needToShow.length) {
this.chooseTheTureLine(needToShow, isDownward, isRightward)
}
})
}, },
methods: {
hideLine() {
Object.keys(this.lineStatus).forEach(line => {
this.lineStatus[line] = false
})
},
showLine(isDownward, isRightward) { translatecurComponentShift(key, condition, curComponentStyle) {
const lines = this.$refs const { width, height } = this.curComponent.style
const components = this.componentData if (key === 'top') {
const curComponentStyle = getComponentRotatedStyle(this.curComponent.style) return Math.round(condition.dragShift - (height - curComponentStyle.height) / 2)
const curComponentHalfwidth = curComponentStyle.width / 2 }
const curComponentHalfHeight = curComponentStyle.height / 2
this.hideLine() return Math.round(condition.dragShift - (width - curComponentStyle.width) / 2)
components.forEach(component => {
if (component == this.curComponent) return
const componentStyle = getComponentRotatedStyle(component.style)
const { top, left, bottom, right } = componentStyle
const componentHalfwidth = componentStyle.width / 2
const componentHalfHeight = componentStyle.height / 2
const conditions = {
top: [
{
isNearly: this.isNearly(curComponentStyle.top, top),
lineNode: lines.xt[0], // xt
line: 'xt',
dragShift: top,
lineShift: top,
},
{
isNearly: this.isNearly(curComponentStyle.bottom, top),
lineNode: lines.xt[0], // xt
line: 'xt',
dragShift: top - curComponentStyle.height,
lineShift: top,
},
{
//
isNearly: this.isNearly(curComponentStyle.top + curComponentHalfHeight, top + componentHalfHeight),
lineNode: lines.xc[0], // xc
line: 'xc',
dragShift: top + componentHalfHeight - curComponentHalfHeight,
lineShift: top + componentHalfHeight,
},
{
isNearly: this.isNearly(curComponentStyle.top, bottom),
lineNode: lines.xb[0], // xb
line: 'xb',
dragShift: bottom,
lineShift: bottom,
},
{
isNearly: this.isNearly(curComponentStyle.bottom, bottom),
lineNode: lines.xb[0], // xb
line: 'xb',
dragShift: bottom - curComponentStyle.height,
lineShift: bottom,
},
],
left: [
{
isNearly: this.isNearly(curComponentStyle.left, left),
lineNode: lines.yl[0], // yl
line: 'yl',
dragShift: left,
lineShift: left,
},
{
isNearly: this.isNearly(curComponentStyle.right, left),
lineNode: lines.yl[0], // yl
line: 'yl',
dragShift: left - curComponentStyle.width,
lineShift: left,
},
{
//
isNearly: this.isNearly(curComponentStyle.left + curComponentHalfwidth, left + componentHalfwidth),
lineNode: lines.yc[0], // yc
line: 'yc',
dragShift: left + componentHalfwidth - curComponentHalfwidth,
lineShift: left + componentHalfwidth,
},
{
isNearly: this.isNearly(curComponentStyle.left, right),
lineNode: lines.yr[0], // yr
line: 'yr',
dragShift: right,
lineShift: right,
},
{
isNearly: this.isNearly(curComponentStyle.right, right),
lineNode: lines.yr[0], // yr
line: 'yr',
dragShift: right - curComponentStyle.width,
lineShift: right,
},
],
}
const needToShow = []
const { rotate } = this.curComponent.style
Object.keys(conditions).forEach(key => {
//
conditions[key].forEach((condition) => {
if (!condition.isNearly) return
//
this.$store.commit('setShapeSingleStyle', {
key,
value: rotate !== 0? this.translatecurComponentShift(key, condition, curComponentStyle) : condition.dragShift,
})
condition.lineNode.style[key] = `${condition.lineShift}px`
needToShow.push(condition.line)
})
})
// 线
// 线线
if (needToShow.length) {
this.chooseTheTureLine(needToShow, isDownward, isRightward)
}
})
},
translatecurComponentShift(key, condition, curComponentStyle) {
const { width, height } = this.curComponent.style
if (key === 'top') {
return Math.round(condition.dragShift - (height - curComponentStyle.height) / 2)
}
return Math.round(condition.dragShift - (width - curComponentStyle.width) / 2)
},
chooseTheTureLine(needToShow, isDownward, isRightward) {
// 线
// 线
if (isRightward) {
if (needToShow.includes('yr')) {
this.lineStatus.yr = true
} else if (needToShow.includes('yc')) {
this.lineStatus.yc = true
} else if (needToShow.includes('yl')) {
this.lineStatus.yl = true
}
} else {
// eslint-disable-next-line no-lonely-if
if (needToShow.includes('yl')) {
this.lineStatus.yl = true
} else if (needToShow.includes('yc')) {
this.lineStatus.yc = true
} else if (needToShow.includes('yr')) {
this.lineStatus.yr = true
}
}
if (isDownward) {
if (needToShow.includes('xb')) {
this.lineStatus.xb = true
} else if (needToShow.includes('xc')) {
this.lineStatus.xc = true
} else if (needToShow.includes('xt')) {
this.lineStatus.xt = true
}
} else {
// eslint-disable-next-line no-lonely-if
if (needToShow.includes('xt')) {
this.lineStatus.xt = true
} else if (needToShow.includes('xc')) {
this.lineStatus.xc = true
} else if (needToShow.includes('xb')) {
this.lineStatus.xb = true
}
}
},
isNearly(dragValue, targetValue) {
return Math.abs(dragValue - targetValue) <= this.diff
},
}, },
chooseTheTureLine(needToShow, isDownward, isRightward) {
// 线
// 线
if (isRightward) {
if (needToShow.includes('yr')) {
this.lineStatus.yr = true
} else if (needToShow.includes('yc')) {
this.lineStatus.yc = true
} else if (needToShow.includes('yl')) {
this.lineStatus.yl = true
}
} else {
// eslint-disable-next-line no-lonely-if
if (needToShow.includes('yl')) {
this.lineStatus.yl = true
} else if (needToShow.includes('yc')) {
this.lineStatus.yc = true
} else if (needToShow.includes('yr')) {
this.lineStatus.yr = true
}
}
if (isDownward) {
if (needToShow.includes('xb')) {
this.lineStatus.xb = true
} else if (needToShow.includes('xc')) {
this.lineStatus.xc = true
} else if (needToShow.includes('xt')) {
this.lineStatus.xt = true
}
} else {
// eslint-disable-next-line no-lonely-if
if (needToShow.includes('xt')) {
this.lineStatus.xt = true
} else if (needToShow.includes('xc')) {
this.lineStatus.xc = true
} else if (needToShow.includes('xb')) {
this.lineStatus.xb = true
}
}
},
isNearly(dragValue, targetValue) {
return Math.abs(dragValue - targetValue) <= this.diff
}
}
} }
</script> </script>

View File

@ -3,13 +3,13 @@
<span v-show="isActive()" class="iconfont icon-xiangyouxuanzhuan" @mousedown="handleRotate" /> <span v-show="isActive()" class="iconfont icon-xiangyouxuanzhuan" @mousedown="handleRotate" />
<span v-show="element.isLock" class="iconfont icon-suo" /> <span v-show="element.isLock" class="iconfont icon-suo" />
<!-- <span v-show="isActive()" class="iconfont icon-more">--> <!-- <span v-show="isActive()" class="iconfont icon-more">-->
<!-- <el-button--> <!-- <el-button-->
<!-- icon="el-icon-more"--> <!-- icon="el-icon-more"-->
<!-- type="text"--> <!-- type="text"-->
<!-- size="small"--> <!-- size="small"-->
<!-- />--> <!-- />-->
<!-- </span>--> <!-- </span>-->
<div <div
v-for="item in (isActive()? pointList : [])" v-for="item in (isActive()? pointList : [])"
:key="item" :key="item"
@ -335,9 +335,9 @@ export default {
symmetricPoint symmetricPoint
}) })
console.log('this is test:' + JSON.stringify(this.element.propValue.viewId)) // console.log('this is test:' + JSON.stringify(this.element.propValue.viewId))
this.$store.commit('setShapeStyle', style) this.$store.commit('setShapeStyle', style)
eventBus.$emit('resizing', this.element.propValue.viewId) this.element.propValue && this.element.propValue.viewId && eventBus.$emit('resizing', this.element.propValue.viewId)
} }
const up = () => { const up = () => {

View File

@ -30,8 +30,8 @@
:id="'component' + item.id" :id="'component' + item.id"
class="component" class="component"
:style="getComponentStyle(item.style)" :style="getComponentStyle(item.style)"
:element="item" :service-name="item.widgetService.name"
:item="item" :panel-id="panelInfo.id"
@filter-value-change="filterValueChange" @filter-value-change="filterValueChange"
/> />
@ -97,12 +97,18 @@ export default {
isShowArea: false isShowArea: false
} }
}, },
computed: mapState([ computed: {
'componentData', panelInfo() {
'curComponent', return this.$store.state.panel.panelInfo
'canvasStyleData', },
'editor' ...mapState([
]), 'componentData',
'curComponent',
'canvasStyleData',
'editor'
])
},
mounted() { mounted() {
// //
this.$store.commit('getEditor') this.$store.commit('getEditor')

View File

@ -1,19 +1,30 @@
<script> <script>
import { ApplicationContext } from '@/utils/ApplicationContext'
export default { export default {
name: 'DeDrawingWidget', name: 'DeDrawingWidget',
functional: true, functional: true,
props: { props: {
item: { serviceName: {
type: Object, type: String,
default: null
},
panelId: {
type: String,
default: null default: null
} }
}, },
render(createElement, context) { render(createElement, context) {
const item = context.props.item const widgetInfo = ApplicationContext.getService(context.props.serviceName)
return createElement(item.component, { // const widgetInfo = context.props.widgetInfo
const panelId = context.props.panelId
const dialogInfo = widgetInfo.getDialogPanel && widgetInfo.getDialogPanel(panelId) || null
if (!dialogInfo) {
throw new Error('系统错误')
}
return createElement(dialogInfo.component, {
props: { props: {
element: item element: dialogInfo
}, },
on: { on: {
'value-change': value => { 'value-change': value => {

View File

@ -0,0 +1,87 @@
import { DrawWidgetService } from '../service/DrawWidgetService'
const leftPanel = {
// name: 'text-select',
icon: 'iconfont icon-xialakuang',
label: '文本下拉',
defaultClass: 'text-filter'
}
const dialogPanel = {
options: {
refId: '1234567890',
attrs: {
multiple: false,
placeholder: '请选择',
datas: [],
key: 'id',
label: 'text',
value: 'id'
},
value: ''
},
defaultClass: 'text-filter',
component: 'de-select'
}
const drawPanel = {
type: 'custom',
style: {
width: 200,
height: 22,
fontSize: 14,
fontWeight: 500,
lineHeight: '',
letterSpacing: 0,
textAlign: '',
color: ''
},
component: 'de-select'
}
class MySelectImpl extends DrawWidgetService {
constructor(options = {}) {
Object.assign(options, { name: 'mySelectWidget' })
super(options)
}
initLeftPanel(uuid) {
uuid = uuid || this.uuid()
this.setLeftPanel(uuid, leftPanel)
return uuid
// console.log('this is first initWidget')
}
initFilterDialog(uuid) {
uuid = uuid || this.uuid()
this.setDialogPanel(uuid, dialogPanel)
return uuid
}
initDrawPanel(uuid) {
uuid = uuid || this.uuid()
this.setDrawPanel(uuid, drawPanel)
return uuid
}
toDrawWidget() {
// console.log('this is first toDrawWidget')
}
// 移动到画布之前回掉
beforeToDraw() {
}
setOptionDatas(uuid, data) {
const dialogPanel = this.getDialogPanel(uuid)
dialogPanel.options.attrs.datas = data
this.setDialogPanel(uuid, dialogPanel)
}
filterFieldMethod(fields) {
return fields.filter(field => {
return field['deType'] === 0
})
}
}
const mySelectImpl = new MySelectImpl()
export default mySelectImpl

View File

@ -31,7 +31,8 @@ requireComponent.keys().forEach(fileName => {
) )
}) })
const req = require.context('./serviceImpl', false, /\.js$/) // const req = require.context('./serviceImpl', false, /\.js$/)
const req = require.context('./drawServiceImpl', false, /\.js$/)
const requireAll = requireContext => requireContext.keys() const requireAll = requireContext => requireContext.keys()
const widgets = {} const widgets = {}

View File

@ -0,0 +1,83 @@
import store from '@/store'
import { uuid } from 'vue-uuid'
export const commonStyle = {
rotate: 0,
opacity: 1
}
export const commonAttr = {
animations: [],
events: {},
groupStyle: {}, // 当一个组件成为 Group 的子组件时使用
isLock: false // 是否锁定组件
}
export class DrawWidgetService {
constructor(options) {
this.options = options
this.name = options.name
this.leftPanelPath = 'application/addLeftWidget'
this.dialogPanelPath = 'application/addDialogWidget'
this.drawPanelPath = 'application/addDrawWidget'
this.storeWidget()
}
/**
* 存储数据到本地
* @param {本地存储路径} path
* @param {要存储的数据} data
*/
store(path, data) {
store.dispatch(path, data)
}
uuid() {
return uuid.v1()
}
setLeftPanel(uuid, leftPanel) {
this.store(this.leftPanelPath, { uuid: uuid, leftPanel: leftPanel })
}
getLeftPanel(uuid) {
if (!store.getters.leftWidgetMap[uuid]) {
this.initLeftPanel && this.initLeftPanel(uuid)
}
return store.getters.leftWidgetMap[uuid]
}
setDialogPanel(uuid, dialogPanel) {
this.store(this.dialogPanelPath, { uuid: uuid, dialogPanel: dialogPanel })
}
getDialogPanel(uuid) {
if (!store.getters.dialogWidgetMap[uuid]) {
this.initFilterDialog && this.initFilterDialog(uuid)
}
return store.getters.dialogWidgetMap[uuid]
}
setDrawPanel(uuid, drawPanel) {
if (!store.getters.drawWidgetMap[uuid]) { // 第一次
drawPanel.style = Object.assign(drawPanel.style, commonStyle)
drawPanel = Object.assign(drawPanel, commonAttr)
if (this.initFilterDialog) { // 需要弹窗
const dialogOptions = this.getDialogPanel(uuid)
drawPanel = Object.assign(drawPanel, dialogOptions)
}
}
this.store(this.drawPanelPath, { uuid: uuid, drawPanel: drawPanel })
}
getDrawPanel(uuid) {
if (!store.getters.drawWidgetMap[uuid]) {
this.initDrawPanel && this.initDrawPanel(uuid)
}
return store.getters.drawWidgetMap[uuid]
}
storeWidget() {
// store.dispatch('application/loadBean', { key: this.name, value: this })
this.store('application/loadBean', { key: this.name, value: this })
}
initWidget() {
console.log('this is initWidget')
}
toDrawWidget() {
console.log('this is toDrawWidget')
}
}

View File

@ -18,6 +18,9 @@ const getters = {
loadingMap: state => state.request.loadingMap, loadingMap: state => state.request.loadingMap,
currentPath: state => state.permission.currentPath, currentPath: state => state.permission.currentPath,
permissions: state => state.user.permissions, permissions: state => state.user.permissions,
beanMap: state => state.application.beanMap beanMap: state => state.application.beanMap,
leftWidgetMap: state => state.application.leftWidgetMap,
dialogWidgetMap: state => state.application.dialogWidgetMap,
drawWidgetMap: state => state.application.drawWidgetMap
} }
export default getters export default getters

View File

@ -1,11 +1,26 @@
const state = { const state = {
beanMap: {} beanMap: {},
leftWidgetMap: {},
dialogWidgetMap: {},
drawWidgetMap: {}
} }
const mutations = { const mutations = {
ADD_BEAN: (state, { key, value }) => { ADD_BEAN: (state, { key, value }) => {
state.beanMap[key] = value state.beanMap[key] = value
},
ADD_LEFT_WIDGET: (state, { uuid, leftPanel }) => {
state.leftWidgetMap[uuid] = leftPanel
},
ADD_DIALOG_WIDGET: (state, { uuid, dialogPanel }) => {
state.dialogWidgetMap[uuid] = dialogPanel
},
ADD_DRAW_WIDGET: (state, { uuid, drawPanel }) => {
state.drawWidgetMap[uuid] = drawPanel
} }
} }
@ -13,7 +28,20 @@ const mutations = {
const actions = { const actions = {
loadBean({ commit }, data) { loadBean({ commit }, data) {
commit('ADD_BEAN', data) commit('ADD_BEAN', data)
},
addLeftWidget({ commit }, data) {
commit('ADD_LEFT_WIDGET', data)
},
addDialogWidget({ commit }, data) {
commit('ADD_DIALOG_WIDGET', data)
},
addDrawWidget({ commit }, data) {
commit('ADD_DRAW_WIDGET', data)
} }
} }
export default { export default {

View File

@ -69,19 +69,18 @@
</de-container> </de-container>
<el-dialog <el-dialog
v-if="filterVisible" v-if="filterVisible && panelInfo.id"
title="过滤组件" title="过滤组件"
:visible.sync="filterVisible" :visible.sync="filterVisible"
custom-class="de-filter-dialog" custom-class="de-filter-dialog"
> >
<filter-dialog v-if="filterVisible" :component-info="currentComponent" :widget-id="currentWidgetId" @re-fresh-component="reFreshComponent"> <filter-dialog v-if="filterVisible && currentWidget" :widget-info="currentWidget" @re-fresh-component="reFreshComponent">
<de-drawing-widget <de-drawing-widget
v-if="filterVisible && currentComponent" v-if="filterVisible"
:id="'component' + currentComponent.id"
style="width: 100% !important;" style="width: 100% !important;"
class="component" class="component"
:element="currentComponent" :service-name="currentWidget.name"
:item="currentComponent" :panel-id="panelInfo.id"
/> />
</filter-dialog> </filter-dialog>
<!-- <div slot="footer" class="dialog-footer"> <!-- <div slot="footer" class="dialog-footer">
@ -144,9 +143,7 @@ export default {
activeName: 'attr', activeName: 'attr',
reSelectAnimateIndex: undefined, reSelectAnimateIndex: undefined,
filterVisible: false, filterVisible: false,
currentWidgetId: null, currentWidget: null
currentWidget: null,
currentComponent: null
} }
}, },
@ -252,6 +249,7 @@ export default {
e.stopPropagation() e.stopPropagation()
let component let component
const newComponentId = uuid.v1() const newComponentId = uuid.v1()
const componentInfo = JSON.parse(e.dataTransfer.getData('componentInfo')) const componentInfo = JSON.parse(e.dataTransfer.getData('componentInfo'))
// //
@ -268,16 +266,18 @@ export default {
}) })
} else { } else {
this.currentWidget = ApplicationContext.getService(componentInfo.id) this.currentWidget = ApplicationContext.getService(componentInfo.id)
if (this.currentWidget.filterDialog) {
const drawPanel = this.currentWidget.getDrawPanel(this.panelInfo.id)
drawPanel.style.top = e.offsetY
drawPanel.style.left = e.offsetX
drawPanel.id = newComponentId
this.currentWidget.setDrawPanel(this.panelInfo.id, drawPanel)
if (this.currentWidget.initFilterDialog) {
this.show = false this.show = false
this.currentComponent = deepCopy(this.currentWidget)
this.currentComponent.style.top = e.offsetY
this.currentComponent.style.left = e.offsetX
this.currentComponent.id = newComponentId
this.openFilterDiolog() this.openFilterDiolog()
return return
} }
component = deepCopy(this.currentWidget) component = deepCopy(drawPanel)
} }
component.style.top = e.offsetY component.style.top = e.offsetY
@ -311,17 +311,16 @@ export default {
} }
}, },
openFilterDiolog() { openFilterDiolog() {
this.currentWidgetId = this.currentComponent.name
this.filterVisible = true this.filterVisible = true
}, },
cancelFilter() { cancelFilter() {
this.filterVisible = false this.filterVisible = false
this.currentWidgetId = null
this.currentWidget = null this.currentWidget = null
this.currentComponent = null
}, },
sureFilter() { sureFilter() {
const component = deepCopy(this.currentComponent) const currentComponent = this.currentWidget.getDrawPanel(this.panelInfo.id)
currentComponent.widgetService = this.currentWidget
const component = deepCopy(currentComponent)
this.$store.commit('addComponent', { component }) this.$store.commit('addComponent', { component })
this.$store.commit('recordSnapshot') this.$store.commit('recordSnapshot')
this.cancelFilter() this.cancelFilter()

View File

@ -144,7 +144,7 @@ import DeContainer from '@/components/dataease/DeContainer'
import DeAsideContainer from '@/components/dataease/DeAsideContainer' import DeAsideContainer from '@/components/dataease/DeAsideContainer'
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import DragItem from '@/components/DragItem' import DragItem from '@/components/DragItem'
import { ApplicationContext } from '@/utils/ApplicationContext' // import { ApplicationContext } from '@/utils/ApplicationContext'
import { groupTree, loadTable, fieldList, fieldValues } from '@/api/dataset/dataset' import { groupTree, loadTable, fieldList, fieldValues } from '@/api/dataset/dataset'
export default { export default {
name: 'FilterDialog', name: 'FilterDialog',
@ -156,11 +156,8 @@ export default {
DragItem DragItem
}, },
props: { props: {
widgetId: {
type: String, widgetInfo: {
default: null
},
componentInfo: {
type: Object, type: Object,
default: null default: null
} }
@ -184,23 +181,29 @@ export default {
fieldValues: [] fieldValues: []
} }
}, },
computed: {
uuid() {
return this.$store.state.panel.panelInfo.id
}
},
watch: { watch: {
selectField(values) { selectField(values) {
if (values && values.length > 0) { if (values && values.length > 0) {
const value = values[0] const value = values[0]
const fieldId = value.id const fieldId = value.id
this.componentInfo && this.componentInfo.setOptionDatas && fieldValues(fieldId).then(res => { this.widget && this.widget.setOptionDatas && fieldValues(fieldId).then(res => {
const datas = res.data.map(item => { const datas = res.data.map(item => {
return { id: item, text: item } return { id: item, text: item }
}) })
this.componentInfo.setOptionDatas(datas) this.widget.setOptionDatas(this.uuid, datas)
this.$emit('re-fresh-component', this.componentInfo) // this.$emit('re-fresh-component', this.componentInfo)
}) })
} }
} }
}, },
created() { created() {
this.widget = ApplicationContext.getService(this.widgetId) // this.widget = ApplicationContext.getService(this.widgetId)
this.widget = this.widgetInfo
this.loadDataSetTree() this.loadDataSetTree()
}, },

View File

@ -10,8 +10,8 @@
<div class="filter-widget-content"> <div class="filter-widget-content">
<div <div
v-for="(widget, index) in item" v-for="(widget, index) in item"
:key="widget.name+index" :key="widget.widgetName+index"
:data-id="widget.name" :data-id="widget.widgetName"
draggable draggable
:data-index="index" :data-index="index"
:class="'filter-widget '+ (widget.defaultClass || '')" :class="'filter-widget '+ (widget.defaultClass || '')"
@ -35,23 +35,29 @@ export default {
data() { data() {
return { return {
componentList, componentList,
panelInfo: this.$store.state.panel.panelInfo,
widgetSubjects: { widgetSubjects: {
'时间过滤组件': [
'timeYearWidget',
'timeMonthWidget',
'timeQuarterWidget',
'timeDateWidget',
'timeDateRangeWidget'
],
'文本过滤组件': [ '文本过滤组件': [
'textSelectWidget', 'mySelectWidget'
'textInputWidget'
],
'按钮': [
'buttonSureWidget'
] ]
} }
// widgetSubjects: {
// '': [
// 'timeYearWidget',
// 'timeMonthWidget',
// 'timeQuarterWidget',
// 'timeDateWidget',
// 'timeDateRangeWidget'
// ],
// '': [
// 'textSelectWidget',
// 'textInputWidget'
// ],
// '': [
// 'buttonSureWidget'
// ]
// }
} }
}, },
created() { created() {
@ -59,7 +65,11 @@ export default {
const widgetNames = this.widgetSubjects[key] const widgetNames = this.widgetSubjects[key]
this.widgetSubjects[key] = widgetNames.map(widgetName => { this.widgetSubjects[key] = widgetNames.map(widgetName => {
const widget = ApplicationContext.getService(widgetName) const widget = ApplicationContext.getService(widgetName)
return widget const uuid = this.panelInfo.id
// widget.initLeftPanel(uuid)
const result = { widgetName: widgetName }
Object.assign(result, widget.getLeftPanel(uuid))
return result
}) })
} }
}, },