index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="dialog" :class="[isH5 ? 'dialog-h5' : '', center ? 'center' : '']" v-if="show" @click.self="toggleView">
  3. <main class="dialog-main" :style="!background && {'background': 'none'}">
  4. <header v-if="isHeaderShow">
  5. <h1>{{title}}</h1>
  6. <i class="icon icon-close" @click="toggleView"></i>
  7. </header>
  8. <div class="dialog-main-content">
  9. <slot />
  10. </div>
  11. <footer v-if="isFooterShow">
  12. <button class="btn btn-cancel" @click="toggleView">{{$t('component.取消')}}</button>
  13. <button class="btn btn-default" @click="submit">{{$t('component.确定')}}</button>
  14. </footer>
  15. </main>
  16. </div>
  17. </template>
  18. <script lang="ts">
  19. import { defineComponent, reactive, watchEffect, toRefs } from 'vue';
  20. export default defineComponent({
  21. props: {
  22. show: {
  23. type: Boolean,
  24. default: () => false,
  25. },
  26. isHeaderShow: {
  27. type: Boolean,
  28. default: () => true,
  29. },
  30. isFooterShow: {
  31. type: Boolean,
  32. default: () => true,
  33. },
  34. background: {
  35. type: Boolean,
  36. default: () => true,
  37. },
  38. title: {
  39. type: String,
  40. default: () => '',
  41. },
  42. isH5: {
  43. type: Boolean,
  44. default: () => false,
  45. },
  46. center: {
  47. type: Boolean,
  48. default: () => false,
  49. },
  50. },
  51. setup(props:any, ctx:any) {
  52. const data = reactive({
  53. show: false,
  54. isHeaderShow: true,
  55. isFooterShow: true,
  56. background: true,
  57. title: '',
  58. });
  59. watchEffect(() => {
  60. data.show = props.show;
  61. data.title = props.title;
  62. data.isHeaderShow = props.isHeaderShow;
  63. data.isFooterShow = props.isFooterShow;
  64. data.background = props.background;
  65. });
  66. const toggleView = () => {
  67. data.show = !data.show;
  68. ctx.emit('update:show', data.show);
  69. };
  70. const submit = () => {
  71. ctx.emit('submit');
  72. toggleView();
  73. };
  74. return {
  75. ...toRefs(data),
  76. toggleView,
  77. submit,
  78. };
  79. },
  80. });
  81. </script>
  82. <style lang="scss" scoped src="./style/dialog.scss"></style>