WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2022-03-08 d7b9586e7e6c0fc62b0f8e326fc7c94c402768e2
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/**
 * mixins
 * @author Tevin
 */
 
 
/**
 * 全局颜色
 */
$colorStress: #2093df;
$colorSuccess: #22c322;
$colorInfo: #05b7c7;
$colorWarning: #db9d00;
$colorDanger: #FF5722;
$colorIgnore: rgba(0, 0, 0, 0.45);
 
/**
 * clearfix - 清除浮动
 * 示例
 *   @include clearfix;
 */
@mixin clearfix() {
    &:after {
        clear: both;
        display: block;
        width: 100%;
        height: 0px;
        overflow: hidden;
        content: " ";
    }
}
 
/**
 * ellipsis - 省略号
 * 示例
 *   @include ellipsis;
 *   @include ellipsis(100%);
 * 参数
 *   $width 宽度
 */
@mixin ellipsis($width:false) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    @if ($width) {
        width: $width;
    }
}
 
/**
 * position 元素定位的简写
 * 示例
 *   @include position(absolute, 0 0);
 *   @include position(absolute, 0 n n 0, 100);
 * 参数
 *   $type 定位类型
 *   $values 定位值
 *   $zindex 定位层级
 */
@mixin position($type, $values:(), $zindex:false) {
    position: $type;
    // 当 1 个值时:上
    @if (length($values)==1) {
        @if (nth($values, 1) !=n) {
            top: nth($values, 1);
        }
    }
    // 当 2 个值时:上、左
    @else if (length($values)==2) {
        @if (nth($values, 1) !=n) {
            top: nth($values, 1);
        }
        @if (nth($values, 2) !=n) {
            left: nth($values, 2);
        }
    }
    // 当 3 个值时:上、左右、下
    @else if (length($values)==3) {
        @if (nth($values, 1) !=n) {
            top: nth($values, 1);
        }
        @if (nth($values, 2) !=n) {
            right: nth($values, 2);
            left: nth($values, 2);
        }
        @if (nth($values, 3) !=n) {
            bottom: nth($values, 3);
        }
    }
    // 当 4 个值时:上、左、下、右
    @else if (length($values)==4) {
        @if (nth($values, 1) !=n) {
            top: nth($values, 1);
        }
        @if (nth($values, 2) !=n) {
            left: nth($values, 2);
        }
        @if (nth($values, 3) !=n) {
            bottom: nth($values, 3);
        }
        @if (nth($values, 4) !=n) {
            right: nth($values, 4);
        }
    }
    @if ($zindex) {
        z-index: $zindex;
    }
}
 
/**
 * flex 适应布局
 * 示例
 *   @include flexbox(flex, center center);
 * 参数
 *   $mode 布局类型
 *     flex / inline
 *   $align 对齐方式
 *     <justify-content> 主轴对齐方式
 *       flex-start / flex-end / center / space-between / space-around
 *     <align-items> 交叉轴对齐方式
 *       flex-start / flex-end / center / baseline / stretch
 *     <align-content> 多轴对齐方式(把每根轴视为一个单元,指定所有单元的对齐方式)
 *       flex-start / flex-end / center / space-between / space-around / stretch
 *   $flow 排列方式
 *     <flex-direction> 主轴方向
 *       row / row-reverse / column / column-reverse
 *     <flex-wrap> 换行方式
 *       nowrap / wrap / wrap-reverse
 */
@mixin flexbox ($mode:flex, $align:(), $flow:()) {
    @if ($mode=="flex") {
        display: -webkit-box;
        display: -webkit-flex;
        display: -moz-flex;
        display: flex;
    }
    @else if($mode=="inline") {
        display: -webkit-inline-box;
        display: -webkit-inline-flex;
        display: -moz-inline-flex;
        display: inline-flex;
    }
    @if (length($align)>=1) {
        @if (nth($align, 1) !=n) {
            -webkit-justify-content: nth($align, 1);
            -moz-justify-content: nth($align, 1);
            justify-content: nth($align, 1);
        }
    }
    @if(length($align)>=2) {
        @if (nth($align, 2) !=n) {
            -webkit-align-items: nth($align, 2);
            -moz-align-items: nth($align, 2);
            align-items: nth($align, 2);
        }
    }
    @if(length($align)>=3) {
        @if (nth($align, 3) !=n) {
            -webkit-align-content: nth($align, 3);
            -moz-align-content: nth($align, 3);
            align-content: nth($align, 3);
        }
    }
    @if (length($flow)>=1) {
        @if (nth($flow, 1) !=n) {
            -webkit-flex-direction: nth($flow, 1);
            -moz-flex-direction: nth($flow, 1);
            flex-direction: nth($flow, 1);
        }
    }
    @if (length($flow)>=2) {
        @if (nth($flow, 2) !=n) {
            -webkit-flex-wrap: nth($flow, 2);
            -moz-flex-wrap: nth($flow, 2);
            flex-wrap: nth($flow, 2);
        }
    }
}
 
/** 
 * keyframes - css 动画简写
 * 示例
 *   @include keyframes(fade-out) {
 *      0% { opacity: 1 }
 *      100% { opacity: 0 }
 *   }
 */
@mixin keyframes($name) {
    @-webkit-keyframes #{$name} {
        @content;
    }
    @-moz-keyframes #{$name} {
        @content;
    }
    @keyframes #{$name} {
        @content;
    }
}
 
/**
 * media - 媒体查询简写
 * 示例
 *   @include media(phone) {
 *       .logo {
 *           display: none;
 *       }
 *   }
 * 参数
 *   $type 指定媒体类型生效,print、pc、padpro、padmini、phone
 *   $only 是否只在此媒体类型生效
 */
@mixin media($type, $only:"") {
    $title: "";
    // 打印媒体
    @if ($type=="print") {
        $title: $title + "print";
    }
    // 显示器媒体
    @else {
        $title: $title + "screen";
        @if ($type=="pc") {
            // 仅电脑
            @if ($only=="only") {
                $title: $title + " and (min-width: 992px)";
            }
            // 所有设备
            @else {}
        }
        @else if ($type=="padpro") {
            // 仅大平板
            @if ($only=="only") {
                $title: $title + " and (min-width: 768px) and (max-width: 992px)";
            }
            // 所有平板和手机
            @else {
                $title: $title + " and (max-width: 992px)";
            }
        }
        @else if ($type=="padmini") {
            // 仅小平板
            @if ($only=="only") {
                $title: $title + " and (min-width: 480px) and (max-width: 768px)";
            }
            // 小平板和手机
            @else {
                $title: $title + " and (max-width: 768px)";
            }
        }
        @else if ($type=="phone") {
            // 仅手机
            $title: $title + " and (max-width: 480px)";
        }
    }
    @media #{$title} {
        @content;
    }
}