CusDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <el-dialog
  3. class="cus-dialog-container fm-dialog"
  4. :title="title"
  5. :visible.sync="dialogVisible"
  6. :close-on-click-modal="closeOnClickModal"
  7. append-to-body
  8. center
  9. :width="width"
  10. ref="elDialog"
  11. :id="id"
  12. v-drag-dialog="true"
  13. :fullscreen="fullscreen"
  14. top="10vh"
  15. :style="{'--scrollbarWidth': scrollbarWidth}"
  16. >
  17. <span v-if="show">
  18. <slot></slot>
  19. </span>
  20. <template #footer v-if="action">
  21. <span class="dialog-footer" v-loading="loading"
  22. :element-loading-text="loadingText">
  23. <slot name="action">
  24. <el-button @click="close">{{$t('fm.actions.cancel')}}</el-button>
  25. <el-button type="primary" @click="submit" >{{$t('fm.actions.confirm')}}</el-button>
  26. </slot>
  27. </span>
  28. </template>
  29. </el-dialog>
  30. </template>
  31. <script>
  32. import DragDialog from '../directive/drag-dialog'
  33. export default {
  34. directives: {
  35. DragDialog
  36. },
  37. props: {
  38. visible: Boolean,
  39. loadingText: {
  40. type: String,
  41. default: ''
  42. },
  43. title: {
  44. type: String,
  45. default: ''
  46. },
  47. width: {
  48. type: String,
  49. default: '600px'
  50. },
  51. form: {
  52. type: Boolean,
  53. default: true
  54. },
  55. action: {
  56. type: Boolean,
  57. default: true
  58. },
  59. fullscreen: {
  60. type: Boolean,
  61. default: false
  62. },
  63. closeOnClickModal: {
  64. type: Boolean,
  65. default: false
  66. }
  67. },
  68. computed: {
  69. show () {
  70. if (this.form) {
  71. return this.showForm
  72. } else {
  73. return true
  74. }
  75. }
  76. },
  77. data () {
  78. return {
  79. loading: false,
  80. dialogVisible: this.visible,
  81. id: 'dialog_' + new Date().getTime(),
  82. showForm: false,
  83. scrollbarWidth: '6px'
  84. }
  85. },
  86. methods: {
  87. close () {
  88. this.dialogVisible = false
  89. },
  90. submit () {
  91. this.loading = true
  92. this.$emit('on-submit')
  93. },
  94. end () {
  95. this.loading = false
  96. }
  97. },
  98. mounted () {
  99. if (navigator.userAgent.indexOf("Firefox") !== -1) {
  100. // 当前浏览器是火狐浏览器
  101. this.scrollbarWidth = '17px'
  102. }
  103. if (navigator.userAgent.includes('Macintosh')) {
  104. // 当前操作系统为 macOS
  105. this.scrollbarWidth = '0px'
  106. }
  107. },
  108. watch: {
  109. dialogVisible (val) {
  110. if (!val) {
  111. this.loading = false
  112. this.$emit('on-close')
  113. setTimeout(() => {
  114. this.showForm = false
  115. }, 300)
  116. } else {
  117. this.showForm = true
  118. }
  119. },
  120. visible (val) {
  121. this.dialogVisible = val
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. .cus-dialog-container{
  128. .el-scrollbar{
  129. .el-scrollbar__wrap{
  130. height: calc(100% + var(--scrollbarWidth));
  131. width: calc(100% + var(--scrollbarWidth));
  132. }
  133. }
  134. > .el-dialog > .el-dialog__header{
  135. background: rgb(230, 239, 245);
  136. padding: 10px;
  137. .el-dialog__headerbtn{
  138. top:10px;
  139. right: 10px;
  140. font-size: 20px;
  141. }
  142. }
  143. &.notitle{
  144. .el-dialog__header{
  145. padding: 0;
  146. }
  147. }
  148. .el-dialog--center .el-dialog__body{
  149. padding: 20px;
  150. text-align: left;
  151. }
  152. .el-dialog__footer{
  153. margin: 0 20px;
  154. // border-top: 1px dashed #ccc;
  155. padding: 15px 0 16px;
  156. text-align: center;
  157. position: relative;
  158. .dialog-footer{
  159. display: block;
  160. .circular{
  161. display: inline-block;
  162. vertical-align: middle;
  163. margin-right: 5px;
  164. width: 24px;
  165. height: 24px;
  166. }
  167. .el-loading-text{
  168. display: inline-block;
  169. vertical-align: middle;
  170. }
  171. .el-loading-spinner{
  172. margin-top: -12px;
  173. }
  174. }
  175. }
  176. }
  177. @media screen and (max-width: 768px) {
  178. .cus-dialog-container{
  179. .el-dialog{
  180. width: 100% !important;
  181. }
  182. }
  183. }
  184. </style>