@@ -9,12 +9,40 @@ import { Delete, Edit } from "@element-plus/icons-vue"
99import { ElButton , ElMessageBox , ElTableColumn } from "element-plus"
1010import { defineComponent , h } from "vue"
1111import { t } from "@app/locale"
12+ import optionService from "@service/option-service"
13+ import { judgeVerificationRequired , processVerification } from "./common"
1214
1315const label = t ( msg => msg . limit . item . operation )
1416const deleteButtonText = t ( msg => msg . button . delete )
1517const modifyButtonText = t ( msg => msg . button . modify )
18+
19+ async function handleDelete ( row : timer . limit . Item , callback : ( ) => void ) {
20+ let promise = undefined
21+ if ( judgeVerificationRequired ( row ) ) {
22+ const option = await optionService . getAllOption ( ) as timer . option . DailyLimitOption
23+ promise = processVerification ( option )
24+ }
25+ if ( ! promise ) {
26+ const message = t ( msg => msg . limit . message . deleteConfirm , { cond : row . cond } )
27+ promise = ElMessageBox . confirm ( message , { type : 'warning' } )
28+ }
29+ promise . then ( callback ) . catch ( ( ) => { /** Do nothing */ } )
30+ }
31+
32+ async function handleModify ( row : timer . limit . Item , callback : ( ) => void ) {
33+ let promise : Promise < void > = undefined
34+ if ( judgeVerificationRequired ( row ) ) {
35+ const option = await optionService . getAllOption ( ) as timer . option . DailyLimitOption
36+ promise = processVerification ( option )
37+ promise
38+ ? promise . then ( callback ) . catch ( ( ) => { } )
39+ : callback ( )
40+ } else {
41+ callback ( )
42+ }
43+ }
44+
1645const _default = defineComponent ( {
17- name : "LimitOperationColumn" ,
1846 emits : {
1947 rowDelete : ( _row : timer . limit . Item , _cond : string ) => true ,
2048 rowModify : ( _row : timer . limit . Item ) => true ,
@@ -31,19 +59,13 @@ const _default = defineComponent({
3159 type : 'danger' ,
3260 size : 'small' ,
3361 icon : Delete ,
34- onClick ( ) {
35- const { cond } = row
36- const message = t ( msg => msg . limit . message . deleteConfirm , { cond } )
37- ElMessageBox . confirm ( message , { type : 'warning' } )
38- . then ( ( ) => ctx . emit ( "rowDelete" , row , cond ) )
39- . catch ( ( ) => { /** Do nothing */ } )
40- }
62+ onClick : ( ) => handleDelete ( row , ( ) => ctx . emit ( "rowDelete" , row , row . cond ) )
4163 } , ( ) => deleteButtonText ) ,
4264 h ( ElButton , {
4365 type : 'primary' ,
4466 size : 'small' ,
4567 icon : Edit ,
46- onClick : ( ) => ctx . emit ( 'rowModify' , row ) ,
68+ onClick : ( ) => handleModify ( row , ( ) => ctx . emit ( 'rowModify' , row ) ) ,
4769 } , ( ) => modifyButtonText )
4870 ]
4971 } )
0 commit comments