hookehuyr

refactor(JoinFamily): 将内联样式提取到less文件并优化组件结构

将内联样式提取到单独的less文件中以提高可维护性
优化组件结构并使用语义化的类名
统一样式管理并减少重复代码
1 +/* JoinFamily/index.less */
2 +
3 +.motto-input-container {
4 + display: flex;
5 + justify-content: space-between;
6 + margin-bottom: 1rem;
7 +}
8 +
9 +.motto-input-box {
10 + width: 5rem;
11 + height: 5rem;
12 + text-align: center;
13 + border: 1px solid #d1d5db;
14 + border-radius: 0.5rem;
15 + display: flex;
16 + align-items: center;
17 + justify-content: center;
18 +}
19 +
20 +.motto-input {
21 + width: 100%;
22 + height: 100%;
23 + text-align: center;
24 + font-size: 1.5rem;
25 + background-color: transparent;
26 + border: none;
27 + outline: none;
28 + padding: 0;
29 + margin: 0;
30 + box-sizing: border-box;
31 + color: inherit;
32 +}
33 +
34 +.identity-title {
35 + font-size: 1.25rem;
36 + font-weight: 700;
37 + margin-bottom: 1rem;
38 +}
39 +
40 +.identity-grid {
41 + display: grid;
42 + grid-template-columns: repeat(2, 1fr);
43 + gap: 1rem;
44 +}
45 +
46 +.identity-item {
47 + display: flex;
48 + align-items: center;
49 + justify-content: center;
50 + padding: 1rem;
51 + border: 1px solid #e5e7eb;
52 + border-radius: 0.5rem;
53 +}
54 +
55 +.identity-item-selected {
56 + border-color: #3b82f6;
57 + background-color: #eff6ff;
58 +}
59 +
60 +.identity-item-content {
61 + display: flex;
62 + flex-direction: column;
63 + align-items: center;
64 +}
65 +
66 +.identity-item-icon {
67 + font-size: 1.5rem;
68 + margin-bottom: 0.5rem;
69 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
11 请输入家人提供的家训口令,加入家庭一起参与健康挑战 11 请输入家人提供的家训口令,加入家庭一起参与健康挑战
12 </view> 12 </view>
13 <!-- Input boxes --> 13 <!-- Input boxes -->
14 - <view class="flex justify-center gap-3 w-full mb-6"> 14 + <view class="motto-input-container">
15 <view 15 <view
16 v-for="(char, index) in mottoChars" 16 v-for="(char, index) in mottoChars"
17 :key="index" 17 :key="index"
18 - class="w-16 h-16 border border-gray-500 rounded-md flex items-center justify-center" 18 + class="motto-input-box"
19 :style="{ 19 :style="{
20 borderColor: focusedIndex === index ? '#3b82f6' : '#d1d5db' 20 borderColor: focusedIndex === index ? '#3b82f6' : '#d1d5db'
21 }" 21 }"
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
28 @keydown="(e) => handleKeyDown(index, e)" 28 @keydown="(e) => handleKeyDown(index, e)"
29 @focus="focusedIndex = index" 29 @focus="focusedIndex = index"
30 @blur="handleBlur(index)" 30 @blur="handleBlur(index)"
31 - class="w-full h-full text-center text-xl bg-transparent outline-none" 31 + class="motto-input"
32 /> 32 />
33 </view> 33 </view>
34 </view> 34 </view>
...@@ -38,36 +38,22 @@ ...@@ -38,36 +38,22 @@
38 </view> 38 </view>
39 <!-- Role selection --> 39 <!-- Role selection -->
40 <view class="mb-6"> 40 <view class="mb-6">
41 - <h3 class="text-base font-medium mb-4 border-t border-gray-300 pt-4"> 41 + <h3 class="identity-title">
42 选择您的身份 42 选择您的身份
43 </h3> 43 </h3>
44 - <view class="grid grid-cols-2 gap-3"> 44 + <view class="identity-grid">
45 <view 45 <view
46 v-for="role in familyRoles" 46 v-for="role in familyRoles"
47 :key="role.id" 47 :key="role.id"
48 :class="[ 48 :class="[
49 - 'flex items-center justify-center p-3 border rounded-md', 49 + 'identity-item',
50 - selectedRole === role.id 50 + { 'identity-item-selected': selectedRole === role.id }
51 - ? 'border-blue-500 bg-blue-50'
52 - : 'border-gray-200'
53 ]" 51 ]"
54 @click="selectedRole = role.id" 52 @click="selectedRole = role.id"
55 > 53 >
56 - <view class="flex flex-col items-center"> 54 + <view class="identity-item-content">
57 - <My 55 + <My size="20" class="identity-item-icon" />
58 - size="20" 56 + <span class="identity-item-label">{{ role.label }}</span>
59 - :class="[
60 - 'mb-1',
61 - selectedRole === role.id ? 'text-blue-500' : 'text-gray-400'
62 - ]"
63 - />
64 - <span
65 - :class="[
66 - selectedRole === role.id ? 'text-blue-500' : 'text-gray-600'
67 - ]"
68 - >
69 - {{ role.label }}
70 - </span>
71 </view> 57 </view>
72 </view> 58 </view>
73 </view> 59 </view>
...@@ -167,3 +153,6 @@ const handleJoinFamily = () => { ...@@ -167,3 +153,6 @@ const handleJoinFamily = () => {
167 } 153 }
168 }; 154 };
169 </script> 155 </script>
156 +<style lang="less">
157 +@import './index.less';
158 +</style>
......