tui-modal.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="tui-modal__container" :class="[show ? 'tui-modal-show' : '']" :style="{zIndex:zIndex}" @touchmove.stop.prevent>
  3. <view
  4. class="tui-modal-box"
  5. :style="{ width: width, padding: padding, borderRadius: radius, backgroundColor: backgroundColor,zIndex:zIndex+1 }"
  6. :class="[fadeIn || show ? 'tui-modal-normal' : 'tui-modal-scale', show ? 'tui-modal-show' : '']"
  7. >
  8. <view v-if="!custom">
  9. <view class="tui-modal-title" v-if="title">{{ title }}</view>
  10. <view class="tui-modal-content" :class="[title ? '' : 'tui-mtop']" :style="{ color: color, fontSize: size + 'rpx' }">{{ content }}</view>
  11. <view class="tui-modalBtn-box" :class="[button.length != 2 ? 'tui-flex-column' : '']">
  12. <block v-for="(item, index) in button" :key="index">
  13. <button
  14. class="tui-modal-btn"
  15. :class="[
  16. 'tui-' + (item.type || 'primary') + (item.plain ? '-outline' : ''),
  17. button.length != 2 ? 'tui-btn-width' : '',
  18. button.length > 2 ? 'tui-mbtm' : '',
  19. shape == 'circle' ? 'tui-circle-btn' : ''
  20. ]"
  21. :hover-class="'tui-' + (item.plain ? 'outline' : item.type || 'primary') + '-hover'"
  22. :data-index="index"
  23. @tap="handleClick"
  24. >
  25. {{ item.text || '确定' }}
  26. </button>
  27. </block>
  28. </view>
  29. </view>
  30. <view v-else><slot></slot></view>
  31. </view>
  32. <view class="tui-modal-mask" :class="[show ? 'tui-mask-show' : '']" :style="{zIndex:maskZIndex}" @tap="handleClickCancel"></view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. name: 'tuiModal',
  38. emits: ['click','cancel'],
  39. props: {
  40. //是否显示
  41. show: {
  42. type: Boolean,
  43. default: false
  44. },
  45. width: {
  46. type: String,
  47. default: '84%'
  48. },
  49. backgroundColor: {
  50. type: String,
  51. default: '#fff'
  52. },
  53. padding: {
  54. type: String,
  55. default: '40rpx 64rpx'
  56. },
  57. radius: {
  58. type: String,
  59. default: '24rpx'
  60. },
  61. //标题
  62. title: {
  63. type: String,
  64. default: ''
  65. },
  66. //内容
  67. content: {
  68. type: String,
  69. default: ''
  70. },
  71. //内容字体颜色
  72. color: {
  73. type: String,
  74. default: '#999'
  75. },
  76. //内容字体大小 rpx
  77. size: {
  78. type: Number,
  79. default: 28
  80. },
  81. //形状 circle, square
  82. shape: {
  83. type: String,
  84. default: 'square'
  85. },
  86. button: {
  87. type: Array,
  88. default: function() {
  89. return [
  90. {
  91. text: '取消',
  92. type: 'red',
  93. plain: true //是否空心
  94. },
  95. {
  96. text: '确定',
  97. type: 'red',
  98. plain: false
  99. }
  100. ];
  101. }
  102. },
  103. //点击遮罩 是否可关闭
  104. maskClosable: {
  105. type: Boolean,
  106. default: true
  107. },
  108. //淡入效果,自定义弹框插入input输入框时传true
  109. fadeIn: {
  110. type: Boolean,
  111. default: false
  112. },
  113. //自定义弹窗内容
  114. custom: {
  115. type: Boolean,
  116. default: false
  117. },
  118. //容器z-index
  119. zIndex:{
  120. type: Number,
  121. default: 9997
  122. },
  123. //mask z-index
  124. maskZIndex:{
  125. type: Number,
  126. default: 9990
  127. }
  128. },
  129. data() {
  130. return {};
  131. },
  132. methods: {
  133. handleClick(e) {
  134. if (!this.show) return;
  135. const dataset = e.currentTarget.dataset;
  136. this.$emit('click', {
  137. index: Number(dataset.index)
  138. });
  139. },
  140. handleClickCancel() {
  141. if (!this.maskClosable) return;
  142. this.$emit('cancel');
  143. }
  144. }
  145. };
  146. </script>
  147. <style scoped>
  148. .tui-modal__container {
  149. width: 100%;
  150. height: 100%;
  151. position: fixed;
  152. left: 0;
  153. top: 0;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. visibility: hidden;
  158. }
  159. .tui-modal-box {
  160. position: relative;
  161. opacity: 0;
  162. visibility: hidden;
  163. box-sizing: border-box;
  164. transition: all 0.3s ease-in-out;
  165. }
  166. .tui-modal-scale {
  167. transform: scale(0);
  168. }
  169. .tui-modal-normal {
  170. transform: scale(1);
  171. }
  172. .tui-modal-show {
  173. opacity: 1;
  174. visibility: visible;
  175. }
  176. .tui-modal-mask {
  177. position: fixed;
  178. top: 0;
  179. left: 0;
  180. right: 0;
  181. bottom: 0;
  182. background-color: rgba(0, 0, 0, 0.6);
  183. transition: all 0.3s ease-in-out;
  184. opacity: 0;
  185. visibility: hidden;
  186. }
  187. .tui-mask-show {
  188. visibility: visible;
  189. opacity: 1;
  190. }
  191. .tui-modal-title {
  192. text-align: center;
  193. font-size: 34rpx;
  194. color: #333;
  195. padding-top: 20rpx;
  196. font-weight: bold;
  197. }
  198. .tui-modal-content {
  199. text-align: center;
  200. color: #999;
  201. font-size: 28rpx;
  202. padding-top: 20rpx;
  203. padding-bottom: 60rpx;
  204. }
  205. .tui-mtop {
  206. margin-top: 30rpx;
  207. }
  208. .tui-mbtm {
  209. margin-bottom: 30rpx;
  210. }
  211. .tui-modalBtn-box {
  212. width: 100%;
  213. display: flex;
  214. align-items: center;
  215. justify-content: space-between;
  216. }
  217. .tui-flex-column {
  218. flex-direction: column;
  219. }
  220. .tui-modal-btn {
  221. width: 46%;
  222. height: 68rpx;
  223. line-height: 68rpx;
  224. position: relative;
  225. border-radius: 10rpx;
  226. font-size: 26rpx;
  227. overflow: visible;
  228. margin-left: 0;
  229. margin-right: 0;
  230. box-sizing: border-box;
  231. }
  232. /* #ifndef MP-QQ */
  233. .tui-modal-btn::after {
  234. content: ' ';
  235. position: absolute;
  236. width: 200%;
  237. height: 200%;
  238. -webkit-transform-origin: 0 0;
  239. transform-origin: 0 0;
  240. transform: scale(0.5, 0.5) translateZ(0);
  241. left: 0;
  242. top: 0;
  243. border-radius: 20rpx;
  244. z-index: 2;
  245. }
  246. /* #endif */
  247. .tui-btn-width {
  248. width: 80% !important;
  249. }
  250. .tui-primary {
  251. background: #5677fc;
  252. color: #fff;
  253. }
  254. .tui-primary-hover {
  255. background: #4a67d6;
  256. color: #e5e5e5;
  257. }
  258. .tui-primary-outline {
  259. color: #5677fc;
  260. background: transparent;
  261. /* #ifdef MP-QQ */
  262. border: 1rpx solid #5677fc;
  263. /* #endif */
  264. }
  265. /* #ifndef MP-QQ */
  266. .tui-primary-outline::after {
  267. border: 1px solid #5677fc;
  268. }
  269. /* #endif */
  270. .tui-danger {
  271. background: #ed3f14;
  272. color: #fff;
  273. }
  274. .tui-danger-hover {
  275. background: #d53912;
  276. color: #e5e5e5;
  277. }
  278. .tui-danger-outline {
  279. color: #ed3f14;
  280. background: transparent;
  281. /* #ifdef MP-QQ */
  282. border: 1rpx solid #ed3f14;
  283. /* #endif */
  284. }
  285. /* #ifndef MP-QQ */
  286. .tui-danger-outline::after {
  287. border: 1px solid #ed3f14;
  288. }
  289. /* #endif */
  290. .tui-red {
  291. background: #e41f19;
  292. color: #fff;
  293. }
  294. .tui-red-hover {
  295. background: #c51a15;
  296. color: #e5e5e5;
  297. }
  298. .tui-red-outline {
  299. color: #e41f19;
  300. background: transparent;
  301. /* #ifdef MP-QQ */
  302. border: 1rpx solid #e41f19;
  303. /* #endif */
  304. }
  305. /* #ifndef MP-QQ */
  306. .tui-red-outline::after {
  307. border: 1px solid #e41f19;
  308. }
  309. /* #endif */
  310. .tui-warning {
  311. background: #ff7900;
  312. color: #fff;
  313. }
  314. .tui-warning-hover {
  315. background: #e56d00;
  316. color: #e5e5e5;
  317. }
  318. .tui-warning-outline {
  319. color: #ff7900;
  320. background: transparent;
  321. /* #ifdef MP-QQ */
  322. border: 1rpx solid #ff7900;
  323. /* #endif */
  324. }
  325. /* #ifndef MP-QQ */
  326. .tui-warning-outline::after {
  327. border: 1px solid #ff7900;
  328. }
  329. /* #endif */
  330. .tui-green {
  331. background: #19be6b;
  332. color: #fff;
  333. }
  334. .tui-green-hover {
  335. background: #16ab60;
  336. color: #e5e5e5;
  337. }
  338. .tui-green-outline {
  339. color: #19be6b;
  340. background: transparent;
  341. /* #ifdef MP-QQ */
  342. border: 1rpx solid #19be6b;
  343. /* #endif */
  344. }
  345. /* #ifndef MP-QQ */
  346. .tui-green-outline::after {
  347. border: 1px solid #19be6b;
  348. }
  349. /* #endif */
  350. .tui-white {
  351. background: #fff;
  352. color: #333;
  353. }
  354. .tui-white-hover {
  355. background: #f7f7f9;
  356. color: #666;
  357. }
  358. .tui-white-outline {
  359. color: #333;
  360. background: transparent;
  361. /* #ifdef MP-QQ */
  362. border: 1rpx solid #333;
  363. /* #endif */
  364. }
  365. /* #ifndef MP-QQ */
  366. .tui-white-outline::after {
  367. border: 1px solid #333;
  368. }
  369. /* #endif */
  370. .tui-gray {
  371. background: #ededed;
  372. color: #999;
  373. }
  374. .tui-gray-hover {
  375. background: #d5d5d5;
  376. color: #898989;
  377. }
  378. .tui-gray-outline {
  379. color: #999;
  380. background: transparent;
  381. /* #ifdef MP-QQ */
  382. border: 1rpx solid #999;
  383. /* #endif */
  384. }
  385. /* #ifndef MP-QQ */
  386. .tui-gray-outline::after {
  387. border: 1px solid #999;
  388. }
  389. /* #endif */
  390. .tui-outline-hover {
  391. opacity: 0.6;
  392. }
  393. .tui-circle-btn {
  394. border-radius: 40rpx !important;
  395. }
  396. .tui-circle-btn::after {
  397. border-radius: 80rpx !important;
  398. }
  399. </style>