Drawer.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="drawer-dialog">
  3. <el-drawer
  4. :custom-class="customClass"
  5. :show-close="showClose"
  6. :append-to-body="false"
  7. :visible.sync="drawerFlag"
  8. :direction="direction"
  9. :size="percent"
  10. :withHeader="withHeader"
  11. @before-close="beforeClose"
  12. @close="close"
  13. >
  14. <div class="el-container">
  15. <div class="el-header">
  16. <div slot="title">{{ title }}</div>
  17. </div>
  18. <div class="el-main">
  19. <slot></slot>
  20. </div>
  21. <div class="el-footer">
  22. <el-button class="el-btn el-save" @click="saveData">{{ confirmText }}</el-button>
  23. <el-button class="el-btn el-cancel" @click="close">{{ cancelText }}</el-button>
  24. </div>
  25. </div>
  26. </el-drawer>
  27. </div>
  28. </template>
  29. <script>
  30. import { Drawer, Button } from 'element-ui'
  31. export default {
  32. name: 'drawer-dialog',
  33. components: {
  34. [Drawer.name]: Drawer,
  35. [Button.name]: Button
  36. },
  37. props: {
  38. showDrawer: {
  39. type: Boolean,
  40. default: false
  41. },
  42. customClass: {
  43. type: String,
  44. default: ''
  45. },
  46. confirmText: {
  47. type: String,
  48. default: '保存设置'
  49. },
  50. cancelText: {
  51. type: String,
  52. default: '取消'
  53. },
  54. percent: {
  55. type: String,
  56. default: '42%'
  57. },
  58. direction: {
  59. type: String,
  60. default () {
  61. return 'rtl'
  62. }
  63. },
  64. // 控制是否显示 header 栏, 默认为 true, 当此项为 false 时, title attribute 和 title slot 均不生效
  65. withHeader: {
  66. type: Boolean,
  67. default: true
  68. },
  69. title: {
  70. type: String,
  71. default: ''
  72. },
  73. showClose: {
  74. type: Boolean,
  75. default: false
  76. }
  77. },
  78. model: {
  79. prop: 'showDrawer',
  80. event: 'change'
  81. },
  82. data () {
  83. return {
  84. drawerFlag: this.showDrawer
  85. }
  86. },
  87. watch: {
  88. showDrawer (val) {
  89. this.drawerFlag = val
  90. }
  91. },
  92. methods: {
  93. saveData () {
  94. this.$emit('saveData')
  95. },
  96. // 关闭回调
  97. close () {
  98. this.drawerFlag = false
  99. this.$emit('close', this.drawerFlag)
  100. },
  101. // 关闭前的回调,会暂停 Drawer 的关闭
  102. beforeClose () {
  103. this.$emit('beforeClose')
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .drawer-dialog{
  110. }
  111. ::v-deep .el-drawer__body{
  112. height: 100%;
  113. .el-container{
  114. display: flex;
  115. justify-content: space-between;
  116. flex-direction: column;
  117. height: 100%;
  118. }
  119. .el-main{
  120. flex: 1;
  121. overflow-y: scroll;
  122. padding: 0!important;
  123. }
  124. .el-footer {
  125. display: flex;
  126. justify-content: center;
  127. align-items: center;
  128. width: 100%;
  129. width: -moz-available;
  130. width: -webkit-fill-available;
  131. height: 72px;
  132. background: #FFFFFF;
  133. box-shadow: 0px -8px 8px 0px rgba(0,0,0,0.05);
  134. .el-btn{
  135. padding: 7px 34px;
  136. min-width: 132px;
  137. height: 36px;
  138. border-radius: 6px;
  139. border: 1px solid #2CB7CA;
  140. color: #2CB7CA;
  141. &.el-cancel {
  142. margin-left: 40px;
  143. color: #686868;
  144. border: 1px solid #E0E0E0;
  145. }
  146. }
  147. }
  148. }
  149. </style>