朱桂飞
2024-08-01 6959c1d4ee2244691603ab1f471b750ac517725d
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 *  uni-app 表格样式表
 *  作者:helang
 *  邮箱:helang.love@qq.com
*/
 
.h-table{
    /* 行 */
    .h-tr{
        box-sizing: border-box;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: stretch;
        align-content: center;
        
        border-color: #ccc;
        border-style: solid;
        border-width: 0;
        border-top-width: 1px;
        border-left-width: 1px;
        border-bottom-width: 1px;
        color: #333;
        
        /* 等比分列,1-6列 */
        @for $i from 1 through 18
        {
            &-#{$i}{
                >.h-td{
                    width:(100% / $i);
                }
            }
        }
        
        + .h-tr{
            border-top-style: none;
        }
    }
    /* 单元格 */
    .h-td{
        box-sizing: border-box;
        padding: 3px;
        word-break:break-all;
        border-color: #ccc;
        border-style: solid;
        border-width: 0;
        border-right-width: 1px;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
        align-content: center;
        min-height: 64rpx;
        
        /* 跨列 */
        &-colspan{
            flex-grow: 1;
            width:0;
        }
        
        &-rowspan{
            // border: none;
            border-right-width: 0;
            padding: 0 !important;
            flex-wrap: wrap !important;
            
            >.h-tr{
                width: 100%;
                border-width: 0;
                
                .h-td{
                    border-right-width: 1px;
                }
                
                & + .h-tr{
                    border-top-width: 1px;
                    border-top-style: solid;
                }
            }
        }
        
        /* 内容顶部对齐 */
        &-top{
            align-items: flex-start;
            align-content:flex-start;
        }
        /* 内容底部对齐 */
        &-bottom{
            align-items: flex-end;
            align-content:flex-end;
        }
        /* 内容左边对齐 */
        &-left{
            justify-content: flex-start;
        }
        /* 内容右边对齐 */
        &-right{
            justify-content: flex-end;
        }
    }
    /* 表头 */
    .h-thead{
        background-color: #e6e6e6;
    }
    
    /* 表格虚线 */
    &-dashed{
        .h-tr{
            border-top-style: dashed;
            border-left-style: dashed;
            border-bottom-style: dashed;
        }
        .h-td{
            border-right-style: dashed;
        }
        
        .h-td-rowspan{
            .h-tr + .h-tr{
                border-top-style: dashed;
            }
        }
    }
    
    /* 表格主题 Map,颜色摘自 Bootstrap */
    $theme-table:(
        primary:(
            color:#fff,
            bgColor:#337ab7,
            border:#2e6da4
        ),
        success:(
            color:#fff,
            bgColor:#5cb85c,
            border:#4cae4c
        ),
        info:(
            color:#fff,
            bgColor:#5bc0de,
            border:#46b8da
        ),
        warning:(
            color:#fff,
            bgColor:#f0ad4e,
            border:#eea236
        ),
        danger:(
            color:#fff,
            bgColor:#d9534f,
            border:#d43f3a
        )
    );
    
    /* 生成主题代码 */
    $theme-table-keys:map-keys($theme-table);
    @each $k in $theme-table-keys {
        $item:map-get($theme-table,$k);
        &-#{$k}{
            .h-tr{
                border-top-color: map-get($item,border);
                border-left-color: map-get($item,border);
                border-bottom-color: map-get($item,border);
                color: map-get($item,bgColor);
            }
            .h-td{
                border-right-color: map-get($item,border);
                
            }
            .h-thead{
                background-color: map-get($item,bgColor);
                color: map-get($item,color);
            }
        }
    }
}