-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from daichen-daisy/main
feat: form dialog & confirm fialog
- Loading branch information
Showing
9 changed files
with
478 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<template> | ||
<q-dialog ref="dialog" persistent @hide="onDialogHide"> | ||
<q-card :style="`width: ${width}`" class="q-pa-md"> | ||
<q-item> | ||
<q-item-section avatar class="q-pr-sm"> | ||
<q-icon name="announcement" color="accent" /> | ||
</q-item-section> | ||
<q-item-section class="q-py-sm"> | ||
<q-item-label class="text-weight-bold text-subtitle1"> | ||
{{ title }} | ||
</q-item-label> | ||
</q-item-section> | ||
<q-space /> | ||
</q-item> | ||
<q-card-section class="q-py-md"> | ||
{{ content }} | ||
</q-card-section> | ||
<q-card-actions align="right"> | ||
<q-btn | ||
v-for="button in buttons" | ||
:key="button.label" | ||
v-bind="button" | ||
v-close-popup | ||
flat | ||
:class="button.class" | ||
@click="onClick(button)" | ||
/> | ||
</q-card-actions> | ||
</q-card> | ||
</q-dialog> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType } from 'vue'; | ||
import { QDialog } from 'quasar'; | ||
import { DialogButton } from './type'; | ||
export default defineComponent({ | ||
name: 'ConfirmDialog', | ||
props: { | ||
title: { | ||
type: String, | ||
default: '弹窗', | ||
}, | ||
width: { | ||
type: String, | ||
default: '400px', | ||
}, | ||
content: { | ||
type: String, | ||
default: '描述', | ||
}, | ||
buttons: { | ||
type: Array as PropType<DialogButton[]>, | ||
default: () => { | ||
return []; | ||
}, | ||
}, | ||
}, | ||
emits: ['ok', 'hide'], | ||
methods: { | ||
show() { | ||
(this.$refs['dialog'] as QDialog).show(); | ||
}, | ||
hide() { | ||
(this.$refs['dialog'] as QDialog).hide(); | ||
}, | ||
onDialogHide() { | ||
this.$emit('hide'); | ||
}, | ||
onClick(button: DialogButton) { | ||
this.$emit('ok', { type: button.actionType }); | ||
this.hide(); | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<template> | ||
<q-dialog ref="dialog" persistent @hide="onDialogHide"> | ||
<q-card :style="`width: ${width}; max-width: 800px`"> | ||
<q-item> | ||
<q-item-section class="q-pa-sm"> | ||
<q-item-label class="text-weight-bold text-subtitle1"> | ||
{{ title }} | ||
</q-item-label> | ||
</q-item-section> | ||
<q-space /> | ||
<q-btn | ||
v-close-popup | ||
dense | ||
flat | ||
no-hover | ||
size="sm" | ||
icon="close" | ||
class="no-hover-btn" | ||
></q-btn> | ||
</q-item> | ||
<q-separator /> | ||
<q-card-section class="q-pa-sm"> | ||
<q-form ref="form" greedy> | ||
<slot name="form-content"></slot> | ||
</q-form> | ||
</q-card-section> | ||
<q-separator /> | ||
<q-card-actions align="right"> | ||
<q-btn v-if="!hideCancel" v-close-popup flat label="取消" /> | ||
<q-btn unelevated :label="okLabel" class="primary-btn" @click="save" /> | ||
</q-card-actions> | ||
</q-card> | ||
</q-dialog> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
import { QDialog } from 'quasar'; | ||
export default defineComponent({ | ||
name: 'FormDialog', | ||
props: { | ||
title: { | ||
type: String, | ||
default: '弹窗', | ||
}, | ||
width: { | ||
type: String, | ||
default: '500px', | ||
}, | ||
okLabel: { | ||
type: String, | ||
default: '保存', | ||
}, | ||
hideCancel: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
emits: ['confirm', 'close'], | ||
methods: { | ||
save() { | ||
(this.$refs['form'] as HTMLFormElement) | ||
.validate() | ||
.then((success: unknown) => { | ||
if (success) { | ||
this.$emit('confirm'); | ||
} | ||
}); | ||
}, | ||
hide() { | ||
(this.$refs['dialog'] as QDialog).hide(); | ||
}, | ||
onDialogHide() { | ||
this.$emit('close'); | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type DialogButton = { | ||
/** 选项的显示文本 */ | ||
label: string; | ||
actionType?: string; | ||
class?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.