-
Notifications
You must be signed in to change notification settings - Fork 1
/
atom.xml
526 lines (256 loc) · 253 KB
/
atom.xml
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Damao</title>
<subtitle>乐躬耕于陇亩兮,吾爱吾庐。聊寄傲于琴书兮,以待天时。</subtitle>
<link href="http://damao2250.com/atom.xml" rel="self"/>
<link href="http://damao2250.com/"/>
<updated>2025-01-02T07:56:11.393Z</updated>
<id>http://damao2250.com/</id>
<author>
<name>Damao</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>记录邻里邦自动签到接口</title>
<link href="http://damao2250.com/2024/12/26/%E8%AE%B0%E5%BD%95%E9%82%BB%E9%87%8C%E9%82%A6%E8%87%AA%E5%8A%A8%E7%AD%BE%E5%88%B0%E6%8E%A5%E5%8F%A3/"/>
<id>http://damao2250.com/2024/12/26/%E8%AE%B0%E5%BD%95%E9%82%BB%E9%87%8C%E9%82%A6%E8%87%AA%E5%8A%A8%E7%AD%BE%E5%88%B0%E6%8E%A5%E5%8F%A3/</id>
<published>2024-12-26T06:23:40.000Z</published>
<updated>2025-01-02T07:56:11.393Z</updated>
<content type="html"><![CDATA[<h2 id="获取验证码"><a href="#获取验证码" class="headerlink" title="获取验证码"></a>获取验证码</h2><ul><li>接口:<a href="https://m-center-prod-linli.timesgroup.cn/times/pub-center/verifycode/api/v1/send">https://m-center-prod-linli.timesgroup.cn/times/pub-center/verifycode/api/v1/send</a></li><li>请求方法:POST</li><li>请求参数<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 只需要修改 phoneNumber 为自己的手机号码</span><span class="token punctuation">{</span><span class="token string">"phoneNumber"</span><span class="token operator">:</span><span class="token string">"1342341234"</span><span class="token punctuation">,</span><span class="token string">"areaCode"</span><span class="token operator">:</span><span class="token string">"86"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li><li>返回结果<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> <span class="token string">"code"</span><span class="token operator">:</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"data"</span><span class="token operator">:</span><span class="token string">"验证码发送成功"</span><span class="token punctuation">,</span> <span class="token string">"message"</span><span class="token operator">:</span><span class="token string">"success"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="根据验证码获取-token"><a href="#根据验证码获取-token" class="headerlink" title="根据验证码获取 token"></a>根据验证码获取 token</h2><ul><li>接口:<a href="https://m-center-prod-linli.timesgroup.cn/times/times-bff/bff/api-c/v1/oauth/token">https://m-center-prod-linli.timesgroup.cn/times/times-bff/bff/api-c/v1/oauth/token</a></li><li>请求方法:POST</li><li>请求参数<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 修改 username 为自己的手机号码</span><span class="token comment">// 修改 password 为收到的验证码</span><span class="token punctuation">{</span> <span class="token string">"grant_type"</span><span class="token operator">:</span><span class="token string">"sms_code"</span><span class="token punctuation">,</span> <span class="token string">"scope"</span><span class="token operator">:</span><span class="token string">"all"</span><span class="token punctuation">,</span> <span class="token string">"client_id"</span><span class="token operator">:</span><span class="token string">"mini_charge"</span><span class="token punctuation">,</span> <span class="token string">"client_secret"</span><span class="token operator">:</span><span class="token string">"times"</span><span class="token punctuation">,</span> <span class="token string">"username"</span><span class="token operator">:</span><span class="token string">"13412341234"</span><span class="token punctuation">,</span> <span class="token string">"password"</span><span class="token operator">:</span><span class="token string">"123456"</span><span class="token punctuation">,</span> <span class="token string">"areaCode"</span><span class="token operator">:</span><span class="token string">"86"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>返回结果<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> <span class="token string">"code"</span><span class="token operator">:</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"data"</span><span class="token operator">:</span><span class="token punctuation">{</span> <span class="token string">"authUserDTO"</span><span class="token operator">:</span><span class="token punctuation">{</span> <span class="token string">"expiresIn"</span><span class="token operator">:</span><span class="token number">86399</span><span class="token punctuation">,</span> <span class="token string">"refreshToken"</span><span class="token operator">:</span><span class="token string">"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"</span><span class="token punctuation">,</span> <span class="token string">"token"</span><span class="token operator">:</span><span class="token string">"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"</span><span class="token punctuation">,</span> <span class="token string">"tokenHead"</span><span class="token operator">:</span><span class="token string">"Bearer "</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">"userDTO"</span><span class="token operator">:</span><span class="token punctuation">{</span> <span class="token string">"eWechatOpenId"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"eWechatUnionId"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"extUserId"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"id"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"isCancel"</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"isEnable"</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"isShowRealName"</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"isSupplement"</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"phone"</span><span class="token operator">:</span><span class="token string">"13412341234"</span><span class="token punctuation">,</span> <span class="token string">"phoneAreaCode"</span><span class="token operator">:</span><span class="token string">"86"</span><span class="token punctuation">,</span> <span class="token string">"projectId"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"projectName"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"storeType"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"storeUrl"</span><span class="token operator">:</span><span class="token string">"https://mall-prod-app-linli.timesgroup.cn/app/index"</span><span class="token punctuation">,</span> <span class="token string">"updateTime"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"userImage"</span><span class="token operator">:</span><span class="token string">"https://thirdwx.qlogo.cn/"</span><span class="token punctuation">,</span> <span class="token string">"userName"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"wxMinipOpenId"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"wxOpenId"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"wxUnionId"</span><span class="token operator">:</span><span class="token string">""</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">"userProjectHistoryDTOS"</span><span class="token operator">:</span><span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token string">"projectId"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"projectName"</span><span class="token operator">:</span><span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"storeType"</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"storeUrl"</span><span class="token operator">:</span><span class="token string">"https://mall-prod-app-linli.timesgroup.cn/app/index"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">"message"</span><span class="token operator">:</span><span class="token string">"success"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="获取会员-id-memberId"><a href="#获取会员-id-memberId" class="headerlink" title="获取会员 id - memberId"></a>获取会员 id - memberId</h2><ul><li>接口:<a href="https://m-center-prod-linli.timesgroup.cn/times/member-bff/member/api-c/v1/member/detailByPhone?phone=13412341234&phoneArea=86">https://m-center-prod-linli.timesgroup.cn/times/member-bff/member/api-c/v1/member/detailByPhone?phone=13412341234&phoneArea=86</a></li><li>请求方法:GET</li><li>请求参数<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 把 url 中的 phone 值替换为自己的手机号码</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li><li>请求头加入上一步返回来的 token 拼接在 <code>Bearer </code>后,如下:<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> headers<span class="token operator">:</span> <span class="token punctuation">{</span> Authorization<span class="token operator">:</span> <span class="token string">"Bearer eyJhbGciOiJSU"</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>返回结果,只需要拿到结果中的 memberId<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> <span class="token string">"code"</span><span class="token operator">:</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"data"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token string">"cardNo"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"cardType"</span><span class="token operator">:</span> <span class="token string">"111"</span><span class="token punctuation">,</span> <span class="token string">"couponNum"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"createTime"</span><span class="token operator">:</span> <span class="token number">1702007451000</span><span class="token punctuation">,</span> <span class="token string">"createUser"</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"email"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"grow"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"integral"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"integralTotal"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"isDeleted"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"isEnable"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"isShowRealName"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"memberCardRelats"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token string">"createTime"</span><span class="token operator">:</span> <span class="token number">1702007451000</span><span class="token punctuation">,</span> <span class="token string">"createUser"</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"expirationTime"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"grow"</span><span class="token operator">:</span> <span class="token number">300</span><span class="token punctuation">,</span> <span class="token string">"id"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"isDeleted"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"levelId"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"levelName"</span><span class="token operator">:</span> <span class="token string">"普通会员"</span><span class="token punctuation">,</span> <span class="token string">"memberCardId"</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">"memberCardImage"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"memberCardName"</span><span class="token operator">:</span> <span class="token string">"时代邻里会员卡"</span><span class="token punctuation">,</span> <span class="token string">"memberCode"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"memberId"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"rangeBegin"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"rangeEnd"</span><span class="token operator">:</span> <span class="token number">5000</span><span class="token punctuation">,</span> <span class="token string">"updateTime"</span><span class="token operator">:</span> <span class="token number">1702187857000</span><span class="token punctuation">,</span> <span class="token string">"updateUser"</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"upgradedTime"</span><span class="token operator">:</span> <span class="token number">1702007451000</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"memberCode"</span><span class="token operator">:</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token string">"memberId"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"memberIdStr"</span><span class="token operator">:</span> <span class="token string">"1"</span><span class="token punctuation">,</span> <span class="token string">"memberImage"</span><span class="token operator">:</span> <span class="token string">"https://thirdwx.qlogo.cn/mmopen/vi_32"</span><span class="token punctuation">,</span> <span class="token string">"memberName"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"memberSources"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token string">"createTime"</span><span class="token operator">:</span> <span class="token number">1702007451000</span><span class="token punctuation">,</span> <span class="token string">"createUser"</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"id"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"isDeleted"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"memberId"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"sourceCode"</span><span class="token operator">:</span> <span class="token string">"linlipro"</span><span class="token punctuation">,</span> <span class="token string">"updateTime"</span><span class="token operator">:</span> <span class="token number">1702007451000</span><span class="token punctuation">,</span> <span class="token string">"updateUser"</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">"memberType"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"memo"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"phone"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span> <span class="token string">"phoneAreaCode"</span><span class="token operator">:</span> <span class="token string">"86"</span><span class="token punctuation">,</span> <span class="token string">"realName"</span><span class="token operator">:</span> <span class="token string">"微信用户"</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">"updateTime"</span><span class="token operator">:</span> <span class="token number">1735185253000</span><span class="token punctuation">,</span> <span class="token string">"updateUser"</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">"message"</span><span class="token operator">:</span> <span class="token string">"success"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="签到"><a href="#签到" class="headerlink" title="签到"></a>签到</h2><ul><li>接口:<a href="https://m-center-prod-linli.timesgroup.cn/times/member-bff/user-behaviour//api-c/v1/user-behaviour/collect">https://m-center-prod-linli.timesgroup.cn/times/member-bff/user-behaviour//api-c/v1/user-behaviour/collect</a></li><li>请求方法:POST</li><li>请求头<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 第二步返回来的 token 拼接在 `Bearer `后</span><span class="token punctuation">{</span> headers<span class="token operator">:</span> <span class="token punctuation">{</span> Authorization<span class="token operator">:</span> <span class="token string">'Bearer eyJhbGciOiJSU'</span><span class="token punctuation">,</span> Content<span class="token operator">-</span>Type<span class="token operator">:</span> <span class="token string">'application/json'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>请求参数<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// memberId 为第三步返回的 memberId</span><span class="token comment">// createTime、sign为当前时间 格式:YYYY-MM-DD HH:mm:ss</span><span class="token punctuation">{</span> <span class="token string">"behaviourId"</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">"clientCode"</span><span class="token operator">:</span> <span class="token string">"sys_linlibang"</span><span class="token punctuation">,</span> <span class="token string">"createTime"</span><span class="token operator">:</span> <span class="token string">"2024-11-27 08:19:45"</span><span class="token punctuation">,</span> <span class="token string">"mapPamater"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token string">"sign"</span><span class="token operator">:</span> <span class="token string">"2024-11-27 08:19:45"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">"memberId"</span><span class="token operator">:</span> <span class="token string">"12332131232133"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>返回结果<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> code<span class="token operator">:</span> <span class="token number">200</span><span class="token punctuation">,</span> data<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> message<span class="token operator">:</span> <span class="token string">'success'</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="自动刷新-token"><a href="#自动刷新-token" class="headerlink" title="自动刷新 token"></a>自动刷新 token</h2><ul><li><p>token 过期时间,当前测试为 8 小时过期,需要在过期前刷新 token,下次签到就不用重新获取验证码登录(理论上可以无限续期)</p></li><li><p>接口:<a href="https://m-center-prod-linli.timesgroup.cn/times/auth/oauth/token">https://m-center-prod-linli.timesgroup.cn/times/auth/oauth/token</a></p></li><li><p>请求方法:POST</p></li><li><p>请求参数(FormData 格式)</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// grant_type=refresh_token&client_secret=times&client_id=app_c&scope=all&refresh_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2iMava32uw</span><span class="token comment">// 第一次刷新:refresh_token 需要设置为第二步获取返回来的 refreshToken</span><span class="token comment">// 第一次以后的刷新:refresh_token 获取本接口返回来的 refreshToken 即可</span><span class="token keyword">let</span> formData <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FormData</span><span class="token punctuation">(</span><span class="token punctuation">)</span>formData<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"grant_type"</span><span class="token punctuation">,</span> <span class="token string">"refresh_token"</span><span class="token punctuation">)</span>formData<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"client_secret"</span><span class="token punctuation">,</span> <span class="token string">"times"</span><span class="token punctuation">)</span>formData<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"client_id"</span><span class="token punctuation">,</span> <span class="token string">"app_c"</span><span class="token punctuation">)</span>formData<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"scope"</span><span class="token punctuation">,</span> <span class="token string">"all"</span><span class="token punctuation">)</span>formData<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"refresh_token"</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>返回结果</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> <span class="token string">"code"</span><span class="token operator">:</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"data"</span><span class="token operator">:</span><span class="token punctuation">{</span> <span class="token string">"expiresIn"</span><span class="token operator">:</span><span class="token number">86399</span><span class="token punctuation">,</span> <span class="token string">"refreshToken"</span><span class="token operator">:</span><span class="token string">"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2"</span><span class="token punctuation">,</span> <span class="token string">"token"</span><span class="token operator">:</span><span class="token string">"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25"</span><span class="token punctuation">,</span> <span class="token string">"tokenHead"</span><span class="token operator">:</span><span class="token string">"Bearer "</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">"message"</span><span class="token operator">:</span><span class="token string">"操作成功"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul>]]></content>
<summary type="html"><h2 id="获取验证码"><a href="#获取验证码" class="headerlink" title="获取验证码"></a>获取验证码</h2><ul>
<li>接口:<a href="https://m-center-prod-linli.timesgroup.c</summary>
<category term="自动化" scheme="http://damao2250.com/categories/%E8%87%AA%E5%8A%A8%E5%8C%96/"/>
<category term="邻里邦" scheme="http://damao2250.com/tags/%E9%82%BB%E9%87%8C%E9%82%A6/"/>
</entry>
<entry>
<title>2024-细细的红线</title>
<link href="http://damao2250.com/2024/12/20/2024-%E7%BB%86%E7%BB%86%E7%9A%84%E7%BA%A2%E7%BA%BF/"/>
<id>http://damao2250.com/2024/12/20/2024-%E7%BB%86%E7%BB%86%E7%9A%84%E7%BA%A2%E7%BA%BF/</id>
<published>2024-12-20T03:00:16.000Z</published>
<updated>2025-01-02T07:56:11.392Z</updated>
<content type="html"><![CDATA[<p>又到了一年一度的讲故事时间,那就少罗嗦先看故事吧</p><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/The_Thin_Red_Line.jpg" alt="The_Thin_Red_Line.jpg"></p><h2 id="《细细的红线》故事"><a href="#《细细的红线》故事" class="headerlink" title="《细细的红线》故事"></a>《细细的红线》故事</h2><p>1854年,在克里米亚战争的巴拉克拉瓦战役中,英国军队铸就了一个传奇般的军事神话——“细细的红线”。</p><p>当时,苏格兰高地兵团第93团肩负着阻击俄罗斯重骑兵的艰巨任务。由于兵力不足,无法形成坚固的方阵,代理指挥官克林做出了一个近乎疯狂的决策:在面对数量相当的俄国骑兵冲击时,他命令部队正面排列成两列横队,形成了一条细薄的战线。这种战术在当时的军事教条中是不被认可的,因为它风险极高——两列横队过于薄弱,一旦首轮射击未能击溃敌军,他们将直接面临被骑兵碾过的致命威胁。</p><p>然而,这些苏格兰勇士凭借他们高昂的士气和坚不可摧的心理素质,在距离敌军仅28码的近距离,直到能看清马匹眼白时才开火。他们的一次齐射便击倒了俄军一半的兵力,引发了俄军毁灭性的恐慌和溃败。最终,苏格兰高地兵团用他们的鲜血和子弹成功抵御了俄军的三轮冲锋,一战成名。战地记者在报道中写道:“阻挡在排山倒海般冲杀而来的俄军骑兵与英军基地之间的,只有“一道细细的红线。”,这红线指的正是身着红色军服的第93团官兵。</p><p>从此,英语里多了一个短语“细细的红线”(thin red line),指的就是英国军人面对惊涛骇浪也岿然不动的大无畏精神。</p><h2 id="我的故事"><a href="#我的故事" class="headerlink" title="我的故事"></a>我的故事</h2><p>看完上面的故事,你应该也能联想到我今年也经历了“细细的红线”战役吧,其实并没有哈,只是今年太过于沉溺在短平快的信息流中了,魔法口袋中实在没有其他故事可以掏出来讲而已。其实现实中遇到的那些事,即使当下觉得非常惨烈与沉重,但只要不是生离死别,都远不如历史上的任何大事件。</p><p>今年可以说是非常平平无奇的一年,生活按部就班几乎没有任何波澜。本来也想偷懒不写的,但是不写吧,又觉得这一年真的白过了,于是在脑海里回想了好久,也掏出几件事记录如下吧</p><h3 id="整备小窝"><a href="#整备小窝" class="headerlink" title="整备小窝"></a>整备小窝</h3><p> 继2023年12月29日收楼之后,就开始忙着筹备各种家电家具,其实早在双十一就开始购买了一些,家电类的各种参数对比得眼花缭乱,最后选了美的居多。</p><p> 大件家具去佛山看的(姐夫的弟弟店里),因为是熟人全程看不到一个小时,就全部定好了主选和备选,回来他给我们发了价格表后就基本落定了。</p><p> 柜子也是大头,几乎2023年初份就开始下订了,中间改了一次风格(一开始决定跟一个邻居的一样,后来去看了另一个邻居的样板房,就照搬了另一个邻居的)。</p><p> 最搞笑的时当时还没收楼,房子也还没装修完,甚至瓷砖也没贴,我就着急让柜子定制的人来量尺寸(人家还是从增城跑来南沙的)。他们也没问我装修进度如何,我以为装修到那个程度就可以量了,但是人家以为的是已经都装修好了。<br> 结果他们来量尺的那天房地产那边就开始严管不给非工作人员进入,后来量尺的那个小伙子只能爬围墙进入,现在想想其实是非常危险的。最后他发现居然还差这么多还没装修,我估计他当时心里应该是在骂我的了。但是又不能白跑了这么远的路程,只能硬着头皮量了能量的,说剩下需要量的,等装修完后让我量了拍照给他就可以了。</p><p> 最后就是精装给刷的灰色墙漆,实在是太暗了无法忍受,叫人来重新刷了一遍白色的乳胶漆。前后对比真的差距太明显了。</p><p> 下面放一张最后选定的清单列表:<br> <details><br> <summary>点击展开查看大图</summary><br> <img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/%E5%AE%B6%E5%85%B7%E5%AE%B6%E7%94%B5%E8%AE%BE%E5%A4%87%E9%80%89%E8%B4%AD%E6%B8%85%E5%8D%95_2024-12-20_15-13-30.png" alt="具家电设备选购清单"><br> </details></p><h3 id="拔智齿"><a href="#拔智齿" class="headerlink" title="拔智齿"></a>拔智齿</h3><p> 在处理智齿这件事上真的是一把辛酸一把泪,一直以为自己的智齿长得很正不用拔也可以,以前经常睡觉会自己咬到自己,也没想到是因为智齿长的太大了,后来发现右下智齿有点发炎就决定去拔了(2020-07-05)。</p><p> 拔了之后没多久到了11月份发现,下排右边尖牙后后面的那颗牙(应该是叫第二前磨牙)每次喝冷水或者刷牙都非常酸痛,特别是进入十一月份开始转凉了。这个时候才记起来这个牙齿之前不知道啥时候崩了一个角,一直没注意,导致现在已经伤到里面的牙髓神经了(后面问了医生之后才知道是被两颗长得有点歪的智齿往中间挤,结果把它给挤崩的)。此时(2020-11-27)只能不得已做了根管治疗。</p><p> 还剩下三根智齿,睡觉还是经常会咬到自己,于是就去把左下的智齿给拔(2021-12-11),拔的时候医生说要不要顺便把左上的一颗也一起拔了,我说不用。唉,现在想来真是找罪受啊。心想着下面的都拔了,跟上面不会咬合,总不能还咬到自己吧!(自己立下的flag)</p><p> 后来还是逃不了要拔智齿,时间来到了今年的三月份,之前立下的flag,没多久就打脸了,虽然智齿不会咬合咬到自己,但是牙齿跟牙龈的硬度不是一样的啊!那段时间经常发生的不是左边的牙龈被智齿磨出溃疡就是右边磨!这可怎么忍受,说拔就拔(2024-03-30),先拔了一颗,过了一周立马去拔第二颗,终于给拔完了。</p><p> 本来应该两次要给它全拔完的,硬是被拖了近四年,拔了四次!这花钱还不说,还咔咔遭罪。所以听完我的辛酸史,智齿不好的,该拔还是尽早啊!</p><h3 id="大意所致的离职"><a href="#大意所致的离职" class="headerlink" title="大意所致的离职"></a>大意所致的离职</h3><p> 不是很想讲这段经历的,但它确实是属于我今年你的一部分,而且是很深刻的一部分。事情的起因是前公司老板发信息给我有意邀我回前公司(前公司离家比较近,现公司在市区离家较远,每天通勤2.5小时),我确实也厌倦了这么长的通勤时间。</p><p> 于是我也向她表明了自己的态度,经过一番沟通后约定了时间去前公司与技术总监沟通技术方向是否符合。经过沟通后当天技术总监已经向老板表明技术是OK的,然后老板也跟我谈了具体的薪资待遇。虽然是降薪了,但是胜在离家近啊,我欣然同意。</p><p> 此时(9月份),老板表示希望我能在国庆后入职,因为国庆后有一位员工期满离职,我也表示我回去回尽快提交离职申请,可能最慢需要30天,老板也表示理解。当时我也想着要不要让她给我发offer先的,但是我想着都这么熟了,而且技术总监面试也通过了,这应该不是很要紧。</p><p> 当时她也提了一嘴,就是找个时间(她并没有说具体得时间)和现在的技术组长见个面聊一下,以为那个所谓的技术组长我也认识,以前我在这家公司的准备要离职的前几个月他才来的公司。我说“ok啊,没问题”,因为都认识的我就没太放在心上。</p><p> 回到先公司后的第二天,我就提了离职,公司这边也同意了我国庆前离职,last day为9月30日。到周末就约了个时间跟那个技术组长聊了一会让技术,双方都觉得没啥问题。回来后就发现前老板始终没有给我其他的信息反馈了,也没有谈入职事宜。</p><p> 我觉得有点不对劲,就主动发了信息询问。结果才得知,她说技术组长反馈我的技术不符合公司的发展速度!我只能说“好的,很抱歉技术没能符合公司的预期”。我怀着好意提前办理好离职,生怕他们公司没能及时有人进去接手工作,这倒好,把自己的饭碗给砸了。</p><p> 事已至此,只能怪自己太大意了,或者说信任给的太多了,临近国庆,只能先安心做好离职交接工作。</p><p> 国庆先跟老婆回她家带了几天,体验摘百香果和钓鱼的乐趣。然后回老家,因为刚好是重阳节到奶奶迁坟的日子,就顺着回去呆了一周(前后呆了近半个月才回广州)。</p><p> 回到广州后就立马筹备着投简历,虽然这个时候又刚好碰上工作非常难找的时期,但是自己还是比较自信的(flag)。一开始先投家附近的,发现招聘人都是几个月甚至一年前在线的了,有些近期在线的投了也没有回应。就这样投了一周没回应信心瞬间减半。</p><p> 第二周把范围扩大,条件也放宽到外包,依然没有回应。在最后没希望的时候有一家有回应了,后来去面试也没问题,但是工资40%作为绩效,这谁顶的住,果断拒绝了。</p><p> 第三周投到了周三也没有回应,这个时候几乎没信心了。但是天无绝人之路,终于有一家约了面试,周四面完后都OK,虽然有点降薪,但是总好过没工作吧,于是当天就决定接下offer,第二天就立马入职了,入职立马开干…</p><h3 id="湛江之行"><a href="#湛江之行" class="headerlink" title="湛江之行"></a>湛江之行</h3><p> 12月14日在小昌的邀约下,我们俩去湛江见了冰。小昌本来是去参加他表妹的婚礼的,但是冰刚好就在附近,于是萌生想法,趁着周末先去看看冰,然后再去参加婚礼。他跟我提议后我俩一拍即合(其实他是想让我帮他分担他开车的路程)。</p><p> 到的时候已是中午,多年的老友许久未见面,必然是要喝上两杯的。冰也是好菜款待我们俩,龙虾、蟹、鲍鱼、花螺、海鱼、皮皮虾、生蚝,满桌全都是海鲜,吃不完根本吃不完。其实看他买的海鲜也不便宜,看着他买都有点心疼,全程下来花了得有两千来块。</p><p> 接近傍晚吃饱喝足没啥事了,冰带我们去海边远远参观了一下他们的“战舰”,然后回去简单吃个晚餐冰就得要回他的基地了,我们也回酒店休息了。</p><p> 附一张海边的图:<br> <img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/20241220172537.jpg" alt="战舰"></p><h2 id="最后"><a href="#最后" class="headerlink" title="最后"></a>最后</h2><p> 一眨眼有到年末了,收获了脸庞的岁月划痕,也收获了很多无形的资产。总之尽了最大努力了,遗憾也好,痛苦也好,快乐也好,留在2024,2025继续加油!未来还是需要砥砺前行,不放弃就有希望!我的2025要充满干劲争取收获一台属于我们的车和小不点</p><h3 id="送给自己:无论现在是低谷还是高峰,请相信,凡事发生,皆有利于我"><a href="#送给自己:无论现在是低谷还是高峰,请相信,凡事发生,皆有利于我" class="headerlink" title="送给自己:无论现在是低谷还是高峰,请相信,凡事发生,皆有利于我"></a>送给自己:无论现在是低谷还是高峰,请相信,凡事发生,皆有利于我</h3>]]></content>
<summary type="html"><p>又到了一年一度的讲故事时间,那就少罗嗦先看故事吧</p>
<p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/The_Thin_Red_Line.jpg" alt="The</summary>
<category term="总结" scheme="http://damao2250.com/categories/%E6%80%BB%E7%BB%93/"/>
<category term="2024" scheme="http://damao2250.com/tags/2024/"/>
</entry>
<entry>
<title>getBoundingClientRect-获取元素的位置</title>
<link href="http://damao2250.com/2024/11/27/getBoundingClientRect-%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0%E7%9A%84%E4%BD%8D%E7%BD%AE/"/>
<id>http://damao2250.com/2024/11/27/getBoundingClientRect-%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0%E7%9A%84%E4%BD%8D%E7%BD%AE/</id>
<published>2024-11-27T01:04:20.012Z</published>
<updated>2024-11-27T02:10:30.685Z</updated>
<content type="html"><![CDATA[<h2 id="getBoundingClientRect"><a href="#getBoundingClientRect" class="headerlink" title="getBoundingClientRect()"></a>getBoundingClientRect()</h2><ul><li>用于获取元素的位置以及大小相关的信息</li><li>DOM 元素的一个方法,返回一个 DOMRect 对象,包含元素的大小及其相对于视口的位置</li></ul><h2 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h2><pre class="line-numbers language-js" data-language="js"><code class="language-js">element<span class="token punctuation">.</span>getBoundingClientRect()<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="返回值"><a href="#返回值" class="headerlink" title="返回值"></a>返回值</h2><ul><li>有 6 个属性:top,<code>lef</code>,<code>right</code>,<code>bottom</code>,<code>width</code>,<code>height</code></li></ul><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token punctuation">{</span> bottom:<span class="token number">353</span><span class="token punctuation">,</span> <span class="token comment">//元素底部距离窗口顶部的距离 (等于 y + height)</span> height<span class="token operator">:</span> <span class="token number">24</span><span class="token punctuation">,</span> <span class="token comment">//元素的高度</span> left<span class="token operator">:</span> <span class="token number">428</span><span class="token punctuation">,</span> <span class="token comment">//元素左侧距离窗口左侧的距离</span> right<span class="token operator">:</span> <span class="token number">1140</span><span class="token punctuation">,</span> <span class="token comment">//元素右侧距离窗口左侧的距离(等于 x + width)</span> top<span class="token operator">:</span> <span class="token number">329</span><span class="token punctuation">,</span> <span class="token comment">//元素顶部距离窗口的距离</span> width<span class="token operator">:</span> <span class="token number">712</span><span class="token punctuation">,</span> <span class="token comment">//元素的宽度</span> x<span class="token operator">:</span> <span class="token number">428</span><span class="token punctuation">,</span> <span class="token comment">//元素左上角相对于视口的横坐标</span> y<span class="token operator">:</span> <span class="token number">329</span> <span class="token comment">//元素左上角相对于视口的纵坐标</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="应用:检查元素是否在视口内"><a href="#应用:检查元素是否在视口内" class="headerlink" title="应用:检查元素是否在视口内"></a>应用:检查元素是否在视口内</h2><ul><li>获取元素位置</li></ul><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">isElementVisible</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">el</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token keyword">const</span> rect <span class="token operator">=</span> el<span class="token punctuation">.</span><span class="token function">getBoundingClientRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><ul><li>获取浏览器窗口的宽高</li></ul><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">isElementVisible</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">el</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token keyword">const</span> rect <span class="token operator">=</span> el<span class="token punctuation">.</span><span class="token function">getBoundingClientRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">const</span> vWidth <span class="token operator">=</span> window<span class="token punctuation">.</span>innerWidth <span class="token operator">||</span> document<span class="token punctuation">.</span>documentElement<span class="token punctuation">.</span>clientWidth <span class="token keyword">const</span> vHeight <span class="token operator">=</span> window<span class="token punctuation">.</span>innerHeight <span class="token operator">||</span> document<span class="token punctuation">.</span>documentElement<span class="token punctuation">.</span>clientHeight<span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre><ul><li>确认元素是否在视口内条件</li></ul><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// rect.right < 0 ||</span><span class="token comment">// rect.bottom < 0 ||</span><span class="token comment">// rect.left > vWidth ||</span><span class="token comment">// rect.top > vHeight</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/getBoundingClientRect-%E7%A4%BA%E6%84%8F%E5%9B%BE.jpg" alt="getBoundingClientRect-示意图"></p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">isElementVisible</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">el</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token keyword">const</span> rect <span class="token operator">=</span> el<span class="token punctuation">.</span><span class="token function">getBoundingClientRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">const</span> vWidth <span class="token operator">=</span> window<span class="token punctuation">.</span>innerWidth <span class="token operator">||</span> document<span class="token punctuation">.</span>documentElement<span class="token punctuation">.</span>clientWidth <span class="token keyword">const</span> vHeight <span class="token operator">=</span> window<span class="token punctuation">.</span>innerHeight <span class="token operator">||</span> document<span class="token punctuation">.</span>documentElement<span class="token punctuation">.</span>clientHeight <span class="token keyword">if</span> <span class="token punctuation">(</span> rect<span class="token punctuation">.</span>right <span class="token operator"><</span> <span class="token number">0</span> <span class="token operator">||</span> rect<span class="token punctuation">.</span>bottom <span class="token operator"><</span> <span class="token number">0</span> <span class="token operator">||</span> rect<span class="token punctuation">.</span>left <span class="token operator">></span> vWidth <span class="token operator">||</span> rect<span class="token punctuation">.</span>top <span class="token operator">></span> vHeight <span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">false</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">}</span><span class="token comment">// getBoundingClientRect 方法会使浏览器发生回流和重绘,性能消耗稍大,但兼容性比 Intersection Observer 要好</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><ul><li><p>Intersection Observer 方案</p><ul><li>Intersection Observer API 提供了一种异步检测目标元素与祖先元素或 <a href="https://developer.mozilla.org/en-US/docs/Glossary/Viewport">viewport</a> 相交情况变化的方法。在目标元素与视口或者其他指定元素发生交集时和触发配置的回调函数。</li></ul><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 获取要监测的元素</span><span class="token keyword">const</span> boxes <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelectorAll</span><span class="token punctuation">(</span><span class="token string">".box"</span><span class="token punctuation">)</span><span class="token comment">// 创建观察者,配置回调函数</span><span class="token comment">// 通过 isIntersecting 属性判断元素与视口是否相交</span><span class="token keyword">const</span> observer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">IntersectionObserver</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">entries<span class="token punctuation">,</span> observer</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> entries<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">entry</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>entry<span class="token punctuation">.</span>target<span class="token punctuation">,</span> entry<span class="token punctuation">.</span>isIntersecting <span class="token operator">?</span> <span class="token string">"visible"</span> <span class="token operator">:</span> <span class="token string">"invisible"</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span>boxes<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">box</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> observer<span class="token punctuation">.</span><span class="token function">observe</span><span class="token punctuation">(</span>box<span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul>]]></content>
<summary type="html"><h2 id="getBoundingClientRect"><a href="#getBoundingClientRect" class="headerlink" title="getBoundingClientRect()"></a>getBoundingClientRect</summary>
<category term="HTML" scheme="http://damao2250.com/categories/HTML/"/>
<category term="元素位置" scheme="http://damao2250.com/tags/%E5%85%83%E7%B4%A0%E4%BD%8D%E7%BD%AE/"/>
<category term="getBoundingClientRect" scheme="http://damao2250.com/tags/getBoundingClientRect/"/>
</entry>
<entry>
<title>Web端视频时间轴预览图思路</title>
<link href="http://damao2250.com/2024/11/25/Web%E7%AB%AF%E8%A7%86%E9%A2%91%E6%97%B6%E9%97%B4%E8%BD%B4%E9%A2%84%E8%A7%88%E5%9B%BE%E6%80%9D%E8%B7%AF/"/>
<id>http://damao2250.com/2024/11/25/Web%E7%AB%AF%E8%A7%86%E9%A2%91%E6%97%B6%E9%97%B4%E8%BD%B4%E9%A2%84%E8%A7%88%E5%9B%BE%E6%80%9D%E8%B7%AF/</id>
<published>2024-11-25T08:36:33.000Z</published>
<updated>2024-11-25T08:42:28.620Z</updated>
<content type="html"><![CDATA[<h3 id="Web端视频时间轴预览图思路"><a href="#Web端视频时间轴预览图思路" class="headerlink" title="Web端视频时间轴预览图思路"></a>Web端视频时间轴预览图思路</h3><ul><li><p>在鼠标首次移动到时间轴上时,获取到一雪碧图,它包含了鼠标所指位置附近的预览画面。在鼠标沿着时间滑动的时候,会根据判断是否需要请求新的雪碧图</p></li><li><p>接口返回一个数据是让前端拿到视频的预览信息,可以定位到预览图在哪个 URL 的几行几列,后端则负责雪碧图的生成</p></li><li><p>后端可以通过FFmpeg抽取关键帧</p></li></ul><h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><ul><li><a href="https://blog.dreamfever.me/posts/2024-07-07-ffmpeg-sprite-sheet/">https://blog.dreamfever.me/posts/2024-07-07-ffmpeg-sprite-sheet/</a></li></ul>]]></content>
<summary type="html"><h3 id="Web端视频时间轴预览图思路"><a href="#Web端视频时间轴预览图思路" class="headerlink" title="Web端视频时间轴预览图思路"></a>Web端视频时间轴预览图思路</h3><ul>
<li><p>在鼠标首次移动到时间轴上时</summary>
<category term="其他" scheme="http://damao2250.com/categories/%E5%85%B6%E4%BB%96/"/>
<category term="其他" scheme="http://damao2250.com/tags/%E5%85%B6%E4%BB%96/"/>
</entry>
<entry>
<title>有趣的调试工具PageSpy</title>
<link href="http://damao2250.com/2024/10/18/%E6%9C%89%E8%B6%A3%E7%9A%84%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7PageSpy/"/>
<id>http://damao2250.com/2024/10/18/%E6%9C%89%E8%B6%A3%E7%9A%84%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7PageSpy/</id>
<published>2024-10-18T04:53:08.000Z</published>
<updated>2024-10-19T06:19:22.543Z</updated>
<content type="html"><![CDATA[<h2 id="贴地址"><a href="#贴地址" class="headerlink" title="贴地址"></a>贴地址</h2><ul><li>PageSpy:<a href="https://pagespy.org/">https://pagespy.org</a></li></ul><h2 id="PageSpy"><a href="#PageSpy" class="headerlink" title="PageSpy"></a>PageSpy</h2><ul><li>PageSpy 是一款兼容 Web / 小程序 / React Native / 鸿蒙 App 等平台项目的开源调试平台。基于对原生 API 的封装,它将调用原生方法时的参数进行过滤、转化,整理成一定格式的消息供调试端消费;调试端收到消息数据后,提供类似本地控制台的功能界面将数据呈现出来。</li></ul><h2 id="现实调试存在问题与PageSpy优势"><a href="#现实调试存在问题与PageSpy优势" class="headerlink" title="现实调试存在问题与PageSpy优势"></a>现实调试存在问题与PageSpy优势</h2><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/why-is-pagespy-zh-a37ee831.png" alt="why-is-pagespy-zh-a37ee831"></p><h2 id="使用场景"><a href="#使用场景" class="headerlink" title="使用场景"></a>使用场景</h2><ul><li><p>日常开发中,项目出现问题基本都会通过 本地浏览器控制台 排查。可有些时候因为无法使用控制台,而导致排查故障需要多花费很多时间和人力,比如:</p><ul><li>真机调试 H5:以往有产品提供了可以在 H5 上查看信息的面板,但真机屏幕太小操作不便、显示不友好,以及数据会被截断;</li><li>远程办公、异地协同:传统沟通方式如邮件、电话、视频等,沟通问题的周期长、效率不高、故障信息不全面,容易误解误判;</li><li>用户设备白屏:除了需要提前获知出现问题的用户信息,定位问题的方式包括查看数据监控、日志分析,甚至还要跑到客户现场等,这些方式依赖排障人员要理解业务场景、技术实现;</li></ul></li><li><p>网站全局的 “问题反馈” 组件</p><ul><li>大多注重用户体验的网站,会在产品端为用户提供反馈问题的表单组件。从用户的角度这确实会提升好感,但用户提交的内容对于排查问题的帮助可能并不大,根本原因是:用户提交的基本上是文字概述和截图,或许还包含用户信息,但开发者更希望看到的是:<ul><li>用户是如何操作的;</li><li>伴随着操作,程序的运行时行为数据。例如:打印的日志、发出的网络请求以及响应数据等;</li></ul></li></ul></li></ul><h2 id="能力"><a href="#能力" class="headerlink" title="能力"></a>能力</h2><h3 id="PageSpy-在线实时调试"><a href="#PageSpy-在线实时调试" class="headerlink" title="PageSpy 在线实时调试"></a>PageSpy 在线实时调试</h3><ul><li>产品联调期间,测试人员上报问题后,开发者通过 「 PageSpy 在线实时调试」 查看程序的运行数据,其中包括实时的 Console 、Network 、Page 、Storage 以及 System 信息,还可以发送代码到真机上执行;</li></ul><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/online-debug.png"></p><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/pagespy-devtools.png"></p><h3 id="PageSpy-日志回放调试"><a href="#PageSpy-日志回放调试" class="headerlink" title="PageSpy 日志回放调试"></a>PageSpy 日志回放调试</h3><ul><li>系统接入 PageSpy 之后,收到类似的反馈只需告诉对方 上传日志 即可</li><li>对方上传完成后就可以前往回放调试,开发者除了可以看到运行时数据外,还可以看到用户的操作轨迹</li></ul><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/replay-debug.png"></p><p><img src="https://raw.githubusercontent.com/Damao2250/FileTransfer/master/replay-page.gif"></p><h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><h3 id="部署PageSpy服务"><a href="#部署PageSpy服务" class="headerlink" title="部署PageSpy服务"></a>部署PageSpy服务</h3><ul><li>使用 Docker 部署<pre class="line-numbers language-ps" data-language="ps"><code class="language-ps">docker run -d --restart=always -v ./log:/app/log -v ./data:/app/data -p 6752:6752 --name="pageSpy" ghcr.io/huolalatech/page-spy-web:latest<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li><li>使用 Node 部署<pre class="line-numbers language-ps" data-language="ps"><code class="language-ps">yarn global add @huolala-tech/page-spy-api@latest && page-spy-api# 或者npm install -g @huolala-tech/page-spy-api@latest && page-spy-api<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li>启动完成后,打开浏览器访问 <a href="http://localhost:6752/">http://localhost:6752</a> 体验</li></ul><h3 id="使用PageSpy"><a href="#使用PageSpy" class="headerlink" title="使用PageSpy"></a>使用PageSpy</h3><ul><li>在客户端的项目中加载 PageSpy:<pre class="line-numbers language-html" data-language="html"><code class="language-html"><span class="token comment"><!-- PageSpy SDK --></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>script</span> <span class="token attr-name">crossorigin</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>anonymous<span class="token punctuation">"</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://<your-pagespy-host>/page-spy/index.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>script</span><span class="token punctuation">></span></span><span class="token comment"><!-- 插件(非必须,但建议使用) --></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>script</span> <span class="token attr-name">crossorigin</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>anonymous<span class="token punctuation">"</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://<your-pagespy-host>/plugin/data-harbor/index.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>script</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>script</span> <span class="token attr-name">crossorigin</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>anonymous<span class="token punctuation">"</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://<your-pagespy-host>/plugin/rrweb/index.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>script</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>初始化 PageSpy 和插件,它们的初始化参数都提供了可选的 配置项 用于自定义 SDK 的行为:<pre class="line-numbers language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>script</span><span class="token punctuation">></span></span><span class="token script"><span class="token language-javascript"> window<span class="token punctuation">.</span>$harbor <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DataHarborPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> window<span class="token punctuation">.</span>$rrweb <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RRWebPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">[</span>window<span class="token punctuation">.</span>$harbor<span class="token punctuation">,</span> window<span class="token punctuation">.</span>$rrweb<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">p</span> <span class="token operator">=></span> <span class="token punctuation">{</span> PageSpy<span class="token punctuation">.</span><span class="token function">registerPlugin</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> window<span class="token punctuation">.</span>$pageSpy <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">PageSpy</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>script</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>引入的插件提供了哪些功能?</li><li>DataHarborPlugin 和 RRWebPlugin 两个插件,主要用于拓展 PageSpy 的能力:<ul><li>DataHarborPlugin:PageSpy 本身仅支持在线模式,即调试期间「客户端和调试端必须同时在线」,DataHarborPlugin 让 PageSpy 实现了离线模式的调试。点击 离线日志回放 查看更多详细信息;</li><li>RRWebPlugin:记录用户操作轨迹,底层使用 rrweb。通常和 DataHarborPlugin 绑定在一起使用。</li></ul></li></ul><h3 id="在小程序中使用"><a href="#在小程序中使用" class="headerlink" title="在小程序中使用"></a>在小程序中使用</h3><ul><li>第一步: 在项目中安装依赖。我们提供了几种小程序平台的 SDK,请根据需要安装:<pre class="line-numbers language-ps" data-language="ps"><code class="language-ps"># 微信小程序yarn add @huolala-tech/page-spy-wechat@latest# 支付宝小程序yarn add @huolala-tech/page-spy-alipay@latest# UniAPPyarn add @huolala-tech/page-spy-uniapp@latest# Taroyarn add @huolala-tech/page-spy-taro@latest<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>第二步: 将 PageSpy 服务域名填入小程序的 http、websocket 请求白名单中。注意除了开发环境,小程序强制要求使用 https 和 wss 协议:<pre class="line-numbers language-ps" data-language="ps"><code class="language-ps">https://<your-pagespy-host>wss://<your-pagespy-host><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li><li>第三步: 在入口文件中引入 SDK 并实例化,初始化参数提供了可选的 配置项 用于自定义 SDK 的行为:<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">import</span> PageSpy <span class="token keyword">from</span> <span class="token string">'@huolala-tech/page-spy-wechat'</span><span class="token punctuation">;</span><span class="token keyword">new</span> <span class="token class-name">PageSpy</span><span class="token punctuation">(</span><span class="token punctuation">{</span> api<span class="token operator">:</span> <span class="token string">"<your-pagespy-host>"</span><span class="token punctuation">,</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h3 id="在框架中集成"><a href="#在框架中集成" class="headerlink" title="在框架中集成"></a>在框架中集成</h3><ul><li>React:CodeSandbox - <a href="https://codesandbox.io/p/sandbox/page-spy-with-react-k3pzzt">PageSpy in React</a></li><li>Vue:CodeSandbox - <a href="https://codesandbox.io/p/sandbox/page-spy-with-vue-ft35qs">PageSpy in Vue</a></li><li>Svelte:CodeSandbox - <a href="https://codesandbox.io/p/sandbox/page-spy-with-svelte-p6mxd6">PageSpy in Svelte</a></li><li>Angular:CodeSandbox - <a href="https://codesandbox.io/p/sandbox/page-spy-with-angular-6wg3ps">PageSpy in Angular</a></li><li>Nextjs:CodeSandbox - <a href="https://codesandbox.io/p/sandbox/page-spy-with-nextjs-5htxv5">PageSpy in Nextjs</a></li><li>Nuxtjs:CodeSandbox - <a href="https://codesandbox.io/p/sandbox/page-spy-with-nuxtjs-8znq22">PageSpy in Nuxtjs</a></li></ul><h2 id="API"><a href="#API" class="headerlink" title="API"></a>API</h2><h3 id="PageSpy-1"><a href="#PageSpy-1" class="headerlink" title="PageSpy"></a>PageSpy</h3><ul><li>约定实例变量名称为 $pageSpy = new PageSpy(…);<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span>$pageSpy<span class="token punctuation">.</span><span class="token function">updateRoomInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span>$pageSpy<span class="token punctuation">.</span><span class="token function">abort</span><span class="token punctuation">(</span><span class="token punctuation">)</span>PageSpy<span class="token punctuation">.</span><span class="token function">registerPlugin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>PageSpy<span class="token punctuation">.</span>pluginsWithOrder$pageSpy<span class="token punctuation">.</span>version$pageSpy<span class="token punctuation">.</span>config$pageSpy<span class="token punctuation">.</span>socketStore<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h3 id="插件"><a href="#插件" class="headerlink" title="插件"></a>插件</h3></li><li>DataHarborPlugin</li><li>约定实例变量名称为 $harbor = new DataHarborPlugin(…);<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span>$harbor<span class="token punctuation">.</span><span class="token function">onOfflineLog</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><h3 id="RRWebPlugin"><a href="#RRWebPlugin" class="headerlink" title="RRWebPlugin"></a>RRWebPlugin</h3></li><li>约定实例变量名称为 $rrweb = new RRWebPlugin(…);<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h3 id="API参考地址"><a href="#API参考地址" class="headerlink" title="API参考地址"></a>API参考地址</h3></li><li><a href="https://www.pagespy.org/#/docs/api">https://www.pagespy.org/#/docs/api</a></li></ul><h2 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h2><ul><li><a href="https://www.v2ex.com/t/107906">https://www.v2ex.com/t/107906</a></li><li><a href="https://www.pagespy.org/">https://www.pagespy.org</a></li></ul>]]></content>
<summary type="html"><h2 id="贴地址"><a href="#贴地址" class="headerlink" title="贴地址"></a>贴地址</h2><ul>
<li>PageSpy:<a href="https://pagespy.org/">https://pagespy.org</</summary>
<category term="调试工具" scheme="http://damao2250.com/categories/%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7/"/>
<category term="PageSpy" scheme="http://damao2250.com/tags/PageSpy/"/>
</entry>
<entry>
<title>窄门大道</title>
<link href="http://damao2250.com/2024/10/14/%E7%AA%84%E9%97%A8%E5%A4%A7%E9%81%93/"/>
<id>http://damao2250.com/2024/10/14/%E7%AA%84%E9%97%A8%E5%A4%A7%E9%81%93/</id>
<published>2024-10-14T06:44:27.000Z</published>
<updated>2024-12-01T13:33:07.347Z</updated>
<content type="html"><![CDATA[<h3 id="我们需要的是一份水涨船高的事业"><a href="#我们需要的是一份水涨船高的事业" class="headerlink" title="我们需要的是一份水涨船高的事业"></a>我们需要的是一份水涨船高的事业</h3><p>工作❌ 事业✅</p><p>我们需要的并不是一份工作</p><p>而是一份水涨船高的事业</p><p>我们没有选择</p><p>因为随着年龄的增长</p><p>人生的风险是指数增加的</p><p>而不是线性增加的</p><p>走了一个越来越陡峭的线</p><p>增加的速度会非常快</p><p>越到后面你会发现麻绳越来越细</p><p>可能还断了 越断越多 越断越快</p><p>这就是指数增长的风险</p><p>但工资是怎么样的呢</p><p>工资是线性增长的</p><p>这还是在特别理想的情况下</p><p>通常是常数,也就是不变</p><p>可能三年也可能五年都不变</p><p>不但不变,搞不好在当下这个环境还降了</p><p>这种事情你听过吗</p><p>以前是从来没有听过这种事情的</p><p>至少在我们的成长经历中是没有经历过的</p><p>这种线性的增加速度怎么赶得上指数增加速度</p><p>我们没有选择</p><p>我们需要的是一份水涨船高的事业</p><p>我们要去哪里</p><p>我们当然要去更高远处</p><p>但是首先知道在哪里</p><p>然后怎么去</p><h3 id="这世界是一款叫生的游戏"><a href="#这世界是一款叫生的游戏" class="headerlink" title="这世界是一款叫生的游戏"></a>这世界是一款叫生的游戏</h3><p>这世界是一款游戏:生</p><p>一个游戏它越是高级越是复杂越是牛</p><p>它的规则就越是简单</p><p>比如像我们这款游戏</p><p>生有两个规则</p><p>第一个:要长久</p><p>第二个:要繁荣</p><p>这两条规则是一切的根本大法</p><p>符合这两条游戏规则的就可以继续玩</p><p>不符合那就没戏</p><h3 id="三追求"><a href="#三追求" class="headerlink" title="三追求"></a>三追求</h3><p>这是世界是一款游戏叫“生”</p><p>那我们每个人在其中都是一款子游戏,叫人生</p><p>它既然是一款游戏,那它就应该有道道、有攻略</p><p>个人生的结构应是怎样的呢</p><p>硬要给它划分你会发现其实很简单</p><p>可以给他划分成三个层次</p><p>我们把整个世界整个社会看成一个大机器</p><p>你会发现第一个层面</p><p>也是绝大部分人所在的层面</p><p>“技能层面”</p><p>在这个层面的人需要把自己打磨成这个大机器需要的某种零件或工具</p><p>然后安装进去不间断运行</p><p>大机器就能给我们一个约定好的回报——工资or奖金</p><p>它的好处就是稳,短期内几乎没有风险</p><p>弊端就是长期几乎是无穷大的风险</p><p>这是第一层,我想绝大部分人所在这个层面,无需多说</p><p>看第二层</p><p>第二层突然就只剩5%的人了,或者可能不到5%</p><p>“产权层面”</p><p>这个层面的人,他永远只思考一件事情</p><p>就是我们怎么才能在这个大机器上拥有点什么</p><p>让这个大机器的某一部分是我的</p><p>广厦千万间能不能有我一间,然我我租出去</p><p>他永远在想这个问题</p><p>做得好的呢他这个广厦千万间可能就在北上广</p><p>做得不好的呢可能在十八线</p><p>所以产权这个游戏他范围非常宽广</p><p>他不光投资算,创业也算</p><p>甚至自己写个小说或者创业也算</p><p>包括哪怕生个娃其实本质上也算一个产权游戏</p><p>这属于第二个层面</p><p>第三个层面就更有意思了</p><p>只有5%里的5%的人了</p><p>大约就是千分之一到万分之一的人在玩这个游戏</p><p>“关系层面”</p><p>关系这个层面它有意思的在哪里</p><p>他在意的是去定义这个机器的功能</p><p>他不是拥有,他也不需要拥有</p><p>因为你想他在画圈的时候,定义那块干什么,那块怎么组织</p><p>他连这个圈都能画了</p><p>他还不能决定这个圈是谁的吗</p><p>这样你会发现这规律、这结构出来了</p><p>“关系定义了产权”</p><p>“产权定义了技能”</p><p>一切决定了我们的命运的走向</p><h3 id="番外:文凭就是产品合格证"><a href="#番外:文凭就是产品合格证" class="headerlink" title="番外:文凭就是产品合格证"></a>番外:文凭就是产品合格证</h3><p>教育的目的是干什么?</p><p>肯定不是为了拓宽人类认知边界</p><p>而是为了培养一批“通用生物计算机”</p><p>这样的话文凭就是产品合格证</p><p>而且还是那种不太靠谱的合格证</p><p>那合格证的目的是什么?</p><p>是为了博得客户的信任</p><p>既然是为了博得客户的信任</p><p>那我们花费这么大的代价</p><p>这么长的时间</p><p>这个代价是不是有点太大了</p>]]></content>
<summary type="html"><h3 id="我们需要的是一份水涨船高的事业"><a href="#我们需要的是一份水涨船高的事业" class="headerlink" title="我们需要的是一份水涨船高的事业"></a>我们需要的是一份水涨船高的事业</h3><p>工作❌ 事业✅</p>
<p>我们</summary>
<category term="窄门大道" scheme="http://damao2250.com/categories/%E7%AA%84%E9%97%A8%E5%A4%A7%E9%81%93/"/>
<category term="窄门大道" scheme="http://damao2250.com/tags/%E7%AA%84%E9%97%A8%E5%A4%A7%E9%81%93/"/>
</entry>
<entry>
<title>简易瀑布流布局</title>
<link href="http://damao2250.com/2024/09/30/%E7%AE%80%E6%98%93%E7%80%91%E5%B8%83%E6%B5%81%E5%B8%83%E5%B1%80/"/>
<id>http://damao2250.com/2024/09/30/%E7%AE%80%E6%98%93%E7%80%91%E5%B8%83%E6%B5%81%E5%B8%83%E5%B1%80/</id>
<published>2024-09-30T01:07:00.000Z</published>
<updated>2024-09-30T01:12:47.054Z</updated>
<content type="html"><![CDATA[<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><pre class="line-numbers language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>style</span><span class="token punctuation">></span></span><span class="token style"><span class="token language-css"> <span class="token selector">.container</span> <span class="token punctuation">{</span> <span class="token property">column-count</span><span class="token punctuation">:</span> 4<span class="token punctuation">;</span> <span class="token comment">/* 定义列数 */</span> <span class="token property">column-gap</span><span class="token punctuation">:</span> 16px<span class="token punctuation">;</span> <span class="token comment">/* 定义列与列之间的间隙 */</span> <span class="token punctuation">}</span> <span class="token selector">.item</span> <span class="token punctuation">{</span> <span class="token property">background-color</span><span class="token punctuation">:</span> #f2f2f2<span class="token punctuation">;</span> <span class="token property">padding</span><span class="token punctuation">:</span> 8px<span class="token punctuation">;</span> <span class="token property">margin-bottom</span><span class="token punctuation">:</span> 16px<span class="token punctuation">;</span> <span class="token comment">/* 定义每项的底部间隙 */</span> <span class="token property">break-inside</span><span class="token punctuation">:</span> avoid<span class="token punctuation">;</span> <span class="token comment">/* 防止内容被分割到不同的列 */</span> <span class="token punctuation">}</span></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>style</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>container<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 1<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 2<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 3<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 4<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 5<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 6<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 7<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 8<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 9<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 10<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 11<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 12<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 13<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 14<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>item<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Item 15<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h2><style> .container-test { column-count: 4; /* 定义列数 */ column-gap: 16px; /* 定义列与列之间的间隙 */ } .item-test { background-color: #f2f2f2; padding: 8px; margin-bottom: 16px; /* 定义每项的底部间隙 */ break-inside: avoid; /* 防止内容被分割到不同的列 */ }</style><div class="container-test"> <div class="item-test">Item 1</div> <div class="item-test">Item 2 Item 2 Item 2 Item 2 Item 2 Item 2 Item 2 </div> <div class="item-test">Item 3</div> <div class="item-test">Item 4 Item 4 Item 4 Item 4 Item 4 Item 4 Item 4 Item 4 Item 4 Item 4 Item 4 </div> <div class="item-test">Item 5</div> <div class="item-test">Item 6</div> <div class="item-test">Item 7</div> <div class="item-test">Item 8</div> <div class="item-test">Item 9 Item 9 Item 9 Item 9</div> <div class="item-test">Item 10</div> <div class="item-test">Item 11</div> <div class="item-test">Item 12</div> <div class="item-test">Item 13</div> <div class="item-test">Item 14</div> <div class="item-test">Item 15</div></div>]]></content>
<summary type="html"><h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><pre class="line-numbers language-html" data-language="html"><code class=</summary>
<category term="HTML" scheme="http://damao2250.com/categories/HTML/"/>
<category term="CSS" scheme="http://damao2250.com/tags/CSS/"/>
<category term="HTML" scheme="http://damao2250.com/tags/HTML/"/>
</entry>
<entry>
<title>治大国</title>
<link href="http://damao2250.com/2024/09/30/%E6%B2%BB%E5%A4%A7%E5%9B%BD/"/>
<id>http://damao2250.com/2024/09/30/%E6%B2%BB%E5%A4%A7%E5%9B%BD/</id>
<published>2024-09-30T00:35:02.000Z</published>
<updated>2024-09-30T00:37:27.742Z</updated>
<content type="html"><![CDATA[<p>治大国,若烹小鲜。</p><p>以道莅天下,其鬼不神;非其鬼不神,其神不伤人;非其神不伤人,圣人亦不伤人。</p><p>夫两不相伤,故德交归焉。</p>]]></content>
<summary type="html"><p>治大国,若烹小鲜。</p>
<p>以道莅天下,其鬼不神;非其鬼不神,其神不伤人;非其神不伤人,圣人亦不伤人。</p>
<p>夫两不相伤,故德交归焉。</p>
</summary>
<category term="阅读记录" scheme="http://damao2250.com/categories/%E9%98%85%E8%AF%BB%E8%AE%B0%E5%BD%95/"/>
</entry>
<entry>
<title>Mr.Go</title>
<link href="http://damao2250.com/2024/09/22/Mr-Go/"/>
<id>http://damao2250.com/2024/09/22/Mr-Go/</id>
<published>2024-09-22T02:37:29.000Z</published>
<updated>2024-09-22T03:30:44.162Z</updated>
<content type="html"><![CDATA[<h2 id="包"><a href="#包" class="headerlink" title="包"></a>包</h2><ul><li>每个 <code>Go</code> 程序都由包构成</li><li>程序都从 <code>main</code> 包开始运行</li><li>下面的程序通过导入路径 <code>"fmt"</code> 和 <code>"math/rand"</code> 来使用这两个包</li><li>按照约定,包名与导入路径的最后一个元素一致,例如,<code>"math/rand"</code> 包中的源码均以 <code>package rand</code> 语句开始。就像 <code>mian</code> 包以 <code>package main</code> 开始<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token punctuation">(</span><span class="token string">"fmt"</span><span class="token string">"math/rand"</span><span class="token punctuation">)</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">"我最喜欢的数字是 "</span><span class="token punctuation">,</span> rand<span class="token punctuation">.</span><span class="token function">Intn</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="导入"><a href="#导入" class="headerlink" title="导入"></a>导入</h2><ul><li>此代码用圆括号将导入的包分成一组,这是“分组”形式的导入语句。</li><li>当然你也可以编写多个导入语句,例如:<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">import</span> <span class="token string">"math"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li><li>不过使用分组导入语句要更好。</li></ul><pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token punctuation">(</span><span class="token string">"fmt"</span><span class="token string">"math"</span><span class="token punctuation">)</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"现在你有了 %g 个问题."</span><span class="token punctuation">,</span> math<span class="token punctuation">.</span><span class="token function">Sqrt</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="导出名"><a href="#导出名" class="headerlink" title="导出名"></a>导出名</h2><ul><li>在 <code>Go</code> 中,如果一个名字以大写字母开头,那么它就是已导出的。例如,<code>Pizza</code> 就是个已导出名,<code>Pi</code> 也同样,它导出自 math 包。</li><li><code>pizza</code> 和 <code>pi</code> 并未以大写字母开头,所以它们是未导出的。</li><li>在导入一个包时,你只能引用其中已导出的名字。 任何「未导出」的名字在该包外均无法访问。</li><li>执行代码,观察错误信息。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token punctuation">.</span><span class="token operator">/</span>prog<span class="token punctuation">.</span><span class="token keyword">go</span><span class="token punctuation">:</span><span class="token number">9</span><span class="token punctuation">:</span><span class="token number">19</span><span class="token punctuation">:</span> undefined<span class="token punctuation">:</span> math<span class="token punctuation">.</span>pi<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li><li>要修复错误,请将 <code>math.pi</code> 改名为 <code>math.Pi</code>,然后再试着执行一次。</li></ul><pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token punctuation">(</span><span class="token string">"fmt"</span><span class="token string">"math"</span><span class="token punctuation">)</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>pi<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h2><ul><li>函数可接受零个或多个参数。</li><li>在本例中,<code>add</code> 接受两个 <code>int</code> 类型的参数。</li><li>注意类型在变量名的后面。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">add</span><span class="token punctuation">(</span>x <span class="token builtin">int</span><span class="token punctuation">,</span> y <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span><span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">}</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">42</span><span class="token punctuation">,</span> <span class="token number">13</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="函数形参类型简写"><a href="#函数形参类型简写" class="headerlink" title="函数形参类型简写"></a>函数形参类型简写</h2><ul><li>当连续两个或多个函数的已命名形参类型相同时,除最后一个类型以外,其它都可以省略。</li><li>在上例中,<code>x int, y int</code>,可以被简写为 <code>x, y int</code><pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">add</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span><span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">}</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">42</span><span class="token punctuation">,</span> <span class="token number">13</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="多返回值"><a href="#多返回值" class="headerlink" title="多返回值"></a>多返回值</h2><ul><li>函数可以返回任意数量的返回值。</li><li>swap 函数返回了两个字符串。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">swap</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">return</span> y<span class="token punctuation">,</span> x<span class="token punctuation">}</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>a<span class="token punctuation">,</span> b <span class="token operator">:=</span> <span class="token function">swap</span><span class="token punctuation">(</span><span class="token string">"hello"</span><span class="token punctuation">,</span> <span class="token string">"world"</span><span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="带名字的返回值"><a href="#带名字的返回值" class="headerlink" title="带名字的返回值"></a>带名字的返回值</h2><ul><li><code>Go</code> 的返回值可被命名,它们会被视作定义在函数顶部的变量。</li><li>返回值的命名应当能反应其含义,它可以作为文档使用。</li><li>没有参数的 <code>return</code> 语句会直接返回已命名的返回值,也就是「裸」返回值。</li><li>裸返回语句应当仅用在下面这样的短函数中。在长的函数中它们会影响代码的可读性。</li><li>命名返回值确定返回值为 <code>int</code> 类型<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">split</span><span class="token punctuation">(</span>sum <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>x<span class="token punctuation">,</span> y <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>x <span class="token operator">=</span> sum <span class="token operator">*</span> <span class="token number">4</span> <span class="token operator">/</span> <span class="token number">9</span>y <span class="token operator">=</span> sum <span class="token operator">-</span> x<span class="token keyword">return</span><span class="token punctuation">}</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h2><ul><li><code>var</code> 语句用于声明一系列变量。和函数的参数列表一样,类型在最后。</li><li>如例中所示,<code>var</code> 语句可以出现在包或函数的层级。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">var</span> c<span class="token punctuation">,</span> python<span class="token punctuation">,</span> java <span class="token builtin">bool</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">var</span> i <span class="token builtin">int</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> c<span class="token punctuation">,</span> python<span class="token punctuation">,</span> java<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="变量的初始化"><a href="#变量的初始化" class="headerlink" title="变量的初始化"></a>变量的初始化</h2><ul><li>变量声明可以包含初始值,每个变量对应一个。</li><li>如果提供了初始值,则类型可以省略;变量会从初始值中推断出类型。</li></ul><pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">var</span> i<span class="token punctuation">,</span> j <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">var</span> c<span class="token punctuation">,</span> python<span class="token punctuation">,</span> java <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">"no!"</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> j<span class="token punctuation">,</span> c<span class="token punctuation">,</span> python<span class="token punctuation">,</span> java<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="短变量声明"><a href="#短变量声明" class="headerlink" title="短变量声明"></a>短变量声明</h2><ul><li>在函数中,短赋值语句 <code>:=</code> 可在隐式确定类型的 <code>var</code> 声明中使用。</li><li>函数外的每个语句都 必须 以关键字开始(<code>var</code>、<code>func</code> 等),因此 <code>:=</code> 结构不能在函数外使用。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">var</span> i<span class="token punctuation">,</span> j <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span>k <span class="token operator">:=</span> <span class="token number">3</span>c<span class="token punctuation">,</span> python<span class="token punctuation">,</span> java <span class="token operator">:=</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">"no!"</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> j<span class="token punctuation">,</span> k<span class="token punctuation">,</span> c<span class="token punctuation">,</span> python<span class="token punctuation">,</span> java<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="基本类型"><a href="#基本类型" class="headerlink" title="基本类型"></a>基本类型</h2><ul><li>Go 的基本类型有<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token builtin">bool</span><span class="token builtin">string</span><span class="token builtin">int</span> <span class="token builtin">int8</span> <span class="token builtin">int16</span> <span class="token builtin">int32</span> <span class="token builtin">int64</span><span class="token builtin">uint</span> <span class="token builtin">uint8</span> <span class="token builtin">uint16</span> <span class="token builtin">uint32</span> <span class="token builtin">uint64</span> <span class="token builtin">uintptr</span><span class="token builtin">byte</span> <span class="token comment">// uint8 的别名</span><span class="token builtin">rune</span> <span class="token comment">// int32 的别名</span> <span class="token comment">// 表示一个 Unicode 码位</span><span class="token builtin">float32</span> <span class="token builtin">float64</span><span class="token builtin">complex64</span> <span class="token builtin">complex128</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>本例展示了几种类型的变量。 和导入语句一样,变量声明也可以「分组」成一个代码块。</li><li><code>int</code>、<code>uint</code> 和 <code>uintptr</code> 类型在 32-位系统上通常为 32-位宽,在 64-位系统上则为 64-位宽。当你需要一个整数值时应使用 <code>int</code> 类型, 除非你有特殊的理由使用固定大小或无符号的整数类型。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token punctuation">(</span><span class="token string">"fmt"</span><span class="token string">"math/cmplx"</span><span class="token punctuation">)</span><span class="token keyword">var</span> <span class="token punctuation">(</span>ToBe <span class="token builtin">bool</span> <span class="token operator">=</span> <span class="token boolean">false</span>MaxInt <span class="token builtin">uint64</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token operator"><<</span><span class="token number">64</span> <span class="token operator">-</span> <span class="token number">1</span>z <span class="token builtin">complex128</span> <span class="token operator">=</span> cmplx<span class="token punctuation">.</span><span class="token function">Sqrt</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">5</span> <span class="token operator">+</span> <span class="token number">12i</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"类型:%T 值:%v\n"</span><span class="token punctuation">,</span> ToBe<span class="token punctuation">,</span> ToBe<span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"类型:%T 值:%v\n"</span><span class="token punctuation">,</span> MaxInt<span class="token punctuation">,</span> MaxInt<span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"类型:%T 值:%v\n"</span><span class="token punctuation">,</span> z<span class="token punctuation">,</span> z<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="零值"><a href="#零值" class="headerlink" title="零值"></a>零值</h2><ul><li>没有明确初始化的变量声明会被赋予对应类型的 零值。</li><li>零值是:<ul><li>数值类型为 0,</li><li>布尔类型为 false,</li><li>字符串为 “”(空字符串)。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">var</span> i <span class="token builtin">int</span><span class="token keyword">var</span> f <span class="token builtin">float64</span><span class="token keyword">var</span> b <span class="token builtin">bool</span><span class="token keyword">var</span> s <span class="token builtin">string</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"%v %v %v %q\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> f<span class="token punctuation">,</span> b<span class="token punctuation">,</span> s<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul></li></ul><h2 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h2><ul><li>表达式 <code>T(v)</code> 将值 <code>v</code> 转换为类型 <code>T</code>。</li><li>一些数值类型的转换:<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">var</span> i <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">42</span><span class="token keyword">var</span> f <span class="token builtin">float64</span> <span class="token operator">=</span> <span class="token function">float64</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token keyword">var</span> u <span class="token builtin">uint</span> <span class="token operator">=</span> <span class="token function">uint</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>或者,更加简短的形式:<pre class="line-numbers language-go" data-language="go"><code class="language-go">i <span class="token operator">:=</span> <span class="token number">42</span>f <span class="token operator">:=</span> <span class="token function">float64</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>u <span class="token operator">:=</span> <span class="token function">uint</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li>与 <code>C</code> 不同的是,<code>Go</code> 在不同类型的项之间赋值时需要显式转换。试着移除例子中的 float64 或 uint 的类型转换,看看会发生什么。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token punctuation">(</span><span class="token string">"fmt"</span><span class="token string">"math"</span><span class="token punctuation">)</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">var</span> x<span class="token punctuation">,</span> y <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token keyword">var</span> f <span class="token builtin">float64</span> <span class="token operator">=</span> math<span class="token punctuation">.</span><span class="token function">Sqrt</span><span class="token punctuation">(</span><span class="token function">float64</span><span class="token punctuation">(</span>x<span class="token operator">*</span>x <span class="token operator">+</span> y<span class="token operator">*</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token keyword">var</span> z <span class="token builtin">uint</span> <span class="token operator">=</span> <span class="token function">uint</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> z<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="类型推断"><a href="#类型推断" class="headerlink" title="类型推断"></a>类型推断</h2><ul><li>在声明一个变量而不指定其类型时(即使用不带类型的 <code>:=</code> 语法 <code>var =</code> 表达式语法),变量的类型会通过右值推断出来。</li><li>当声明的右值确定了类型时,新变量的类型与其相同:<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">var</span> i <span class="token builtin">int</span>j <span class="token operator">:=</span> i <span class="token comment">// j 也是一个 int</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li><li>不过当右边包含未指明类型的数值常量时,新变量的类型就可能是 <code>int</code>、<code>float64</code> 或 <code>complex128</code> 了,这取决于常量的精度:<pre class="line-numbers language-go" data-language="go"><code class="language-go">i <span class="token operator">:=</span> <span class="token number">42</span> <span class="token comment">// int</span>f <span class="token operator">:=</span> <span class="token number">3.142</span> <span class="token comment">// float64</span>g <span class="token operator">:=</span> <span class="token number">0.867</span> <span class="token operator">+</span> <span class="token number">0.5i</span> <span class="token comment">// complex128</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li>试着修改示例代码中 v 的初始值,并观察它是如何影响类型的。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>v <span class="token operator">:=</span> <span class="token number">42</span> <span class="token comment">// 修改这里看看!</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"v is of type %T\n"</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="常量"><a href="#常量" class="headerlink" title="常量"></a>常量</h2><ul><li>常量的声明与变量类似,只不过使用 <code>const</code> 关键字。</li><li>常量可以是字符、字符串、布尔值或数值。</li><li>常量不能用 <code>:=</code> 语法声明。<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">const</span> Pi <span class="token operator">=</span> <span class="token number">3.14</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token keyword">const</span> World <span class="token operator">=</span> <span class="token string">"世界"</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">"Hello"</span><span class="token punctuation">,</span> World<span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">"Happy"</span><span class="token punctuation">,</span> Pi<span class="token punctuation">,</span> <span class="token string">"Day"</span><span class="token punctuation">)</span><span class="token keyword">const</span> Truth <span class="token operator">=</span> <span class="token boolean">true</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">"Go rules?"</span><span class="token punctuation">,</span> Truth<span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="数值常量"><a href="#数值常量" class="headerlink" title="数值常量"></a>数值常量</h2><ul><li>数值常量是高精度的值。</li><li>一个未指定类型的常量由上下文来决定其类型。</li><li>再试着一下输出 <code>needInt(Big)</code> 吧。</li><li>(<code>int</code> 类型可以存储最大 <code>64</code> 位的整数,根据平台不同有时会更小。)<pre class="line-numbers language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span><span class="token keyword">const</span> <span class="token punctuation">(</span><span class="token comment">// 将 1 左移 100 位来创建一个非常大的数字</span><span class="token comment">// 即这个数的二进制是 1 后面跟着 100 个 0</span>Big <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator"><<</span> <span class="token number">100</span><span class="token comment">// 再往右移 99 位,即 Small = 1 << 1,或者说 Small = 2</span>Small <span class="token operator">=</span> Big <span class="token operator">>></span> <span class="token number">99</span><span class="token punctuation">)</span><span class="token keyword">func</span> <span class="token function">needInt</span><span class="token punctuation">(</span>x <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> x<span class="token operator">*</span><span class="token number">10</span> <span class="token operator">+</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token keyword">func</span> <span class="token function">needFloat</span><span class="token punctuation">(</span>x <span class="token builtin">float64</span><span class="token punctuation">)</span> <span class="token builtin">float64</span> <span class="token punctuation">{</span><span class="token keyword">return</span> x <span class="token operator">*</span> <span class="token number">0.1</span><span class="token punctuation">}</span><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">needInt</span><span class="token punctuation">(</span>Small<span class="token punctuation">)</span><span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">needFloat</span><span class="token punctuation">(</span>Small<span class="token punctuation">)</span><span class="token punctuation">)</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">needFloat</span><span class="token punctuation">(</span>Big<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul>]]></content>
<summary type="html"><h2 id="包"><a href="#包" class="headerlink" title="包"></a>包</h2><ul>
<li>每个 <code>Go</code> 程序都由包构成</li>
<li>程序都从 <code>main</code> 包开始运行</li</summary>
<category term="GO" scheme="http://damao2250.com/categories/GO/"/>
<category term="GO" scheme="http://damao2250.com/tags/GO/"/>
</entry>
<entry>
<title>一个新的css属性:field-sizing</title>
<link href="http://damao2250.com/2024/09/20/%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84css%E5%B1%9E%E6%80%A7%EF%BC%9Afield-sizing/"/>
<id>http://damao2250.com/2024/09/20/%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84css%E5%B1%9E%E6%80%A7%EF%BC%9Afield-sizing/</id>
<published>2024-09-20T12:21:07.000Z</published>
<updated>2024-09-20T13:00:00.473Z</updated>
<content type="html"><![CDATA[<h2 id="field-sizing-控制表单尺寸自适应的CSS"><a href="#field-sizing-控制表单尺寸自适应的CSS" class="headerlink" title="field-sizing 控制表单尺寸自适应的CSS"></a>field-sizing 控制表单尺寸自适应的CSS</h2><ul><li>语法<ul><li>fixed,输入框、文本区域和下拉选择,无论内容如何,它们宽高都是固定</li><li>content,输入框、文本区域和下拉选择元素的宽高会根据内容的大小而变化</li></ul></li><li>需要 Chrome 123版本以上才能查看效果<pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token property">field-sizing</span><span class="token punctuation">:</span> fixed | content<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="示例代码"><a href="#示例代码" class="headerlink" title="示例代码"></a>示例代码</h2><pre class="line-numbers language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">min-height</span><span class="token punctuation">:</span>300px<span class="token punctuation">;</span> <span class="token property">width</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span> <span class="token property">border</span><span class="token punctuation">:</span>2px solid #ccc<span class="token punctuation">;</span><span class="token property">padding</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>input</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">border</span><span class="token punctuation">:</span>1px solid #ccc<span class="token punctuation">;</span> <span class="token property">min-width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span><span class="token property">max-width</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span> <span class="token property">field-sizing</span><span class="token punctuation">:</span> content</span><span class="token punctuation">"</span></span></span> <span class="token punctuation">/></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>textarea</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">field-sizing</span><span class="token punctuation">:</span> content<span class="token punctuation">;</span> <span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>textarea</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>select</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">field-sizing</span><span class="token punctuation">:</span> content<span class="token punctuation">;</span> <span class="token property">display</span><span class="token punctuation">:</span>block<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>3<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>测试<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>测试数据<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>测试一条很长很长很长很长很长的数据<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>select</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><ul><li>当前环境不可预览效果,可复制代码到html预览查看<div style="min-height:300px; width: 300px; border:2px solid #ccc;padding: 5px;"><input style="border:1px solid #ccc; min-width: 100px;max-width: 300px; field-sizing: content" /><textarea style="field-sizing: content; width: 200px;"></textarea><div> <select style="field-sizing: content; display:block;"> <option value="3">测试</option> <option value="2">测试数据</option> <option value="1">测试一条很长很长很长很长很长的数据</option> </select></div></div></li></ul>]]></content>
<summary type="html"><h2 id="field-sizing-控制表单尺寸自适应的CSS"><a href="#field-sizing-控制表单尺寸自适应的CSS" class="headerlink" title="field-sizing 控制表单尺寸自适应的CSS"></a>field-si</summary>
<category term="CSS" scheme="http://damao2250.com/categories/CSS/"/>
<category term="CSS" scheme="http://damao2250.com/tags/CSS/"/>
</entry>
<entry>
<title>故失道而后德</title>
<link href="http://damao2250.com/2024/09/20/%E6%95%85%E5%A4%B1%E9%81%93%E8%80%8C%E5%90%8E%E5%BE%B7/"/>
<id>http://damao2250.com/2024/09/20/%E6%95%85%E5%A4%B1%E9%81%93%E8%80%8C%E5%90%8E%E5%BE%B7/</id>
<published>2024-09-20T09:34:36.000Z</published>
<updated>2024-09-30T00:37:49.030Z</updated>
<content type="html"><![CDATA[<p>故失道而后德,失德面后仁,失仁而后义,失义而后礼。</p><p>夫礼者,忠信之薄,而乱之首。</p>]]></content>
<summary type="html"><p>故失道而后德,失德面后仁,失仁而后义,失义而后礼。</p>
<p>夫礼者,忠信之薄,而乱之首。</p>
</summary>
<category term="阅读记录" scheme="http://damao2250.com/categories/%E9%98%85%E8%AF%BB%E8%AE%B0%E5%BD%95/"/>
</entry>
<entry>
<title>视图转换动画-startViewTransition</title>
<link href="http://damao2250.com/2024/08/28/%E8%A7%86%E5%9B%BE%E8%BD%AC%E6%8D%A2%E5%8A%A8%E7%94%BB-startViewTransition/"/>
<id>http://damao2250.com/2024/08/28/%E8%A7%86%E5%9B%BE%E8%BD%AC%E6%8D%A2%E5%8A%A8%E7%94%BB-startViewTransition/</id>
<published>2024-08-28T01:02:36.000Z</published>
<updated>2024-08-28T09:07:02.954Z</updated>
<content type="html"><![CDATA[<h2 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h2><div style="widht: 1000px; height: 250px; background: #ccc; display: flex;"> <div style="flex:1; border-right:1px solid #000; position:relative;"> <div id="box1" style="position:absolute; left:0; top:0; width:50px; height:50px;background:#58bc58;">有效果的</div> </div> <div style="flex:1; position:relative;"> <div id="box2" style="position:absolute; left:0; top:0; width:50px; height:50px; background:#58b;">没有效果的</div> </div></div><div> <button id='changeBtn' style="margin-top:10px; user-select:none;">移动位置</button></div><script> let changeBtn = document.getElementById('changeBtn') let index1 = 0 let index2 = 0 changeBtn.onclick = async (ev)=>{ console.log(ev) let box2 = document.getElementById('box2') let box3 = document.getElementById('box1') if( index2%2 === 0 ){ box2.style.left = '150px' box2.style.top = '150px' } else { box2.style.left = '0px' box2.style.top = '0px' } index2++ if( document.startViewTransition ){ // 支持 document.startViewTransition(() => { // 开始视图变换 let box1 = document.getElementById('box1') if( index1%2 === 0 ){ box1.style.left = '150px' box1.style.top = '150px' } else { box1.style.left = '0px' box1.style.top = '0px' } index1++ }); } else { // 不支持 console.log('不支持startViewTransition') } }</script><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 调用document.startViewTransition,浏览器会捕捉当前页面的状态,类似于实时截图,或者“快照”</span><span class="token comment">// 执行实际的 dom 变化,再次记录变化后的页面状态(截图)</span><span class="token comment">// 触发两者的过渡动画,包括透明度、位移等变化,也可以自定义 CSS 动画</span><span class="token comment">// 默认情况下是整个页面的淡入淡出变化</span><span class="token comment">// ::view-transition-old表示「旧视图」的状态,也就是变化之前的截图</span><span class="token comment">// ::view-transition-new表示「新视图」的状态,也就是变化之后的截图</span><span class="token comment">// 如果需要指定具体元素的变化,可以给该元素指定 view-transition-name</span><span class="token comment">// 前后变化不一定要同一元素,浏览器是根据 view-transition-name 寻找的</span><span class="token comment">// 同一时间页面上不能出现两个相同 view-transition-name 的元素,不然视图变化会失效</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><pre class="line-numbers language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">widht</span><span class="token punctuation">:</span> 1000px<span class="token punctuation">;</span> <span class="token property">height</span><span class="token punctuation">:</span> 250px<span class="token punctuation">;</span> <span class="token property">background</span><span class="token punctuation">:</span> #ccc<span class="token punctuation">;</span> <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">flex</span><span class="token punctuation">:</span>1<span class="token punctuation">;</span> <span class="token property">border-right</span><span class="token punctuation">:</span>1px solid #000<span class="token punctuation">;</span> <span class="token property">position</span><span class="token punctuation">:</span>relative<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box1<span class="token punctuation">"</span></span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">position</span><span class="token punctuation">:</span>absolute<span class="token punctuation">;</span> <span class="token property">left</span><span class="token punctuation">:</span>0<span class="token punctuation">;</span> <span class="token property">top</span><span class="token punctuation">:</span>0<span class="token punctuation">;</span> <span class="token property">width</span><span class="token punctuation">:</span>50px<span class="token punctuation">;</span> <span class="token property">height</span><span class="token punctuation">:</span>50px<span class="token punctuation">;</span><span class="token property">background</span><span class="token punctuation">:</span>#58bc58<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span>有效果的<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">flex</span><span class="token punctuation">:</span>1<span class="token punctuation">;</span> <span class="token property">position</span><span class="token punctuation">:</span>relative<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>box2<span class="token punctuation">"</span></span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">position</span><span class="token punctuation">:</span>absolute<span class="token punctuation">;</span> <span class="token property">left</span><span class="token punctuation">:</span>0<span class="token punctuation">;</span> <span class="token property">top</span><span class="token punctuation">:</span>0<span class="token punctuation">;</span> <span class="token property">width</span><span class="token punctuation">:</span>50px<span class="token punctuation">;</span> <span class="token property">height</span><span class="token punctuation">:</span>50px<span class="token punctuation">;</span> <span class="token property">background</span><span class="token punctuation">:</span>#58b<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span>没有效果的<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>button</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>changeBtn<span class="token punctuation">'</span></span> <span class="token special-attr"><span class="token attr-name">style</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token value css language-css"><span class="token property">margin-top</span><span class="token punctuation">:</span>10px<span class="token punctuation">;</span> <span class="token property">user-select</span><span class="token punctuation">:</span>none<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span></span><span class="token punctuation">></span></span>移动位置<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>button</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">let</span> changeBtn <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'changeBtn'</span><span class="token punctuation">)</span><span class="token keyword">let</span> index1 <span class="token operator">=</span> <span class="token number">0</span><span class="token keyword">let</span> index2 <span class="token operator">=</span> <span class="token number">0</span>changeBtn<span class="token punctuation">.</span><span class="token function-variable function">onclick</span> <span class="token operator">=</span> <span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token parameter">ev</span><span class="token punctuation">)</span><span class="token operator">=></span><span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>ev<span class="token punctuation">)</span> <span class="token keyword">let</span> box2 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'box2'</span><span class="token punctuation">)</span> <span class="token keyword">let</span> box3 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'box1'</span><span class="token punctuation">)</span> <span class="token keyword">if</span><span class="token punctuation">(</span> index2<span class="token operator">%</span><span class="token number">2</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token punctuation">)</span><span class="token punctuation">{</span> box2<span class="token punctuation">.</span>style<span class="token punctuation">.</span>left <span class="token operator">=</span> <span class="token string">'150px'</span> box2<span class="token punctuation">.</span>style<span class="token punctuation">.</span>top <span class="token operator">=</span> <span class="token string">'150px'</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> box2<span class="token punctuation">.</span>style<span class="token punctuation">.</span>left <span class="token operator">=</span> <span class="token string">'0px'</span> box2<span class="token punctuation">.</span>style<span class="token punctuation">.</span>top <span class="token operator">=</span> <span class="token string">'0px'</span> <span class="token punctuation">}</span> index2<span class="token operator">++</span> <span class="token keyword">if</span><span class="token punctuation">(</span> document<span class="token punctuation">.</span>startViewTransition <span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token comment">// 支持</span> document<span class="token punctuation">.</span><span class="token function">startViewTransition</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token comment">// 开始视图变换</span> <span class="token keyword">let</span> box1 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'box1'</span><span class="token punctuation">)</span> <span class="token keyword">if</span><span class="token punctuation">(</span> index1<span class="token operator">%</span><span class="token number">2</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token punctuation">)</span><span class="token punctuation">{</span> box1<span class="token punctuation">.</span>style<span class="token punctuation">.</span>left <span class="token operator">=</span> <span class="token string">'150px'</span> box1<span class="token punctuation">.</span>style<span class="token punctuation">.</span>top <span class="token operator">=</span> <span class="token string">'150px'</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> box1<span class="token punctuation">.</span>style<span class="token punctuation">.</span>left <span class="token operator">=</span> <span class="token string">'0px'</span> box1<span class="token punctuation">.</span>style<span class="token punctuation">.</span>top <span class="token operator">=</span> <span class="token string">'0px'</span> <span class="token punctuation">}</span> index1<span class="token operator">++</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token comment">// 不支持</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'不支持startViewTransition'</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h2><div style="widht: 1000px; height: 250px; background: #ccc; display: flex</summary>
<category term="HTML API" scheme="http://damao2250.com/categories/HTML-API/"/>
<category term="startViewTransition" scheme="http://damao2250.com/tags/startViewTransition/"/>
</entry>
<entry>
<title>go-module相关</title>
<link href="http://damao2250.com/2024/08/14/go-module%E7%9B%B8%E5%85%B3/"/>
<id>http://damao2250.com/2024/08/14/go-module%E7%9B%B8%E5%85%B3/</id>
<published>2024-08-14T08:26:33.000Z</published>
<updated>2024-08-14T08:45:59.814Z</updated>
<content type="html"><![CDATA[<h2 id="go-mod-命令"><a href="#go-mod-命令" class="headerlink" title="go mod 命令"></a>go mod 命令</h2><ul><li><code>go mod init</code> 模块名初始化<code>go mod</code>,生成<code>go.mod</code>文件,后可接参数指定<code>module</code>名。</li><li><code>go mod download</code> 手动触发下载依赖包到本地cache(默认为<code>$GOPATH/pkg/mod</code>目录)</li><li><code>go mod graph</code> 打印项目的模块依赖结构</li><li><code>go mod tidy</code> 添加缺少的包,且删除无用的包</li><li><code>go mod verify</code> 校验模块是否被篡改过</li><li><code>go mod why</code> 查看为什么需要依赖</li><li><code>go mod vendor</code> 导出项目所有依赖到<code>vendor</code>下</li><li><code>go mod edit -fmt</code> 参数格式化</li><li><code>go mod edit -require=golang.org/x/text</code> 添加依赖</li><li><code>go mod edit -droprequire=golang.org/x/text</code> 删除依赖</li><li><code>go list -m -json all</code> 以json的方式打印依赖详情</li><li><code>go list -m -u all</code> 来检查可以升级的<code>package</code></li><li><code>go get -u need-upgrade-package</code> 升级后会将新的依赖版本更新到<code>go.mod</code>中</li><li><code>go get -u</code> 升级所有依赖到最新的版本</li><li><code>go get package@verison</code> 更新到指定版本</li></ul><h2 id="给项目添加依赖写进-go-mod"><a href="#给项目添加依赖写进-go-mod" class="headerlink" title="给项目添加依赖写进 go.mod"></a>给项目添加依赖写进 go.mod</h2><ul><li>在项目中有import,然后go build就会go module自动下载并添加</li><li>自己手工使用go get下载安装后,会自动加入go.mod</li></ul><h2 id="go-mod-文件"><a href="#go-mod-文件" class="headerlink" title="go.mod 文件"></a>go.mod 文件</h2><pre class="line-numbers language-js" data-language="js"><code class="language-js">module github<span class="token punctuation">.</span>com<span class="token operator">/</span>Ackites<span class="token operator">/</span>KillWxapkggo <span class="token number">1.23</span><span class="token function">require</span> <span class="token punctuation">(</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>ditashi<span class="token operator">/</span>jsbeautifier<span class="token operator">-</span>go v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20141206144643</span><span class="token operator">-</span><span class="token number">2520</span>a8026a9cgithub<span class="token punctuation">.</span>com<span class="token operator">/</span>dop251<span class="token operator">/</span>goja v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20240806095544</span><span class="token operator">-</span><span class="token number">3491</span>d4a58fbegithub<span class="token punctuation">.</span>com<span class="token operator">/</span>fsnotify<span class="token operator">/</span>fsnotify v1<span class="token punctuation">.</span><span class="token number">7.0</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>tdewolff<span class="token operator">/</span>parse<span class="token operator">/</span>v2 v2<span class="token punctuation">.</span><span class="token number">7.15</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>yosssi<span class="token operator">/</span>gohtml v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20201013000340</span><span class="token operator">-</span>ee4748c638f4golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>crypto v0<span class="token punctuation">.</span><span class="token number">26.0</span>golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>net v0<span class="token punctuation">.</span><span class="token number">28.0</span>golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>text v0<span class="token punctuation">.</span><span class="token number">17.0</span><span class="token punctuation">)</span><span class="token function">require</span> <span class="token punctuation">(</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>dlclark<span class="token operator">/</span>regexp2 v1<span class="token punctuation">.</span><span class="token number">11.4</span> <span class="token comment">// indirect</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>go<span class="token operator">-</span>sourcemap<span class="token operator">/</span>sourcemap v2<span class="token punctuation">.</span><span class="token number">1.3</span><span class="token operator">+</span>incompatible <span class="token comment">// indirect</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>google<span class="token operator">/</span>pprof v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20230207041349</span><span class="token operator">-</span><span class="token number">798e818</span>bf904 <span class="token comment">// indirect</span>golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>sys v0<span class="token punctuation">.</span><span class="token number">23.0</span> <span class="token comment">// indirect</span><span class="token punctuation">)</span><span class="token function">exclude</span><span class="token punctuation">(</span> golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>text v0<span class="token punctuation">.</span><span class="token number">17.0</span><span class="token punctuation">)</span><span class="token function">replace</span><span class="token punctuation">(</span> golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>text v0<span class="token punctuation">.</span><span class="token number">17.0</span> <span class="token operator">=></span> golang<span class="token punctuation">.</span>org<span class="token operator">/</span>x<span class="token operator">/</span>text v0<span class="token punctuation">.</span><span class="token number">18.0</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><ul><li>第一项:当前项目的模块路径</li><li>第二项:项目使用的go版本</li><li>第三项:require项目所需的直接依赖包及其版本</li><li>exclude:用于从使用中排除一个特定的模块版本</li><li>replace:用于将一个包的版本替换为另一个包版本</li><li>其中require后的indirect说明这个依赖是非直接依赖</li></ul><h2 id="go-sum文件"><a href="#go-sum文件" class="headerlink" title="go.sum文件"></a>go.sum文件</h2><pre class="line-numbers language-js" data-language="js"><code class="language-js">github<span class="token punctuation">.</span>com<span class="token operator">/</span>ditashi<span class="token operator">/</span>jsbeautifier<span class="token operator">-</span>go v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20141206144643</span><span class="token operator">-</span><span class="token number">2520</span>a8026a9c h1<span class="token operator">:</span><span class="token operator">+</span>Zo5Ca9GH0RoeVZQKzFJcTLoAixx5s5Gq3pTIS<span class="token operator">+</span>n354<span class="token operator">=</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>ditashi<span class="token operator">/</span>jsbeautifier<span class="token operator">-</span>go v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20141206144643</span><span class="token operator">-</span><span class="token number">2520</span>a8026a9c<span class="token operator">/</span>go<span class="token punctuation">.</span>mod h1<span class="token operator">:</span>HJGU9ULdREjOcVGZVPB5s6zYmHi1RxzT71l2wQyLmnE<span class="token operator">=</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>dlclark<span class="token operator">/</span>regexp2 v1<span class="token punctuation">.</span><span class="token number">11.4</span> h1<span class="token operator">:</span>rPYF9<span class="token operator">/</span>LECdNymJufQKmri9gV604RvvABwgOA8un7yAo<span class="token operator">=</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>dlclark<span class="token operator">/</span>regexp2 v1<span class="token punctuation">.</span><span class="token number">11.4</span><span class="token operator">/</span>go<span class="token punctuation">.</span>mod h1<span class="token operator">:</span>DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8<span class="token operator">=</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>dop251<span class="token operator">/</span>goja v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20240806095544</span><span class="token operator">-</span><span class="token number">3491</span>d4a58fbe h1<span class="token operator">:</span>jwFJkgsdelB87ohlXaAGSd05Cb5ALDFa9iW9IGRHcRM<span class="token operator">=</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>dop251<span class="token operator">/</span>goja v0<span class="token punctuation">.</span><span class="token number">0.0</span><span class="token operator">-</span><span class="token number">20240806095544</span><span class="token operator">-</span><span class="token number">3491</span>d4a58fbe<span class="token operator">/</span>go<span class="token punctuation">.</span>mod h1<span class="token operator">:</span><span class="token constant">DF</span><span class="token operator">+</span>w<span class="token operator">/</span>nLMIkvRpyhd<span class="token operator">/</span><span class="token number">0</span>K<span class="token operator">+</span>Okbh3fVZBtXLwRtS<span class="token operator">/</span>ccAa5w<span class="token operator">=</span>github<span class="token punctuation">.</span>com<span class="token operator">/</span>fsnotify<span class="token operator">/</span>fsnotify v1<span class="token punctuation">.</span><span class="token number">7.0</span> h1<span class="token operator">:</span><span class="token number">8</span>JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA<span class="token operator">=</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><ul><li>每一行都是由模块路径,模块版本,哈希值组成</li><li>其中哈希值是用来保证当前缓存的模块不会被篡改</li><li>hash是以h1:开头的字符串,表示生成checksum的算法是第一版的hash算法</li></ul>]]></content>
<summary type="html"><h2 id="go-mod-命令"><a href="#go-mod-命令" class="headerlink" title="go mod 命令"></a>go mod 命令</h2><ul>
<li><code>go mod init</code> 模块名初始化<code</summary>
<category term="GO" scheme="http://damao2250.com/categories/GO/"/>
<category term="module" scheme="http://damao2250.com/tags/module/"/>
</entry>
<entry>
<title>TS泛型定义实例</title>
<link href="http://damao2250.com/2024/06/26/TS%E6%B3%9B%E5%9E%8B%E5%AE%9A%E4%B9%89%E5%AE%9E%E4%BE%8B/"/>
<id>http://damao2250.com/2024/06/26/TS%E6%B3%9B%E5%9E%8B%E5%AE%9A%E4%B9%89%E5%AE%9E%E4%BE%8B/</id>
<published>2024-06-26T08:58:59.000Z</published>
<updated>2024-06-26T09:57:38.996Z</updated>
<content type="html"><![CDATA[<h2 id="定义泛型函数"><a href="#定义泛型函数" class="headerlink" title="定义泛型函数"></a>定义泛型函数</h2><ul><li>为了确保传入的类型与返回的类型相同,使用<code>类型变量T</code>表示传入参数和返回值的类型<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">function</span> identity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> arg<span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li>泛型函数两种调用方式:<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 指定传入参数类型</span><span class="token comment">// 事实没必要使用尖括号(<>)来明确地传入类型</span><span class="token keyword">let</span> output <span class="token operator">=</span> identity<span class="token operator"><</span>string<span class="token operator">></span><span class="token punctuation">(</span><span class="token string">"myString"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 较常用,使用 类型推论,推断传入类型和返回类型</span><span class="token comment">// 编译器可以查看myString的值,然后把T设置为它的类型</span><span class="token keyword">let</span> output <span class="token operator">=</span> <span class="token function">identity</span><span class="token punctuation">(</span><span class="token string">"myString"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="使用泛型变量"><a href="#使用泛型变量" class="headerlink" title="使用泛型变量"></a>使用泛型变量</h2><ul><li>明确表示传入的参数为T类型的数组,确保参数有<code>.length</code>这个属性<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">function</span> loggingIdentity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arg<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 也可以这样表示</span><span class="token keyword">function</span> loggingIdentity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> Array<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">)</span><span class="token operator">:</span> Array<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arg<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="泛型类型"><a href="#泛型类型" class="headerlink" title="泛型类型"></a>泛型类型</h2><ul><li><p>泛型函数的类型,只需要将类型参数写在最前面,跟函数声明一样</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">function</span> identity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> myIdentity<span class="token operator">:</span> <span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token parameter">arg<span class="token operator">:</span> <span class="token constant">T</span></span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token constant">T</span> <span class="token operator">=</span> identity<span class="token punctuation">;</span><span class="token comment">// 也可以使用不同的泛型参数名,只要在数量上和使用方式上能对应上就可以</span><span class="token keyword">let</span> myIdentity2<span class="token operator">:</span> <span class="token operator"><</span><span class="token constant">U</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token parameter">arg<span class="token operator">:</span> <span class="token constant">U</span></span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token constant">U</span> <span class="token operator">=</span> identity<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>可以使用带有调用签名的对象字面量来定义泛型函数</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">function</span> identity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> myIdentity<span class="token operator">:</span> <span class="token punctuation">{</span><span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">}</span> <span class="token operator">=</span> identity<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>上面例子里的对象字面量可以拿出来做为一个接口</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">interface</span> <span class="token class-name">GenericIdentityFn</span> <span class="token punctuation">{</span> <span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">function</span> identity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> myIdentity<span class="token operator">:</span> GenericIdentityFn <span class="token operator">=</span> identity<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>把泛型参数当作整个接口的一个参数,指定<code>GenericIdentityFn</code>的类型,这样接口里的其它成员也能知道这个参数的类型</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">interface</span> <span class="token class-name">GenericIdentityFn</span><span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span> <span class="token punctuation">{</span> <span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">function</span> identity<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> myIdentity<span class="token operator">:</span> GenericIdentityFn<span class="token operator"><</span>number<span class="token operator">></span> <span class="token operator">=</span> identity<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="泛型类"><a href="#泛型类" class="headerlink" title="泛型类"></a>泛型类</h2><ul><li><p>泛型类看上去与泛型接口差不多。 泛型类使用( <code><></code>)括起泛型类型,跟在类名后面</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">class</span> <span class="token class-name">GenericNumber</span><span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span> <span class="token punctuation">{</span> zeroValue<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">;</span> <span class="token function-variable function">add</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">x<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">,</span> y<span class="token operator">:</span> <span class="token constant">T</span></span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token constant">T</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> myGenericNumber <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">GenericNumber</span><span class="token operator"><</span>number<span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>myGenericNumber<span class="token punctuation">.</span>zeroValue <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>myGenericNumber<span class="token punctuation">.</span><span class="token function-variable function">add</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token punctuation">,</span> y</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p><code>GenericNumber</code>类的使用是十分直观的,并且你可能已经注意到了,没有什么去限制它只能使用number类型。 也可以使用字符串或其它更复杂的类型</p><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">let</span> stringNumeric <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">GenericNumber</span><span class="token operator"><</span>string<span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>stringNumeric<span class="token punctuation">.</span>zeroValue <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span>stringNumeric<span class="token punctuation">.</span><span class="token function-variable function">add</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token punctuation">,</span> y</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>stringNumeric<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>stringNumeric<span class="token punctuation">.</span>zeroValue<span class="token punctuation">,</span> <span class="token string">"test"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="泛型约束"><a href="#泛型约束" class="headerlink" title="泛型约束"></a>泛型约束</h2><ul><li>定义一个接口来描述约束条件。 创建一个包含<code>.length</code>属性的接口,使用这个接口和extends关键字来实现约束<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">interface</span> <span class="token class-name">Lengthwise</span> <span class="token punctuation">{</span> length<span class="token operator">:</span> number<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">function</span> loggingIdentity<span class="token operator"><</span><span class="token constant">T</span> <span class="token keyword">extends</span> <span class="token class-name">Lengthwise</span><span class="token operator">></span><span class="token punctuation">(</span>arg<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token constant">T</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arg<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span> arg<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token function">loggingIdentity</span><span class="token punctuation">(</span><span class="token string">"good"</span><span class="token punctuation">)</span> <span class="token comment">// √</span><span class="token function">loggingIdentity</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span> <span class="token comment">// ×</span><span class="token function">loggingIdentity</span><span class="token punctuation">(</span><span class="token punctuation">{</span>length<span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span> value<span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token comment">// √</span><span class="token function">loggingIdentity</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token comment">// ×</span><span class="token function">loggingIdentity</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment">// √</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul><h2 id="在泛型约束中使用类型参数"><a href="#在泛型约束中使用类型参数" class="headerlink" title="在泛型约束中使用类型参数"></a>在泛型约束中使用类型参数</h2><ul><li>声明一个类型参数,且它被另一个类型参数所约束。 比如,现在我们想要用属性名从对象里获取这个属性。 并且我们想要确保这个属性存在于对象 obj上,因此我们需要在这两个类型之间使用约束<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">function</span> <span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token parameter">obj<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">,</span> key<span class="token operator">:</span> <span class="token constant">K</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> x <span class="token operator">=</span> <span class="token punctuation">{</span> a<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> b<span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> c<span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span> d<span class="token operator">:</span> <span class="token number">4</span> <span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token function">getProperty</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> <span class="token string">"a"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token function">getProperty</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> <span class="token string">"m"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// error: Argument of type 'm' isn't assignable to 'a' | 'b' | 'c' | 'd'.</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul>]]></content>
<summary type="html"><h2 id="定义泛型函数"><a href="#定义泛型函数" class="headerlink" title="定义泛型函数"></a>定义泛型函数</h2><ul>
<li>为了确保传入的类型与返回的类型相同,使用<code>类型变量T</code>表示传入参数和返回值</summary>
<category term="TypeScript" scheme="http://damao2250.com/categories/TypeScript/"/>
<category term="TS" scheme="http://damao2250.com/tags/TS/"/>
<category term="TypeScript" scheme="http://damao2250.com/tags/TypeScript/"/>
</entry>
<entry>
<title>浏览器渲染页面过程</title>
<link href="http://damao2250.com/2024/06/25/%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B8%B2%E6%9F%93%E9%A1%B5%E9%9D%A2%E8%BF%87%E7%A8%8B/"/>
<id>http://damao2250.com/2024/06/25/%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B8%B2%E6%9F%93%E9%A1%B5%E9%9D%A2%E8%BF%87%E7%A8%8B/</id>
<published>2024-06-25T09:09:23.000Z</published>
<updated>2024-06-25T09:16:45.560Z</updated>
<content type="html"><![CDATA[<h2 id="浏览器是如何渲染页面的?"><a href="#浏览器是如何渲染页面的?" class="headerlink" title="浏览器是如何渲染页面的?"></a>浏览器是如何渲染页面的?</h2><p>当浏览器的网络线程收到 HTML 文档后,会产生一个渲染任务,并将其传递给渲染主线程的消息队列。<br>在事件循环机制的作用下,渲染主线程取出消息队列中的渲染任务,开启渲染流程。</p><p>整个渲染流程分为多个阶段,分别是: HTML 解析、样式计算、布局、分层、绘制、分块、光栅化、画<br>每个阶段都有明确的输入输出,上一个阶段的输出会成为下一个阶段的输入。<br>这样,整个渲染流程就形成了一套组织严密的生产流水线。</p><h3 id="渲染的第一步是解析-HTML。"><a href="#渲染的第一步是解析-HTML。" class="headerlink" title="渲染的第一步是解析 HTML。"></a>渲染的第一步是解析 HTML。</h3><p>解析过程中遇到 CSS 解析 CSS,遇到 JS 执行 JS。为了提高解析效率,浏览器在开始解析前,会启动一个预解析的线程,率先下载 HTML 中的外部 CSS 文件和 外部的 JS 文件。<br>如果主线程解析到link位置,此时外部的 CSS 文件还没有下载解析好,主线程不会等待,继续解析后续的 HTML。这是因为下载和解析 CSS 的工作是在预解析线程中进行的。这就是 CSS 不会阻塞 HTML 解析的根本原因。<br>如果主线程解析到script位置,会停止解析 HTML,转而等待 JS 文件下载好,并将全局代码解析执行完成后,才能继续解析 HTML。这是因为 JS 代码的执行过程可能会修改当前的 DOM 树,所以 DOM 树的生成必须暂停。这就是 JS 会阻塞 HTML 解析的根本原因。<br>第一步完成后,会得到 DOM 树和 CSSOM 树,浏览器的默认样式、内部样式、外部样式、行内样式均会包含在 CSSOM 树中。</p><h3 id="渲染的下一步是样式计算。"><a href="#渲染的下一步是样式计算。" class="headerlink" title="渲染的下一步是样式计算。"></a>渲染的下一步是样式计算。</h3><p>主线程会遍历得到的 DOM 树,依次为树中的每个节点计算出它最终的样式,称之为 Computed Style。<br>在这一过程中,很多预设值会变成绝对值,比如red会变成rgb(255,0,0);相对单位会变成绝对单位,比如em会变成px<br>这一步完成后,会得到一棵带有样式的 DOM 树。</p><h3 id="接下来是布局,布局完成后会得到布局树。"><a href="#接下来是布局,布局完成后会得到布局树。" class="headerlink" title="接下来是布局,布局完成后会得到布局树。"></a>接下来是布局,布局完成后会得到布局树。</h3><p>布局阶段会依次遍历 DOM 树的每一个节点,计算每个节点的几何信息。例如节点的宽高、相对包含块的位置。<br>大部分时候,DOM 树和布局树并非一一对应。<br>比如display:none的节点没有几何信息,因此不会生成到布局树;又比如使用了伪元素选择器,虽然 DOM 树中不存在这些伪元素节点,但它们拥有几何信息,所以会生成到布局树中。还有匿名行盒、匿名块盒等等都会导致 DOM 树和布局树无法一一对应。</p><h3 id="下一步是分层"><a href="#下一步是分层" class="headerlink" title="下一步是分层"></a>下一步是分层</h3><p>主线程会使用一套复杂的策略对整个布局树中进行分层。<br>分层的好处在于,将来某一个层改变后,仅会对该层进行后续处理,从而提升效率。<br>滚动条、堆叠上下文、transform、opacity 等样式都会或多或少的影响分层结果,也可以通过will-change属性更大程度的影响分层结果。</p><h3 id="再下一步是绘制"><a href="#再下一步是绘制" class="headerlink" title="再下一步是绘制"></a>再下一步是绘制</h3><p>主线程会为每个层单独产生绘制指令集,用于描述这一层的内容该如何画出来。<br>完成绘制后,主线程将每个图层的绘制信息提交给合成线程,剩余工作将由合成线程完成。<br>合成线程首先对每个图层进行分块,将其划分为更多的小区域。<br>它会从线程池中拿取多个线程来完成分块工作。<br>分块完成后,进入光栅化阶段。<br>合成线程会将块信息交给 GPU 进程,以极高的速度完成光栅化。<br>GPU 进程会开启多个线程来完成光栅化,并且优先处理靠近视口区域的块。<br>光栅化的结果,就是一块一块的位图</p><h3 id="最后一个阶段就是画了"><a href="#最后一个阶段就是画了" class="headerlink" title="最后一个阶段就是画了"></a>最后一个阶段就是画了</h3><p>合成线程拿到每个层、每个块的位图后,生成一个个「指引(quad)」信息。<br>指引会标识出每个位图应该画到屏幕的哪个位置,以及会考虑到旋转、缩放等变形。<br>变形发生在合成线程,与渲染主线程无关,这就是transform效率高的本质原因。<br>合成线程会把 quad 提交给 GPU 进程,由 GPU 进程产生系统调用,提交给 GPU 硬件,完成最终的屏幕成像。</p><p><a href="https://www.cnblogs.com/xw-01/p/18259655">摘自<二价亚铁>-你不知道的CSS之包含块-附加</a></p>]]></content>
<summary type="html"><h2 id="浏览器是如何渲染页面的?"><a href="#浏览器是如何渲染页面的?" class="headerlink" title="浏览器是如何渲染页面的?"></a>浏览器是如何渲染页面的?</h2><p>当浏览器的网络线程收到 HTML 文档后,会产生一个渲染任务</summary>
<category term="HTML" scheme="http://damao2250.com/categories/HTML/"/>
<category term="浏览器渲染" scheme="http://damao2250.com/tags/%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B8%B2%E6%9F%93/"/>
</entry>
<entry>
<title>Linux防火墙</title>
<link href="http://damao2250.com/2024/05/29/Linux%E9%98%B2%E7%81%AB%E5%A2%99/"/>
<id>http://damao2250.com/2024/05/29/Linux%E9%98%B2%E7%81%AB%E5%A2%99/</id>
<published>2024-05-29T07:29:07.000Z</published>
<updated>2024-05-29T09:52:44.392Z</updated>
<content type="html"><![CDATA[<h2 id="查看firewall服务状态"><a href="#查看firewall服务状态" class="headerlink" title="查看firewall服务状态"></a>查看firewall服务状态</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">$ systemctl status firewalld<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><ul><li>出现 Active: active (running) 表示防火墙启动状态</li><li>出现 Active: inactive (dead) 表示防火墙关闭状态</li><li>出现 Unit firewalld.service could not be found. 表示没有找到防火墙,需要先安装<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># Ubuntu</span><span class="token function">apt</span> <span class="token function">install</span> firewalld<span class="token comment"># CentOS</span>yum <span class="token function">install</span> firewalld<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><h2 id="查看firewall的状态"><a href="#查看firewall的状态" class="headerlink" title="查看firewall的状态"></a>查看firewall的状态</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">firewall-cmd --state<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="开启、重启、关闭、firewalld-service服务"><a href="#开启、重启、关闭、firewalld-service服务" class="headerlink" title="开启、重启、关闭、firewalld.service服务"></a>开启、重启、关闭、firewalld.service服务</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 开启</span>$ <span class="token function">service</span> firewalld start<span class="token comment"># 重启</span>$ <span class="token function">service</span> firewalld restart<span class="token comment"># 关闭</span>$ <span class="token function">service</span> firewalld stop<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="查询端口是否开放"><a href="#查询端口是否开放" class="headerlink" title="查询端口是否开放"></a>查询端口是否开放</h2><ul><li>yes 表示开放 no表示不开放<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">$ firewall-cmd --query-port<span class="token operator">=</span><span class="token number">8080</span>/tcp<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="开放80端口"><a href="#开放80端口" class="headerlink" title="开放80端口"></a>开放80端口</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">$ firewall-cmd --permanent --add-port<span class="token operator">=</span><span class="token number">80</span>/tcp<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="移除端口"><a href="#移除端口" class="headerlink" title="移除端口"></a>移除端口</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">$ firewall-cmd --permanent --remove-port<span class="token operator">=</span><span class="token number">8080</span>/tcp<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="查看已开放的端口"><a href="#查看已开放的端口" class="headerlink" title="查看已开放的端口"></a>查看已开放的端口</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">netstat</span> -anp<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="设置开机自启"><a href="#设置开机自启" class="headerlink" title="设置开机自启"></a>设置开机自启</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">systemctl <span class="token builtin class-name">enable</span> firewalld.service<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="设置关闭开机自启动"><a href="#设置关闭开机自启动" class="headerlink" title="设置关闭开机自启动"></a>设置关闭开机自启动</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">systemctl disable firewalld.service<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h2 id="重启防火墙-修改配置后要重启防火墙"><a href="#重启防火墙-修改配置后要重启防火墙" class="headerlink" title="重启防火墙(修改配置后要重启防火墙)"></a>重启防火墙(修改配置后要重启防火墙)</h2><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">$ firewall-cmd --reload<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><ul><li>firwall-cmd:是Linux提供的操作firewall的一个工具;</li><li>–permanent:表示设置为持久;</li><li>–add-port:标识添加的端口;</li></ul>]]></content>
<summary type="html"><h2 id="查看firewall服务状态"><a href="#查看firewall服务状态" class="headerlink" title="查看firewall服务状态"></a>查看firewall服务状态</h2><pre class="line-numbers </summary>
<category term="Linux" scheme="http://damao2250.com/categories/Linux/"/>
<category term="Linux" scheme="http://damao2250.com/tags/Linux/"/>
<category term="防火墙" scheme="http://damao2250.com/tags/%E9%98%B2%E7%81%AB%E5%A2%99/"/>
</entry>
<entry>
<title>Windows常用命令</title>
<link href="http://damao2250.com/2024/05/22/Windows%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/"/>
<id>http://damao2250.com/2024/05/22/Windows%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/</id>
<published>2024-05-22T01:48:09.000Z</published>
<updated>2024-05-22T01:59:57.012Z</updated>
<content type="html"><![CDATA[<h2 id="查看路由表"><a href="#查看路由表" class="headerlink" title="查看路由表"></a>查看路由表</h2><ul><li>Windows下查看命令<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">route PRINT<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>接口列表 <span class="token number">8</span><span class="token punctuation">..</span>.9e b6 d0 f6 5d 5f <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Microsoft Wi-Fi Direct Virtual Adapter <span class="token number">6</span><span class="token punctuation">..</span>.ae b6 d0 f6 5d 5f <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Microsoft Wi-Fi Direct Virtual Adapter <span class="token comment">#2</span> <span class="token number">13</span><span class="token punctuation">..</span>.d8 9e f3 f2 08 2c <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>ASIX USB to Gigabit Ethernet Family Adapter <span class="token comment">#2</span> <span class="token number">23</span><span class="token punctuation">..</span>.9c b6 d0 f6 5d 5f <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Killer Wireless-n/a/ac <span class="token number">1535</span> Wireless Network Adapter <span class="token number">19</span><span class="token punctuation">..</span>.00 ff bf <span class="token number">92</span> 2a 5a <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Sangfor SSL VPN CS Support System VNIC <span class="token number">1</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>.Software Loopback Interface <span class="token number">1</span> <span class="token number">21</span><span class="token punctuation">..</span>.00 <span class="token number">15</span> 5d e8 e1 ee <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Hyper-V Virtual Ethernet Adapter <span class="token number">33</span><span class="token punctuation">..</span>.00 <span class="token number">15</span> 5d <span class="token number">43</span> a6 09 <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Hyper-V Virtual Ethernet Adapter <span class="token comment">#2</span> <span class="token number">40</span><span class="token punctuation">..</span>.00 <span class="token number">15</span> 5d <span class="token number">75</span> <span class="token number">16</span> ff <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Hyper-V Virtual Ethernet Adapter <span class="token comment">#3</span> <span class="token number">45</span><span class="token punctuation">..</span>.00 <span class="token number">15</span> 5d f5 0d <span class="token number">55</span> <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>Hyper-V Virtual Ethernet Adapter <span class="token comment">#4</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>IPv4 路由表<span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>活动路由: 网络目标 网络掩码 网关 接口 跃点数 <span class="token number">0.0</span>.0.0 <span class="token number">0.0</span>.0.0 <span class="token number">172.18</span>.2.1 <span class="token number">172.18</span>.3.140 <span class="token number">35</span> <span class="token number">127.0</span>.0.0 <span class="token number">255.0</span>.0.0 在链路上 <span class="token number">127.0</span>.0.1 <span class="token number">331</span> <span class="token number">255.255</span>.255.255 <span class="token number">255.255</span>.255.255 在链路上 <span class="token number">172.30</span>.224.1 <span class="token number">5256</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>永久路由: 网络地址 网络掩码 网关地址 跃点数 <span class="token number">137.0</span>.0.0 <span class="token number">255.255</span>.0.0 <span class="token number">138.0</span>.0.250 <span class="token number">1</span> <span class="token number">138.0</span>.0.0 <span class="token number">255.255</span>.0.0 <span class="token number">137.0</span>.23.176 <span class="token number">1</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>IPv6 路由表<span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>活动路由: 接口跃点数网络目标 网关 <span class="token number">1</span> <span class="token number">331</span> ::1/128 在链路上 <span class="token number">13</span> <span class="token number">291</span> fe80::/64 在链路上 <span class="token number">23</span> <span class="token number">291</span> fe80::/64 在链路上<span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>永久路由: 无<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li>Linux系统中查看路由表:<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">ip</span> route show<span class="token comment"># or</span><span class="token function">netstat</span> -rn<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li></ul>]]></content>
<summary type="html"><h2 id="查看路由表"><a href="#查看路由表" class="headerlink" title="查看路由表"></a>查看路由表</h2><ul>
<li>Windows下查看命令<pre class="line-numbers language-bash" </summary>
<category term="Windows" scheme="http://damao2250.com/categories/Windows/"/>
<category term="Windows" scheme="http://damao2250.com/tags/Windows/"/>
</entry>
<entry>
<title>GO取指针和取值</title>
<link href="http://damao2250.com/2024/05/10/GO%E5%8F%96%E6%8C%87%E9%92%88%E5%92%8C%E5%8F%96%E5%80%BC/"/>
<id>http://damao2250.com/2024/05/10/GO%E5%8F%96%E6%8C%87%E9%92%88%E5%92%8C%E5%8F%96%E5%80%BC/</id>
<published>2024-05-10T08:25:24.000Z</published>
<updated>2024-05-11T01:44:46.484Z</updated>
<content type="html"><![CDATA[<ul><li>GO取值和取指针的操作<ul><li><code>*</code>是取值,即获取指针指向的值;<code>&</code>取指针,即获取变量的地址<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">package</span> main<span class="token keyword">import</span> <span class="token string">"fmt"</span>func <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token comment">// 取值 start</span><span class="token keyword">var</span> a int <span class="token operator">=</span> <span class="token number">666</span><span class="token keyword">var</span> b int <span class="token operator">=</span> a <span class="token comment">// a是值传递,b取到的是a的值</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span> <span class="token comment">// 输出:666</span><span class="token comment">// 取值 end</span><span class="token comment">// a的类型 start</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"a的类型为:: %T\n"</span><span class="token punctuation">,</span> a<span class="token punctuation">)</span> <span class="token comment">// a的类型为:: int</span><span class="token comment">// a的类型 end</span><span class="token comment">// 取指针 start</span><span class="token keyword">var</span> c <span class="token operator">*</span>int <span class="token operator">=</span> <span class="token operator">&</span>a <span class="token comment">// c取到的是a的地址,c是一个指针,指向a的地址</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span> <span class="token comment">// 输出:0xc00000a0b8</span><span class="token comment">// 取指针 end</span><span class="token comment">// 指针类型 start</span>fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"c的指针类型为:: %T\n"</span><span class="token punctuation">,</span> c<span class="token punctuation">)</span> <span class="token comment">// c的指针类型为:: *int</span><span class="token comment">// 指针类型 end</span><span class="token comment">// 通过指针取值 start</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token operator">*</span>c<span class="token punctuation">)</span> <span class="token comment">// 输出:666</span><span class="token comment">// 通过指针取值 end</span><span class="token comment">// 修改指针指向的值 start</span><span class="token operator">*</span>c <span class="token operator">=</span> <span class="token number">789</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token operator">*</span>c<span class="token punctuation">)</span> <span class="token comment">// 输出:789</span><span class="token comment">// 修改指针指向的值 end</span><span class="token comment">// 指针作为参数传递并参与运算</span><span class="token function">sum1</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">}</span>func <span class="token function">sum1</span><span class="token punctuation">(</span><span class="token parameter">params <span class="token operator">*</span>int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token operator">*</span>params<span class="token punctuation">)</span> <span class="token comment">// 输出:789</span><span class="token operator">*</span>params <span class="token operator">=</span> <span class="token operator">*</span>params <span class="token operator">+</span> <span class="token number">1</span>fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token operator">*</span>params<span class="token punctuation">)</span> <span class="token comment">// 输出:790</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul></li></ul>]]></content>
<summary type="html"><ul>
<li>GO取值和取指针的操作<ul>
<li><code>*</code>是取值,即获取指针指向的值;<code>&amp;</code>取指针,即获取变量的地址<pre class="line-numbers language-js" data-language="</summary>
<category term="GO" scheme="http://damao2250.com/categories/GO/"/>
<category term="指针" scheme="http://damao2250.com/tags/%E6%8C%87%E9%92%88/"/>
<category term="指针类型" scheme="http://damao2250.com/tags/%E6%8C%87%E9%92%88%E7%B1%BB%E5%9E%8B/"/>
<category term="指针取值" scheme="http://damao2250.com/tags/%E6%8C%87%E9%92%88%E5%8F%96%E5%80%BC/"/>
</entry>
<entry>
<title>JS中的groupBy</title>
<link href="http://damao2250.com/2024/04/26/JS%E4%B8%AD%E7%9A%84groupBy/"/>
<id>http://damao2250.com/2024/04/26/JS%E4%B8%AD%E7%9A%84groupBy/</id>
<published>2024-04-26T03:41:01.000Z</published>
<updated>2024-04-26T05:52:41.645Z</updated>
<content type="html"><![CDATA[<h2 id="手动实现"><a href="#手动实现" class="headerlink" title="手动实现"></a>手动实现</h2><ul><li>使用 <code>reduce</code> 方法实现 <code>groupBy</code> 函数来实现将数组中的元素根据某个属性或条件分组</li></ul><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">const</span> <span class="token function-variable function">groupBy</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">array<span class="token punctuation">,</span> key</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token keyword">return</span> array<span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">result<span class="token punctuation">,</span> element</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token comment">// 使用 key 函数获取分组的键</span> <span class="token keyword">const</span> groupKey <span class="token operator">=</span> <span class="token function">key</span><span class="token punctuation">(</span>element<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 如果结果对象中没有这个键,就创建一个空数组</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>result<span class="token punctuation">[</span>groupKey<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> result<span class="token punctuation">[</span>groupKey<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token comment">// 将元素添加到对应的数组中</span> result<span class="token punctuation">[</span>groupKey<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>element<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span> result<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token keyword">const</span> people <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'John'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jane'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jim'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Joan'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment">// 使用 groupBy 方法</span><span class="token keyword">const</span> peopleByAge <span class="token operator">=</span> <span class="token function">groupBy</span><span class="token punctuation">(</span>people<span class="token punctuation">,</span> <span class="token parameter">person</span> <span class="token operator">=></span> person<span class="token punctuation">.</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>peopleByAge<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// `groupBy` 函数接收两个参数:一个数组和一个函数,这个函数用于从数组的每个元素中提取分组的键。</span><span class="token comment">// `reduce` 方法遍历数组,为每个不同的键创建一个新数组,并将具有相同键的元素添加到对应的数组中。</span><span class="token comment">// 输出</span><span class="token punctuation">{</span> <span class="token string">'20'</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'John'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jane'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">'30'</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jim'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Joan'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="原生支持-Object-groupBy"><a href="#原生支持-Object-groupBy" class="headerlink" title="原生支持 Object.groupBy"></a>原生支持 Object.groupBy</h2><ul><li><code>ECMAScript 2024(ES15)</code>提案已加入 <code>Object.groupBy</code> 方法</li><li>注意目前需要谷歌浏览器<code>117</code>以上的版本才能运行</li></ul><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token keyword">const</span> people <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'John'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jane'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jim'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Joan'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment">// 调用</span><span class="token keyword">const</span> peopleByAge <span class="token operator">=</span> Object<span class="token punctuation">.</span><span class="token function">groupBy</span><span class="token punctuation">(</span>people<span class="token punctuation">,</span> <span class="token parameter">person</span> <span class="token operator">=></span> person<span class="token punctuation">.</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>peopleByAge<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// 输出</span><span class="token punctuation">{</span> <span class="token string">'20'</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'John'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jane'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">20</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">'30'</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Jim'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'Joan'</span><span class="token punctuation">,</span> age<span class="token operator">:</span> <span class="token number">30</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="手动实现"><a href="#手动实现" class="headerlink" title="手动实现"></a>手动实现</h2><ul>
<li>使用 <code>reduce</code> 方法实现 <code>groupBy</code> 函数来实现将数</summary>
<category term="JavaScript" scheme="http://damao2250.com/categories/JavaScript/"/>
<category term="groupBy" scheme="http://damao2250.com/tags/groupBy/"/>
</entry>
<entry>
<title>Vue中的键盘事件</title>
<link href="http://damao2250.com/2024/03/01/Vue%E4%B8%AD%E7%9A%84%E9%94%AE%E7%9B%98%E4%BA%8B%E4%BB%B6/"/>
<id>http://damao2250.com/2024/03/01/Vue%E4%B8%AD%E7%9A%84%E9%94%AE%E7%9B%98%E4%BA%8B%E4%BB%B6/</id>
<published>2024-03-01T07:50:11.000Z</published>
<updated>2024-03-01T07:54:27.161Z</updated>
<content type="html"><![CDATA[<h2 id="字母键"><a href="#字母键" class="headerlink" title="字母键"></a>字母键</h2><ul><li>只有按下q键时才会执行send方法<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token operator"><</span>input v<span class="token operator">-</span>on<span class="token operator">:</span>keyup<span class="token punctuation">.</span><span class="token constant">Q</span><span class="token operator">=</span><span class="token string">"send"</span> type<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="大写锁定键"><a href="#大写锁定键" class="headerlink" title="大写锁定键"></a>大写锁定键</h2><ul><li>只有按下capslock键时才会执行send方法<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token operator"><</span>input v<span class="token operator">-</span>on<span class="token operator">:</span>keyup<span class="token punctuation">.</span>caps<span class="token operator">-</span>lock<span class="token operator">=</span><span class="token string">"send"</span> type<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="回车键"><a href="#回车键" class="headerlink" title="回车键"></a>回车键</h2><ul><li>只有按下回车键时才会执行 send 方法<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token operator"><</span>input v<span class="token operator">-</span>on<span class="token operator">:</span>keyup<span class="token punctuation">.</span>enter<span class="token operator">=</span><span class="token string">"send"</span> type<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="Alt-字母组合键"><a href="#Alt-字母组合键" class="headerlink" title="Alt+字母组合键"></a>Alt+字母组合键</h2><ul><li>keyup事件时需要同时按下组合键才会执行send方法<pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token operator"><</span>input v<span class="token operator">-</span>on<span class="token operator">:</span>keyup<span class="token punctuation">.</span>Alt<span class="token punctuation">.</span>y<span class="token operator">=</span><span class="token string">"send"</span> type<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li></ul><h2 id="自定义按键"><a href="#自定义按键" class="headerlink" title="自定义按键"></a>自定义按键</h2><pre class="line-numbers language-js" data-language="js"><code class="language-js"><span class="token comment">// 13是回车键的键码,将他的别名定义为send</span>Vue<span class="token punctuation">.</span>config<span class="token punctuation">.</span>keyCodes<span class="token punctuation">.</span>send<span class="token operator">=</span><span class="token number">13</span><span class="token comment">// 只有按下回车键时才会执行send方法</span><span class="token operator"><</span>input v<span class="token operator">-</span>on<span class="token operator">:</span>keydown<span class="token punctuation">.</span>send<span class="token operator">=</span><span class="token string">"send"</span> type<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="字母键"><a href="#字母键" class="headerlink" title="字母键"></a>字母键</h2><ul>
<li>只有按下q键时才会执行send方法<pre class="line-numbers language-js" data-</summary>
<category term="Vue" scheme="http://damao2250.com/categories/Vue/"/>
<category term="键盘事件" scheme="http://damao2250.com/tags/%E9%94%AE%E7%9B%98%E4%BA%8B%E4%BB%B6/"/>
</entry>
</feed>