index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. })
  62. },
  63. },
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. @media screen and (min-width: 768px) {
  68. .general-dialog {
  69. position: relative;
  70. z-index: 999;
  71. .dialog__container {
  72. position: fixed;
  73. top: 50%;
  74. left: 50%;
  75. transform: translate(-50%, -50%);
  76. min-width: 400px;
  77. background: #fff;
  78. box-sizing: border-box;
  79. padding: 40px 32px 32px;
  80. z-index: 1;
  81. border-radius: 4px;
  82. .dialog__close {
  83. position: absolute;
  84. width: 36px;
  85. height: 36px;
  86. right: 8px;
  87. top: 8px;
  88. text-align: center;
  89. line-height: 36px;
  90. font-size: 24px;
  91. color: #b2b2b2;
  92. transition: all 0.2s;
  93. cursor: pointer;
  94. &:hover {
  95. color: #666;
  96. }
  97. }
  98. .dialog__title {
  99. font-size: 24px;
  100. color: #282828;
  101. text-align: center;
  102. }
  103. .dialog__content {
  104. padding: 32px 0;
  105. .dialog__content_text {
  106. font-size: 16px;
  107. color: #282828;
  108. text-align: center;
  109. }
  110. }
  111. .dialog__footer {
  112. .btn {
  113. height: 46px;
  114. border-radius: 4px;
  115. text-align: center;
  116. box-sizing: border-box;
  117. font-size: 14px;
  118. margin: 0 auto;
  119. cursor: pointer;
  120. &.confirm {
  121. line-height: 46px;
  122. background: #f3920d;
  123. color: #fff;
  124. }
  125. &.cancel {
  126. line-height: 44px;
  127. border: 1px solid #f3920d;
  128. color: #f3920d;
  129. margin-top: 16px;
  130. }
  131. }
  132. }
  133. }
  134. .dialog__mask {
  135. position: fixed;
  136. width: 100vw;
  137. height: 100vh;
  138. left: 0;
  139. top: 0;
  140. background: #000;
  141. opacity: 0.4;
  142. }
  143. }
  144. }
  145. @media screen and (max-width: 768px) {
  146. .general-dialog {
  147. position: relative;
  148. z-index: 999;
  149. .dialog__container {
  150. position: fixed;
  151. top: 50%;
  152. left: 50%;
  153. transform: translate(-50%, -50%);
  154. min-width: 76vw;
  155. background: #fff;
  156. box-sizing: border-box;
  157. padding: 7vw 7vw 6.4vw;
  158. z-index: 1;
  159. border-radius: 0.4vw;
  160. .dialog__close {
  161. position: absolute;
  162. width: 5.6vw;
  163. height: 5.6vw;
  164. right: 3.2vw;
  165. top: 3.2vw;
  166. text-align: center;
  167. line-height: 5.6vw;
  168. font-size: 4.8vw;
  169. color: #b2b2b2;
  170. transition: all 0.2s;
  171. cursor: pointer;
  172. &:hover {
  173. color: #666;
  174. }
  175. }
  176. .dialog__title {
  177. font-size: 4.8vw;
  178. color: #282828;
  179. text-align: center;
  180. }
  181. .dialog__content {
  182. padding: 3.2vw 0;
  183. .dialog__content_text {
  184. font-size: 3.6vw;
  185. color: #282828;
  186. line-height: 5.6vw;
  187. text-align: center;
  188. }
  189. }
  190. .dialog__footer {
  191. .btn {
  192. height: 8.8vw;
  193. border-radius: 0.4vw;
  194. text-align: center;
  195. box-sizing: border-box;
  196. font-size: 3.6vw;
  197. margin: 0 auto;
  198. cursor: pointer;
  199. &.confirm {
  200. line-height: 8.8vw;
  201. background: #f3920d;
  202. color: #fff;
  203. }
  204. &.cancel {
  205. line-height: 8.8vw;
  206. border: 0.1vw solid #f3920d;
  207. color: #f3920d;
  208. margin-top: 2.4vw;
  209. }
  210. }
  211. }
  212. }
  213. .dialog__mask {
  214. position: fixed;
  215. width: 100vw;
  216. height: 100vh;
  217. left: 0;
  218. top: 0;
  219. background: #000;
  220. opacity: 0.4;
  221. }
  222. }
  223. }
  224. </style>