Commit 70df6457 by luyt

feat:table配置初版

1 parent 4abc56ab
...@@ -44,38 +44,7 @@ ...@@ -44,38 +44,7 @@
<hr /> <hr />
<h3>el-table调整</h3> <h3>el-table调整</h3>
<i class="gl-icon-question"></i> <i class="gl-icon-question"></i>
<div style="margin-left: 300px;"> <GLTableOption @change="changeFn" :optionsList="optionsList"></GLTableOption>
<el-popover popper-class="gl-col" width="260" trigger="click">
<div>
<div class="gl-title">
表头字段配置
<el-tooltip
content="点击字段前的图标可拖动位置"
popper-class="gl-tip"
placement="bottom"
effect="light"
>
<i class="gl-icon-question"></i>
</el-tooltip>
</div>
<div class="gl-content">
<el-checkbox-group v-model="checkList">
<vuedraggable v-model="optionsList" draggable=".item" group="tableClomns" animation="1000" @onStart="startHook" @onEnd="endHook">
<transition-group>
<el-checkbox :class="{'item':!disabledList.includes(item.id)}" v-for="(item,index) in optionsList" :label="item.id" :key="'tableOpt'+index" :disabled="disabledList.includes(item.id)">{{item.name}}</el-checkbox>
</transition-group>
</vuedraggable>
</el-checkbox-group>
</div>
<div class="gl-btns">
<el-button plain size="small" class="btn-three">重置</el-button>
<el-button type="primary" size="small">确定</el-button>
</div>
</div>
<el-button plain size="small" class="btn-three" icon="gl-icon-cog-fill" round slot="reference"></el-button>
</el-popover>
</div>
<GLTable ref="liveRoomRef" :tableParams="tableParams" :tableData="tableData" max-height="250"> <GLTable ref="liveRoomRef" :tableParams="tableParams" :tableData="tableData" max-height="250">
<span slot="shareImgUrl" slot-scope="scope"> <span slot="shareImgUrl" slot-scope="scope">
<img class="img-60" :src="scope.scope.shareImgUrl" /> <img class="img-60" :src="scope.scope.shareImgUrl" />
...@@ -255,7 +224,6 @@ ...@@ -255,7 +224,6 @@
</div> </div>
</template> </template>
<script> <script>
import vuedraggable from 'vuedraggable'
export default { export default {
name: 'App', name: 'App',
data() { data() {
...@@ -834,31 +802,34 @@ export default { ...@@ -834,31 +802,34 @@ export default {
activeName: 'tab0', activeName: 'tab0',
tabPaneList: [], tabPaneList: [],
//测试table配置项 //测试table配置项
checkList: ['1','4'],
optionsList: [ optionsList: [
{ {
id:'1', label: '复选框A',
name: '复选框A', prop: 'liveStatus1',
checkItem: true,
}, },
{ {
id:'2', label: '复选框b',
name: '复选框b' prop: 'liveStatus2',
}, },
{ {
id:'5', label: '复选框c',
name: '复选框c' prop: 'liveStatus3',
}, },
{ {
id:'3', label: '禁用',
name: '禁用' prop: 'liveStatus4',
disabledCheck: true,
order: 1
}, },
{ {
id:'4', label: '选中禁用',
name: '选中且禁用', prop: 'liveStatus5',
checkItem: true,
disabledCheck: true,
order: 2 //数值越大越靠前
}, },
], ],
disabledList:['3','4']
} }
}, },
mounted() { mounted() {
...@@ -1177,21 +1148,11 @@ export default { ...@@ -1177,21 +1148,11 @@ export default {
// console.log(val, '删除') // console.log(val, '删除')
}, },
//测试table配置项 //测试table配置项
startHook(){ changeFn(checkList,checkAttrList){
console.log('onStart: ', onStart); console.log('checkList,checkAttrList: ', checkList,checkAttrList);
},
endHook(){
console.log('onEnd: ', onEnd);
},
},
components: {
vuedraggable
},
watch:{
checkList (val, oldVal) {
console.log('new: %s, old: %s', val, oldVal)
} }
} }
} }
</script> </script>
...@@ -1212,34 +1173,5 @@ export default { ...@@ -1212,34 +1173,5 @@ export default {
color: red; color: red;
} }
// 配置表单项
.gl-col {
.gl-title {
}
.gl-content {
margin-top: 10px;
padding-top: 10px;
padding-bottom: 10px;
border-top: 1px solid #e8e8ea;
border-bottom: 1px solid #e8e8ea;
}
.gl-btns {
padding-top: 16px;
padding-bottom: 6px;
text-align: right;
}
}
.gl-tip.el-tooltip__popper.is-light {
color: #666666;
border: 0;
box-shadow: 0 4px 12px 0 rgba(0,0,0,0.08);
.popper__arrow{
border-bottom-color: rgba(0,0,0,0.05) !important;
// box-shadow: 0 -4px 12px 0 rgba(0,0,0,0.1);
&:after{
// display: none;
// border: 0;
}
}
}
</style> </style>
import GLTableOption from './src/index.vue'
// 为组件提供 install 安装方法,供按需引入
GLTableOption.install = function(Vue) {
Vue.component(GLTableOption.name, GLTableOption)
}
// 默认导出组件
export default GLTableOption
<template>
<el-popover popper-class="gl-col" width="260" trigger="click">
<div>
<div class="gl-title">
表头字段配置
<el-tooltip content="点击字段前的图标可拖动位置" popper-class="gl-tip" placement="bottom" effect="light">
<i class="gl-icon-question"></i>
</el-tooltip>
</div>
<div class="gl-content">
<el-checkbox-group v-model="innerValue" @change="changeFn">
<vuedraggable v-model="innerOptionsList" draggable=".item" group="tableClomns" animation="500" @onStart="startHook" @onEnd="endHook">
<transition-group>
<el-checkbox :class="{ item: !disabledList.includes(item[attr]) }" v-for="(item, index) in innerOptionsList" :label="item[attr]" :key="'tableOpt' + index" :disabled="disabledList.includes(item[attr])">{{ item[attrLabel] }}</el-checkbox>
</transition-group>
</vuedraggable>
</el-checkbox-group>
</div>
<div class="gl-btns">
<el-button plain size="small" class="btn-three">重置</el-button>
<el-button type="primary" size="small">确定</el-button>
</div>
</div>
<el-button plain size="small" class="btn-three" icon="gl-icon-cog-fill" round slot="reference"></el-button>
</el-popover>
</template>
<script>
import vuedraggable from 'vuedraggable'
export default {
name: 'GLTableOption',
props: {
// 可选列表
optionsList: {
type: Array,
default: () => []
},
// 默认可选列表关联的属性
attr: {
type: String,
default: 'prop'
},
// 默认可选列表关联的文本属性
attrLabel: {
type: String,
default: 'label'
}
},
data() {
return {
innerValue: [],
innerOptionsList: [],
disabledList:[]
}
},
mounted() {
this.innerOptionsList = this.getOrderList()
this.innerValue = this.getCheckAttrList('checkItem')
this.disabledList = this.getCheckAttrList('disabledCheck')
},
methods: {
// 获取选中项的对应的attr属性数组
getCheckAttrList(propertyName){
return this.innerOptionsList.filter(item=>item[propertyName]).map(item=>item[this.attr])
},
//排序order(将禁用项提前)
getOrderList(){
return this.optionsList.sort((a,b)=>{
if(!a.order)a.order = 0
if(!b.order)b.order = 0
return b.order - a.order
})
},
startHook() {
this.$emit('onStart')
},
endHook() {
//列表顺序
this.$emit('onEnd', innerOptionsList)
},
// 当绑定值变化时触发的事件
changeFn() {
this.$emit('change', this.getCheckList(), this.innerValue)
},
// 获取选中的列表配置项
getCheckList() {
if (this.innerOptionsList.length === 0) return
const resultArr = this.innerOptionsList.filter(item => {
if (this.innerValue.includes(item[this.attr])) {
return item
}
})
return resultArr
}
},
components: {
vuedraggable
}
}
</script>
<style lang="scss">
// 配置表单项
.gl-col {
.gl-title {
}
.gl-content {
margin-top: 10px;
padding-top: 10px;
padding-bottom: 10px;
border-top: 1px solid #e8e8ea;
border-bottom: 1px solid #e8e8ea;
.el-checkbox {
display: block;
}
}
.gl-btns {
padding-top: 16px;
padding-bottom: 6px;
text-align: right;
}
}
.gl-tip.el-tooltip__popper.is-light {
color: #666666;
border: 0;
box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
.popper__arrow {
border-bottom-color: rgba(0, 0, 0, 0.05) !important;
// box-shadow: 0 -4px 12px 0 rgba(0,0,0,0.1);
&:after {
// display: none;
// border: 0;
}
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!