gaoshp
2024-06-13 fd7586c8d91473d2850af1e48b12f1a289e6b8d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
    <div v-if="usercolumn.length>0" class="setting-column" v-loading="isSave">
        <div class="setting-column__title">
            <span class="move_b"></span>
            <span class="show_b">显示</span>
            <span class="name_b">名称</span>
            <span class="width_b">宽度</span>
            <span class="sortable_b">排序</span>
            <span class="fixed_b">固定</span>
        </div>
        <div class="setting-column__list" ref="list">
            <ul>
                <li v-for="item in usercolumn" :key="item.prop">
                    <span class="move_b">
                        <el-tag class="move" style="cursor: move;"><el-icon-d-caret style="width: 1em; height: 1em;"/></el-tag>
                    </span>
                    <span class="show_b">
                        <el-switch v-model="item.hide" :active-value="false" :inactive-value="true"></el-switch>
                    </span>
                    <span class="name_b" :title="item.prop">{{ item.label }}</span>
                    <span class="width_b">
                        <el-input v-model="item.width" placeholder="auto" size="small"></el-input>
                    </span>
                    <span class="sortable_b">
                        <el-switch v-model="item.sortable"></el-switch>
                    </span>
                    <span class="fixed_b">
                        <el-switch v-model="item.fixed"></el-switch>
                    </span>
                </li>
            </ul>
        </div>
        <div class="setting-column__bottom">
            <el-button @click="backDefaul" :disabled="isSave">重置</el-button>
            <el-button @click="save" type="primary">保存</el-button>
        </div>
    </div>
    <el-empty v-else description="暂无可配置的列" :image-size="80"></el-empty>
</template>
 
<script>
    import Sortable from 'sortablejs'
 
    export default {
        components: {
            Sortable
        },
        props: {
            column: { type: Object, default: () => {} }
        },
        data() {
            return {
                isSave: false,
                usercolumn: JSON.parse(JSON.stringify(this.column||[]))
            }
        },
        watch:{
            usercolumn: {
                handler(){
                    this.$emit('userChange', this.usercolumn)
                },
                deep: true
            }
        },
        mounted() {
            this.usercolumn.length>0 && this.rowDrop()
        },
        methods: {
            rowDrop(){
                const _this = this
                const tbody = this.$refs.list.querySelector('ul')
                Sortable.create(tbody, {
                    handle: ".move",
                    animation: 300,
                    ghostClass: "ghost",
                    onEnd({ newIndex, oldIndex }) {
                        const tableData = _this.usercolumn
                        const currRow = tableData.splice(oldIndex, 1)[0]
                        tableData.splice(newIndex, 0, currRow)
                    }
                })
            },
            backDefaul(){
                this.$emit('back', this.usercolumn)
            },
            save(){
                this.$emit('save', this.usercolumn)
            }
        }
    }
</script>
 
<style scoped>
    .setting-column {}
 
    .setting-column__title {border-bottom: 1px solid #EBEEF5;padding-bottom:15px;}
    .setting-column__title span {display: inline-block;font-weight: bold;color: #909399;font-size: 12px;}
    .setting-column__title span.move_b {width: 30px;margin-right:15px;}
    .setting-column__title span.show_b {width: 60px;}
    .setting-column__title span.name_b {width: 140px;}
    .setting-column__title span.width_b {width: 60px;margin-right:15px;}
    .setting-column__title span.sortable_b {width: 60px;}
    .setting-column__title span.fixed_b {width: 60px;}
 
    .setting-column__list {max-height:314px;overflow: auto;}
    .setting-column__list li {list-style: none;margin:10px 0;display: flex;align-items: center;}
    .setting-column__list li>span {display: inline-block;font-size: 12px;}
    .setting-column__list li span.move_b {width: 30px;margin-right:15px;}
    .setting-column__list li span.show_b {width: 60px;}
    .setting-column__list li span.name_b {width: 140px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;cursor:default;}
    .setting-column__list li span.width_b {width: 60px;margin-right:15px;}
    .setting-column__list li span.sortable_b {width: 60px;}
    .setting-column__list li span.fixed_b {width: 60px;}
    .setting-column__list li.ghost {opacity: 0.3;}
 
    .setting-column__bottom {border-top: 1px solid #EBEEF5;padding-top:15px;text-align: right;}
    
    .dark .setting-column__title {border-color: var(--el-border-color-light);}
    .dark .setting-column__bottom {border-color: var(--el-border-color-light);}
</style>