index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view>
  3. <sjs src="../wxs/utils.sjs" module="utils" />
  4. <van-overlay :wx:if="overlay" :show="show" :z-index="zIndex" :custom-style="overlayStyle" :duration="duration" @click="onClickOverlay" />
  5. <view
  6. :wx:if="inited"
  7. :class="'custom-class ' + classes + ' ' + utils.bem('popup', [position, { round, safe: safeAreaInsetBottom, safeTop: safeAreaInsetTop }])"
  8. :style="
  9. 'z-index: ' +
  10. zIndex +
  11. '; -webkit-transition-duration:' +
  12. currentDuration +
  13. 'ms; transition-duration:' +
  14. currentDuration +
  15. 'ms; ' +
  16. (display ? '' : 'display: none;') +
  17. ';' +
  18. customStyle
  19. "
  20. @transitionend="onTransitionEnd"
  21. >
  22. <slot />
  23. <van-icon :wx:if="closeable" :name="closeIcon" :class="'van-popup__close-icon van-popup__close-icon--' + closeIconPosition" @tap.native="onClickCloseIcon" />
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { VantComponent } from '../common/component';
  29. import { transition } from '../mixins/transition';
  30. export default {
  31. data() {
  32. return {
  33. show: '',
  34. duration: '',
  35. inited: '',
  36. classes: '',
  37. display: false,
  38. currentDuration: ''
  39. };
  40. },
  41. classes: ['enter-class', 'enter-active-class', 'enter-to-class', 'leave-class', 'leave-active-class', 'leave-to-class'],
  42. mixins: [transition(false)],
  43. props: {
  44. round: Boolean,
  45. closeable: Boolean,
  46. customStyle: String,
  47. overlayStyle: String,
  48. transition: {
  49. type: String
  50. },
  51. zIndex: {
  52. type: Number,
  53. default: 100
  54. },
  55. overlay: {
  56. type: Boolean,
  57. default: true
  58. },
  59. closeIcon: {
  60. type: String,
  61. default: 'cross'
  62. },
  63. closeIconPosition: {
  64. type: String,
  65. default: 'top-right'
  66. },
  67. closeOnClickOverlay: {
  68. type: Boolean,
  69. default: true
  70. },
  71. position: {
  72. type: String,
  73. default: 'center'
  74. },
  75. safeAreaInsetBottom: {
  76. type: Boolean,
  77. default: true
  78. },
  79. safeAreaInsetTop: {
  80. type: Boolean,
  81. default: false
  82. }
  83. },
  84. created() {
  85. this.observeClass();
  86. },
  87. methods: {
  88. onClickCloseIcon() {
  89. this.$emit('close');
  90. },
  91. onClickOverlay() {
  92. this.$emit('click-overlay');
  93. if (this.closeOnClickOverlay) {
  94. this.$emit('close');
  95. }
  96. },
  97. observeClass() {
  98. const { transition, position } = this;
  99. const updateData = {
  100. name: transition || position
  101. };
  102. if (transition === 'none') {
  103. updateData.duration = 0;
  104. }
  105. this.setData(updateData);
  106. },
  107. onTransitionEnd() {
  108. console.log('占位:函数 onTransitionEnd 未声明');
  109. }
  110. },
  111. watch: {
  112. transition: {
  113. handler: function () {
  114. const { transition, position } = this;
  115. const updateData = {
  116. name: transition || position
  117. };
  118. if (transition === 'none') {
  119. updateData.duration = 0;
  120. }
  121. this.setData(updateData);
  122. },
  123. immediate: true
  124. },
  125. position: {
  126. handler: function () {
  127. const { transition, position } = this;
  128. const updateData = {
  129. name: transition || position
  130. };
  131. if (transition === 'none') {
  132. updateData.duration = 0;
  133. }
  134. this.setData(updateData);
  135. },
  136. immediate: true
  137. }
  138. }
  139. };
  140. </script>
  141. <style>
  142. @import '../common/index.ttss';
  143. .van-popup {
  144. position: fixed;
  145. box-sizing: border-box;
  146. max-height: 100%;
  147. overflow-y: auto;
  148. transition-timing-function: ease;
  149. -webkit-animation: ease both;
  150. animation: ease both;
  151. -webkit-overflow-scrolling: touch;
  152. background-color: #fff;
  153. background-color: var(--popup-background-color, #fff);
  154. }
  155. .van-popup--center {
  156. top: 50%;
  157. left: 50%;
  158. -webkit-transform: translate3d(-50%, -50%, 0);
  159. transform: translate3d(-50%, -50%, 0);
  160. }
  161. .van-popup--center.van-popup--round {
  162. border-radius: 20px;
  163. border-radius: var(--popup-round-border-radius, 20px);
  164. }
  165. .van-popup--top {
  166. top: 0;
  167. left: 0;
  168. width: 100%;
  169. }
  170. .van-popup--top.van-popup--round {
  171. border-radius: 0 0 20px 20px;
  172. border-radius: 0 0 var(--popup-round-border-radius, 20px) var(--popup-round-border-radius, 20px);
  173. }
  174. .van-popup--right {
  175. top: 50%;
  176. right: 0;
  177. -webkit-transform: translate3d(0, -50%, 0);
  178. transform: translate3d(0, -50%, 0);
  179. }
  180. .van-popup--right.van-popup--round {
  181. border-radius: 20px 0 0 20px;
  182. border-radius: var(--popup-round-border-radius, 20px) 0 0 var(--popup-round-border-radius, 20px);
  183. }
  184. .van-popup--bottom {
  185. bottom: 0;
  186. left: 0;
  187. width: 100%;
  188. }
  189. .van-popup--bottom.van-popup--round {
  190. border-radius: 20px 20px 0 0;
  191. border-radius: var(--popup-round-border-radius, 20px) var(--popup-round-border-radius, 20px) 0 0;
  192. }
  193. .van-popup--left {
  194. top: 50%;
  195. left: 0;
  196. -webkit-transform: translate3d(0, -50%, 0);
  197. transform: translate3d(0, -50%, 0);
  198. }
  199. .van-popup--left.van-popup--round {
  200. border-radius: 0 20px 20px 0;
  201. border-radius: 0 var(--popup-round-border-radius, 20px) var(--popup-round-border-radius, 20px) 0;
  202. }
  203. .van-popup--bottom.van-popup--safe {
  204. padding-bottom: env(safe-area-inset-bottom);
  205. }
  206. .van-popup--safeTop {
  207. padding-top: env(safe-area-inset-top);
  208. }
  209. .van-popup__close-icon {
  210. position: absolute;
  211. z-index: 1;
  212. z-index: var(--popup-close-icon-z-index, 1);
  213. color: #969799;
  214. color: var(--popup-close-icon-color, #969799);
  215. font-size: 18px;
  216. font-size: var(--popup-close-icon-size, 18px);
  217. }
  218. .van-popup__close-icon--top-left {
  219. top: 16px;
  220. top: var(--popup-close-icon-margin, 16px);
  221. left: 16px;
  222. left: var(--popup-close-icon-margin, 16px);
  223. }
  224. .van-popup__close-icon--top-right {
  225. top: 16px;
  226. top: var(--popup-close-icon-margin, 16px);
  227. right: 16px;
  228. right: var(--popup-close-icon-margin, 16px);
  229. }
  230. .van-popup__close-icon--bottom-left {
  231. bottom: 16px;
  232. bottom: var(--popup-close-icon-margin, 16px);
  233. left: 16px;
  234. left: var(--popup-close-icon-margin, 16px);
  235. }
  236. .van-popup__close-icon--bottom-right {
  237. right: 16px;
  238. right: var(--popup-close-icon-margin, 16px);
  239. bottom: 16px;
  240. bottom: var(--popup-close-icon-margin, 16px);
  241. }
  242. .van-popup__close-icon:active {
  243. opacity: 0.6;
  244. }
  245. .van-scale-enter-active,
  246. .van-scale-leave-active {
  247. transition-property: opacity, -webkit-transform;
  248. transition-property: opacity, transform;
  249. transition-property: opacity, transform, -webkit-transform;
  250. }
  251. .van-scale-enter,
  252. .van-scale-leave-to {
  253. -webkit-transform: translate3d(-50%, -50%, 0) scale(0.7);
  254. transform: translate3d(-50%, -50%, 0) scale(0.7);
  255. opacity: 0;
  256. }
  257. .van-fade-enter-active,
  258. .van-fade-leave-active {
  259. transition-property: opacity;
  260. }
  261. .van-fade-enter,
  262. .van-fade-leave-to {
  263. opacity: 0;
  264. }
  265. .van-center-enter-active,
  266. .van-center-leave-active {
  267. transition-property: opacity;
  268. }
  269. .van-center-enter,
  270. .van-center-leave-to {
  271. opacity: 0;
  272. }
  273. .van-bottom-enter-active,
  274. .van-bottom-leave-active,
  275. .van-left-enter-active,
  276. .van-left-leave-active,
  277. .van-right-enter-active,
  278. .van-right-leave-active,
  279. .van-top-enter-active,
  280. .van-top-leave-active {
  281. transition-property: -webkit-transform;
  282. transition-property: transform;
  283. transition-property: transform, -webkit-transform;
  284. }
  285. .van-bottom-enter,
  286. .van-bottom-leave-to {
  287. -webkit-transform: translate3d(0, 100%, 0);
  288. transform: translate3d(0, 100%, 0);
  289. }
  290. .van-top-enter,
  291. .van-top-leave-to {
  292. -webkit-transform: translate3d(0, -100%, 0);
  293. transform: translate3d(0, -100%, 0);
  294. }
  295. .van-left-enter,
  296. .van-left-leave-to {
  297. -webkit-transform: translate3d(-100%, -50%, 0);
  298. transform: translate3d(-100%, -50%, 0);
  299. }
  300. .van-right-enter,
  301. .van-right-leave-to {
  302. -webkit-transform: translate3d(100%, -50%, 0);
  303. transform: translate3d(100%, -50%, 0);
  304. }
  305. </style>