-
Notifications
You must be signed in to change notification settings - Fork 580
/
card.js
210 lines (206 loc) · 5.15 KB
/
card.js
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
export default class LastMayday {
palette() {
return ({
width: '654rpx',
height: '1000rpx',
background: '#eee',
views: [
_textDecoration('overline', 0),
_textDecoration('underline', 1),
_textDecoration('line-through', 2),
_textDecoration('overline underline line-through', 3, 'red'),
{
type: 'rect',
css: {
width: '200rpx',
right: '20rpx',
top: '30rpx',
height: '100rpx',
borderRadius: '100%',
shadow: '10rpx 10rpx 5rpx #888888',
color: 'linear-gradient(-135deg, #fedcba 0%, rgba(18, 52, 86, 1) 20%, #987 80%)',
},
},
{
id: 'my_text_id',
type: 'text',
text: "fontWeight: 'bold'",
css: [{
top: `${startTop 4 * gapSize}rpx`,
shadow: '10rpx 10rpx 5rpx #888888',
fontWeight: 'bold',
}, common],
},
{
type: 'rect',
css: {
width: '20rpx',
height: '20rpx',
color: 'red',
left: 'calc(my_text_id.right 20rpx)',
top: `${startTop 4 * gapSize 15}rpx`,
},
},
{
id: 'text_id_2',
type: 'text',
text: '我是把width设置为400rpx后,我就换行了xx行了',
css: [{
top: `${startTop 5 * gapSize}rpx`,
align: 'center',
width: '400rpx',
background: '#538e60',
textAlign: 'center',
padding: '10rpx',
scalable: true,
deletable: true,
}, common, { left: '300rpx' }],
},
{
type: 'rect',
css: {
width: '20rpx',
height: '20rpx',
color: 'red',
left: '200rpx',
top: 'calc(text_id_2.bottom 20rpx)',
},
},
{
type: 'text',
text: '我设置了maxLines为1,看看会产生什么效果',
css: [{
top: `${startTop 7 * gapSize}rpx`,
width: '500rpx',
maxLines: 1,
}, common],
},
_image(0),
_des(0, '普通'),
_image(1, 30),
_des(1, 'rotate: 30'),
_image(2, 30, '20rpx'),
_des(2, 'borderRadius: 30rpx'),
_image(3, 0, '60rpx'),
_des(3, '圆形'),
{
type: 'image',
url: '/palette/avatar.jpg',
css: {
bottom: '40rpx',
left: '40rpx',
borderRadius: '50rpx',
borderWidth: '10rpx',
borderColor: 'yellow',
width: '100rpx',
height: '100rpx',
},
},
{
type: 'qrcode',
content: 'https://github.com/Kujiale-Mobile/Painter',
css: {
bottom: '40rpx',
left: '180rpx',
color: 'red',
borderWidth: '10rpx',
borderColor: 'blue',
borderStyle: 'dashed',
width: '120rpx',
height: '120rpx',
},
},
{
id: 'rect',
type: 'rect',
css: {
scalable: true,
bottom: '40rpx',
right: '40rpx',
color: 'radial-gradient(rgba(0, 0, 0, 0) 5%, #0ff 15%, #f0f 60%)',
borderRadius: '20rpx',
borderWidth: '10rpx',
width: '120rpx',
height: '120rpx',
},
},
{
type: 'text',
text: 'borderWidth',
css: {
bottom: '40rpx',
right: '200rpx',
color: 'green',
borderWidth: '2rpx',
},
},
{
type: 'rect',
css: {
width: '100rpx',
height: '100rpx',
color: 'rgba(0,0,0,0.2)',
left: '50%',
top: '50%',
align: 'center',
verticalAlign: 'center',
}
}
],
});
}
}
const startTop = 50;
const startLeft = 20;
const gapSize = 70;
const common = {
left: `${startLeft}rpx`,
fontSize: '40rpx',
};
function _textDecoration(decoration, index, color) {
return ({
type: 'text',
text: decoration,
css: [{
top: `${startTop index * gapSize}rpx`,
color: color,
textDecoration: decoration,
}, common],
});
}
function _image(index, rotate, borderRadius) {
return (
{
id: `image-${index}`,
type: 'image',
url: '/palette/avatar.jpg',
css: {
top: `${startTop 8.5 * gapSize}rpx`,
left: `${startLeft 160 * index}rpx`,
width: '120rpx',
height: '120rpx',
shadow: '10rpx 10rpx 5rpx #888888',
rotate: rotate,
minWidth: '60rpx',
borderRadius: borderRadius,
scalable: true,
},
}
);
}
function _des(index, content) {
const des = {
type: 'text',
text: content,
css: {
fontSize: '22rpx',
top: `${startTop 8.5 * gapSize 140}rpx`,
},
};
if (index === 3) {
des.css.right = '60rpx';
} else {
des.css.left = `${startLeft 120 * index 30}rpx`;
}
return des;
}