33 type PinyinParts ,
44 type CharMatch ,
55} from ' ../idiom'
6+ import { ref , onMounted , onUnmounted } from ' vue' ;
67
78interface Props {
89 char: string ;
@@ -19,7 +20,36 @@ const toneSymbols: Record<string, string> = {
1920 ' 4' : ' \u02CB ' ,
2021};
2122
22- const getToneSymbol = (tone : string ) => toneSymbols [tone ] || ' ' ;
23+ const toneDisplay = ref <' symbol' | ' number' >(' symbol' );
24+
25+ const getToneDisplay = (tone : string ) => {
26+ if (toneDisplay .value === ' number' ) {
27+ return tone ;
28+ }
29+ return toneSymbols [tone ] || ' ' ;
30+ };
31+
32+ const handleToneDisplayChange = (event : Event ) => {
33+ const customEvent = event as CustomEvent ;
34+ toneDisplay .value = customEvent .detail ;
35+ };
36+
37+ onMounted (() => {
38+ const settings = localStorage .getItem (' settings' );
39+ if (settings ) {
40+ try {
41+ const parsed = JSON .parse (settings );
42+ toneDisplay .value = parsed .toneDisplay || ' symbol' ;
43+ } catch {
44+ toneDisplay .value = ' symbol' ;
45+ }
46+ }
47+ window .addEventListener (' toneDisplayChange' , handleToneDisplayChange );
48+ });
49+
50+ onUnmounted (() => {
51+ window .removeEventListener (' toneDisplayChange' , handleToneDisplayChange );
52+ });
2353 </script >
2454
2555<template >
@@ -31,8 +61,9 @@ const getToneSymbol = (tone: string) => toneSymbols[tone] || '';
3161 <span class =" final" :class =" { correct: match.pinyin.final === 2, present: match.pinyin.final === 1 }" >
3262 {{ pinyin.final }}
3363 </span >
34- <span class =" tone" :class =" { correct: match.pinyin.tone === 2, present: match.pinyin.tone === 1 }" >
35- {{ getToneSymbol(pinyin.tone) }}
64+ <span class =" tone"
65+ :class =" { correct: match.pinyin.tone === 2, present: match.pinyin.tone === 1, 'tone-symbol': toneDisplay === 'symbol' }" >
66+ {{ getToneDisplay(pinyin.tone) }}
3667 </span >
3768 </div >
3869 <div class =" char" >{{ char }}</div >
@@ -84,7 +115,7 @@ const getToneSymbol = (tone: string) => toneSymbols[tone] || '';
84115.pinyin .final.present ,
85116.pinyin .tone.present {
86117 color : #ff9800 ;
87- font-weight : bold ;
118+ /* font-weight: bold; */
88119}
89120
90121.char-box.correct .pinyin .initial.correct ,
@@ -102,10 +133,19 @@ const getToneSymbol = (tone: string) => toneSymbols[tone] || '';
102133}
103134
104135.pinyin {
105- font-size : 14 px ;
136+ font-size : 16 px ;
106137 color : #666 ;
107138}
108139
140+ .pinyin .tone {
141+ margin-left : 2px ;
142+ }
143+
144+ .pinyin .tone.tone-symbol {
145+ transform : scale (1.2 , 1 );
146+ display : inline-block ;
147+ }
148+
109149.char {
110150 font-size : 28px ;
111151 font-weight : normal ;
0 commit comments