-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
1076 lines (531 loc) · 799 KB
/
search.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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>Mysql数据库基础(六)</title>
<link href="/posts/aabb.html"/>
<url>/posts/aabb.html</url>
<content type="html"><![CDATA[<h2 id="事务概述"><a href="#事务概述" class="headerlink" title="事务概述"></a>事务概述</h2><p>事务是<strong>一组操作的集合</strong>,它是一个不可分割的工作单位。事务会把所有的操作作为一个整体一起向系统提交或撤消操作请求,即这些操作<strong>要么同时完成,要么同时失败</strong></p><p>Mysql的事务是默认<strong>自动提交</strong>的,即执行DML语句时就会<strong>立即</strong>隐式的提交事务</p><h2 id="事务操作"><a href="#事务操作" class="headerlink" title="事务操作"></a>事务操作</h2><p>先创建 account表,并插入数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> account(</span><br><span class="line">id <span class="type">int</span> auto_increment <span class="keyword">PRIMARY</span> KEY COMMENT <span class="string">'主键ID'</span>,</span><br><span class="line">name <span class="type">VARCHAR</span>(<span class="number">10</span>) COMMENT <span class="string">'姓名'</span>,</span><br><span class="line">money <span class="type">int</span> COMMENT <span class="string">'余额'</span></span><br><span class="line">)COMMENT <span class="string">'账户表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> account <span class="keyword">VALUES</span>(<span class="keyword">NULL</span>,<span class="string">'张三'</span>,<span class="number">2000</span>),(<span class="keyword">NULL</span>,<span class="string">'李四'</span>,<span class="number">2000</span>);</span><br></pre></td></tr></table></figure><p>因为Mysql是<strong>立即自动提交</strong>DML语句的,所以我们可以将这个自动更改为<strong>手动</strong>:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查看当前提交方式</span></span><br><span class="line"><span class="keyword">SELECT</span> @<span class="variable">@autocommit</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 更改提交方式为手动</span></span><br><span class="line"><span class="keyword">SET</span> @<span class="variable">@autocommit</span> <span class="operator">=</span> <span class="number">0</span>;</span><br></pre></td></tr></table></figure><p>将其更改为手动后,执行DML语句是不会提交到数据库的,这时可以执行下面两个SQL语句来操作事务:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 提交事务</span></span><br><span class="line"><span class="keyword">COMMIT</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 回滚事务</span></span><br><span class="line"><span class="keyword">ROLLBACK</span>;</span><br></pre></td></tr></table></figure><p>一般大部分情况下,我们都不会更改Mysql的提交方式的,这时我看可以通过该SQL语句来<strong>开启事务</strong>:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">START</span> TRANSACTION 或 <span class="keyword">BEGIN</span>;</span><br></pre></td></tr></table></figure><h2 id="四大特性"><a href="#四大特性" class="headerlink" title="四大特性"></a>四大特性</h2><p>如果一个数据库声称支持事务的操作,那么该数据库必须要具备以下四个特性(<strong>ACID</strong>):</p><ul><li>原子性(Atomicity):指事务包含的所有操作要么全部成功,要么全部失败回滚,因此事务的操作如果成功就必须要完全应用到数据库,如果操作失败则不能对数据库有任何影响</li><li>一致性(Consistency):指事务必须使数据库从一个一致性状态变换到另一个一致性状态,也就是说一个事务执行之前和执行之后都必须处于一致性状态<blockquote><p>拿转账来说,假设用户A和用户B两者的钱加起来一共是5000,那么不管A和B之间如何转账,转几次账,事务结束后两个用户的钱相加起来应该还得是5000,这就是事务的一致性</p></blockquote></li><li>隔离性(Isolation):当多个用户并发访问数据库时,比如操作同一张表时,数据库为每一个用户开启的事务,不能被其他事务的操作所干扰,多个并发事务之间要相互隔离<blockquote><p>要达到这么一种效果:对于任意两个并发的事务T1和T2,在事务T1看来,T2要么在T1开始之前就已经结束,要么在T1结束之后才开始,这样每个事务都感觉不到有其他事务在并发地执行</p></blockquote></li><li>持久性(Durability):指一个事务一旦被提交了,那么对数据库中的数据的改变就是永久性的,即便是在数据库系统遇到故障的情况下也不会丢失提交事务的操作<blockquote><p>如我们在使用JDBC操作数据库时,在提交事务方法后,提示用户事务操作完成,当我们程序执行完成直到看到提示后,就可以认定事务以及正确提交,即使这时候数据库出现了问题,也必须要将我们的事务完全执行完成,否则就会造成我们看到提示事务处理完毕,但是数据库因为故障而没有执行事务的重大错误</p></blockquote></li></ul><h2 id="并发事务"><a href="#并发事务" class="headerlink" title="并发事务"></a>并发事务</h2><p>总的说,数据库事务无非就两种:读取事务(select)、修改事务(update,insert)。在没有事务隔离控制的时候,多个事务在同一时刻对同一数据的操作可能就会影响到最终期望的结果,通常有四种情况:</p><ol><li>两个更新事务同时修改一条数据时,很显然这种情况是最严重的了,程序中无论如何也不能出现这种情况,因为它会造成更新的丢失</li><li>一个更新事务更新一条数据时,另一个读取事务读取了还没提交的更新,这种情况下会出现读取到脏数据</li><li>一个读取事务读取一条数据时,另一个更新事务修改了这条数据,这时就会出现不可重现的读取</li><li>一个读取事务读取时,另一个插入事务(注意此处时插入)插入了一条新数据,这样就可能多读出一条数据,出现幻读</li></ol><p>以上四种情况描述完毕,相信大家也发现规律了,前三种是对同一条数据的并发操作,对程序的结果可能产生致命影响,尤其是金融等实时性,准确性要求极高的系统,绝不容许这三中情况的出现,相比第四种情况不会影响数据的真实性,在很多情况下是允许的,如社交论坛等实时性要求不高的系统</p><p>综上四个情况,我们可以大致这样简单的理解(最初说的两种事务的自由组合2*2=4):</p><ol><li>修改时允许修改(丢失更新)</li><li>修改时允许读取(脏读)</li><li>读取时允许修改(不可重复读)</li><li>读取时允许插入(幻读)</li></ol><p>从上到下问题越来越不严重,但所需的性能开销却越大。因为不同的系统允许不同级别的情况,所以就出现了事务隔离这么一个东东,来允许我们设定数据库的并发行为</p><p>总结下如果不考虑事务的隔离性,会发生的几种问题:</p><ol><li><p>脏读:指在一个事务处理过程里读取了另一个未提交的事务中的数据</p><blockquote><p>当一个事务正在多次修改某个数据,而在这个事务中这多次的修改都还未提交,这时一个并发的事务来访问该数据,就会造成两个事务得到的数据不一致<br>例如:用户A向用户B转账100元,对应SQL命令如下:<br> update account set money=money+100 where name=’B’; (此时A通知B)<br> update account set money=money - 100 where name=’A’;<br>当只执行第一条SQL时,A通知B查看账户,B发现确实钱已到账(此时即发生了脏读),而之后无论第二条SQL是否执行,只要该事务不提交,则所有操作都将回滚,那么当B以后再次查看账户时就会发现钱其实并没有转</p></blockquote></li><li><p>不可重复读:指在对于数据库中的某个数据,一个事务范围内多次查询却返回了不同的数据值,这是由于在查询间隔,被另一个事务修改并提交了</p><blockquote><p>例如事务T1在读取某一数据,而事务T2立马修改了这个数据并且提交事务给数据库,事务T1再次读取该数据就得到了不同的结果,发送了不可重复读<br>不可重复读和脏读的区别是,脏读是某一事务读取了另一个事务未提交的脏数据,而不可重复读则是读取了前一事务提交的数据<br>在某些情况下,不可重复读并不是问题,比如我们多次查询某个数据当然以最后查询得到的结果为主。但在另一些情况下就有可能发生问题,例如对于同一个数据A和B依次查询就可能不同,A和B就可能打起来了……</p></blockquote></li><li><p>虚读(幻读):事务非独立执行时发生的一种现象</p><blockquote><p>例如事务T1对一个表中所有的行的某个数据项做了从“1”修改为“2”的操作,这时事务T2又对这个表中插入了一行数据项,而这个数据项的数值还是为“1”并且提交给数据库。而操作事务T1的用户如果再查看刚刚修改的数据,会发现还有一行没有修改,其实这行是从事务T2中添加的,就好像产生幻觉一样,这就是发生了幻读<br>幻读和不可重复读都是读取了另一条已经提交的事务(这点就脏读不同),所不同的是不可重复读查询的都是同一个数据项,而幻读针对的是一批数据整体(比如数据的个数)</p></blockquote></li></ol><h2 id="隔离级别"><a href="#隔离级别" class="headerlink" title="隔离级别"></a>隔离级别</h2><p>SQL标准定义了4类隔离级别,包括了一些具体规则,用来限定事务内外的哪些改变是可见的,哪些是不可见的。低级别的隔离级一般支持更高的并发处理,并拥有更低的系统开销</p><ol><li><p>Read Uncommitted(读取未提交内容):在该隔离级别,所有事务都可以看到其他未提交事务的执行结果</p><blockquote><p>本隔离级别很少用于实际应用,因为它的性能也不比其他级别好多少。读取未提交的数据,也被称之为脏读(Dirty Read)</p></blockquote></li><li><p>Read Committed(读取提交内容): 这是大多数数据库系统的默认隔离级别(但不是MySQL默认的)</p><blockquote><p>它满足了隔离的简单定义:一个事务只能看见已经提交事务所做的改变。这种隔离级别 也支持所谓的不可重复读(Nonrepeatable Read),因为同一事务的其他实例在该实例处理其间可能会有新的commit,所以同一select可能返回不同结果</p></blockquote></li><li><p>Repeatable Read(可重读):这是MySQL的默认事务隔离级别,它确保同一事务的多个实例在并发读取数据时,会看到同样的数据行</p><blockquote><p>不过理论上,这会导致另一个棘手的问题:幻读 (Phantom Read)。简单的说,幻读指当用户读取某一范围的数据行时,另一个事务又在该范围内插入了新行,当用户再读取该范围的数据行时,会发现有新的“幻影” 行<br>InnoDB和Falcon存储引擎通过多版本并发控制(MVCC,Multiversion Concurrency Control)机制解决了该问题</p></blockquote></li><li><p>Serializable(可串行化):这是最高的隔离级别,它通过强制事务排序,使之不可能相互冲突,从而解决幻读问题。简言之,它是在每个读的数据行上加上共享锁。在这个级别,可能导致大量的超时现象和锁竞争</p><blockquote><p> 这四种隔离级别采取不同的锁类型来实现,若读取的是同一个数据的话,就容易发生问题。例如:</p><ul><li>脏读(Drity Read):某个事务已更新一份数据,另一个事务在此时读取了同一份数据,由于某些原因,前一个RollBack了操作,则后一个事务所读取的数据就会是不正确的</li><li>不可重复读(Non-repeatable read):在一个事务的两次查询之中数据不一致,这可能是两次查询过程中间插入了一个事务更新的原有的数据</li><li>幻读(Phantom Read):在一个事务的两次查询中数据笔数不一致,例如有一个事务查询了几列(Row)数据,而另一个事务却在此时插入了新的几列数据,先前的事务在接下来的查询中,就会发现有几列数据是它先前所没有的</li></ul></blockquote></li></ol><p><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-03_01-54-46.webp"><br>以上四种隔离级别最高的是 Serializable 级别,最低的是 Read uncommitted 级别,当然<strong>级别越高,执行效率就越低,数据越安全</strong>。像 Serializable 这样的级别,就是以锁表的方式(类似于Java多线程中的锁)使得其他的线程只能在锁外等待,所以平时<strong>选用何种隔离级别应该根据实际情况</strong>。在<strong>MySQL数据库中默认的隔离级别为Repeatable read (可重复读)</strong></p><blockquote><p>在 Oracle 数据库中,只支持 Serializable (串行化)级别和 Read committed (读已提交)这两种级别,其中默认的为 Read committed 级别</p></blockquote><p>在MySQL数据库中查看当前事务的隔离级别: <strong>select @@tx_isolation;</strong></p><p>在MySQL数据库中设置事务的隔离 级别:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">set</span> [glogal <span class="operator">|</span> session] transaction isolation level 隔离级别名称;</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span> tx_isolation<span class="operator">=</span>’隔离级别名称;’</span><br></pre></td></tr></table></figure><p>注意:<strong>设置数据库的隔离级别一定要是在开启事务之前!</strong></p><p>隔离级别的设置只对当前链接有效。对于使用MySQL命令窗口而言,一个窗口就相当于一个链接,当前窗口设置的隔离级别只对当前窗口中的事务有效</p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Mysql数据库基础 </tag>
</tags>
</entry>
<entry>
<title>Mysql数据库基础(五)</title>
<link href="/posts/e2a2.html"/>
<url>/posts/e2a2.html</url>
<content type="html"><![CDATA[<h2 id="多表关系"><a href="#多表关系" class="headerlink" title="多表关系"></a>多表关系</h2><p>在项目开发进行数据库结构设计时,根据业务需求和业务模块之间的关系进行分享并设计表的结构,而由于业务之间是相互关联的,所以各个表结构之间也存在着各种联系,主要分为 <strong>一对多(多对一)</strong>、<strong>多对多</strong>、<strong>一对一</strong> 这三种</p><h3 id="一对多(多对一)"><a href="#一对多(多对一)" class="headerlink" title="一对多(多对一)"></a>一对多(多对一)</h3><p>例如部门与员工的关系:一个部门可以对应多个员工,而一个员工则对应一个部门,这种可以通过<strong>在多的一方建立外键,指向一的一方的主键</strong></p><h3 id="多对多"><a href="#多对多" class="headerlink" title="多对多"></a>多对多</h3><p>例如学生与课程的关系:一个学生可以选修多门课程,而一个课程可以被多名学生选修,这种可以通过<strong>建立第三张中间表,该表至少包含两个外键,分别关联两方主键</strong></p><p>创建学生表并插入数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 学生表</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> student (</span><br><span class="line"> id <span class="type">INT</span> auto_increment <span class="keyword">PRIMARY</span> KEY COMMENT <span class="string">'主键ID'</span>,</span><br><span class="line"> name <span class="type">VARCHAR</span> ( <span class="number">10</span> ) COMMENT <span class="string">'姓名'</span>,</span><br><span class="line"> <span class="keyword">no</span> <span class="type">VARCHAR</span> ( <span class="number">10</span> ) COMMENT <span class="string">'学号'</span> </span><br><span class="line">)COMMENT <span class="string">' 学生表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> student</span><br><span class="line"><span class="keyword">values</span> (<span class="keyword">null</span>,<span class="string">'黛绮丝'</span>,<span class="string">'2000100101'</span>),(<span class="keyword">null</span>,<span class="string">'谢逊'</span>,<span class="string">'2000100102'</span>),(<span class="keyword">null</span>,<span class="string">'殷天正'</span>,<span class="string">'2000100103'</span>),(<span class="keyword">null</span>,<span class="string">'韦一笑'</span>,<span class="string">'2000100104'</span>);</span><br></pre></td></tr></table></figure><p>创建课程表并插入数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> course(</span><br><span class="line">id <span class="type">int</span> auto_increment <span class="keyword">primary</span> key comment <span class="string">'主键ID'</span>,</span><br><span class="line">name <span class="type">varchar</span>(<span class="number">10</span>) comment <span class="string">'课程名称'</span></span><br><span class="line">)comment <span class="string">'课程表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> course </span><br><span class="line"><span class="keyword">values</span> (<span class="keyword">null</span>,<span class="string">'Java'</span>),(<span class="keyword">null</span>,<span class="string">'PHP'</span>),(<span class="keyword">null</span>,<span class="string">'Mysql'</span>),(<span class="keyword">null</span>,<span class="string">'Hadoop'</span>);</span><br></pre></td></tr></table></figure><p>上述两张表没有关联,可以通过<strong>中间表</strong>进行关联:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> student_course(</span><br><span class="line">id <span class="type">int</span> auto_increment comment <span class="string">'主键'</span> <span class="keyword">primary</span> key,</span><br><span class="line">studentid <span class="type">int</span> <span class="keyword">not</span> <span class="keyword">null</span> comment <span class="string">'学生ID'</span>,</span><br><span class="line">courseid <span class="type">int</span> <span class="keyword">not</span> <span class="keyword">null</span> comment <span class="string">'课程ID'</span>,</span><br><span class="line"><span class="keyword">constraint</span> fk_courseid <span class="keyword">foreign</span> key (courseid) <span class="keyword">references</span> course(id),</span><br><span class="line"><span class="keyword">constraint</span> fk_studentid <span class="keyword">foreign</span> key (studentid) <span class="keyword">references</span> student(id)</span><br><span class="line">)comment <span class="string">'学生课程中间表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> student_course </span><br><span class="line"><span class="keyword">values</span> (<span class="keyword">null</span>,<span class="number">1</span>,<span class="number">1</span>),(<span class="keyword">null</span>,<span class="number">1</span>,<span class="number">2</span>),(<span class="keyword">null</span>,<span class="number">1</span>,<span class="number">3</span>),(<span class="keyword">null</span>,<span class="number">2</span>,<span class="number">3</span>),(<span class="keyword">null</span>,<span class="number">3</span>,<span class="number">4</span>);</span><br></pre></td></tr></table></figure><h3 id="一对一"><a href="#一对一" class="headerlink" title="一对一"></a>一对一</h3><p>例如用户与用户详情的关系。一对一的关系多用于<strong>单表拆分</strong>,将一张表的基础字段放在一张表中,其他详情字段则放在另一张表中,用以提升操作效率</p><p>这种关系跟一对多(多对一)的处理类似,区别在于该<strong>外键是唯一(UNIQUE)</strong>的</p><p>创建用户基本信息表并插入数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> tb_user (</span><br><span class="line">id <span class="type">INT</span> AUTO_INCREMENT <span class="keyword">PRIMARY</span> KEY COMMENT <span class="string">'主键ID'</span>,</span><br><span class="line">name <span class="type">VARCHAR</span>(<span class="number">10</span>) COMMENT <span class="string">'姓名'</span>,</span><br><span class="line">age <span class="type">INT</span> COMMENT <span class="string">'年龄'</span>,</span><br><span class="line">gender <span class="type">CHAR</span>(<span class="number">1</span>) COMMENT <span class="string">'1: 男,2: 女'</span>,</span><br><span class="line">phone <span class="type">CHAR</span>(<span class="number">11</span>) COMMENT <span class="string">'手机号'</span></span><br><span class="line">) COMMENT <span class="string">'用户基本信息表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> tb_user(id, name, age, gender, phone) </span><br><span class="line"><span class="keyword">VALUES</span>(<span class="keyword">null</span>, <span class="string">'黄渤'</span>, <span class="number">45</span>, <span class="string">'1'</span>, <span class="string">'18800001111'</span>),</span><br><span class="line">(<span class="keyword">null</span>, <span class="string">'冰冰'</span>, <span class="number">352</span>, <span class="string">'1'</span>, <span class="string">'18800002222'</span>),</span><br><span class="line">(<span class="keyword">null</span>, <span class="string">'码云'</span>, <span class="number">55</span>, <span class="string">'1'</span>, <span class="string">'18800008888'</span>),</span><br><span class="line">(<span class="keyword">null</span>, <span class="string">'李彦宏'</span>, <span class="number">50</span>, <span class="string">'1'</span>, <span class="string">'18800009999'</span>);</span><br></pre></td></tr></table></figure><p>创建用户详情表并插入数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> tb_user_edu(</span><br><span class="line">id <span class="type">INT</span> AUTO_INCREMENT <span class="keyword">PRIMARY</span> KEY COMMENT <span class="string">'主键ID'</span>,</span><br><span class="line">degree <span class="type">VARCHAR</span>(<span class="number">20</span>) COMMENT <span class="string">'学历'</span>,</span><br><span class="line">major <span class="type">VARCHAR</span>(<span class="number">50</span>) COMMENT <span class="string">'专业'</span>,</span><br><span class="line">primaryschool <span class="type">VARCHAR</span>(<span class="number">50</span>) COMMENT <span class="string">'小学'</span>,</span><br><span class="line">middleschool <span class="type">VARCHAR</span>(<span class="number">50</span>) COMMENT <span class="string">'中学'</span>,</span><br><span class="line">university <span class="type">VARCHAR</span>(<span class="number">50</span>) COMMENT <span class="string">'大学'</span>,</span><br><span class="line">userid <span class="type">INT</span> <span class="keyword">UNIQUE</span> COMMENT <span class="string">'用户ID'</span>,</span><br><span class="line"><span class="keyword">CONSTRAINT</span> fk_userid <span class="keyword">FOREIGN</span> KEY (userid) <span class="keyword">REFERENCES</span> tb_user(id)</span><br><span class="line">) COMMENT <span class="string">'用户教育信息表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> tb_user_edu(id, degree, major, primaryschool, middleschool, university, userid) </span><br><span class="line"><span class="keyword">VALUES</span>(<span class="keyword">null</span>, <span class="string">'本科'</span>, <span class="string">'舞蹈'</span>, <span class="string">'静安区第一小学'</span>, <span class="string">'静安区第一中学'</span>, <span class="string">'北京舞蹈学院'</span>, <span class="number">1</span>),</span><br><span class="line">(<span class="keyword">null</span>, <span class="string">'硕士'</span>, <span class="string">'表演'</span>, <span class="string">'朝阳区第一小学'</span>, <span class="string">'朝阳区第一中学'</span>, <span class="string">'北京电影学院'</span>, <span class="number">2</span>),</span><br><span class="line">(<span class="keyword">null</span>, <span class="string">'本科'</span>, <span class="string">'英语'</span>, <span class="string">'杭州市第一小学'</span>, <span class="string">'杭州市第一中学'</span>, <span class="string">'杭州师范大学'</span>, <span class="number">3</span>),</span><br><span class="line">(<span class="keyword">null</span>, <span class="string">'本科'</span>, <span class="string">'应用数学'</span>, <span class="string">'阳泉第一小学'</span>, <span class="string">'阳泉区第一中学'</span>, <span class="string">'清华大学'</span>, <span class="number">4</span>);</span><br></pre></td></tr></table></figure><p>可以看出对 userid 使用了唯一 UNIQUE</p><h2 id="多表查询"><a href="#多表查询" class="headerlink" title="多表查询"></a>多表查询</h2><p>从多张表中查询数据。按照 <strong>SELECT * FROM A表,B表</strong> 来进行查询会造成<strong>数据冗余</strong>,即笛卡尔积。很明显,这种数据并不是我们所需要的,所以在进行多表查询时我们需要消除无效的笛卡尔积</p><blockquote><p>笛卡尔积:两个集合的所有组合情况,即A集合有2条数据,B集合有3条数据,那么总共会形成6条数据</p></blockquote><p>多表查询主要分为 <strong>连接查询</strong> 和 <strong>子查询</strong></p><ul><li>连接查询分为 <strong>内连接</strong>、<strong>外连接</strong>、<strong>自连接</strong></li><li>子查询,又被称为嵌套查询,分为 <strong>标量子查询</strong>、<strong>列子查询</strong>、<strong>行子查询</strong>、<strong>表子查询</strong></li></ul><h2 id="连接查询"><a href="#连接查询" class="headerlink" title="连接查询"></a>连接查询</h2><h3 id="内连接"><a href="#内连接" class="headerlink" title="内连接"></a>内连接</h3><p>内连接所查询的是<strong>两张表所交集的部分</strong>,分为隐式内连接和显式内连接</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 隐式内连接</span></span><br><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表<span class="number">1</span>,表<span class="number">2</span> <span class="keyword">WHERE</span> 条件;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 显式内连接</span></span><br><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表<span class="number">1</span> [<span class="keyword">INNER</span>] <span class="keyword">JOIN</span> 表<span class="number">2</span> <span class="keyword">ON</span> 连接条件;</span><br></pre></td></tr></table></figure><p>查询员工所对应的部门:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 隐式内连接</span></span><br><span class="line"><span class="keyword">SELECT</span> emp.name <span class="keyword">as</span> <span class="string">'员工'</span> , dept.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp,dept <span class="keyword">WHERE</span> emp.dept_id <span class="operator">=</span> dept.id;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 显式内连接</span></span><br><span class="line"><span class="keyword">SELECT</span> emp.name <span class="keyword">as</span> <span class="string">'员工'</span> , dept.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp <span class="keyword">INNER</span> <span class="keyword">JOIN</span> dept <span class="keyword">ON</span> emp.dept_id <span class="operator">=</span> dept.id;</span><br></pre></td></tr></table></figure><h3 id="外连接"><a href="#外连接" class="headerlink" title="外连接"></a>外连接</h3><p>外连接分为左外连接和右外连接:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 左外连接:表1数据 + 表1和表2交集</span></span><br><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表<span class="number">1</span> <span class="keyword">LEFT</span> [<span class="keyword">OUTER</span>] <span class="keyword">JOIN</span> 表<span class="number">2</span> <span class="keyword">ON</span> 条件;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 右外连接:表2数据 + 表1和表2交集</span></span><br><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表<span class="number">1</span> <span class="keyword">RIGHT</span> [<span class="keyword">OUTER</span>] <span class="keyword">JOIN</span> 表<span class="number">2</span> <span class="keyword">ON</span> 条件;</span><br></pre></td></tr></table></figure><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- emp表的所有数据和其对应的部门信息</span></span><br><span class="line"><span class="keyword">SELECT</span> e.<span class="operator">*</span>,d.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp e <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> dept d <span class="keyword">ON</span> e.dept_id <span class="operator">=</span> d.id;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- dept表的所有数据与其所在的员工</span></span><br><span class="line"><span class="keyword">SELECT</span> e.name <span class="keyword">as</span> <span class="string">'员工'</span>, d.<span class="operator">*</span> <span class="keyword">FROM</span> emp e <span class="keyword">RIGHT</span> <span class="keyword">JOIN</span> dept d <span class="keyword">ON</span> e.dept_id <span class="operator">=</span> d.id;</span><br></pre></td></tr></table></figure><h3 id="自连接"><a href="#自连接" class="headerlink" title="自连接"></a>自连接</h3><p>自连接可以是内连接,也可以是外连接</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表A 别名A <span class="keyword">JOIN</span> 表A 别名B <span class="keyword">ON</span> 条件;</span><br></pre></td></tr></table></figure><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 员工的所属领导</span></span><br><span class="line"><span class="keyword">SELECT</span> ework.name <span class="keyword">as</span> <span class="string">'员工'</span>,emana.name <span class="keyword">as</span> <span class="string">'所属领导'</span> <span class="keyword">FROM</span> emp ework <span class="keyword">JOIN</span> emp emana <span class="keyword">ON</span> ework.managerid <span class="operator">=</span> emana.id;</span><br><span class="line"><span class="keyword">SELECT</span> ework.name <span class="keyword">as</span> <span class="string">'员工'</span>,emana.name <span class="keyword">as</span> <span class="string">'所属领导'</span> <span class="keyword">FROM</span> emp ework , emp emana <span class="keyword">WHERE</span> ework.managerid <span class="operator">=</span> emana.id;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 员工的所属领导,没有领导也要查出来</span></span><br><span class="line"><span class="keyword">SELECT</span> ework.name <span class="keyword">as</span> <span class="string">'员工'</span>,emana.name <span class="keyword">as</span> <span class="string">'所属领导'</span> <span class="keyword">FROM</span> emp ework <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> emp emana <span class="keyword">ON</span> ework.managerid <span class="operator">=</span> emana.id;</span><br></pre></td></tr></table></figure><h2 id="联合查询"><a href="#联合查询" class="headerlink" title="联合查询"></a>联合查询</h2><p>将多次查询的结果合并起来形成一个新的结果集:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表A</span><br><span class="line"><span class="keyword">UNION</span> [<span class="keyword">ALL</span>]</span><br><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表B;</span><br></pre></td></tr></table></figure><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 薪资低于10000的员工和年龄大于30岁的员工</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">Where</span> age <span class="operator">></span> <span class="number">30</span></span><br><span class="line"><span class="keyword">UNION</span> <span class="keyword">ALL</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> salary <span class="operator"><</span> <span class="number">10000</span>;</span><br></pre></td></tr></table></figure><p>多张表的<strong>列数必须保持一致</strong>,字段<strong>类型也必须要保持一致</strong></p><p>UNION ALL 会将全部查询返回的数据直接合并在一起,而 UNION 会<strong>对合并之后的数据去重</strong></p><h2 id="子查询"><a href="#子查询" class="headerlink" title="子查询"></a>子查询</h2><p>子查询语法:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> t1 <span class="keyword">WHERE</span> column1 <span class="operator">=</span> (<span class="keyword">SELECT</span> column1 <span class="keyword">FROM</span> t2)</span><br></pre></td></tr></table></figure><p>该外部语句除了可以是查询外,还能是增删改其中一种</p><h3 id="标量子查询"><a href="#标量子查询" class="headerlink" title="标量子查询"></a>标量子查询</h3><p>所返回的结果是<strong>单个值</strong>(字符串、数字、日期等),是最简单的形式</p><p>常用的操作符有:=、<>、>、>=、<、<=</p><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 杨逍之后入职的员工信息</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> entrydate <span class="operator">></span> (<span class="keyword">SELECT</span> entrydate <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'杨逍'</span>);</span><br></pre></td></tr></table></figure><h3 id="列子查询"><a href="#列子查询" class="headerlink" title="列子查询"></a>列子查询</h3><p>子查询所返回的结果是<strong>一列(也可以是多行)</strong>,这种子查询称为列子查询</p><p>常见的操作符如下图所示:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_22-34-34.webp"></p><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询销售部和市场部的所有员工信息</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> dept_id <span class="keyword">in</span> (<span class="keyword">SELECT</span> id <span class="keyword">FROM</span> dept <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'销售部'</span> <span class="operator">||</span> name <span class="operator">=</span> <span class="string">'市场部'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询比财务部所有人工资高的员工信息</span></span><br><span class="line"><span class="keyword">SELECT</span> id <span class="keyword">from</span> dept <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'财务部'</span>;</span><br><span class="line"><span class="keyword">SELECT</span> salary <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> dept_id <span class="operator">=</span> (<span class="keyword">SELECT</span> id <span class="keyword">from</span> dept <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'财务部'</span>);</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> salary <span class="operator">></span> <span class="keyword">ALL</span> (<span class="keyword">SELECT</span> salary <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> dept_id <span class="operator">=</span> (<span class="keyword">SELECT</span> id <span class="keyword">from</span> dept <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'财务部'</span>));</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询比研发部其中任意一人工资高的员工信息</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> salary <span class="operator">></span> <span class="keyword">SOME</span> (<span class="keyword">SELECT</span> salary <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> dept_id <span class="operator">=</span> (<span class="keyword">SELECT</span> id <span class="keyword">FROM</span> dept <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'研发部'</span>));</span><br></pre></td></tr></table></figure><h3 id="行子查询"><a href="#行子查询" class="headerlink" title="行子查询"></a>行子查询</h3><p>子查询所返回的结果是<strong>一行(也可以是多列)</strong>,这种子查询称为行子查询</p><p>常用的操作符有:=、<>、IN、NOT IN</p><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询与'张无忌'的薪资及直属领导相同的员工信息</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> (salary,managerid) <span class="operator">=</span> (<span class="keyword">SELECT</span> salary,managerid <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'张无忌'</span>);</span><br></pre></td></tr></table></figure><h3 id="行子查询-1"><a href="#行子查询-1" class="headerlink" title="行子查询"></a>行子查询</h3><p>子查询所返回的结果是<strong>多行多列</strong>,这种子查询称为表子查询</p><p>常用的操作符有:IN</p><p>练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询与'杨逍'薪资和工作相同的员工信息</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> (salary,job) <span class="keyword">IN</span> (<span class="keyword">SELECT</span> salary,job <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'杨逍'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询在2004-09-07后入职的员工部门信息</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> (<span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> entrydate <span class="operator">></span> <span class="string">'2004-09-07'</span>) e <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> dept d <span class="keyword">ON</span> e.dept_id <span class="operator">=</span> d.id;</span><br></pre></td></tr></table></figure><h2 id="案例练习"><a href="#案例练习" class="headerlink" title="案例练习"></a>案例练习</h2><h3 id="建表"><a href="#建表" class="headerlink" title="建表"></a>建表</h3><p>上述练习没有删除 emp表 和 dept表 的数据,但是基本操作相同,除了数据</p><p>现在重新创建 dept表,并插入相应数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> dept ( id <span class="type">INT</span> <span class="keyword">PRIMARY</span> KEY auto_increment, NAME <span class="type">VARCHAR</span> ( <span class="number">10</span> ) );</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> dept</span><br><span class="line"><span class="keyword">VALUES</span></span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'研发部'</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'市场部'</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'财务部'</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'销售部'</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'总经办'</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'人事部'</span> );</span><br></pre></td></tr></table></figure><p>创建 emp表,并插入数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> emp (</span><br><span class="line">id <span class="type">INT</span> <span class="keyword">PRIMARY</span> KEY auto_increment,</span><br><span class="line">NAME <span class="type">VARCHAR</span> ( <span class="number">10</span> ),</span><br><span class="line">age <span class="type">INT</span>,</span><br><span class="line">job <span class="type">VARCHAR</span> ( <span class="number">10</span> ),</span><br><span class="line">salary <span class="type">INT</span>,</span><br><span class="line">entrydate <span class="type">date</span>,</span><br><span class="line">managerid <span class="type">INT</span>,</span><br><span class="line">dept_id <span class="type">INT</span>,</span><br><span class="line"><span class="keyword">CONSTRAINT</span> fk_dept <span class="keyword">FOREIGN</span> KEY ( dept_id ) <span class="keyword">REFERENCES</span> dept ( id ) </span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> emp</span><br><span class="line"><span class="keyword">VALUES</span></span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'金庸'</span>, <span class="number">66</span>, <span class="string">'总裁'</span>, <span class="number">20000</span>, <span class="string">'2000-01-01'</span>, <span class="keyword">NULL</span>, <span class="number">5</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'张无忌'</span>, <span class="number">20</span>, <span class="string">'项目经理'</span>, <span class="number">12500</span>, <span class="string">'2005-12-05'</span>, <span class="number">1</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'杨逍'</span>, <span class="number">33</span>, <span class="string">'开发'</span>, <span class="number">8400</span>, <span class="string">'2000-11-03'</span>, <span class="number">2</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'韦一笑'</span>, <span class="number">48</span>, <span class="string">'开发'</span>, <span class="number">11000</span>, <span class="string">'2002-02-05'</span>, <span class="number">2</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'常遇春'</span>, <span class="number">43</span>, <span class="string">'开发'</span>, <span class="number">10500</span>, <span class="string">'2004-09-07'</span>, <span class="number">3</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'小昭'</span>, <span class="number">19</span>, <span class="string">'程序员鼓励师'</span>, <span class="number">6600</span>, <span class="string">'2004-10-12'</span>, <span class="number">2</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'灭绝'</span>, <span class="number">60</span>, <span class="string">'财务总监'</span>, <span class="number">8500</span>, <span class="string">'2002-09-12'</span>, <span class="number">1</span>, <span class="number">3</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'周芷若'</span>, <span class="number">19</span>, <span class="string">'会计'</span>, <span class="number">4800</span>, <span class="string">'2006-06-02'</span>, <span class="number">7</span>, <span class="number">3</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'丁敏君'</span>, <span class="number">23</span>, <span class="string">'出纳'</span>, <span class="number">5250</span>, <span class="string">'2009-05-13'</span>, <span class="number">7</span>, <span class="number">3</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'赵敏'</span>, <span class="number">20</span>, <span class="string">'市场部总监'</span>, <span class="number">12500</span>, <span class="string">'2004-10-12'</span>, <span class="number">1</span>, <span class="number">2</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'鹿杖客'</span>, <span class="number">56</span>, <span class="string">'职员'</span>, <span class="number">3750</span>, <span class="string">'2006-10-03'</span>, <span class="number">10</span>, <span class="number">2</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'鹤笔翁'</span>, <span class="number">19</span>, <span class="string">'职员'</span>, <span class="number">3750</span>, <span class="string">'2007-05-09'</span>, <span class="number">10</span>, <span class="number">2</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'方东白'</span>, <span class="number">19</span>, <span class="string">'职员'</span>, <span class="number">5500</span>, <span class="string">'2009-02-12'</span>, <span class="number">10</span>, <span class="number">2</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'张三丰'</span>, <span class="number">88</span>, <span class="string">'销售总监'</span>, <span class="number">14000</span>, <span class="string">'2004-10-12'</span>, <span class="number">1</span>, <span class="number">4</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'俞莲舟'</span>, <span class="number">38</span>, <span class="string">'销售'</span>, <span class="number">4600</span>, <span class="string">'2004-10-12'</span>, <span class="number">14</span>, <span class="number">4</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'宋远桥'</span>, <span class="number">40</span>, <span class="string">'销售'</span>, <span class="number">4600</span>, <span class="string">'2004-10-12'</span>, <span class="number">14</span>, <span class="number">4</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'陈友谅'</span>, <span class="number">42</span>, <span class="keyword">NULL</span>, <span class="number">2000</span>, <span class="string">'2011-10-12'</span>, <span class="number">1</span>, <span class="keyword">NULL</span> );</span><br></pre></td></tr></table></figure><p>创建 salgrade表,并插入相应数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> salgrade ( grade <span class="type">INT</span>, losal <span class="type">INT</span>, hisal <span class="type">INT</span> ) COMMENT <span class="string">'薪资等级表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> salgrade</span><br><span class="line"><span class="keyword">VALUES</span></span><br><span class="line">( <span class="number">1</span>, <span class="number">0</span>, <span class="number">3000</span> ),</span><br><span class="line">( <span class="number">2</span>, <span class="number">3001</span>, <span class="number">5000</span> ),</span><br><span class="line">( <span class="number">3</span>, <span class="number">5001</span>, <span class="number">8000</span> ),</span><br><span class="line">( <span class="number">4</span>, <span class="number">8001</span>, <span class="number">10000</span> ),</span><br><span class="line">( <span class="number">5</span>, <span class="number">10001</span>, <span class="number">15000</span> ),</span><br><span class="line">( <span class="number">6</span>, <span class="number">15001</span>, <span class="number">20000</span> ),</span><br><span class="line">( <span class="number">7</span>, <span class="number">20001</span>, <span class="number">25000</span> ),</span><br><span class="line">( <span class="number">8</span>, <span class="number">25001</span>, <span class="number">30000</span> );</span><br></pre></td></tr></table></figure><h3 id="练习"><a href="#练习" class="headerlink" title="练习"></a>练习</h3><ul><li><p>1、查询员工的姓名、年龄、职位、部门信息(隐式内连接)</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> e.name,e.age,e.job,d.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp e, dept d <span class="keyword">WHERE</span> e.dept_id <span class="operator">=</span> d.id;</span><br></pre></td></tr></table></figure></li><li><p>2、查询年龄小于30岁的员工姓名、年龄、职位、部门信息(显示式内连接)</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> e.name,e.age,e.job,d.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp e <span class="keyword">INNER</span> <span class="keyword">JOIN</span> dept d <span class="keyword">ON</span> e.dept_id <span class="operator">=</span> d.id <span class="operator">&&</span> e.age <span class="operator"><</span> <span class="number">30</span>;</span><br></pre></td></tr></table></figure></li><li><p>3、查询所有员工的部门ID、部门名称</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span> d.id,d.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp e , dept d <span class="keyword">WHERE</span> e.dept_id <span class="operator">=</span> d.id;</span><br></pre></td></tr></table></figure></li><li><p>4、查询所有年龄大于40岁的员工及其所属部门名称,如果没有也需要展示出来</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> e.<span class="operator">*</span>,d.name <span class="keyword">as</span> <span class="string">'部门'</span> <span class="keyword">FROM</span> emp e <span class="keyword">LEFT</span> <span class="keyword">JOIN</span> dept d <span class="keyword">ON</span> e.dept_id <span class="operator">=</span> d.id <span class="keyword">WHERE</span> e.age <span class="operator">></span> <span class="number">40</span>;</span><br></pre></td></tr></table></figure></li><li><p>5、查询所有员工的工资等级</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> e.<span class="operator">*</span>,s.grade <span class="keyword">AS</span> <span class="string">'薪资等级'</span> <span class="keyword">FROM</span> emp e,salgrade s <span class="keyword">WHERE</span> e.salary <span class="keyword">BETWEEN</span> s.losal <span class="keyword">AND</span> s.hisal;</span><br></pre></td></tr></table></figure></li><li><p>6、查询’研发部’所有员工的信息及工资等级</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> e.<span class="operator">*</span>,s.grade <span class="keyword">FROM</span> (<span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> emp.dept_id <span class="operator">=</span> (<span class="keyword">SELECT</span> id <span class="keyword">FROM</span> dept <span class="keyword">WHERE</span> name <span class="operator">=</span> <span class="string">'研发部'</span>)) e,salgrade s <span class="keyword">WHERE</span> e.salary <span class="keyword">BETWEEN</span> s.losal <span class="keyword">AND</span> s.hisal;</span><br></pre></td></tr></table></figure></li><li><p>7、查询’研发部’的平均工资</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> d.name <span class="keyword">as</span> <span class="string">'部门'</span>,<span class="built_in">AVG</span>(e.salary) <span class="keyword">AS</span> <span class="string">'平均工资'</span> <span class="keyword">FROM</span> emp e,dept d <span class="keyword">WHERE</span> e.dept_id <span class="operator">=</span> d.id <span class="keyword">and</span> d.name <span class="operator">=</span> <span class="string">'研发部'</span>;</span><br></pre></td></tr></table></figure></li><li><p>8、查询工资比’灭绝’高的员工信息</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> salary <span class="operator">></span> (<span class="keyword">SELECT</span> salary <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> emp.name <span class="operator">=</span> <span class="string">'灭绝'</span>);</span><br></pre></td></tr></table></figure></li><li><p>9、查询比平均薪资高的员工信息</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> salary <span class="operator">></span> (<span class="keyword">SELECT</span> <span class="built_in">AVG</span>(emp.salary) <span class="keyword">FROM</span> emp);</span><br></pre></td></tr></table></figure></li><li><p>10、查询低于本部门平均薪资的员工信息</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">AVG</span>(e.salary) <span class="keyword">FROM</span> emp e <span class="keyword">WHERE</span> e.dept_id <span class="operator">=</span> <span class="number">3</span>;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> emp e2 <span class="keyword">WHERE</span> salary <span class="operator"><</span> (<span class="keyword">SELECT</span> <span class="built_in">AVG</span>(e.salary) <span class="keyword">FROM</span> emp e <span class="keyword">WHERE</span> e.dept_id <span class="operator">=</span> e2.dept_id);</span><br></pre></td></tr></table></figure></li><li><p>11、查询所有的部门信息,并统计部门的人数</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="built_in">COUNT</span>(<span class="operator">*</span>) <span class="keyword">FROM</span> emp <span class="keyword">WHERE</span> dept_id <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line"><span class="keyword">SELECT</span> d.id,d.name,(<span class="keyword">SELECT</span> <span class="built_in">COUNT</span>(<span class="operator">*</span>) <span class="keyword">FROM</span> emp e <span class="keyword">WHERE</span> e.dept_id <span class="operator">=</span> d.id) <span class="keyword">AS</span> <span class="string">'人数'</span> <span class="keyword">FROM</span> dept d;</span><br></pre></td></tr></table></figure></li><li><p>12、查询所有学生的选课情况,展示学生名称、学号、课程名称</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 所涉及表:student、course、student_course</span></span><br><span class="line"><span class="comment">-- 连接条件:student.id = student_course.studentid、course.id = student_course.courseid</span></span><br><span class="line"><span class="keyword">SELECT</span> s.name,s.no,c.name <span class="keyword">FROM</span> student s,course c,student_course sc <span class="keyword">WHERE</span> s.id <span class="operator">=</span> sc.studentid <span class="keyword">AND</span> c.id <span class="operator">=</span> sc.courseid;</span><br></pre></td></tr></table></figure></li></ul>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Mysql数据库基础 </tag>
</tags>
</entry>
<entry>
<title>Mysql数据库基础(四)</title>
<link href="/posts/201c.html"/>
<url>/posts/201c.html</url>
<content type="html"><![CDATA[<h2 id="约束概述"><a href="#约束概述" class="headerlink" title="约束概述"></a>约束概述</h2><p>概念:作用于表中字段的<strong>规则</strong>,用于限制存储在表中的数据</p><p>目的:保证数据库中数据的正确,有效性和完整性</p><p>约束有以下几种分类:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_10-27-19.webp"></p><p>因为约束时作用于表中字段的,所以可以在<strong>创建表/修改表</strong>时进行添加</p><p>根据需求,完成该 user 表的创建:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_10-37-29.webp"></p><p>上述SQL语句:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> <span class="keyword">USER</span> (</span><br><span class="line">id <span class="type">INT</span> <span class="keyword">PRIMARY</span> KEY auto_increment COMMENT <span class="string">'ID唯一表示'</span>,</span><br><span class="line">NAME <span class="type">VARCHAR</span> ( <span class="number">10</span> ) <span class="keyword">NOT</span> <span class="keyword">NULL</span> <span class="keyword">UNIQUE</span> COMMENT <span class="string">'姓名'</span>,</span><br><span class="line">age <span class="type">INT</span> <span class="keyword">CHECK</span> ( age <span class="operator">></span> <span class="number">0</span> <span class="operator">&&</span> age <span class="operator"><=</span> <span class="number">120</span> ) COMMENT <span class="string">'年龄'</span>,</span><br><span class="line">STATUS <span class="type">CHAR</span> ( <span class="number">1</span> ) <span class="keyword">DEFAULT</span> <span class="string">'1'</span> COMMENT <span class="string">'状态'</span>,</span><br><span class="line">gender <span class="type">CHAR</span> ( <span class="number">1</span> ) COMMENT <span class="string">'性别'</span></span><br><span class="line">) COMMENT <span class="string">'约束练习'</span>;</span><br></pre></td></tr></table></figure><h2 id="外键约束"><a href="#外键约束" class="headerlink" title="外键约束"></a>外键约束</h2><p>外键是用来<strong>建立两张表数据之间的连接</strong>,从而保证数据的一致性和完整性</p><p>具有外键的表我们称之为<strong>子表(从表)</strong>,而其关联的另一张表称之为<strong>父表(主表)</strong></p><p>添加外键:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> emp <span class="keyword">ADD</span> <span class="keyword">CONSTRAINT</span> 外键名称 <span class="keyword">FOREIGN</span> KEY(外键字段名) <span class="keyword">REFERENCES</span> 主表(主表列名);</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 也可以在创建表时添加</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名 (</span><br><span class="line"> 字段名 数据类型,</span><br><span class="line"><span class="keyword">CONSTRAINT</span> 外键名称 <span class="keyword">FOREIGN</span> KEY (外键字段名) <span class="keyword">REFERENCES</span> 主表(主表列名)</span><br><span class="line">);</span><br></pre></td></tr></table></figure><p>删除外键:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">DROP</span> <span class="keyword">FOREIGN</span> KEY 外键名称;</span><br></pre></td></tr></table></figure><p>外键默认是不允许更新或删除的,这与其更新/删除<strong>行为</strong>有关,主要有以下几种:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_11-22-34.webp"></p><p>可以在外键相关SQL语句后面更新该行为,如:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> emp <span class="keyword">ADD</span> <span class="keyword">CONSTRAINT</span> 外键名称 <span class="keyword">FOREIGN</span> KEY(外键字段名) <span class="keyword">REFERENCES</span> 主表(主表列名) <span class="keyword">ON</span> <span class="keyword">UPDATE</span> 行为 <span class="keyword">ON</span> <span class="keyword">DELETE</span> 行为;</span><br></pre></td></tr></table></figure><h3 id="案例练习"><a href="#案例练习" class="headerlink" title="案例练习"></a>案例练习</h3><p>将之前的 emp(员工)表删除,创建一个 dept(部门) 表和 emp(员工)表:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- dept表</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> dept ( id <span class="type">INT</span> auto_increment COMMENT <span class="string">'ID'</span> <span class="keyword">PRIMARY</span> KEY, NAME <span class="type">VARCHAR</span> ( <span class="number">50</span> ) <span class="keyword">NOT</span> <span class="keyword">NULL</span> COMMENT <span class="string">'部门名称'</span> ) COMMENT <span class="string">'部门表'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- emp表</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> emp (</span><br><span class="line">id <span class="type">INT</span> AUTO_INCREMENT COMMENT <span class="string">'ID'</span> <span class="keyword">PRIMARY</span> KEY,</span><br><span class="line">NAME <span class="type">VARCHAR</span> ( <span class="number">50</span> ) <span class="keyword">NOT</span> <span class="keyword">NULL</span> COMMENT <span class="string">'姓名'</span>,</span><br><span class="line">age <span class="type">INT</span> COMMENT <span class="string">'年龄'</span>,</span><br><span class="line">job <span class="type">VARCHAR</span> ( <span class="number">20</span> ) COMMENT <span class="string">'职位'</span>,</span><br><span class="line">salary <span class="type">INT</span> COMMENT <span class="string">'薪资'</span>,</span><br><span class="line">entrydate <span class="type">date</span> COMMENT <span class="string">'入职时间'</span>,</span><br><span class="line">managerid <span class="type">INT</span> COMMENT <span class="string">'直属领导ID'</span>,</span><br><span class="line">dept_id <span class="type">INT</span> COMMENT <span class="string">'部门ID'</span> </span><br><span class="line">) COMMENT <span class="string">'员工表'</span>;</span><br></pre></td></tr></table></figure><p>插入相应的数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- dept表</span></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> dept ( id, NAME ) <span class="keyword">VALUES</span>( <span class="number">1</span>, <span class="string">'研发部'</span> ),(<span class="number">2</span>,<span class="string">'市场部'</span> ),(<span class="number">3</span>,<span class="string">'财务部'</span> ),(<span class="number">4</span>,<span class="string">'销售部'</span> ),(<span class="number">5</span>,<span class="string">'总经办'</span> );</span><br><span class="line"></span><br><span class="line"><span class="comment">-- emp表</span></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> emp</span><br><span class="line"><span class="keyword">VALUES</span></span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'金庸'</span>, <span class="number">66</span>, <span class="string">'总裁'</span>, <span class="number">20000</span>, <span class="string">'2000-01-01'</span>, <span class="keyword">NULL</span>, <span class="number">5</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'张无忌'</span>, <span class="number">20</span>, <span class="string">'项目经理'</span>, <span class="number">12500</span>, <span class="string">'2005-12-05'</span>, <span class="number">1</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'杨逍'</span>, <span class="number">33</span>, <span class="string">'开发'</span>, <span class="number">8400</span>, <span class="string">'2000-11-03'</span>, <span class="number">2</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'韦一笑'</span>, <span class="number">48</span>, <span class="string">'开发'</span>, <span class="number">11000</span>, <span class="string">'2002-02-05'</span>, <span class="number">2</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'常遇春'</span>, <span class="number">43</span>, <span class="string">'开发'</span>, <span class="number">10500</span>, <span class="string">'2004-09-07'</span>, <span class="number">3</span>, <span class="number">1</span> ),</span><br><span class="line">( <span class="keyword">NULL</span>, <span class="string">'小昭'</span>, <span class="number">19</span>, <span class="string">'程序员鼓励师'</span>, <span class="number">6600</span>, <span class="string">'2004-10-12'</span>, <span class="number">2</span>, <span class="number">1</span> );</span><br></pre></td></tr></table></figure><p>给 emp 表添加外键:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> emp <span class="keyword">ADD</span> <span class="keyword">CONSTRAINT</span> fk_emp_dept_id <span class="keyword">FOREIGN</span> KEY (dept_id) <span class="keyword">REFERENCES</span> dept(id);</span><br></pre></td></tr></table></figure><p>当成功添加外键后,这时我们想删除部门表的研发部时会报错,提示存在外键。我们可以删除该外键:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> emp <span class="keyword">drop</span> <span class="keyword">FOREIGN</span> key fk_emp_dept_id;</span><br></pre></td></tr></table></figure><p>这时就可以将研发部给删除掉了</p><p>给外键添加 <strong>CASCADE</strong> 行为后,可以看出员工表一旦发生变化,那么 emp 表其对应的部门 id 也会跟随着其改变</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> emp <span class="keyword">ADD</span> <span class="keyword">CONSTRAINT</span> fk_emp_dept_id <span class="keyword">FOREIGN</span> KEY (dept_id) <span class="keyword">REFERENCES</span> dept(id);</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Mysql数据库基础 </tag>
</tags>
</entry>
<entry>
<title>Mysql数据库基础(三)</title>
<link href="/posts/4edd.html"/>
<url>/posts/4edd.html</url>
<content type="html"><![CDATA[<p><strong>函数</strong>是指一段可以被另一个程序直接调用的程序或代码</p><h2 id="字符串函数"><a href="#字符串函数" class="headerlink" title="字符串函数"></a>字符串函数</h2><p>常见的字符串函数如下:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_09-44-54.webp"></p><p>可以通过 <strong>SELECT 函数(参数)</strong> 来使用这些函数</p><h2 id="数值函数"><a href="#数值函数" class="headerlink" title="数值函数"></a>数值函数</h2><p>常见的数值函数如下:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_09-52-33.webp"></p><p>1.1 向上取整是 2,向下取整则是 1;4/3 取模则是 1</p><h2 id="日期函数"><a href="#日期函数" class="headerlink" title="日期函数"></a>日期函数</h2><p>常见的数值函数如下:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_10-03-12.webp"></p><h2 id="流程函数"><a href="#流程函数" class="headerlink" title="流程函数"></a>流程函数</h2><p>流畅函数是一种常用的函数,常用于<strong>SQL语句的条件筛选</strong>,从而提高其效率<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_10-07-02.webp"></p><p>创建 score 表:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> score (</span><br><span class="line">id <span class="type">INT</span> COMMENT <span class="string">'编号'</span>,</span><br><span class="line">NAME <span class="type">VARCHAR</span> ( <span class="number">20</span> ) COMMENT <span class="string">'姓名'</span>,</span><br><span class="line">math <span class="type">INT</span> COMMENT <span class="string">'数学'</span>,</span><br><span class="line">english <span class="type">INT</span> COMMENT <span class="string">'英语'</span>,</span><br><span class="line">chinese <span class="type">INT</span> COMMENT <span class="string">'语文'</span> </span><br><span class="line">) COMMENT <span class="string">'学员成绩表'</span>;</span><br></pre></td></tr></table></figure><p>插入相应的数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> score</span><br><span class="line"><span class="keyword">VALUES</span></span><br><span class="line">( <span class="number">1</span>, <span class="string">'Tom'</span>, <span class="number">67</span>, <span class="number">88</span>, <span class="number">95</span> ),</span><br><span class="line">( <span class="number">2</span>, <span class="string">'Rose'</span>, <span class="number">23</span>, <span class="number">66</span>, <span class="number">90</span> ),</span><br><span class="line">( <span class="number">3</span>, <span class="string">'Jack'</span>, <span class="number">56</span>, <span class="number">98</span>, <span class="number">76</span> );</span><br></pre></td></tr></table></figure><p>成绩大于等于85的为优秀,大于等于60的为合格,否则为不及格:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span></span><br><span class="line">id,</span><br><span class="line">name,</span><br><span class="line">( <span class="keyword">CASE</span> <span class="keyword">WHEN</span> math <span class="operator">>=</span> <span class="number">85</span> <span class="keyword">THEN</span> <span class="string">'优秀'</span> <span class="keyword">WHEN</span> math <span class="operator">>=</span> <span class="number">60</span> <span class="keyword">THEN</span> <span class="string">'及格'</span> <span class="keyword">ELSE</span> <span class="string">'不及格'</span> <span class="keyword">END</span> ) <span class="keyword">AS</span> <span class="string">'数学成绩'</span>,</span><br><span class="line">( <span class="keyword">CASE</span> <span class="keyword">WHEN</span> english <span class="operator">>=</span> <span class="number">85</span> <span class="keyword">THEN</span> <span class="string">'优秀'</span> <span class="keyword">WHEN</span> english <span class="operator">>=</span> <span class="number">60</span> <span class="keyword">THEN</span> <span class="string">'及格'</span> <span class="keyword">ELSE</span> <span class="string">'不及格'</span> <span class="keyword">END</span> ) <span class="keyword">AS</span> <span class="string">'英语成绩'</span>,</span><br><span class="line">( <span class="keyword">CASE</span> <span class="keyword">WHEN</span> chinese <span class="operator">>=</span> <span class="number">85</span> <span class="keyword">THEN</span> <span class="string">'优秀'</span> <span class="keyword">WHEN</span> chinese <span class="operator">>=</span> <span class="number">60</span> <span class="keyword">THEN</span> <span class="string">'及格'</span> <span class="keyword">ELSE</span> <span class="string">'不及格'</span> <span class="keyword">END</span> ) <span class="keyword">AS</span> <span class="string">'语文成绩'</span> </span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line">score;</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Mysql数据库基础 </tag>
</tags>
</entry>
<entry>
<title>Mysql数据库基础(二)</title>
<link href="/posts/afc9c419.html"/>
<url>/posts/afc9c419.html</url>
<content type="html"><![CDATA[<h2 id="SQL概述"><a href="#SQL概述" class="headerlink" title="SQL概述"></a>SQL概述</h2><p>SQL的通用语法:</p><ul><li>语句可以单行或多行书写,以<strong>分号</strong>结尾</li><li>可以通过空格/缩进来增强语句的可读性,空格可以是多个</li><li>MySQL数据库的SQL语句不区分大小写,但关键字建议使用大写区分开来</li></ul><p>SQL的分类:</p><ul><li>DDL(Data Definition Language):数据定义语言,用来定义数据库对象:数据库、表、字段等</li><li>DML(Data Manipulation Language):数据操作语言,用来对数据库表中的数据进行增删改</li><li>DCL(Data Control Language):数据控制语言,用来创建数据库用户、控制数据库的访问权限</li><li>DQL(Data Query Language):数据查询语言,用来查询数据库中表的记录</li></ul><h2 id="DDL"><a href="#DDL" class="headerlink" title="DDL"></a>DDL</h2><p>DDL(Data Definition Language):数据定义语言,用来定义数据库对象:数据库、表、字段等</p><p>数据库操作:</p><ul><li><p>查询</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询所有的数据库</span></span><br><span class="line"><span class="keyword">SHOW</span> DATABASES;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询当前的数据库</span></span><br><span class="line"><span class="keyword">SELECT</span> DATABASE();</span><br></pre></td></tr></table></figure></li><li><p>创建</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 创建数据库</span></span><br><span class="line"><span class="keyword">CREATE</span> DATABASE [IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span>] 数据库名 [<span class="keyword">DEFAULT</span> CHARSET 字符集] [<span class="keyword">COLLATE</span> 排序规则];</span><br></pre></td></tr></table></figure><blockquote><p>utf8 长度只有三个字符,有一些特殊的字符有四个字符,可以使用<strong>utf8mb4</strong></p></blockquote></li><li><p>删除</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 删除数据库</span></span><br><span class="line"><span class="keyword">DROP</span> DATABASE [IF <span class="keyword">EXISTS</span>] 数据库名;</span><br></pre></td></tr></table></figure></li><li><p>使用</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">USE 数据库名;</span><br></pre></td></tr></table></figure></li></ul><hr><p>表操作:</p><ul><li><p>创建</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 创建表</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名(</span><br><span class="line"> 字段<span class="number">1</span> 字段<span class="number">1</span>类型[COMMENT 字段<span class="number">1</span>注释],</span><br><span class="line"> 字段<span class="number">2</span> 字段<span class="number">2</span>类型[COMMENT 字段<span class="number">2</span>注释]</span><br><span class="line">)[COMMENT 表注释];</span><br></pre></td></tr></table></figure><blockquote><p>注意:<strong>最后一个字段</strong>后面没有逗号;在Mysql中字符串是<strong>varchar(长度)</strong></p></blockquote></li><li><p>查询</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询当前数据库所有表</span></span><br><span class="line"><span class="keyword">SHOW</span> TABLES;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查看表结构</span></span><br><span class="line"><span class="keyword">DESC</span> 表名;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询指定表的建表语句</span></span><br><span class="line"><span class="keyword">SHOW</span> <span class="keyword">CREATE</span> <span class="keyword">TABLE</span> 表名;</span><br></pre></td></tr></table></figure></li></ul><p>在这里就需要提及Mysql的数据类型了,其主要分为三类:<strong>数值类型</strong>、<strong>字符串类型</strong>、<strong>日期时间类型</strong></p><ul><li><p>数值类型<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-04-21_10-09-07.webp"></p><blockquote><p>例如 <strong>123.45</strong>,那么它的<strong>精度(M)则是它的长度5</strong>,<strong>标度(D)则是它的小数点后位数2</strong></p></blockquote></li><li><p>字符串类型<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-04-21_10-16-37.webp"></p><blockquote><ul><li>二进制数据例如文件、压缩包等,一般都会有一个专门的文件服务器来存储,因为存储在数据库中会影响其性能</li><li>变长字符串会根据你的存储内容来计算占用空间,性能较差;定长字符串则都会占用指定的空间,性能较好</li></ul></blockquote></li><li><p>日期时间类型<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-04-21_10-25-03.webp"></p></li><li><p>添加字段</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 创建表</span></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">ADD</span> 字段名 字段类型 [COMMENT 注释] [约束];</span><br></pre></td></tr></table></figure></li><li><p>修改字段</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 修改数据类型</span></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 MODIFY 字段名 新数据类型;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 修改字段名和其数据类型</span></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 CHANGE 旧字段名 新字段名 新数据类型 [COMMENT 注释] [约束];</span><br></pre></td></tr></table></figure></li><li><p>删除字段</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 删除字段</span></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 <span class="keyword">DROP</span> 字段名;</span><br></pre></td></tr></table></figure></li><li><p>修改表名</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 修改表名</span></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">TABLE</span> 表名 RENAME <span class="keyword">TO</span> 新表名;</span><br></pre></td></tr></table></figure></li><li><p>删除表</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 删除表</span></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> [IF <span class="keyword">EXISTS</span>] 表名;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 只删除表中的数据</span></span><br><span class="line"><span class="keyword">TRUNCATE</span> <span class="keyword">TABLE</span> 表名;</span><br></pre></td></tr></table></figure></li></ul><h2 id="DML"><a href="#DML" class="headerlink" title="DML"></a>DML</h2><p>DML(Data Manipulation Language):数据操作语言,用来对数据库表中的数据进行增删改</p><ul><li><p>添加数据</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 给指定字段添加数据</span></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 (字段<span class="number">1</span>,字段<span class="number">2</span>,...) <span class="keyword">VALUES</span>(值<span class="number">1</span>,值<span class="number">2</span>,...);</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 给所有字段添加数据</span></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> 表名 <span class="keyword">VALUES</span>(值<span class="number">1</span>,值<span class="number">2</span>,...);</span><br></pre></td></tr></table></figure><blockquote><ol><li>如果想批量添加数据,可以在关键字<strong>VALUES</strong>后面<strong>再增加,(值1,值2,…)【以逗号分隔开】</strong></li><li>插入的数据要<strong>一一对应</strong>且注意<strong>该字段的数据类型</strong></li></ol></blockquote></li><li><p>更新数据</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> 表名 <span class="keyword">SET</span> 字段<span class="number">1</span><span class="operator">=</span>值<span class="number">1</span>,字段<span class="number">2</span><span class="operator">=</span>值<span class="number">2</span>,... [<span class="keyword">WHERE</span> 条件];</span><br></pre></td></tr></table></figure><blockquote><p>没有添加条件则会更新所有数据!</p></blockquote></li><li><p>删除数据</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span> <span class="keyword">FROM</span> 表名 [<span class="keyword">WHERE</span> 条件];</span><br></pre></td></tr></table></figure><blockquote><p>没有添加条件则会删除所有数据!同时delete是不能删除一个字段的值的</p></blockquote></li></ul><p>数据库操作最基本也是最重要的是<strong>查询</strong>操作</p><h2 id="DQL"><a href="#DQL" class="headerlink" title="DQL"></a>DQL</h2><p>DQL(Data Query Language):数据查询语言,用来查询数据库中表的记录</p><h3 id="基本查询"><a href="#基本查询" class="headerlink" title="基本查询"></a>基本查询</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询指定字段</span></span><br><span class="line"><span class="keyword">SELECT</span> 字段<span class="number">1</span> [<span class="keyword">AS</span> 别名<span class="number">1</span>],字段<span class="number">2</span> [<span class="keyword">AS</span> 别名<span class="number">2</span>],... <span class="keyword">FROM</span> 表名;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询所有</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> 表名;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 去除重复记录</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="keyword">DISTINCT</span> 字段列表 <span class="keyword">FROM</span> 表名;</span><br></pre></td></tr></table></figure><h3 id="条件查询"><a href="#条件查询" class="headerlink" title="条件查询"></a>条件查询</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表名 <span class="keyword">WHERE</span> 条件列表;</span><br></pre></td></tr></table></figure><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-04-29_10-29-19.webp"></p><h3 id="聚合函数"><a href="#聚合函数" class="headerlink" title="聚合函数"></a>聚合函数</h3><p>将一列数据作为一个整体,进行纵向计算。聚合函数一般配合分组查询<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-04-29_10-48-49.webp"></p><blockquote><p> 聚合函数是<strong>作用于字段</strong>的,一般<strong>NULL值是不参与任</strong>何聚合函数的运算</p></blockquote><h3 id="分组查询"><a href="#分组查询" class="headerlink" title="分组查询"></a>分组查询</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表名 [<span class="keyword">WHERE</span> 条件列表] <span class="keyword">GROUP</span> <span class="keyword">BY</span> 分组字段名 [<span class="keyword">HAVING</span> 分组后过滤的条件];</span><br></pre></td></tr></table></figure><p>WHERE 和 HAVING 的区别:</p><ul><li>执行时机不同:where 是在<strong>分组之前进行过滤</strong>,不满足 where 条件的不参与分组;而 having 是在<strong>分组之后对结果进行过滤</strong></li><li>判断条件不足:where 不能对聚合函数进行判断,而 having 可以</li></ul><p>需要注意的是:</p><ul><li>执行顺序:where > 聚合函数 > having</li><li>分组之后,查询的字段一般是聚合函数和分组字段,查询其他字段毫无意义</li></ul><h3 id="排序查询"><a href="#排序查询" class="headerlink" title="排序查询"></a>排序查询</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表名 <span class="keyword">ORDER</span> <span class="keyword">BY</span> 字段<span class="number">1</span> 排序方式<span class="number">1</span> , 字段<span class="number">2</span> 排序方式<span class="number">2</span>;</span><br></pre></td></tr></table></figure><p>默认排序方式是 <strong>升序(ASC)</strong>。同时还有一种排序方式,即 <strong>降序(DESC)</strong></p><blockquote><p>当进行多字段排序,当<strong>第一个字段值相同</strong>时,才会根据第二个字段进行排序</p></blockquote><h3 id="分页查询"><a href="#分页查询" class="headerlink" title="分页查询"></a>分页查询</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> 字段列表 <span class="keyword">FROM</span> 表名 LIMIT 起始索引 , 查询记录数;</span><br></pre></td></tr></table></figure><p>起始索引的计算方式:<strong>(查询页码 - 1) * 每页显示记录数</strong>。当查询的是第一页数据时,起始索引可以省略掉</p><p>分页查询是是数据库的方言,即不同数据库有不同的实现方式,比如 Mysql 就是 LIMIT 的了</p><h3 id="案例练习"><a href="#案例练习" class="headerlink" title="案例练习"></a>案例练习</h3><p>创建一个 emp(员工) 表:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> emp (</span><br><span class="line">id <span class="type">INT</span> COMMENT <span class="string">'编号'</span>,</span><br><span class="line">workno <span class="type">VARCHAR</span> ( <span class="number">10</span> ) COMMENT <span class="string">'工号'</span>,</span><br><span class="line">NAME <span class="type">VARCHAR</span> ( <span class="number">10</span> ) COMMENT <span class="string">'名字'</span>,</span><br><span class="line">gender <span class="type">CHAR</span> COMMENT <span class="string">'性别'</span>,</span><br><span class="line">age TINYINT UNSIGNED COMMENT <span class="string">'年龄'</span>,</span><br><span class="line">idcard <span class="type">CHAR</span> ( <span class="number">18</span> ) COMMENT <span class="string">'身份证号'</span>,</span><br><span class="line">workaddress <span class="type">VARCHAR</span> ( <span class="number">50</span> ) COMMENT <span class="string">'工作地址'</span>,</span><br><span class="line">entrydate <span class="type">date</span> COMMENT <span class="string">'入职时间'</span> </span><br><span class="line">) COMMENT <span class="string">'员工表'</span>;</span><br></pre></td></tr></table></figure><p>插入相应的数据:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> emp ( id, workno, NAME, gender, age, idcard, workaddress, entrydate )</span><br><span class="line"><span class="keyword">VALUES</span></span><br><span class="line">( <span class="number">1</span>, <span class="number">1</span>, <span class="string">'柳岩'</span>, <span class="string">'女'</span>, <span class="number">20</span>, <span class="string">'123456789012345678'</span>, <span class="string">'北京'</span>, <span class="string">'2000-01-01'</span> ),</span><br><span class="line">( <span class="number">2</span>, <span class="number">2</span>, <span class="string">'张无忌'</span>, <span class="string">'男'</span>, <span class="number">18</span>, <span class="string">'123456789012345670'</span>, <span class="string">'北京'</span>, <span class="string">'2005-09-01'</span> ),</span><br><span class="line">( <span class="number">3</span>, <span class="number">3</span>, <span class="string">'韦一笑'</span>, <span class="string">'男'</span>, <span class="number">38</span>, <span class="string">'123456789712345670'</span>, <span class="string">'上海'</span>, <span class="string">'2005-08-01'</span> ),</span><br><span class="line">( <span class="number">4</span>, <span class="number">4</span>, <span class="string">'赵敏'</span>, <span class="string">'女'</span>, <span class="number">18</span>, <span class="string">'123456757123845670'</span>, <span class="string">'北京'</span>, <span class="string">'2009-12-01'</span> ),</span><br><span class="line">( <span class="number">5</span>, <span class="number">5</span>, <span class="string">'小昭'</span>, <span class="string">'女'</span>, <span class="number">16</span>, <span class="string">'123456769012345678'</span>, <span class="string">'上海'</span>, <span class="string">'2007-07-01'</span> ),</span><br><span class="line">( <span class="number">6</span>, <span class="number">6</span>, <span class="string">'杨道'</span>, <span class="string">'男'</span>, <span class="number">28</span>, <span class="string">'12345678931234567X'</span>, <span class="string">'北京'</span>, <span class="string">'2006-01-01'</span> ),</span><br><span class="line">( <span class="number">7</span>, <span class="number">7</span>, <span class="string">'范骚'</span>, <span class="string">'男'</span>, <span class="number">40</span>, <span class="string">'123456789212345670'</span>, <span class="string">'北京'</span>, <span class="string">'2005-05-01'</span> ),</span><br><span class="line">( <span class="number">8</span>, <span class="number">8</span>, <span class="string">'黛绮丝'</span>, <span class="string">'女'</span>, <span class="number">38</span>, <span class="string">'123456157123645670'</span>, <span class="string">'天津'</span>, <span class="string">'2015-05-01'</span> ),</span><br><span class="line">( <span class="number">9</span>, <span class="number">9</span>, <span class="string">'范凉凉'</span>, <span class="string">'女'</span>, <span class="number">45</span>, <span class="string">'123156789012345678'</span>, <span class="string">'北京'</span>, <span class="string">'2010-04-01'</span> ),</span><br><span class="line">( <span class="number">10</span>, <span class="number">10</span>, <span class="string">'陈友凉'</span>, <span class="string">'男'</span>, <span class="number">53</span>, <span class="string">'123456789012345670'</span>, <span class="string">'上海'</span>, <span class="string">'2011-01-01'</span> ),</span><br><span class="line">( <span class="number">11</span>, <span class="number">11</span>, <span class="string">'张士诚'</span>, <span class="string">'男'</span>, <span class="number">55</span>, <span class="string">'123567897123465670'</span>, <span class="string">'江苏'</span>, <span class="string">'2015-05-01'</span> ),</span><br><span class="line">( <span class="number">12</span>, <span class="number">12</span>, <span class="string">'常遇春'</span>, <span class="string">'男'</span>, <span class="number">32</span>, <span class="string">'123446757152345670'</span>, <span class="string">'北京'</span>, <span class="string">'2004-02-01'</span> ),</span><br><span class="line">( <span class="number">13</span>, <span class="number">13</span>, <span class="string">'张三丰'</span>, <span class="string">'男'</span>, <span class="number">88</span>, <span class="string">'123656789012345678'</span>, <span class="string">'江苏'</span>, <span class="string">'2020-11-01'</span> ),</span><br><span class="line">( <span class="number">14</span>, <span class="number">14</span>, <span class="string">'灭绝'</span>, <span class="string">'女'</span>, <span class="number">65</span>, <span class="string">'123456719012345670'</span>, <span class="string">'西安'</span>, <span class="string">'2019-05-01'</span> ),</span><br><span class="line">( <span class="number">15</span>, <span class="number">15</span>, <span class="string">'胡青牛'</span>, <span class="string">'男'</span>, <span class="number">70</span>, <span class="string">'12345674971234567X'</span>, <span class="string">'西安'</span>, <span class="string">'2018-04-01'</span> ),</span><br><span class="line">( <span class="number">16</span>, <span class="number">16</span>, <span class="string">'周芷若'</span>, <span class="string">'女'</span>, <span class="number">18</span>, <span class="keyword">NULL</span>, <span class="string">'北京'</span>, <span class="string">'2012-06-01'</span> );</span><br></pre></td></tr></table></figure><p>实际练习:</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询年龄为20,21,22,23的员工信息</span></span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> emp <span class="keyword">WHERE</span> age <span class="keyword">IN</span>(<span class="number">20</span>,<span class="number">21</span>,<span class="number">22</span>,<span class="number">23</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询性别男,年龄在20~40岁(含)以内的姓名为三个字的员工信息</span></span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> emp <span class="keyword">WHERE</span> gender <span class="operator">=</span> <span class="string">'男'</span> <span class="operator">&&</span> age <span class="keyword">BETWEEN</span> <span class="number">20</span> <span class="keyword">AND</span> <span class="number">40</span> <span class="operator">&&</span> name <span class="keyword">like</span> <span class="string">'___'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 统计员工表中,年龄小于60的男女员工人数</span></span><br><span class="line"><span class="keyword">select</span> gender,<span class="built_in">COUNT</span>(<span class="operator">*</span>) <span class="keyword">from</span> emp <span class="keyword">WHERE</span> age <span class="operator"><</span> <span class="number">60</span> <span class="keyword">GROUP</span> <span class="keyword">BY</span> gender;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询年龄小于等于35岁的员工信息,并根据其年龄进行升序,如果年龄相同,则按照入职时间降序</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">from</span> emp <span class="keyword">where</span> age <span class="operator"><=</span> <span class="number">35</span> <span class="keyword">ORDER</span> <span class="keyword">BY</span> age,entrydate <span class="keyword">DESC</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 查询年龄在20~40岁(含)以内的前5个男员工信息,并根据其年龄进行升序,如果年龄相同,则按照入职时间降序</span></span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> emp <span class="keyword">where</span> gender <span class="operator">=</span> <span class="string">'男'</span> <span class="operator">&&</span> age <span class="keyword">BETWEEN</span> <span class="number">20</span> <span class="keyword">and</span> <span class="number">40</span> <span class="keyword">ORDER</span> <span class="keyword">BY</span> age,entrydate <span class="keyword">desc</span> LIMIT <span class="number">5</span>;</span><br></pre></td></tr></table></figure><p>SELECT 的多种查询方式是有先后执行顺序的,具体如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-04-30_09-46-47.webp"></p><h2 id="DCL"><a href="#DCL" class="headerlink" title="DCL"></a>DCL</h2><p>DCL(Data Control Language):数据控制语言,用来管理数据库用户、控制数据库的访问权限</p><h3 id="管理用户"><a href="#管理用户" class="headerlink" title="管理用户"></a>管理用户</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询用户,用户信息存储在系统数据库mysql的user表中</span></span><br><span class="line">use mysql;</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> <span class="keyword">user</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 创建用户</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">USER</span> <span class="string">'用户名'</span>@<span class="string">'主机名'</span> IDENTIFIED <span class="keyword">BY</span> <span class="string">'密码'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 修改用户密码</span></span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">USER</span> <span class="string">'用户名'</span>@<span class="string">'主机名'</span> IDENTIFIED <span class="keyword">WITH</span> mysql_native_password <span class="keyword">BY</span> <span class="string">'新密码'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 删除用户</span></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">USER</span> <span class="string">'用户名'</span>@<span class="string">'主机名'</span>;</span><br></pre></td></tr></table></figure><p>当主机名为 <strong>%</strong> 时,则表示在<strong>任意主机</strong>都可以访问到</p><p>新创建的用户默认是<strong>没有任何权限</strong>的,当前<strong>只能访问到information_schema</strong>该数据库</p><p>这类SQL开发人员操作的比较少,主要是DBA(Database Administrator 数据库管理员)会使用</p><h3 id="权限控制"><a href="#权限控制" class="headerlink" title="权限控制"></a>权限控制</h3><p>在mysql中定义了很多种权限,但是常用的就以下几种:<br><img src="/images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Mysql%E5%9F%BA%E7%A1%80/Snipaste_2024-05-02_08-55-40.webp"></p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 查询权限</span></span><br><span class="line"><span class="keyword">SHOW</span> GRANTS <span class="keyword">FOR</span> <span class="string">'用户名'</span>@<span class="string">'主机名'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 授予权限</span></span><br><span class="line"><span class="keyword">GRANT</span> 权限列表 <span class="keyword">ON</span> 数据库名.表名 <span class="keyword">TO</span> <span class="string">'用户名'</span>@<span class="string">'主机名'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 撤销权限</span></span><br><span class="line"><span class="keyword">REVOKE</span> 权限列表 <span class="keyword">ON</span> 数据库名.表名 <span class="keyword">FROM</span> <span class="string">'用户名'</span>@<span class="string">'主机名'</span>;</span><br></pre></td></tr></table></figure><p>授予多个权限时,多个权限之间以<strong>逗号</strong>分隔开;授权时数据库和表名以<code>*</code>表示,则代表所有</p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Mysql数据库基础 </tag>
</tags>
</entry>
<entry>
<title>搭建个人博客</title>
<link href="/posts/5d85.html"/>
<url>/posts/5d85.html</url>
<content type="html"><![CDATA[<h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><p>Hexo 是一个快速、简洁且高效的 静态 博客框架,它是<strong>基于 Node.js 运行</strong>的,也就是说它是可以 <strong>不需要服务器</strong> 的</p><div class="tabs" id="准备工作"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#准备工作-1">安装 Node.js</button></li><li class="tab"><button type="button" data-href="#准备工作-2">安装 Vscode</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="准备工作-1"><p>在 <a href="https://nodejs.org/en">Node.js官网</a> 中下载并安装。安装完成后可以通过如下指令检测<strong>是否成功安装</strong>:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看Node.js版本</span></span><br><span class="line">node -v</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看npm版本</span></span><br><span class="line">npm -v</span><br></pre></td></tr></table></figure><blockquote><p>如果你想要安装<strong>其他版本</strong>的 Node.js,可以前往此处:<a href="https://nodejs.org/zh-cn/download/releases">以往的版本</a></p></blockquote><p>Node.js 会自带 <strong>npm</strong>,该 npm 会用于后续为Hexo博客安装相应的<strong>插件</strong>。关于npm的<strong>镜像源</strong>有如下操作:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 自带的镜像源对于国内有时下载插件会很慢,可以更换为淘宝的镜像源</span></span><br><span class="line">npm config <span class="built_in">set</span> registry https://registry.npm.taobao.org</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看当前npm的镜像源</span></span><br><span class="line">npm config get registry</span><br><span class="line"></span><br><span class="line"><span class="comment"># 取消镜像</span></span><br><span class="line">npm config delete registry</span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="准备工作-2"><p><a href="https://code.visualstudio.com/">Visual Studio Code</a> 是一款免费的、轻量级且可扩展的<strong>代码编辑器</strong>,适用于构建 Web、桌面和移动应用</p><p>安装完 VSCode 后是不能立马使用<strong>终端</strong>来对Hexo博客输入命令的,需要在<strong>终端</strong>中执行如下操作:</p><ol><li>鼠标右键以 <strong>管理员身份</strong> 运行 Visual Studio Code,在<strong>终端</strong>中执行 <strong>get-ExecutionPolicy</strong>,显示 <strong>Restricted(禁止)</strong></li><li>执行 <strong>set-ExecutionPolicy RemoteSigned</strong> 后再执行 get-ExecutionPolicy,显示 <strong>RemoteSigned(解锁)</strong></li></ol><p>Visual Studio Code 默认<strong>文件夹合并</strong>,可以在<strong>文件 - 首选项 - 设置</strong>上进行如下操作:<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/newblog/foldercompat.webp"></p><blockquote><p>小技巧:可以对 VSCode 下载 <a href="https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons">vscode-icons</a> 来美化默认的文件夹样式</p></blockquote><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><h2 id="安装-Hexo"><a href="#安装-Hexo" class="headerlink" title="安装 Hexo"></a>安装 Hexo</h2><p>Windows上可以按下快捷键 <strong>Win + R</strong> 打开运行 <strong>cmd</strong> 来启动<strong>命令提示符窗口</strong>,执行如下指令:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 安装Hexo</span></span><br><span class="line">npm install -g hexo-cli</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看Hexo版本</span></span><br><span class="line">hexo -v</span><br></pre></td></tr></table></figure><p>这时我们就可以利用如下指令在本地电脑上新建一个 HexoBlog 文件夹,里面就有运行Hexo博客的文件了:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 初始化Hexo博客</span></span><br><span class="line">hexo init HexoBlog</span><br></pre></td></tr></table></figure><p>初始化完成后,会生成相应的文件夹。下面对这些文件夹进行简单的介绍:</p><blockquote><p><strong>node_modules</strong>:依赖包<br><strong>public</strong>:存放生成的页面<br><strong>scaffolds</strong>:生成文章的一些模板<br><strong>source</strong>:用来存放你的文章<br><strong>themes</strong>:主题<br><strong>.gitignore</strong>:发布时忽略的文件(可忽略)<br><strong>_config.landscape.yml</strong>:主题的配置文件<br><strong>config.yml</strong>:博客的配置文件<br><strong>package.json</strong>:项目名称、描述、版本、运行和开发等信息</p></blockquote><p>此时依次执行如下指令(<strong>Hexo三连</strong>):</p><blockquote><p><strong>hexo clean</strong>:清除缓存文件(db.json)和已生成的静态文件(public),缩写为 <strong>hexo cl</strong><br><strong>hexo generate</strong>:生成静态文件,缩写为 <strong>hexo g</strong><br><strong>hexo server</strong>:启动服务器,缩写为 <strong>hexo s</strong></p></blockquote><p>在浏览器中打开此<a href="http://localhost:4000/">链接</a>就可以访问到Hexo博客默认的<strong>landscape主题</strong>了<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/newblog/hexobuild.webp"></p><h2 id="挂载博客"><a href="#挂载博客" class="headerlink" title="挂载博客"></a>挂载博客</h2><p>在 <a href="https://git-scm.com/downloads">Git官网</a> 上根据你的操作系统下载安装。安装好 Git 后,鼠标右键就可以看到 Git BASH Here,执行如下指令:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 配置你的用户名,需要跟Github相同</span></span><br><span class="line">git config --global user.name <span class="string">"你的用户名"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置你的邮箱,需要跟Github相同</span></span><br><span class="line">git config --global user.email <span class="string">"你的邮箱"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看配置的是否成功</span></span><br><span class="line">git config --global --list</span><br></pre></td></tr></table></figure><p>在 <a href="https://github.com/">Github官网</a> 上点击右上角的 <strong>+</strong> 按钮,选择 <strong>New repository</strong>,创建一个 <strong><用户名>.github.io</strong> 的仓库<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/newblog/repositorybuild.webp"></p><p>创建完成后,需要一个<strong>密钥</strong>来让你的计算机可以<strong>连接 Github</strong>,可以在命令提示符窗口通过如下指令来生成:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 生成密钥</span></span><br><span class="line">ssh-keygen -t rsa -C <span class="string">"你的邮箱"</span></span><br></pre></td></tr></table></figure><p>在你的<strong>C盘用户文件夹内</strong>生成 <strong>.ssh</strong> 这个文件夹。其中 <strong>id_rsa.pub</strong> 里的内容就是我们要在Github上配置的<strong>密钥</strong></p><p>在 Github 右上角头选择 <strong>Settings</strong>,进入设置页后选择 <strong>SSH and GPG keys</strong>,然后点击 <strong>New SSH key</strong> 配置密钥<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/newblog/idrsapub.webp"></p><p>执行如下指令,如果你看到 <strong>You’ve successfully authenticated</strong> 出现,就说明你计算机与 Github 连接成功了</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看密钥是否配置成功</span></span><br><span class="line">ssh -T [email protected]</span><br></pre></td></tr></table></figure><p>在 <a href="https://vercel.com/">Vercel官网</a> 中通过<strong>授权 Github</strong> 的方式注册一个账号。点击此<a href="https://vercel.com/new">链接</a>导入 Github 上的 Hexo博客 仓库,导入后点击 <strong>Deploy</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/newblog/vercelbuild.webp"></p><blockquote><p>上图的 <strong>Domains</strong> 可以自定义你的博客<strong>域名</strong></p></blockquote><p>在 VSCode 上的<strong>终端</strong>上执行如下命令安装该插件,该插件可以将本地的博客文件上传到 GitHub仓库 中</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure><p>在博客配置文件 <strong>_config.yml</strong> 中的 <strong>deploy</strong> 填写如下信息:</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">deploy:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">git</span></span><br><span class="line"> <span class="attr">repository:</span> <span class="string">[email protected]:Fomalhaut-Blog/Fomalhaut-Blog.github.io.git</span> <span class="comment"># 填写仓库的SSH</span></span><br><span class="line"> <span class="attr">branch:</span> <span class="string">main</span></span><br></pre></td></tr></table></figure><p>在这之后就可以通过 <strong>hexo deploy</strong> 或 <strong>hexo d</strong> 来部署我们的网站了。这时通过 <strong><用户名>.github.io</strong> 就可以访问Hexo博客 了</p><blockquote><p><strong><用户名></strong> 替换为你的 Github用户名</p></blockquote>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 搭建 </tag>
</tags>
</entry>
<entry>
<title>Mysql数据库基础(一)</title>
<link href="/posts/6c7926d0.html"/>
<url>/posts/6c7926d0.html</url>
<content type="html"><![CDATA[<blockquote><p>高效的管理和存储数据才是软件系统的核心!</p></blockquote><h2 id="Mysql概述"><a href="#Mysql概述" class="headerlink" title="Mysql概述"></a>Mysql概述</h2><p>数据库(Database)是按照数据结构来组织、存储和管理数据的仓库</p><p>数据库管理系统(Database Management System)是一种操纵和管理数据库的大型软件,用于建立、使用和维护数据库,简称DBMS。它对数据库进行统一的管理和控制,以保证数据库的安全性和完整性</p><p>关系型数据库是建立在关系模型基础上,由多张相互连接的<strong>二维表</strong>组成的数据库,其特点:</p><ul><li>表结构进行数据存储,格式统一,便于维护</li><li>使用SQL语言操作,标准统一,使用方便<blockquote><p>SQL 是用于访问和处理关系型数据库的<strong>标准</strong>的计算机语言</p></blockquote></li></ul><h2 id="Mysql安装"><a href="#Mysql安装" class="headerlink" title="Mysql安装"></a>Mysql安装</h2><p>下载Mysql的安装包:<a href="https://dev.mysql.com/downloads/installer/">8.0.36</a>,具体安装步骤可参考:<a href="https://zhuanlan.zhihu.com/p/687170328">Mysql 8.0 – 最新版本安装(保姆级教程)</a></p><p>可以通过命令 <strong>net start mysql80</strong> 启动mysql,也可以通过命令 <strong>net stop mysql80</strong> 来停止mysql</p><blockquote><p>mysql80 是在安装mysql时注册到Windows上的服务名称</p></blockquote><p>在设置好环境变量后,可以在 cmd窗口 以 <strong>mysql [-h localhost] [-P 3306] -u root -p</strong> 来连接mysql</p><p>点击<a href="https://kkdaj.lanzouq.com/iCJfT04o3pkh">链接</a>(密码:ec23)下载 <strong>Navicate</strong> 及其破解软件,具体破解流程可参考:<a href="https://www.cnblogs.com/kkdaj/p/16260681.html">NavicatPremium16破解</a></p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Mysql数据库基础 </tag>
</tags>
</entry>
<entry>
<title>Linux简单操作(五)</title>
<link href="/posts/cd6ed668.html"/>
<url>/posts/cd6ed668.html</url>
<content type="html"><![CDATA[<p>所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在。但是目前我们使用比较多的是 vim 编辑器。</p><p>vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计</p><p>Vim 是从 vi 发展出来的一个文本编辑器。代码补全、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。</p><p>简单的来说, vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方。 vim 则可以说是程序开发者的一项很好用的工具。</p><p>以下是普通模式常用的几个命令:</p><ul><li>i – 切换到输入模式,在光标当前位置开始输入文本。</li><li>x – 删除当前光标所在处的字符。</li><li>: – 切换到底线命令模式,以在最底一行输入命令。</li><li>a – 进入插入模式,在光标下一个位置开始输入文本。</li><li>o:在当前行的下方插入一个新行,并进入插入模式。</li><li>O – 在当前行的上方插入一个新行,并进入插入模式。</li><li>dd – 剪切当前行。</li><li>yy – 复制当前行。</li><li>p(小写) – 粘贴剪贴板内容到光标下方。</li><li>P(大写)– 粘贴剪贴板内容到光标上方。</li><li>u – 撤销上一次操作。</li><li>Ctrl + r – 重做上一次撤销的操作。</li><li>:w – 保存文件。</li><li>:q – 退出 Vim 编辑器。</li><li>:q! – 强制退出Vim 编辑器,不保存修改。</li></ul><blockquote><p>在命令模式下按下 i 就进入了输入模式,使用 Esc 键可以返回到普通模式</p></blockquote><p>在输入模式中,可以使用以下按键:</p><ul><li>字符按键以及Shift组合,输入字符</li><li>ENTER,回车键,换行</li><li>BACK SPACE,退格键,删除光标前一个字符</li><li>DEL,删除键,删除光标后一个字符</li><li>方向键,在文本中移动光标</li><li>HOME/END,移动光标到行首/行尾</li><li>Page Up/Page Down,上/下翻页</li><li>Insert,切换光标为输入/替换模式,光标将变成竖线/下划线</li><li>ESC,退出输入模式,切换到命令模式</li></ul><p>在命令模式下按下 :(英文冒号)就进入了底线命令模式:</p><ul><li>:w:保存文件。</li><li>:q:退出 Vim 编辑器。</li><li>:wq:保存文件并退出 Vim 编辑器。</li><li>:q!:强制退出Vim编辑器,不保存修改。</li></ul><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Linux%E7%AE%80%E5%8D%95%E4%BD%A0%E6%93%8D%E4%BD%9C/vim-vi-workmodel.png"></p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Linux简单操作 </tag>
</tags>
</entry>
<entry>
<title>Linux简单操作(四)</title>
<link href="/posts/cbc58115.html"/>
<url>/posts/cbc58115.html</url>
<content type="html"><![CDATA[<h2 id="ln-命令"><a href="#ln-命令" class="headerlink" title="ln 命令"></a>ln 命令</h2><p>ln(英文全拼:link files)命令是一个非常重要命令,它的功能是<strong>为某一个文件在另外一个位置建立一个同步的链接</strong></p><blockquote><p>当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在其它的目录下用ln命令链接(link)它就可以,不必重复的占用磁盘空间</p></blockquote><p>语法: <strong>ln [参数][源文件或目录][目标文件或目录]</strong><br>必要参数:</p><ul><li>–backup[=CONTROL] 备份已存在的目标文件</li><li>-b 类似 –backup ,但不接受参数</li><li>-d 允许超级用户制作目录的硬链接</li><li>-f 强制执行</li><li>-i 交互模式,文件存在则提示用户是否覆盖</li><li>-n 把符号链接视为一般目录</li><li><strong>-s</strong> 软链接(符号链接)</li><li>-v 显示详细的处理过程<br>选择参数:</li><li>-S “-S<字尾备份字符串> “或 “–suffix=<字尾备份字符串>”</li><li>-V “-V<备份方式>”或”–version-control=<备份方式>”</li><li>–help 显示帮助信息</li><li>–version 显示版本信息</li></ul><p>Linux链接分两种,一种被称为<strong>硬链接</strong>(Hard Link),另一种被称为<strong>符号链接</strong>(Symbolic Link)。默认情况下,ln命令产生硬链接</p><ul><li><p>符号连接(Symbolic Link),也叫软连接。软链接文件有类似于Windows的快捷方式。它实际上是一个特殊的文件。在符号连接中,文件实际上是一个文本文件,其中包含的有<strong>另一文件的位置信息</strong></p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ln -s d.txt d_soft_link</span><br><span class="line">[moe@master ~]$ ll</span><br><span class="line">总用量 16</span><br><span class="line">...</span><br><span class="line">drwxrwxr-x. 4 moe moe 54 4月 15 11:04 dongman</span><br><span class="line">lrwxrwxrwx 1 moe moe 5 4月 15 15:59 d_soft_link -> d.txt</span><br><span class="line">-rw-rw-r-- 1 moe moe 22 4月 15 10:43 d.txt</span><br><span class="line">...</span><br><span class="line">[moe@master ~]$ cat d_soft_link </span><br><span class="line">你好我是测试者</span><br><span class="line">[moe@master ~]$ cat d.txt </span><br><span class="line">你好我是测试者</span><br><span class="line">[moe@master ~]$ gedit d.txt </span><br><span class="line">[moe@master ~]$ cat d_soft_link </span><br><span class="line">你好我是测试者22</span><br><span class="line">[moe@master ~]$ cat d.txt </span><br><span class="line">你好我是测试者22</span><br></pre></td></tr></table></figure><p>上面脚本是在相同目录创建这个软链接。当在不同目录时,需要<strong>使用绝对路径</strong>,否则会报红,不能使用,因为软链接记录的是文件的位置信息</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ln -s ~/d.txt dongman/d2_soft_link</span><br><span class="line">[moe@master ~]$ ll dongman/</span><br><span class="line">总用量 4</span><br><span class="line">-rw-rw-r-- 1 moe moe 0 4月 15 10:59 a.txt</span><br><span class="line">-rw-rw-r-- 1 moe moe 22 4月 15 10:44 c.txt</span><br><span class="line">lrwxrwxrwx 1 moe moe 15 4月 15 16:00 d2_soft_link -> /home/moe/d.txt</span><br><span class="line">drwxrwxr-x 2 moe moe 6 4月 15 11:04 nv</span><br><span class="line">drwxrwxr-x 5 moe moe 43 4月 15 11:10 test</span><br><span class="line">[moe@master ~]$ ln -s d.txt dongman/d3_soft_link</span><br><span class="line">[moe@master ~]$ ll dongman/</span><br><span class="line">总用量 4</span><br><span class="line">-rw-rw-r-- 1 moe moe 0 4月 15 10:59 a.txt</span><br><span class="line">-rw-rw-r-- 1 moe moe 22 4月 15 10:44 c.txt</span><br><span class="line">lrwxrwxrwx 1 moe moe 15 4月 15 16:00 d2_soft_link -> /home/moe/d.txt</span><br><span class="line">lrwxrwxrwx 1 moe moe 5 4月 15 16:04 d3_soft_link -> d.txt(报红)</span><br><span class="line">drwxrwxr-x 2 moe moe 6 4月 15 11:04 nv</span><br><span class="line">drwxrwxr-x 5 moe moe 43 4月 15 11:10 test</span><br><span class="line">[moe@master ~]$ cat dongman/d3_soft_link </span><br><span class="line">cat: dongman/d3_soft_link: 没有那个文件或目录</span><br></pre></td></tr></table></figure><blockquote><p>可以给目录创建一个软链接,同时需要注意的是软链接只记录文件的位置信息,所以它占用的空间不会跟原文件相同</p></blockquote></li><li><p>硬连接指通过<strong>索引节点</strong>来进行连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种连接就是硬连接。硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,<strong>文件真正删除的条件是与之相关的所有硬连接文件均被删除</strong></p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">[moe@master dongman]$ ln c.txt c_hard_link</span><br><span class="line">[moe@master dongman]$ ll</span><br><span class="line">总用量 8</span><br><span class="line">-rw-rw-r-- 1 moe moe 0 4月 15 10:59 a.txt</span><br><span class="line">-rw-rw-r-- 2 moe moe 22 4月 15 10:44 c_hard_link</span><br><span class="line">-rw-rw-r-- 2 moe moe 22 4月 15 10:44 c.txt</span><br><span class="line">lrwxrwxrwx 1 moe moe 15 4月 15 16:00 d2_soft_link -> /home/moe/d.txt</span><br><span class="line">drwxrwxr-x 2 moe moe 6 4月 15 11:04 nv</span><br><span class="line">drwxrwxr-x 5 moe moe 43 4月 15 11:10 test</span><br><span class="line">[moe@master dongman]$ ln c.txt c1_hard_link</span><br><span class="line">[moe@master dongman]$ ll</span><br><span class="line">总用量 12</span><br><span class="line">-rw-rw-r-- 1 moe moe 0 4月 15 10:59 a.txt</span><br><span class="line">-rw-rw-r-- 3 moe moe 22 4月 15 10:44 c1_hard_link</span><br><span class="line">-rw-rw-r-- 3 moe moe 22 4月 15 10:44 c_hard_link</span><br><span class="line">-rw-rw-r-- 3 moe moe 22 4月 15 10:44 c.txt</span><br><span class="line">lrwxrwxrwx 1 moe moe 15 4月 15 16:00 d2_soft_link -> /home/moe/d.txt</span><br><span class="line">drwxrwxr-x 2 moe moe 6 4月 15 11:04 nv</span><br><span class="line">drwxrwxr-x 5 moe moe 43 4月 15 11:10 test</span><br><span class="line">[moe@master dongman]$ ln nv nv_hard_link</span><br><span class="line">ln: "nv": 不允许将硬链接指向目录</span><br></pre></td></tr></table></figure><blockquote><p>可以看出这个<strong>2和3</strong>代表该文件目前有几个索引,只有当这些索引链接的文件都被删除时该文件才会被真正删除,相当于一个<strong>实时的备份文件(并不是简单拷贝)</strong>,防止误删。同时需要注意<strong>硬链接不能链接目录</strong></p></blockquote></li></ul><h2 id="grep-命令"><a href="#grep-命令" class="headerlink" title="grep 命令"></a>grep 命令</h2><p>Linux系统中 grep(Global Regular Expression Print) 命令是一种<strong>强大的文本搜索工具</strong>,它能使用正则表达式搜索文本,并把匹配的行打印出来</p><p>语法:<strong>grep [options] pattern [files]</strong><br>常用选项::</p><ul><li><strong>-i</strong>:忽略大小写进行匹配。</li><li>-v:反向查找,只打印不匹配的行。</li><li><strong>-n</strong>:显示匹配行的行号。</li><li>-r:递归查找子目录中的文件。</li><li>-l:只打印匹配的文件名。</li><li>-c:只打印匹配的行数。</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link 公共 视频 文档 音乐</span><br><span class="line">b b.txt dongman1 d.txt 模板 图片 下载 桌面</span><br><span class="line">[moe@master ~]$ grep -ni 你好 b.txt</span><br><span class="line">3:hello你好</span><br><span class="line">[moe@master ~]$ grep -ni 你好 . -r</span><br><span class="line">匹配到二进制文件 ./.cache/tracker/meta.db-wal</span><br><span class="line">./dongman/c.txt:1:你好我是测试者</span><br><span class="line">./dongman/c_hard_link:1:你好我是测试者</span><br><span class="line">./dongman/c1_hard_link:1:你好我是测试者</span><br><span class="line">./b.txt:3:hello你好</span><br><span class="line">./d.txt:1:你好我是测试者22</span><br><span class="line">./b_hard_link:3:hello你好</span><br></pre></td></tr></table></figure><blockquote><p>拓展:<a href="https://blog.csdn.net/qq_51010919/article/details/130714120">Linux-grep的详细使用</a></p></blockquote><h2 id="find-命令"><a href="#find-命令" class="headerlink" title="find 命令"></a>find 命令</h2><p>find 命令用于在指定目录下查找文件和目录</p><p>语法:<strong>find [路径] [匹配条件] [动作]</strong><br>参数说明 :<br>路径 是要查找的目录路径,可以是一个目录或文件名,也可以是多个路径,多个路径之间用空格分隔,如果未指定路径,则默认为当前目录。expression 是可选参数,用于指定查找的条件,可以是文件名、文件类型、文件大小等等。匹配条件 中可使用的选项有二三十个之多,以下列出最常用的部份:</p><ul><li><strong>-name</strong> pattern:按文件名查找,支持使用通配符 * 和 ?。</li><li>-type type:按文件类型查找,可以是 f(普通文件)、d(目录)、l(符号链接)等。</li><li>-size [+-]size[cwbkMG]:按文件大小查找,支持使用 + 或 - 表示大于或小于指定大小,单位可以是 c(字节)、w(字数)、b(块数)、k(KB)、M(MB)或 G(GB)。</li><li>-mtime days:按修改时间查找,支持使用 + 或 - 表示在指定天数前或后,days 是一个整数表示天数。</li><li>-user username:按文件所有者查找。</li><li>-group groupname:按文件所属组查找。</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ find -name b.txt</span><br><span class="line">./b.txt</span><br><span class="line">[moe@master ~]$ find ~ -name b.txt</span><br><span class="line">/home/moe/b.txt</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">使用单引号包含</span></span><br><span class="line">[moe@master ~]$ find ~ -name '*txt'</span><br></pre></td></tr></table></figure><h2 id="tar-命令"><a href="#tar-命令" class="headerlink" title="tar 命令"></a>tar 命令</h2><p>tar(英文全拼:tape archive )命令用于<strong>备份文件</strong>。是创建和解压归档文件的命令行工具,可以用来将多个文件和目录组合成一个单一的归档文件,也可以用来解压已经存在的归档文件<br>简单语法:tar [选项] 压缩包名 压缩文件 [-C] [存放目录]<br>常用选项:</p><ul><li>c或–create 建立新的备份文件</li><li>-C<目的目录>或–directory=<目的目录> 将压缩包指定到目的目录</li><li>-v或–verbose 显示指令执行过程</li><li>-x或–extract或–get 从备份文件中还原文件,即解压</li><li>-t或–list 列出备份文件的内容</li><li>-f<备份文件>或–file=<备份文件> 指定备份文件</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link 公共 视频 文档 音乐</span><br><span class="line">b b.txt dongman1 d.txt 模板 图片 下载 桌面</span><br><span class="line">[moe@master ~]$ tar -cf txt.tar b.txt d.txt </span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link txt.tar(红色显示) 模板 图片 下载 桌面</span><br><span class="line">b b.txt dongman1 d.txt 公共 视频 文档 音乐</span><br><span class="line">[moe@master ~]$ tar -cf txt.tar b.txt d.txt -C dongman</span><br><span class="line">[moe@master ~]$ ls dongman</span><br><span class="line">a.txt c1_hard_link c_hard_link c.txt d2_soft_link nv test</span><br><span class="line">[moe@master ~]$ tar -xf txt.tar -C dongman</span><br><span class="line">[moe@master ~]$ ls dongman</span><br><span class="line">a.txt b.txt c1_hard_link c_hard_link c.txt d2_soft_link d.txt nv test</span><br></pre></td></tr></table></figure><blockquote><p>可以看出只能将解压的文件移动到指定目录中去。其中<strong>f</strong>这个选项必须放在后面。拓展:<a href="https://www.runoob.com/linux/linux-comm-tar.html">tar命令</a></p></blockquote><h2 id="gzip-命令"><a href="#gzip-命令" class="headerlink" title="gzip 命令"></a>gzip 命令</h2><p>gzip命令用于<strong>压缩文件</strong>。是个使用广泛的压缩程序,文件经它压缩过后,其名称后面会多出”<strong>.gz</strong>“的扩展名<br>简单语法:<strong>gzip [选项] 压缩包</strong><br>常用选项:</p><ul><li>d 解压</li><li>-r或–recursive 递归处理,将指定目录下的所有文件及子目录一并处理</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link txt.tar 模板 图片 下载 桌面</span><br><span class="line">b b.txt dongman1 d.txt 公共 视频 文档 音乐</span><br><span class="line">[moe@master ~]$ gzip -d txt.tar</span><br><span class="line">gzip: txt.tar: unknown suffix -- ignored</span><br><span class="line">[moe@master ~]$ gzip -r txt.tar</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link txt.tar.gz 模板 图片 下载 桌面</span><br><span class="line">b b.txt dongman1 d.txt 公共 视频 文档 音乐</span><br><span class="line">[moe@master ~]$ gzip -d txt.tar.gz </span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link txt.tar 模板 图片 下载 桌面</span><br><span class="line">b b.txt dongman1 d.txt 公共 视频 文档 音乐</span><br></pre></td></tr></table></figure><blockquote><p>拓展:<a href="https://www.runoob.com/linux/linux-comm-gzip.html">gzip命令</a></p></blockquote><p>一步到位:</p><ul><li>以gzip的方式打包且压缩:<strong>tar czf 名称.tar.gz 目标文件</strong><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link txt.tar 模板 图片 下载 桌面</span><br><span class="line">b b.txt dongman1 d.txt 公共 视频 文档 音乐</span><br><span class="line">[moe@master ~]$ tar czf test.tar.gz b.txt d.txt </span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b_hard_link dongman d_soft_link test.tar.gz 公共 视频 文档 音乐</span><br><span class="line">b b.txt dongman1 d.txt txt.tar 模板 图片 下载 桌面</span><br></pre></td></tr></table></figure></li><li>以gzip的方式解压并解包:<strong>tar zxf 名称.tar.gz -C 目标目录</strong><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ tar zxf test.tar.gz -C dongman1</span><br><span class="line">[moe@master ~]$ ls dongman1</span><br><span class="line">a.txt b.txt c1_hard_link c_hard_link c.txt d2_soft_link d.txt nv test</span><br></pre></td></tr></table></figure></li></ul><h2 id="bzip2-命令"><a href="#bzip2-命令" class="headerlink" title="bzip2 命令"></a>bzip2 命令</h2><p>bzip2命令是 <strong>.bz2文件</strong> 的压缩程序。bzip2采用新的压缩演算法,压缩效果比传统的LZ77/LZ78压缩演算法来得好。若没有加上任何参数,bzip2压缩完文件后会产生.bz2的压缩文件,并删除原始的文件</p><p>与gzip用法类似,这里也可以一步到位:</p><ul><li>以bzip2的方式打包且压缩:<strong>tar cjf 名称.tar.gz 目标文件</strong><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ mkdir bzip2</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt dongman1 test.tar.gz 模板 文档 桌面</span><br><span class="line">b bzip2 d_soft_link txt.tar 视频 下载</span><br><span class="line">b_hard_link dongman d.txt 公共 图片 音乐</span><br><span class="line">[moe@master ~]$ tar cjf test.tar.bz2 b.txt d.txt </span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt dongman1 test.tar.bz2 公共 图片 音乐</span><br><span class="line">b bzip2 d_soft_link test.tar.gz 模板 文档 桌面</span><br><span class="line">b_hard_link dongman d.txt txt.tar 视频 下载</span><br></pre></td></tr></table></figure></li><li>以bzip2的方式解压并解包:<strong>tar zxf 名称.tar.gz -C 目标目录</strong><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ tar xjf test.tar.bz2 -C bzip2/</span><br><span class="line">[moe@master ~]$ ls bzip2/</span><br><span class="line">b.txt d.txt</span><br></pre></td></tr></table></figure></li></ul><h2 id="zip命令"><a href="#zip命令" class="headerlink" title="zip命令"></a>zip命令</h2><p>zip 命令用于压缩文件。zip 是个使用广泛的压缩程序,压缩后的文件后缀名为 <strong>.zip</strong><br>通过 <strong>zip -r 压缩名称(不需要写后缀码) 压缩文件</strong> 来压缩文件</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ zip -r zz b.txt d.txt </span><br><span class="line"> adding: b.txt (deflated 15%)</span><br><span class="line"> adding: d.txt (stored 0%)</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt dongman1 test.tar.bz2 zz.zip 视频 下载</span><br><span class="line">b bzip2 d_soft_link test.tar.gz 公共 图片 音乐</span><br><span class="line">b_hard_link dongman d.txt txt.tar 模板 文档 桌面</span><br></pre></td></tr></table></figure><p>又可以通过 <strong>unzip -d 压缩后的文件目录 压缩文件</strong> 来解压文件</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ unzip -d zz zz.zip </span><br><span class="line">Archive: zz.zip</span><br><span class="line"> inflating: zz/b.txt </span><br><span class="line"> extracting: zz/d.txt </span><br><span class="line">[moe@master ~]$ ls zz</span><br><span class="line">b.txt d.txt</span><br></pre></td></tr></table></figure><blockquote><p>压缩后的文件目录如果没有会自动创建</p></blockquote><p>上述三种压缩方式的<strong>压缩率</strong>对比:zip < gzip < bzip2,通用性则是:zip > gzip > bzip2,所以最终常用的压缩方式取中间的 gzip 即可,在Windows中下载的般都是以 tar.gz 为后缀名的文件</p><h2 id="which-命令"><a href="#which-命令" class="headerlink" title="which 命令"></a>which 命令</h2><p>which命令用于查找文件。which指令会在环境变量$PATH设置的目录里查找符合条件的文件</p><p>语法:<strong>which [文件…]</strong><br>参数:</p><ul><li>-n<文件名长度> 指定文件名长度,指定的长度必须大于或等于所有文件中最长的文件名。</li><li>-p<文件名长度> 与-n参数相同,但此处的<文件名长度>包括了文件的路径。</li><li>-w 指定输出时栏位的宽度。</li><li>-V 显示版本信息。</li></ul><p>寻找命令 tar 所在的文件在哪</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ which tar</span><br><span class="line">/usr/bin/tar</span><br></pre></td></tr></table></figure><p>切换到<strong>root(超级管理员)</strong>下,可以使用 <strong>su [用户]</strong> 命令</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ su</span><br><span class="line">密码:</span><br><span class="line">[root@master moe]# </span><br></pre></td></tr></table></figure><p>修改用户的密码,可以使用 **passwd [用户]**,此时修改的密码不能简单的使用123456来设置</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@master moe]# passwd root</span><br><span class="line">更改用户 root 的密码 。</span><br><span class="line">新的 密码:</span><br></pre></td></tr></table></figure><blockquote><p>可以<strong>在root用户下</strong>修改其他用户的密码,此时密码可以用简单的数字表示</p></blockquote><p><strong>exit 命令</strong>可以退出当前用户到上一个用户。如果没有,则关闭终端窗口</p><p><strong>who 命令</strong>可以查看当前登录的用户</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ who</span><br><span class="line">moe :0 2024-04-16 16:22 (:0)</span><br><span class="line">moe pts/0 2024-04-16 16:27 (:0)</span><br><span class="line">moe pts/1 2024-04-16 17:10 (:0)</span><br></pre></td></tr></table></figure><blockquote><p>pts:代表终端用户、tty:代表操作系统用户。可以通过 pkill -kill -t [pts/tty]</p></blockquote><p>reboot 和 shutdown 命令:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Linux%E7%AE%80%E5%8D%95%E4%BD%A0%E6%93%8D%E4%BD%9C/Snipaste_2024-04-16_17-15-23.png"></p><h2 id="chmod-命令"><a href="#chmod-命令" class="headerlink" title="chmod 命令"></a>chmod 命令</h2><p>chmod(英文全拼:change mode)命令是控制用户<strong>对文件的权限</strong>的命令<br>其中:</p><ul><li>u 表示该文件的拥有者,g 表示与该文件的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。</li><li><strong>+</strong> 表示增加权限、- 表示取消权限、= 表示唯一设定权限。</li><li>r 表示可读取(数字代号为’4’),w 表示可写入(数字代号为’2’),x 表示可执行(数字代号为’1’),- 表示不具有任何权限(数字代号为’0’)<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ll d.txt</span><br><span class="line">-rw-rw-r-- 1 moe moe 50 4月 15 16:39 d.txt</span><br><span class="line">[moe@master ~]$ chmod u+x d.txt </span><br><span class="line">[moe@master ~]$ ll d.txt</span><br><span class="line">-rwxrw-r-- 1 moe moe 50 4月 15 16:39 d.txt</span><br><span class="line">[moe@master ~]$ chmod u=- d.txt </span><br><span class="line">[moe@master ~]$ ll d.txt </span><br><span class="line">----rw-r-- 1 moe moe 50 4月 15 16:39 d.txt</span><br></pre></td></tr></table></figure><blockquote><p>可以直接通过 <strong>=-</strong> 来取消所有权限</p></blockquote></li></ul>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Linux简单操作 </tag>
</tags>
</entry>
<entry>
<title>Linux简单操作(三)</title>
<link href="/posts/31866e1a.html"/>
<url>/posts/31866e1a.html</url>
<content type="html"><![CDATA[<h2 id="cp-命令"><a href="#cp-命令" class="headerlink" title="cp 命令"></a>cp 命令</h2><p>cp(英文全拼:copy file)命令主要用于<strong>复制文件或目录</strong></p><p>语法:<strong>cp [选项] 源文件 目标文件</strong></p><blockquote><p>source(源文件)表示要复制的文件或目录的路径,dest(目标文件)表示复制后的文件或目录的路径</p></blockquote><p>选项说明:</p><ul><li><strong>-a</strong>:此选项通常在复制目录时使用,它保留链接、文件属性,并复制目录下的所有内容。其作用等于 dpR 参数组合。</li><li>-d:复制时保留链接。这里所说的链接相当于 Windows 系统中的快捷方式。</li><li><strong>-r</strong> 或 –recursive:用于复制目录及其所有的子目录和文件,如果要复制目录,需要使用该选项。</li><li>-i 或 –interactive:在复制前提示确认,如果目标文件已存在,则会询问是否覆盖,回答 y 时目标文件将被覆盖。。</li><li>-u 或 –update:仅复制源文件中更新时间较新的文件。</li><li>-v 或 –verbose:显示详细的复制过程。</li><li>-p 或 –preserve:保留源文件的权限、所有者和时间戳信息。</li><li>-f 或 –force:强制复制,即使目标文件已存在也会覆盖,而且不给出提示。</li><li>-l:不复制文件,只是生成链接文件。</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ cp a.txt dongman</span><br><span class="line">[moe@master ~]$ ls dongman/</span><br><span class="line">a.txt</span><br></pre></td></tr></table></figure><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls test/</span><br><span class="line">dongwu ren</span><br><span class="line">[moe@master ~]$ cp test dongman -r</span><br><span class="line">[moe@master ~]$ ls dongman/</span><br><span class="line">a.txt test</span><br><span class="line">[moe@master ~]$ ls dongman/test</span><br><span class="line">dongwu ren</span><br></pre></td></tr></table></figure><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ cp a.txt d.txt -a</span><br><span class="line">[moe@master ~]$ ll</span><br><span class="line">总用量 20</span><br><span class="line">-rw-rw-r--. 1 moe moe 6 4月 15 00:04 a</span><br><span class="line">-rw-rw-r-- 1 moe moe 22 4月 15 10:43 a.txt</span><br><span class="line">-rw-rw-r--. 1 moe moe 7 4月 15 00:07 b</span><br><span class="line">-rw-rw-r-- 1 moe moe 0 4月 15 09:26 b.txt</span><br><span class="line">-rw-rw-r-- 1 moe moe 22 4月 15 10:44 c.txt</span><br><span class="line">drwxrwxr-x. 2 moe moe 19 4月 15 10:43 dongman</span><br><span class="line">-rw-rw-r-- 1 moe moe 22 4月 15 10:43 d.txt</span><br><span class="line">drwxrwxr-x. 4 moe moe 31 4月 14 23:46 test</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 22:32 公共</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 18:57 模板</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 18:57 视频</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 18:57 图片</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 18:57 文档</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 18:57 下载</span><br><span class="line">drwxr-xr-x. 2 moe moe 6 4月 14 18:57 音乐</span><br><span class="line">drwxr-xr-x. 2 moe moe 40 4月 14 20:46 桌面</span><br></pre></td></tr></table></figure><h2 id="mv-命令"><a href="#mv-命令" class="headerlink" title="mv 命令"></a>mv 命令</h2><p>mv(英文全拼:move file)命令用来为文件或目录改名、或将文件或目录<strong>移入</strong>其它位置</p><p>语法:<strong>mv [options] source dest</strong><br>选项说明:</p><ul><li>-b: 当目标文件或目录存在时,在执行覆盖前,会为其创建一个备份。</li><li>-i: 如果指定移动的源目录或文件与目标的目录或文件同名,则会先询问是否覆盖旧文件,输入 y 表示直接覆盖,输入 n 表示取消该操作。</li><li>-f: 如果指定移动的源目录或文件与目标的目录或文件同名,不会询问,直接覆盖旧文件(默认)。</li><li>-n: 不要覆盖任何已存在的文件或目录。</li><li>-u:当源文件比目标文件新或者目标文件不存在时,才执行移动操作。</li></ul><p>执行命令: <strong>mv source_file(文件) dest_file(文件)</strong> ,会将源文件名 source_file 改为目标文件名 dest_file</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ mv a.txt e.txt</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt dongman e.txt 公共 视频 文档 音乐</span><br><span class="line">b c.txt d.txt test 模板 图片 下载 桌面</span><br><span class="line">[moe@master ~]$ gedit e.txt </span><br><span class="line">[moe@master ~]$ mv e.txt d.txt</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt dongman test 模板 图片 下载 桌面</span><br><span class="line">b c.txt d.txt 公共 视频 文档 音乐</span><br></pre></td></tr></table></figure><blockquote><p>如果 <strong>dest_file文件</strong> 存在,会被覆盖掉</p></blockquote><p>执行命令: <strong>mv source_file(文件) dest_directory(目录)</strong> ,将文件 source_file 移动到目标目录 dest_directory 中</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls dongman</span><br><span class="line">a.txt test</span><br><span class="line">[moe@master ~]$ gedit dongman/a.txt </span><br><span class="line">[moe@master ~]$ touch a.txt</span><br><span class="line">[moe@master ~]$ mv a.txt dongman/a.txt </span><br><span class="line">[moe@master ~]$ gedit dongman/a.txt </span><br><span class="line"></span><br><span class="line">[moe@master ~]$ mv c.txt dongman</span><br><span class="line">[moe@master ~]$ ls dongman/</span><br><span class="line">a.txt c.txt test</span><br></pre></td></tr></table></figure><blockquote><p>如果 <strong>dest_directory(目录)</strong> 中存在同名的 **source_file(文件)**,会将其覆盖掉</p></blockquote><p>执行命令: <strong>mv source_directory(目录) dest_directory(目录)</strong> ,目录名 dest_directory 不存在则 source_directory 改名为目录名 dest_directory</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ mv test dongman/</span><br><span class="line">mv: 无法将"test" 移动至"dongman/test": 文件已存在</span><br><span class="line"></span><br><span class="line">[moe@master ~]$ mkdir nv</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt d.txt test 模板 图片 下载 桌面</span><br><span class="line">b dongman nv 公共 视频 文档 音乐</span><br><span class="line">[moe@master ~]$ mv nv dongman/</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b.txt d.txt 公共 视频 文档 音乐</span><br><span class="line">b dongman test 模板 图片 下载 桌面</span><br><span class="line">[moe@master ~]$ ls dongman/</span><br><span class="line">a.txt c.txt nv test</span><br></pre></td></tr></table></figure><blockquote><p>不能将一个目录移动到已存在该目录的目录中去</p></blockquote><p>执行命令:<strong>mv source_directory(目录) dest_file(文件)</strong> ,错误</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ mv dongman/ d.txt</span><br><span class="line">mv: 无法以目录"dongman/" 来覆盖非目录"d.txt"</span><br></pre></td></tr></table></figure><h2 id="输出重定向命令"><a href="#输出重定向命令" class="headerlink" title="输出重定向命令"></a>输出重定向命令</h2><p>Linux允许将命令执行结果重定向到一个文件(不存在则新建一个)中,即本应显示到终端上的执行结果会保存到指定文件中去</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ pwd >b.txt</span><br><span class="line">[moe@master ~]$ pwd >>b.txt</span><br></pre></td></tr></table></figure><blockquote><p><strong>></strong> 输出重定向会覆盖原来的内容, <strong>>></strong> 输出重定向会追加到文件的尾部</p></blockquote><h2 id="cat-命令"><a href="#cat-命令" class="headerlink" title="cat 命令"></a>cat 命令</h2><p>cat(英文全拼:concatenate)命令用于将文件的内容<strong>显示到终端界面</strong>上</p><p>语法:<strong>cat [-AbeEnstTuv] [–help] [–version] fileName</strong><br>选项说明:</p><ul><li>-n 或 –number:由 1 开始对所有输出的行数编号。</li><li>-b 或 –number-nonblank:和 -n 相似,只不过对于空白行不编号。</li><li>-s 或 –squeeze-blank:当遇到有连续两行以上的空白行,就代换为一行的空白行。</li><li>-v 或 –show-nonprinting:使用 ^ 和 M- 符号,除了 LFD 和 TAB 之外。</li><li>-E 或 –show-ends : 在每行结束处显示 $。</li><li>-T 或 –show-tabs: 将 TAB 字符显示为 ^I。</li><li>-A, –show-all:等价于 -vET。</li><li>-e:等价于”-vE”选项;</li><li>-t:等价于”-vT”选项;</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ cat b.txt </span><br><span class="line">/home/moe</span><br><span class="line">/home/moe</span><br><span class="line">[moe@master ~]$ cat d.txt </span><br><span class="line">你好我是测试者</span><br><span class="line">[moe@master ~]$ cat b.txt d.txt > a.txt</span><br><span class="line">[moe@master ~]$ cat a.txt </span><br><span class="line">/home/moe</span><br><span class="line">/home/moe</span><br><span class="line">你好我是测试者</span><br></pre></td></tr></table></figure><blockquote><p><strong>dev/null</strong>:在类 Unix 系统中,/dev/null 称空设备,是一个特殊的设备文件,它丢弃一切写入其中的数据(但报告写入操作成功),读取它则会立即得到一个 EOF</p></blockquote><h2 id="more-命令"><a href="#more-命令" class="headerlink" title="more 命令"></a>more 命令</h2><p>more 命令类似 cat ,不过会以一页一页的形式显示,更方便使用者<strong>逐页阅读</strong>,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还有搜寻字串的功能(与 vi 相似),使用中的说明文件,请按 h </p><p>语法:<strong>more [-dlfpcsu] [-num] [+/pattern] [+linenum] [fileNames..]</strong><br>参数:</p><ul><li>-num 一次显示的行数</li><li>-d 提示使用者,在画面下方显示 [Press space to continue, ‘q’ to quit.] ,如果使用者按错键,则会显示 [Press ‘h’ for instructions.] 而不是 ‘哔’ 声</li><li>-l 取消遇见特殊字元 ^L(送纸字元)时会暂停的功能</li><li>-f 计算行数时,以实际上的行数,而非自动换行过后的行数(有些单行字数太长的会被扩展为两行或两行以上)</li><li>-p 不以卷动的方式显示每一页,而是先清除萤幕后再显示内容</li><li>-c 跟 -p 相似,不同的是先显示内容再清除其他旧资料</li><li>-s 当遇到有连续两行以上的空白行,就代换为一行的空白行</li><li>-u 不显示下引号 (根据环境变数 TERM 指定的 terminal 而有所不同)</li><li>+/pattern 在每个文档显示前搜寻该字串(pattern),然后从该字串之后开始显示</li><li>+num 从第 num 行开始显示</li><li>fileNames 欲显示内容的文档,可为复数个数</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ more a.txt </span><br></pre></td></tr></table></figure><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Linux%E7%AE%80%E5%8D%95%E4%BD%A0%E6%93%8D%E4%BD%9C/Snipaste_2024-04-15_11-57-44.png"></p><p>常用操作命令:</p><ul><li>Enter 向下n行,需要定义。默认为1行</li><li>Ctrl+F 向下滚动一屏</li><li>空格键 向下滚动一屏</li><li>Ctrl+B 返回上一屏</li><li>= 输出当前行的行号</li><li>:f 输出文件名和当前行的行号</li><li>V 调用vi编辑器</li><li>!命令 调用Shell,并执行命令</li><li>q 退出more</li></ul><h2 id="管道"><a href="#管道" class="headerlink" title="管道"></a>管道</h2><p>管道:一个命令的输出可以通过管道作为另一个命令的输入</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls ~ -al | more</span><br></pre></td></tr></table></figure><blockquote><p>以 <strong>|</strong> 作为这个管道</p></blockquote>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Linux简单操作 </tag>
</tags>
</entry>
<entry>
<title>Linux简单操作(二)</title>
<link href="/posts/4f754e31.html"/>
<url>/posts/4f754e31.html</url>
<content type="html"><![CDATA[<h2 id="cd命令"><a href="#cd命令" class="headerlink" title="cd命令"></a>cd命令</h2><p>cd(英文全拼:change directory)命令用于<strong>改变当前工作目录</strong>的命令,切换到指定的路径</p><p>若目录名称省略,则变换至使用者的 home 目录 (也就是刚 login 时所在的目录)。另外, <strong>~</strong> 也表示为 home 目录 的意思, <strong>.</strong> 则是表示目前所在的目录, <strong>..</strong> 则表示目前目录位置的上一层目录</p><ul><li><p>cd [dirName]</p><blockquote><p>dirName:要切换的目标目录,可以是相对路径或绝对路径</p></blockquote><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">换到绝对路径:指定完整的目录路径来切换到目标目录</span></span><br><span class="line">[moe@master ~]$ cd /dev/block</span><br><span class="line">[moe@master block]$ pwd</span><br><span class="line">/dev/block</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">切换到相对路径:指定相对于当前目录的路径来切换到目标目录</span></span><br><span class="line">[moe@master dev]$ cd disk/by-id/</span><br><span class="line">[moe@master by-id]$ pwd</span><br><span class="line">/dev/disk/by-id</span><br></pre></td></tr></table></figure></li><li><p>切换到上级目录:使用 .. 表示上级目录,可以通过连续多次使用 .. 来切换到更高级的目录</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[moe@master by-id]$ cd ..</span><br><span class="line">[moe@master disk]$ cd ..</span><br><span class="line">[moe@master dev]$ pwd</span><br><span class="line">/dev</span><br></pre></td></tr></table></figure></li><li><p>切换到用户主目录(home):使用 ~ 表示当前用户的主目录,可以使用 cd 命令直接切换到主目录</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master dev]$ cd ~</span><br><span class="line">[moe@master ~]$ pwd</span><br><span class="line">/home/moe</span><br></pre></td></tr></table></figure></li><li><p>切换到上次访问的目录:使用 <strong>cd -</strong> 可以切换到上次访问的目录</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ cd -</span><br><span class="line">/dev</span><br></pre></td></tr></table></figure><blockquote><p>拓展:<a href="https://blog.csdn.net/qq_45112637/article/details/134323473?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-134323473-blog-130321172.235%5Ev43%5Epc_blog_bottom_relevance_base2&spm=1001.2101.3001.4242.2&utm_relevant_index=4">Centos7安装配置中文输入法</a></p></blockquote></li></ul><h2 id="ls-命令"><a href="#ls-命令" class="headerlink" title="ls 命令"></a>ls 命令</h2><p>ls(英文全拼: list directory contents)命令用于显示指定工作目录下之内容(<strong>列出目前工作目录所含的文件及子目录</strong>)</p><p>语法:<strong>ls [-alrtAFR] [name…]</strong></p><p>参数 :</p><ul><li>-a 显示所有文件及目录 (. 开头的隐藏文件也会列出)</li><li>-d 只列出目录(不递归列出目录内的文件)</li><li>-l 以长格式显示文件和目录信息,包括权限、所有者、大小、创建时间等</li><li>-r 倒序显示文件和目录</li><li>-t 将按照修改时间排序,最新的文件在最前面</li><li>-A 同 -a ,但不列出 “.” (目前目录) 及 “..” (父目录)</li><li>-F 在列出的文件名称后加一符号;例如可执行档则加 “*”, 目录则加 “/“</li><li>-R 递归显示目录中的所有文件和子目录</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">ls -l # 以长格式显示当前目录中的文件和目录,可简写为 ll</span><br><span class="line">ls -a # 显示当前目录中的所有文件和目录,包括隐藏文件</span><br><span class="line">ls -lh # 以人类可读的方式显示当前目录中的文件和目录大小</span><br><span class="line">ls -t # 按照修改时间排序显示当前目录中的文件和目录</span><br><span class="line">ls -R # 递归显示当前目录中的所有文件和子目录</span><br><span class="line">ls -l /etc/passwd # 显示/etc/passwd文件的详细信息</span><br></pre></td></tr></table></figure><p>列出根目录()下的所有目录:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master /]$ ls /</span><br><span class="line">bin dev home lib64 mnt proc run srv tmp var</span><br><span class="line">boot etc lib media opt root sbin sys usr</span><br></pre></td></tr></table></figure><p>将 /bin 目录以下所有目录及文件详细资料列出:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[moe@master /]$ ls -lR /bin</span><br><span class="line">lrwxrwxrwx. 1 root root 7 4月 14 18:50 /bin -> usr/bin</span><br></pre></td></tr></table></figure><p>当文件名包含空格、特殊字符或者开始字符为破折号时,可以使用反斜杠(\)进行转义,或者使用引号将文件名括起来。例如:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ls "my file.txt" # 列出文件名为"my file.txt"的文件</span><br><span class="line">ls my\ file.txt # 列出文件名为"my file.txt"的文件</span><br><span class="line">ls -- -filename # 列出文件名为"-filename"的文件</span><br></pre></td></tr></table></figure><p>ls 命令还可以使用通配符进行模式匹配,例如 * 表示匹配任意字符,? 表示匹配一个字符,[…] 表示匹配指定范围内的字符。例如:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ls *.txt # 列出所有扩展名为.txt的文件</span><br><span class="line">ls file?.txt # 列出文件名为file?.txt的文件,其中?表示任意一个字符</span><br><span class="line">ls [abc]*.txt # 列出以a、b或c开头、扩展名为.txt的文件</span><br></pre></td></tr></table></figure><p>列出目前工作目录下所有名称是 s 开头的文件或目录,越新的排越后面:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls -ltr s*</span><br></pre></td></tr></table></figure><p>在使用 ls -l 命令时,第一列的字符表示文件或目录的类型和权限。其中第一个字符表示文件类型,例如:</p><ul><li><strong>-</strong> 表示普通文件</li><li>d 表示目录</li><li>l 表示符号链接</li><li>c 表示字符设备文件</li><li>b 表示块设备文件</li><li>s 表示套接字文件</li><li>p 表示管道文件</li></ul><p>在使用 ls -l 命令时,第一列的其余 9 个字符表示文件或目录的访问权限,分别对应三个字符一组的 rwx 权限。例如:</p><ul><li>表示读取权限</li><li>w 表示写入权限</li><li>x 表示执行权限</li><li><strong>-</strong> 表示没有对应权限</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drwxr-xr-x. 144 root root 0 4月 14 18:56 module</span><br></pre></td></tr></table></figure><p>从上面可以看到,每一行都有7列,分别是:</p><ul><li>第一列共10位,第1位表示文档类型,d表示目录,-表示文件,l表示链接文件,d表示可随机存取的设备,如U盘等,c表示一次性读取设备,如鼠标、键盘等。后9位,依次对应三种身份所拥有的权限,身份顺序为:owner、group、others,权限顺序为:readable、writable、executable。如:-r-xr-x—的含义为当前文档是一个文件,拥有者可读、可执行,同一个群组下的用户,可读、可执行,其他人没有任何权限</li><li>第二列表示链接数,表示有多少个文件链接到inode号码</li><li>第三列表示拥有者</li><li>第四列表示所属群组</li><li>第五列表示文档容量大小,单位字节</li><li>第六列表示文档最后修改时间,注意不是文档的创建时间哦</li><li>第七列表示文档名称。以点(.)开头的是隐藏文档</li></ul><h2 id="mkdir-命令"><a href="#mkdir-命令" class="headerlink" title="mkdir 命令"></a>mkdir 命令</h2><p>mkdir(英文全拼:make directory)命令用于<strong>创建目录</strong></p><p>语法:<strong>mkdir [-p] dirName</strong></p><ul><li>-p 确保目录名称存在,不存在的就建一个</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls</span><br><span class="line">公共 模板 视频 图片 文档 下载 音乐 桌面</span><br><span class="line">[moe@master ~]$ mkdir test</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br></pre></td></tr></table></figure><p>可以同时创建两个目录,以空格格式隔开</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[moe@master dongman]$ cd ~</span><br><span class="line">[moe@master ~]$ mkdir test/ren test/dongwu</span><br><span class="line">[moe@master ~]$ cd test</span><br><span class="line">[moe@master test]$ ls</span><br><span class="line">dongwu ren</span><br></pre></td></tr></table></figure><p>如果是在同一个目录下再创建多个目录,可以用 <strong>{}</strong> 来表示,并以<strong>英文逗号</strong>隔开</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[moe@master test]$ cd ~</span><br><span class="line">[moe@master ~]$ mkdir dongman/{xuni,fengjing,xiaz}</span><br><span class="line">[moe@master ~]$ cd dongman/</span><br><span class="line">[moe@master dongman]$ ls</span><br><span class="line">daojian fengjing xiaz xuni</span><br></pre></td></tr></table></figure><p>可以通过 <strong>.dirname</strong> 来创建一个隐藏的目录</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[moe@master dongman]$ cd ~</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">dongman test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br><span class="line">[moe@master ~]$ mkdir .yinc</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">dongman test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br><span class="line">[moe@master ~]$ ls -a</span><br><span class="line">. .shell_profile .dbus .local .yinc 图片 桌面</span><br><span class="line">.. .shellrc dongman .mozilla 公共 文档</span><br><span class="line">.shell_history .cache .esd_auth .pki 模板 下载</span><br><span class="line">.shell_logout .config .ICEauthority test 视频 音乐</span><br></pre></td></tr></table></figure><blockquote><p>每个目录都会有 <strong>.(当前目录)</strong> 和 <strong>..(上一级目录)</strong> 这两个存在</p></blockquote><h2 id="touch-命令"><a href="#touch-命令" class="headerlink" title="touch 命令"></a>touch 命令</h2><p>touch 命令用于修改文件或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会<strong>建立一个新的文件</strong></p><p>语法:<strong>touch [-acfm][-d<日期时间>][-r<参考文件或目录>] [-t<日期时间>][–help][–version][文件或目录…]</strong><br>参数说明:</p><ul><li>a 改变档案的读取时间记录。</li><li>m 改变档案的修改时间记录。</li><li>c 假如目的档案不存在,不会建立新的档案。与 –no-create 的效果一样。</li><li>f 不使用,是为了与其他 unix 系统的相容性而保留。</li><li>r 使用参考档的时间记录,与 –file 的效果一样。</li><li>d 设定时间与日期,可以使用各种不同的格式。</li><li>t 设定档案的时间记录,格式与 date 指令相同。</li><li>–no-create 不会建立新档案。</li><li>–help 列出指令格式。</li><li>–version 列出版本讯息。</li></ul><p>使用指令”touch”时,如果指定的文件不存在,则将创建一个新的空白文件</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ touch a</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a dongman test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br></pre></td></tr></table></figure><p>可以通过 <strong>.filename</strong> 来创建一个隐藏的目录创建一个隐藏的文件</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ touch .a</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a dongman test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br><span class="line">[moe@master ~]$ ls -a</span><br><span class="line">. .shell_history .cache .esd_auth .pki 模板 下载</span><br><span class="line">.. .shell_logout .config .ICEauthority test 视频 音乐</span><br><span class="line">a .shell_profile .dbus .local .yinc 图片 桌面</span><br><span class="line">.a .shellrc dongman .mozilla 公共 文档</span><br></pre></td></tr></table></figure><blockquote><p>一般touch命令用的较少,只有想要创建一个空文件时才会使用</p></blockquote><p>使用 <strong>gedit</strong> 命令可以创建(没有的情况下)并打开文件进行编辑</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[moe@master ~]$ ls</span><br><span class="line">a dongman test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br><span class="line">[moe@master ~]$ gedit b</span><br><span class="line">[moe@master ~]$ ls</span><br><span class="line">a b dongman test 公共 模板 视频 图片 文档 下载 音乐 桌面</span><br></pre></td></tr></table></figure><h2 id="rm-命令"><a href="#rm-命令" class="headerlink" title="rm 命令"></a>rm 命令</h2><p>rm(英文全拼:remove)命令用于<strong>删除一个文件或者目录</strong></p><p>语法:<strong>rm [options] name…</strong></p><ul><li>-i 删除前逐一询问确认</li><li>-f 即使原档案(文件)属性设为唯读,亦直接删除,无需逐一确认</li><li>-r 将目录及以下之档案(文件)亦逐一删除</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[moe@master dongman]$ touch a.txt</span><br><span class="line">[moe@master dongman]$ ls</span><br><span class="line">a.txt daojian fengjing xiaz xuni</span><br><span class="line">[moe@master dongman]$ rm a.txt</span><br><span class="line">[moe@master dongman]$ ls</span><br><span class="line">daojian fengjing xiaz xuni</span><br><span class="line">[moe@master dongman]$ rm daojian</span><br><span class="line">rm: 无法删除"daojian": 是一个目录</span><br><span class="line">[moe@master dongman]$ rm daojian -r</span><br><span class="line">[moe@master dongman]$ ls</span><br><span class="line">fengjing xiaz xuni</span><br><span class="line">[moe@master dongman]$ rm * -r</span><br><span class="line">[moe@master dongman]$ ls -a</span><br><span class="line">. ..</span><br></pre></td></tr></table></figure><blockquote><p>可以看出 <strong>.</strong> 和 <strong>..</strong> 两个目录是删除不了的,同时<strong>rm * -r</strong>是不能<strong>直接</strong>删除隐藏文件的,需要手动逐个删除</p></blockquote><h2 id="clear-命令"><a href="#clear-命令" class="headerlink" title="clear 命令"></a>clear 命令</h2><p>clear 命令用于清除屏幕。本质上是给你翻屏了,以前的命令向上翻就可以看到了</p><blockquote><p>通过 <strong>tab</strong> 键可以自动补全。<strong>ctrl + c</strong>终止当前命令</p></blockquote><h2 id="终端命令格式"><a href="#终端命令格式" class="headerlink" title="终端命令格式"></a>终端命令格式</h2><p>格式:<strong>command [-options] [parameter]</strong></p><ul><li>commmand:命令名,相应功能的英文单词或其缩写</li><li>-options:选项,对命令进行控制,可以省略</li><li>parameter:传给命令的参数,可以零个或多个</li></ul><p>一般终端自带的命令,如<strong>cd</strong>和<strong>pwd</strong>等,通过 <strong>–help</strong>是查看不到帮助文档的,这时可以通过 <strong>man命令</strong> 来查看<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/Linux%E7%AE%80%E5%8D%95%E4%BD%A0%E6%93%8D%E4%BD%9C/Snipaste_2024-04-15_09-06-23.png"></p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Linux简单操作 </tag>
</tags>
</entry>
<entry>
<title>Linux简单操作(一)</title>
<link href="/posts/e044d553.html"/>
<url>/posts/e044d553.html</url>
<content type="html"><![CDATA[<h2 id="操作系统"><a href="#操作系统" class="headerlink" title="操作系统"></a>操作系统</h2><p>操作系统(Operation System, OS)是指控制和管理整个计算机系统的硬件和软件资源,并合理的组织和调度计算机的工作和资源的分配,以提供给用户和其它软件方便的接口和环境,它是计算机系统中最基本也是最重要的<strong>系统软件</strong>。</p><blockquote><p>拓展:<a href="https://blog.csdn.net/Royalic/article/details/119999404">计算机操作系统知识点总结(有这一篇就够了!!!)</a>、<a href="https://zhuanlan.zhihu.com/p/105945721">什么是操作系统?</a></p></blockquote><p>不同领域的操作系统有:桌面操作系统、服务器操作系统、嵌入式操作系统、移动设备操作系统</p><h2 id="安装CentOS7"><a href="#安装CentOS7" class="headerlink" title="安装CentOS7"></a>安装CentOS7</h2><p>VMware17虚拟机下载教程:<a href="https://www.bilibili.com/video/BV1Zz4y157AN/?spm_id_from=333.337.search-card.all.click&vd_source=8abceb502969e7de8c2eb9bc66a1d6e3">【2023新版】VMware17虚拟机的下载安装指南</a>,许可证:<strong>MC60H-DWHD5-H80U9-6V85M-8280D</strong><br>在阿里这里下载CentOS7镜像:<a href="https://developer.aliyun.com/mirror/?spm=a2c6h.13651104.mirror-detail.d1002.7162320c71ugFr">CentOS7镜像</a>,选择<strong>OS镜像</strong><br>安装步骤可参考:<a href="https://blog.csdn.net/weixin_43849575/article/details/102996790">CentOS7(Linux)详细安装教程(图文详解)</a></p><h2 id="Linux的文件和目录"><a href="#Linux的文件和目录" class="headerlink" title="Linux的文件和目录"></a>Linux的文件和目录</h2><p>在Windows中文件会存放在一个个<strong>驱动器盘符</strong>中,但是在Linux中则没有这个概念,其所有的文件都是存放在一个<strong>根目录</strong>中的。在CentOS7中根目录有:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@master moe]# ls /</span><br><span class="line">bin dev home lib64 mnt proc run srv tmp var</span><br><span class="line">boot etc lib media opt root sbin sys usr</span><br></pre></td></tr></table></figure><p>系统启动必须:</p><ul><li>/boot:放置linux系统启动时用到的核心文件,自己的安装别放在这里。建议单独分区,分区大小100M即可</li><li>/etc:存放所有的系统需要的配置文件和子目录列表,更改目录下的文件可能会导致系统不能启动</li><li>/lib:存放基本代码库(比如c++库),其作用类似于Windows里的DLL文件。几乎所有的应用程序都需要用到这些共享库</li><li>/sys: 这是linux2.6内核的一个很大的变化。该目录下安装了2.6内核中新出现的一个文件系统 sysfs 。sysfs文件系统集成了下面3种文件系统的信息:针对进程信息的proc文件系统、针对设备的devfs文件系统以及针对伪终端的devpts文件系统。该文件系统是内核设备树的一个直观反映。当一个内核对象被创建的时候,对应的文件和目录也在内核对象子系统中</li></ul><p>指令集合:</p><ul><li>/bin:可执行二进制文件的目录,存放着常用的命令ls、tar、mv、cat等</li><li>/sbin:s表示Super User,放置系统管理员使用的可执行命令,如fdisk、shutdown、mount等。与/bin不同的是,这几个目录是给系统管理员root使用的命令,一般用户只能”查看”而不能设置和使用</li></ul><p>外部文件管理:</p><ul><li>/dev :Device(设备)的缩写, 存放的是Linux的外部设备。注意:在Linux中访问设备和访问文件的方式是相同的</li><li>/media:类windows的其他设备,例如U盘、光驱等等,识别后linux会把设备放到这个目录下</li><li>/mnt:临时挂载别的文件系统的,我们可以将光驱挂载在/mnt/上,然后进入该目录就可以查看光驱里的内容了</li></ul><p>临时文件:</p><ul><li>/run:是一个临时文件系统,存储系统启动以来的信息。当系统重启时,这个目录下的文件应该被删掉或清除。如果你的系统上有 /var/run 目录,应该让它指向 run</li><li>/lost+found:一般情况下为空的,系统非法关机后,这里就存放一些文件</li><li>/tmp:这个目录是用来存放一些临时文件的</li></ul><p>账户:</p><ul><li>/root:系统管理员root的家目录,系统第一个启动的分区为/,所以最好将/root和/放置在一个分区下</li><li>/home:存放普通用户的家目录,新增用户账号时,用户的家目录都存放在此目录下。建议单独分区,并设置较大的磁盘空间,方便用户存放数据</li><li>/usr:用户的很多应用程序和文件都放在这个目录下,类似于windows下的program files目录。建议单独分区,设置较大的磁盘空间</li><li>/usr/bin:系统用户使用的应用程序与指令</li><li>/usr/sbin:超级用户使用的比较高级的管理程序和系统守护程序</li><li>/usr/src:内核源代码默认的放置目录</li></ul><p>运行过程中要用:</p><ul><li>/var:存放经常修改的数据,比如程序运行的日志文件(/var/log 目录下)。建议单独分区,设置较大的磁盘空间</li><li>/proc:管理内存空间!虚拟的目录,是系统内存的映射,我们可以直接访问这个目录来,获取系统信息。这个目录的内容不在硬盘上而是在内存里,我们也可以直接修改里面的某些文件来做修改。由于数据都存放于内存中,所以不占用磁盘空间</li></ul><p>扩展用的:</p><ul><li>/opt:给主机额外安装软件所摆放的目录,比如你安装oracle数据库就可以放倒这个目录下,默认是空的。以前的 Linux 系统中,习惯放置在 /usr/local 目录下</li><li>/srv:存放服务启动后需要访问的数据(不用服务器就是空)</li></ul><p>参考:<a href="https://www.runoob.com/linux/linux-system-contents.html">Linux 系统目录结构</a>、 <a href="https://cnblogs.com/heimatengyun/p/12161873.html">linux入门系列2–CentOs图形界面操作及目录结构</a></p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> Linux简单操作 </tag>
</tags>
</entry>
<entry>
<title>软件测试基础(五)</title>
<link href="/posts/f83f843e.html"/>
<url>/posts/f83f843e.html</url>
<content type="html"><![CDATA[<h2 id="项目介绍"><a href="#项目介绍" class="headerlink" title="项目介绍"></a>项目介绍</h2><ul><li><p>项目背景<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-34-28.png"></p><blockquote><p>软件是因为什么而来的</p></blockquote></li><li><p>产品定位<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-38-37.png"></p><blockquote><p>这个软件开发出来是什么样子的</p></blockquote></li><li><p>项目目标<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-40-25.png"></p></li><li><p>产品功能架构<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-43-17.png"></p></li></ul><h2 id="项目功能测试"><a href="#项目功能测试" class="headerlink" title="项目功能测试"></a>项目功能测试</h2><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-45-23.png"></p><h3 id="登录功能测试"><a href="#登录功能测试" class="headerlink" title="登录功能测试"></a>登录功能测试</h3><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-46-43.png"></p><ul><li><p>登录需求<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-49-32.png"><br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_14-50-24.png"></p></li><li><p>提取测试点<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_15-12-58.png"><br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_15-25-14.png"></p></li><li><p>设计用例<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_16-29-42.png"><br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_16-30-22.png"></p><blockquote><p>滑块属于验证码这边的<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/Snipaste_2024-04-14_16-42-11.png"></p></blockquote></li></ul><blockquote><p>拓展:<a href="https://zhuanlan.zhihu.com/p/102911463">五大主流浏览器及四大内核</a></p></blockquote><p>还有个发布文章的功能测试:<a href="https://www.bilibili.com/video/BV1TP4y1J7BD?p=71&vd_source=8abceb502969e7de8c2eb9bc66a1d6e3">发布文章需求梳理</a>,这里感觉老师讲的不咋样</p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>到这里软件测试基础的已经算结束了。总的来说:</p><ol><li>要学会<strong>根据需求来编写好测试用例</strong></li><li>测试点要<strong>覆盖好</strong></li><li>编写的测试用例不一定要有多好,但是需要<strong>条理清晰易懂</strong>,能够讲明白</li></ol><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%94%E5%A4%A9/1.webp"></p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> 软件测试基础 </tag>
</tags>
</entry>
<entry>
<title>软件测试基础(四)</title>
<link href="/posts/b5d9d04a.html"/>
<url>/posts/b5d9d04a.html</url>
<content type="html"><![CDATA[<blockquote><p>学习Html是为了未来给<strong>Web项目功能测试</strong>打基础的</p></blockquote><h2 id="认知Html"><a href="#认知Html" class="headerlink" title="认知Html"></a>认知Html</h2><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_11-40-10.png"></p><blockquote><p>Html:<strong>超文本标记语言</strong></p></blockquote><p><strong>Html5基本骨架</strong>组成:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>网页标题<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> 网页内容编写区域</span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><h2 id="常用标签"><a href="#常用标签" class="headerlink" title="常用标签"></a>常用标签</h2><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_11-53-51.png"></p><p>注释:不会被程序执行,用来解释代码的含义。快捷键:<strong>Ctrl + /</strong></p><blockquote><p>在前端中,页面发布上线之前,需要检查所有的注释是否由不恰当的文字出现或去除掉注释</p></blockquote><ul><li><p>标题标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>标题标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> 通过 h1 ~ h6 来定义标题,其中 h1 最大</span></span><br><span class="line"><span class="comment"> h1 一般用来代表整个网页的主标题,只能出现一次,利于seo优化</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">h1</span>></span>标题1<span class="tag"></<span class="name">h1</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>标题2<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h3</span>></span>标题3<span class="tag"></<span class="name">h3</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h4</span>></span>标题5<span class="tag"></<span class="name">h4</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h5</span>></span>标题5<span class="tag"></<span class="name">h5</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">h6</span>></span>标题6<span class="tag"></<span class="name">h6</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_12-15-15.png"></p></li><li><p>段落标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>段落标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> 通过 p 来定义段落</span></span><br><span class="line"><span class="comment"> 浏览器会自动在每个 <p> 元素前后添加一个空行</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>Lorem ipsum dolor sit amet consectetur adipisicing elit. A, officiis!<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">p</span>></span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, libero!<span class="tag"></<span class="name">p</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_12-21-31.png"></p><blockquote><p>在Vscode中可以输入<strong>lorenm+数字</strong>来快速生成一段英文</p></blockquote></li><li><p>超链接标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>超链接标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> 通过 a 来定义超链接,用于从一张页面链接到另一张页面</span></span><br><span class="line"><span class="comment"> 其中最重要的是 href 属性,它指示链接的目的地</span></span><br><span class="line"><span class="comment"> target 属性指定窗口的打开方式,_blank 新建窗口、_self 在当前窗口</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://www.bilibili.com/"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span>哔哩哔哩<span class="tag"></<span class="name">a</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_12-31-16.png"></p></li><li><p>图片标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>图片标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> 通过 img 来定义图片,用于在 HTML 页面中嵌入图像</span></span><br><span class="line"><span class="comment"> 从技术上讲,实际上并没有将图像插入到网页中,而是将图像链接到了网页,<img> 标签创建了一个容器,用于引用图像</span></span><br><span class="line"><span class="comment"> 用 src 属性来规定图像的路径,用 alt 属性来显示因某种原因无法显示图像的替代文本</span></span><br><span class="line"><span class="comment"> 可以通过 width、height 来规定图片的长高,否则会以图片的本身大小显示</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">img</span> <span class="attr">src</span>=<span class="string">"../source/images/logo.png"</span> <span class="attr">alt</span>=<span class="string">"显示不出"</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_13-05-24.png"></p><blockquote><p><strong>绝对路径</strong>:目标文件在硬盘上的真实路径(最精确路径)<br><strong>相对路径</strong>:相对当前执行文件所在位置作为起点。其中 <strong>../</strong> 为上一级, <strong>./</strong> 为同级(可以省略)</p></blockquote></li><li><p>换行标签和空格</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>换行标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> 通过 br 来定义换行,用于在 HTML 页面中插入单行换行符</span></span><br><span class="line"><span class="comment"> 代码的换行在浏览器中只会当作空格来显示</span></span><br><span class="line"><span class="comment"> <br> 标签只是简单地开始新的一行,而当浏览器遇到 <p> 标签时,通常会在相邻的段落之间插入一些垂直的间距</span></span><br><span class="line"><span class="comment"> 注意:请使用 <br> 标签来插入换行符,而不是用它来增加段落之间的空白。</span></span><br><span class="line"><span class="comment"> <br> 标签是空标签(意味着它没有结束标签,因此这是错误的:<br></br>)</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> 如需<span class="tag"><<span class="name">br</span>></span>在文本中强制<span class="tag"><<span class="name">p</span>></span>换行<span class="tag"><<span class="name">br</span>></span>,请使用 <span class="tag"><<span class="name">br</span>></span>br<span class="tag"><<span class="name">br</span>></span> 元素<span class="tag"></<span class="name">p</span>></span>。</span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_21-04-14.png"></p><blockquote><p>在浏览器中,不论你在<strong>两个字间</strong>有多少空格,都只会显示一个。想要显示多个空格,需要借用 <code>&nbsp;</code></p></blockquote></li><li><p>div和span标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>div标签和span标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> <div> 标签定义 HTML 文档中的分割或部分(分区或小节),把文档分割为独立的、不同的部分</span></span><br><span class="line"><span class="comment"> <div> 是块级元素。这意味着它的内容自动地开始一个新行</span></span><br><span class="line"><span class="comment"> 对同一个 <div> 元素应用 class 或 id 属性,但是更常见的情况是只应用其中一种</span></span><br><span class="line"><span class="comment"> 这两者的主要差异是,class 用于元素组(类似的元素,或者可以理解为某一类元素),而 id 用于标识单独的唯一的元素</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>div标签<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span>></span>Lorem ipsum dolor sit amet.<span class="tag"></<span class="name">div</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">div</span>></span>Lorem ipsum dolor sit amet consectetur.<span class="tag"></<span class="name">div</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> <span> 标签是一个行内容器,用于标记文本的一部分,或文档的一部分</span></span><br><span class="line"><span class="comment"> <span> 是行内元素。不会自动开始一个新行</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>span标签<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span>></span>Lorem ipsum dolor sit amet consectetur.<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">span</span>></span>Lorem ipsum dolor sit, amet consectetur adipisicing.<span class="tag"></<span class="name">span</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_21-27-51.png"></p></li><li><p>列表标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>列表标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> <ol> 标签定义有序列表。有序列表可以是数字或字母顺序</span></span><br><span class="line"><span class="comment"> <ul> 标签定义无序(带项目符号)列表</span></span><br><span class="line"><span class="comment"> <li> 标签定义列表项,用于有序列表 (<ol>)、无序列表 (<ul>) 和菜单列表 (<menu>) 中</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>有序列表<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">ol</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">li</span>></span>水果<span class="tag"></<span class="name">li</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">li</span>></span>西瓜<span class="tag"></<span class="name">li</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">ol</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>无序列表<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">ul</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">li</span>></span>哔哩哔哩<span class="tag"></<span class="name">li</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">li</span>></span>百度<span class="tag"></<span class="name">li</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">ul</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_21-43-06.png"></p></li><li><p>表单标签</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><!DOCTYPE <span class="keyword">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>表单标签<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> <form> 标签用于为接收用户输入创建 HTML 表单,用以将表单信息提交到指定地方</span></span><br><span class="line"><span class="comment"> <input> 标签是行内元素,用于定义输入字段,用户可以在其中输入数据</span></span><br><span class="line"><span class="comment"> <input> 元素是最重要的表单元素,可以以多种方式显示,具体取决于 type 属性</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">h2</span>></span>表单列表<span class="tag"></<span class="name">h2</span>></span></span><br><span class="line"> <span class="comment"><!-- </span></span><br><span class="line"><span class="comment"> get: 提交参数显示在Url上且对长度有限制,但提交速度快。一般用来提交数据</span></span><br><span class="line"><span class="comment"> post:提交参数不显示在Url上且没有长度限制,但提交速度慢。在F12的Network中可以看到,一般用来发送数据</span></span><br><span class="line"><span class="comment"> --></span></span><br><span class="line"> <span class="tag"><<span class="name">form</span> <span class="attr">action</span>=<span class="string">""</span> <span class="attr">method</span>=<span class="string">"get"</span>></span></span><br><span class="line"> 文本框:<span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"username"</span>></span><span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> 密码框:<span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"password"</span> <span class="attr">name</span>=<span class="string">"password"</span>></span><span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> <span class="comment"><!-- 单选框和多选框需要同一组才能实现,通过 name 属性来分组 --></span></span><br><span class="line"> 性别:<span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"radio"</span> <span class="attr">name</span>=<span class="string">"sex"</span> <span class="attr">value</span>=<span class="string">"男"</span>></span>男 <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"radio"</span> <span class="attr">name</span>=<span class="string">"sex"</span> <span class="attr">value</span>=<span class="string">"女"</span>></span>女<span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> 爱好:<span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"checkbox"</span> <span class="attr">name</span>=<span class="string">"hobby"</span> <span class="attr">value</span>=<span class="string">"跑步"</span>></span>跑步 <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"checkbox"</span> <span class="attr">name</span>=<span class="string">"hobby"</span> <span class="attr">value</span>=<span class="string">"动漫"</span>></span>动漫 <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"checkbox"</span> <span class="attr">name</span>=<span class="string">"hobby"</span> <span class="attr">value</span>=<span class="string">"睡觉"</span>></span>睡觉<span class="tag"><<span class="name">br</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> <span class="attr">value</span>=<span class="string">"提交"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"reset"</span> <span class="attr">value</span>=<span class="string">"重置"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"button"</span> <span class="attr">value</span>=<span class="string">"点击验证"</span>></span></span><br><span class="line"> <span class="tag"></<span class="name">form</span>></span></span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure><p>浏览器页面显示如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E5%9B%9B%E5%A4%A9/Snipaste_2024-04-04_22-36-00.png"></p><blockquote><p>对于单选框和多选框的文本内容,服务端是无法获取的,而真正操作的是 <strong>name</strong> 和 <strong>value</strong> 属性</p></blockquote></li></ul>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> 软件测试基础 </tag>
</tags>
</entry>
<entry>
<title>软件测试基础(三)</title>
<link href="/posts/4d73c4c.html"/>
<url>/posts/4d73c4c.html</url>
<content type="html"><![CDATA[<p>测试用例需要在软件开发完成前做好。在将软件成品交付给你进行测试时,通过测试用例去验证该软件</p><p><strong>缺陷</strong>:实际测试结果与测试用例的预期结果不一致</p><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-27_09-53-02.png"></p><h2 id="缺陷"><a href="#缺陷" class="headerlink" title="缺陷"></a>缺陷</h2><p>软件在使用的过程中出现的任何<strong>问题</strong>都叫软件的缺陷,俗称<strong>bug</strong>。其判定的标准如下:</p><ul><li><strong>少功能</strong>:软件未实现需求(规格)说明书明确要求的功能</li><li><strong>功能错误</strong>:软件出现了需求(规格)说明书中指明不应该出现的错误</li><li><strong>多功能</strong>:软件实现的功能超出需求(规格)说明书指明的范围</li><li><strong>缺少隐性功能</strong>:软件未实现需求(规格)说明书虽未明确指明但应该实现的功能</li><li><strong>不易使用</strong>:软件难以理解,不易使用,运行缓慢,用户体验不好</li></ul><p>缺陷产生的原因如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-27_10-25-59.png"></p><p>软件缺陷的生命周期如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-27_10-29-50.png"></p><p>当一个缺陷被发现后,要懂得如何去描述这个缺陷,并知道根据缺陷类型和优先级等提交给谁来去解决,同时公司一般会有一个缺陷管理工具来记录这些缺陷。</p><p>软件缺陷的核心内容如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-28_09-53-17.png"></p><p>缺陷的提交要素如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-28_10-00-39.png"></p><p>缺陷的类型如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-28_10-02-43.png"></p><p>下图上的<strong>缺陷示例</strong>是在Excel上写的,真实在公司内部肯定会有一个专门的软件来写这个<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_09-50-18.png"></p><p>测试与开发在整个软件开发过程中的交流过程如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_09-54-55.png"></p><blockquote><p>知道测试和开发流程中涉及的工作即可</p></blockquote><p>提交缺陷的注意事项如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_09-56-58.png"></p><blockquote><p>面试题:当你发现缺陷后,首先你会怎么办? -> <strong>检查该缺陷是否可重现、再确定是否重复</strong></p></blockquote><p>缺陷的编写规范如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_10-04-35.png"></p><blockquote><p>有时A模块和B模块同时出现同一个缺陷,这时一般就只会处理一个就好了</p></blockquote><h2 id="缺陷管理工具"><a href="#缺陷管理工具" class="headerlink" title="缺陷管理工具"></a>缺陷管理工具</h2><p>一个国产、免费、开源、简单、轻量级的工具,该工具还支持三管融合(产品经理、项目管理、质量管理)。其地址为<a href="https://zentao.demo.qucheng.cc/user-login.html">禅道</a><br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_10-14-27.png"></p><blockquote><p>一般常用的还有<strong>JIRA</strong>、<strong>TFS</strong></p></blockquote><p>禅道本质上是一个<strong>项目管理工具</strong>,只是这里用其测试的地方来作为缺陷管理工具<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_10-18-29.png"></p><p>公司每一个角色的权限如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-03-29_10-23-54.png"></p><p>禅道使用流程:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-04-04_10-29-11.png"></p><blockquote><p>重点是对缺陷的管理</p></blockquote><p>提交Bug的图示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-04-04_10-46-40.png"><br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-04-04_10-50-41.png"></p><blockquote><p>将Bug指定给某个开发,在开发处理完该Bug后会指派给你这个Bug,告诉你当前状态后你<strong>验证</strong>该Bug即可</p></blockquote><p>禅道也可以创建用例,但是一般不好用。企业基本都是购买开发版,并将在Excel中写好的测试用例导入进去<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-04-04_11-01-53.png"></p><p>缺陷标题实现:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%89%E5%A4%A9/Snipaste_2024-04-04_11-14-51.png"></p><blockquote><p>本质就是按照规范去写,从而让人明白</p></blockquote>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> 软件测试基础 </tag>
</tags>
</entry>
<entry>
<title>软件测试基础(二)</title>
<link href="/posts/7a241c67.html"/>
<url>/posts/7a241c67.html</url>
<content type="html"><![CDATA[<p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_12-07-09.png"></p><h2 id="测试用例"><a href="#测试用例" class="headerlink" title="测试用例"></a>测试用例</h2><p><strong>用例</strong>:用户使用的<strong>案例</strong>。<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%80%E5%A4%A9/Snipaste_2024-03-19_11-14-21.png"></p><p><strong>测试用例</strong>:(模拟用户使用情景,进行测试)是为测试项目而设计的<strong>执行文档</strong>。</p><p>测试用例的<strong>作用</strong>:</p><ul><li>防止漏测</li><li>实施测试的标准:测试人员不仅要关注功能是否符合,还需要关注用户使用的体验感等</li></ul><p>测试用例的的编写格式,如下图所示:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%80%E5%A4%A9/Snipaste_2024-03-19_11-20-37.png"></p><ul><li><strong>用例编号</strong>:该用例的唯一标识符。格式:<strong>项目_模块_编号</strong></li><li><strong>用例标题</strong>:该用例的测试场景。格式:<strong>预期结果(测试点)</strong></li><li><strong>项目/模块</strong>:该用例是属于哪个项目/模块的。格式:<strong>所属项目或模块</strong></li><li><strong>优先级</strong>:表示用例的重要程度或影响力。格式:<strong>P0~P4(P0最高,即用户使用频率最高的功能)</strong></li><li><strong>前置条件</strong>:执行此条用例有哪些前置操作</li><li><strong>测试步骤</strong>:执行此条用例如何去操作</li><li><strong>测试数据</strong>:执行此条用例所需要使用的数据,没有可以为空</li><li><strong>预期结果</strong>:期望达到的结果</li></ul><h2 id="测试用例编写案例"><a href="#测试用例编写案例" class="headerlink" title="测试用例编写案例"></a>测试用例编写案例</h2><p>练习如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%80%E5%A4%A9/Snipaste_2024-03-19_11-38-20.png"></p><p>参考答案如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%B8%80%E5%A4%A9/Snipaste_2024-03-19_13-36-12.png"></p><h2 id="等价类"><a href="#等价类" class="headerlink" title="等价类"></a>等价类</h2><blockquote><p>解决数据过多的问题</p></blockquote><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_12-14-02.png"><br>在<strong>无穷多的数据</strong>中,<strong>有效数据中只取其一</strong>、<strong>无效数据中只取其一</strong>,最关键的是符合<strong>某种特征的集合</strong></p><p>练习如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_13-38-34.png"></p><p>参考答案如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_13-40-27.png"><br>这里重点关注<strong>类型</strong>、<strong>长度</strong>和<strong>规则</strong>。</p><p>适用场景:针对有大量数据测试输入,但是没法穷举测试的地方。其中最经常见的是<strong>页面的输入框类测试</strong></p><ul><li>输入框</li><li>下拉列表</li><li>单选复选框</li></ul><blockquote><p>重点:<br> 1、正向用例:一条尽可能覆盖多条<br> 2、逆向用例:每一条数据,都是一条单独用例。</p></blockquote><h2 id="边界值"><a href="#边界值" class="headerlink" title="边界值"></a>边界值</h2><blockquote><p>解决边界位数限制问题</p></blockquote><p>边界范围节点:选取<strong>正好等于</strong>、<strong>刚好大于</strong>、<strong>刚好小于</strong>边界的值作为测试数据</p><ul><li><strong>上点</strong>:边界上的点(正好等于)</li><li><strong>离点</strong>:距离上点最近的点(刚好大于、刚好小于)</li><li><strong>内点</strong>:范围内的点(区间范围内的数据)<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_17-24-17.png"></li></ul><p>步骤:<strong>明确需求</strong> -》 <strong>确定有效等价和无效等价类</strong> -》 <strong>确定边界范围值</strong> -》 <strong>提取数据编写测试用例</strong></p><p>练习如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_17-36-49.png"></p><p>参考答案如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-19_18-05-50.png"></p><p>边界值优化:将7个优化位<strong>5个</strong></p><ul><li>上点:必选(不考虑区间开闭)</li><li>内点:必选(建议选取中间范围)</li><li>离点:开内闭外(考虑开闭区间,开区间选择内部离点,闭区间选择外部离点)</li></ul><p>使用场景:</p><ul><li>在等价类的基础上针对边界范围内的测试数据输入的地方(重点关注边界)</li><li>常见词语描述:大小、尺寸、重量、最大、最小、至少、至多等修饰词语</li><li>典型代表:有边界范围的输入框测试</li></ul><blockquote><p>面试题:最常用的用例设计方法有哪些?–等价类、边界值</p></blockquote><h2 id="判定表法"><a href="#判定表法" class="headerlink" title="判定表法"></a>判定表法</h2><blockquote><p>适合条件组合数量较少的情况(比如4个以下)。当超过4个时,就不符合覆盖所有条件,应采用<strong>正交法</strong>来解决</p></blockquote><p>等价边界值分析法主要关注<strong>单个输入类条件</strong>的测试,并未考虑<strong>输入条件的各种组合</strong>、<strong>输入条件与输出结果之间有相互制约关系</strong></p><p>定义:以<strong>表格</strong>的形式表达<strong>多种条件逻辑判断</strong>的工具。主要由如下组成:</p><ul><li><strong>条件桩</strong>:无关次序,列出问题中的所有条件</li><li><strong>动作桩</strong>:排序没有约束,列出问题中可能采取的操作</li><li><strong>条件项</strong>:列出条件对应的取值,所有可能情况下的真假值</li><li><strong>动作项</strong>:列出条件项的、各种取值情况下应该采取的动作结果</li></ul><p>以案例:验证”若用户欠费或关机,则不允许主被叫”功能的测试:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-20_17-05-12.png"></p><p>所得出的规则:</p><ul><li>判定表中贯穿条件项与动作项的一列就是一条<strong>规则</strong></li><li>假设由n个条件,每个条件的取值有两个(0,1),全组合由2的n次方个规则</li></ul><p>设计用例的步骤:</p><ol><li>明确需求</li><li>画出判定表:<strong>列出条件桩和动作桩</strong>、<strong>列出条件项并将填写的条件进行全组合</strong>、<strong>根据条件项的组合确定动作项</strong>、<strong>简化合并相似规则</strong></li><li>根据规则编写测试用例</li></ol><p>练习如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-20_17-41-31.png"></p><p>参考答案如下图:<br><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-20_17-40-09.png"></p><h2 id="场景法"><a href="#场景法" class="headerlink" title="场景法"></a>场景法</h2><blockquote><p>根据实际的应用场景,测试人员一般优先测试<strong>业务用例</strong></p></blockquote><p>通过<strong>流程图</strong>来表达程序或业务的走向,其作用如下:</p><ul><li>通过看懂流程图来设计业务用例</li><li>当需求文档信息不全时,能根据需求梳理出流程</li></ul><p>场景法也可以叫做<strong>流程图法</strong>,通过流程图来描述用户的使用场景,然后覆盖流程路径来设计测试用例。其所具有的意义:</p><ul><li>用户使用角度:用户平时使用的不是单个功能,而是多个功能组合起来一起使用</li><li>测试人员角度:平时测试的都是单个功能点进行测试,容易忽略多个功能的组合测试</li></ul><h2 id="错误推荐法"><a href="#错误推荐法" class="headerlink" title="错误推荐法"></a>错误推荐法</h2><blockquote><p>应用场景:当项目用例都执行完毕,且BUG修复完成,离上线还有一段时间,在这段时间中可是使用错误推荐法复测主要业务或测试未覆盖的功能。</p></blockquote><p>先保证优先级高的业务流程正常,优先级低的业务上架以后慢慢测</p><p><img src="/../images/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80/%E7%AC%AC%E4%BA%8C%E5%A4%A9/Snipaste_2024-03-21_10-03-21.png"></p>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> 软件测试基础 </tag>
</tags>
</entry>
<entry>
<title>软件测试基础(一)</title>
<link href="/posts/d5158705.html"/>
<url>/posts/d5158705.html</url>
<content type="html"><![CDATA[<h2 id="软件测试的概念"><a href="#软件测试的概念" class="headerlink" title="软件测试的概念"></a>软件测试的概念</h2><p><strong>软件的产生过程</strong>,如下图所示:<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/softwareget.webp"></p><p>软件测试是指<strong>在预定的条件下执行程序,以此发现潜在的缺陷,并确保软件系统按照设计和预期的方式运行</strong>。测试的目标不仅仅是找出错误,更是为了验证软件是否符合规格和满足用户需求。</p><p>软件测试的目的是确保软件系统符合预期的需求,并能在不同的使用情境下表现良好。因为,我们需要<strong>通过不同的软件测试类型,全面验证软件的功能性、性能、安全性和兼容性</strong>,为用户提供一个可信赖的软件产品。</p><blockquote><p>评判一个软件是否优秀可从<strong>功能性</strong>、<strong>性能</strong>、<strong>兼容性</strong>、<strong>易用性</strong>、可靠性、<strong>安全</strong>、可维护性、可移植性这 8 个维度来衡量</p></blockquote><p>软件测试主流包含<strong>功能测试</strong>、<strong>接口测试</strong>、<strong>自动化测试</strong>和<strong>性能测试</strong>。</p><p>在进行软件测试时,我们要遵循一些基本原则,以确保测试的有效性和全面性。这些原则包括:</p><ul><li><strong>全面性(Exhaustiveness):</strong>测试应该覆盖软件的所有功能和情况,确保每个方面都经过验证。</li><li><strong>独立性(Independence):</strong>测试过程应该独立于开发过程,以确保独立的视角和避免潜在的偏见。</li><li><strong>可重复性(Repeatability):</strong>测试过程应该是可重复的,以便在发现问题时能够准确地重现并分析。</li><li><strong>尽早测试(Early Testing):</strong>测试应该在开发早期开始,以便在问题变得更加显著和昂贵之前就能够发现和解决它们。</li></ul><p>测试生命周期是指测试活动<strong>从计划阶段到测试执行、分析和报告</strong>的整个过程。它包括以下阶段:</p><ul><li><strong>计划和准备阶段:</strong>在项目开始之前,确定测试的范围、目标和资源需求,并制定测试计划。</li><li><strong>设计阶段:</strong>开发测试用例和测试数据,确保测试覆盖到所有关键功能和场景。</li><li><strong>执行阶段:</strong>执行测试用例,记录测试结果,并识别潜在的缺陷。</li><li><strong>分析和报告阶段:</strong>分析测试结果,生成测试报告,并协助开发团队解决发现的问题。</li></ul><p>通过理解这些基本概念,我们能够更好地理解软件测试的整体框架,为后续深入讨论不同软件测试的分类和方法奠定基础。</p><h2 id="软件测试模型"><a href="#软件测试模型" class="headerlink" title="软件测试模型"></a>软件测试模型</h2><p>软件测试模型是<strong>软件测试和开发阶段的对应关系</strong>,能够用来指导软件测试的整个过程,而常见的软件测试模型包括:V 模型、W 模型、H 模型、X 模型和前置模型,其中V 模型是最具代表性的软件测试模型,需要掌握,其余了解即可。</p><h3 id="V-模型"><a href="#V-模型" class="headerlink" title="V 模型"></a>V 模型</h3><p>RAD(Rapid Application Development,快速应用开发)模型是软件开发过程中的一个重要模型,通过开发和测试同时进行的方式来缩短开发周期,以提高开发效率。因其形状像一个字母V,故称为V模型。</p><p>V模型是一个著名的、以测试为驱动的开发模型,该模型强调开发过程中测试贯穿始终,是瀑布模型的一个变体。V模型描述了<strong>质量保证活动和沟通、建模相关活动以及早期构键相关的活动之间的关系</strong>。随着软件团队工作沿着V模型左侧步骤向下推进,基本问题需求逐步细化,形成问题及解决方案的技术描述。一旦编码结束,团队沿着V模型右侧的步骤向上推进工作,其实际上是执行了一系列测试(质量保证活动),这些测试验证了团队沿着V模型左侧步骤向下推进过程中所生成的每个模型。V模型提供了一种<strong>将验证确认活动应用于早期软件工程工作中的方法</strong>。<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/vmodel.webp"></p><p>V 模型包含了底层测试和高层测试,清楚标识了开发和测试的各个阶段:<strong>自上而下求精,对每个阶段都分工明确,方便把控整体项目</strong>。但也因为它的自上而下,导致缺陷到测试阶段才被发现,甚至很难发现;在开发过程中,也很难把握用户的需求,使得 V 模型步骤反复执行,返工量大,灵活度低。这时可以在每个阶段都加入<strong>适量的迭代</strong>进行改良。</p><blockquote><p><strong>底层测试:</strong>检测源代码质量,如单元测试;<strong>高层测试:</strong>检验整个系统的测试。<br><strong>迭代:</strong>重复反馈过程的活动,每一次迭代的结果会作为下一次迭代的初始值。</p></blockquote><p>一般来讲:<strong>单元测试所对应的是详细设计环节</strong>,也就是说,单元测试的测试用例是和详细设计一起出现的,在研发人员做详细设计的时候,相应的测试人员也就把测试用例写了出来;<strong>集成测试对应概要设计</strong>,在做模块功能分析及模块接口,数据传输方法的时候,就把集成测试用例根据概要设计中模块功能及接口等实现方法编写出来,以备以后作集成测试的时候可以直接引用;而<strong>系统测试,就是根据需求分析而来</strong>,在系统分析人员作系统分析,编写需求说明书的时候测试人员就根据客户需求说明书,把最后能实现系统功能的各种测试用例写出来,为做最后系统测试作准备。验收测试与用户需求对应,是非设计流程。</p><p>V模式是一种传统软件开发模型,一般适用于<strong>一些传统信息系统应用的开发</strong>,而一些高性能高风险的系统、互联网软件,或一个系统难以被具体模块化的时候,就比较难做成V模式所需的各种构件,需要更强调迭代的开发模型或者敏捷开发模型。</p><p>参考:<a href="https://blog.csdn.net/weixin_39294633/article/details/81805893">软件测试模型——V模型 & W模型</a>、<a href="https://zhuanlan.zhihu.com/p/99355357">深究递归和迭代的区别、优缺点及实例对比</a>、<a href="https://www.cnblogs.com/zp0923/p/10686334.html">测试模型—V模型</a>、<a href="https://www.cnblogs.com/yilang/p/12252661.html">软件生存周期模型之V模型 </a></p><h3 id="W-模型"><a href="#W-模型" class="headerlink" title="W 模型"></a>W 模型</h3><p>W 模型也称之为双 V 模型,一个 V 是开发的生命同期,另一个 V 是测试的生命周期,W 模型与 V 模型有一个很大的不同,就是 ** W 模型是一个并行的模型,V 模型是一个串行的模型**,W 模型开始是从用户需求分析开始,而不是等到编码完成后。并且测试阶段的划分更清楚,而不仅仅是单元测试、集成测试、系统测试,还包括前期的测试计划、测试方案等内容,这更符合现在企业测试的流程。<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/wmodel.webp"></p><p>W 模型有利于尽早全面地发现问题。从用户需求分析开始测试工程师就参与到项目的测试中,<strong>当用户需求分析完成后,测试工程师就需要参与到需求的验证和确认活动中,并需要提供可测试性用户需求分析说明书,这样可以尽早地发现需求阶段的缺陷</strong>。同时,对需求的测试也有利于及时了解项目难度和测试风险,及早制定应对措施,这将显著减少总体测试时间,加快项目进度。但 W 模型也存在局限性,需求、设计、编码等活动被视为是串行的,同时,<strong>测试和开发活动也保持着一种线性的前后关系,上一阶段完全结束,才可正式开始下一阶段工作</strong>,这样就无法支持迭代的开发模型。对于当前软件开发复杂多变的情况,W 模型并不能解除测试管理面临的困惑。</p><ul><li>在<strong>需求分析阶段</strong>,测试人员需要与开发人员共同参与需求讨论,确保对需求的理解准确无误。同时,测试人员应从测试角度提出疑虑和建议,以便在后续测试过程中顺利地发现问题和缺陷。在需求确定后,测试人员需要根据需求分析结果制定测试计划和测试用例。</li><li>在<strong>设计阶段</strong>,测试人员需要关注设计合理性和可测试性,对设计中可能存在的问题提出反馈。此时,测试人员应参与到设计评审中,以确保设计符合需求和测试要求。</li><li>在<strong>编码阶段</strong>,测试人员应关注代码质量,通过单元测试、集成测试和系统测试等手段,发现并修复代码中的缺陷。同时,测试人员还应与开发人员保持密切沟通,确保缺0陷修复的及时性和准确性。</li></ul><p>在 W 模型中,开发人员和测试人员不再是独立的个体,而是紧密结合成一个团队。开发人员需要根据测试人员的需求,提供合适的接口和工具支持,以便测试人员能够更高效地进行测试。同时,开发人员还需要积极参与缺陷修复工作,确保问题能够及时解决。测试人员则需要根据开发进度,合理安排测试资源和时间,确保测试工作的有效性和及时性。在发现缺陷时,测试人员应快速反馈给开发人员进行修复,并跟进修复进度,确保问题得到及时解决。</p><p>通过这种方式,开发与测试在W模型中相互支持、相互影响。不仅提高了软件质量和可靠性,还提高了开发效率。</p><h3 id="H-模型"><a href="#H-模型" class="headerlink" title="H 模型"></a>H 模型</h3><p>H模型将测试活动完全独立出来,形成一个完整的流程,同时将测试准备和测试执行清晰表现出来:<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/hmodel.webp"></p><ul><li>测试准备:所有测试活动的准备判断是否到测试就绪点。</li><li>测试就绪点:测试准入准则,即是否可以开始执行测试的条件。</li><li>测试执行:具体的执行测试的程序。</li><li>其它流程:回归测试、冒烟测试、探索性测试。</li></ul><p>H 模型让软件测试<strong>完全独立</strong>贯穿整个生命周期与其它流程并发进行,使得其可以<strong>尽早准备尽早执行</strong>,灵活性很强。同时也揭示了除测试执行外,还<strong>应有其他工作要处理</strong>,并且能根据<strong>被测对象的不同</strong>而分层次、分阶段、分次序的执行,同时也是可以被迭代。</p><p>H 模型要定义清晰的规则和管理制度,否则测试过程将很难管理和控制(<strong>管理型要求高</strong>),也要求能够很好的定义每个迭代的规模,不能太大也不能太小(<strong>技能要求高</strong>)。并且测试很多时候,你并不知道测试准备到什么时候是合适的,就绪点在哪,就绪点标准是什么,对后续的测试执行启动带来很大的困难(<strong>测试就绪点分析困难</strong>)。当被分了一个很小的迭代时,因人员技能不足而无法完成,会使整个项目会受到很大的干扰(<strong>对整个项目组的人员要求非常高</strong>)。</p><h3 id="X-模型"><a href="#X-模型" class="headerlink" title="X 模型"></a>X 模型</h3><p>X 模型也是对 V 模型的改进,X 模型的左边描述的是针对单独程序片段所进行的相互分离的编码和测试,此后将进行频繁的交接,通过集成,最终成为可执行的程序,然后再对这些可执行程序进行测试。己通过集成测试的成品可以进行封装并提交给用户,也可以作为更大规模和范围内集成的一部分。多根并行的曲线表示变更可以在各个部分发生。<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/xmodel.webp"></p><p>X 模型定位了探索性测试,这是<strong>不进行事先计划</strong>的特殊类型的测试,这一方式往往能帮助有经验的测试人员在测试计划之外发现更多的软件错误。但这样可能对测试造成人力、物力和财力的浪费,对测试员的熟练程度要求比较高。</p><h3 id="前置模型"><a href="#前置模型" class="headerlink" title="前置模型"></a>前置模型</h3><p>开发和测试相结合:前置测试模型将开发和测试的生命周期整合在起,标识了项目生命周期从开始到结束之间的关键行为。并且标识了这些行为在项目用期中的价值所在。如果其中有些行为没有得到很好的执行,那么项目成功的问能性就会因此而有所降低。如果有业务需求,则系统开发过程将更有效率。我们认为在没有业务需求的情况下进行开发和测试是不可能的。而且,业务需求最好在设计和开发之前就被正确定义。<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/frontmodel.webp"></p><p>对每一个交付内容进行测试:每一个交付的开发结果都必须通过一定的方式进行测试。源程序代码并不是惟一需要测试的内容。图中的椭圆框表示了其他一些要测试的对象,包括可行性报告、业务需求说明,以及系统设计文档等。这同V模型中开发和测试的对应关系是一致的,并且在其基础上有所扩展,变得更为明确。</p><p>在设计阶段进行测试计划和测试设计:设计阶段是作测试计划和测试设计的最好时机。很多组织要么根本不作测试计划和测试设计,要么在即将开始执行测试之前才飞快地完成测试计划和测试设计。在这种情况下,测试只是验证了程序的正确性,而不是验证整个系统本该实现的东西。</p><p>测试和开发结合在一起:前置测试将测试执行和开发结合在起,并在开发阶段以编码一测试一编码一测试的方式来体现。也就是说,程序片段一旦编写完成,就会立即进行测试。一般情况下,先进行的测试是单元测试,因为开发人员认为通过测试来发现错误是最经济的方式。但也可参考X模型,即一一个程序片段也需要相关的集成测试,甚至有时还需要一些特殊测试。 对于一个特定的程序片段,其测试的顺序可以按照v模型的规定,但其中还会交织一些程序片段的开发,而不是按阶段完全地隔离。</p><p>让验收测试和技术测试保持相互独立:验收测试应该独立于技术测试,这样可以提供双重的保险,以保证设计及程序编码能够符合最终用户的需求。验收测试既可以在实施阶段的第一步来执行,也可以在开发阶段的最后一步执行。前置测试模型提倡验收测试和技术测试沿循两条不同的路线来进行,每条路线分别地验证系统是否能够如预期设想的那样进行正常工作。这样,当单独设计好的验收测试完成了系统的验证时,我们即可确信这是一个正确的系统。</p><h2 id="软件测试的分类"><a href="#软件测试的分类" class="headerlink" title="软件测试的分类"></a>软件测试的分类</h2><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/softwaretest/testcategories.webp"></p><p>为了更有效地组织测试活动,我们可以<strong>根据不同的标准和目的将软件测试分为多个类别</strong>,比如<strong>按测试阶段划分、按测试类型划分和按测试方法划分</strong>等。下面将详细介绍这几种主要的软件测试的分类。</p><h3 id="按测试阶段划分"><a href="#按测试阶段划分" class="headerlink" title="按测试阶段划分"></a>按测试阶段划分</h3><p><strong>① 单元测试(Unit Testing):</strong>单元测试是测试软件中最小可测试单元的过程,通常是一个函数或方法。其目的是验证单元在隔离的环境中是否按照设计的预期工作,常用的工具包括 JUnit、PyTest 等。</p><p><strong>② 集成测试(Integration Testing):</strong>集成测试是将已通过单元测试的模块组合在一起进行测试,验证它们在集成时是否能够协同工作。这样可以及时发现模块之间的接口问题、数据传递问题以及其他由集成引起的错误。常用的集成测试方法包括自顶向下、自底向上、增量式集成等。</p><p><strong>③ 系统测试(System Testing):</strong>系统测试是指对整个软件系统进行全面测试,确保系统在各种情况下都能按照需求工作,包括功能测试、性能测试、安全测试等。验收测试,这在最终用户或客户的环境中进行,以确认系统是否符合用户需求,为软件发布做准备。</p><p><strong>④ 验收测试(Acceptance Testing):</strong>验收测试是在最终用户或客户的环境中对整个软件系统进行的测试,以确认系统是否符合用户需求,为软件发布做准备。</p><h3 id="按测试类型划分"><a href="#按测试类型划分" class="headerlink" title="按测试类型划分"></a>按测试类型划分</h3><p><strong>① 功能测试(Functional Testing):</strong>功能测试主要是验证软件系统的各个功能是否按照需求规格书中描述的要求正常工作。通常采用黑盒测试的方法,关注输入和输出。</p><p><strong>② 性能测试(Performance Testing):</strong>性能测试主要评估系统在不同负载和压力条件下的性能,包括响应时间、吞吐量等。一般可分为负载测试、压力测试和性能稳定性测试。</p><p><strong>③ 安全测试(Security Testing):</strong>安全测试主要评估软件系统对潜在威胁和攻击的抵御能力,包括身份验证、授权、数据保护等。</p><p><strong>④ 兼容性测试(Compatibility Testing):</strong>兼容性测试的目的是确保软件在不同环境、操作系统、浏览器等条件下能够正常运行。测试对象主要为不同操作系统、不同浏览器、不同设备等。</p><h3 id="按测试方法划分"><a href="#按测试方法划分" class="headerlink" title="按测试方法划分"></a>按测试方法划分</h3><p><strong>① 手动测试(Manual Testing):</strong>也是功能测试,测试中把被测的软件当成一个黑盒子,不关心盒子的内部结构是什么,只关心软件的输入数据和输出数据。</p><p><strong>② 自动化测试(Automated Testing):</strong>自动化测试主要通过使用自动化工具和脚本来执行测试用例,提高测试效率和覆盖范围。虽然初期投入较大,但适用于大规模和重复性测试。</p><h3 id="按代码可见度划分"><a href="#按代码可见度划分" class="headerlink" title="按代码可见度划分"></a>按代码可见度划分</h3><p><strong>① 黑盒测试(Black-box Testing):</strong>功能测试主要是验证软件系统的各个功能是否按照需求规格书中描述的要求正常工作。通常采用黑盒测试的方法,关注输入和输出。</p><p><strong>② 白盒测试(White-box Testing):</strong>又称结构测试、透明盒测试、逻辑驱动测试或基于代码的测试。白盒测试是指打开盒子,去研究里面的源代码和程序结果。白盒测试也是接口测试的一种。</p><p><strong>③ 灰盒测试(Gray-Box Testing):</strong>灰盒测试是介于白盒测试和黑盒测试之间的一种,灰盒测试多用于集成测试阶段,不仅关注输入、输出的正确性,同时也关注程序内部的情况。灰盒测试也是接口测试和功能测试的结合。</p><p>以上就是集中常见的软件测试的分类,通过深入了解这些分类的细节,团队能够更精确地选择合适的测试方法和阶段,确保全面有效地进行软件测试,提高软件质量。</p><blockquote><p>参考:<a href="https://ones.cn/blog/articles/the-classification-of-software-testing">软件测试的分类有哪些,如何进行软件测试?</a></p></blockquote><h2 id="测试流程"><a href="#测试流程" class="headerlink" title="测试流程"></a>测试流程</h2><p>软件测试的基本流程和步骤是<strong>确保软件质量</strong>的重要过程。它涉及验证软件的功能、性能、安全性和用户体验是否符合预期。</p><p>下面是软件测试的基本流程和步骤:</p><ol><li><p><strong>需求分析:</strong>了解软件的功能和性能需求。分析用户需求和系统需求,明确软件的预期目标和功能。</p></li><li><p><strong>测试计划:</strong>制定测试计划,确定测试目标、测试范围、测试资源和时间计划。考虑测试环境、测试工具和测试数据的需求。</p></li><li><p><strong>测试设计:</strong>设计测试用例,包括功能测试、性能测试、安全性测试和用户体验测试。测试用例应该覆盖各种功能和使用场景,以确保软件的全面测试。</p></li><li><p><strong>测试环境搭建:</strong>配置测试环境,包括硬件设备、操作系统、数据库和网络设置。确保测试环境与实际使用环境相似。</p></li><li><p><strong>测试执行:</strong>根据测试计划和测试设计执行测试用例。记录测试结果,包括测试通过和测试失败的情况。对测试失败的情况进行缺陷管理和跟踪。</p></li><li><p><strong>缺陷管理:</strong>将测试中发现的缺陷记录到缺陷管理系统中。包括缺陷的描述、重现步骤和优先级。跟踪缺陷的修复和验证过程。</p></li><li><p><strong>缺陷修复和验证:</strong>开发人员修复测试中发现的缺陷。测试人员验证修复后的软件是否符合预期。如果修复不完全或引入新的问题,则重新进行测试。</p></li><li><p><strong>测试报告:</strong>生成测试报告,总结测试结果和缺陷情况。报告应包括测试覆盖率、通过率和失败率。提供给项目组、开发人员和管理层参考。</p></li><li><p><strong>回归测试:</strong>在软件的修改版本中执行回归测试,确保修复缺陷不会引入新的问题。重复执行测试用例,验证软件的稳定性和功能性。</p></li><li><p><strong>最终验证:</strong>在软件发布前进行最终验证,确保软件符合预期目标和质量要求。验证软件的功能、性能、安全性和用户体验。</p></li><li><p><strong>发布和维护:</strong>在软件通过最终验证后,将其发布到生产环境中。跟踪用户反馈和问题报告,进行维护和更新。</p></li></ol><p>软件测试的基本流程和步骤是确保软件质量的关键过程。通过合理的测试计划和测试设计,可以发现和修复软件中的缺陷,提高软件的可靠性和稳定性。</p><blockquote><p>参考:<a href="https://www.kexintest.com/sys-nd/902.html">软件测试的基本流程和步骤是什么?</a></p></blockquote>]]></content>
<categories>
<category> 软件测试 </category>
</categories>
<tags>
<tag> 软件测试基础 </tag>
</tags>
</entry>
<entry>
<title>Excel学习笔记之操作表格</title>
<link href="/posts/83221823.html"/>
<url>/posts/83221823.html</url>
<content type="html"><![CDATA[<ol><li><p>在你浏览表格的数据时,常会在第n个列时不知道该列代表什么,这时可以在<strong>视图</strong>中冻结该窗口<br><img src="/../images/excel/dongjie.gif"></p></li><li><p>在需要比对第一条和第n条时,常规拖拽来比对会很麻烦,这时可以<strong>分割视窗</strong>来解决该问题,选择<strong>视图 > 拆分</strong><br><img src="/../images/excel/fenge.gif"></p></li><li><p>在<strong>开始 > 编辑</strong>的<strong>排序和筛选</strong>中和通过筛选来对单个或多个栏目进行排序<br><img src="/../images/excel/paixu.gif"></p></li><li><p>在<strong>插入 > 表格</strong>中创建表【最好<strong>无填充</strong>】,之后会生成一个<strong>表设计</strong>,在这里就可以对该表进行设计了,在<strong>页面布局</strong>中也可以对表的颜色进行更改<br><img src="/../images/excel/biao.gif"></p></li><li><p>跟筛选类似,可以选择特定栏目的指定规则。在<strong>开始 > 条件格式</strong>中使用<br><img src="/../images/excel/tiaojian.gif"></p></li><li><p>在一个Excel文件中可以创建<strong>多个工作表</strong>,并可以对这些工作表进行相应操作。其中按<strong>CTRL键</strong>可以在一个Excel中复制另一个工作表,也可以在工作表中鼠标右键选择<strong>移动和复制</strong>将工作表复制到另外一个Excel中</p></li><li><p>可以通过表创建一个图表。在<strong>插入 > 图表</strong>中可以进行创建并执行操作,当创建完成后在窗口生成一个图表并在操作栏生成一个<strong>图表格式</strong>。其中可以通过<strong>CTRL键</strong>来单独选择两栏来创建图表<br>【<strong>圆形图:描述资料间的相对比例</strong>、<strong>折线图:数值在一定时间的高低变化</strong>、<strong>散点图:比较两组数值之间的关系</strong>、<strong>雷达图:一般用于企业的财务分析</strong>】<br><img src="/../images/excel/tubiao.gif"></p></li><li><p><strong>数据透视表</strong>可以用来分析一组庞大的数据,对其进行筛选分析。此操作在<strong>插入</strong>操作选项中,这里需要注意的是一旦原数据发生改变,那么在数据透视表中是不会自动改变的,想要一键改变可以先将其变成表,再变成数据透视表<br><img src="/../images/excel/shuju.gif"></p></li></ol>]]></content>
<categories>
<category> 学习笔记 </category>
</categories>
<tags>
<tag> Excel </tag>
</tags>
</entry>
<entry>
<title>Excel学习笔记之入门</title>
<link href="/posts/74f74261.html"/>
<url>/posts/74f74261.html</url>
<content type="html"><![CDATA[<p>Excel在界面上都是由多个<strong>储存格</strong>所组成,这些储存格可以用来<strong>输入资料</strong>或<strong>设定公式</strong>,此外储存格还有一个重要的特点:每个都想地图上的坐标点那样有特点的<strong>参照位置</strong>,其显示在界面的左上角</p><p>先试着建立一个简单的资料表格:</p><ol><li><p>先在A1的储存格中输入<strong>ABC公司食品订单</strong>,这时你会发现文字已经超出了储存格的<strong>边界</strong>,这也可以说明一个储存格的长度是<strong>有限制</strong>的<br><img src="/../images/excel/Snipaste_2024-03-03_18-15-39.png"></p></li><li><p>通过按<strong>Enter键</strong>可以将选取的方框【kuang】移动到下方的储存格,在该储存格输入:<strong>订单编号</strong>,想要将游标移动到右边的储存格,可以按<strong>Tab键</strong>。当然如果想向左移动,可以按<strong>Shift + Tab键</strong>;事实上,也可以使用键盘的方向键来控制选取框的移动<br><img src="/../images/excel/yidong.gif"></p></li><li><p>只需要拖一标题栏位的<strong>间隔线【黑色十字架】</strong>来调整单一栏宽高,同时在excel也有一个小技巧:通过按两次间隔线可以将栏宽调整到文字宽度<br><img src="/../images/excel/kuan.gif"></p></li><li><p>一般来说对于表格的大标题通常会放在整个表格的正中央,可以通过<strong>合并并居中</strong>来实现,同时Excel也提供了针对标题文件的一些美化<br><img src="/../images/excel/hebing.gif"></p></li><li><p>在这里,Excel提供了一些简单的设计标准,可以在<strong>样式</strong>中使用。将多个单位<strong>一次性调整为相同的宽高度</strong>,可以先将宽度或高度不一致的栏位先框选起来,再选择其中任意一个间隔线的位置进行拖拽<br><img src="/../images/excel/du.gif"></p></li><li><p>Excel会根据你所输入的<strong>一组数据</strong>来产生<strong>相应差距</strong>的数列;Excel可以辨别的时间格式:如<strong>2023/5/6【以斜线隔开年月日】</strong>,可以利用<strong>设置单元格格式</strong>来改变格式;这里也有个小技巧,通过 CTRL + ;【分号】 来显示当前年月日<br><img src="/../images/excel/fen.gif"></p></li><li><p>如果里面有些资料是带<strong>重复性</strong>质的,通过鼠标右键选择<strong>从下拉列表中选择</strong>来快速填写<br><img src="/../images/excel/Snipaste_2024-03-03_20-49-21.png"></p></li><li><p>通过公式 <strong>【=参照位置*参照位置】</strong> 来进行计算。当复制该公式计算出来的数据时,<strong>不会复制数字而是复制其公式</strong>,也可以用下拉来快速进行计算,同时在栏位还是选取的时候可以通过<strong>格式刷</strong>来快速复制该栏位的所有样式<br><img src="/../images/excel/geshi.gif"></p></li><li><p>Excel里的表格线是不能打印出来的,这时可以在<strong>页面布局 > 工作表选项</strong>中的<strong>设置</strong>选择网格线,但是这种打印出来的外边框是黑线,内边框是虚线,并且是固定的,所以需要在<strong>开始 > 画笔</strong>中对边框线进行描绘<br><img src="/../images/excel/xian.gif"></p></li><li><p>可以在<strong>页面布局 > 背景</strong>中给表格添加背景;在<strong>页面布局 > 工作表选项</strong>中<strong>取消勾选</strong>查看,可以将Excel的网格线给隐藏;选取栏框后鼠标右键选择<strong>插入</strong>可以新增新的栏框</p></li><li><p>在 <strong>开始 > 自动求和</strong> 中对指定的储存格进行相应栏目的计算<br><img src="/../images/excel/sum.gif"></p></li></ol>]]></content>
<categories>
<category> 学习笔记 </category>
</categories>
<tags>
<tag> Excel </tag>
</tags>
</entry>
<entry>
<title>待办清单页</title>
<link href="/posts/95d8ff79.html"/>
<url>/posts/95d8ff79.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>最初是在 <strong>Leonus</strong> 的 <a href="https://blog.leonus.cn/2023/memeos.html">基于Memos实现说说和清单功能</a> 文章上了解到,该功能是需要依赖 <a href="https://memos.nesxc.com/">Memos</a> 来发布新的清单,而我这个 <strong>Memos</strong> 是 <a href="https://www.imcharon.com/">小N同学</a> 的纯公益代部署服务</p><p>在用了一段时间后,我发现我也没有经常发布这个清单,也就想可不可以将这个<strong>静态部署</strong>呢。在看到 <strong>铭心石刻</strong> 的 <a href="https://blog.kouseki.cn/posts/bc0.html">为你的博客添加待办清单页</a> 后就根据教程进行了部署,只不过发现在我<strong>小米10</strong>的手机上顶部图左右移动会很卡,遂觉得需要解决掉</p><p>最后在某一天逛自已博客的朋友圈时,发现 <strong>冰梦</strong> 发布了 <a href="https://hcer.top/posts/f316.html">待办清单页(本地整改版)</a> 这篇文章,也是对清单页的静态部署,既然这样就根据教程部署吧,最后发现<strong>手机卡顿</strong>问题解决了</p><h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><p>执行如下命令创建一个页面</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new page todolist</span><br></pre></td></tr></table></figure><p>在 <strong>/themes/anzhiyu/layout/includes/page</strong> 下创建 <strong>todolist.pug</strong> 文件,添加如下代码:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">#todolist-box</span><br><span class="line"> .page-top-card(style='background-image: url(https://pic.imgdb.cn/item/64fc80bd661c6c8e5403c5d9.webp) top / cover no-repeat;')</span><br><span class="line"> .content-item-tips 待办</span><br><span class="line"> span.content-item-title 记录清单</span><br><span class="line"> .content-bottom</span><br><span class="line"> .tips 想要记录的事还有很多,想要做的事源源不断</span><br><span class="line"></span><br><span class="line"> #todolist-container</span><br><span class="line"> each i in site.data.todolist</span><br><span class="line"> #todolist-main</span><br><span class="line"> h3= i.class_name</span><br><span class="line"> .todolist-content</span><br><span class="line"> ul</span><br><span class="line"> each item in i.todo_list</span><br><span class="line"> li</span><br><span class="line"> if item.completed</span><br><span class="line"> i.fa-regular.fa-check-circle</span><br><span class="line"> else</span><br><span class="line"> i.fa-regular.fa-circle</span><br><span class="line"> if item.link</span><br><span class="line"> a(href=item.link)= item.content</span><br><span class="line"> else</span><br><span class="line"> span= item.content</span><br></pre></td></tr></table></figure><p>在 <strong>/themes/anzhiyu/layout</strong> 目录下找到 <strong>page.pug</strong> 文件,添加文件路径:</p><figure class="highlight diff"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="addition">+ when 'todolist'</span></span><br><span class="line"><span class="addition">+ include includes/page/todolist.pug</span></span><br></pre></td></tr></table></figure><p>在 <strong>/source/_data</strong> 新建 <strong>todolist.yml</strong> 文件,添加如下代码:</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="attr">class_name:</span> <span class="string">我的博客</span></span><br><span class="line"> <span class="attr">todo_list:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">content:</span> <span class="string">冰刻无痕</span></span><br><span class="line"> <span class="attr">completed:</span> <span class="literal">false</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">content:</span> <span class="string">冰梦の博客</span></span><br><span class="line"> <span class="attr">link:</span> <span class="string">https://icemyst.github.io/</span></span><br><span class="line"> <span class="attr">completed:</span> <span class="literal">true</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">content:</span> <span class="string">Github支线</span></span><br><span class="line"> <span class="attr">link:</span> <span class="string">https://icemyst.github.io/</span></span><br><span class="line"> <span class="attr">completed:</span> <span class="literal">false</span></span><br></pre></td></tr></table></figure><p>在 <strong>/source/css</strong> 新建 <strong>todolist.css</strong> 文件,添加如下代码:</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:root</span> {</span><br><span class="line"> <span class="attr">--todo-border</span>: <span class="number">1px</span> solid <span class="number">#f7a796</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=dark]</span> {</span><br><span class="line"> <span class="attr">--todo-border</span>: <span class="number">1px</span> solid <span class="number">#51908b</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 处理单页背景 */</span></span><br><span class="line"><span class="selector-tag">body</span><span class="selector-attr">[data-type=<span class="string">"todolist"</span>]</span> <span class="selector-id">#page</span> {</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">box-shadow</span>: none <span class="meta">!important</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">0</span> <span class="meta">!important</span>;</span><br><span class="line"> <span class="attribute">background</span>: <span class="number">0</span> <span class="number">0</span> <span class="meta">!important</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">body</span><span class="selector-attr">[data-type=<span class="string">"todolist"</span>]</span> <span class="selector-id">#page</span> <span class="selector-class">.page-title</span> {</span><br><span class="line"> <span class="attribute">display</span>: none;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 顶部显示 */</span></span><br><span class="line"><span class="selector-class">.page-top-card</span> {</span><br><span class="line"> <span class="comment">/* background-size: cover;</span></span><br><span class="line"><span class="comment"> background-position: center; */</span></span><br><span class="line"> <span class="attribute">height</span>: <span class="number">20.5rem</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">10px</span> <span class="number">2.7rem</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">20px</span>;</span><br><span class="line"> <span class="attribute">color</span>: <span class="number">#fff</span>;</span><br><span class="line"> <span class="attribute">position</span>: relative;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.page-top-card</span> <span class="selector-tag">span</span><span class="selector-class">.content-item-title</span> {</span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">2.3em</span>;</span><br><span class="line"> <span class="attribute">font-weight</span>: bold;</span><br><span class="line"> <span class="attribute">line-height</span>: <span class="number">1.2</span>;</span><br><span class="line"> <span class="attribute">font-family</span>: <span class="string">'Microsoft YaHei'</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.page-top-card</span> <span class="selector-class">.content-bottom</span> {</span><br><span class="line"> <span class="attribute">display</span>: flex;</span><br><span class="line"> <span class="attribute">justify-content</span>: space-between;</span><br><span class="line"> <span class="attribute">align-items</span>: center;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="number">5.4rem</span>);</span><br><span class="line"> <span class="attribute">bottom</span>: <span class="number">1rem</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=<span class="string">'dark'</span>]</span> <span class="selector-class">.page-top-card</span> {</span><br><span class="line"> <span class="attribute">opacity</span>: .<span class="number">92</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 清单 */</span></span><br><span class="line"></span><br><span class="line"><span class="selector-id">#todolist-container</span> {</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">16px</span> <span class="number">0</span> <span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">column-count</span>: <span class="number">2</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#todolist-main</span> {</span><br><span class="line"> <span class="attribute">break-inside</span>: avoid-column;</span><br><span class="line"> <span class="attribute">background</span>: <span class="number">#fae4df</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">10px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">2px</span> dashed <span class="number">#f7a796</span>;</span><br><span class="line"> <span class="attribute">margin-bottom</span>: <span class="number">20px</span>;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">12px</span>;</span><br><span class="line"> <span class="attribute">box-shadow</span>: <span class="number">0</span> <span class="number">0</span> <span class="number">5px</span> <span class="number">0</span> <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0.5</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=dark]</span> <span class="selector-id">#todolist-main</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="number">#242424</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">2px</span> dashed <span class="number">#51908b</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#todolist-main</span> <span class="selector-tag">h3</span> {</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">0</span> <span class="meta">!important</span>;</span><br><span class="line"> <span class="attribute">border-bottom</span>: <span class="built_in">var</span>(--todo-border);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#todolist-main</span> <span class="selector-tag">ul</span> {</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">list-style</span>: none;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#todolist-main</span> <span class="selector-tag">li</span> {</span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">18px</span>;</span><br><span class="line"> <span class="attribute">text-indent</span>: <span class="number">5px</span>;</span><br><span class="line"> <span class="attribute">border-bottom</span>: <span class="built_in">var</span>(--todo-border);</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">0</span> <span class="meta">!important</span>;</span><br><span class="line"> <span class="attribute">font-weight</span>: normal;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#todolist-main</span> <span class="selector-tag">i</span> {</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">0</span> <span class="number">5px</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width</span>: <span class="number">768px</span>) {</span><br><span class="line"> <span class="selector-id">#todolist-container</span> {</span><br><span class="line"> <span class="attribute">column-count</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>在主题配置文件 <strong>_config.anzhiyu.yml</strong> 添加如下代码:</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">inject:</span></span><br><span class="line"> <span class="attr">head:</span></span><br><span class="line"> <span class="comment"># 清单</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><link</span> <span class="string">rel="stylesheet"</span> <span class="string">href="/css/todolist.css"></span></span><br></pre></td></tr></table></figure><p>接下来执行<strong>hexo三连</strong>就可以成功访问 <a href="/todolist/">清单</a> 了</p>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>Hexo搜索功能</title>
<link href="/posts/4e29.html"/>
<url>/posts/4e29.html</url>
<content type="html"><![CDATA[<h2 id="本地搜索"><a href="#本地搜索" class="headerlink" title="本地搜索"></a>本地搜索</h2><p>当你的博客文章数据<strong>不多</strong>时,使用 <a href="https://github.com/wzpan/hexo-generator-search">hexo-generator-search</a> 插件给博客添加搜索功能<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/Snipaste_2023-10-24_23-00-26.webp"></p><p>运行如下命令安装此插件</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-search --save</span><br></pre></td></tr></table></figure><p>在博客配置文件 <strong>_config.yml</strong> 中添加如下代码</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">search:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">search.xml</span></span><br><span class="line"> <span class="attr">field:</span> <span class="string">post</span></span><br><span class="line"> <span class="attr">content:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure><p>在主题配置文件 <strong>_config.anzhiyu.yml</strong> 中修改以下内容为</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Local search</span></span><br><span class="line"><span class="attr">local_search:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">preload:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">CDN:</span></span><br></pre></td></tr></table></figure><h2 id="algolia搜索"><a href="#algolia搜索" class="headerlink" title="algolia搜索"></a>algolia搜索</h2><p>但是当你的博客文章数据<strong>很多</strong>时,这时建议使用<strong>第三方</strong>的搜索系统,而这里推荐使用<strong>Algolia搜索</strong>,毕竟对于个人用户来说几乎是<strong>免费</strong>的</p><blockquote><p>algolia提供给个人用户上限1万条索引记录和每月1万次的搜索次数,故对于个人用户来说几乎是<strong>无限供应</strong></p></blockquote><p>在使用该搜索功能前需要获取下<strong>密钥</strong>。通过 Github 来注册 <a href="https://dashboard.algolia.com/users/sign_up">algolia</a><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/Snipaste_2023-10-24_23-17-53.webp"></p><p>在注册完后,根据如下步骤来创建一个 <strong>Index</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/algoliaIndex.webp"></p><p>接下来就是获取algolia搜索的密钥了。创建拥有一定权限的 <strong>api key</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/algoliaKeys.webp"></p><p>进入 <strong>All API Keys</strong>,点击 <strong>New API Key</strong>。<strong>indices</strong> 选择你创建的 <strong>Index</strong>,<strong>ACL</strong> 按照如下图选择对应的权限,其他均默认即可<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/ALgoliaAcl.webp"></p><p>点击 <strong>Create</strong> 就能创建一个 <strong>api key</strong> 了<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/AlgoliaKey.webp"></p><p>前期已经准备好了,这时后运行如下命令为你的博客安装插件</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-algoliasearch --save</span><br></pre></td></tr></table></figure><p>在博客配置文件 <strong>_config.yml</strong> 中添加如下代码</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">algolia:</span></span><br><span class="line"> <span class="attr">appId:</span> <span class="string">"your ApplicationID"</span></span><br><span class="line"> <span class="attr">apiKey:</span> <span class="string">"your Search-Only API Key"</span></span><br><span class="line"> <span class="attr">adminApiKey:</span> <span class="string">"your Admin API Key"</span></span><br><span class="line"> <span class="attr">chunkSize:</span> <span class="number">5000</span></span><br><span class="line"> <span class="attr">indexName:</span> <span class="string">"your indexName"</span></span><br><span class="line"> <span class="attr">fields:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">content:strip:truncate,0,500</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">excerpt:strip</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">gallery</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">permalink</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">photos</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">slug</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">tags</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">title</span></span><br></pre></td></tr></table></figure><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/search/AlgoliaApi.webp"></p><p>在主题配置文件 <strong>_config.anzhiyu.yml</strong> 中修改以下内容为</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Algolia search</span></span><br><span class="line"><span class="attr">algolia_search:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">hits:</span></span><br><span class="line"> <span class="attr">per_page:</span> <span class="number">5</span></span><br><span class="line"> <span class="attr">labels:</span></span><br><span class="line"> <span class="attr">input_placeholder:</span> <span class="string">Search</span> <span class="string">for</span> <span class="string">Posts</span></span><br><span class="line"> <span class="attr">hits_empty:</span> <span class="string">"我们没有找到任何搜索结果: ${query}"</span></span><br><span class="line"> <span class="attr">hits_stats:</span> <span class="string">"找到${hits}条结果(用时${time} ms)"</span></span><br></pre></td></tr></table></figure><p>每当你需要将一篇文章给放进索引中去时,可以运行 <strong>hexo algolia</strong> 来将当前博客所有文章数据给<strong>覆盖</strong>进去</p>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>Twikoo评论部署</title>
<link href="/posts/d924f329.html"/>
<url>/posts/d924f329.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>通过使用 <strong>Vercel + MongoDB</strong> 来部署Twikoo服务<strong>免费且不需要服务器</strong>,加上Twikoo的独立的配置界面,对小白超级友好</p><div class='btf-tag-link'><a class="tag-Link" target="_blank" href="https://twikoo.js.org/backend.html"> <div class="tag-link-tips">引用站外地址</div> <div class="tag-link-bottom"> <div class="tag-link-left" style="background-image: url(https://twikoo.js.org/twikoo-logo-mini.png);"></div> <div class="tag-link-right"> <div class="tag-link-title">Twikoo文档</div> <div class="tag-link-sitename"> 一个简洁、安全、免费的静态网站评论系统</div> </div> <i class="fas fa-angle-right"></i> </div> </a></div><h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><p>申请 <a href="https://www.mongodb.com/cloud/atlas/register">MongoDB</a> 账号,之后点击 <strong>Create your Atlas account</strong>。然后创建<strong>免费</strong>的 MongoDB 数据库,区域推荐选择 <strong>AWS / N. Virginia (us-east-1)</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/twikoo/20230227012516.webp"></p><p>点击 <strong>Create Cluster</strong> 开始创建数据库用户。记住<strong>数据库密码</strong>,按步骤设置允许所有 <strong>IP(0.0.0.0/0)</strong> 地址的连接,填完信息后,点击 <strong>Finish and Close</strong> </p><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/twikoo/20230227012936.webp"></p><p>在 <strong>Clusters</strong> 页面点击 <strong>Connect</strong>,选择 <strong>Connect your appliction</strong>,记住<strong>数据库连接字符串</strong> </p><blockquote><p>连接字符串中的 <code><password></code> 修改为你的数据库密码</p></blockquote><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/twikoo/20230227013253.webp"></p><p>点击 <a href="https://vercel.com/import/project?template=https://github.com/twikoojs/twikoo/tree/main/src/server/vercel-min">此链接</a> 将 <strong>Twikoo</strong> 一键部署到 <strong>Vercel</strong> 中,然后在成功部署的项目的<strong>Settings</strong>中找到 <strong>Environment Variables</strong> 来添加环境变量 <strong>MONGODB_URI</strong>,它的值为前面记录的<strong>数据库连接字符串</strong></p><p>进入 <strong>Deployments</strong> , 然后在任意一项后面点击更多(三个点) , 然后点击 <strong>Promote to Production</strong>。成功部署当前服务后,在 <strong>Project</strong> 就可以看到 <strong>Twikoo 云函数运行正常</strong> 的提示</p><blockquote><p>可以在 Project 页面中点击 <strong>Domain</strong> 来配置一个域名(Vercel提供的域名被墙了)</p></blockquote><p>在主题配置文件 <strong>_config.anzhiyu.yml</strong> 中修改如下代码为</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Twikoo</span></span><br><span class="line"><span class="comment"># https://github.com/imaegoo/twikoo</span></span><br><span class="line"><span class="attr">twikoo:</span></span><br><span class="line"> <span class="attr">envId:</span> [<span class="string">vercel中该项目域名</span>]</span><br><span class="line"> <span class="attr">region:</span></span><br><span class="line"> <span class="attr">visitor:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">option:</span></span><br></pre></td></tr></table></figure><h2 id="邮件通知"><a href="#邮件通知" class="headerlink" title="邮件通知"></a>邮件通知</h2><p>进入 Twikoo评论系统 的管理界面,<strong>配置管理</strong> -> <strong>邮件通知</strong> -> <strong>MAIL_TEMPLATE</strong> 和 <strong>MAIL_TEMPLATE_ADMIN</strong>,这两个分别是<strong>通知邮件模板</strong>和<strong>博主通知邮件模板</strong>:</p><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/twikoo/Snipaste20231014000300.webp"></p><div class="tabs" id="邮件通知"><ul class="nav-tabs"><li class="tab active"><button type="button" data-href="#邮件通知-1">通知邮件模板</button></li><li class="tab"><button type="button" data-href="#邮件通知-2">博主通知邮件模板</button></li></ul><div class="tab-contents"><div class="tab-item-content active" id="邮件通知-1"><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"isForwardContent"</span>></span><span class="tag"><<span class="name">div</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"content"</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">style</span>=<span class="string">"background: white;width: 95%;max-width: 800px;margin: auto auto; border-radius: 15px; border: #39c5bb 1px solid; overflow: hidden; -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.12); box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.18); "</span>></span><span class="tag"><<span class="name">header</span> <span class="attr">style</span>=<span class="string">"overflow: hidden"</span>></span><span class="tag"><<span class="name">img</span> <span class="attr">src</span>=<span class="string">"https://tuchuang.voooe.cnhttps://jsd.onmicrosoft.cn/npm/blogassert/images/2023/01/02/violet.webp"</span> <span class="attr">style</span>=<span class="string">"width: 100%; z-index: 666"</span> /></span><span class="tag"></<span class="name">header</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">style</span>=<span class="string">"padding: 5px 20px;background-color: #46e1c60d"</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"dear"</span> <span class="attr">style</span>=<span class="string">" border-radius: 30px; position: relative; color: white; float: left; z-index: 999; background: #39c5bb; padding: 10px 30px; margin: -25px auto 0; box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3); "</span>></span>亲爱的 ${PARENT_NICK} 同学:<span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">br</span> /></span><span class="tag"><<span class="name">center</span>></span><span class="tag"><<span class="name">h3</span>></span>来自 <span class="tag"><<span class="name">strong</span>></span>${NICK}<span class="tag"></<span class="name">strong</span>></span> 的回复<span class="tag"></<span class="name">h3</span>></span><span class="tag"></<span class="name">center</span>></span><span class="tag"><<span class="name">hr</span> <span class="attr">style</span>=<span class="string">"width:200px;border:0;border-bottom:1px solid #e5e5e5;margin:12px auto;"</span> /></span><span class="tag"><<span class="name">br</span> /></span><span class="tag"><<span class="name">p</span>></span>您好!您在 <span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"${POST_URL}"</span> <span class="attr">style</span>=<span class="string">"text-decoration: none; color: #39c5bb"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span><span class="symbol">&nbsp;</span>${SITE_NAME}<span class="symbol">&nbsp;</span><span class="tag"></<span class="name">a</span>></span>上发表的评论:<span class="tag"></<span class="name">p</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"tk-content"</span> <span class="attr">style</span>=<span class="string">"border-radius: 8px;border: 1px solid #ddd; padding-bottom: 20px; background-color: #f5f5f5; margin: 15px 0px; padding-left: 20px; padding-right: 20px; padding-top: 20px;"</span>></span>${PARENT_COMMENT}<span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">p</span>></span><span class="tag"><<span class="name">strong</span>></span>${NICK}<span class="tag"></<span class="name">strong</span>></span> 给您回复啦: <span class="tag"></<span class="name">p</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"tk-content"</span> <span class="attr">style</span>=<span class="string">"border-radius: 8px;border: 1px solid #ddd; padding-bottom: 20px; background-color: #f5f5f5; margin: 15px 0px; padding-left: 20px; padding-right: 20px; padding-top: 20px; "</span>></span>${COMMENT}<span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">p</span>></span>欢迎再次光临小站: <span class="tag"><<span class="name">a</span> <span class="attr">style</span>=<span class="string">"text-decoration:none; color:#39c5bb"</span> <span class="attr">href</span>=<span class="string">"${SITE_URL}"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span>${SITE_NAME}<span class="tag"></<span class="name">a</span>></span><span class="tag"></<span class="name">p</span>></span><span class="tag"><<span class="name">p</span>></span>(此邮件由Twikoo系统发出,支持直接回复)<span class="tag"></<span class="name">p</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"chakan"</span> <span class="attr">style</span>=<span class="string">"text-align: center;"</span>></span><span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"${POST_URL}"</span> <span class="attr">style</span>=<span class="string">"color:#ffffff;text-decoration:none;display:inline-block;min-height:28px;line-height:28px;padding:0 13px;outline:0;background:#39c5bb;font-size:13px;text-align: center;font-weight:400;border:0;border-radius:999em"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span>点击去原文查看<span class="symbol">&gt;</span><span class="symbol">&gt;</span><span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">p</span>></span><span class="tag"></<span class="name">p</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"footer-p"</span> <span class="attr">style</span>=<span class="string">"text-align: center; margin-top: 3rem; display:block;color:#b3b3b1;text-decoration:none;"</span>></span><span class="tag"><<span class="name">img</span> <span class="attr">src</span>=<span class="string">"https://blhorizon.github.io/img/avatar.webp"</span> <span class="attr">style</span>=<span class="string">"width:5rem; margin:0 auto;border-radius: 5px;"</span> /></span><span class="symbol">&nbsp;</span> <span class="tag"><<span class="name">hr</span> <span class="attr">style</span>=<span class="string">"width:165px;border:0;border-bottom:1px solid #e5e5e5;margin:5px auto;"</span> /></span>©<span class="symbol">&nbsp;</span>2022-2023<span class="symbol">&nbsp;</span>By <span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://blhorizon.github.io/"</span> <span class="attr">style</span>=<span class="string">"text-align:center; color: #39c5bb;text-decoration: none;font-weight: bold"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span>萌傀儡<span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">p</span>></span><span class="tag"></<span class="name">p</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">br</span> /></span><span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> ::-webkit-scrollbar { <span class="attribute">display</span>: none; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">id</span>=<span class="string">"cloudAttachStyle"</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-id">#divNeteaseBigAttach</span>, <span class="selector-class">.qmbox</span> <span class="selector-id">#divNeteaseBigAttach_bak</span> { <span class="attribute">display</span>: none; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">id</span>=<span class="string">"blockquoteStyle"</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-tag">blockquote</span> { <span class="attribute">display</span>: none; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-tag">body</span> { <span class="attribute">font-size</span>: <span class="number">14px</span>; <span class="attribute">font-family</span>: arial, verdana, sans-serif; <span class="attribute">line-height</span>: <span class="number">1.666</span>; <span class="attribute">padding</span>: <span class="number">0</span>; <span class="attribute">margin</span>: <span class="number">0</span>; <span class="attribute">overflow</span>: auto; <span class="attribute">white-space</span>: normal; <span class="attribute">word-wrap</span>: break-word; <span class="attribute">min-height</span>: <span class="number">100px</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">td</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">input</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">button</span>, <span class="selector-class">.qmbox</span> select, <span class="selector-class">.qmbox</span> <span class="selector-tag">body</span> { <span class="attribute">font-family</span>: Helvetica, <span class="string">'Microsoft Yahei'</span>, verdana; } <span class="selector-class">.qmbox</span> pre { <span class="attribute">white-space</span>: pre-wrap; <span class="attribute">white-space</span>: -moz-pre-wrap; <span class="attribute">white-space</span>: -pre-wrap; <span class="attribute">white-space</span>: -o-pre-wrap; <span class="attribute">word-wrap</span>: break-word; <span class="attribute">width</span>: <span class="number">95%</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">th</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">td</span> { <span class="attribute">font-family</span>: arial, verdana, sans-serif; <span class="attribute">line-height</span>: <span class="number">1.666</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">img</span> { <span class="attribute">border</span>: <span class="number">0</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">header</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">footer</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">section</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">aside</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">article</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">nav</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">hgroup</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">figure</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">figcaption</span> { <span class="attribute">display</span>: block; } <span class="selector-class">.qmbox</span> <span class="selector-tag">blockquote</span> { <span class="attribute">margin-right</span>: <span class="number">0px</span>; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width</span>: <span class="number">1100px</span>) {<span class="selector-id">#content</span> <span class="selector-tag">p</span> {<span class="attribute">font-size</span>: <span class="number">10px</span>;} <span class="selector-id">#content</span> <span class="selector-tag">h3</span> {<span class="attribute">font-size</span>: <span class="number">14px</span>;} <span class="selector-class">.footer-p</span> {<span class="attribute">font-size</span>: <span class="number">9px</span>;} <span class="selector-class">.dear</span> {<span class="attribute">font-size</span>: <span class="number">12px</span>;}} </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">id</span>=<span class="string">"ntes_link_color"</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-tag">a</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">td</span> <span class="selector-tag">a</span> { <span class="attribute">color</span>: <span class="number">#236da1</span>; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div><div class="tab-item-content" id="邮件通知-2"><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">div</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"isForwardContent"</span>></span><span class="tag"><<span class="name">div</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"content"</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">style</span>=<span class="string">"background: white;width: 95%;max-width: 800px;margin: auto auto; border-radius: 15px; border: #39c5bb 1px solid; overflow: hidden; -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.12); box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.18); "</span>></span><span class="tag"><<span class="name">header</span> <span class="attr">style</span>=<span class="string">"overflow: hidden"</span>></span><span class="tag"><<span class="name">img</span> <span class="attr">src</span>=<span class="string">"https://tuchuang.voooe.cnhttps://jsd.onmicrosoft.cn/npm/blogassert/images/2023/01/02/violet.webp"</span> <span class="attr">style</span>=<span class="string">"width: 100%; z-index: 666"</span> /></span><span class="tag"></<span class="name">header</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">style</span>=<span class="string">"padding: 5px 20px;background-color: #46e1c60d"</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"dear"</span> <span class="attr">style</span>=<span class="string">" border-radius: 30px; position: relative; color: white; float: left; z-index: 999; background: #39c5bb; padding: 10px 30px; margin: -25px auto 0; box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3); "</span>></span>亲爱的萌傀儡:<span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">br</span> /></span><span class="tag"><<span class="name">center</span>></span><span class="tag"><<span class="name">h3</span>></span>来自 <span class="tag"><<span class="name">strong</span>></span>${NICK}<span class="tag"></<span class="name">strong</span>></span> 的评论<span class="tag"></<span class="name">h3</span>></span><span class="tag"></<span class="name">center</span>></span><span class="tag"><<span class="name">hr</span> <span class="attr">style</span>=<span class="string">"width:200px;border:0;border-bottom:1px solid #e5e5e5;margin:12px auto;"</span> /></span><span class="tag"><<span class="name">br</span>></span><span class="tag"><<span class="name">p</span>></span> 您好!系统得知 <span class="tag"><<span class="name">strong</span>></span>${NICK}<span class="tag"></<span class="name">strong</span>></span> 刚刚在您的网站发表评论: <span class="tag"></<span class="name">p</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"tk-content"</span> <span class="attr">style</span>=<span class="string">"border-radius: 8px;border: 1px solid #ddd; padding-bottom: 20px; background-color: #f5f5f5; margin: 15px 0px; padding-left: 20px; padding-right: 20px; padding-top: 20px; "</span>></span>${COMMENT}<span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">p</span>></span>特地通知您,快去看看吧!<span class="tag"></<span class="name">p</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"chakan"</span> <span class="attr">style</span>=<span class="string">"text-align: center;"</span>></span><span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"${POST_URL}"</span> <span class="attr">style</span>=<span class="string">"color:#ffffff;text-decoration:none;display:inline-block;min-height:28px;line-height:28px;padding:0 13px;outline:0;background:#39c5bb;font-size:13px;text-align: center;font-weight:400;border:0;border-radius:999em"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span>点击去原文查看<span class="symbol">&gt;</span><span class="symbol">&gt;</span><span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">p</span>></span><span class="tag"></<span class="name">p</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"footer-p"</span> <span class="attr">style</span>=<span class="string">"text-align: center; margin-top: 3rem; display:block;color:#b3b3b1;text-decoration:none;"</span>></span><span class="tag"><<span class="name">img</span> <span class="attr">src</span>=<span class="string">"https://blhorizon.github.io/img/avatar.webp"</span> <span class="attr">style</span>=<span class="string">"width:5rem; margin:0 auto;border-radius: 5px;"</span> /></span><span class="symbol">&nbsp;</span> <span class="tag"><<span class="name">hr</span> <span class="attr">style</span>=<span class="string">"width:165px;border:0;border-bottom:1px solid #e5e5e5;margin:5px auto;"</span> /></span>©<span class="symbol">&nbsp;</span>2022-2023<span class="symbol">&nbsp;</span>By <span class="tag"><<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://www.fomal.cc/"</span> <span class="attr">style</span>=<span class="string">"text-align:center; color: #39c5bb;text-decoration: none;font-weight: bold"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>></span>萌傀儡<span class="tag"></<span class="name">a</span>></span><span class="tag"><<span class="name">p</span>></span><span class="tag"></<span class="name">p</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">br</span> /></span><span class="tag"></<span class="name">div</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> ::-webkit-scrollbar { <span class="attribute">display</span>: none; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">id</span>=<span class="string">"cloudAttachStyle"</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-id">#divNeteaseBigAttach</span>, <span class="selector-class">.qmbox</span> <span class="selector-id">#divNeteaseBigAttach_bak</span> { <span class="attribute">display</span>: none; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">id</span>=<span class="string">"blockquoteStyle"</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-tag">blockquote</span> { <span class="attribute">display</span>: none; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-tag">body</span> { <span class="attribute">font-size</span>: <span class="number">14px</span>; <span class="attribute">font-family</span>: arial, verdana, sans-serif; <span class="attribute">line-height</span>: <span class="number">1.666</span>; <span class="attribute">padding</span>: <span class="number">0</span>; <span class="attribute">margin</span>: <span class="number">0</span>; <span class="attribute">overflow</span>: auto; <span class="attribute">white-space</span>: normal; <span class="attribute">word-wrap</span>: break-word; <span class="attribute">min-height</span>: <span class="number">100px</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">td</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">input</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">button</span>, <span class="selector-class">.qmbox</span> select, <span class="selector-class">.qmbox</span> <span class="selector-tag">body</span> { <span class="attribute">font-family</span>: Helvetica, <span class="string">'Microsoft Yahei'</span>, verdana; } <span class="selector-class">.qmbox</span> pre { <span class="attribute">white-space</span>: pre-wrap; <span class="attribute">white-space</span>: -moz-pre-wrap; <span class="attribute">white-space</span>: -pre-wrap; <span class="attribute">white-space</span>: -o-pre-wrap; <span class="attribute">word-wrap</span>: break-word; <span class="attribute">width</span>: <span class="number">95%</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">th</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">td</span> { <span class="attribute">font-family</span>: arial, verdana, sans-serif; <span class="attribute">line-height</span>: <span class="number">1.666</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">img</span> { <span class="attribute">border</span>: <span class="number">0</span>; } <span class="selector-class">.qmbox</span> <span class="selector-tag">header</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">footer</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">section</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">aside</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">article</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">nav</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">hgroup</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">figure</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">figcaption</span> { <span class="attribute">display</span>: block; } <span class="selector-class">.qmbox</span> <span class="selector-tag">blockquote</span> { <span class="attribute">margin-right</span>: <span class="number">0px</span>; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width</span>: <span class="number">1100px</span>) {<span class="selector-id">#content</span> <span class="selector-tag">p</span> {<span class="attribute">font-size</span>: <span class="number">10px</span>;} <span class="selector-id">#content</span> <span class="selector-tag">h3</span> {<span class="attribute">font-size</span>: <span class="number">14px</span>;} <span class="selector-class">.footer-p</span> {<span class="attribute">font-size</span>: <span class="number">9px</span>;} <span class="selector-class">.dear</span> {<span class="attribute">font-size</span>: <span class="number">12px</span>;}} </span><span class="tag"></<span class="name">style</span>></span><span class="tag"><<span class="name">style</span> <span class="attr">id</span>=<span class="string">"ntes_link_color"</span> <span class="attr">type</span>=<span class="string">"text/css"</span>></span><span class="language-css"> <span class="selector-class">.qmbox</span> <span class="selector-tag">a</span>, <span class="selector-class">.qmbox</span> <span class="selector-tag">td</span> <span class="selector-tag">a</span> { <span class="attribute">color</span>: <span class="number">#236da1</span>; } </span><span class="tag"></<span class="name">style</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span></span><br><span class="line"><span class="tag"></<span class="name">style</span>></span><span class="tag"></<span class="name">div</span>></span><span class="tag"></<span class="name">div</span>></span></span><br></pre></td></tr></table></figure><button type="button" class="tab-to-top" aria-label="scroll to top"><i class="fas fa-arrow-up"></i></button></div></div></div><p>可以先通过 <a href="https://www.wetools.com/html-formatter">HTML 代码格式化</a> 进行<strong>格式化</strong>,这样可以根据自己的实际情况微调里面的信息和样式,然后通过 <a href="https://www.wetools.com/html-minify">HTML 代码压缩工具</a> 进行压缩并写入相应位置</p><p>配置好模板后,接下来就是让你的邮箱能够接收通知了。这里我以 <strong>QQ邮箱</strong> 为例,其他邮箱可自行摸索,原理大同小异。先前往你的邮件服务提供商,开通<strong>POP3/SMTP</strong>服务获取<strong>授权码</strong></p><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/twikoo/Snipaste20231014011144.webp"></p><p>最后进入 Twikoo评论系统 的管理界面,<strong>配置管理</strong> -> <strong>邮件通知</strong> -> <strong>SMTP_PASS</strong> 中填写自已的授权码即可</p><h2 id="配置表情"><a href="#配置表情" class="headerlink" title="配置表情"></a>配置表情</h2><p>在 <a href="https://github.com/2X-ercha/Twikoo-Magic">Twikoo-Magic</a> 或 <a href="https://emotion.xiaokang.me/">表情速查</a> 的 <strong>表情OSS</strong> 中复制相应的 json 信息,将这些信息结合起来后命名为 <strong>owo.json</strong>(最好),然后托管到静态部署网站。</p><p>进入 Twikoo评论系统 的管理界面,选择 <strong>配置管理</strong> -> <strong>插件</strong> -> <strong>EMOTION_CDN</strong>,这里填写你的 owo.json 文件链接</p><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/twikoo/Snipaste20231014000412.webp"></p>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>解决SM.MS图床访问</title>
<link href="/posts/3c588f54.html"/>
<url>/posts/3c588f54.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>突然间 SM.MS图床 的图片访问不了,同时也发现 <a href="https://s2.loli.net/">https://s2.loli.net/</a> 也访问不了。通过百度找到了这篇文章:<a href="https://blog.csdn.net/szullc/article/details/128163496">【经验分享】突然我的SM.MS的图床没法访问了(内附解决方法)</a> ,从而解决了问题。</p><p>那么先进行排查,找出问题所在:</p><ul><li>先确认下我的电脑是具有外网能力的:很简单,因为我都可以访问百度等网页内容</li><li>再用浏览器访问一下图片的URL地址,发现报错了,提示如下,错误是 <strong>对方关闭了链接,无法访问此网站</strong></li><li>有了上面的报错,我决定排查一下 <code>s2.loli.net</code> 的网络畅通情况,这里使用 <strong>ping</strong> 命令,却发现所返回来的 IP地址 是 <strong>127.0.0.1</strong></li></ul><p>有了以上几个简单排查,我基本确认了,问题可能出在 <strong>域名解析</strong> 上面;可能是我的路由器网络偶尔抽风了,导致 <code>s2.loli.net</code> 域名的解析出问题了,所以图片对应的URL就无法访问,自然图片也就无法加载出来了。</p><h2 id="解决"><a href="#解决" class="headerlink" title="解决"></a>解决</h2><p>有了上面的基础判断,基本思路就是想办法把 域名 s2.loli.net 解析到正确的IP上面。</p><p>这样就需要修改 <code>C:\Windows\System32\drivers\etc\hosts</code> 这个文件,而现在的关键点在于找到 <code>s2.loli.net</code> 这个域名解析的正确IP地址。</p><p>回到上一步的需求,如何找到 域名 s2.loli.net 对应的IP地址,这里推荐使用 Linux 下的 <strong>nslookup</strong> 命令:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$</span><span class="language-bash">nslookup s2.loli.net</span></span><br><span class="line">Server: 192.168.3.166</span><br><span class="line">Address: 192.168.3.166#53</span><br><span class="line"></span><br><span class="line">Non-authoritative answer:</span><br><span class="line">s2.loli.net canonical name = s2.loli.net.cdn.cloudflare.net.</span><br><span class="line">Name: s2.loli.net.cdn.cloudflare.net</span><br><span class="line">Address: 172.67.69.40</span><br><span class="line">Name: s2.loli.net.cdn.cloudflare.net</span><br><span class="line">Address: 104.26.0.190</span><br><span class="line">Name: s2.loli.net.cdn.cloudflare.net</span><br><span class="line">Address: 104.26.1.190</span><br><span class="line">Name: s2.loli.net.cdn.cloudflare.net</span><br><span class="line">Address: 2606:4700:20::681a:be</span><br><span class="line">Name: s2.loli.net.cdn.cloudflare.net</span><br><span class="line">Address: 2606:4700:20::681a:1be</span><br><span class="line">Name: s2.loli.net.cdn.cloudflare.net</span><br><span class="line">Address: 2606:4700:20::ac43:4528</span><br></pre></td></tr></table></figure><p>从上面的解析输出,我们可以知道,这个域名对应很多个IP地址,我们只需要选择一个就好了,比如 <strong>104.26.1.190</strong>。</p><p>然后在 <code>C:\Windows\System32\drivers\etc\hosts</code> 文件的尾部,按这样加上解析规则即可。这里需要注意的是修改此文件需要<strong>管理员权限</strong>。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># localhost name resolution is handled within DNS itself.</span><br><span class="line">#127.0.0.1 localhost</span><br><span class="line"># ::1 localhost</span><br><span class="line"></span><br><span class="line">104.26.1.190 s2.loli.net</span><br></pre></td></tr></table></figure><p>修改完了之后,可能不会马上就恢复,可以尝试把浏览器关闭,再打开,重新输入图片的地址,应该就可以解析到图片了。</p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>一般来说,遇到图片加载不出来,有两种情况:</p><ul><li>要么就是本地的网络问题:先确保本地网络畅通,再查浏览器图片的预览,从而判断是不是域名解析出了问题。</li><li>要么就是服务器端图床限制:比如禁止外链加载、防盗;或者图传服务挂了,又或者是自建的图床云服务欠费了等等之类的原因。</li></ul><p>但这里也有个问题,是否每次我都需要去修改hosts文件啊?改天如果网络的域名解析恢复正常了,那个hosts文件,我能恢复回去吗?</p>]]></content>
<categories>
<category> 技术教程 </category>
</categories>
<tags>
<tag> SM.MS </tag>
</tags>
</entry>
<entry>
<title>哔哩哔哩卡片标签外挂</title>
<link href="/posts/94703d10.html"/>
<url>/posts/94703d10.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>通过<strong>标签外挂</strong>为博客添加一个<strong>b站视频卡片样式</strong>。本篇文章原教程来自 <strong>Leonus</strong> 所发布的 <a href="https://blog.leonus.cn/2023/butterflyTag-1.html">哔哩哔哩卡片标签外挂</a></p> <a href="https://www.bilibili.com/video/BV1pS4y1t7Lz/" class="bilibili_box" id="BV1pS4y1t7Lz"></a> <script> bilibili() function bilibili() { let dom = document.getElementById('BV1pS4y1t7Lz') fetch('https://api.320.ink/api/b?id=BV1pS4y1t7Lz').then(res=>res.json()).then(data=>{ dom.innerHTML = ` <div class="bilibili_cover"> <img src="https://s1.hdslb.com/bfs/static/player/img/play.svg" class="play_icon nolazyload"> <img src="${data.pic + '&h=300'}" class="nolazyload"> <span>03:47</span> </div> <div class="bilibili_info"> <div class="title">${data.title}</div> <div class="stat"> <span><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none" class="icon"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.67735 4.2798C5.98983 4.1725 7.85812 4.0625 10 4.0625C12.1421 4.0625 14.0105 4.17252 15.323 4.27983C16.2216 4.3533 16.9184 5.04049 16.9989 5.9318C17.0962 7.00837 17.1875 8.43614 17.1875 10C17.1875 11.5639 17.0962 12.9916 16.9989 14.0682C16.9184 14.9595 16.2216 15.6467 15.323 15.7202C14.0105 15.8275 12.1421 15.9375 10 15.9375C7.85812 15.9375 5.98983 15.8275 4.67735 15.7202C3.77861 15.6467 3.08174 14.9593 3.00119 14.0678C2.90388 12.9908 2.8125 11.5627 2.8125 10C2.8125 8.43727 2.90388 7.00924 3.00119 5.93221C3.08174 5.04067 3.77861 4.35327 4.67735 4.2798ZM10 2.8125C7.81674 2.8125 5.9136 2.92456 4.5755 3.03395C3.07738 3.15643 1.8921 4.31616 1.75626 5.81973C1.65651 6.92379 1.5625 8.39058 1.5625 10C1.5625 11.6094 1.65651 13.0762 1.75626 14.1803C1.8921 15.6838 3.07738 16.8436 4.5755 16.966C5.9136 17.0754 7.81674 17.1875 10 17.1875C12.1835 17.1875 14.0868 17.0754 15.4249 16.966C16.9228 16.8436 18.108 15.6841 18.2438 14.1807C18.3435 13.077 18.4375 11.6105 18.4375 10C18.4375 8.38948 18.3435 6.92296 18.2438 5.81931C18.108 4.31588 16.9228 3.15645 15.4249 3.03398C14.0868 2.92458 12.1835 2.8125 10 2.8125ZM12.1876 10.722C12.7431 10.4013 12.7431 9.59941 12.1876 9.27866L9.06133 7.47373C8.50577 7.15298 7.81133 7.55392 7.81133 8.19542V11.8053C7.81133 12.4468 8.50577 12.8477 9.06133 12.527L12.1876 10.722Z" fill="#9499A0"/></svg>${data.view >= 10000 ? (data.view / 10000).toFixed(1) + "w" : data.view}</span> <span><svg width="36" height="36" viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg" class="icon"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.77234 30.8573V11.7471H7.54573C5.50932 11.7471 3.85742 13.3931 3.85742 15.425V27.1794C3.85742 29.2112 5.50932 30.8573 7.54573 30.8573H9.77234ZM11.9902 30.8573V11.7054C14.9897 10.627 16.6942 7.8853 17.1055 3.33591C17.2666 1.55463 18.9633 0.814421 20.5803 1.59505C22.1847 2.36964 23.243 4.32583 23.243 6.93947C23.243 8.50265 23.0478 10.1054 22.6582 11.7471H29.7324C31.7739 11.7471 33.4289 13.402 33.4289 15.4435C33.4289 15.7416 33.3928 16.0386 33.3215 16.328L30.9883 25.7957C30.2558 28.7683 27.5894 30.8573 24.528 30.8573H11.9911H11.9902Z"></path></svg>${data.like >= 10000 ? (data.like / 10000).toFixed(1) + "w" : data.view}</span> <span><svg width="28" height="28" viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg" class="icon" style="fill:;"><path fill-rule="evenodd" clip-rule="evenodd" d="M14.045 25.5454C7.69377 25.5454 2.54504 20.3967 2.54504 14.0454C2.54504 7.69413 7.69377 2.54541 14.045 2.54541C20.3963 2.54541 25.545 7.69413 25.545 14.0454C25.545 17.0954 24.3334 20.0205 22.1768 22.1771C20.0201 24.3338 17.095 25.5454 14.045 25.5454ZM9.66202 6.81624H18.2761C18.825 6.81624 19.27 7.22183 19.27 7.72216C19.27 8.22248 18.825 8.62807 18.2761 8.62807H14.95V10.2903C17.989 10.4444 20.3766 12.9487 20.3855 15.9916V17.1995C20.3854 17.6997 19.9799 18.1052 19.4796 18.1052C18.9793 18.1052 18.5738 17.6997 18.5737 17.1995V15.9916C18.5667 13.9478 16.9882 12.2535 14.95 12.1022V20.5574C14.95 21.0577 14.5444 21.4633 14.0441 21.4633C13.5437 21.4633 13.1382 21.0577 13.1382 20.5574V12.1022C11.1 12.2535 9.52148 13.9478 9.51448 15.9916V17.1995C9.5144 17.6997 9.10883 18.1052 8.60856 18.1052C8.1083 18.1052 7.70273 17.6997 7.70265 17.1995V15.9916C7.71158 12.9487 10.0992 10.4444 13.1382 10.2903V8.62807H9.66202C9.11309 8.62807 8.66809 8.22248 8.66809 7.72216C8.66809 7.22183 9.11309 6.81624 9.66202 6.81624Z"></path></svg>${data.coin >= 10000 ? (data.coin / 10000).toFixed(1) + "w" : data.coin}</span> </div> <div class="owner"> <span class="tip">视频</span> <img src="${data.face + '&h=100'}" class="nolazyload"> <span>${data.owner}</span> </div> </div> ` }) } </script> <h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>在 <strong>/themes/anzhiyu/scripts/tag</strong> 下新建 <strong>bilibili.js</strong> 文件并粘贴如下代码:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">"use strict"</span>;</span><br><span class="line"><span class="keyword">let</span> playIcon = <span class="string">`<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none" class="icon"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.67735 4.2798C5.98983 4.1725 7.85812 4.0625 10 4.0625C12.1421 4.0625 14.0105 4.17252 15.323 4.27983C16.2216 4.3533 16.9184 5.04049 16.9989 5.9318C17.0962 7.00837 17.1875 8.43614 17.1875 10C17.1875 11.5639 17.0962 12.9916 16.9989 14.0682C16.9184 14.9595 16.2216 15.6467 15.323 15.7202C14.0105 15.8275 12.1421 15.9375 10 15.9375C7.85812 15.9375 5.98983 15.8275 4.67735 15.7202C3.77861 15.6467 3.08174 14.9593 3.00119 14.0678C2.90388 12.9908 2.8125 11.5627 2.8125 10C2.8125 8.43727 2.90388 7.00924 3.00119 5.93221C3.08174 5.04067 3.77861 4.35327 4.67735 4.2798ZM10 2.8125C7.81674 2.8125 5.9136 2.92456 4.5755 3.03395C3.07738 3.15643 1.8921 4.31616 1.75626 5.81973C1.65651 6.92379 1.5625 8.39058 1.5625 10C1.5625 11.6094 1.65651 13.0762 1.75626 14.1803C1.8921 15.6838 3.07738 16.8436 4.5755 16.966C5.9136 17.0754 7.81674 17.1875 10 17.1875C12.1835 17.1875 14.0868 17.0754 15.4249 16.966C16.9228 16.8436 18.108 15.6841 18.2438 14.1807C18.3435 13.077 18.4375 11.6105 18.4375 10C18.4375 8.38948 18.3435 6.92296 18.2438 5.81931C18.108 4.31588 16.9228 3.15645 15.4249 3.03398C14.0868 2.92458 12.1835 2.8125 10 2.8125ZM12.1876 10.722C12.7431 10.4013 12.7431 9.59941 12.1876 9.27866L9.06133 7.47373C8.50577 7.15298 7.81133 7.55392 7.81133 8.19542V11.8053C7.81133 12.4468 8.50577 12.8477 9.06133 12.527L12.1876 10.722Z" fill="#9499A0"/></svg>`</span>;</span><br><span class="line"><span class="keyword">let</span> likeIcon = <span class="string">`<svg width="36" height="36" viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg" class="icon"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.77234 30.8573V11.7471H7.54573C5.50932 11.7471 3.85742 13.3931 3.85742 15.425V27.1794C3.85742 29.2112 5.50932 30.8573 7.54573 30.8573H9.77234ZM11.9902 30.8573V11.7054C14.9897 10.627 16.6942 7.8853 17.1055 3.33591C17.2666 1.55463 18.9633 0.814421 20.5803 1.59505C22.1847 2.36964 23.243 4.32583 23.243 6.93947C23.243 8.50265 23.0478 10.1054 22.6582 11.7471H29.7324C31.7739 11.7471 33.4289 13.402 33.4289 15.4435C33.4289 15.7416 33.3928 16.0386 33.3215 16.328L30.9883 25.7957C30.2558 28.7683 27.5894 30.8573 24.528 30.8573H11.9911H11.9902Z"></path></svg>`</span>;</span><br><span class="line"><span class="keyword">let</span> coinIcon = <span class="string">`<svg width="28" height="28" viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg" class="icon" style="fill:;"><path fill-rule="evenodd" clip-rule="evenodd" d="M14.045 25.5454C7.69377 25.5454 2.54504 20.3967 2.54504 14.0454C2.54504 7.69413 7.69377 2.54541 14.045 2.54541C20.3963 2.54541 25.545 7.69413 25.545 14.0454C25.545 17.0954 24.3334 20.0205 22.1768 22.1771C20.0201 24.3338 17.095 25.5454 14.045 25.5454ZM9.66202 6.81624H18.2761C18.825 6.81624 19.27 7.22183 19.27 7.72216C19.27 8.22248 18.825 8.62807 18.2761 8.62807H14.95V10.2903C17.989 10.4444 20.3766 12.9487 20.3855 15.9916V17.1995C20.3854 17.6997 19.9799 18.1052 19.4796 18.1052C18.9793 18.1052 18.5738 17.6997 18.5737 17.1995V15.9916C18.5667 13.9478 16.9882 12.2535 14.95 12.1022V20.5574C14.95 21.0577 14.5444 21.4633 14.0441 21.4633C13.5437 21.4633 13.1382 21.0577 13.1382 20.5574V12.1022C11.1 12.2535 9.52148 13.9478 9.51448 15.9916V17.1995C9.5144 17.6997 9.10883 18.1052 8.60856 18.1052C8.1083 18.1052 7.70273 17.6997 7.70265 17.1995V15.9916C7.71158 12.9487 10.0992 10.4444 13.1382 10.2903V8.62807H9.66202C9.11309 8.62807 8.66809 8.22248 8.66809 7.72216C8.66809 7.22183 9.11309 6.81624 9.66202 6.81624Z"></path></svg>`</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">bilibili</span>(<span class="params">args</span>) {</span><br><span class="line"> <span class="keyword">const</span> id = args[<span class="number">0</span>].<span class="title function_">replace</span>(<span class="regexp">/.*video\/(.*)\/?.*/</span>, <span class="string">"$1"</span>);</span><br><span class="line"> <span class="keyword">const</span> time = args[<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">const</span> hidden_desc = args[<span class="number">2</span>];</span><br><span class="line"> <span class="keyword">const</span> <span class="variable constant_">API</span> = hexo.<span class="property">bilibiliApi</span> ? hexo.<span class="property">bilibiliApi</span> : <span class="string">"https://api.320.ink/api/b"</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="string">`</span></span><br><span class="line"><span class="string"> <a href="https://www.bilibili.com/video/<span class="subst">${id}</span>/" class="bilibili_box" id="<span class="subst">${id}</span>"></a></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> <script></span></span><br><span class="line"><span class="string"> bilibili()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> function bilibili() {</span></span><br><span class="line"><span class="string"> let dom = document.getElementById('<span class="subst">${id}</span>')</span></span><br><span class="line"><span class="string"> fetch('<span class="subst">${API}</span>?id=<span class="subst">${id}</span>').then(res=>res.json()).then(data=>{</span></span><br><span class="line"><span class="string"> dom.innerHTML = \`</span></span><br><span class="line"><span class="string"> <div class="bilibili_cover"></span></span><br><span class="line"><span class="string"> <img src="https://s1.hdslb.com/bfs/static/player/img/play.svg" class="play_icon nolazyload"></span></span><br><span class="line"><span class="string"> <img src="\${data.pic + '&h=300'}" class="nolazyload"></span></span><br><span class="line"><span class="string"> <span class="subst">${time ? <span class="string">`<span><span class="subst">${time}</span></span>`</span> : <span class="string">""</span>}</span></span></span><br><span class="line"><span class="string"> </div></span></span><br><span class="line"><span class="string"> <div class="bilibili_info"></span></span><br><span class="line"><span class="string"> <div class="title">\${data.title}</div></span></span><br><span class="line"><span class="string"> <span class="subst">${hidden_desc == <span class="string">"true"</span> ? <span class="string">""</span> : <span class="string">'<div class="desc">${data.desc}</div>'</span>}</span></span></span><br><span class="line"><span class="string"> <div class="stat"></span></span><br><span class="line"><span class="string"> <span><span class="subst">${playIcon}</span>\${data.view >= 10000 ? (data.view / 10000).toFixed(1) + "w" : data.view}</span></span></span><br><span class="line"><span class="string"> <span><span class="subst">${likeIcon}</span>\${data.like >= 10000 ? (data.like / 10000).toFixed(1) + "w" : data.view}</span></span></span><br><span class="line"><span class="string"> <span><span class="subst">${coinIcon}</span>\${data.coin >= 10000 ? (data.coin / 10000).toFixed(1) + "w" : data.coin}</span></span></span><br><span class="line"><span class="string"> </div></span></span><br><span class="line"><span class="string"> <div class="owner"></span></span><br><span class="line"><span class="string"> <span class="tip">视频</span></span></span><br><span class="line"><span class="string"> <img src="\${data.face + '&h=100'}" class="nolazyload"></span></span><br><span class="line"><span class="string"> <span>\${data.owner}</span></span></span><br><span class="line"><span class="string"> </div></span></span><br><span class="line"><span class="string"> </div></span></span><br><span class="line"><span class="string"> \`</span></span><br><span class="line"><span class="string"> })</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> </script></span></span><br><span class="line"><span class="string"> `</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">tag</span>.<span class="title function_">register</span>(<span class="string">"bilibili"</span>, bilibili, { <span class="attr">ends</span>: <span class="literal">false</span> });</span><br><span class="line"></span><br></pre></td></tr></table></figure><p>在 <strong>/themes/anzhiyu/source/css/_tags</strong> 下新建 <strong>bilbili.styl</strong> 文件并粘贴如下代码:</p><figure class="highlight styl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.bilibili_box</span></span><br><span class="line"> <span class="attribute">display</span>: flex</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">var</span>(--card-bg)</span><br><span class="line"> <span class="attribute">border</span>: <span class="built_in">var</span>(--style-border)</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">12px</span> <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">overflow</span>: hidden</span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">var</span>(--font-color) <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">text-decoration</span>: none <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">transition</span>: .<span class="number">3s</span></span><br><span class="line"> <span class="attribute">border-bottom</span>: <span class="built_in">var</span>(--style-border) <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">0</span> <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">height</span> <span class="number">143px</span></span><br><span class="line"> <span class="selector-pseudo">&:hover</span></span><br><span class="line"> <span class="attribute">border-color</span>: <span class="built_in">var</span>(--anzhiyu-main) <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">var</span>(--anzhiyu-white) <span class="meta">!important</span></span><br><span class="line"> <span class="selector-class">.bilibili_info</span> <span class="selector-class">.stat</span> svg path</span><br><span class="line"> fill: <span class="selector-tag">var</span>(<span class="attr">--anzhiyu-white</span>) !important</span><br><span class="line"> +<span class="built_in">maxWidth768</span>()</span><br><span class="line"> <span class="attribute">flex-direction</span>: column</span><br><span class="line"> <span class="selector-class">.bilibili_cover</span></span><br><span class="line"> <span class="attribute">width</span>: <span class="number">234px</span></span><br><span class="line"> <span class="attribute">position</span> relative</span><br><span class="line"> +<span class="built_in">maxWidth768</span>()</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span></span><br><span class="line"> <span class="selector-tag">img</span></span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span></span><br><span class="line"> <span class="attribute">filter</span>: none</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">0</span> <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">0</span> <span class="meta">!important</span></span><br><span class="line"> <span class="selector-class">.play_icon</span></span><br><span class="line"> <span class="attribute">position</span>: absolute</span><br><span class="line"> <span class="attribute">width</span> <span class="number">45px</span></span><br><span class="line"> <span class="attribute">height</span> <span class="number">45px</span></span><br><span class="line"> <span class="attribute">opacity</span> .<span class="number">8</span></span><br><span class="line"> <span class="attribute">top</span>: <span class="number">50%</span></span><br><span class="line"> <span class="attribute">left</span> <span class="number">50%</span></span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">translate</span>(-<span class="number">50%</span>,-<span class="number">50%</span>)</span><br><span class="line"> <span class="selector-tag">span</span> </span><br><span class="line"> <span class="attribute">position</span>: absolute</span><br><span class="line"> <span class="attribute">bottom</span>: <span class="number">0px</span></span><br><span class="line"> <span class="attribute">right</span>: <span class="number">5px</span></span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">var</span>(--anzhiyu-white)</span><br><span class="line"> <span class="selector-class">.bilibili_info</span></span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">10px</span> <span class="number">10px</span> <span class="number">10px</span> <span class="number">18px</span></span><br><span class="line"> <span class="attribute">line-height</span>: <span class="number">1</span></span><br><span class="line"> <span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="number">200px</span>)</span><br><span class="line"> <span class="attribute">display</span>: flex</span><br><span class="line"> <span class="attribute">flex-direction</span>: column</span><br><span class="line"> <span class="attribute">justify-content</span>: space-around</span><br><span class="line"> +<span class="built_in">maxWidth768</span>()</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span></span><br><span class="line"> <span class="attribute">padding-bottom</span>: <span class="number">25px</span></span><br><span class="line"> <span class="attribute">line-height</span>: <span class="number">1.5</span></span><br><span class="line"> <span class="selector-class">.title</span> </span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">1.2rem</span></span><br><span class="line"> <span class="attribute">font-weight</span>: bold</span><br><span class="line"> <span class="attribute">white-space</span>: nowrap</span><br><span class="line"> <span class="attribute">overflow</span>: hidden</span><br><span class="line"> <span class="attribute">text-overflow</span>: ellipsis</span><br><span class="line"> <span class="attribute">line-height</span>: <span class="number">1.5</span></span><br><span class="line"> <span class="selector-class">.desc</span> </span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">15px</span></span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">2px</span> <span class="number">0</span> <span class="number">4px</span></span><br><span class="line"> <span class="attribute">white-space</span>: nowrap</span><br><span class="line"> <span class="attribute">overflow</span>: hidden</span><br><span class="line"> <span class="attribute">text-overflow</span>: ellipsis</span><br><span class="line"> +<span class="built_in">maxWidth768</span>()</span><br><span class="line"> <span class="attribute">white-space</span>: normal</span><br><span class="line"> <span class="attribute">display</span>:-webkit-box;</span><br><span class="line"> -webkit-box-orient:vertical;</span><br><span class="line"> -webkit-line-clamp:<span class="number">2</span>; </span><br><span class="line"> <span class="selector-class">.stat</span> </span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">15px</span></span><br><span class="line"> svg</span><br><span class="line"> <span class="attribute">margin-right</span>: <span class="number">3px</span></span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">18px</span></span><br><span class="line"> <span class="attribute">width</span>: <span class="number">1em</span></span><br><span class="line"> <span class="attribute">height</span>: <span class="number">1em</span></span><br><span class="line"> path</span><br><span class="line"> fill: <span class="selector-tag">var</span>(<span class="attr">--font-color</span>)</span><br><span class="line"> <span class="selector-tag">span</span></span><br><span class="line"> <span class="attribute">margin-right</span>: <span class="number">10px</span></span><br><span class="line"> <span class="attribute">display</span>: inline-flex</span><br><span class="line"> <span class="attribute">align-items</span>: center</span><br><span class="line"> <span class="selector-class">.owner</span> </span><br><span class="line"> <span class="attribute">display</span>: flex</span><br><span class="line"> <span class="attribute">align-items</span>: center</span><br><span class="line"> <span class="attribute">line-height</span>: <span class="number">1</span></span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">15px</span></span><br><span class="line"> <span class="selector-class">.tip</span></span><br><span class="line"> <span class="attribute">color</span>: <span class="number">#f69</span></span><br><span class="line"> <span class="attribute">border</span>: <span class="number">1px</span> solid</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">3px</span> <span class="number">6px</span></span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">12px</span></span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">5px</span></span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">0</span> <span class="number">10px</span> <span class="number">0</span> <span class="number">0</span></span><br><span class="line"> <span class="attribute">background</span>: none;</span><br><span class="line"> <span class="attribute">box-shadow</span>: none;</span><br><span class="line"> <span class="selector-tag">img</span></span><br><span class="line"> <span class="attribute">width</span> <span class="number">22px</span></span><br><span class="line"> <span class="attribute">height</span>: <span class="number">22px</span></span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">50%</span> <span class="meta">!important</span></span><br><span class="line"> <span class="attribute">object-fit</span>: cover</span><br><span class="line"> <span class="attribute">margin</span> <span class="number">0</span> <span class="number">5px</span> <span class="number">0</span> <span class="number">0</span> <span class="meta">!important</span></span><br><span class="line"></span><br><span class="line"><span class="selector-attr">[data-theme=<span class="string">'light'</span>]</span> <span class="selector-class">.bilibili_box</span> <span class="selector-class">.bilibili_info</span> <span class="selector-class">.stat</span> svg,</span><br><span class="line"><span class="selector-attr">[data-theme=<span class="string">'dark'</span>]</span> <span class="selector-class">.bilibili_cover</span></span><br><span class="line"> <span class="attribute">opacity</span> .<span class="number">8</span></span><br></pre></td></tr></table></figure><h2 id="使用格式"><a href="#使用格式" class="headerlink" title="使用格式"></a>使用格式</h2><p>使用此标签外挂只需要填写视频链接,填写后将会自动获取信息,由于视频时长不容易通过 api 获取所以设置成了手动填写</p><blockquote><p>如果是手机的话:进入视频之后点击分享,复制链接然后用浏览器打开再复制链接,不要使用短链接</p></blockquote><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">{% bilibili 视频链接 [视频时长 隐藏简介] %}</span><br></pre></td></tr></table></figure><p>示例:</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">{% bilibili https://www.bilibili.com/video/BV1eh411G7bK 00:29 %}</span><br><span class="line"><!-- 如果你要隐藏简介,添加true即可(注意,要隐藏简介则必须设置适配时间!),如下 --></span><br><span class="line">{% bilibili https://www.bilibili.com/video/BV1eh411G7bK 00:29 true %}</span><br></pre></td></tr></table></figure><h2 id="结尾"><a href="#结尾" class="headerlink" title="结尾"></a>结尾</h2><p>在安知鱼主题<strong>1.6.8</strong>已经适配哔哩哔哩标签外挂了,但是当前存在一些问题:</p><ul><li><p>由于懒加载问题,导致获取的图片不能第一时间就显示出来<br>在 <strong>/themes/anzhiyu/scripts/filters/post_lazyload.js</strong> 中进行如下修改:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title function_">lazyload</span> = htmlContent => {</span><br><span class="line"> <span class="keyword">const</span> error_img = hexo.<span class="property">theme</span>.<span class="property">config</span>.<span class="property">error_img</span>.<span class="property">post_page</span></span><br><span class="line"> <span class="keyword">const</span> bg = hexo.<span class="property">theme</span>.<span class="property">config</span>.<span class="property">lazyload</span>.<span class="property">placeholder</span></span><br><span class="line"> ? <span class="title function_">urlFor</span>(hexo.<span class="property">theme</span>.<span class="property">config</span>.<span class="property">lazyload</span>.<span class="property">placeholder</span>)</span><br><span class="line"> : <span class="string">"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"</span>;</span><br><span class="line"> <span class="keyword">return</span> htmlContent.<span class="title function_">replace</span>(</span><br><span class="line"> <span class="regexp">/(<img(?!.*?class[\t]*=[\t]*['"].*?nolazyload.*?['"]).*? src=)/gi</span>,</span><br><span class="line"> <span class="string">`$1 "<span class="subst">${bg}</span>" data-lazy-src=`</span></span><br><span class="line"> );</span><br><span class="line"> <span class="comment">// 原主题</span></span><br><span class="line"> <span class="comment">// return htmlContent.replace(</span></span><br><span class="line"> <span class="comment">// /(<img(?!.class[\t]*=[\t]*['"].*?nolazyload.*?['"]).*? src=)/gi,</span></span><br><span class="line"> <span class="comment">// `$1 "${bg}" onerror="this.onerror=null,this.src=&quot;${error_img}&quot;" data-lazy-src=`</span></span><br><span class="line"> <span class="comment">// );</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>样式没有适配<br>将如下代码粘贴进你的任意一个css文件中即可</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 白天鼠标触碰时背景颜色 */</span></span><br><span class="line"><span class="selector-attr">[data-theme=light]</span> <span class="selector-class">.bilibili_box</span><span class="selector-pseudo">:hover</span> {</span><br><span class="line"> <span class="attribute">background</span>: none <span class="meta">!important</span>;</span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">var</span>(--anzhiyu-fontcolor) <span class="meta">!important</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 白天播放量、点赞数等图标颜色 */</span></span><br><span class="line"><span class="selector-attr">[data-theme=light]</span> <span class="selector-class">.bilibili_box</span> <span class="selector-class">.bilibili_info</span> <span class="selector-class">.stat</span> svg path {</span><br><span class="line"> fill: <span class="built_in">rgba</span>(<span class="number">54</span>, <span class="number">54</span>, <span class="number">54</span>, <span class="number">1</span>) <span class="meta">!important</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 夜间鼠标触碰时背景颜色 */</span></span><br><span class="line"><span class="selector-attr">[data-theme=dark]</span> <span class="selector-class">.bilibili_box</span><span class="selector-pseudo">:hover</span> {</span><br><span class="line"> <span class="attribute">background</span>: none <span class="meta">!important</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>首页背景图渐进式加载</title>
<link href="/posts/29ff7730.html"/>
<url>/posts/29ff7730.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>看了 铭心石刻 的 <a href="https://blog.kouseki.cn/posts/4f72.html">首页背景图渐进式加载,解决卡顿难题</a> 这篇文章开启了博客首页图片,还是挺不错的<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/imageload/Snipaste_2023-10-25_13-05-21.webp"></p><h2 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h2><p>以本站使用的主题 <code>anzhiyu</code> 为例(butterfly通用),为首页顶部图配置渐进式加载。这个方法应该也同样适用于一图流的博客背景,有需要的朋友可以自己研究一下~</p><p>新建文件 <code>source/js/imgloaded.js</code> 新增以下内容,并按照注释调整图片路径</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 实现medium的渐进加载背景的效果</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">ProgressiveLoad</span> {</span><br><span class="line"> <span class="title function_">constructor</span>(<span class="params">smallSrc, largeSrc</span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallSrc</span> = smallSrc;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeSrc</span> = largeSrc;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="title function_">initTpl</span>();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 生成ui模板</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">initTpl</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">video</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallImg</span> = <span class="keyword">new</span> <span class="title class_">Image</span>();</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeImg</span> = <span class="keyword">new</span> <span class="title class_">Image</span>();</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="property">className</span> = <span class="string">'pl-container'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span>.<span class="property">className</span> = <span class="string">'pl-img pl-blur'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span>.<span class="property">className</span> = <span class="string">'pl-img'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">video</span>.<span class="property">className</span> = <span class="string">'pl-video'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="title function_">appendChild</span>(<span class="variable language_">this</span>.<span class="property">smallStage</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="title function_">appendChild</span>(<span class="variable language_">this</span>.<span class="property">largeStage</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="title function_">appendChild</span>(<span class="variable language_">this</span>.<span class="property">video</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallImg</span>.<span class="property">onload</span> = <span class="variable language_">this</span>.<span class="property">_onSmallLoaded</span>.<span class="title function_">bind</span>(<span class="variable language_">this</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeImg</span>.<span class="property">onload</span> = <span class="variable language_">this</span>.<span class="property">_onLargeLoaded</span>.<span class="title function_">bind</span>(<span class="variable language_">this</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 加载背景</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">progressiveLoad</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallImg</span>.<span class="property">src</span> = <span class="variable language_">this</span>.<span class="property">smallSrc</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeImg</span>.<span class="property">src</span> = <span class="variable language_">this</span>.<span class="property">largeSrc</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 大图加载完成</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">_onLargeLoaded</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span>.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'pl-visible'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span>.<span class="property">style</span>.<span class="property">backgroundImage</span> = <span class="string">`url('<span class="subst">${<span class="variable language_">this</span>.largeSrc}</span>')`</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 小图加载完成</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">_onSmallLoaded</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span>.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'pl-visible'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span>.<span class="property">style</span>.<span class="property">backgroundImage</span> = <span class="string">`url('<span class="subst">${<span class="variable language_">this</span>.smallSrc}</span>')`</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="title function_">executeLoad</span> = (<span class="params">config, target</span>) => {</span><br><span class="line"> <span class="keyword">const</span> isMobile = <span class="variable language_">window</span>.<span class="title function_">matchMedia</span>(<span class="string">'(max-width: 767px)'</span>).<span class="property">matches</span>;</span><br><span class="line"> <span class="keyword">const</span> loader = <span class="keyword">new</span> <span class="title class_">ProgressiveLoad</span>(</span><br><span class="line"> isMobile ? config.<span class="property">mobileSmallSrc</span> : config.<span class="property">smallSrc</span>,</span><br><span class="line"> isMobile ? config.<span class="property">mobileLargeSrc</span> : config.<span class="property">largeSrc</span></span><br><span class="line"> );</span><br><span class="line"> <span class="comment">// 和背景图颜色保持一致,防止高斯模糊后差异较大</span></span><br><span class="line"> <span class="keyword">if</span> (target.<span class="property">children</span>[<span class="number">0</span>]) {</span><br><span class="line"> target.<span class="title function_">insertBefore</span>(loader.<span class="property">container</span>, target.<span class="property">children</span>[<span class="number">0</span>]);</span><br><span class="line"> }</span><br><span class="line"> loader.<span class="title function_">progressiveLoad</span>();</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> config = {</span><br><span class="line"> <span class="attr">smallSrc</span>: <span class="string">'https://t.mwm.moe/pc'</span>, <span class="comment">// 小图链接 尽可能配置小于100k的图片</span></span><br><span class="line"> <span class="attr">largeSrc</span>: <span class="string">'https://t.mwm.moe/pc'</span>, <span class="comment">// 大图链接 最终显示的图片</span></span><br><span class="line"> <span class="attr">mobileSmallSrc</span>: <span class="string">'https://t.mwm.moe/mp'</span>, <span class="comment">// 手机端小图链接 尽可能配置小于100k的图片</span></span><br><span class="line"> <span class="attr">mobileLargeSrc</span>: <span class="string">'https://t.mwm.moe/mp'</span>, <span class="comment">// 手机端大图链接 最终显示的图片</span></span><br><span class="line"> <span class="attr">enableRoutes</span>: [<span class="string">'/'</span>],</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">initProgressiveLoad</span>(<span class="params">config</span>) {</span><br><span class="line"> <span class="keyword">const</span> target = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'page-header'</span>);</span><br><span class="line"> <span class="keyword">if</span> (target && target.<span class="property">classList</span>.<span class="title function_">contains</span>(<span class="string">'full_page'</span>)) {</span><br><span class="line"> <span class="title function_">executeLoad</span>(config, target);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">onPJAXComplete</span>(<span class="params">config</span>) {</span><br><span class="line"> <span class="keyword">const</span> target = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'page-header'</span>);</span><br><span class="line"> <span class="keyword">if</span> (target && target.<span class="property">classList</span>.<span class="title function_">contains</span>(<span class="string">'full_page'</span>)) {</span><br><span class="line"> <span class="title function_">initProgressiveLoad</span>(config);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"DOMContentLoaded"</span>, <span class="keyword">function</span> (<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">initProgressiveLoad</span>(config);</span><br><span class="line">});</span><br><span class="line"></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"pjax:complete"</span>, <span class="keyword">function</span> (<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">onPJAXComplete</span>(config);</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><p>在 <strong>imgloaded.js</strong> 中第 <strong>70行至73行</strong> 处,配置自己的图片,可以是图片直链也可以是本地路径。这里可以获取 <a href="https://blog.jixiaob.cn/?post=93">随机二次元背景图</a> 。需要注意的是,在本地部署可能首页背景图不能显示,远程部署就可以解决了</p><p>新建文件 <code>source/css/imgloaded.css</code> 新增以下内容,并按照注释自行决定调整内容</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 首页头图加载 */</span></span><br><span class="line"><span class="selector-class">.pl-container</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">position</span>: relative;</span><br><span class="line"> <span class="attribute">overflow</span>: hidden;</span><br><span class="line"> <span class="attribute">will-change</span>: transform;</span><br><span class="line"> <span class="comment">/* 添加性能优化 */</span></span><br><span class="line"> <span class="attribute">animation</span>: blur-to-clear <span class="number">2s</span> <span class="built_in">cubic-bezier</span>(.<span class="number">62</span>, .<span class="number">21</span>, .<span class="number">25</span>, <span class="number">1</span>) <span class="number">0s</span> <span class="number">1</span> normal backwards running, scale <span class="number">1.5s</span> <span class="built_in">cubic-bezier</span>(.<span class="number">62</span>, .<span class="number">21</span>, .<span class="number">25</span>, <span class="number">1</span>) <span class="number">0s</span> <span class="number">1</span> both;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-img</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">background-position</span>: center;</span><br><span class="line"> <span class="attribute">background-size</span>: cover;</span><br><span class="line"> <span class="attribute">background-repeat</span>: no-repeat;</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">transition</span>: opacity <span class="number">1s</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@keyframes</span> blur-to-clear {</span><br><span class="line"> <span class="number">0%</span> {</span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">50px</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="number">100%</span> {</span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@keyframes</span> scale {</span><br><span class="line"> <span class="number">0%</span> {</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">scale</span>(<span class="number">1.5</span>) <span class="built_in">translateZ</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="selector-tag">to</span> {</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">scale</span>(<span class="number">1</span>) <span class="built_in">translateZ</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-visible</span> {</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-blur</span> {</span><br><span class="line"> <span class="comment">/* 小图锯齿多,增加高斯模糊 */</span></span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">50px</span>);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>在 <strong>_config.anzhiyu.yml</strong> 主题配置文件下引入文件</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">inject:</span></span><br><span class="line"> <span class="attr">head:</span></span><br><span class="line"> <span class="comment"># 首页图片</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><link</span> <span class="string">rel="stylesheet"</span> <span class="string">href="/css/imgloaded.css?1"></span></span><br><span class="line"></span><br><span class="line"> <span class="attr">bottom:</span></span><br><span class="line"> <span class="comment"># 首页图片</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><script</span> <span class="string">async</span> <span class="string">data-pjax</span> <span class="string">src="/js/imgloaded.js?1"></script></span></span><br></pre></td></tr></table></figure><p>务必记得在主题配置文件中开启顶部图的功能,也可以像我这样配置空链接。因为js文件已经接替了图片加载功能,此处不需要配置图片(当然你也可以配置上)</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># The banner image of home page</span></span><br><span class="line"><span class="attr">index_img:</span> <span class="string">"background: url() top / cover no-repeat"</span></span><br></pre></td></tr></table></figure><h2 id="后续"><a href="#后续" class="headerlink" title="后续"></a>后续</h2><p>在2023年9月29日,通过<a href="https://satera.cn/posts/6a8fb549/">Kouseki式首页背景图渐进式加载 · 改</a>将首页背景图重新优化</p><ul><li><p>将如下代码粘贴至 imgloaded.js 文件中</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 首页头图加载优化</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 实现medium的渐进加载背景的效果</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (!<span class="variable language_">window</span>.<span class="property">ProgressiveLoad</span>) {</span><br><span class="line"> <span class="comment">// 定义ProgressiveLoad类</span></span><br><span class="line"> <span class="keyword">class</span> <span class="title class_">ProgressiveLoad</span> {</span><br><span class="line"> <span class="title function_">constructor</span>(<span class="params">smallSrc, largeSrc</span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallSrc</span> = smallSrc;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeSrc</span> = largeSrc;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="title function_">initScrollListener</span>(),</span><br><span class="line"> <span class="variable language_">this</span>.<span class="title function_">initTpl</span>();</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// 这里的1是滚动全程渐变 改为0.3就是前30%渐变后固定前30%产生的渐变效果</span></span><br><span class="line"> <span class="title function_">initScrollListener</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">"scroll"</span>, (<span class="function">()=></span>{</span><br><span class="line"> <span class="keyword">var</span> e = <span class="title class_">Math</span>.<span class="title function_">min</span>(<span class="variable language_">window</span>.<span class="property">scrollY</span> / <span class="variable language_">window</span>.<span class="property">innerHeight</span>, <span class="number">1</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="property">style</span>.<span class="title function_">setProperty</span>(<span class="string">"--process"</span>, e)</span><br><span class="line"> }</span><br><span class="line"> ))</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 生成ui模板</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">initTpl</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">video</span> = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">'div'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallImg</span> = <span class="keyword">new</span> <span class="title class_">Image</span>();</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeImg</span> = <span class="keyword">new</span> <span class="title class_">Image</span>();</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="property">className</span> = <span class="string">'pl-container'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="property">style</span>.<span class="title function_">setProperty</span>(<span class="string">"--process"</span>, <span class="number">0</span>),</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span>.<span class="property">className</span> = <span class="string">'pl-img pl-blur'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span>.<span class="property">className</span> = <span class="string">'pl-img'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">video</span>.<span class="property">className</span> = <span class="string">'pl-video'</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="title function_">appendChild</span>(<span class="variable language_">this</span>.<span class="property">smallStage</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="title function_">appendChild</span>(<span class="variable language_">this</span>.<span class="property">largeStage</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">container</span>.<span class="title function_">appendChild</span>(<span class="variable language_">this</span>.<span class="property">video</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallImg</span>.<span class="property">onload</span> = <span class="variable language_">this</span>.<span class="property">_onSmallLoaded</span>.<span class="title function_">bind</span>(<span class="variable language_">this</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeImg</span>.<span class="property">onload</span> = <span class="variable language_">this</span>.<span class="property">_onLargeLoaded</span>.<span class="title function_">bind</span>(<span class="variable language_">this</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 加载背景</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">progressiveLoad</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallImg</span>.<span class="property">src</span> = <span class="variable language_">this</span>.<span class="property">smallSrc</span>;</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeImg</span>.<span class="property">src</span> = <span class="variable language_">this</span>.<span class="property">largeSrc</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 大图加载完成</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">_onLargeLoaded</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span>.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'pl-visible'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">largeStage</span>.<span class="property">style</span>.<span class="property">backgroundImage</span> = <span class="string">`url('<span class="subst">${<span class="variable language_">this</span>.largeSrc}</span>')`</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span> 小图加载完成</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="title function_">_onSmallLoaded</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span>.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">'pl-visible'</span>);</span><br><span class="line"> <span class="variable language_">this</span>.<span class="property">smallStage</span>.<span class="property">style</span>.<span class="property">backgroundImage</span> = <span class="string">`url('<span class="subst">${<span class="variable language_">this</span>.smallSrc}</span>')`</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">const</span> <span class="title function_">executeLoad</span> = (<span class="params">config, target</span>) => {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">'执行渐进背景替换'</span>);</span><br><span class="line"> <span class="keyword">const</span> isMobile = <span class="variable language_">window</span>.<span class="title function_">matchMedia</span>(<span class="string">'(max-width: 767px)'</span>).<span class="property">matches</span>;</span><br><span class="line"> <span class="keyword">const</span> loader = <span class="keyword">new</span> <span class="title class_">ProgressiveLoad</span>(</span><br><span class="line"> isMobile ? config.<span class="property">mobileSmallSrc</span> : config.<span class="property">smallSrc</span>,</span><br><span class="line"> isMobile ? config.<span class="property">mobileLargeSrc</span> : config.<span class="property">largeSrc</span></span><br><span class="line"> );</span><br><span class="line"> <span class="comment">// 和背景图颜色保持一致,防止高斯模糊后差异较大</span></span><br><span class="line"> <span class="keyword">if</span> (target.<span class="property">children</span>[<span class="number">0</span>]) {</span><br><span class="line"> target.<span class="title function_">insertBefore</span>(loader.<span class="property">container</span>, target.<span class="property">children</span>[<span class="number">0</span>]);</span><br><span class="line"> }</span><br><span class="line"> loader.<span class="title function_">progressiveLoad</span>();</span><br><span class="line"> };</span><br><span class="line"></span><br><span class="line"> <span class="keyword">const</span> config = {</span><br><span class="line"> <span class="attr">smallSrc</span>: <span class="string">'https://www.loliapi.com/acg/'</span>, <span class="comment">// 小图链接 尽可能配置小于100k的图片</span></span><br><span class="line"> <span class="attr">largeSrc</span>: <span class="string">'https://www.loliapi.com/acg/'</span>, <span class="comment">// 大图链接 最终显示的图片</span></span><br><span class="line"> <span class="attr">mobileSmallSrc</span>: <span class="string">'https://www.loliapi.com/acg/'</span>, <span class="comment">// 手机端小图链接 尽可能配置小于100k的图片</span></span><br><span class="line"> <span class="attr">mobileLargeSrc</span>: <span class="string">'https://www.loliapi.com/acg/'</span>, <span class="comment">// 手机端大图链接 最终显示的图片</span></span><br><span class="line"> <span class="attr">enableRoutes</span>: [<span class="string">'/'</span>],</span><br><span class="line"> };</span><br><span class="line"></span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">initProgressiveLoad</span>(<span class="params">config</span>) {</span><br><span class="line"> <span class="comment">// 每次加载前先清除已有的元素</span></span><br><span class="line"> <span class="keyword">const</span> container = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">'.pl-container'</span>); </span><br><span class="line"> <span class="keyword">if</span> (container) {</span><br><span class="line"> container.<span class="title function_">remove</span>(); </span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">const</span> target = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'page-header'</span>);</span><br><span class="line"> <span class="keyword">if</span> (target && target.<span class="property">classList</span>.<span class="title function_">contains</span>(<span class="string">'full_page'</span>)) {</span><br><span class="line"> <span class="title function_">executeLoad</span>(config, target);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">onPJAXComplete</span>(<span class="params">config</span>) {</span><br><span class="line"> <span class="keyword">const</span> target = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'page-header'</span>);</span><br><span class="line"> <span class="keyword">if</span> (target && target.<span class="property">classList</span>.<span class="title function_">contains</span>(<span class="string">'full_page'</span>)) {</span><br><span class="line"> <span class="title function_">initProgressiveLoad</span>(config);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"DOMContentLoaded"</span>, <span class="keyword">function</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">initProgressiveLoad</span>(config);</span><br><span class="line"> });</span><br><span class="line"></span><br><span class="line"> <span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"pjax:complete"</span>, <span class="keyword">function</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">onPJAXComplete</span>(config);</span><br><span class="line"> });</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>将如下代码粘贴至 imgloaded.css 文件中</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 首页头图加载 */</span></span><br><span class="line"><span class="selector-tag">body</span><span class="selector-attr">[data-type=anzhiyu]</span> <span class="selector-id">#nav</span>,</span><br><span class="line"><span class="selector-tag">body</span><span class="selector-attr">[data-type=anzhiyu]</span> <span class="selector-id">#scroll-down</span>,</span><br><span class="line"><span class="selector-tag">body</span><span class="selector-attr">[data-type=anzhiyu]</span> <span class="selector-id">#site-info</span> {</span><br><span class="line"> -webkit-<span class="attribute">animation</span>: scale <span class="number">2.2s</span> <span class="built_in">cubic-bezier</span>(.<span class="number">6</span>, .<span class="number">1</span>, .<span class="number">25</span>, <span class="number">1</span>) .<span class="number">5s</span> <span class="number">1</span> backwards;</span><br><span class="line"> <span class="attribute">animation</span>: scale <span class="number">2.2s</span> <span class="built_in">cubic-bezier</span>(.<span class="number">6</span>, .<span class="number">1</span>, .<span class="number">25</span>, <span class="number">1</span>) .<span class="number">5s</span> <span class="number">1</span> backwards</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">max-width</span>: <span class="number">768px</span>) {</span><br><span class="line"> <span class="selector-class">.pl-container</span> {</span><br><span class="line"> <span class="attribute">position</span>: relative <span class="meta">!important</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">min-width</span>: <span class="number">768px</span>) {</span><br><span class="line"></span><br><span class="line"> <span class="selector-id">#page-header</span><span class="selector-class">.full_page</span>,</span><br><span class="line"> <span class="selector-class">.pl-container</span> {</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100vh</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="selector-id">#page-header</span><span class="selector-class">.full_page</span><span class="selector-class">.expand-to-full</span>,</span><br><span class="line"> <span class="selector-class">.pl-container</span><span class="selector-class">.expand-to-full</span> {</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">50vh</span> <span class="meta">!important</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="selector-class">.pl-container</span> {</span><br><span class="line"> <span class="attribute">will-change</span>: opacity, transform, filter;</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="built_in">calc</span>(<span class="number">1</span> - <span class="built_in">var</span>(--process) * <span class="number">1</span>) <span class="meta">!important</span>;</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">scale</span>(<span class="built_in">calc</span>(<span class="number">1</span> + <span class="built_in">var</span>(--process) * .<span class="number">1</span>));</span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="built_in">calc</span>(<span class="built_in">var</span>(--process) * <span class="number">10px</span>));</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-container</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">position</span>: fixed;</span><br><span class="line"> <span class="attribute">z-index</span>: -<span class="number">2</span>;</span><br><span class="line"> <span class="attribute">overflow</span>: hidden;</span><br><span class="line"> <span class="attribute">will-change</span>: transform;</span><br><span class="line"> <span class="comment">/* 添加性能优化 */</span></span><br><span class="line"> <span class="attribute">animation</span>: blur-to-clear <span class="number">2.5s</span> <span class="built_in">cubic-bezier</span>(.<span class="number">6</span>, .<span class="number">25</span>, .<span class="number">25</span>, <span class="number">1</span>) <span class="number">0s</span> <span class="number">1</span> backwards, scale <span class="number">2.2s</span> <span class="built_in">cubic-bezier</span>(.<span class="number">6</span>, .<span class="number">1</span>, .<span class="number">25</span>, <span class="number">1</span>) .<span class="number">5s</span> <span class="number">1</span> backwards;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-img</span> {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">background-position</span>: center;</span><br><span class="line"> <span class="attribute">background-size</span>: cover;</span><br><span class="line"> <span class="attribute">background-repeat</span>: no-repeat;</span><br><span class="line"> <span class="attribute">opacity</span>: .<span class="number">1</span>;</span><br><span class="line"> <span class="attribute">transition</span>: opacity <span class="number">1s</span>;</span><br><span class="line"> <span class="attribute">will-change</span>: transform, opacity</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-video</span><span class="selector-class">.pl-visible</span> {</span><br><span class="line"> <span class="attribute">display</span>: block</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@keyframes</span> blur-to-clear {</span><br><span class="line"> <span class="number">0%</span> {</span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">50px</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="number">100%</span> {</span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">@keyframes</span> scale {</span><br><span class="line"> <span class="number">0%</span> {</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">scale</span>(<span class="number">1.5</span>) <span class="built_in">translateZ</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="selector-tag">to</span> {</span><br><span class="line"> <span class="attribute">transform</span>: <span class="built_in">scale</span>(<span class="number">1</span>) <span class="built_in">translateZ</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-video</span> {</span><br><span class="line"> <span class="attribute">position</span>: absolute;</span><br><span class="line"> <span class="attribute">top</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line"> <span class="attribute">object-fit</span>: cover;</span><br><span class="line"> <span class="attribute">z-index</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">url</span>(<span class="string">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAKUlEQVQImU3IMREAIAgAwJfNkQCEsH8cijjpMf6vnXlQaIiJFx+omEBfmqIEZLe2jzcAAAAASUVORK5CYII=</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-visible</span> {</span><br><span class="line"> <span class="attribute">opacity</span>: <span class="number">1</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.pl-blur</span> {</span><br><span class="line"> <span class="comment">/* 小图锯齿多,增加高斯模糊 */</span></span><br><span class="line"> <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">50px</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 去除首页图片背景黑板 */</span></span><br><span class="line"><span class="selector-id">#page-header</span>{</span><br><span class="line"> <span class="attribute">position</span>: inherit <span class="meta">!important</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>基于Memos实现闲言碎语和待办项功能</title>
<link href="/posts/f27cb9bd.html"/>
<url>/posts/f27cb9bd.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>当前的闲言碎语界面是参考 Leonus大佬 的文章 <a href="https://blog.leonus.cn/2023/memeos.html">基于Memos实现说说和清单功能。</a> 而成的。过程中数据显示不出来,大佬也通过远程控制我的电脑帮助我解决了问题,感谢大佬</p><p>这里建议最好基于自身服务器进行部署。当然,我是通过 小N同学 的 <a href="https://www.imcharon.com/1467/">memos纯公益代部署服务</a> 获取 API 进行部署的,这里也有一些大佬们研究出使用 Zeabur 和 Railway 部署 memos</p><h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><p>通过命令 <code>hexo new page memos</code> 创建页面,并在 <strong>_config.anzhiyu.yml</strong> 的菜单里使这个界面可以通过点击进去</p><p>用户ID的获取方法如下:</p><ol><li>注册并登录 <a href="https://memos.nesxc.com/">Memos</a></li><li>发布一条<strong>所有人可见</strong>的memos</li><li>点击<strong>探索</strong>接着点击用户名<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/memos/leonus_2023-03-15_11-28-49.webp"></li></ol><p>我这里是使用 小N同学 的 Memos 的,所以这是我最终的 <a href="https://memos.nesxc.com/api/v1/memo?creatorId=72&tag=%E8%AF%B4%E8%AF%B4&limit=30">链接地址</a> ,出现数据就代表成功了</p><h2 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h2><p>粘贴如下代码并按照注释修改内容即可</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br></pre></td><td class="code"><pre><span class="line"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"author-content author-content-item single"</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml"> <span class="attr">style</span>=<span class="string">"background:url(https://jsd.onmicrosoft.cn/npm/blogassert/covers/1687615739569.png) left 28%/cover no-repeat"</span>></span></span></span><br><span class="line"><span class="code"> <div class="card-content"></span></span><br><span class="line"><span class="code"> <div class="author-content-item-tips">闲言碎语</div><span class="author-content-item-title">咸鱼的日常生活</span></span></span><br><span class="line"><span class="code"> <div class="content-bottom"></span></span><br><span class="line"><span class="code"> <div class="tips">随时随地,分享生活</div></span></span><br><span class="line"><span class="code"> </div></span></span><br><span class="line"><span class="code"> <div class="banner-button-group"><a class="banner-button" href="/album" data-pjax-state=""</span></span><br><span class="line"><span class="code"> draggable="false"><i class="anzhiyufont anzhiyu-icon-arrow-circle-right"</span></span><br><span class="line"><span class="code"> style="font-size:1.5rem"></i><span class="banner-button-text">我的相册</span></a></div></span></span><br><span class="line"><span class="code"> </div></span></span><br><span class="line"><span class="code"></div></span></span><br><span class="line"><span class="code"></span></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">style</span>></span></span></span><br><span class="line">.bber-reply {</span><br><span class="line"><span class="code"> cursor: pointer !important;</span></span><br><span class="line"><span class="code">}</span></span><br><span class="line"><span class="code"></span></span><br><span class="line">.bber-reply:hover {</span><br><span class="line"><span class="code"> color: var(--anzhiyu-main);</span></span><br><span class="line"><span class="code"> max-height: 35px;</span></span><br><span class="line"><span class="code">}</span></span><br><span class="line"><span class="code"></span></span><br><span class="line">/* 页面初始化 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis">div#page {</span></span><br><span class="line"><span class="emphasis"> background: 0 0!important;</span></span><br><span class="line"><span class="emphasis"> border: 0;</span></span><br><span class="line"><span class="emphasis"> padding: 0;</span></span><br><span class="line"><span class="emphasis"> box-shadow: none !important</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">[data-theme=dark] #twikoo .tk-content,</span></span><br><span class="line"><span class="emphasis">#twikoo .tk-content {</span></span><br><span class="line"><span class="emphasis"> padding: 0;</span></span><br><span class="line"><span class="emphasis"> background: transparent;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_item,</span></span><br><span class="line"><span class="emphasis">.tk-expand,</span></span><br><span class="line"><span class="emphasis">.tk-comments-container>.tk-comment,</span></span><br><span class="line"><span class="emphasis">.tk-submit:nth-child(1) {</span></span><br><span class="line"><span class="emphasis"> background: rgba(255,255,255,.6);</span></span><br><span class="line"><span class="emphasis"> border: 1px solid #e0e3ed;</span></span><br><span class="line"><span class="emphasis"> box-shadow: 0 5px 10px rgb(189 189 189 / 10%);</span></span><br><span class="line"><span class="emphasis"> transition: all .3s ease-in-out;</span></span><br><span class="line"><span class="emphasis"> border-radius: 12px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">/*</span> 瀑布溜布局卡片 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis">.talk_item {</span></span><br><span class="line"><span class="emphasis"> display: inline-block;</span></span><br><span class="line"><span class="emphasis"> width: 32.7%;</span></span><br><span class="line"><span class="emphasis"> margin-right: 1%;</span></span><br><span class="line"><span class="emphasis"> padding: 15px 1rem 12px;</span></span><br><span class="line"><span class="emphasis"> margin-bottom: 15px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">[data-theme=dark] .talk_item,</span></span><br><span class="line"><span class="emphasis">.tk-expand,</span></span><br><span class="line"><span class="emphasis">.tk-comments-container>.tk-comment,</span></span><br><span class="line"><span class="emphasis">.tk-submit:nth-child(1) {</span></span><br><span class="line"><span class="emphasis"> background: none;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_item:hover,</span></span><br><span class="line"><span class="emphasis">.tk-comments-container>.tk-comment:hover,</span></span><br><span class="line"><span class="emphasis">.tk-submit:nth-child(1):hover {</span></span><br><span class="line"><span class="emphasis"> border-color: #49b1f5;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.tk-submit {</span></span><br><span class="line"><span class="emphasis"> padding: 20px 10px 0;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.tk-comments-container>.tk-comment {</span></span><br><span class="line"><span class="emphasis"> padding: 15px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">/*</span> 页面初始化结束 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">#talk {</span></span><br><span class="line"><span class="emphasis"> margin-top: 1rem;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">#talk .loading {</span></span><br><span class="line"><span class="emphasis"> display: flex;</span></span><br><span class="line"><span class="emphasis"> align-items: center;</span></span><br><span class="line"><span class="emphasis"> justify-content: center;</span></span><br><span class="line"><span class="emphasis"> flex-direction: column;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">#talk .loading img {</span></span><br><span class="line"><span class="emphasis"> width: 200px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.avatar {</span></span><br><span class="line"><span class="emphasis"> margin: 0 !important;</span></span><br><span class="line"><span class="emphasis"> width: 60px;</span></span><br><span class="line"><span class="emphasis"> height: 60px;</span></span><br><span class="line"><span class="emphasis"> border-radius: 10px !important;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_bottom,</span></span><br><span class="line"><span class="emphasis">.talk_meta {</span></span><br><span class="line"><span class="emphasis"> display: flex;</span></span><br><span class="line"><span class="emphasis"> align-items: center;</span></span><br><span class="line"><span class="emphasis"> width: 100%;</span></span><br><span class="line"><span class="emphasis"> line-height: 1.5;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_bottom {</span></span><br><span class="line"><span class="emphasis"> justify-content: space-between;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.info {</span></span><br><span class="line"><span class="emphasis"> display: flex;</span></span><br><span class="line"><span class="emphasis"> flex-direction: column;</span></span><br><span class="line"><span class="emphasis"> margin-left: 10px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">span.talk_nick {</span></span><br><span class="line"><span class="emphasis"> color: #6dbdc3;</span></span><br><span class="line"><span class="emphasis"> font-size: 1.2rem;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">svg.is-badge.icon {</span></span><br><span class="line"><span class="emphasis"> width: 15px;</span></span><br><span class="line"><span class="emphasis"> margin-left: 5px;</span></span><br><span class="line"><span class="emphasis"> padding-top: 3px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">span.talk_date {</span></span><br><span class="line"><span class="emphasis"> font-size: 14px;</span></span><br><span class="line"><span class="emphasis"> opacity: .6;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_content {</span></span><br><span class="line"><span class="emphasis"> line-height: 1.5;</span></span><br><span class="line"><span class="emphasis"> margin-top: 10px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.zone_imgbox {</span></span><br><span class="line"><span class="emphasis"> display: flex;</span></span><br><span class="line"><span class="emphasis"> flex-wrap: wrap;</span></span><br><span class="line"><span class="emphasis"> --w: calc(25% - 8px);</span></span><br><span class="line"><span class="emphasis"> gap: 10px;</span></span><br><span class="line"><span class="emphasis"> margin-top: 5px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.zone_imgbox a {</span></span><br><span class="line"><span class="emphasis"> display: block;</span></span><br><span class="line"><span class="emphasis"> border-radius: 12px;</span></span><br><span class="line"><span class="emphasis"> width: 177px;</span></span><br><span class="line"><span class="emphasis"> aspect-ratio: 1/1;</span></span><br><span class="line"><span class="emphasis"> position: relative;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.zone_imgbox img {</span></span><br><span class="line"><span class="emphasis"> width: 100%;</span></span><br><span class="line"><span class="emphasis"> height: 100%;</span></span><br><span class="line"><span class="emphasis"> margin: 0 !important;</span></span><br><span class="line"><span class="emphasis"> object-fit: cover;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">/*</span> 底部 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_bottom {</span></span><br><span class="line"><span class="emphasis"> opacity: .9;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_bottom a {</span></span><br><span class="line"><span class="emphasis"> border-bottom: none !important;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">span.talk_tag {</span></span><br><span class="line"><span class="emphasis"> font-size: 14px;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_content>a {</span></span><br><span class="line"><span class="emphasis"> margin: 0 3px;</span></span><br><span class="line"><span class="emphasis"> color: #ff7d73 !important;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.talk_content>a:hover {</span></span><br><span class="line"><span class="emphasis"> text-decoration: none !important;</span></span><br><span class="line"><span class="emphasis"> color: #ff5143 !important</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">/*</span> 提醒 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.limit {</span></span><br><span class="line"><span class="emphasis"> transition: all .3s ease-in-out;</span></span><br><span class="line"><span class="emphasis"> color: rgba(76, 73, 72, 0.6);</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">[data-theme=dark] .limit {</span></span><br><span class="line"><span class="emphasis"> color: rgba(255, 255, 255, 0.5);</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.limit {</span></span><br><span class="line"><span class="emphasis"> display: none;</span></span><br><span class="line"><span class="emphasis"> text-align: center;</span></span><br><span class="line"><span class="emphasis"> margin-top: 20px;</span></span><br><span class="line"><span class="emphasis"> color: #4c4948;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">/*</span> 哔哩哔哩视频适配 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis">iframe {</span></span><br><span class="line"><span class="emphasis"> position: absolute;</span></span><br><span class="line"><span class="emphasis"> width: 100%;</span></span><br><span class="line"><span class="emphasis"> height: 100%;</span></span><br><span class="line"><span class="emphasis"> left: 0;</span></span><br><span class="line"><span class="emphasis"> top: 0;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.video {</span></span><br><span class="line"><span class="emphasis"> position: relative;</span></span><br><span class="line"><span class="emphasis"> padding: 30% 45%;</span></span><br><span class="line"><span class="emphasis"> margin-top: 10px;</span></span><br><span class="line"><span class="emphasis"> margin-bottom: 10px;</span></span><br><span class="line"><span class="emphasis"> border-radius: 12px;</span></span><br><span class="line"><span class="emphasis"> overflow: hidden;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">/*</span> 手机卡片自适应 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis">@media screen and (max-width: 768px) {</span></span><br><span class="line"><span class="emphasis"> .talk_item {</span></span><br><span class="line"><span class="emphasis"> width: 49.3%;</span></span><br><span class="line"><span class="emphasis"> margin-right: 1.4%;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"> .zone_imgbox a {</span></span><br><span class="line"><span class="emphasis"> width: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> max-height: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">@media screen and (max-width: 1100px) {</span></span><br><span class="line"><span class="emphasis"> .talk_item {</span></span><br><span class="line"><span class="emphasis"> width: 100%;</span></span><br><span class="line"><span class="emphasis"> margin-right: 0;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"> .zone_imgbox a {</span></span><br><span class="line"><span class="emphasis"> width: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> max-height: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">@media screen and (max-width: 900px) {</span></span><br><span class="line"><span class="emphasis"> .zone_imgbox {</span></span><br><span class="line"><span class="emphasis"> --w: calc(33% - 5px);</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"> #talk {</span></span><br><span class="line"><span class="emphasis"> margin: 10px 3px 0</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"> #post-comment {</span></span><br><span class="line"><span class="emphasis"> margin: 0 3px</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"> .zone_imgbox a {</span></span><br><span class="line"><span class="emphasis"> width: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> max-height: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">@media screen and (max-width: 768px) {</span></span><br><span class="line"><span class="emphasis"> .zone_imgbox {</span></span><br><span class="line"><span class="emphasis"> gap: 6px;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"> .zone_imgbox {</span></span><br><span class="line"><span class="emphasis"> --w: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"> span.talk_date {</span></span><br><span class="line"><span class="emphasis"> font-size: 14px;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis"> .zone_imgbox a {</span></span><br><span class="line"><span class="emphasis"> width: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> max-height: calc(50% - 3px);</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"></<span class="name">style</span>></span></span></span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"talk"</span> <span class="attr">style</span>=<span class="string">"position: relative;height: 2845px;"</span>></span></span></span></span><br><span class="line"><span class="emphasis"> <span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">'loading'</span>></span></span><span class="language-xml"><span class="tag"><<span class="name">img</span> <span class="attr">src</span>=<span class="string">"/img/loading.gif"</span> <span class="attr">alt</span>=<span class="string">"加载中..."</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"limit"</span>></span></span>- 只展示最近30条说说 -<span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"/js/imgStatus.js"</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">script</span>></span></span></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"><<span class="name">script</span>></span></span></span></span><br><span class="line"><span class="emphasis">if (1) {</span></span><br><span class="line"><span class="emphasis"> let url = 'memos地址'</span></span><br><span class="line"><span class="emphasis"> fetch(url + '/api/v1/memo?creatorId=72&tag=说说&limit=30').then(res => res.json()).then(data => { // 注意修改域名和用户id</span></span><br><span class="line"><span class="emphasis"> let items = [],</span></span><br><span class="line"><span class="emphasis"> html = '',</span></span><br><span class="line"><span class="emphasis"> icon = '<span class="language-xml"><span class="language-javascript"><svg viewBox=<span class="string">"0 0 512 512"</span>xmlns=<span class="string">"http://www.w3.org/2000/svg"</span><span class="keyword">class</span>=<span class="string">"is-badge icon"</span>></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"><<span class="name">path</span> <span class="attr">d</span>=<span class="string">"m512 268c0 17.9-4.3 34.5-12.9 49.7s-20.1 27.1-34.6 35.4c.4 2.7.6 6.9.6 12.6 0 27.1-9.1 50.1-27.1 69.1-18.1 19.1-39.9 28.6-65.4 28.6-11.4 0-22.3-2.1-32.6-6.3-8 16.4-19.5 29.6-34.6 39.7-15 10.2-31.5 15.2-49.4 15.2-18.3 0-34.9-4.9-49.7-14.9-14.9-9.9-26.3-23.2-34.3-40-10.3 4.2-21.1 6.3-32.6 6.3-25.5 0-47.4-9.5-65.7-28.6-18.3-19-27.4-42.1-27.4-69.1 0-3 .4-7.2 1.1-12.6-14.5-8.4-26-20.2-34.6-35.4-8.5-15.2-12.8-31.8-12.8-49.7 0-19 4.8-36.5 14.3-52.3s22.3-27.5 38.3-35.1c-4.2-11.4-6.3-22.9-6.3-34.3 0-27 9.1-50.1 27.4-69.1s40.2-28.6 65.7-28.6c11.4 0 22.3 2.1 32.6 6.3 8-16.4 19.5-29.6 34.6-39.7 15-10.1 31.5-15.2 49.4-15.2s34.4 5.1 49.4 15.1c15 10.1 26.6 23.3 34.6 39.7 10.3-4.2 21.1-6.3 32.6-6.3 25.5 0 47.3 9.5 65.4 28.6s27.1 42.1 27.1 69.1c0 12.6-1.9 24-5.7 34.3 16 7.6 28.8 19.3 38.3 35.1 9.5 15.9 14.3 33.4 14.3 52.4zm-266.9 77.1 105.7-158.3c2.7-4.2 3.5-8.8 2.6-13.7-1-4.9-3.5-8.8-7.7-11.4-4.2-2.7-8.8-3.6-13.7-2.9-5 .8-9 3.2-12 7.4l-93.1 140-42.9-42.8c-3.8-3.8-8.2-5.6-13.1-5.4-5 .2-9.3 2-13.1 5.4-3.4 3.4-5.1 7.7-5.1 12.9 0 5.1 1.7 9.4 5.1 12.9l58.9 58.9 2.9 2.3c3.4 2.3 6.9 3.4 10.3 3.4 6.7-.1 11.8-2.9 15.2-8.7z"</span><span class="attr">fill</span>=<span class="string">"#1da1f2"</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">path</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">svg</span>></span></span></span></span>';</span></span><br><span class="line"><span class="emphasis"> data.forEach(item => { items.push(Format(item)) });</span></span><br><span class="line"><span class="emphasis"> if (items.length == 30) document.querySelector('.limit').style.display = 'block';</span></span><br><span class="line"><span class="emphasis"> items.forEach(item => {</span></span><br><span class="line"><span class="emphasis"> html += `<span class="language-xml"><span class="language-javascript"><div <span class="keyword">class</span>=<span class="string">"talk_item"</span>></span></span><span class="language-xml"><span class="language-javascript"><div <span class="keyword">class</span>=<span class="string">"talk_meta"</span>></span></span><span class="language-xml"><span class="language-javascript"><img <span class="keyword">class</span>=<span class="string">"no-lightbox nolazyload avatar"</span> src=<span class="string">"/img/avatar.webp"</span>></span></span><span class="language-xml"><span class="language-javascript"><div <span class="keyword">class</span>=<span class="string">"info"</span>></span></span><span class="language-xml"><span class="language-javascript"><span <span class="keyword">class</span>=<span class="string">"talk_nick"</span>></span></span>萌傀儡${icon}<span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">span</span>></span></span></span></span><span class="language-xml"><span class="language-javascript"><span <span class="keyword">class</span>=<span class="string">"talk_date"</span>></span></span>${item.date}<span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">span</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-javascript"><div <span class="keyword">class</span>=<span class="string">"talk_content"</span>></span></span>${item.content}<span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-javascript"><div <span class="keyword">class</span>=<span class="string">"talk_bottom"</span>></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"><<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-javascript"><span <span class="keyword">class</span>=<span class="string">"talk_tag"</span>></span></span># ${item.tag}<span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">span</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-javascript"><div <span class="keyword">class</span>=<span class="string">"bber-reply"</span> onclick=<span class="string">"rm.rightMenuCommentText('${item.content.split('<')[0]}')"</span>></span></span><span class="language-xml"><span class="language-javascript"><i <span class="keyword">class</span>=<span class="string">"anzhiyufont anzhiyu-icon-message"</span>></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">i</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span>` // 注意修改头像链接和名称</span></span><br><span class="line"><span class="emphasis"> })</span></span><br><span class="line"><span class="emphasis"> document.getElementById('talk').innerHTML = html</span></span><br><span class="line"><span class="emphasis"> waterfall('#talk')</span></span><br><span class="line"><span class="emphasis"> })</span></span><br><span class="line"><span class="emphasis"> // 页面内容格式化</span></span><br><span class="line"><span class="emphasis"> function Format(item) {</span></span><br><span class="line"><span class="emphasis"> let date = getTime(new Date(item.createdTs *</span> 1000).toString()),</span><br><span class="line"><span class="code"> content = item.content,</span></span><br><span class="line"><span class="code"> tag = item.content.match(/\{(.*?)\}/g),</span></span><br><span class="line"><span class="code"> imgs = content.match(/!\[.*\]\(.*?\)/g),</span></span><br><span class="line"><span class="code"> musics = content.match(/{\s*music\s*(.*)\s*}/g),</span></span><br><span class="line"><span class="code"> text = '',</span></span><br><span class="line"><span class="code"> videos = content.match(/{\s*bilibili\s*(.*)\s*}/g);</span></span><br><span class="line"><span class="code"> if (imgs) imgs = imgs.map(item => { return item.replace(/!\[.*\]\((.*?)\)/, '$1') })</span></span><br><span class="line"><span class="code"> if (item.resourceList.length) {</span></span><br><span class="line"><span class="code"> if (!imgs) imgs = []</span></span><br><span class="line"><span class="code"> item.resourceList.forEach(t => {</span></span><br><span class="line"><span class="code"> if (t.externalLink) imgs.push(t.externalLink)</span></span><br><span class="line"><span class="code"> else imgs.push(`${url}/o/r/${t.id}/${t.publicId}/${t.filename}`)</span></span><br><span class="line"><span class="code"> })</span></span><br><span class="line"><span class="code"> }</span></span><br><span class="line"><span class="code"> // content = content.replace(/#(.*?)\s/g, '').replace(/{.*}/g, '').replace(/\!\[(.*?)\]\((.*?)\)/g, '').replace(/```/g, '').replace(/\[(.*?)\]\((.*?)\)/g, `<a href="$2">@$1</a>`);</span></span><br><span class="line"><span class="code"> text = content.replace(/#(.*?)\s/g, '').replace(/\!\[(.*?)\]\((.*?)\)/g, '').replace(/\{(.*?)\}/g, '')</span></span><br><span class="line"><span class="code"> content = text.replace(/\[(.*?)\]\((.*?)\)/g, `<a href="$2">@$1</a>`);</span></span><br><span class="line"><span class="code"> if (imgs) {</span></span><br><span class="line"><span class="code"> content += `<div class="zone_imgbox">`</span></span><br><span class="line"><span class="code"> imgs.forEach(e => content += `<a href="${e}" data-fancybox="gallery" class="fancybox" data-thumb="${e}"><img class="nolazyload talk-img" src="${e}"></a>`)</span></span><br><span class="line"><span class="code"> content += '</div>'</span></span><br><span class="line"><span class="code"> }</span></span><br><span class="line"><span class="code"> if (musics) musics.forEach(item => { content += `<meting-js auto="${item.replace(/{\s*music\s*(.*)\s*}/, '$1')}" theme="#4976f5" preload="metadata"></meting-js>` })</span></span><br><span class="line"><span class="code"> if (videos) videos.forEach(item => {</span></span><br><span class="line"><span class="code"> content += `<div style="position: relative; padding: 30% 45%;margin-top: 10px;margin-bottom: 10px"><iframe style="position: absolute; width: 100%; height: 100%; left: 0; top: 0;" src="//player.bilibili.com/player.html?autoplay=0&bvid=${item.replace(/{\s*bilibili\s*(.*)\s*}/, '$1').replace(/.*video\/([^\/]*).*/, '$1')}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>`</span></span><br><span class="line"><span class="code"> })</span></span><br><span class="line"><span class="code"> return { </span></span><br><span class="line"><span class="code"> content: content, </span></span><br><span class="line"><span class="code"> date: date, </span></span><br><span class="line"><span class="code"> tag: tag ? tag[0].replace(/\{(.*?)\}/, '$1') : '无标签',</span></span><br><span class="line"><span class="code"> text: text.replace(/\[(.*?)\]\((.*?)\)/g, '[链接]' + `${imgs ? '[图片]' : ''}`)</span></span><br><span class="line"><span class="code"> }</span></span><br><span class="line"><span class="code"> }</span></span><br><span class="line"><span class="code"> // 页面时间格式化</span></span><br><span class="line"><span class="code"> function getTime(time) {</span></span><br><span class="line"><span class="code"> let d = new Date(time),</span></span><br><span class="line"><span class="code"> ls = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()];</span></span><br><span class="line"><span class="code"> for (let i = 0; i < ls.length; i++) {</span></span><br><span class="line"><span class="code"> ls[i] = ls[i] <= 9 ? '0' + ls[i] : ls[i] + ''</span></span><br><span class="line"><span class="code"> }</span></span><br><span class="line"><span class="code"> if (new Date().getFullYear() == ls[0]) return ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4]</span></span><br><span class="line"><span class="code"> else return ls[0] + '年' + ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4]</span></span><br><span class="line"><span class="code"> }</span></span><br><span class="line"><span class="code">}</span></span><br><span class="line"><span class="code"></script></span></span><br></pre></td></tr></table></figure><h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><p>使用的格式如下:</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">#说说 {说说标签} 我是内容 [<span class="string">我是链接</span>](<span class="link">链接地址</span>) ![](<span class="link">图片链接</span>)</span></span><br></pre></td></tr></table></figure><p>注意,前面的 <strong>#说说</strong> 是固定的。标签用大括号包起来。<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/memos/leonus_2023-01-14_15-36-47.webp"></p><h2 id="待办项功能"><a href="#待办项功能" class="headerlink" title="待办项功能"></a>待办项功能</h2><p>通过命令 <code>hexo new page todo</code> 创建页面,并在 <strong>_config.anzhiyu.yml</strong> 的菜单里使这个界面可以通过点击进去。</p><p>粘贴如下代码并按照注释修改内容即可。</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">class</span>=<span class="string">"author-content author-content-item single"</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml"> <span class="attr">style</span>=<span class="string">"background:url(https://jsd.onmicrosoft.cn/npm/blogassert/covers/yuanshen1.webp) top/cover no-repeat"</span>></span></span></span><br><span class="line"><span class="code"> <div class="card-content"></span></span><br><span class="line"><span class="code"> <div class="author-content-item-tips">待办项</div><span class="author-content-item-title">这是我应该要记得做的事情</span></span></span><br><span class="line"><span class="code"> <div class="content-bottom"></div></span></span><br><span class="line"><span class="code"> <div class="tips">列出需要处理的事物,包括生活、工作或其他事项</div></span></span><br><span class="line"><span class="code"> <div class="banner-button-group"><a class="banner-button" onclick="pjax.loadUrl(&quot;/memos/&quot;)"</span></span><br><span class="line"><span class="code"> data-pjax-state=""><i class="anzhiyufont anzhiyu-icon-arrow-circle-right"</span></span><br><span class="line"><span class="code"> style="font-size:1.5rem"></i><span class="banner-button-text">闲言碎语</span></a></div></span></span><br><span class="line"><span class="code"> </div><canvas id="header_canvas" width="897" height="859" style="position: absolute; bottom: 0px;"></canvas></span></span><br><span class="line"><span class="code"></div></span></span><br><span class="line"><span class="code"></span></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">style</span>></span></span></span><br><span class="line">/* 页面初始化 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis">div#page {</span></span><br><span class="line"><span class="emphasis"> background: none;</span></span><br><span class="line"><span class="emphasis"> border: 0;</span></span><br><span class="line"><span class="emphasis"> padding: 0;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.page-title{</span></span><br><span class="line"><span class="emphasis"> display: none;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.page-top-card {</span></span><br><span class="line"><span class="emphasis"> background-color: #ffe3dd;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">/*</span> 页面初始化结束 <span class="emphasis">*/</span></span><br><span class="line"><span class="emphasis">div#todolist {</span></span><br><span class="line"><span class="emphasis"> display: flex;</span></span><br><span class="line"><span class="emphasis"> flex-wrap: wrap;</span></span><br><span class="line"><span class="emphasis"> margin-top: 1rem;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis">.list_item {</span></span><br><span class="line"><span class="emphasis"> position: relative;</span></span><br><span class="line"><span class="emphasis"> display: inline-block;</span></span><br><span class="line"><span class="emphasis"> width: calc(50% - .4rem);</span></span><br><span class="line"><span class="emphasis"> background: #ffe3dd;</span></span><br><span class="line"><span class="emphasis"> border-radius: 12px;</span></span><br><span class="line"><span class="emphasis"> padding: 10px 1rem 1.2rem;</span></span><br><span class="line"><span class="emphasis"> border: 2px dashed #f7a796;</span></span><br><span class="line"><span class="emphasis"> --todo-border: 1px solid #f7a796;</span></span><br><span class="line"><span class="emphasis"> margin-right: 1rem;</span></span><br><span class="line"><span class="emphasis"> margin-bottom: 1rem;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.list_item h3 {</span></span><br><span class="line"><span class="emphasis"> margin: 0;</span></span><br><span class="line"><span class="emphasis"> color: #333;</span></span><br><span class="line"><span class="emphasis"> border-bottom: 1px solid #f7a796;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.list_item ul {</span></span><br><span class="line"><span class="emphasis"> font-size: 17px;</span></span><br><span class="line"><span class="emphasis"> padding: 0 !important;</span></span><br><span class="line"><span class="emphasis"> margin: 0;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"> .list_item li{</span></span><br><span class="line"><span class="emphasis"> margin: 0 !important;</span></span><br><span class="line"><span class="emphasis"> color: #333;</span></span><br><span class="line"><span class="emphasis"> border-bottom: 1px solid #f7a796;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">.list_item li::marker {</span></span><br><span class="line"><span class="emphasis"> content: none;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">li.achieve {</span></span><br><span class="line"><span class="emphasis"> opacity: .8;</span></span><br><span class="line"><span class="emphasis"> text-decoration: line-through;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.bottom{</span></span><br><span class="line"><span class="emphasis"> line-height: 1.5;</span></span><br><span class="line"><span class="emphasis"> text-align: right;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.bottom p {</span></span><br><span class="line"><span class="emphasis"> margin: 0 !important;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.bottom a {</span></span><br><span class="line"><span class="emphasis"> font-weight: 700;</span></span><br><span class="line"><span class="emphasis"> color: #4c4948 !important;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">.bottom a:hover {</span></span><br><span class="line"><span class="emphasis"> color: #4976f5 !important;</span></span><br><span class="line"><span class="emphasis"> text-decoration: none !important;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">[data-theme=dark] .list_item {</span></span><br><span class="line"><span class="emphasis"> background: #dfc1b9;</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">@media screen and (max-width: 900px) {</span></span><br><span class="line"><span class="emphasis"> .bottom {</span></span><br><span class="line"><span class="emphasis"> margin: 0 8px;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis">@media screen and (max-width: 768px) {</span></span><br><span class="line"><span class="emphasis"> .list_item{</span></span><br><span class="line"><span class="emphasis"> width: 100%;</span></span><br><span class="line"><span class="emphasis"> }</span></span><br><span class="line"><span class="emphasis">}</span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"></<span class="name">style</span>></span></span></span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"todolist"</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span></span><br><span class="line"><span class="emphasis"></span></span><br><span class="line"><span class="emphasis"><span class="language-xml"><span class="tag"><<span class="name">script</span>></span></span></span></span><br><span class="line"><span class="emphasis">if (1) {</span></span><br><span class="line"><span class="emphasis"> fetch('memos地址/api/v1/memo?creatorId=72&tag=清单').then(res => res.json()).then(data => {</span></span><br><span class="line"><span class="emphasis"> // 获取并处理数据</span></span><br><span class="line"><span class="emphasis"> data.forEach(item => {</span></span><br><span class="line"><span class="emphasis"> // 处理数据</span></span><br><span class="line"><span class="emphasis"> let content = item.content,</span></span><br><span class="line"><span class="emphasis"> title = content.match(/\[(.*</span>?)\]/g)[0].replace(/\[(.<span class="emphasis">*?)\]/, '$1');</span></span><br><span class="line"><span class="emphasis"> // 去掉多余内容,替换清单内容</span></span><br><span class="line"><span class="emphasis"> content = content.replace(/#.*</span>\s/g, '').replace(/(-\s\[\s\]\s)(.<span class="emphasis">*)/g, `<span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"><<span class="name">li</span>></span></span></span></span><span class="language-xml"><span class="language-javascript"><i style=<span class="string">"margin-right: 5px;"</span> <span class="keyword">class</span>=<span class="string">"fa-regular fa-circle"</span>></span></span><span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">i</span>></span></span></span></span>$2<span class="language-xml"><span class="language-handlebars"><span class="language-xml"><span class="tag"></<span class="name">li</span>></span></span></span></span>`).replace(/(-\s\[x\]\s)(.*</span>)/g, <span class="code">`<li class="achieve"><i style="margin-right: 5px;" class="fa-regular fa-circle-check"></i>$2</li>`</span>);</span><br><span class="line"><span class="code"> // 渲染数据</span></span><br><span class="line"><span class="code"> let div = document.createElement('div');</span></span><br><span class="line"><span class="code"> div.className = 'list_item';</span></span><br><span class="line"><span class="code"> div.innerHTML = `<h3>${title}</h3><ul>${content}</ul>`;</span></span><br><span class="line"><span class="code"> document.getElementById('todolist').appendChild(div);</span></span><br><span class="line"><span class="code"> });</span></span><br><span class="line"><span class="code"> waterfall('#todolist');</span></span><br><span class="line"><span class="code"> }).catch()</span></span><br><span class="line"><span class="code">}</span></span><br><span class="line"><span class="code"></script></span></span><br></pre></td></tr></table></figure><p>使用的格式如下:</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">#清单 [想去的地方]</span></span><br><span class="line"><span class="bullet">-</span> [ ] 轻笑的米奇妙妙屋(轻笑让我加的)</span><br><span class="line"><span class="bullet">-</span> [x] 已完成的清单</span><br></pre></td></tr></table></figure><p>注意,前面的 <strong>#清单</strong> 是固定的。标题用中括号包起来。已完成的将括号内的空格改成x即可。<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/memos/leonus_2023-01-14_16-02-58.webp"></p><h2 id="后记"><a href="#后记" class="headerlink" title="后记"></a>后记</h2><p>2023年8月18日,使用 <a href="https://dash.zeabur.com/">Zeabur</a> 成功部署了 Memos。原因也是 <a href="https://memos.nesxc.com/">原有的</a> 加载图片速度较慢,所以才进行更换。这里也发现一旦更换白嫖的服务器,那么原有的数据大概就会没了,毕竟不是自已的服务器,不过由于不是重要数据,丢了也没大伤。</p><p>2024年5月3日看到出现这个警告,相当于想要更好的服务就要收费了,不过也没啥<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/memos/Snipaste_2024-05-03_02-51-25.webp"></p><p>接下来就是如何实现首页说说轮播了,先找到 <code>/themes/butterfly/layout/includes/layout.pug</code> 这个文件,然后将如何代码添加进去</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">if (is_home())</span><br><span class="line"> #bbTimeList.bbTimeList.container.wow.animate__tada(data-wow-duration="700ms",data-wow-delay="200ms",data-wow-offset="100",data-wow-iteration="1",style="visibility: visible; animation-duration: 700ms; animation-delay: 200ms; animation-iteration-count: 1; animation-name: slide-in;")</span><br><span class="line"> i.anzhiyufont.anzhiyu-icon-jike.bber-logo.fontbold(onclick=`pjax.loadUrl("/memos/")`,title="即刻短文",aria-hidden="true")</span><br><span class="line"> #bbtalk.swiper-container.swiper-no-swiping.essay_bar_swiper_container.swiper-initialized.swiper-vertical.swiper-pointer-events.swiper-backface-hidden(tabindex="-1")</span><br><span class="line"> #bber-talk.swiper-wrapper(onclick=`pjax.loadUrl("/memos/")`,aria-live="off",style="transition-duration: 0ms;")</span><br><span class="line"> #talk-list</span><br><span class="line"> span.swiper-notification(aria-live="assertive",aria-atomic="true")</span><br><span class="line"> i.bber-gotobb.anzhiyufont.anzhiyu-icon-circle-arrow-right(onclick=`pjax.loadUrl("/memos/")`,title="查看全文")</span><br></pre></td></tr></table></figure><p>如下图所示:<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/memos/64de7f74661c6c8e54a93659.webp"></p><p>然后分别在你的 css文件夹 和 js文件夹 中添加如下两个文件,并放入<strong>inject</strong>中去</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">@media</span> screen <span class="keyword">and</span> (<span class="attribute">min-width</span>: <span class="number">768px</span>) {</span><br><span class="line"> <span class="selector-id">#bbTimeList</span> {</span><br><span class="line"> <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.75</span>) <span class="meta">!important</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#bber-talk</span>,<span class="selector-id">#bber-talk</span> <span class="selector-tag">a</span> {</span><br><span class="line"> <span class="attribute">color</span>: <span class="number">#4c4948</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="selector-id">#talk-list</span> {</span><br><span class="line"> <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line"> <span class="attribute">max-height</span>: <span class="number">32px</span>;</span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">16px</span>;</span><br><span class="line"> <span class="attribute">font-weight</span>: <span class="number">700</span>;</span><br><span class="line"> <span class="attribute">padding</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">margin</span>: <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">margin</span>: -<span class="number">1.2px</span> <span class="number">0</span> <span class="number">0</span> <span class="number">0</span>;</span><br><span class="line"> <span class="attribute">text-align</span>: center;</span><br><span class="line"> <span class="attribute">cursor</span>: pointer</span><br><span class="line">}</span><br></pre></td></tr></table></figure><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">saveData</span>(<span class="params">e, a</span>) {</span><br><span class="line"> <span class="variable language_">localStorage</span>.<span class="title function_">setItem</span>(e, <span class="title class_">JSON</span>.<span class="title function_">stringify</span>({</span><br><span class="line"> <span class="attr">time</span>: <span class="title class_">Date</span>.<span class="title function_">now</span>(),</span><br><span class="line"> <span class="attr">data</span>: a</span><br><span class="line"> }))</span><br><span class="line">}</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">loadData</span>(<span class="params">e, a</span>) {</span><br><span class="line"> <span class="keyword">let</span> t = <span class="title class_">JSON</span>.<span class="title function_">parse</span>(<span class="variable language_">localStorage</span>.<span class="title function_">getItem</span>(e));</span><br><span class="line"> <span class="keyword">if</span> (t) {</span><br><span class="line"> <span class="keyword">let</span> e = <span class="title class_">Date</span>.<span class="title function_">now</span>() - t.<span class="property">time</span>;</span><br><span class="line"> <span class="keyword">if</span> (-<span class="number">1</span> < e && e < <span class="number">6e4</span> * a)</span><br><span class="line"> <span class="keyword">return</span> t.<span class="property">data</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">let</span> talkTimer = <span class="literal">null</span>;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">indexTalk</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="keyword">if</span> (talkTimer && (<span class="built_in">clearInterval</span>(talkTimer),</span><br><span class="line"> talkTimer = <span class="literal">null</span>),</span><br><span class="line"> !<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">"bber-talk"</span>))</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">e</span>(<span class="params">e</span>) {</span><br><span class="line"> <span class="keyword">let</span> a = <span class="string">""</span>;</span><br><span class="line"> e.<span class="title function_">forEach</span>((<span class="function">(<span class="params">e,t</span>)=></span>{</span><br><span class="line"> a += <span class="string">`<li class="item item-<span class="subst">${t + <span class="number">1</span>}</span>" style="text-align: center;"><span class="subst">${e}</span></li>`</span></span><br><span class="line"> }</span><br><span class="line"> ));</span><br><span class="line"> <span class="keyword">let</span> t = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">"#bber-talk #talk-list"</span>);</span><br><span class="line"> t.<span class="property">innerHTML</span> = a,</span><br><span class="line"> talkTimer = <span class="built_in">setInterval</span>((<span class="function">()=></span>{</span><br><span class="line"> t.<span class="title function_">appendChild</span>(t.<span class="property">children</span>[<span class="number">0</span>])</span><br><span class="line"> }</span><br><span class="line"> ), <span class="number">3e3</span>)</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">let</span> a = <span class="title function_">loadData</span>(<span class="string">"talk"</span>, <span class="number">1000</span>);</span><br><span class="line"> a ? <span class="title function_">e</span>(a) : <span class="title function_">fetch</span>(<span class="string">"memos地址/api/v1/memo?creatorId=1&tag=说说&limit=30"</span>).<span class="title function_">then</span>((<span class="function"><span class="params">e</span>=></span>e.<span class="title function_">json</span>())).<span class="title function_">then</span>((<span class="function"><span class="params">a</span>=></span>{</span><br><span class="line"> <span class="title function_">e</span>(a = <span class="keyword">function</span>(<span class="params">e</span>) {</span><br><span class="line"> <span class="keyword">let</span> a = [];</span><br><span class="line"> <span class="keyword">return</span> e.<span class="title function_">forEach</span>((<span class="function"><span class="params">e</span>=></span>{</span><br><span class="line"> a.<span class="title function_">push</span>(e.<span class="property">content</span>.<span class="title function_">replace</span>(<span class="regexp">/#(.*?)\s/g</span>, <span class="string">""</span>).<span class="title function_">replace</span>(<span class="regexp">/\{(.*?)\}/</span>, <span class="string">""</span>).<span class="title function_">replace</span>(<span class="regexp">/\!\[(.*?)\]\((.*?)\)/g</span>, <span class="string">'<i class="fa-solid fa-image"></i>'</span>).<span class="title function_">replace</span>(<span class="regexp">/\[(.*?)\]\((.*?)\)/g</span>, <span class="string">'<i class="fa-solid fa-link"></i>'</span>).<span class="title function_">replace</span>(<span class="regexp">/{\s*bilibili\s*(.*)\s*}/g</span>, <span class="string">'<i class="fa-brands fa-bilibili"></i>'</span>).<span class="title function_">replace</span>(<span class="regexp">/{\s*music\s*(.*)\s*}/g</span>, <span class="string">'<i class="fa-solid fa-music"></i>'</span>))</span><br><span class="line"> }</span><br><span class="line"> )),</span><br><span class="line"> <span class="title function_">saveData</span>(<span class="string">"talk"</span>, a)</span><br><span class="line"> a</span><br><span class="line"> }(a))</span><br><span class="line"> }</span><br><span class="line"> ))</span><br><span class="line">}</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">whenDOMReady</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">indexTalk</span>()</span><br><span class="line">}</span><br><span class="line"><span class="title function_">whenDOMReady</span>(),</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"pjax:complete"</span>, whenDOMReady);</span><br></pre></td></tr></table></figure><p>这里比较耗费我时间的是如何获取 memos 的数据,一直返回 null</p><p>2023年8月19日处理<strong>视频</strong>首页轮播问题,在询问过<strong>Leonus大佬</strong>后成功解决问题了。下面是js文件的代码:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 存数据</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">saveData</span>(<span class="params">name, data</span>) { <span class="variable language_">localStorage</span>.<span class="title function_">setItem</span>(name, <span class="title class_">JSON</span>.<span class="title function_">stringify</span>({ <span class="string">'time'</span>: <span class="title class_">Date</span>.<span class="title function_">now</span>(), <span class="string">'data'</span>: data })) };</span><br><span class="line"><span class="comment">// 取数据</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">loadData</span>(<span class="params">name, time</span>) {</span><br><span class="line"> <span class="keyword">let</span> d = <span class="title class_">JSON</span>.<span class="title function_">parse</span>(<span class="variable language_">localStorage</span>.<span class="title function_">getItem</span>(name));</span><br><span class="line"> <span class="comment">// 过期或有错误返回 0 否则返回数据</span></span><br><span class="line"> <span class="keyword">if</span> (d) {</span><br><span class="line"> <span class="keyword">return</span> d.<span class="property">data</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> talkTimer = <span class="literal">null</span>;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">indexTalk</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="keyword">if</span> (talkTimer) {</span><br><span class="line"> <span class="built_in">clearInterval</span>(talkTimer)</span><br><span class="line"> talkTimer = <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (!<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'bber-talk'</span>)) <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">toText</span>(<span class="params">ls</span>) {</span><br><span class="line"> <span class="keyword">let</span> text = []</span><br><span class="line"> ls.<span class="title function_">forEach</span>(<span class="function"><span class="params">item</span> =></span> {</span><br><span class="line"> text.<span class="title function_">push</span>(item.<span class="property">content</span>.<span class="title function_">replace</span>(<span class="regexp">/#(.*?)\s/g</span>, <span class="string">""</span>).<span class="title function_">replace</span>(<span class="regexp">/\{(.*?)\}/</span>, <span class="string">""</span>).<span class="title function_">replace</span>(<span class="regexp">/\!\[(.*?)\]\((.*?)\)/g</span>, <span class="string">'<i class="fa-solid fa-image"></i>'</span>).<span class="title function_">replace</span>(<span class="regexp">/\[(.*?)\]\((.*?)\)/g</span>, <span class="string">'<i class="fa-solid fa-link"></i>'</span>).<span class="title function_">replace</span>(<span class="regexp">/{\s*bilibili\s*(.*)\s*}/g</span>, <span class="string">'<i class="fa-brands fa-bilibili"></i>'</span>).<span class="title function_">replace</span>(<span class="regexp">/{\s*music\s*(.*)\s*}/g</span>, <span class="string">'<i class="fa-solid fa-music"></i>'</span>))</span><br><span class="line"> });</span><br><span class="line"> <span class="keyword">return</span> text</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">talk</span>(<span class="params">ls</span>) {</span><br><span class="line"> <span class="keyword">let</span> html = <span class="string">''</span></span><br><span class="line"> ls.<span class="title function_">forEach</span>(<span class="function">(<span class="params">item, i</span>) =></span> { html += <span class="string">`<li class="item item-<span class="subst">${i + <span class="number">1</span>}</span>"><span class="subst">${item}</span></li>`</span> });</span><br><span class="line"> <span class="keyword">let</span> box = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">"#bber-talk #talk-list"</span>)</span><br><span class="line"> box.<span class="property">innerHTML</span> = html;</span><br><span class="line"> talkTimer = <span class="built_in">setInterval</span>(<span class="function">() =></span> {</span><br><span class="line"> box.<span class="title function_">appendChild</span>(box.<span class="property">children</span>[<span class="number">0</span>]);</span><br><span class="line"> }, <span class="number">5000</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> d = <span class="title function_">loadData</span>(<span class="string">'talk'</span>, <span class="number">10</span>);</span><br><span class="line"> <span class="keyword">if</span> (d) <span class="title function_">talk</span>(d);</span><br><span class="line"> <span class="keyword">else</span> {</span><br><span class="line"> <span class="comment">// memos1.4.0以上版本请在下面的/api/后面加上v1,即/api/v1/memo?creatorId=1&tag=说说&limit=30</span></span><br><span class="line"> <span class="title function_">fetch</span>(<span class="string">'memos地址/api/v1/memo?creatorId=1&tag=说说&limit=30'</span>).<span class="title function_">then</span>(<span class="function"><span class="params">res</span> =></span> res.<span class="title function_">json</span>()).<span class="title function_">then</span>(<span class="function"><span class="params">data</span> =></span> { <span class="comment">// 更改地址和ID</span></span><br><span class="line"> <span class="comment">// memos1.4.0以上版本请删除掉下面的一个data,即data = toText(data)</span></span><br><span class="line"> data = <span class="title function_">toText</span>(data)</span><br><span class="line"> <span class="title function_">talk</span>(data);</span><br><span class="line"> <span class="title function_">saveData</span>(<span class="string">'talk'</span>, data);</span><br><span class="line"> })</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="title function_">indexTalk</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">// pjax注释掉上面的 indexTalk(); 使用如下方法:</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">whenDOMReady</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">indexTalk</span>();</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="title function_">whenDOMReady</span>()</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"pjax:complete"</span>, whenDOMReady)</span><br></pre></td></tr></table></figure><p>并且在css文件中天下如下代码,处理视频、音频和图片等的数据</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#bber-talk</span> <span class="selector-class">.item</span> <span class="selector-tag">i</span> {</span><br><span class="line"> <span class="attribute">margin-left</span>: <span class="number">5px</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>文章统计页面</title>
<link href="/posts/adff8459.html"/>
<url>/posts/adff8459.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>本文教程是来自<a href="https://blog.eurkon.com/">Eurkon</a>所发布的文章,更加详细的可以前往<a href="https://blog.eurkon.com/post/1213ef82.html#b7ce69f4cd8845738248b95c748f61d6">Hexo 博客文章统计图</a>中查看<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/articlechart/Snipaste_2023-10-25_13-09-13.webp"></p><h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>执行如下命令创建一个页面</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new page charts</span><br></pre></td></tr></table></figure><p>在 <strong>/themes/anzhiyu/scripts/helpers/</strong> 目录下新建 <strong>charts.js</strong> 文件,然后添加以下内容:</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> cheerio = <span class="built_in">require</span>(<span class="string">'cheerio'</span>)</span><br><span class="line"><span class="keyword">const</span> moment = <span class="built_in">require</span>(<span class="string">'moment'</span>)</span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">filter</span>.<span class="title function_">register</span>(<span class="string">'after_render:html'</span>, <span class="keyword">function</span> (<span class="params">locals</span>) {</span><br><span class="line"> <span class="keyword">const</span> $ = cheerio.<span class="title function_">load</span>(locals)</span><br><span class="line"> <span class="keyword">const</span> post = $(<span class="string">'#posts-chart'</span>)</span><br><span class="line"> <span class="keyword">const</span> tag = $(<span class="string">'#tags-chart'</span>)</span><br><span class="line"> <span class="keyword">const</span> category = $(<span class="string">'#categories-chart'</span>)</span><br><span class="line"> <span class="keyword">const</span> htmlEncode = <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (post.<span class="property">length</span> > <span class="number">0</span> || tag.<span class="property">length</span> > <span class="number">0</span> || category.<span class="property">length</span> > <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">if</span> (post.<span class="property">length</span> > <span class="number">0</span> && $(<span class="string">'#postsChart'</span>).<span class="property">length</span> === <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">if</span> (post.<span class="title function_">attr</span>(<span class="string">'data-encode'</span>) === <span class="string">'true'</span>) htmlEncode = <span class="literal">true</span></span><br><span class="line"> post.<span class="title function_">after</span>(<span class="title function_">postsChart</span>(post.<span class="title function_">attr</span>(<span class="string">'data-start'</span>)))</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (tag.<span class="property">length</span> > <span class="number">0</span> && $(<span class="string">'#tagsChart'</span>).<span class="property">length</span> === <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">if</span> (tag.<span class="title function_">attr</span>(<span class="string">'data-encode'</span>) === <span class="string">'true'</span>) htmlEncode = <span class="literal">true</span></span><br><span class="line"> tag.<span class="title function_">after</span>(<span class="title function_">tagsChart</span>(tag.<span class="title function_">attr</span>(<span class="string">'data-length'</span>)))</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (category.<span class="property">length</span> > <span class="number">0</span> && $(<span class="string">'#categoriesChart'</span>).<span class="property">length</span> === <span class="number">0</span>) {</span><br><span class="line"> <span class="keyword">if</span> (category.<span class="title function_">attr</span>(<span class="string">'data-encode'</span>) === <span class="string">'true'</span>) htmlEncode = <span class="literal">true</span></span><br><span class="line"> category.<span class="title function_">after</span>(<span class="title function_">categoriesChart</span>(category.<span class="title function_">attr</span>(<span class="string">'data-parent'</span>)))</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> (htmlEncode) {</span><br><span class="line"> <span class="keyword">return</span> $.<span class="title function_">root</span>().<span class="title function_">html</span>().<span class="title function_">replace</span>(<span class="regexp">/&amp;#/g</span>, <span class="string">'&#'</span>)</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> <span class="keyword">return</span> $.<span class="title function_">root</span>().<span class="title function_">html</span>()</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> <span class="keyword">return</span> locals</span><br><span class="line"> }</span><br><span class="line">}, <span class="number">15</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">postsChart</span> (startMonth) {</span><br><span class="line"> <span class="keyword">const</span> startDate = <span class="title function_">moment</span>(startMonth || <span class="string">'2020-01'</span>)</span><br><span class="line"> <span class="keyword">const</span> endDate = <span class="title function_">moment</span>()</span><br><span class="line"></span><br><span class="line"> <span class="keyword">const</span> monthMap = <span class="keyword">new</span> <span class="title class_">Map</span>()</span><br><span class="line"> <span class="keyword">const</span> dayTime = <span class="number">3600</span> * <span class="number">24</span> * <span class="number">1000</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">let</span> time = startDate; time <= endDate; time += dayTime) {</span><br><span class="line"> <span class="keyword">const</span> month = <span class="title function_">moment</span>(time).<span class="title function_">format</span>(<span class="string">'YYYY-MM'</span>)</span><br><span class="line"> <span class="keyword">if</span> (!monthMap.<span class="title function_">has</span>(month)) {</span><br><span class="line"> monthMap.<span class="title function_">set</span>(month, <span class="number">0</span>)</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> hexo.<span class="property">locals</span>.<span class="title function_">get</span>(<span class="string">'posts'</span>).<span class="title function_">forEach</span>(<span class="keyword">function</span> (<span class="params">post</span>) {</span><br><span class="line"> <span class="keyword">const</span> month = post.<span class="property">date</span>.<span class="title function_">format</span>(<span class="string">'YYYY-MM'</span>)</span><br><span class="line"> <span class="keyword">if</span> (monthMap.<span class="title function_">has</span>(month)) {</span><br><span class="line"> monthMap.<span class="title function_">set</span>(month, monthMap.<span class="title function_">get</span>(month) + <span class="number">1</span>)</span><br><span class="line"> }</span><br><span class="line"> })</span><br><span class="line"> <span class="keyword">const</span> monthArr = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>([...monthMap.<span class="title function_">keys</span>()])</span><br><span class="line"> <span class="keyword">const</span> monthValueArr = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>([...monthMap.<span class="title function_">values</span>()])</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="string">`</span></span><br><span class="line"><span class="string"> <script id="postsChart"></span></span><br><span class="line"><span class="string"> var color = document.documentElement.getAttribute('data-theme') === 'light' ? '#4c4948' : 'rgba(255,255,255,0.7)'</span></span><br><span class="line"><span class="string"> var postsChart = echarts.init(document.getElementById('posts-chart'), 'light');</span></span><br><span class="line"><span class="string"> var postsOption = {</span></span><br><span class="line"><span class="string"> title: {</span></span><br><span class="line"><span class="string"> text: '文章发布统计图',</span></span><br><span class="line"><span class="string"> x: 'center',</span></span><br><span class="line"><span class="string"> textStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> tooltip: {</span></span><br><span class="line"><span class="string"> trigger: 'axis'</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> xAxis: {</span></span><br><span class="line"><span class="string"> name: '日期',</span></span><br><span class="line"><span class="string"> type: 'category',</span></span><br><span class="line"><span class="string"> boundaryGap: false,</span></span><br><span class="line"><span class="string"> nameTextStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisTick: {</span></span><br><span class="line"><span class="string"> show: false</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLabel: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLine: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> lineStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> data: <span class="subst">${monthArr}</span></span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> yAxis: {</span></span><br><span class="line"><span class="string"> name: '文章篇数',</span></span><br><span class="line"><span class="string"> type: 'value',</span></span><br><span class="line"><span class="string"> nameTextStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> splitLine: {</span></span><br><span class="line"><span class="string"> show: false</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisTick: {</span></span><br><span class="line"><span class="string"> show: false</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLabel: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLine: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> lineStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> series: [{</span></span><br><span class="line"><span class="string"> name: '文章篇数',</span></span><br><span class="line"><span class="string"> type: 'line',</span></span><br><span class="line"><span class="string"> smooth: true,</span></span><br><span class="line"><span class="string"> lineStyle: {</span></span><br><span class="line"><span class="string"> width: 0</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> showSymbol: false,</span></span><br><span class="line"><span class="string"> itemStyle: {</span></span><br><span class="line"><span class="string"> opacity: 1,</span></span><br><span class="line"><span class="string"> color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{</span></span><br><span class="line"><span class="string"> offset: 0,</span></span><br><span class="line"><span class="string"> color: 'rgba(128, 255, 165)'</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> {</span></span><br><span class="line"><span class="string"> offset: 1,</span></span><br><span class="line"><span class="string"> color: 'rgba(1, 191, 236)'</span></span><br><span class="line"><span class="string"> }])</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> areaStyle: {</span></span><br><span class="line"><span class="string"> opacity: 1,</span></span><br><span class="line"><span class="string"> color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{</span></span><br><span class="line"><span class="string"> offset: 0,</span></span><br><span class="line"><span class="string"> color: 'rgba(128, 255, 165)'</span></span><br><span class="line"><span class="string"> }, {</span></span><br><span class="line"><span class="string"> offset: 1,</span></span><br><span class="line"><span class="string"> color: 'rgba(1, 191, 236)'</span></span><br><span class="line"><span class="string"> }])</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> data: <span class="subst">${monthValueArr}</span>,</span></span><br><span class="line"><span class="string"> markLine: {</span></span><br><span class="line"><span class="string"> data: [{</span></span><br><span class="line"><span class="string"> name: '平均值',</span></span><br><span class="line"><span class="string"> type: 'average',</span></span><br><span class="line"><span class="string"> label: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }]</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }]</span></span><br><span class="line"><span class="string"> };</span></span><br><span class="line"><span class="string"> postsChart.setOption(postsOption);</span></span><br><span class="line"><span class="string"> window.addEventListener('resize', () => { </span></span><br><span class="line"><span class="string"> postsChart.resize();</span></span><br><span class="line"><span class="string"> });</span></span><br><span class="line"><span class="string"> postsChart.on('click', 'series', (event) => {</span></span><br><span class="line"><span class="string"> if (event.componentType === 'series') window.location.href = '/archives/' + event.name.replace('-', '/');</span></span><br><span class="line"><span class="string"> });</span></span><br><span class="line"><span class="string"> </script>`</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">tagsChart</span> (len) {</span><br><span class="line"> <span class="keyword">const</span> tagArr = []</span><br><span class="line"> hexo.<span class="property">locals</span>.<span class="title function_">get</span>(<span class="string">'tags'</span>).<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">tag</span>) {</span><br><span class="line"> tagArr.<span class="title function_">push</span>({ <span class="attr">name</span>: tag.<span class="property">name</span>, <span class="attr">value</span>: tag.<span class="property">length</span>, <span class="attr">path</span>: tag.<span class="property">path</span> })</span><br><span class="line"> })</span><br><span class="line"> tagArr.<span class="title function_">sort</span>(<span class="function">(<span class="params">a, b</span>) =></span> { <span class="keyword">return</span> b.<span class="property">value</span> - a.<span class="property">value</span> })</span><br><span class="line"></span><br><span class="line"> <span class="keyword">const</span> dataLength = <span class="title class_">Math</span>.<span class="title function_">min</span>(tagArr.<span class="property">length</span>, len) || tagArr.<span class="property">length</span></span><br><span class="line"> <span class="keyword">const</span> tagNameArr = []</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i < dataLength; i++) {</span><br><span class="line"> tagNameArr.<span class="title function_">push</span>(tagArr[i].<span class="property">name</span>)</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">const</span> tagNameArrJson = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(tagNameArr)</span><br><span class="line"> <span class="keyword">const</span> tagArrJson = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(tagArr)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="string">`</span></span><br><span class="line"><span class="string"> <script id="tagsChart"></span></span><br><span class="line"><span class="string"> var color = document.documentElement.getAttribute('data-theme') === 'light' ? '#4c4948' : 'rgba(255,255,255,0.7)'</span></span><br><span class="line"><span class="string"> var tagsChart = echarts.init(document.getElementById('tags-chart'), 'light');</span></span><br><span class="line"><span class="string"> var tagsOption = {</span></span><br><span class="line"><span class="string"> title: {</span></span><br><span class="line"><span class="string"> text: 'Top <span class="subst">${dataLength}</span> 标签统计图',</span></span><br><span class="line"><span class="string"> x: 'center',</span></span><br><span class="line"><span class="string"> textStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> tooltip: {},</span></span><br><span class="line"><span class="string"> xAxis: {</span></span><br><span class="line"><span class="string"> name: '标签',</span></span><br><span class="line"><span class="string"> type: 'category',</span></span><br><span class="line"><span class="string"> nameTextStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisTick: {</span></span><br><span class="line"><span class="string"> show: false</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLabel: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> color: color,</span></span><br><span class="line"><span class="string"> interval: 0</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLine: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> lineStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> data: <span class="subst">${tagNameArrJson}</span></span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> yAxis: {</span></span><br><span class="line"><span class="string"> name: '文章篇数',</span></span><br><span class="line"><span class="string"> type: 'value',</span></span><br><span class="line"><span class="string"> splitLine: {</span></span><br><span class="line"><span class="string"> show: false</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> nameTextStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisTick: {</span></span><br><span class="line"><span class="string"> show: false</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLabel: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> axisLine: {</span></span><br><span class="line"><span class="string"> show: true,</span></span><br><span class="line"><span class="string"> lineStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> series: [{</span></span><br><span class="line"><span class="string"> name: '文章篇数',</span></span><br><span class="line"><span class="string"> type: 'bar',</span></span><br><span class="line"><span class="string"> data: <span class="subst">${tagArrJson}</span>,</span></span><br><span class="line"><span class="string"> itemStyle: {</span></span><br><span class="line"><span class="string"> borderRadius: [5, 5, 0, 0],</span></span><br><span class="line"><span class="string"> color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{</span></span><br><span class="line"><span class="string"> offset: 0,</span></span><br><span class="line"><span class="string"> color: 'rgba(128, 255, 165)'</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> {</span></span><br><span class="line"><span class="string"> offset: 1,</span></span><br><span class="line"><span class="string"> color: 'rgba(1, 191, 236)'</span></span><br><span class="line"><span class="string"> }])</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> emphasis: {</span></span><br><span class="line"><span class="string"> itemStyle: {</span></span><br><span class="line"><span class="string"> color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{</span></span><br><span class="line"><span class="string"> offset: 0,</span></span><br><span class="line"><span class="string"> color: 'rgba(128, 255, 195)'</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> {</span></span><br><span class="line"><span class="string"> offset: 1,</span></span><br><span class="line"><span class="string"> color: 'rgba(1, 211, 255)'</span></span><br><span class="line"><span class="string"> }])</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> markLine: {</span></span><br><span class="line"><span class="string"> data: [{</span></span><br><span class="line"><span class="string"> name: '平均值',</span></span><br><span class="line"><span class="string"> type: 'average',</span></span><br><span class="line"><span class="string"> label: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }]</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }]</span></span><br><span class="line"><span class="string"> };</span></span><br><span class="line"><span class="string"> tagsChart.setOption(tagsOption);</span></span><br><span class="line"><span class="string"> window.addEventListener('resize', () => { </span></span><br><span class="line"><span class="string"> tagsChart.resize();</span></span><br><span class="line"><span class="string"> });</span></span><br><span class="line"><span class="string"> tagsChart.on('click', 'series', (event) => {</span></span><br><span class="line"><span class="string"> if(event.data.path) window.location.href = '/' + event.data.path;</span></span><br><span class="line"><span class="string"> });</span></span><br><span class="line"><span class="string"> </script>`</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">categoriesChart</span> (dataParent) {</span><br><span class="line"> <span class="keyword">const</span> categoryArr = []</span><br><span class="line"> <span class="keyword">let</span> categoryParentFlag = <span class="literal">false</span></span><br><span class="line"> hexo.<span class="property">locals</span>.<span class="title function_">get</span>(<span class="string">'categories'</span>).<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">category</span>) {</span><br><span class="line"> <span class="keyword">if</span> (category.<span class="property">parent</span>) categoryParentFlag = <span class="literal">true</span></span><br><span class="line"> categoryArr.<span class="title function_">push</span>({</span><br><span class="line"> <span class="attr">name</span>: category.<span class="property">name</span>,</span><br><span class="line"> <span class="attr">value</span>: category.<span class="property">length</span>,</span><br><span class="line"> <span class="attr">path</span>: category.<span class="property">path</span>,</span><br><span class="line"> <span class="attr">id</span>: category.<span class="property">_id</span>,</span><br><span class="line"> <span class="attr">parentId</span>: category.<span class="property">parent</span> || <span class="string">'0'</span></span><br><span class="line"> })</span><br><span class="line"> })</span><br><span class="line"> categoryParentFlag = categoryParentFlag && dataParent === <span class="string">'true'</span></span><br><span class="line"> categoryArr.<span class="title function_">sort</span>(<span class="function">(<span class="params">a, b</span>) =></span> { <span class="keyword">return</span> b.<span class="property">value</span> - a.<span class="property">value</span> })</span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">translateListToTree</span> (data, parent) {</span><br><span class="line"> <span class="keyword">let</span> tree = []</span><br><span class="line"> <span class="keyword">let</span> temp</span><br><span class="line"> data.<span class="title function_">forEach</span>(<span class="function">(<span class="params">item, index</span>) =></span> {</span><br><span class="line"> <span class="keyword">if</span> (data[index].<span class="property">parentId</span> == parent) {</span><br><span class="line"> <span class="keyword">let</span> obj = data[index];</span><br><span class="line"> temp = <span class="title function_">translateListToTree</span>(data, data[index].<span class="property">id</span>);</span><br><span class="line"> <span class="keyword">if</span> (temp.<span class="property">length</span> > <span class="number">0</span>) {</span><br><span class="line"> obj.<span class="property">children</span> = temp</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (tree.<span class="title function_">indexOf</span>())</span><br><span class="line"> tree.<span class="title function_">push</span>(obj)</span><br><span class="line"> }</span><br><span class="line"> })</span><br><span class="line"> <span class="keyword">return</span> tree</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">const</span> categoryNameJson = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(categoryArr.<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">category</span>) { <span class="keyword">return</span> category.<span class="property">name</span> }))</span><br><span class="line"> <span class="keyword">const</span> categoryArrJson = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(categoryArr)</span><br><span class="line"> <span class="keyword">const</span> categoryArrParentJson = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(<span class="title function_">translateListToTree</span>(categoryArr, <span class="string">'0'</span>))</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="string">`</span></span><br><span class="line"><span class="string"> <script id="categoriesChart"></span></span><br><span class="line"><span class="string"> var color = document.documentElement.getAttribute('data-theme') === 'light' ? '#4c4948' : 'rgba(255,255,255,0.7)'</span></span><br><span class="line"><span class="string"> var categoriesChart = echarts.init(document.getElementById('categories-chart'), 'light');</span></span><br><span class="line"><span class="string"> var categoryParentFlag = <span class="subst">${categoryParentFlag}</span></span></span><br><span class="line"><span class="string"> var categoriesOption = {</span></span><br><span class="line"><span class="string"> title: {</span></span><br><span class="line"><span class="string"> text: '文章分类统计图',</span></span><br><span class="line"><span class="string"> x: 'center',</span></span><br><span class="line"><span class="string"> textStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> legend: {</span></span><br><span class="line"><span class="string"> top: 'bottom',</span></span><br><span class="line"><span class="string"> data: <span class="subst">${categoryNameJson}</span>,</span></span><br><span class="line"><span class="string"> textStyle: {</span></span><br><span class="line"><span class="string"> color: color</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> tooltip: {</span></span><br><span class="line"><span class="string"> trigger: 'item'</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> series: []</span></span><br><span class="line"><span class="string"> };</span></span><br><span class="line"><span class="string"> categoriesOption.series.push(</span></span><br><span class="line"><span class="string"> categoryParentFlag ? </span></span><br><span class="line"><span class="string"> {</span></span><br><span class="line"><span class="string"> nodeClick :false,</span></span><br><span class="line"><span class="string"> name: '文章篇数',</span></span><br><span class="line"><span class="string"> type: 'sunburst',</span></span><br><span class="line"><span class="string"> radius: ['15%', '90%'],</span></span><br><span class="line"><span class="string"> center: ['50%', '55%'],</span></span><br><span class="line"><span class="string"> sort: 'desc',</span></span><br><span class="line"><span class="string"> data: <span class="subst">${categoryArrParentJson}</span>,</span></span><br><span class="line"><span class="string"> itemStyle: {</span></span><br><span class="line"><span class="string"> borderColor: '#fff',</span></span><br><span class="line"><span class="string"> borderWidth: 2,</span></span><br><span class="line"><span class="string"> emphasis: {</span></span><br><span class="line"><span class="string"> focus: 'ancestor',</span></span><br><span class="line"><span class="string"> shadowBlur: 10,</span></span><br><span class="line"><span class="string"> shadowOffsetX: 0,</span></span><br><span class="line"><span class="string"> shadowColor: 'rgba(255, 255, 255, 0.5)'</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> :</span></span><br><span class="line"><span class="string"> {</span></span><br><span class="line"><span class="string"> name: '文章篇数',</span></span><br><span class="line"><span class="string"> type: 'pie',</span></span><br><span class="line"><span class="string"> radius: [30, 80],</span></span><br><span class="line"><span class="string"> roseType: 'area',</span></span><br><span class="line"><span class="string"> label: {</span></span><br><span class="line"><span class="string"> color: color,</span></span><br><span class="line"><span class="string"> formatter: '{b} : {c} ({d}%)'</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> data: <span class="subst">${categoryArrJson}</span>,</span></span><br><span class="line"><span class="string"> itemStyle: {</span></span><br><span class="line"><span class="string"> emphasis: {</span></span><br><span class="line"><span class="string"> shadowBlur: 10,</span></span><br><span class="line"><span class="string"> shadowOffsetX: 0,</span></span><br><span class="line"><span class="string"> shadowColor: 'rgba(255, 255, 255, 0.5)'</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> )</span></span><br><span class="line"><span class="string"> categoriesChart.setOption(categoriesOption);</span></span><br><span class="line"><span class="string"> window.addEventListener('resize', () => { </span></span><br><span class="line"><span class="string"> categoriesChart.resize();</span></span><br><span class="line"><span class="string"> });</span></span><br><span class="line"><span class="string"> categoriesChart.on('click', 'series', (event) => {</span></span><br><span class="line"><span class="string"> if(event.data.path) window.location.href = '/' + event.data.path;</span></span><br><span class="line"><span class="string"> });</span></span><br><span class="line"><span class="string"> </script>`</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>更多统计图的自定义属性可以查看 <a href="https://echarts.apache.org/zh/option.html#title">ECharts 配置项文档</a>,根据自行喜好对 ECharts 统计图进行修改</p><p>在 <strong>/charts/index.md</strong> 这个文件中添加以下内容:</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><!-- 文章发布时间统计图 --></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"posts-chart"</span> <span class="attr">data-start</span>=<span class="string">"2023-01"</span> <span class="attr">style</span>=<span class="string">"border-radius: 8px; height: 300px; padding: 10px;"</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span><br><span class="line"><!-- 文章标签统计图 --></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"tags-chart"</span> <span class="attr">data-length</span>=<span class="string">"10"</span> <span class="attr">style</span>=<span class="string">"border-radius: 8px; height: 300px; padding: 10px;"</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span><br><span class="line"><!-- 文章分类统计图 --></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">div</span> <span class="attr">id</span>=<span class="string">"categories-chart"</span> <span class="attr">data-parent</span>=<span class="string">"true"</span> <span class="attr">style</span>=<span class="string">"border-radius: 8px; height: 300px; padding: 10px;"</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">div</span>></span></span></span><br></pre></td></tr></table></figure><h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><ul><li><p>控制台报错 <strong>Cannot find module ‘cheerio’</strong><br>解决方法:安装 <strong>cheerio</strong>,在控制台中执行 <strong>npm i cheerio –save</strong></p></li><li><p>第一次进入页面没显示统计图<br>解决方法:在主题配置文件 <strong>_config.anzhiyu.yml</strong> 中引入 <strong>echarts.min.js</strong> 文件</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">inject:</span></span><br><span class="line"> <span class="attr">head:</span></span><br><span class="line"> <span class="attr">bottom:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><script</span> <span class="string">src="https://npm.elemecdn.com/[email protected]/dist/echarts.min.js"></script></span></span><br></pre></td></tr></table></figure><p>引入后第一次进入没什么问题,但是在刷新后控制台会出现 <span class='p red'>Uncaught ReferenceError: echarts is not defined</span> 这个问题,可以在你的统计页面再引入该文件即可解决</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="language-xml"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"https://npm.elemecdn.com/[email protected]/dist/echarts.min.js"</span>></span></span><span class="language-xml"><span class="tag"></<span class="name">script</span>></span></span></span><br></pre></td></tr></table></figure></li></ul>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>Github上传主题文件</title>
<link href="/posts/257f258a.html"/>
<url>/posts/257f258a.html</url>
<content type="html"><![CDATA[<blockquote><p>参考自:<a href="https://blog.csdn.net/liaoweilin0529/article/details/113650333">Hexo主题themes-文件夹无法提交到GitHub的解决方法</a></p></blockquote><h2 id="所遇问题"><a href="#所遇问题" class="headerlink" title="所遇问题"></a>所遇问题</h2><p>在 Github 上发现上传的博客文件唯独 <strong>主题文件</strong> 没有真正上传。通过百度了解到是因为 <strong>themes/anzhiyu</strong> 也是从仓库里拉取下来的,他关联到了作者的 git 仓库,所以才提交不上去</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">C:\Users\WeiLin\Desktop\weilin-liao.github (master -> origin)</span><br><span class="line">λ git status</span><br><span class="line">On branch master</span><br><span class="line">Your branch is up to date with 'origin/master'.</span><br><span class="line"></span><br><span class="line">Changes not staged for commit:</span><br><span class="line"> (use "git add <file>..." to update what will be committed)</span><br><span class="line"> (use "git restore <file>..." to discard changes in working directory)</span><br><span class="line"> (commit or discard the untracked or modified content in submodules)</span><br><span class="line"> modified: themes/hexo-theme-icarus (modified content, untracked content)</span><br><span class="line"></span><br><span class="line">no changes added to commit (use "git add" and/or "git commit -a")</span><br></pre></td></tr></table></figure><h2 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h2><p>删除暂存区的该文件夹,其中 <strong>主题文件名</strong> 填写你自已的</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">rm</span> --cache themes/主题文件名</span><br></pre></td></tr></table></figure><p>移除相应文件或文件夹,例如我将 <strong>themes/anzhiyu/.git</strong> 文件夹移动到桌面上去,同时 <strong>.gitignore</strong> 里的 <strong>_config</strong> 去掉</p><blockquote><p>没有这些可以不用理会该步</p></blockquote><p>通过 <strong>git status</strong> 查看当前状态</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">C:\Users\WeiLin\Desktop\weilin-liao.github (master -> origin)</span><br><span class="line">λ git status</span><br><span class="line">On branch master</span><br><span class="line">Your branch is up to date with 'origin/master'.</span><br><span class="line"></span><br><span class="line">Changes to be committed:</span><br><span class="line"> (use "git restore --staged <file>..." to unstage)</span><br><span class="line"> deleted: themes/hexo-theme-icarus</span><br><span class="line"></span><br><span class="line">Untracked files:</span><br><span class="line"> (use "git add <file>..." to include in what will be committed)</span><br><span class="line"> themes/</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category> 技术教程 </category>
</categories>
<tags>
<tag> 主题文件 </tag>
</tags>
</entry>
<entry>
<title>侧边栏欢迎语</title>
<link href="/posts/37d43a26.html"/>
<url>/posts/37d43a26.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>为博客的<strong>侧边栏</strong>添加一个欢迎语。本篇文章原教程来自 <strong>Kouseki</strong> 所发布的 <a href="https://blog.kouseki.cn/posts/da2a.html">在侧边栏添加个性定位欢迎信息</a><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/asidewelcome/Snipaste_2023-10-25_13-01-28.webp"></p><h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>在 <a href="https://lbs.qq.com/dev/console/application/mine">腾讯位置服务</a> 中先<strong>创建应用</strong>,其中<strong>应用名称</strong>和 <strong>应用类型</strong>可以随意填写。然后点击<strong>添加Key</strong>,勾选<strong>WebServiceAPI</strong>。其中<strong>Key名称</strong>和<strong>描述</strong>可任意填写,<strong>添加</strong>后会生成一个 <strong>Key</strong></p><blockquote><p>这里面的白名单 <strong>localhost</strong> 是有效的,需带上端口号,记得<strong>填上自己域名</strong></p></blockquote><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/asidewelcome/Snipaste_2023-10-15_18-23-45.webp"></p><p>新建 <strong>welcome.js</strong> 文件,并粘贴如下代码:</p><blockquote><p>在<strong>第6行</strong>及<strong>第32行</strong>分别填入自己的 <strong>Key</strong> 和 <strong>经纬度</strong></p></blockquote><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//get请求</span></span><br><span class="line">$.<span class="title function_">ajax</span>({</span><br><span class="line"> <span class="attr">type</span>: <span class="string">'get'</span>,</span><br><span class="line"> <span class="attr">url</span>: <span class="string">'https://apis.map.qq.com/ws/location/v1/ip'</span>,</span><br><span class="line"> <span class="attr">data</span>: {</span><br><span class="line"> <span class="attr">key</span>: <span class="string">'你刚刚获取到的Key'</span>,</span><br><span class="line"> <span class="attr">output</span>: <span class="string">'jsonp'</span>,</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">dataType</span>: <span class="string">'jsonp'</span>,</span><br><span class="line"> <span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">res</span>) {</span><br><span class="line"> ipLocation = res;</span><br><span class="line"> }</span><br><span class="line">})</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getDistance</span>(<span class="params">e1, n1, e2, n2</span>) {</span><br><span class="line"> <span class="keyword">const</span> R = <span class="number">6371</span></span><br><span class="line"> <span class="keyword">const</span> { sin, cos, asin, <span class="variable constant_">PI</span>, hypot } = <span class="title class_">Math</span></span><br><span class="line"> <span class="keyword">let</span> <span class="title function_">getPoint</span> = (<span class="params">e, n</span>) => {</span><br><span class="line"> e *= <span class="variable constant_">PI</span> / <span class="number">180</span></span><br><span class="line"> n *= <span class="variable constant_">PI</span> / <span class="number">180</span></span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">x</span>: <span class="title function_">cos</span>(n) * <span class="title function_">cos</span>(e), <span class="attr">y</span>: <span class="title function_">cos</span>(n) * <span class="title function_">sin</span>(e), <span class="attr">z</span>: <span class="title function_">sin</span>(n) }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> a = <span class="title function_">getPoint</span>(e1, n1)</span><br><span class="line"> <span class="keyword">let</span> b = <span class="title function_">getPoint</span>(e2, n2)</span><br><span class="line"> <span class="keyword">let</span> c = <span class="title function_">hypot</span>(a.<span class="property">x</span> - b.<span class="property">x</span>, a.<span class="property">y</span> - b.<span class="property">y</span>, a.<span class="property">z</span> - b.<span class="property">z</span>)</span><br><span class="line"> <span class="keyword">let</span> r = <span class="title function_">asin</span>(c / <span class="number">2</span>) * <span class="number">2</span> * R</span><br><span class="line"> <span class="keyword">return</span> <span class="title class_">Math</span>.<span class="title function_">round</span>(r);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">showWelcome</span>(<span class="params"></span>) {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> dist = <span class="title function_">getDistance</span>(<span class="number">114.21416</span>, <span class="number">22.576264</span>, ipLocation.<span class="property">result</span>.<span class="property">location</span>.<span class="property">lng</span>, ipLocation.<span class="property">result</span>.<span class="property">location</span>.<span class="property">lat</span>); <span class="comment">//这里记得换成自己的经纬度</span></span><br><span class="line"> <span class="keyword">let</span> pos = ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">nation</span>;</span><br><span class="line"> <span class="keyword">let</span> ip;</span><br><span class="line"> <span class="keyword">let</span> posdesc;</span><br><span class="line"> <span class="comment">//根据国家、省份、城市信息自定义欢迎语</span></span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">nation</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"日本"</span>:</span><br><span class="line"> posdesc = <span class="string">"よろしく,一起去看樱花吗"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"美国"</span>:</span><br><span class="line"> posdesc = <span class="string">"Let us live in peace!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"英国"</span>:</span><br><span class="line"> posdesc = <span class="string">"想同你一起夜乘伦敦眼"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"俄罗斯"</span>:</span><br><span class="line"> posdesc = <span class="string">"干了这瓶伏特加!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"法国"</span>:</span><br><span class="line"> posdesc = <span class="string">"C'est La Vie"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"德国"</span>:</span><br><span class="line"> posdesc = <span class="string">"Die Zeit verging im Fluge."</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"澳大利亚"</span>:</span><br><span class="line"> posdesc = <span class="string">"一起去大堡礁吧!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"加拿大"</span>:</span><br><span class="line"> posdesc = <span class="string">"拾起一片枫叶赠予你"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"中国"</span>:</span><br><span class="line"> pos = ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">province</span> + <span class="string">" "</span> + ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">city</span> + <span class="string">" "</span> + ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">district</span>;</span><br><span class="line"> ip = ipLocation.<span class="property">result</span>.<span class="property">ip</span>;</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">province</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"北京市"</span>:</span><br><span class="line"> posdesc = <span class="string">"北——京——欢迎你~~~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"天津市"</span>:</span><br><span class="line"> posdesc = <span class="string">"讲段相声吧"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"河北省"</span>:</span><br><span class="line"> posdesc = <span class="string">"山势巍巍成壁垒,天下雄关铁马金戈由此向,无限江山"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"山西省"</span>:</span><br><span class="line"> posdesc = <span class="string">"展开坐具长三尺,已占山河五百余"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"内蒙古自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"天苍苍,野茫茫,风吹草低见牛羊"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"辽宁省"</span>:</span><br><span class="line"> posdesc = <span class="string">"我想吃烤鸡架!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"吉林省"</span>:</span><br><span class="line"> posdesc = <span class="string">"状元阁就是东北烧烤之王"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"黑龙江省"</span>:</span><br><span class="line"> posdesc = <span class="string">"很喜欢哈尔滨大剧院"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"上海市"</span>:</span><br><span class="line"> posdesc = <span class="string">"众所周知,中国只有两个城市"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"江苏省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"南京市"</span>:</span><br><span class="line"> posdesc = <span class="string">"这是我挺想去的城市啦"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"苏州市"</span>:</span><br><span class="line"> posdesc = <span class="string">"上有天堂,下有苏杭"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"散装是必须要散装的"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"浙江省"</span>:</span><br><span class="line"> posdesc = <span class="string">"东风渐绿西湖柳,雁已还人未南归"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"河南省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"郑州市"</span>:</span><br><span class="line"> posdesc = <span class="string">"豫州之域,天地之中"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"南阳市"</span>:</span><br><span class="line"> posdesc = <span class="string">"臣本布衣,躬耕于南阳此南阳非彼南阳!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"驻马店市"</span>:</span><br><span class="line"> posdesc = <span class="string">"峰峰有奇石,石石挟仙气嵖岈山的花很美哦!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"开封市"</span>:</span><br><span class="line"> posdesc = <span class="string">"刚正不阿包青天"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"洛阳市"</span>:</span><br><span class="line"> posdesc = <span class="string">"洛阳牡丹甲天下"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"可否带我品尝河南烩面啦?"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"安徽省"</span>:</span><br><span class="line"> posdesc = <span class="string">"蚌埠住了,芜湖起飞"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"福建省"</span>:</span><br><span class="line"> posdesc = <span class="string">"井邑白云间,岩城远带山"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"江西省"</span>:</span><br><span class="line"> posdesc = <span class="string">"落霞与孤鹜齐飞,秋水共长天一色"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"山东省"</span>:</span><br><span class="line"> posdesc = <span class="string">"遥望齐州九点烟,一泓海水杯中泻"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"湖北省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"黄冈市"</span>:</span><br><span class="line"> posdesc = <span class="string">"红安将军县!辈出将才!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"来碗热干面~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"湖南省"</span>:</span><br><span class="line"> posdesc = <span class="string">"74751,长沙斯塔克"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"广东省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">result</span>.<span class="property">ad_info</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"广州市"</span>:</span><br><span class="line"> posdesc = <span class="string">"看小蛮腰,喝早茶了嘛~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"深圳市"</span>:</span><br><span class="line"> posdesc = <span class="string">"今天你逛商场了嘛~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"阳江市"</span>:</span><br><span class="line"> posdesc = <span class="string">"阳春合水!博主家乡~ 欢迎来玩~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"来两斤福建人~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"广西壮族自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"桂林山水甲天下"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"海南省"</span>:</span><br><span class="line"> posdesc = <span class="string">"朝观日出逐白浪,夕看云起收霞光"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"四川省"</span>:</span><br><span class="line"> posdesc = <span class="string">"康康川妹子"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"贵州省"</span>:</span><br><span class="line"> posdesc = <span class="string">"茅台,学生,再塞200"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"云南省"</span>:</span><br><span class="line"> posdesc = <span class="string">"玉龙飞舞云缠绕,万仞冰川直耸天"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"西藏自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"躺在茫茫草原上,仰望蓝天"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"陕西省"</span>:</span><br><span class="line"> posdesc = <span class="string">"来份臊子面加馍"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"甘肃省"</span>:</span><br><span class="line"> posdesc = <span class="string">"羌笛何须怨杨柳,春风不度玉门关"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"青海省"</span>:</span><br><span class="line"> posdesc = <span class="string">"牛肉干和老酸奶都好好吃"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"宁夏回族自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"大漠孤烟直,长河落日圆"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"新疆维吾尔自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"驼铃古道丝绸路,胡马犹闻唐汉风"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"台湾省"</span>:</span><br><span class="line"> posdesc = <span class="string">"我在这头,大陆在那头"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"香港特别行政区"</span>:</span><br><span class="line"> posdesc = <span class="string">"永定贼有残留地鬼嚎,迎击光非岁玉"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"澳门特别行政区"</span>:</span><br><span class="line"> posdesc = <span class="string">"性感荷官,在线发牌"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"带我去你的城市逛逛吧!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"带我去你的国家逛逛吧"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//根据本地时间切换欢迎语</span></span><br><span class="line"> <span class="keyword">let</span> timeChange;</span><br><span class="line"> <span class="keyword">let</span> date = <span class="keyword">new</span> <span class="title class_">Date</span>();</span><br><span class="line"> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">5</span> && date.<span class="title function_">getHours</span>() < <span class="number">11</span>) timeChange = <span class="string">"<span>🌤️ 早上好,一日之计在于晨</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">11</span> && date.<span class="title function_">getHours</span>() < <span class="number">13</span>) timeChange = <span class="string">"<span>☀️ 中午好,记得午休喔~</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">13</span> && date.<span class="title function_">getHours</span>() < <span class="number">17</span>) timeChange = <span class="string">"<span>🕞 下午好,饮茶先啦!</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">17</span> && date.<span class="title function_">getHours</span>() < <span class="number">19</span>) timeChange = <span class="string">"<span>🚶♂️ 即将下班,记得按时吃饭~</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">19</span> && date.<span class="title function_">getHours</span>() < <span class="number">24</span>) timeChange = <span class="string">"<span>🌙 晚上好,夜生活嗨起来!</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> timeChange = <span class="string">"夜深了,早点休息,少熬夜"</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="comment">//自定义文本和需要放的位置</span></span><br><span class="line"> <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">"welcome-info"</span>).<span class="property">innerHTML</span> =</span><br><span class="line"> <span class="string">`欢迎来自 <b><span style="color: var(--kouseki-ip-color);font-size: var(--kouseki-gl-size)"><span class="subst">${pos}</span></span></b> 的小友💖<br><span class="subst">${posdesc}</span>🍂<br>当前位置距博主约 <b><span style="color: var(--kouseki-ip-color)"><span class="subst">${dist}</span></span></b> 公里!<br>您的IP地址为:<b><span><span class="subst">${ip}</span></span></b><br><span class="subst">${timeChange}</span> <br>`</span>;</span><br><span class="line"> } <span class="keyword">catch</span> (err) {</span><br><span class="line"> <span class="comment">// console.log("Pjax无法获取元素")</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="variable language_">window</span>.<span class="property">onload</span> = showWelcome;</span><br><span class="line"><span class="comment">// 如果使用了pjax在加上下面这行代码</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">'pjax:complete'</span>, showWelcome);</span><br></pre></td></tr></table></figure><p>新建 <strong>welcome.css</strong> 文件,并粘贴如下代码:</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#welcome-info</span> {</span><br><span class="line"> <span class="attribute">overflow</span>: hidden;</span><br><span class="line"> <span class="attribute">border-radius</span>: <span class="number">14px</span>;</span><br><span class="line"> <span class="attr">--kouseki-welcome-color</span>: <span class="number">#49B1F5</span>;</span><br><span class="line"> <span class="attr">--kouseki-ip-color</span>: <span class="number">#49B1F5</span>;</span><br><span class="line"> <span class="attr">--kouseki-gl-size</span>: <span class="number">16px</span><span class="meta">!important</span>;</span><br><span class="line"> }</span><br></pre></td></tr></table></figure><p>在主题配置文件 <strong>_config.anzhiyu.yml</strong> 中引入这两个文件</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">inject:</span></span><br><span class="line"> <span class="attr">head:</span></span><br><span class="line"> <span class="comment"># 侧边栏欢迎语</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><link</span> <span class="string">rel="stylesheet"</span> <span class="string">href="/css/welcome.css"></span></span><br><span class="line"></span><br><span class="line"> <span class="attr">bottom:</span></span><br><span class="line"> <span class="comment"># 侧边栏欢迎语</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><script</span> <span class="string">type="text/javascript"</span> <span class="string">src="https://unpkg.zhimg.com/jquery@latest/dist/jquery.min.js"></script></span> <span class="comment"># jquery.min.js</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string"><script</span> <span class="string">src="/js/welcome.js"></script></span></span><br></pre></td></tr></table></figure><h2 id="后续"><a href="#后续" class="headerlink" title="后续"></a>后续</h2><p><strong>2023年12月5日凌晨</strong>在 <a href="https://blog.qjqq.cn/posts/2a52.html">Hexo的Butterfly魔改教程:侧边栏添加个性定位欢迎信息</a> 查看到另外一种实现方式并<strong>精确</strong>获取了自已的经纬度</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//get请求</span></span><br><span class="line"><span class="title function_">fetch</span>(<span class="string">'https://api.qjqq.cn/api/Local'</span>)</span><br><span class="line"> .<span class="title function_">then</span>(<span class="function"><span class="params">response</span> =></span> response.<span class="title function_">json</span>())</span><br><span class="line"> .<span class="title function_">then</span>(<span class="function"><span class="params">data</span> =></span> {</span><br><span class="line"> ipLocation = data;</span><br><span class="line"> <span class="title function_">showWelcome</span>();</span><br><span class="line"> })</span><br><span class="line"> .<span class="title function_">catch</span>(<span class="function"><span class="params">error</span> =></span> <span class="variable language_">console</span>.<span class="title function_">error</span>(<span class="string">'Error:'</span>, error));</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getDistance</span>(<span class="params">e1, n1, e2, n2</span>) {</span><br><span class="line"> <span class="keyword">const</span> R = <span class="number">6371</span>;</span><br><span class="line"> <span class="keyword">const</span> { sin, cos, asin, <span class="variable constant_">PI</span>, hypot } = <span class="title class_">Math</span>;</span><br><span class="line"> <span class="keyword">let</span> <span class="title function_">getPoint</span> = (<span class="params">e, n</span>) => {</span><br><span class="line"> e *= <span class="variable constant_">PI</span> / <span class="number">180</span>;</span><br><span class="line"> n *= <span class="variable constant_">PI</span> / <span class="number">180</span>;</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">x</span>: <span class="title function_">cos</span>(n) * <span class="title function_">cos</span>(e), <span class="attr">y</span>: <span class="title function_">cos</span>(n) * <span class="title function_">sin</span>(e), <span class="attr">z</span>: <span class="title function_">sin</span>(n) };</span><br><span class="line"> };</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> a = <span class="title function_">getPoint</span>(e1, n1);</span><br><span class="line"> <span class="keyword">let</span> b = <span class="title function_">getPoint</span>(e2, n2);</span><br><span class="line"> <span class="keyword">let</span> c = <span class="title function_">hypot</span>(a.<span class="property">x</span> - b.<span class="property">x</span>, a.<span class="property">y</span> - b.<span class="property">y</span>, a.<span class="property">z</span> - b.<span class="property">z</span>);</span><br><span class="line"> <span class="keyword">let</span> r = <span class="title function_">asin</span>(c / <span class="number">2</span>) * <span class="number">2</span> * R;</span><br><span class="line"> <span class="keyword">return</span> <span class="title class_">Math</span>.<span class="title function_">round</span>(r);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">showWelcome</span>(<span class="params"></span>) {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">let</span> dist = <span class="title function_">getDistance</span>(<span class="number">121.413921</span>, <span class="number">31.089290</span>, ipLocation.<span class="property">data</span>.<span class="property">lng</span>, ipLocation.<span class="property">data</span>.<span class="property">lat</span>); <span class="comment">//修改自己的经度(121.413921)纬度(31.089290)</span></span><br><span class="line"> <span class="keyword">let</span> pos = ipLocation.<span class="property">data</span>.<span class="property">country</span>;</span><br><span class="line"> <span class="keyword">let</span> ip = ipLocation.<span class="property">ip</span>;</span><br><span class="line"> <span class="keyword">let</span> posdesc;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 以下的代码需要根据新API返回的结果进行相应的调整</span></span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">data</span>.<span class="property">country</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"日本"</span>:</span><br><span class="line"> posdesc = <span class="string">"よろしく,一起去看樱花吗"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"美国"</span>:</span><br><span class="line"> posdesc = <span class="string">"Let us live in peace!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"英国"</span>:</span><br><span class="line"> posdesc = <span class="string">"想同你一起夜乘伦敦眼"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"俄罗斯"</span>:</span><br><span class="line"> posdesc = <span class="string">"干了这瓶伏特加!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"法国"</span>:</span><br><span class="line"> posdesc = <span class="string">"C'est La Vie"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"德国"</span>:</span><br><span class="line"> posdesc = <span class="string">"Die Zeit verging im Fluge."</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"澳大利亚"</span>:</span><br><span class="line"> posdesc = <span class="string">"一起去大堡礁吧!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"加拿大"</span>:</span><br><span class="line"> posdesc = <span class="string">"拾起一片枫叶赠予你"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"中国"</span>:</span><br><span class="line"> pos = ipLocation.<span class="property">data</span>.<span class="property">prov</span> + <span class="string">" "</span> + ipLocation.<span class="property">data</span>.<span class="property">city</span> + <span class="string">" "</span> + ipLocation.<span class="property">data</span>.<span class="property">district</span>;</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">data</span>.<span class="property">prov</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"北京市"</span>:</span><br><span class="line"> posdesc = <span class="string">"北——京——欢迎你~~~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"天津市"</span>:</span><br><span class="line"> posdesc = <span class="string">"讲段相声吧"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"河北省"</span>:</span><br><span class="line"> posdesc = <span class="string">"山势巍巍成壁垒,天下雄关铁马金戈由此向,无限江山"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"山西省"</span>:</span><br><span class="line"> posdesc = <span class="string">"展开坐具长三尺,已占山河五百余"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"内蒙古自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"天苍苍,野茫茫,风吹草低见牛羊"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"辽宁省"</span>:</span><br><span class="line"> posdesc = <span class="string">"我想吃烤鸡架!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"吉林省"</span>:</span><br><span class="line"> posdesc = <span class="string">"状元阁就是东北烧烤之王"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"黑龙江省"</span>:</span><br><span class="line"> posdesc = <span class="string">"很喜欢哈尔滨大剧院"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"上海市"</span>:</span><br><span class="line"> posdesc = <span class="string">"众所周知,中国只有两个城市"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"江苏省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">data</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"南京市"</span>:</span><br><span class="line"> posdesc = <span class="string">"这是我挺想去的城市啦"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"苏州市"</span>:</span><br><span class="line"> posdesc = <span class="string">"上有天堂,下有苏杭"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"散装是必须要散装的"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"浙江省"</span>:</span><br><span class="line"> posdesc = <span class="string">"东风渐绿西湖柳,雁已还人未南归"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"河南省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">data</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"郑州市"</span>:</span><br><span class="line"> posdesc = <span class="string">"豫州之域,天地之中"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"南阳市"</span>:</span><br><span class="line"> posdesc = <span class="string">"臣本布衣,躬耕于南阳此南阳非彼南阳!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"驻马店市"</span>:</span><br><span class="line"> posdesc = <span class="string">"峰峰有奇石,石石挟仙气嵖岈山的花很美哦!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"开封市"</span>:</span><br><span class="line"> posdesc = <span class="string">"刚正不阿包青天"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"洛阳市"</span>:</span><br><span class="line"> posdesc = <span class="string">"洛阳牡丹甲天下"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"可否带我品尝河南烩面啦?"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"安徽省"</span>:</span><br><span class="line"> posdesc = <span class="string">"蚌埠住了,芜湖起飞"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"福建省"</span>:</span><br><span class="line"> posdesc = <span class="string">"井邑白云间,岩城远带山"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"江西省"</span>:</span><br><span class="line"> posdesc = <span class="string">"落霞与孤鹜齐飞,秋水共长天一色"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"山东省"</span>:</span><br><span class="line"> posdesc = <span class="string">"遥望齐州九点烟,一泓海水杯中泻"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"湖北省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">data</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"黄冈市"</span>:</span><br><span class="line"> posdesc = <span class="string">"红安将军县!辈出将才!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"来碗热干面~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"湖南省"</span>:</span><br><span class="line"> posdesc = <span class="string">"74751,长沙斯塔克"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"广东省"</span>:</span><br><span class="line"> <span class="keyword">switch</span> (ipLocation.<span class="property">data</span>.<span class="property">city</span>) {</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"广州市"</span>:</span><br><span class="line"> posdesc = <span class="string">"看小蛮腰,喝早茶了嘛~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"深圳市"</span>:</span><br><span class="line"> posdesc = <span class="string">"今天你逛商场了嘛~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"阳江市"</span>:</span><br><span class="line"> posdesc = <span class="string">"阳春合水!博主家乡~ 欢迎来玩~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"来两斤福建人~"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"广西壮族自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"桂林山水甲天下"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"海南省"</span>:</span><br><span class="line"> posdesc = <span class="string">"朝观日出逐白浪,夕看云起收霞光"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"四川省"</span>:</span><br><span class="line"> posdesc = <span class="string">"康康川妹子"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"贵州省"</span>:</span><br><span class="line"> posdesc = <span class="string">"茅台,学生,再塞200"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"云南省"</span>:</span><br><span class="line"> posdesc = <span class="string">"玉龙飞舞云缠绕,万仞冰川直耸天"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"西藏自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"躺在茫茫草原上,仰望蓝天"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"陕西省"</span>:</span><br><span class="line"> posdesc = <span class="string">"来份臊子面加馍"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"甘肃省"</span>:</span><br><span class="line"> posdesc = <span class="string">"羌笛何须怨杨柳,春风不度玉门关"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"青海省"</span>:</span><br><span class="line"> posdesc = <span class="string">"牛肉干和老酸奶都好好吃"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"宁夏回族自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"大漠孤烟直,长河落日圆"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"新疆维吾尔自治区"</span>:</span><br><span class="line"> posdesc = <span class="string">"驼铃古道丝绸路,胡马犹闻唐汉风"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"台湾省"</span>:</span><br><span class="line"> posdesc = <span class="string">"我在这头,大陆在那头"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"香港特别行政区"</span>:</span><br><span class="line"> posdesc = <span class="string">"永定贼有残留地鬼嚎,迎击光非岁玉"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">"澳门特别行政区"</span>:</span><br><span class="line"> posdesc = <span class="string">"性感荷官,在线发牌"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"带我去你的城市逛逛吧!"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="attr">default</span>:</span><br><span class="line"> posdesc = <span class="string">"带我去你的国家逛逛吧"</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//根据本地时间切换欢迎语</span></span><br><span class="line"> <span class="keyword">let</span> timeChange;</span><br><span class="line"> <span class="keyword">let</span> date = <span class="keyword">new</span> <span class="title class_">Date</span>();</span><br><span class="line"> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">5</span> && date.<span class="title function_">getHours</span>() < <span class="number">11</span>) timeChange = <span class="string">"<span>🌤️ 早上好,一日之计在于晨</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">11</span> && date.<span class="title function_">getHours</span>() < <span class="number">13</span>) timeChange = <span class="string">"<span>☀️ 中午好,记得午休喔~</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">13</span> && date.<span class="title function_">getHours</span>() < <span class="number">17</span>) timeChange = <span class="string">"<span>🕞 下午好,饮茶先啦!</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">17</span> && date.<span class="title function_">getHours</span>() < <span class="number">19</span>) timeChange = <span class="string">"<span>🚶♂️ 即将下班,记得按时吃饭~</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (date.<span class="title function_">getHours</span>() >= <span class="number">19</span> && date.<span class="title function_">getHours</span>() < <span class="number">24</span>) timeChange = <span class="string">"<span>🌙 晚上好,夜生活嗨起来!</span>"</span>;</span><br><span class="line"> <span class="keyword">else</span> timeChange = <span class="string">"夜深了,早点休息,少熬夜"</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="comment">//自定义文本和需要放的位置</span></span><br><span class="line"> <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">"welcome-info"</span>).<span class="property">innerHTML</span> =</span><br><span class="line"> <span class="string">`欢迎来自 <b><span style="color: var(--kouseki-ip-color);font-size: var(--kouseki-gl-size)"><span class="subst">${pos}</span></span></b> 的小友💖<br><span class="subst">${posdesc}</span>🍂<br>当前位置距博主约 <b><span style="color: var(--kouseki-ip-color)"><span class="subst">${dist}</span></span></b> 公里!<br>您的IP地址为:<b><span style="font-size: 12px;"><span class="subst">${ip}</span></span></b><br><span class="subst">${timeChange}</span> <br>`</span>;</span><br><span class="line"> } <span class="keyword">catch</span> (err) {</span><br><span class="line"> <span class="comment">// console.log("Pjax无法获取元素");</span></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// Pjax完成页面切换的事件回调处理</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">handlePjaxComplete</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">showWelcome</span>();</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="variable language_">window</span>.<span class="property">onload</span> = <span class="keyword">function</span>(<span class="params"></span>) {</span><br><span class="line"> <span class="title function_">showWelcome</span>();</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 添加pjax:complete事件监听</span></span><br><span class="line"> <span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">"pjax:complete"</span>, handlePjaxComplete);</span><br><span class="line">};</span><br></pre></td></tr></table></figure><p>算是更改了请求地址,使用了 <a href="https://api.qjqq.cn/api/Local">https://api.qjqq.cn/api/Local</a> 来获取<strong>经纬度</strong></p>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>利用Github搭建NPM图床</title>
<link href="/posts/be3e28ff.html"/>
<url>/posts/be3e28ff.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>通过<strong>NPM + Github</strong>的方式来搭建一个<strong>NPM图床</strong>,这种方式是不需要服务器的</p><blockquote><p>存储的图片总大小建议不要超过 <strong>1G</strong>,否则Github会有<strong>人工审核</strong>仓库内容,如果发现<strong>用来做图床</strong>,轻则删库,重则封号。因此为了安全起见,建议在 <strong>1G</strong> 之前就换个仓库,反正可以创建无数个仓库嘛</p></blockquote><h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>在 <a href="https://github.com/">Github官网</a> 上创建一个<strong>仓库</strong>,用来存储本地上传来的图片</p><p>在本地任选一个文件路径,克隆所选仓库的文件</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> [email protected]:blhorizon/BlogImages.git</span><br></pre></td></tr></table></figure><p>输入如下指令。根据指示验证完邮箱后就会跳转到如下页面</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 切换回原生源,否则需要你输入账号密码</span></span><br><span class="line">npm config <span class="built_in">set</span> registry https://registry.npmjs.org</span><br><span class="line"></span><br><span class="line"><span class="comment"># 仅第一次使用需要添加用户</span></span><br><span class="line">npm adduser</span><br><span class="line"></span><br><span class="line"><span class="comment"># 非第一次使用直接登录即可</span></span><br><span class="line">npm login</span><br></pre></td></tr></table></figure><p>执行如下指令会生成<strong>package.json</strong>文件。需要注意的是,事先需要通过搜索确认你的包名是否<strong>唯一</strong>。同时 <strong>git repository</strong> 填写的是仓库的 <strong>HTTPS</strong>,而不是 <strong>SSH</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm init</span><br></pre></td></tr></table></figure><p>依次输入如下指令将本地路径中的文件分别上传到 <strong>Github</strong> 和 <strong>NPM</strong> 中</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 将更改提交到暂存区中</span></span><br><span class="line">git add .</span><br><span class="line"></span><br><span class="line"><span class="comment"># 将暂存区内容添加到本地仓库中</span></span><br><span class="line">git commit -m <span class="string">"npm publish"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新package版本号,每次会在末尾版本号 +1。例如 0.0.1 => 0.0.2</span></span><br><span class="line"><span class="comment"># 大版本需要在 package.json 手动更改 version,即从 1.0.0 => 2.0.0</span></span><br><span class="line">npm version patch</span><br><span class="line"></span><br><span class="line"><span class="comment"># 推送至Github上</span></span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line"><span class="comment"># 推送到npm上</span></span><br><span class="line">npm publish</span><br></pre></td></tr></table></figure><p>这时你就可以通过链接在网上访问你的图片了。由于在国内访问会很慢,建议使用 <strong>CDN</strong> 进行加速。</p><blockquote><p>目前我正在使用的CDN是 <a href="https://cdn.onmicrosoft.cn/">渺软公益 CDN</a>,访问速度很快。其链接为:<a href="https://jsd.onmicrosoft.cn/npm/%E3%80%90%E6%96%87%E4%BB%B6%E8%B7%AF%E5%BE%84%E3%80%91">https://jsd.onmicrosoft.cn/npm/【文件路径】</a></p></blockquote>]]></content>
<categories>
<category> 技术教程 </category>
</categories>
<tags>
<tag> 图床 </tag>
</tags>
</entry>
<entry>
<title>U盘重装系统</title>
<link href="/posts/97f26e5d.html"/>
<url>/posts/97f26e5d.html</url>
<content type="html"><![CDATA[<p><strong>重装系统</strong> 是在电脑系统出现问题或受到恶意软件、流氓软件的“污染”时可以让电脑满血复活的 <strong>一种电脑抢救措施</strong></p><blockquote><p>优点:</p><ol><li><strong>清除系统垃圾,提高运行速度</strong>,这也是大家重装系统的主要原因之一</li><li>重装系统是 <strong>直接格式化C盘</strong>,对于系统感染病毒、其它各种未知因素引发的严重系统故障问题,起到直接了断的解决效果</li><li>重装后的系统是 <strong>基本处于初始状态</strong>,各项性能都是最佳的,运行最流畅,对于重新分配这个机器的用途起到很好的初始化作用</li></ol></blockquote><blockquote><p>缺点:</p><ol><li>一般重装系统格式化的时候都 <strong>会损伤硬盘</strong>,因为对于覆盖重装系统或者高级格式化真正意义上的重装系统来说,不管是高级格式化还是低级格式化都会给硬盘带来损伤。不过目前的硬盘都会对其进行一定的保护,所以不需要太过于害怕</li><li>重装系统可能会导致没有及时备份好的数据丢失,所以在重装系统之前一定要 <strong>做好备份</strong>,有一些人不愿意重装系统就是害怕数据丢失</li><li>重装系统无法解决为何导致系统故障的原因,不利于预防和解决相关问题</li><li>重装系统格式化的只是C盘,如果有病毒潜伏在其它磁盘,重装系统后还是有被感染的风险;除非格式化所有盘</li></ol></blockquote><h2 id="制作启动盘"><a href="#制作启动盘" class="headerlink" title="制作启动盘"></a>制作启动盘</h2><blockquote><p>先需要在 <a href="https://www.xitongku.com/">MSDN</a> 上下载 <strong>纯净的系统镜像</strong>,之后准备一个 <strong>8G以上的U盘</strong>,通过 <a href="https://cn.ultraiso.net/">软碟通</a> 来制作 <strong>启动盘</strong></p></blockquote><ol><li>将你的 U盘 进行格式化,在软碟通界面选择 <strong>文件</strong>,然后 <strong>打开</strong> 并选择你在 MSDN 上下载的系统镜像</li><li>加载完你的系统镜像后,选择 <strong>启动</strong> 后点击 <strong>写入硬盘映像</strong>。这里写入方式要选择 <strong>USB-HDD+</strong></li><li>当消息处显示 <strong>刻录成功</strong> 后,就代表你的启动盘弄好了</li></ol><h2 id="重装系统"><a href="#重装系统" class="headerlink" title="重装系统"></a>重装系统</h2><blockquote><p>我的笔记本电脑是 <strong>暗影精灵7</strong>,其他品牌的可以自行百度搜索。同时重装前记得 <strong>备份好重要数据</strong></p></blockquote><ol><li><p>将 U盘 插入你的笔记本电脑后进行重启,在启动的过程中 <strong>一直按F9</strong>,直到出现如下所示,选择 <strong>USB硬盘(UEFI)</strong> 。后续基本都是按 <strong>下一页</strong>。在这过程中操作系统建议选择 <strong>Windows11专业版</strong></p><blockquote><p><strong>自定义:仅安装 Windows(高级)</strong> 表示删除所有软件、文件等</p></blockquote></li><li><p>有时候在选择 <strong>系统</strong> 的安装路径时,<strong>不显示你当前的盘符情况</strong>。这里要根据自已的品牌电脑,下载对应的<strong>驱动程序</strong>。点击 <strong>浏览</strong> 后选择 <strong>SOftpaq文件</strong> 所在的盘符,选择 <strong>F6</strong> 后任意选择一个需要安装的驱动程序</p><blockquote><p>我的暗影精灵7的就是 <a href="https://pan.baidu.com/s/1a_yWmhko38fsuFqm5Y-FdA?pwd=vm59">SOftpaq</a></p></blockquote></li><li><p>选择过后盘符就能正常显示了。这里都可以进行 <strong>格式化</strong>,在这之后选择系统所要安装的盘符,这时候就开始安装系统了。当显示如下界面时记得 <strong>拔掉U盘</strong>,否则可能会出现 <strong>蓝屏</strong></p><blockquote><p>当然如果没有做到出现蓝屏,这时 <strong>关机</strong> 即可</p></blockquote></li><li><p>接下来就是等待了,如果出现 <strong>界面卡住</strong> 的问题,直接关机重新启动即可</p></li></ol>]]></content>
<categories>
<category> 技术教程 </category>
</categories>
<tags>
<tag> 重装系统 </tag>
</tags>
</entry>
<entry>
<title>利用51LA进行网站数据统计</title>
<link href="/posts/d75f59bb.html"/>
<url>/posts/d75f59bb.html</url>
<content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>通过 <a href="https://v6.51.la/">51LA</a> 为博客添加<strong>网站数据统计</strong>,提供一定量免费的<strong>统计流量(PV)额度</strong>,这些对于中小型个人博客来说已经足够了<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/Snipaste_2023-10-15_16-40-21.webp"></p><h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>在 <a href="https://v6.51.la/">51LA</a> 中进行注册,登录进去之后其他不用管直接点击 <strong>添加应用统计</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/20230526135813.webp"></p><p>之后给你的应用写一个 <strong>名称</strong>,然后将你的 <strong>域名</strong> 填写进去,行业类别根据你的网站性质填写就好了,博主是写的 <strong>论坛博客/IT</strong>,最后点击添加<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/20230526140244.webp"></p><p>添加后点击 <strong>参数设置</strong> - 选择 <strong>统计代码</strong> - 选择 <strong>手动安装</strong> – 点击 <strong>获取SDK追踪代码</strong>,复制 <strong>id</strong> 和 <strong>ck</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/b45693.webp"></p><p>然后点击 <strong>数据挂件</strong> 并开启 <strong>挂件功能</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/d0a3ae75.webp"></p><p>最后在 <strong>应用管理</strong> 查看状态是否配置成功,一般需要等 <strong>五分钟</strong> 网页才会生效,如果没成功可以点击 <strong>配置</strong> 根据上面的步骤进行排查<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/8bea467127f.webp"></p><p>在<strong>博客配置文件</strong> _config.anzhiyu.yml 中将 ck 和 id 分别写入</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 51a统计配置</span></span><br><span class="line"><span class="attr">LA:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">ck:</span> [<span class="string">ck</span>]</span><br><span class="line"> <span class="attr">LingQueMonitorID:</span> [<span class="string">id</span>]</span><br></pre></td></tr></table></figure><h2 id="结尾"><a href="#结尾" class="headerlink" title="结尾"></a>结尾</h2><p>在<strong>本地部署</strong>中,会看到如下问题信息,原因是我们没有在添加应用统计时将本地部署域名添加进内(51LA不允许添加)。在远程部署到网络后就可以正常显示你的网站数据统计了<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/51la/Snipaste_2023-10-15_16-47-04.webp"></p>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title>获取朋友圈API</title>
<link href="/posts/6895678f.html"/>
<url>/posts/6895678f.html</url>
<content type="html"><![CDATA[<blockquote><p>参考自:<a href="https://fcircle-doc.yyyzyyyz.cn/#/">朋友圈</a>,根据步骤进行朋友圈 <strong>后端部署</strong></p></blockquote><h2 id="Github-配置"><a href="#Github-配置" class="headerlink" title="Github 配置"></a>Github 配置</h2><p>先 <strong>Fork</strong> <a href="https://github.com/Rock-Candy-Tea/hexo-circle-of-friends">友链朋友圈项目</a>,编辑 <strong>/hexo_circle_of_friends/fc_settings.yaml</strong> 文件,修改配置</p><blockquote><p>在 Fork 的时候记住 <strong>不要</strong> 勾选 <strong>Copy the main branch only</strong></p></blockquote><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">LINK:</span></span><br><span class="line"> <span class="comment"># link改为你的友链页地址,theme选择你的博客主题(我这里安知鱼主题,所以选 common2)</span></span><br><span class="line"> <span class="bullet">-</span> {<span class="attr">link:</span> <span class="string">"https://blhorizon.github.io/link/"</span>, <span class="attr">theme:</span> <span class="string">"common2"</span>} </span><br></pre></td></tr></table></figure><p>根据下图步骤进行操作,添加相应的 <strong>环境变量</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/20220205080305.webp"></p><blockquote><p><strong>GH_NAME</strong>:Github 名称,也就是 <strong>你的用户名</strong><br><strong>GH_EMAIL</strong>:Github 邮箱,填写你注册 <strong>Github的邮箱</strong><br><strong>GH_TOKEN</strong>:Github 访问 <strong>Token</strong><br><strong>STORAGE_TYPE</strong>:存储方式,填写 <strong>sqlite</strong></p></blockquote><p>获取 Github 的 <strong>Token</strong> 可以前往 <a href="https://github.com/settings/tokens">此链接</a>,点击 <strong>Generate new token</strong>,选择 <strong>Generate new token (classic)</strong> </p><blockquote><p>Select scopes 要选择 <strong>repo</strong> 和 <strong>workflow</strong>,Expiration 要选择 <strong>no expiration(永不过期)</strong></p></blockquote><p><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/image-20221008230906574.webp"></p><p>上述四个环境变量配置好后,点击仓库的 <strong>Settings</strong> - 点击 <strong>Actions</strong> - 点击 <strong>General</strong>,向下拉会看到 <strong>Workflow permissions</strong>,选择 <strong>Read and write permissions</strong> 后 <strong>Save</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/workflow_permissions.webp"></p><h2 id="Vercel-配置"><a href="#Vercel-配置" class="headerlink" title="Vercel 配置"></a>Vercel 配置</h2><p>点击 <a href="https://vercel.com/new">此链接</a>,将友链朋友圈项目仓库 <strong>Deploy</strong> 到 Vercel 中。部署完成后,根据下图步骤 <strong>在项目中</strong> 添加相应的 <strong>环境变量</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/image-20221008231737297.webp"></p><blockquote><p><strong>GH_NAME</strong>:Github 名称,也就是 <strong>你的用户名</strong><br><strong>GH_EMAIL</strong>:Github 邮箱,填写你注册 <strong>Github的邮箱</strong><br><strong>GH_TOKEN</strong>:Github 访问 <strong>Token</strong><br><strong>VERCEL_ACCESS_TOKEN</strong>:Vercel 访问 <strong>Token</strong></p></blockquote><p>获取 Vercel 的 <strong>Token</strong> 可以前往 <a href="https://vercel.com/account/tokens">此链接</a>,并 <strong>Create</strong> 生成一个 Token<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/20230611143935.webp"></p><h2 id="最终配置"><a href="#最终配置" class="headerlink" title="最终配置"></a>最终配置</h2><p>回到 Github 中的友链朋友圈项目,点击 <strong>Actions</strong> - 点击 <strong>I understand my workflows, go ahead and enable them</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/20220205081120.webp"></p><p>之后根据下图所示步骤进行操作启用 <strong>workflow</strong><br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/20220205081424.webp"></p><p>然后点击 <strong>Run workflow</strong>,等待变<strong>绿色</strong>说明已经成功运行了。这时会在仓库生成一个 <strong>data.db</strong>,并会同步更新到 Vercel 中<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/image-20221008232746973.webp"></p><p>到 Vercel 的友链朋友圈项目中找到 <strong>DOMAINS</strong>,在链接的后缀添加 <strong>/all</strong> 进行访问,如果出现相应数据,那么该链接就是所需的<strong>朋友圈后端地址</strong>了<br><img src="https://jsd.onmicrosoft.cn/npm/hexoblogimages/friendsapi/20220205083633.webp"></p>]]></content>
<categories>
<category> Hexo博客 </category>
</categories>
<tags>
<tag> 功能 </tag>
</tags>
</entry>
<entry>
<title></title>
<link href="/manifest.json"/>
<url>/manifest.json</url>
<content type="html"><![CDATA[{"name":"冰梦の博客","short_name":"冰梦","display":"standalone","theme_color":"#ffffff","background_color":"#ffffff","scope":"/","start_url":"/","id":"/","icons":[{"src":"/img/siteicon/android-chrome-36x36.png","sizes":"36x36","type":"image/png"},{"src":"/img/siteicon/android-chrome-48x48.png","sizes":"48x48","type":"image/png"},{"src":"/img/siteicon/android-chrome-72x72.png","sizes":"72x72","type":"image/png"},{"src":"/img/siteicon/android-chrome-96x96.png","sizes":"96x96","type":"image/png"},{"src":"/img/siteicon/android-chrome-144x144.png","sizes":"144x144","type":"image/png"},{"src":"/img/siteicon/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/img/siteicon/android-chrome-256x256.png","sizes":"256x256","type":"image/png"},{"src":"/img/siteicon/android-chrome-384x384.png","sizes":"384x384","type":"image/png"},{"src":"/img/siteicon/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"splash_pages":null}]]></content>
</entry>
<entry>
<title>关于</title>
<link href="/about/index.html"/>
<url>/about/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>藏宝阁</title>
<link href="/collect/index.html"/>
<url>/collect/index.html</url>
<content type="html"><![CDATA[<style>#page > h1{ display:none;}</style>]]></content>
</entry>
<entry>
<title>相册集</title>
<link href="/album/index.html"/>
<url>/album/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>统计表</title>
<link href="/charts/index.html"/>
<url>/charts/index.html</url>
<content type="html"><![CDATA[<p><span class="p center logo large" style="font-family: STZhongsong,'Microsoft YaHei';">统计</span></p><p><span class="p center small" style="font-weight:600;font-family: STZhongsong,'Microsoft YaHei';">萌傀儡的小站·世事无常·小萌新·随缘更新<span></p><p style="text-align:center;font-weight:600;font-size:18px;line-height:.3em">访问统计</p><div id="statistic"></div><script src="https://npm.elemecdn.com/[email protected]/dist/echarts.min.js"></script><!-- 文章发布时间统计图 --><div id="posts-chart" data-start="2023-01" style="border-radius: 8px; height: 300px; padding: 10px;"></div><!-- 文章标签统计图 --><div id="tags-chart" data-length="10" style="border-radius: 8px; height: 300px; padding: 10px;"></div><!-- 文章分类统计图 --><div id="categories-chart" data-parent="true" style="border-radius: 8px; height: 300px; padding: 10px;"></div><style>#statistic div span:last-child { font-weight: 700; font-size: 34px; line-height: 1; white-space: nowrap;}#page > h1{ display:none;}#statistic { display: flex; font-size: 18px; padding: 20px 10px; border-radius: 12px; width: 100%; color: var(--font-color); border: 2px solid #03a9f4; max-width: 710px; margin: 0 auto; min-height: 135px; justify-content:space-between; -webkit-user-select: none; /* Safari */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */ user-select: none;}#statistic .content { display: flex; flex-wrap: wrap; justify-content: space-between;}#statistic a { text-decoration: none}#statistic .content div { display: inline-block}#statistic div { margin: 0 12px; width: 50%; flex-direction: column;}#statistic div span { font-size: 13px; line-height: 1.3; display: block}@media screen and (max-width: 768px) { #statistic div span:last-child { font-weight: 700; font-size: 16px; line-height: 2; }}</style><script> async function fetchAndDisplayStatistic() { try { const data = await fetchData(); const numbers = extractNumbersFromData(data); displayStatistics(numbers); addSupportElement(); animateStatisticValues(); } catch (error) { console.error(error.message); } } async function fetchData() { const response = await fetch("https://v6-widget.51.la/v6/JxSuAna3ua5vGXEw/quote.js"); if (!response.ok) throw new Error('获取数据失败。'); return await response.text(); } function extractNumbersFromData(data) { const numRegex = /<\/span><span>(\d+)<\/span><\/p>/g; return [...data.matchAll(numRegex)].map(([, num]) => parseInt(num, 10)); } function displayStatistics(numbers) { const title = ["最近活跃", "今日人数", "今日访问", "昨日人数", "昨日访问", "本月访问", "总访问量"]; const statisticEl = document.querySelector("#statistic"); if (!statisticEl) throw new Error("未找到统计元素"); const statisticHtml = numbers .slice(1) // 跳过第一个元素(最近活跃数据) .map((num, i) => `<div><span>${title[i + 1]}</span><span class="statistic-value">${num}</span></div>`) .join(''); statisticEl.innerHTML = statisticHtml; } function addSupportElement() { const statisticEl = document.querySelector("#statistic"); const supportEl = document.createElement("span"); supportEl.style.fontSize = "14px"; supportEl.innerHTML = "流量统计支持:<a style='color:#1690ff;' target='_blank' rel='noopener' href='https://v6.51.la/'>51la</a>"; statisticEl.appendChild(supportEl); statisticEl.style.position = "relative"; supportEl.style.position = "absolute"; supportEl.style.bottom = "10px"; supportEl.style.left = "10px"; } function animateStatisticValues() { const statisticValues = document.querySelectorAll('.statistic-value'); statisticValues.forEach((value) => { const targetValue = parseInt(value.innerText, 10); let startTime; const easeOutCubic = t => (--t) * t * t + 1; function animate(timestamp) { if (!startTime) startTime = timestamp; const progress = timestamp - startTime; // 动画持续时间 const duration = 2000; const percentage = easeOutCubic(progress / duration); const currentValue = Math.round(percentage * targetValue); value.innerText = currentValue; if (currentValue < targetValue) { requestAnimationFrame(animate); } else { value.innerText = targetValue; // 确保最后的值与目标值匹配 } } requestAnimationFrame(animate); }); } (async () => { await fetchAndDisplayStatistic(); })();</script>]]></content>
</entry>
<entry>
<title>文章分类</title>
<link href="/categories/index.html"/>
<url>/categories/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>朋友圈</title>
<link href="/fcircle/index.html"/>
<url>/fcircle/index.html</url>
<content type="html"><![CDATA[<style>/* 去除夜间朋友圈右侧空白 */#cf-overlay { display: none;}</style>]]></content>
</entry>
<entry>
<title></title>
<link href="/essay/index.html"/>
<url>/essay/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title></title>
<link href="/css/custom.css"/>
<url>/css/custom.css</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>友人帐</title>
<link href="/link/index.html"/>
<url>/link/index.html</url>
<content type="html"><![CDATA[<h2>友链链接申请</h2><div>很高兴能和非常多的朋友们交流,如果你也想加入友链,可以在下方留言,我会在不忙的时候统一添加。</div><h2 id="我的友链"><a href="#我的友链" class="headerlink" title="我的友链"></a>我的友链</h2><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="attr">name:</span> <span class="string">萌傀儡</span></span><br><span class="line"> <span class="attr">link:</span> <span class="string">https://blhorizon.github.io</span></span><br><span class="line"> <span class="attr">avatar:</span> <span class="string">https://blhorizon.github.io/img/avatar.webp</span></span><br><span class="line"> <span class="attr">descr:</span> <span class="string">人生,就是用来享受的!</span></span><br><span class="line"> <span class="attr">siteshot:</span></span><br></pre></td></tr></table></figure><details class="folding-tag" ><summary> ✅ 加入本站友链须知 </summary> <div class='content'> <h2 id="本站添加的友链要求"><a href="#本站添加的友链要求" class="headerlink" title="本站添加的友链要求"></a>本站添加的友链要求</h2><ol><li>能够正常访问</li><li>含本站友链</li><li>网站类型为<b>个人博客</b></li></ol><p>请(<a href="#post-comment">点击这里快速添加</a>) 站点信息申请友情链接,申请后在我不忙的时候会统一添加,即使不通过也会给予邮件回复。</p><h2 id="你提交的信息有可能被修改"><a href="#你提交的信息有可能被修改" class="headerlink" title="你提交的信息有可能被修改"></a>你提交的信息有可能被修改</h2><p>如果有修改,我会将修改内容进行告知</p><ol><li>为了友链相关页面和组件的统一性和美观性,可能会对你的昵称进行缩短处理,例如昵称包含<code>博客</code>、<code>XX 的 XX</code>等内容或形式将被简化。</li><li>为了图片加载速度和内容安全性考虑,头像实际展示图片均使用博客自己图床,所以无法收到贵站自己的头像更新,如果有迫切的更改信息需求,请在本页的评论中添加。</li><li>为了保证鱼塘能够正确抓取文章,所有的友链链接要求为博客主页链接,而不是个人主页链接。</li></ol><h2 id="提交友链信息"><a href="#提交友链信息" class="headerlink" title="提交友链信息"></a>提交友链信息</h2><p>为了避免图床问题,建议你将头像存储到贵站图床。</p><ol><li>我的名称: <code>萌傀儡</code></li><li>网站地址: <code>blhorizon.github.io</code></li><li>描述: <code>人生,就是用来享受的!</code></li><li>头像: <code>blhorizon.github.io/img/avatar.webp</code></li></ol><p>参照以下格式留言 📋 即可(示例如下)。</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">昵称:萌傀儡</span></span><br><span class="line"><span class="string">网站地址:https://blhorizon.github.io</span></span><br><span class="line"><span class="string">头像图片url:https://blhorizon.github.io/img/avatar.webp</span></span><br><span class="line"><span class="string">描述:人生,就是用来享受的!</span></span><br><span class="line"><span class="string">站点截图:(可选):</span></span><br></pre></td></tr></table></figure><blockquote><p>站点截图建议自己提供,尺寸尽量不要大于 300*300。<br>未提供站点预览图的,本站会根据贵站链接调用以下 API 自动获取贵站的站点截图。<br>对于做了反扒措施的站点,API 获取的将是反扒页面,望知悉。</p></blockquote><p>站点截图建议使用以下 <strong>API</strong> 获取以匹配本站样式。</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://image.thum.io/get/width/400/crop/800/allowJPG/wait/20/https://<你的域名></span><br></pre></td></tr></table></figure> </div> </details><p style="padding:0 0 0 .8rem"> 请<strong>勾选</strong>你符合的条件:</p><div id="friendlink_checkboxs" style="padding:0 0 0 1.6rem"> <p> <label class="checkbox"> <input type="checkbox" id="checkbox1" onclick="checkForm()"> 我已添加 <b>萌傀儡</b> 博客的友情链接 </label> </p> <p> <label class="checkbox"> <input type="checkbox" id="checkbox2" onclick="checkForm()"> 我的链接主体为 <b>个人</b>,网站类型为<b>博客</b> </label> </p> <p> <label class="checkbox"> <input type="checkbox" id="checkbox3" onclick="checkForm()">我的网站现在可以在中国大陆区域正常访问 </label> </p> <p> <label class="checkbox"> <input type="checkbox" id="checkbox4" onclick="checkForm()">网站内容符合中国大陆法律法规 </label> </p> <p> <label class="checkbox"> <input type="checkbox" id="checkbox5" onclick="checkForm()">我的网站可以在1分钟内加载完成首屏 </label> </p></div><script> // 获取 twikooSubmit 元素 function getTwikooSubmit() { return document.getElementsByClassName("tk-submit")[0]; } // 检查表单并处理样式 function checkForm() { var checkboxes = []; for (var i = 1; i <= 5; i++) { var checkbox = document.getElementById("checkbox" + i); checkboxes.push(checkbox); } var twikooSubmit = getTwikooSubmit(); if (checkboxes.every(function(checkbox) { return checkbox.checked })) { twikooSubmit.style.opacity = "1"; twikooSubmit.style.height = "auto"; twikooSubmit.style.overflow = "auto"; var input = document.getElementsByClassName('el-textarea__inner')[0]; let evt = document.createEvent('HTMLEvents'); evt.initEvent('input', true, true); input.value = '昵称(请勿包含博客等字样):\n网站地址(要求博客地址,请勿提交个人主页):\n头像图片url(请提供尽可能清晰的图片,我会上传到我自己的图床):\n描述:\n'; input.dispatchEvent(evt); input.focus(); input.setSelectionRange(-1, -1); } else { twikooSubmit.style.opacity = "0"; twikooSubmit.style.height = "0"; twikooSubmit.style.overflow = "hidden"; } }</script><style> .tk-comments > .tk-submit { opacity: 0; height: 0; transition: opacity .5s, height .5s; overflow: hidden; }</style>]]></content>
</entry>
<entry>
<title>音乐馆</title>
<link href="/music/index.html"/>
<url>/music/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>动态</title>
<link href="/memos/index.html"/>
<url>/memos/index.html</url>
<content type="html"><![CDATA[<div class="author-content author-content-item single" style="background:url(https://jsd.onmicrosoft.cn/npm/hexoblogimages/covers/16.webp) left 28%/cover no-repeat"> <div class="card-content"> <div class="author-content-item-tips">闲言碎语</div><span class="author-content-item-title">咸鱼的日常生活</span> <div class="content-bottom"> <div class="tips">随时随地,分享生活</div> </div> <div class="banner-button-group"><a class="banner-button" href="/album" data-pjax-state="" draggable="false"><i class="anzhiyufont anzhiyu-icon-arrow-circle-right" style="font-size:1.5rem"></i><span class="banner-button-text">我的相册</span></a></div> </div></div><style>#page > h1{ display:none;}.bber-reply { cursor: pointer !important;}.bber-reply:hover { color: var(--anzhiyu-main); max-height: 35px;}/* 页面初始化 */div#page { background: 0 0!important; border: 0; padding: 0; box-shadow: none !important}[data-theme=dark] #twikoo .tk-content,#twikoo .tk-content { padding: 0; background: transparent;}.talk_item,.tk-expand,.tk-comments-container>.tk-comment,.tk-submit:nth-child(1) { background: var(--icemyst-card-bg); border: 1px solid #e0e3ed; box-shadow: 0 5px 10px rgb(189 189 189 / 10%); transition: all .3s ease-in-out; border-radius: 12px;}#post-comment{ padding: 0 51px 18px !important;}/* 瀑布溜布局卡片 */.talk_item { display: inline-block; width: 32.7%; margin-right: 1%; padding: 15px 1rem 12px; margin-bottom: 15px;}/* [data-theme=dark] .talk_item,.tk-expand,.tk-comments-container>.tk-comment,.tk-submit:nth-child(1) { background: var(--icemyst-card-bg)} */.talk_item:hover,.tk-comments-container>.tk-comment:hover,.tk-submit:nth-child(1):hover { border-color: #49b1f5;}.tk-submit { padding: 20px 10px 0;}.tk-comments-container>.tk-comment { padding: 15px;}/* 页面初始化结束 */#talk { margin-top: 1rem; margin-left: 32px;}#talk .loading { display: flex; align-items: center; justify-content: center; flex-direction: column;}#talk .loading img { width: 200px;}.avatar { margin: 0 !important; width: 60px; height: 60px; border-radius: 10px !important;}.talk_bottom,.talk_meta { display: flex; align-items: center; width: 100%; line-height: 1.5;}.talk_bottom { justify-content: space-between;}.info { display: flex; flex-direction: column; margin-left: 10px;}span.talk_nick { color: #6dbdc3; font-size: 1.2rem;}svg.is-badge.icon { width: 15px; margin-left: 5px; padding-top: 3px;}span.talk_date { font-size: 14px; opacity: .6;}.talk_content { line-height: 1.5; margin-top: 10px;}.zone_imgbox { display: flex; flex-wrap: wrap; --w: calc(25% - 8px); gap: 10px; margin-top: 5px;}.zone_imgbox a { display: block; border-radius: 12px; width: 177px; aspect-ratio: 1/1; position: relative;}.zone_imgbox img { width: 100%; height: 100%; margin: 0 !important; object-fit: cover;}/* 底部 */.talk_bottom { opacity: .9;}.talk_bottom a { border-bottom: none !important;}span.talk_tag { font-size: 14px;}.talk_content>a { margin: 0 3px; color: #ff7d73 !important;}.talk_content>a:hover { text-decoration: none !important; color: #ff5143 !important}/* 提醒 */.limit { transition: all .3s ease-in-out; color: rgba(76, 73, 72, 0.6);}[data-theme=dark] .limit { color: rgba(255, 255, 255, 0.5);}.limit { display: none; text-align: center; margin-top: 20px; color: #4c4948;}/* 哔哩哔哩视频适配 */iframe { position: absolute; width: 100%; height: 100%; left: 0; top: 0;}.video { position: relative; padding: 30% 45%; margin-top: 10px; margin-bottom: 10px; border-radius: 12px; overflow: hidden;}/* 手机卡片自适应 */@media screen and (max-width: 768px) { .talk_item { width: 49.3%; margin-right: 1.4%; } .zone_imgbox a { width: calc(50% - 3px); max-height: calc(50% - 3px); }}@media screen and (max-width: 1100px) { .talk_item { width: 100%; margin-right: 0; } .zone_imgbox a { width: calc(50% - 3px); max-height: calc(50% - 3px); }}@media screen and (max-width: 900px) { .zone_imgbox { --w: calc(33% - 5px); } #talk { margin: 10px 3px 0 } #post-comment { margin: 0 3px } .zone_imgbox a { width: calc(50% - 3px); max-height: calc(50% - 3px); }}@media screen and (max-width: 768px) { .zone_imgbox { gap: 6px; } .zone_imgbox { --w: calc(50% - 3px); } span.talk_date { font-size: 14px; } .zone_imgbox a { width: calc(50% - 3px); max-height: calc(50% - 3px); }}</style><div id="talk" style="position: relative;height: 2845px;"> <div class='loading'><img src="/img/loading.gif" alt="加载中..."></div></div><div class="limit">- 只展示最近30条说说 -</div><script src="/js/imgStatus.js"></script><script>if (1) { let url = 'https://memos53.zeabur.app' fetch(url + '/api/v1/memo?creatorId=1&tag=说说&limit=30').then(res => res.json()).then(data => { // 注意修改域名和用户id let items = [], html = '', icon = '<svg viewBox="0 0 512 512"xmlns="http://www.w3.org/2000/svg"class="is-badge icon"><path d="m512 268c0 17.9-4.3 34.5-12.9 49.7s-20.1 27.1-34.6 35.4c.4 2.7.6 6.9.6 12.6 0 27.1-9.1 50.1-27.1 69.1-18.1 19.1-39.9 28.6-65.4 28.6-11.4 0-22.3-2.1-32.6-6.3-8 16.4-19.5 29.6-34.6 39.7-15 10.2-31.5 15.2-49.4 15.2-18.3 0-34.9-4.9-49.7-14.9-14.9-9.9-26.3-23.2-34.3-40-10.3 4.2-21.1 6.3-32.6 6.3-25.5 0-47.4-9.5-65.7-28.6-18.3-19-27.4-42.1-27.4-69.1 0-3 .4-7.2 1.1-12.6-14.5-8.4-26-20.2-34.6-35.4-8.5-15.2-12.8-31.8-12.8-49.7 0-19 4.8-36.5 14.3-52.3s22.3-27.5 38.3-35.1c-4.2-11.4-6.3-22.9-6.3-34.3 0-27 9.1-50.1 27.4-69.1s40.2-28.6 65.7-28.6c11.4 0 22.3 2.1 32.6 6.3 8-16.4 19.5-29.6 34.6-39.7 15-10.1 31.5-15.2 49.4-15.2s34.4 5.1 49.4 15.1c15 10.1 26.6 23.3 34.6 39.7 10.3-4.2 21.1-6.3 32.6-6.3 25.5 0 47.3 9.5 65.4 28.6s27.1 42.1 27.1 69.1c0 12.6-1.9 24-5.7 34.3 16 7.6 28.8 19.3 38.3 35.1 9.5 15.9 14.3 33.4 14.3 52.4zm-266.9 77.1 105.7-158.3c2.7-4.2 3.5-8.8 2.6-13.7-1-4.9-3.5-8.8-7.7-11.4-4.2-2.7-8.8-3.6-13.7-2.9-5 .8-9 3.2-12 7.4l-93.1 140-42.9-42.8c-3.8-3.8-8.2-5.6-13.1-5.4-5 .2-9.3 2-13.1 5.4-3.4 3.4-5.1 7.7-5.1 12.9 0 5.1 1.7 9.4 5.1 12.9l58.9 58.9 2.9 2.3c3.4 2.3 6.9 3.4 10.3 3.4 6.7-.1 11.8-2.9 15.2-8.7z"fill="#1da1f2"></path></svg>'; data.forEach(item => { items.push(Format(item)) }); if (items.length == 30) document.querySelector('.limit').style.display = 'block'; items.forEach(item => { html += `<div class="talk_item" style="background: var(--icemyst-card-bg)"><div class="talk_meta"><img class="no-lightbox nolazyload avatar" src="/img/avatar.webp"><div class="info"><span class="talk_nick">萌傀儡${icon}</span><span class="talk_date">${item.date}</span></div></div><div class="talk_content">${item.content}</div><div class="talk_bottom"><div><span class="talk_tag"># ${item.tag}</span></div><div class="bber-reply" onclick="rm.rightMenuCommentText('${item.content.split('<')[0]}')"><i class="anzhiyufont anzhiyu-icon-message"></i></div></div></div>` // 注意修改头像链接和名称 }) document.getElementById('talk').innerHTML = html waterfall('#talk') }) // 页面内容格式化 function Format(item) { let date = getTime(new Date(item.createdTs * 1000).toString()), content = item.content, tag = item.content.match(/\{(.*?)\}/g), imgs = content.match(/!\[.*\]\(.*?\)/g), musics = content.match(/{\s*music\s*(.*)\s*}/g), text = '', videos = content.match(/{\s*bilibili\s*(.*)\s*}/g); if (imgs) imgs = imgs.map(item => { return item.replace(/!\[.*\]\((.*?)\)/, '$1') }) if (item.resourceList.length) { if (!imgs) imgs = [] item.resourceList.forEach(t => { if (t.externalLink) imgs.push(t.externalLink) else imgs.push(`${url}/o/r/${t.id}/${t.publicId}/${t.filename}`) }) } // content = content.replace(/#(.*?)\s/g, '').replace(/{.*}/g, '').replace(/\!\[(.*?)\]\((.*?)\)/g, '').replace(/```/g, '').replace(/\[(.*?)\]\((.*?)\)/g, `<a href="$2">@$1</a>`); text = content.replace(/#(.*?)\s/g, '').replace(/\!\[(.*?)\]\((.*?)\)/g, '').replace(/\{(.*?)\}/g, '') content = text.replace(/\[(.*?)\]\((.*?)\)/g, `<a href="$2">@$1</a>`); if (imgs) { content += `<div class="zone_imgbox">` imgs.forEach(e => content += `<a href="${e}" data-fancybox="gallery" class="fancybox" data-thumb="${e}"><img class="nolazyload talk-img" src="${e}"></a>`) content += '</div>' } if (musics) musics.forEach(item => { content += `<meting-js auto="${item.replace(/{\s*music\s*(.*)\s*}/, '$1')}" theme="#4976f5" preload="metadata"></meting-js>` }) if (videos) videos.forEach(item => { content += `<div style="position: relative; padding: 30% 45%;margin-top: 10px;margin-bottom: 10px"><iframe style="position: absolute; width: 100%; height: 100%; left: 0; top: 0;" src="//player.bilibili.com/player.html?autoplay=0&bvid=${item.replace(/{\s*bilibili\s*(.*)\s*}/, '$1').replace(/.*video\/([^\/]*).*/, '$1')}" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>` }) return { content: content, date: date, tag: tag ? tag[0].replace(/\{(.*?)\}/, '$1') : '无标签', text: text.replace(/\[(.*?)\]\((.*?)\)/g, '[链接]' + `${imgs ? '[图片]' : ''}`) } } // 页面时间格式化 function getTime(time) { let d = new Date(time), ls = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()]; for (let i = 0; i < ls.length; i++) { ls[i] = ls[i] <= 9 ? '0' + ls[i] : ls[i] + '' } if (new Date().getFullYear() == ls[0]) return ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4] else return ls[0] + '年' + ls[1] + '月' + ls[2] + '日 ' + ls[3] +':'+ ls[4] }}</script>]]></content>
</entry>
<entry>
<title>message</title>
<link href="/message/index.html"/>
<url>/message/index.html</url>
<content type="html"><![CDATA[<style>#article-container a:not(.headerlink, .fancybox, .default-style a) { font-weight: 700; color: var(--font-color); padding: 0 3px; border-bottom: 2px var(--leonus-purple) solid;}#article-container a:not(.headerlink, .fancybox, .default-style a):hover { color: #fff; border-radius: 5px; text-decoration: none; background-color: var(--leonus-purple);}#danmu { width: 100%; height: calc(100% - 60px); position: fixed; left: 0; top: 60px; z-index: 1; pointer-events: none;}.hidedanmu { opacity: 0;}.hidedanmu * { pointer-events: none !important;}div#danmuBtn { display: flex; justify-content: center;}div#danmuBtn button { background: var(--leonus-purple); color: white; padding: 8px 20px; margin: 0 20px; border-radius: 100px;}.default-style { pointer-events: all; cursor: pointer; font-size: 16px; border-radius: 100px; overflow: hidden;}.default-style a { background-color: rgba(0, 0, 0, 0.5); transition: .3s; color: #eee !important; display: flex; align-items: center; justify-content: center; padding: 6px 16px 6px 6px; text-decoration: none !important;}.default-style a:hover { background-color: rgba(0, 0, 0, 0.7);}.default-style img { pointer-events: none; height: 30px; width: 30px; margin: 0 5px 0 0 !important; border-radius: 50% !important;}.default-style p { line-height: 1; pointer-events: none; margin: 0 !important; max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}</style><div class="note success flat"><p>如果有什么 <strong>想说的</strong>、<strong>想问的</strong> 或者 <strong>发现了本站的BUG</strong>,欢迎留言告知😊。</p></div><div class="note pink icon-padding flat"><i class="note-icon fa-solid fa-link"></i><p>若想 <strong>添加友链</strong> 请前往 <a href="/link/">友情链接</a> 页面进行友链申请😄</p></div><div id="danmuBtn"></div><div id="danmu"></div>]]></content>
</entry>
<entry>
<title></title>
<link href="/photos/index.html"/>
<url>/photos/index.html</url>
<content type="html"><![CDATA[<!-- 复制以下内容,上方内容是为了避免一些人看不懂放在哪 --><div class="gallery-photos page"><img src="/img/loading.gif" style="margin:auto"></div><style>#article-container a img {margin: 0; border-radius:0;}.gallery-photos{width:100%;margin-top: 10px;}.gallery-photo{min-height:5rem;width:24.97%;padding:4px;position: relative;}.gallery-photo a{border-radius:8px;display:block;overflow: hidden;}.gallery-photo img{display: block;width:100%;animation: fadeIn 1s;cursor: pointer;transition: all .4s ease-in-out !important;}.gallery-photo span.photo-title,.gallery-photo span.photo-time{max-width: calc(100% - 7px);line-height:1.8;position:absolute;left:4px;font-size:14px;background: rgba(0, 0, 0, 0.3);padding:0px 8px;color: #fff;animation: fadeIn 1s;}.gallery-photo span.photo-title{bottom:4px;border-radius: 0 8px 0 8px;}.gallery-photo span.photo-time{top:4px;border-radius: 8px 0 8px 0;}.gallery-photo:hover img{transform: scale(1.1);}@media screen and (max-width: 1100px) {.gallery-photo{width:33.3%;}}@media screen and (max-width: 768px) { .gallery-photo{width:49.9%;padding:3px} .gallery-photo span.photo-time{display:none} .gallery-photo span.photo-title{font-size:12px} .gallery-photo span.photo-title{left:3px;bottom:3px;}}@keyframes fadeIn{0% {opacity: 0;}100%{opacity: 1;}}</style>]]></content>
</entry>
<entry>
<title>隐私政策</title>
<link href="/privacy/index.html"/>
<url>/privacy/index.html</url>
<content type="html"><![CDATA[<p>本站非常重视用户的隐私和个人信息保护。你在使用网站时,可能会收集和使用你的相关信息。通过《隐私政策》向你说明在你访问 <code>hcer.top</code>网站时,如何收集、使用、保存、共享和转让这些信息。</p><h2 id="最新更新时间"><a href="#最新更新时间" class="headerlink" title="最新更新时间"></a>最新更新时间</h2><p>协议最新更新时间为:2023-05-01</p><h2 id="一、在访问时如何收集和使用你的个人信息"><a href="#一、在访问时如何收集和使用你的个人信息" class="headerlink" title="一、在访问时如何收集和使用你的个人信息"></a>一、在访问时如何收集和使用你的个人信息</h2><h3 id="在访问时,收集访问信息的服务会收集不限于以下信息:"><a href="#在访问时,收集访问信息的服务会收集不限于以下信息:" class="headerlink" title="在访问时,收集访问信息的服务会收集不限于以下信息:"></a>在访问时,收集访问信息的服务会收集不限于以下信息:</h3><p><strong>网络身份标识信息</strong>(浏览器 UA、IP 地址)</p><p><strong>设备信息</strong></p><p><strong>浏览过程</strong>操作方式、浏览方式与时长、性能与网络加载情况)。</p><h3 id="在访问时,本站内置的第三方服务会通过以下或更多途径,来获取你的以下或更多信息:"><a href="#在访问时,本站内置的第三方服务会通过以下或更多途径,来获取你的以下或更多信息:" class="headerlink" title="在访问时,本站内置的第三方服务会通过以下或更多途径,来获取你的以下或更多信息:"></a>在访问时,本站内置的第三方服务会通过以下或更多途径,来获取你的以下或更多信息:</h3><ul><li><strong>百度统计工具</strong> 会收集你的访问信息、访问操作过程</li><li><strong>51la 统计工具</strong> 会收集你的访问信息</li><li><strong>灵雀应用监控平台</strong> 会收集你的访问操作过程和资源加载情况</li><li><strong>今日头条搜索</strong> 会收集你的访问信息</li><li><strong>字节跳动静态资源库</strong> 会收集你的访问信息</li><li><strong>Tianlicdn</strong> 会收集你的访问信息</li><li><strong>busuanzi 统计</strong> 会收集你的访问信息</li><li><strong>腾讯云</strong> 会收集你的访问信息</li><li><strong>腾讯 Codesign</strong> 会收集你的访问信息</li><li><strong>QQ 音乐</strong> 会收集你的访问信息</li><li><strong>网易云 音乐</strong> 会收集你的访问信息</li></ul><h3 id="在访问时,本人仅会处于以下目的,使用你的个人信息:"><a href="#在访问时,本人仅会处于以下目的,使用你的个人信息:" class="headerlink" title="在访问时,本人仅会处于以下目的,使用你的个人信息:"></a>在访问时,本人仅会处于以下目的,使用你的个人信息:</h3><ul><li>用于网站的优化与文章分类,用户优化文章</li><li>恶意访问识别,用于维护网站</li><li>恶意攻击排查,用于维护网站</li><li>网站点击情况监测,用于优化网站页面</li><li>网站加载情况监测,用于优化网站性能</li><li>用于网站搜索结果优化</li><li>浏览数据的展示</li></ul><h3 id="第三方信息获取方将您的数据用于以下用途:"><a href="#第三方信息获取方将您的数据用于以下用途:" class="headerlink" title="第三方信息获取方将您的数据用于以下用途:"></a>第三方信息获取方将您的数据用于以下用途:</h3><p>第三方可能会用于其他目的,详情请访问对应第三方服务提供的隐私协议。</p><h3 id="你应该知道在你访问的时候不限于以下信息会被第三方获取并使用:"><a href="#你应该知道在你访问的时候不限于以下信息会被第三方获取并使用:" class="headerlink" title="你应该知道在你访问的时候不限于以下信息会被第三方获取并使用:"></a>你应该知道在你访问的时候不限于以下信息会被第三方获取并使用:</h3><p>第三方部分为了抵抗攻击、使用不同节点 cdn 加速等需求会收集不限于以下信息</p><!-- 在表格中添加 id 以便于通过 JavaScript 获取元素 --><table> <thead> <tr> <th>类型</th> <th>信息</th> </tr> </thead> <tbody> <tr> <td colspan="2" style="text-align: center;"><b>网络信息</b></td> </tr> <tr> <td>IP地址</td> <td><div id="userAgentIp"></div></td> </tr> <tr> <td>州/大陆</td> <td><div id="userAgentState"></div></td> </tr> <tr> <td>国家</td> <td><div id="userAgentCountry"></div></td> </tr> <tr> <td>省份</td> <td><div id="userAgentProv"></div></td> </tr> <tr> <td>城市</td> <td><div id="userAgentCity"></div></td> </tr> <tr> <td>区</td> <td><div id="userAgentDistrict"></div></td> </tr> <tr> <td>运营商</td> <td><div id="userAgentISP"></div></td> </tr> <tr> <td colspan="2" style="text-align: center;"><b>设备信息</b></td> </tr> <tr> <td>设备</td> <td><div id="userAgentDevice"></div></td> </tr> </tbody></table><h2 id="二、在评论时如何收集和使用你的个人信息"><a href="#二、在评论时如何收集和使用你的个人信息" class="headerlink" title="二、在评论时如何收集和使用你的个人信息"></a>二、在评论时如何收集和使用你的个人信息</h2><p>评论使用的是无登陆系统的匿名评论系统,你可以自愿填写真实的、或者虚假的信息作为你评论的展示信息。</p><p><code>鼓励你使用不易被人恶意识别的昵称进行评论</code>,但是建议你填写<code>真实的邮箱</code>以便收到回复(邮箱信息不会被公开)。</p><p>在你评论时,会额外收集你的个人信息。</p><h3 id="在评论时,本站内置的第三方服务会通过以下或更多途径,来获取你的相关信息:"><a href="#在评论时,本站内置的第三方服务会通过以下或更多途径,来获取你的相关信息:" class="headerlink" title="在评论时,本站内置的第三方服务会通过以下或更多途径,来获取你的相关信息:"></a>在评论时,本站内置的第三方服务会通过以下或更多途径,来获取你的相关信息:</h3><ul><li><code>cravatar</code> 会收集你的访问信息、评论填写的个人信息用于展示头像</li></ul><h3 id="在访问时,本人仅会处于以下目的,收集并使用以下信息:"><a href="#在访问时,本人仅会处于以下目的,收集并使用以下信息:" class="headerlink" title="在访问时,本人仅会处于以下目的,收集并使用以下信息:"></a>在访问时,本人仅会处于以下目的,收集并使用以下信息:</h3><ul><li>评论时会记录你的 QQ 账号(如果在邮箱位置填写 QQ 邮箱或 QQ 号),方便获取你的 QQ 头像。如果使用 QQ 邮箱但不想展示 QQ头像,可以填写不含 QQ 号的 QQ 邮箱。(主动,存储)</li><li>评论时会记录你的邮箱,当我回复后会通过邮件通知你(主动,存储,不会公开邮箱)</li><li>评论时会记录你的网址,用于点击头像时快速进入你的网站(主动,存储)</li><li>评论时会记录你的 IP 地址,作为反垃圾的用户判别依据(被动,存储,不会公开 IP,会公开 IP 所在城市)</li><li>评论会记录你的浏览器代理,用作展示系统版本、浏览器版本方便展示你使用的设备,快速定位问题(被动,存储)</li></ul><h2 id="三、如何使用-Cookies-和本地-LocalStorage-存储"><a href="#三、如何使用-Cookies-和本地-LocalStorage-存储" class="headerlink" title="三、如何使用-Cookies-和本地-LocalStorage-存储"></a>三、如何使用-Cookies-和本地-LocalStorage-存储</h2><p>本站为实现无账号评论、深色模式切换,不蒜子的 uv 统计等功能,会在你的浏览器中进行本地存储,你可以随时清除浏览器中保存的所有<br>Cookies 以及 LocalStorage,不影响你的正常使用。</p><p>本博客中的以下业务会在你的计算机上主动存储数据:</p><p><strong>内置服务</strong></p><ul><li>评论系统</li><li>即刻短文</li><li>中控台</li><li>胶囊音乐</li></ul><p><strong>第三方服务</strong></p><ul><li>百度统计</li><li>51a 统计</li><li>busuanzi 统计</li></ul><p>关于如何使用你的 Cookies,请访问 <a href="https://blog.qjqq.cn/cookies/">Cookies 政策</a>。</p><p>关于如何<a href="https://support.google.com/chrome/answer/95647?co=GENIE.Platform=Desktop&hl=zh-Hans">在 Chrome 中清除、启用和管理 Cookie</a>。</p><h2 id="四、如何共享、转让你的个人信息"><a href="#四、如何共享、转让你的个人信息" class="headerlink" title="四、如何共享、转让你的个人信息"></a>四、如何共享、转让你的个人信息</h2><p>本人不会与任何公司、组织和个人共享你的隐私信息</p><p>本人不会将你的个人信息转让给任何公司、组织和个人</p><p>第三方服务的共享、转让情况详见对应服务的隐私协议</p><h2 id="五、附属协议"><a href="#五、附属协议" class="headerlink" title="五、附属协议"></a>五、附属协议</h2><p>当监测到存在恶意访问、恶意请求、恶意攻击、恶意评论的行为时,为了防止增大受害范围,可能会临时将你的 ip<br>地址及访问信息短期内添加到黑名单,短期内禁止访问。</p><p>此黑名单可能被公开,并共享给其他站点(主体并非本人)使用,包括但不限于:IP 地址、设备信息、地理位置。</p><!-- 在模板文件中添加 JavaScript 代码 --><script> (async function() { async function getIpInfo() { var fetchUrl = "https://api.qjqq.cn/api/Local"; try { var response = await fetch(fetchUrl); var json = await response.json(); var ip = json.ip; var continent = json.data.continent; var country = json.data.country; var prov = json.data.prov; var city = json.data.city; var district = json.data.district; var isp = json.data.isp; document.getElementById("userAgentIp").innerHTML = ip; document.getElementById("userAgentState").innerHTML = continent; document.getElementById("userAgentCountry").innerHTML = country; document.getElementById("userAgentProv").innerHTML = prov; document.getElementById("userAgentCity").innerHTML = city; document.getElementById("userAgentDistrict").innerHTML = district; document.getElementById("userAgentISP").innerHTML = isp; var uaInfo = navigator.userAgent; document.getElementById("userAgentDevice").innerHTML = uaInfo; } catch (error) { console.error("An error occurred while fetching IP info:", error); } } await getIpInfo();})();</script>]]></content>
</entry>
<entry>
<title>文章标签</title>