28
28
autocomplete =" off"
29
29
@submit.prevent =" submitDialogForm"
30
30
>
31
- <label for =" dg-input-elem" style =" font-size : 13px ; " >{{ hardConfirmHelpText }}</label >
31
+ <label for =" dg-input-elem" style =" font-size : 13px " >{{ isPrompt ? promptHelpText : hardConfirmHelpText }}</label >
32
32
<input type =" text"
33
- :placeholder =" options.verification"
33
+ :placeholder =" isPrompt ? '' : options.verification"
34
34
v-model =" input"
35
35
autocomplete =" off"
36
36
id =" dg-input-elem"
37
37
ref =" inputElem"
38
- style =" width : 100% ;margin-top : 10px ;padding : 5px 15px ; font-size : 16px ;border-radius : 4px ; border : 2px solid #eee ;" />
38
+ style =" width : 100% ;margin-top : 10px ;
39
+ padding : 5px 15px ; font-size : 16px ;
40
+ border-radius : 4px ; border : 2px solid #eee "
41
+ />
39
42
</form >
40
43
</div >
41
44
42
45
<div class =" dg-content-footer" :class =" customClass.footer" >
43
46
<component @click =" clickLeftBtn()"
44
47
:is =" leftBtnComponent"
48
+ :btn-state =" leftBtnState"
45
49
:loading =" loading"
46
50
:class =" customClass.cancel"
47
51
:visible =" leftBtnVisible"
53
57
</component >
54
58
55
59
<component @click =" clickRightBtn()"
56
- :is =" rightBtnComponent"
60
+ :is =" rightBtnState.component"
61
+ :btn-state =" rightBtnState"
57
62
:loading =" loading"
58
63
:class =" customClass.ok"
59
64
:visible =" rightBtnVisible"
73
78
</div >
74
79
</template >
75
80
76
- <script >
81
+ <script lang="ts" >
77
82
import {defineComponent } from " vue" ;
78
83
import OkBtn from ' ./OkButton.vue' ;
79
84
import CancelBtn from ' ./CancelButton.vue' ;
@@ -83,6 +88,7 @@ import {
83
88
DIALOG_TYPES ,
84
89
CUSTOM_CLASS
85
90
} from " ../constants" ;
91
+ import type {ButtonStateInterface } from " @/plugin/interface" ;
86
92
// import {MessageMixin} from "@/plugin/mixins/MessageMixin";
87
93
// import {ButtonMixin} from "@/plugin/mixins/ButtonMixin";
88
94
@@ -144,6 +150,12 @@ export default defineComponent({
144
150
return this .options [$1 ] || match
145
151
})
146
152
},
153
+ promptHelpText () {
154
+ return this .options .promptHelp
155
+ .replace (/ \[\+ :(\w + )]/ g , (match , $1 ) => {
156
+ return this .options [$1 ] || match
157
+ })
158
+ },
147
159
148
160
// Refactored from MessageMixin
149
161
messageHasTitle(){
@@ -154,8 +166,7 @@ export default defineComponent({
154
166
return this .messageHasTitle ? this .options .message .title : null
155
167
},
156
168
messageBody(){
157
- let m = this .options .message
158
- return (typeof m === ' string' ) ? m : (m .body || ' ' )
169
+ return this .messageHasTitle ? this .options .message .body : this .options .message
159
170
},
160
171
// END - Refactored from MessageMixin
161
172
@@ -185,37 +196,68 @@ export default defineComponent({
185
196
},
186
197
rightBtnText () {
187
198
return this .options .reverse ? this .options .cancelText : this .options .okText
188
- }
199
+ },
189
200
// END - Refactored from ButtonMixin
201
+
202
+ btnState(): Pick <ButtonStateInterface , ' loading' | ' options' > {
203
+ return {
204
+ loading: this .loading ,
205
+ options: this .options ,
206
+ }
207
+ },
208
+ rightBtnState(): ButtonStateInterface {
209
+ const { reverse } = this .options ;
210
+ return {
211
+ ... this .btnState ,
212
+ component: reverse ? CancelBtn : OkBtn ,
213
+ disabled: this .okBtnDisabled ,
214
+ visible: (this .options .window !== DIALOG_TYPES .ALERT ) || ! reverse
215
+ }
216
+ },
217
+ leftBtnState(): ButtonStateInterface {
218
+ const { reverse } = this .options ;
219
+ return {
220
+ ... this .btnState ,
221
+ component: ! reverse ? CancelBtn : OkBtn ,
222
+ disabled: this .cancelBtnDisabled ,
223
+ visible: ! this .cancelBtnDisabled || reverse ,
224
+ }
225
+ }
190
226
},
191
227
mounted () {
192
228
this .setCustomClasses ()
193
- this .isHardConfirm && this .$refs .inputElem .focus ()
229
+ ;( this .isHardConfirm || this . isPrompt ) && this . $refs . inputElem && this .$refs .inputElem .focus ()
194
230
},
195
231
methods: {
196
232
closeAtOutsideClick() {
197
233
if (this .options .backdropClose === true ) {
198
234
this .cancel ()
199
235
}
200
236
},
201
- clickRightBtn (){
202
- this .options .reverse ? this .cancel () : this .proceed ()
237
+ clickRightBtn () {
238
+ this .options .reverse ? this .cancel () : this .proceed (this .getDefaultData ())
239
+ },
240
+ clickLeftBtn () {
241
+ this .options .reverse ? this .proceed (this .getDefaultData ()) : this .cancel ()
203
242
},
204
- clickLeftBtn () {
205
- this .options . reverse ? this .proceed () : this .cancel ( )
243
+ submitDialogForm () {
244
+ this .okBtnDisabled || this .proceed (this .getDefaultData () )
206
245
},
207
- submitDialogForm () {
208
- this .okBtnDisabled || this .proceed ()
246
+ getDefaultData () {
247
+ return this .isPrompt ? this .input : null
209
248
},
210
- proceed (){
249
+ proceed(withData = null ){
211
250
if (this .loaderEnabled ) {
212
251
this .switchLoadingState (true )
213
252
this .options .promiseResolver ({
214
253
close: this .close ,
215
- loading: this .switchLoadingState
254
+ loading: this .switchLoadingState ,
255
+ data: withData
216
256
})
217
257
} else {
218
- this .options .promiseResolver (true )
258
+ this .options .promiseResolver ({
259
+ data: withData
260
+ })
219
261
this .close ()
220
262
}
221
263
},
0 commit comments