Blame view

node_modules/uview-ui/libs/mixin/style.js 6.89 KB
c7add6cf   “wangming”   初始版本开发完毕
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
  export default {

      props: {

          // flex排列方式

          flexDirection: {

              type: String,

              default: ''

          },

          // flex-direction的简写

          fd: {

              type: String,

              default: ''

          },

          // 展示类型

          display: {

              type: String,

              default: ''

          },

          // display简写

          d: {

              type: String,

              default: ''

          },

          // 主轴排列方式

          justifyContent: {

              type: String,

              default: ''

          },

          // justifyContent的简写

          jc: {

              type: String,

              default: ''

          },

          // 纵轴排列方式

          alignItems: {

              type: String,

              default: ''

          },

          // align-items的简写

          ai: {

              type: String,

              default: ''

          },

          color: {

              type: String,

              default: ''

          },

          // color简写

          c: {

              type: String,

              default: ''

          },

          // 字体大小

          fontSize: {

              type: [String, Number],

              default: 0

          },

          // font-size简写

          fs: {

              type: [String, Number],

              default: ''

          },

          margin: {

              type: [String, Number],

              default: 0

          },

          // margin简写

          m: {

              type: [String, Number],

              default: 0

          },

          // margin-top

          marginTop: {

              type: [String, Number],

              default: 0

          },

          // margin-top简写

          mt: {

              type: [String, Number],

              default: 0

          },

          // margin-right

          marginRight: {

              type: [String, Number],

              default: 0

          },

          // margin-right简写

          mr: {

              type: [String, Number],

              default: 0

          },

          // margin-bottom

          marginBottom: {

              type: [String, Number],

              default: 0

          },

          // margin-bottom简写

          mb: {

              type: [String, Number],

              default: 0

          },

          // margin-left

          marginLeft: {

              type: [String, Number],

              default: 0

          },

          // margin-left简写

          ml: {

              type: [String, Number],

              default: 0

          },

          // padding-left

          paddingLeft: {

              type: [String, Number],

              default: 0

          },

          // padding-left简写

          pl: {

              type: [String, Number],

              default: 0

          },

          // padding-top

          paddingTop: {

              type: [String, Number],

              default: 0

          },

          // padding-top简写

          pt: {

              type: [String, Number],

              default: 0

          },

          // padding-right

          paddingRight: {

              type: [String, Number],

              default: 0

          },

          // padding-right简写

          pr: {

              type: [String, Number],

              default: 0

          },

          // padding-bottom

          paddingBottom: {

              type: [String, Number],

              default: 0

          },

          // padding-bottom简写

          pb: {

              type: [String, Number],

              default: 0

          },

          // border-radius

          borderRadius: {

              type: [String, Number],

              default: 0

          },

          // border-radius简写

          radius: {

              type: [String, Number],

              default: 0

          },

          // transform

          transform: {

              type: String,

              default: ''

          },

          // 定位

          position: {

              type: String,

              default: ''

          },

          // position简写

          pos: {

              type: String,

              default: ''

          },

          // 宽度

          width: {

              type: [String, Number],

              default: null

          },

          // width简写

          w: {

              type: [String, Number],

              default: null

          },

          // 高度

          height: {

              type: [String, Number],

              default: null

          },

          // height简写

          h: {

              type: [String, Number],

              default: null

          },

          top: {

              type: [String, Number],

              default: 0

          },

          right: {

              type: [String, Number],

              default: 0

          },

          bottom: {

              type: [String, Number],

              default: 0

          },

          left: {

              type: [String, Number],

              default: 0

          }

      },

      computed: {

          viewStyle() {

              const style = {}

              const addStyle = uni.$u.addStyle(this.width || this.w) && (style.width = addStyle(this.width || this.w))(this.height || this.h) && (style.height = addStyle(this.height || this.h))(this.margin || this.m) && (style.margin = addStyle(this.margin || this.m))(this.marginTop || this.mt) && (style.marginTop = addStyle(this.marginTop || this.mt))(this.marginRight || this.mr) && (style.marginRight = addStyle(this.marginRight || this.mr))(this.marginBottom || this.mb) && (style.marginBottom = addStyle(this.marginBottom || this.mb))(this.marginLeft || this.ml) && (style.marginLeft = addStyle(this.marginLeft || this.ml))(this.padding || this.p) && (style.padding = addStyle(this.padding || this.p))(this.paddingTop || this.pt) && (style.paddingTop = addStyle(this.paddingTop || this.pt))(this.paddingRight || this.pr) && (style.paddingRight = addStyle(this.paddingRight || this.pr))(this.paddingBottom || this.pb) && (style.paddingBottom = addStyle(this.paddingBottom || this.pb))(this.paddingLeft || this.pl) && (style.paddingLeft = addStyle(this.paddingLeft || this.pl))(this.color || this.c) && (style.color = this.color || this.c)(this.fontSize || this.fs) && (style.fontSize = this.fontSize || this.fs)(this.borderRadius || this.radius) && (style.borderRadius = this.borderRadius || this.radius)(this.position || this.pos) && (this.position = this.position || this.pos)(this.flexDirection || this.fd) && (this.flexDirection = this.flexDirection || this.fd)(this.justifyContent || jc) && (this.justifyContent = this.justifyContent || jc)(this.alignItems || ai) && (this.alignItems = this.alignItems || ai)

  

              return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))

          }

      },

      methods: {

          // 获取margin或者padding的单位,比如padding: 0 20转为padding: 0 20px

          getUnit(unit = '') {

              // 取出两端空格,分隔成数组,再对数组的每个元素添加单位,最后再合并成字符串

              return uni.$u.trim(unit).split(' ').map((item) => uni.$u.addUnit(item)).join(' ')

          }

      }

  }