index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <component
  3. :is="cname"
  4. v-bind="nestedProps"
  5. >
  6. <!-- <slot></slot>
  7. <template v-slot:footer>
  8. <slot name="footer"></slot>
  9. </template> -->
  10. <template v-for="(_, slotName) in $slots" :slot="slotName">
  11. <slot :name="slotName"></slot>
  12. </template>
  13. </component>
  14. </template>
  15. <script>
  16. export default {
  17. name: "",
  18. props: {
  19. width: {
  20. type: [String, Number],
  21. default: '70%'
  22. },
  23. // 组件名ElDialog或ElDrawer
  24. cname: {
  25. type: String,
  26. default: 'ElDrawer'
  27. },
  28. // 组件的props
  29. viewProps: {
  30. type: Object,
  31. default: () => ({})
  32. }
  33. },
  34. data() {
  35. return {
  36. title: '',
  37. visible: false
  38. }
  39. },
  40. computed: {
  41. nestedProps() {
  42. switch(this.cname) {
  43. case 'ElDialog':
  44. return {
  45. width: this.width,
  46. title: this.title,
  47. beforeClose: (done) => this.onClose(done),
  48. visible: this.visible,
  49. destroyOnClose: true,
  50. closeOnClickModal: true,
  51. ...this.viewProps
  52. }
  53. default:
  54. return {
  55. size: this.width,
  56. title: this.title,
  57. beforeClose: (done) => this.onClose(done),
  58. visible: this.visible,
  59. appendToBody: true,
  60. destroyOnClose: true,
  61. closeOnClickModal: true,
  62. ...this.viewProps
  63. }
  64. }
  65. },
  66. },
  67. methods: {
  68. onClose(done) {
  69. this.$emit('onClose');
  70. this.close();
  71. done();
  72. },
  73. open(t) {
  74. if (t) this.title = t;
  75. this.visible = true;
  76. },
  77. // 关闭弹窗
  78. close() {
  79. this.visible = false;
  80. },
  81. }
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. </style>