index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div>
  3. <!-- 正常弹窗 -->
  4. <el-dialog
  5. v-show="!minimized"
  6. :visible.sync="visibleSync"
  7. :title="title"
  8. v-bind="$attrs"
  9. v-on="$listeners"
  10. :before-close="handleClose"
  11. >
  12. <template #title>
  13. <span>{{ title }}</span>
  14. <i
  15. class="el-icon-minus"
  16. style="cursor:pointer;float:right;margin-right:35px;"
  17. @click.stop="minimize"
  18. ></i>
  19. </template>
  20. <slot />
  21. <template #footer>
  22. <slot name="footer" />
  23. </template>
  24. </el-dialog>
  25. <!-- 最小化悬浮卡片 -->
  26. <div
  27. v-show="minimized"
  28. class="minimized-dialog"
  29. ref="minCard"
  30. @click="restore"
  31. >
  32. <i :class="minIcon"></i>
  33. <span>{{ minTitle || title }}</span>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. export default {
  39. name: "MinimizableDialog",
  40. props: {
  41. visible: {
  42. type: Boolean,
  43. required: true
  44. },
  45. title: {
  46. type: String,
  47. default: ""
  48. },
  49. minTitle: {
  50. type: String,
  51. default: ""
  52. },
  53. minIcon: {
  54. type: String,
  55. default: "el-icon-files"
  56. }
  57. },
  58. data() {
  59. return {
  60. minimized: false,
  61. visibleSync: this.visible
  62. };
  63. },
  64. watch: {
  65. visible(val) {
  66. this.visibleSync = val;
  67. if (val) this.minimized = false;
  68. },
  69. visibleSync(val) {
  70. this.$emit("update:visible", val);
  71. }
  72. },
  73. mounted() {
  74. this.moveMinCardToBody();
  75. },
  76. beforeDestroy() {
  77. this.removeMinCardFromBody();
  78. },
  79. methods: {
  80. moveMinCardToBody() {
  81. if (this.$refs.minCard && typeof window !== 'undefined') {
  82. document.body.appendChild(this.$refs.minCard);
  83. }
  84. },
  85. removeMinCardFromBody() {
  86. if (this.$refs.minCard && this.$refs.minCard.parentNode) {
  87. this.$refs.minCard.parentNode.removeChild(this.$refs.minCard);
  88. }
  89. },
  90. minimize() {
  91. this.minimized = true;
  92. this.visibleSync = false;
  93. this.$emit("minimize");
  94. },
  95. restore() {
  96. this.minimized = false;
  97. this.visibleSync = true;
  98. this.$emit("restore");
  99. },
  100. handleClose(done) {
  101. this.$emit("close");
  102. done();
  103. }
  104. }
  105. };
  106. </script>
  107. <style scoped>
  108. .minimized-dialog {
  109. position: fixed;
  110. right: 30px;
  111. bottom: 30px;
  112. background: #409EFF;
  113. color: #fff;
  114. padding: 10px 18px;
  115. border-radius: 20px;
  116. box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  117. cursor: pointer;
  118. z-index: 1000;
  119. display: flex;
  120. align-items: center;
  121. font-size: 15px;
  122. }
  123. .minimized-dialog:hover {
  124. box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  125. }
  126. .minimized-dialog i {
  127. margin-right: 8px;
  128. font-size: 18px;
  129. }
  130. </style>