Skip to content

Commit e5e58a9

Browse files
author
sheepzh
committed
Optimize style of select
1 parent 3f43a49 commit e5e58a9

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/app/components/option/components/popup.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { unref, UnwrapRef } from "vue"
99

1010
import { ElDivider, ElInputNumber, ElOption, ElSelect, ElSwitch } from "element-plus"
1111
import { t } from "@app/locale"
12+
import { I18nKey, t as t_ } from "@i18n"
1213
import { defineComponent, h, reactive } from "vue"
1314
import optionService from "@service/option-service"
1415
import { renderOptionItem, tagText } from "../common"
@@ -18,6 +19,36 @@ import { ALL_DIMENSIONS } from "@util/stat"
1819
import { locale } from "@i18n"
1920
import { rotate } from "@util/array"
2021

22+
type LocaleStyle = {
23+
durationSelectWidth: number
24+
typeSelectWidth: number
25+
}
26+
27+
const STYLES: Messages<LocaleStyle> = {
28+
zh_CN: {
29+
typeSelectWidth: 85,
30+
durationSelectWidth: 80,
31+
},
32+
en: {
33+
typeSelectWidth: 115,
34+
durationSelectWidth: 110
35+
},
36+
ja: {
37+
typeSelectWidth: 85,
38+
durationSelectWidth: 105,
39+
},
40+
pt_PT: {
41+
typeSelectWidth: 155,
42+
durationSelectWidth: 120,
43+
},
44+
zh_TW: {
45+
typeSelectWidth: 85,
46+
durationSelectWidth: 80,
47+
},
48+
}
49+
50+
const tStyle = (key: I18nKey<LocaleStyle>) => t_(STYLES, { key })
51+
2152
const mergeDomain = (option: UnwrapRef<timer.option.PopupOption>) => h(ElSwitch, {
2253
modelValue: option.defaultMergeDomain,
2354
onChange: (newVal: boolean) => {
@@ -41,7 +72,7 @@ const typeOptions = () => ALL_DIMENSIONS.map(item => h(ElOption, { value: item,
4172
const typeSelect = (option: UnwrapRef<timer.option.PopupOption>) => h(ElSelect, {
4273
modelValue: option.defaultType,
4374
size: 'small',
44-
style: { width: '120px' },
75+
style: { width: `${tStyle(m => m.typeSelectWidth)}px` },
4576
onChange: (val: timer.stat.Dimension) => {
4677
option.defaultType = val
4778
optionService.setPopupOption(unref(option))
@@ -52,7 +83,7 @@ const durationOptions = () => ALL_POPUP_DURATION.map(item => h(ElOption, { value
5283
const durationSelect = (option: UnwrapRef<timer.option.PopupOption>) => h(ElSelect, {
5384
modelValue: option.defaultDuration,
5485
size: 'small',
55-
style: { width: t(msg => msg.option.popup.durationWidth) },
86+
style: { width: `${tStyle(m => m.durationSelectWidth)}px` },
5687
onChange: (val: PopupDuration) => {
5788
option.defaultDuration = val
5889
optionService.setPopupOption(unref(option))

src/i18n/message/app/option-resource.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"defaultMergeDomain": "{input} 打开时合并子域名",
99
"defaultDisplay": "打开时显示 {duration} {type}",
1010
"displaySiteName": "{input} 显示时是否使用 {siteName} 来代替域名",
11-
"durationWidth": "80px",
1211
"weekStart": "每周的第一天 {input}",
1312
"weekStartAsNormal": "按照惯例"
1413
},
@@ -107,7 +106,6 @@
107106
"defaultMergeDomain": "{input} 打開時合併子域名",
108107
"defaultDisplay": "打開時顯示 {duration} {type}",
109108
"displaySiteName": "{input} 顯示時是否使用 {siteName} 來代替域名",
110-
"durationWidth": "80px",
111109
"weekStart": "每週的第一天 {input}",
112110
"weekStartAsNormal": "按照慣例"
113111
},
@@ -193,7 +191,6 @@
193191
"defaultMergeDomain": "{input} Whether to merge subdomains on open",
194192
"defaultDisplay": "Show {duration} {type} on open",
195193
"displaySiteName": "{input} Whether to display {siteName} instead of URL",
196-
"durationWidth": "110px",
197194
"weekStart": "The first day for each week {input}",
198195
"weekStartAsNormal": "As Normal"
199196
},
@@ -293,7 +290,6 @@
293290
"defaultMergeDomain": "{input} オープン時にサブドメインをマージ",
294291
"defaultDisplay": "開くと {duration} {type} が表示されます",
295292
"displaySiteName": "{input} ホストの代わりに {siteName} を表示するかどうか",
296-
"durationWidth": "100px",
297293
"weekStart": "週の最初の日 {input}",
298294
"weekStartAsNormal": "いつものように"
299295
},

src/i18n/message/app/option.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type OptionMessage = {
1616
defaultMergeDomain: string
1717
defaultDisplay: string
1818
displaySiteName: string
19-
durationWidth: string
2019
weekStart: string
2120
weekStartAsNormal: string
2221
}

0 commit comments

Comments
 (0)