Skip to content

Commit 3efd2f2

Browse files
committed
Beautify the limit modal (sheepzh#270)
1 parent 0830cc6 commit 3efd2f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1117
-758
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
.idea
23
dist*
34

45
Timer_Safari_DEV

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"Qihu",
1818
"sheepzh",
1919
"vueuse",
20+
"webcomponents",
2021
"webstore",
2122
"webtime",
2223
"zrender"

src/api/chrome/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function onRuntimeMessage<T = any, R = any>(handler: ChromeMessageHandler
2626
// Can't use await/async in callback parameter
2727
chrome.runtime.onMessage.addListener((message: timer.mq.Request<T>, sender: chrome.runtime.MessageSender, sendResponse: timer.mq.Callback<R>) => {
2828
handler(message, sender).then((response: timer.mq.Response<R>) => sendResponse(response))
29-
// 'return ture' will force chrome to wait for the response processed in the above promise.
29+
// 'return true' will force chrome to wait for the response processed in the above promise.
3030
// @see https://github.com/mozilla/webextension-polyfill/issues/130
3131
return true
3232
})

src/app/components/Analysis/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,20 @@ const _default = defineComponent(() => {
5151
const { data: rows, loading } = useRequest(() => query(site.value), { deps: site })
5252

5353
initProvider(site, timeFormat, rows)
54-
return () => (
55-
<ContentContainer v-slots={{
54+
return () => <ContentContainer
55+
v-slots={{
5656
filter: () => <Filter
5757
site={site.value}
5858
timeFormat={timeFormat.value}
5959
onSiteChange={setSite}
6060
onTimeFormatChange={setTimeFormat}
61-
/>
62-
}}>
63-
<div v-loading={loading.value}>
61+
/>,
62+
default: () => <div v-loading={loading.value}>
6463
<Summary />
6564
<Trend />
6665
</div>
67-
</ContentContainer>
68-
)
66+
}}
67+
/>
6968
})
7069

7170
export default _default

src/app/components/Limit/LimitModify/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const _default = defineComponent({
3535
const { cond, enabled, name, time, visitTime, periods } = rule
3636
const toSave: timer.limit.Rule = {
3737
...modifyingItem || {},
38-
cond, enabled, name, time, visitTime, periods, allowDelay: false,
38+
cond, enabled, name, time, visitTime, periods
3939
}
4040
if (mode.value === 'modify') {
4141
await limitService.update(toSave)

src/app/components/Limit/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const _default = defineComponent(() => {
3232
{ defaultValue: [], deps: filterOption },
3333
)
3434
// Query data if the window become visible
35-
useWindowVisible(refresh)
35+
useWindowVisible({ onVisible: refresh })
3636

3737
const handleDelete = async (row: timer.limit.Item) => {
3838
await limitService.remove(row)

src/app/components/Option/components/LimitOption/index.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ import "./limit-option.sass"
1616
import { judgeVerificationRequired, processVerification } from "@app/util/limit"
1717
import limitService from "@service/limit-service"
1818

19-
const ALL_FILTER: timer.limit.FilterType[] = [
20-
'translucent',
21-
'groundGlass',
22-
]
23-
2419
const ALL_LEVEL: timer.limit.RestrictionLevel[] = [
2520
'nothing',
2621
'verification',
@@ -48,7 +43,7 @@ const verifyTriggered = async (option: timer.option.DailyLimitOption, verified:
4843
}
4944

5045
function copy(target: timer.option.DailyLimitOption, source: timer.option.DailyLimitOption) {
51-
target.limitFilter = source.limitFilter
46+
target.limitPrompt = source.limitPrompt
5247
target.limitLevel = source.limitLevel
5348
target.limitPassword = source.limitPassword
5449
target.limitVerifyDifficulty = source.limitVerifyDifficulty
@@ -83,22 +78,10 @@ const _default = defineComponent((_, ctx) => {
8378
ctx.expose({ reset: () => reset(option) } satisfies OptionInstance)
8479

8580
return () => <>
86-
<OptionItem
87-
label={msg => msg.option.dailyLimit.filter.label}
88-
defaultValue={t(msg => msg.option.dailyLimit.filter[defaultDailyLimit().limitFilter])}
89-
hideDivider
90-
>
91-
<ElSelect
92-
modelValue={option.limitFilter}
93-
size="small"
94-
onChange={val => option.limitFilter = val}
95-
>
96-
{ALL_FILTER.map(item => <ElOption value={item} label={t(msg => msg.option.dailyLimit.filter[item])} />)}
97-
</ElSelect>
98-
</OptionItem>
9981
<OptionItem
10082
label={msg => msg.option.dailyLimit.level.label}
10183
defaultValue={t(msg => msg.option.dailyLimit.level[defaultDailyLimit().limitLevel])}
84+
hideDivider
10285
>
10386
<ElSelect
10487
modelValue={option.limitLevel}
@@ -145,6 +128,15 @@ const _default = defineComponent((_, ctx) => {
145128
{ALL_DIFF.map(item => <ElOption value={item} label={t(msg => msg.option.dailyLimit.level.verificationDifficulty[item])} />)}
146129
</ElSelect>
147130
</OptionItem>
131+
<OptionItem label={msg => msg.option.dailyLimit.prompt}>
132+
<ElInput
133+
modelValue={option.limitPrompt}
134+
size="small"
135+
onInput={val => option.limitPrompt = val}
136+
placeholder={t(msg => msg.limitModal.defaultPrompt)}
137+
style={{ width: "250px" }}
138+
/>
139+
</OptionItem>
148140
</>
149141
})
150142

src/app/components/Option/style/index.sass

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
height: 28px
5353
.el-select__wrapper
5454
width: 120px
55+
.el-input
56+
margin-left: 10px
5557
.el-date-editor--time
5658
width: 100px
5759
.el-input__prefix

src/app/components/Report/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const _default = defineComponent(() => {
187187
)
188188

189189
// Query data if window become visible
190-
useWindowVisible(refresh)
190+
useWindowVisible({ onVisible: refresh })
191191

192192
const handleDownload = async (format: FileFormat) => {
193193
const rows = await statService.select(queryParam.value, true)

src/app/util/limit.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { locale } from "@i18n"
44
import { VerificationPair } from "@service/limit-service/verification/common"
55
import verificationProcessor from "@service/limit-service/verification/processor"
66
import { getCssVariable } from "@util/style"
7-
import { ElMessageBox, ElMessage } from "element-plus"
7+
import { ElMessageBox, ElMessage, type ElMessageBoxOptions } from "element-plus"
88
import { defineComponent, onMounted, ref, VNode } from "vue"
99
import { sendMsg2Runtime } from "@api/chrome/runtime"
1010
import { hasLimited, dateMinute2Idx } from "@util/limit"
@@ -76,19 +76,21 @@ const AnswerCanvas = defineComponent({
7676
})
7777
})
7878

79-
/**
79+
/**
8080
* NOT TO return Promise.resolve()
81-
*
82-
* NOT USE async
83-
*
81+
*
82+
* NOT TO use async
83+
*
8484
* @returns null if verification not required,
8585
* or promise with resolve invoked only if verification code or password correct
8686
*/
87-
export function processVerification(option: timer.option.DailyLimitOption): Promise<void> {
87+
export function processVerification(option: timer.option.DailyLimitOption, context?: Pick<ElMessageBoxOptions, 'appendTo'>): Promise<void> {
8888
const { limitLevel, limitPassword, limitVerifyDifficulty } = option
89+
const { appendTo } = context || {}
8990
if (limitLevel === "strict") {
9091
return new Promise(
9192
(_, reject) => ElMessageBox({
93+
appendTo,
9294
boxType: 'alert',
9395
type: 'warning',
9496
title: '',
@@ -134,6 +136,7 @@ export function processVerification(option: timer.option.DailyLimitOption): Prom
134136

135137
return new Promise(resolve => {
136138
ElMessageBox({
139+
appendTo,
137140
boxType: 'prompt',
138141
type: 'warning',
139142
title: '',
@@ -144,7 +147,7 @@ export function processVerification(option: timer.option.DailyLimitOption): Prom
144147
}).then(data => {
145148
const { value } = data
146149
if (value === answerValue) return resolve()
147-
ElMessage.error(incorrectMessage)
150+
ElMessage.error({ appendTo, message: incorrectMessage })
148151
}).catch(() => { })
149152
})
150153
}

0 commit comments

Comments
 (0)