Skip to content

Commit 4b042d4

Browse files
committed
Chore: add missing prompt dialog features
1 parent 33b6e66 commit 4b042d4

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

src/plugin/components/DialogWindow.vue

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,24 @@
2828
autocomplete="off"
2929
@submit.prevent="submitDialogForm"
3030
>
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>
3232
<input type="text"
33-
:placeholder="options.verification"
33+
:placeholder="isPrompt ? '' : options.verification"
3434
v-model="input"
3535
autocomplete="off"
3636
id="dg-input-elem"
3737
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+
/>
3942
</form>
4043
</div>
4144

4245
<div class="dg-content-footer" :class="customClass.footer">
4346
<component @click="clickLeftBtn()"
4447
:is="leftBtnComponent"
48+
:btn-state="leftBtnState"
4549
:loading="loading"
4650
:class="customClass.cancel"
4751
:visible="leftBtnVisible"
@@ -53,7 +57,8 @@
5357
</component>
5458

5559
<component @click="clickRightBtn()"
56-
:is="rightBtnComponent"
60+
:is="rightBtnState.component"
61+
:btn-state="rightBtnState"
5762
:loading="loading"
5863
:class="customClass.ok"
5964
:visible="rightBtnVisible"
@@ -73,7 +78,7 @@
7378
</div>
7479
</template>
7580

76-
<script>
81+
<script lang="ts">
7782
import {defineComponent} from "vue";
7883
import OkBtn from './OkButton.vue';
7984
import CancelBtn from './CancelButton.vue';
@@ -83,6 +88,7 @@ import {
8388
DIALOG_TYPES,
8489
CUSTOM_CLASS
8590
} from "../constants";
91+
import type {ButtonStateInterface} from "@/plugin/interface";
8692
// import {MessageMixin} from "@/plugin/mixins/MessageMixin";
8793
// import {ButtonMixin} from "@/plugin/mixins/ButtonMixin";
8894
@@ -144,6 +150,12 @@ export default defineComponent({
144150
return this.options[$1] || match
145151
})
146152
},
153+
promptHelpText () {
154+
return this.options.promptHelp
155+
.replace(/\[\+:(\w+)]/g, (match, $1) => {
156+
return this.options[$1] || match
157+
})
158+
},
147159
148160
// Refactored from MessageMixin
149161
messageHasTitle(){
@@ -154,8 +166,7 @@ export default defineComponent({
154166
return this.messageHasTitle ? this.options.message.title : null
155167
},
156168
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
159170
},
160171
// END - Refactored from MessageMixin
161172
@@ -185,37 +196,68 @@ export default defineComponent({
185196
},
186197
rightBtnText () {
187198
return this.options.reverse ? this.options.cancelText : this.options.okText
188-
}
199+
},
189200
// 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+
}
190226
},
191227
mounted () {
192228
this.setCustomClasses()
193-
this.isHardConfirm && this.$refs.inputElem.focus()
229+
;(this.isHardConfirm || this.isPrompt) && this.$refs.inputElem && this.$refs.inputElem.focus()
194230
},
195231
methods: {
196232
closeAtOutsideClick() {
197233
if (this.options.backdropClose === true) {
198234
this.cancel()
199235
}
200236
},
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()
203242
},
204-
clickLeftBtn(){
205-
this.options.reverse ? this.proceed() : this.cancel()
243+
submitDialogForm () {
244+
this.okBtnDisabled || this.proceed(this.getDefaultData())
206245
},
207-
submitDialogForm(){
208-
this.okBtnDisabled || this.proceed()
246+
getDefaultData () {
247+
return this.isPrompt ? this.input : null
209248
},
210-
proceed(){
249+
proceed(withData = null){
211250
if (this.loaderEnabled) {
212251
this.switchLoadingState(true)
213252
this.options.promiseResolver({
214253
close: this.close,
215-
loading: this.switchLoadingState
254+
loading: this.switchLoadingState,
255+
data: withData
216256
})
217257
} else {
218-
this.options.promiseResolver(true)
258+
this.options.promiseResolver({
259+
data: withData
260+
})
219261
this.close()
220262
}
221263
},

0 commit comments

Comments
 (0)