index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div class="general-dialog" v-if="value">
  3. <!-- 内容区域 -->
  4. <div class="dialog__container">
  5. <div class="dialog__close iconfont icon-close" @click="$emit('change', false)"></div>
  6. <div class="dialog__title">
  7. <slot name="title"></slot>
  8. <span v-text="title" v-if="!$slots.title"></span>
  9. </div>
  10. <div class="dialog__content">
  11. <slot></slot>
  12. <div class="dialog__content_text" v-text="content" v-if="!$slots.default"></div>
  13. </div>
  14. <div class="dialog__footer">
  15. <slot name="footer"></slot>
  16. <template v-if="!$slots.footer">
  17. <div class="btn confirm" @click="$emit('confirm')" v-if="confirm">
  18. {{ confirmText ? confirmText : '确定' }}
  19. </div>
  20. <div class="btn cancel" @click="$emit('cancel')" v-if="cancel">
  21. {{ cancelText ? cancelText : '取消' }}
  22. </div>
  23. </template>
  24. </div>
  25. </div>
  26. <!-- 遮罩层 -->
  27. <div class="dialog__mask"></div>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. model: {
  33. prop: 'value',
  34. event: 'change',
  35. },
  36. props: {
  37. title: {
  38. type: String,
  39. default: '提示',
  40. },
  41. content: String,
  42. value: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. confirm: {
  47. type: Boolean,
  48. default: true,
  49. },
  50. cancel: {
  51. type: Boolean,
  52. default: false,
  53. },
  54. confirmText: String,
  55. cancelText: String,
  56. },
  57. watch: {
  58. value(val) {
  59. this.$nextTick(() => {
  60. val ? document.body.classList.add('scroll-none') : document.body.classList.remove('scroll-none')
  61. if (!val) {
  62. this.$emit('closed')
  63. }
  64. })
  65. },
  66. },
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. @media screen and (min-width: 768px) {
  71. .general-dialog {
  72. position: relative;
  73. z-index: 999;
  74. .dialog__container {
  75. position: fixed;
  76. top: 50%;
  77. left: 50%;
  78. transform: translate(-50%, -50%);
  79. min-width: 400px;
  80. background: #fff;
  81. box-sizing: border-box;
  82. padding: 40px 32px 32px;
  83. z-index: 1;
  84. border-radius: 4px;
  85. .dialog__close {
  86. position: absolute;
  87. width: 36px;
  88. height: 36px;
  89. right: 8px;
  90. top: 8px;
  91. text-align: center;
  92. line-height: 36px;
  93. font-size: 24px;
  94. color: #b2b2b2;
  95. transition: all 0.2s;
  96. cursor: pointer;
  97. &:hover {
  98. color: #666;
  99. }
  100. }
  101. .dialog__title {
  102. font-size: 24px;
  103. color: #282828;
  104. text-align: center;
  105. }
  106. .dialog__content {
  107. padding: 32px 0;
  108. .dialog__content_text {
  109. font-size: 16px;
  110. color: #282828;
  111. text-align: center;
  112. }
  113. }
  114. .dialog__footer {
  115. .btn {
  116. height: 46px;
  117. border-radius: 4px;
  118. text-align: center;
  119. box-sizing: border-box;
  120. font-size: 14px;
  121. margin: 0 auto;
  122. cursor: pointer;
  123. &.confirm {
  124. line-height: 46px;
  125. background: #f3920d;
  126. color: #fff;
  127. }
  128. &.cancel {
  129. line-height: 44px;
  130. border: 1px solid #f3920d;
  131. color: #f3920d;
  132. margin-top: 16px;
  133. }
  134. }
  135. }
  136. }
  137. .dialog__mask {
  138. position: fixed;
  139. width: 100vw;
  140. height: 100vh;
  141. left: 0;
  142. top: 0;
  143. background: #000;
  144. opacity: 0.4;
  145. }
  146. }
  147. }
  148. @media screen and (max-width: 768px) {
  149. .general-dialog {
  150. position: relative;
  151. z-index: 999;
  152. .dialog__container {
  153. position: fixed;
  154. top: 50%;
  155. left: 50%;
  156. transform: translate(-50%, -50%);
  157. min-width: 76vw;
  158. background: #fff;
  159. box-sizing: border-box;
  160. padding: 7vw 7vw 6.4vw;
  161. z-index: 1;
  162. border-radius: 0.4vw;
  163. .dialog__close {
  164. position: absolute;
  165. width: 5.6vw;
  166. height: 5.6vw;
  167. right: 3.2vw;
  168. top: 3.2vw;
  169. text-align: center;
  170. line-height: 5.6vw;
  171. font-size: 4.8vw;
  172. color: #b2b2b2;
  173. transition: all 0.2s;
  174. cursor: pointer;
  175. &:hover {
  176. color: #666;
  177. }
  178. }
  179. .dialog__title {
  180. font-size: 4.8vw;
  181. color: #282828;
  182. text-align: center;
  183. }
  184. .dialog__content {
  185. padding: 3.2vw 0;
  186. .dialog__content_text {
  187. font-size: 3.6vw;
  188. color: #282828;
  189. line-height: 5.6vw;
  190. text-align: center;
  191. }
  192. }
  193. .dialog__footer {
  194. .btn {
  195. height: 8.8vw;
  196. border-radius: 0.4vw;
  197. text-align: center;
  198. box-sizing: border-box;
  199. font-size: 3.6vw;
  200. margin: 0 auto;
  201. cursor: pointer;
  202. &.confirm {
  203. line-height: 8.8vw;
  204. background: #f3920d;
  205. color: #fff;
  206. }
  207. &.cancel {
  208. line-height: 8.8vw;
  209. border: 0.1vw solid #f3920d;
  210. color: #f3920d;
  211. margin-top: 2.4vw;
  212. }
  213. }
  214. }
  215. }
  216. .dialog__mask {
  217. position: fixed;
  218. width: 100vw;
  219. height: 100vh;
  220. left: 0;
  221. top: 0;
  222. background: #000;
  223. opacity: 0.4;
  224. }
  225. }
  226. }
  227. </style>