提交 7dac4702 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 仪表板tabs组件

上级 f81e65aa
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
:out-style="config.style" :out-style="config.style"
:style="getComponentStyleDefault(config.style)" :style="getComponentStyleDefault(config.style)"
:prop-value="config.propValue" :prop-value="config.propValue"
:is-edit="false"
:element="config" :element="config"
:search-count="searchCount" :search-count="searchCount"
/> />
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<el-dropdown-item icon="el-icon-arrow-up" @click.native="upComponent">{{ $t('panel.upComponent') }}</el-dropdown-item> <el-dropdown-item icon="el-icon-arrow-up" @click.native="upComponent">{{ $t('panel.upComponent') }}</el-dropdown-item>
<el-dropdown-item icon="el-icon-arrow-down" @click.native="downComponent">{{ $t('panel.downComponent') }}</el-dropdown-item> <el-dropdown-item icon="el-icon-arrow-down" @click.native="downComponent">{{ $t('panel.downComponent') }}</el-dropdown-item>
<el-dropdown-item v-if="'view'===curComponent.type" icon="el-icon-link" @click.native="linkageSetting">{{ $t('panel.linkage_setting') }}</el-dropdown-item> <el-dropdown-item v-if="'view'===curComponent.type" icon="el-icon-link" @click.native="linkageSetting">{{ $t('panel.linkage_setting') }}</el-dropdown-item>
<el-dropdown-item v-if="'de-tabs'===curComponent.type" icon="el-icon-link" @click.native="addTab">新增Tab</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
</div> </div>
...@@ -137,6 +138,9 @@ export default { ...@@ -137,6 +138,9 @@ export default {
getViewLinkageGather(requestInfo).then(rsp => { getViewLinkageGather(requestInfo).then(rsp => {
this.$store.commit('setLinkageInfo', rsp.data) this.$store.commit('setLinkageInfo', rsp.data)
}) })
},
addTab() {
bus.$emit('add-new-tab')
} }
} }
} }
......
...@@ -630,7 +630,7 @@ export default { ...@@ -630,7 +630,7 @@ export default {
this.$refs.wrapperChild[index].openChartDetailsDialog() this.$refs.wrapperChild[index].openChartDetailsDialog()
}, },
resizestop(index, item) { resizestop(index, item) {
if (item.type === 'view') { if (item.type === 'view' || item.type === 'de-tabs') {
this.$refs.wrapperChild[index].chartResize() this.$refs.wrapperChild[index].chartResize()
} }
} }
......
...@@ -162,6 +162,13 @@ const list = [ ...@@ -162,6 +162,13 @@ const list = [
borderColor: '#000000', borderColor: '#000000',
backgroundColor: '#ffffff', backgroundColor: '#ffffff',
borderRadius: 0 borderRadius: 0
},
options: {
tabList: [{
title: 'Tab1',
name: '1',
content: null
}]
} }
}, },
{ {
......
<template> <template>
<div> <div class="de-tabs-div">
<el-tabs v-model="editableTabsValue" type="card" addable @edit="handleTabsEdit"> <el-tabs v-model="activeTabName" type="card" class="de-tabs">
<el-tab-pane <el-tab-pane
v-for="(item, index) in tabList" v-for="(item, index) in tabList"
:key="item.name+index" :key="item.name+index"
:lazy="true"
:name="item.name" :name="item.name"
> >
<span slot="label">
<span>{{ item.title }}</span>
<el-dropdown slot="label" :disabled="!isEdit" class="de-tab-drop" trigger="click" @command="handleCommand"> <el-dropdown v-if="isEdit" slot="label" class="de-tab-drop" trigger="click" @command="handleCommand">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
<span>{{ item.title }}</span> <!-- <span>{{ item.title }}</span> -->
<i v-if="isEdit" class="de-tab-i el-icon-arrow-down el-icon--right" /> <i v-if="isEdit" class="de-tab-i el-icon-arrow-down el-icon--right" />
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="beforeHandleCommond('editTitle', item)"> <el-dropdown-item :command="beforeHandleCommond('editTitle', item)">
编辑标题 编辑标题
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item :command="beforeHandleCommond('selectView', item)"> <el-dropdown-item :command="beforeHandleCommond('selectView', item)">
选择视图 选择视图
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item :command="beforeHandleCommond('deleteCur', item)"> <el-dropdown-item v-if="tabList.length > 1" :command="beforeHandleCommond('deleteCur', item)">
删除 删除
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
</span>
<div class="de-tab-content"> <div class="de-tab-content">
<user-view v-if="item.viewInfo" :element="item.viewInfo" /> <user-view v-if="item.content" :ref="item.name" :element="item.content" :out-style="outStyle" />
</div> </div>
</el-tab-pane> </el-tab-pane>
...@@ -82,7 +86,9 @@ ...@@ -82,7 +86,9 @@
import ViewSelect from '@/views/panel/ViewSelect' import ViewSelect from '@/views/panel/ViewSelect'
import { uuid } from 'vue-uuid' import { uuid } from 'vue-uuid'
import bus from '@/utils/bus'
import componentList from '@/components/canvas/custom-component/component-list' import componentList from '@/components/canvas/custom-component/component-list'
export default { export default {
name: 'DeTabls', name: 'DeTabls',
components: { ViewSelect }, components: { ViewSelect },
...@@ -90,31 +96,37 @@ export default { ...@@ -90,31 +96,37 @@ export default {
element: { element: {
type: Object, type: Object,
default: null default: null
},
isEdit: {
type: Boolean,
default: true
},
outStyle: {
type: Object,
required: false,
default: function() {
return {}
}
} }
}, },
data() { data() {
return { return {
editableTabsValue: '1', activeTabName: null,
editableTabs: [{
title: 'Tab 1',
name: '1',
content: ''
}],
tabIndex: 1, tabIndex: 1,
isEdit: true, // isEdit: true,
dialogVisible: false, dialogVisible: false,
textarea: '', textarea: '',
curItem: null, curItem: null,
viewDialogVisible: false, viewDialogVisible: false,
curViewInfo: null, tabList: []
tabList: [],
options: null
} }
}, },
created() { created() {
this.options = this.element.options bus.$on('add-new-tab', this.addNewTab)
this.tabList = this.options && this.options.tabList || this.editableTabs this.tabList = this.element.options && this.element.options.tabList
this.activeTabName = this.tabList[0].name
}, },
methods: { methods: {
beforeHandleCommond(item, param) { beforeHandleCommond(item, param) {
...@@ -136,6 +148,11 @@ export default { ...@@ -136,6 +148,11 @@ export default {
break break
} }
}, },
selectView(param) {
this.activeTabName = param.name
this.curItem = param
this.viewDialogVisible = true
},
sureViewSelector() { sureViewSelector() {
const nodes = this.$refs.viewSelect.getCurrentSelected() const nodes = this.$refs.viewSelect.getCurrentSelected()
const node = nodes[0] const node = nodes[0]
...@@ -162,12 +179,20 @@ export default { ...@@ -162,12 +179,20 @@ export default {
component.id = newComponentId component.id = newComponentId
component.style.width = '100%' component.style.width = '100%'
component.style.height = '100%' component.style.height = '100%'
this.curItem.viewInfo = component this.curItem.content = component
this.curItem.name = newComponentId this.curItem.name = newComponentId
this.viewDialogVisible = false this.viewDialogVisible = false
this.activeTabName = newComponentId
this.styleChange()
// this.setComponentInfo()
},
setComponentInfo() {
console.log('aaa')
}, },
editCurTitle(param) { editCurTitle(param) {
this.activeTabName = param.name
this.curItem = param this.curItem = param
this.textarea = param.title this.textarea = param.title
this.dialogVisible = true this.dialogVisible = true
...@@ -175,48 +200,57 @@ export default { ...@@ -175,48 +200,57 @@ export default {
sureCurTitle() { sureCurTitle() {
this.curItem.title = this.textarea this.curItem.title = this.textarea
this.dialogVisible = false this.dialogVisible = false
this.styleChange()
}, },
deleteCur(param) { deleteCur(param) {
},
selectView(param) {
this.curItem = param this.curItem = param
this.viewDialogVisible = true let len = this.element.options.tabList.length
}, while (len--) {
if (this.element.options.tabList[len].name === param.name) {
handleTabsEdit(targetName, action) { this.element.options.tabList.splice(len, 1)
if (action === 'add') { this.tabList = this.element.options.tabList
const newTabName = ++this.tabIndex + '' const activIndex = (len - 1 + this.element.options.tabList.length) % this.element.options.tabList.length
this.editableTabs.push({ this.activeTabName = this.element.options.tabList[activIndex].name
title: 'New Tab',
name: newTabName,
content: 'New Tab content'
})
this.editableTabsValue = newTabName
}
if (action === 'remove') {
const tabs = this.editableTabs
let activeName = this.editableTabsValue
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
const nextTab = tabs[index + 1] || tabs[index - 1]
if (nextTab) {
activeName = nextTab.name
}
}
})
} }
}
this.styleChange()
},
this.editableTabsValue = activeName addNewTab() {
this.editableTabs = tabs.filter(tab => tab.name !== targetName) const curName = uuid.v1()
const tab = {
title: 'NewTab',
name: curName,
content: null
} }
this.element.options.tabList.push(tab)
this.tabList = this.element.options.tabList
this.styleChange()
},
styleChange() {
this.$store.state.styleChangeTimes++
},
chartResize() {
// this.$refs[this.activeTabName]
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.de-tabs-div {
height: 100%;
}
.de-tabs {
height: 100%;
>>>div.el-tabs__content {
height: calc(100% - 55px);
.el-tab-pane {
height: 100%;
}
}
}
.de-tab-i { .de-tab-i {
transition: 0.3s; transition: 0.3s;
opacity: 0; opacity: 0;
...@@ -228,8 +262,8 @@ export default { ...@@ -228,8 +262,8 @@ export default {
transform: translateY(0); transform: translateY(0);
} }
.de-tab-content { .de-tab-content {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论