gui-popup.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view
  3. v-if="show">
  4. <!-- 居中 -->
  5. <view
  6. class="gui-popup gui-flex gui-column gui-justify-content-center gui-align-items-center"
  7. :class="[out ? 'gui-fade-out' : 'gui-fade-in']"
  8. ref="guipopup"
  9. @tap.stop="closebysd"
  10. @touchmove.stop.prevent="stopfun"
  11. :style="{
  12. backgroundColor:bgColor,
  13. zIndex:zIndex,
  14. top:top+'px',
  15. animationDuration:duration+'ms'
  16. }"
  17. v-if="position == 'center'">
  18. <view
  19. class="gui-popup-content gui-popup-center"
  20. @tap.stop="stopfun"
  21. ref="guiPopupCenter"
  22. :class="[out ? 'gui-scale-out' : 'gui-scale-in']"
  23. :style="{width:width, animationDuration:duration+'ms'}">
  24. <slot></slot>
  25. </view>
  26. </view>
  27. <!-- 顶部 -->
  28. <view
  29. class="gui-popup gui-flex gui-column"
  30. :style="{
  31. backgroundColor:bgColor,
  32. zIndex:zIndex,
  33. top:top+'px',
  34. animationDuration:duration+'ms'
  35. }"
  36. v-if="position == 'top'"
  37. :class="[out ? 'gui-fade-out' : 'gui-fade-in']"
  38. ref="guipopup"
  39. @tap.stop="closebysd"
  40. @touchmove.stop.prevent="stopfun">
  41. <view
  42. class="gui-popup-content gui-popup-top"
  43. @tap.stop="stopfun"
  44. ref="guiPopupTop"
  45. :class="[out ? 'gui-top-out' : 'gui-top-in']"
  46. :style="{animationDuration:duration+'ms'}">
  47. <slot></slot>
  48. </view>
  49. </view>
  50. <!-- 底部 -->
  51. <view
  52. class="gui-popup gui-flex gui-column gui-justify-content-end"
  53. :style="{
  54. backgroundColor:bgColor,
  55. zIndex:zIndex,
  56. top:top+'px',
  57. animationDuration:duration+'ms'
  58. }"
  59. v-if="position == 'bottom'"
  60. :class="[out ? 'gui-fade-out' : 'gui-fade-in']"
  61. ref="guipopup"
  62. @tap.stop="closebysd"
  63. @touchmove.stop.prevent="stopfun">
  64. <view
  65. class="gui-popup-content gui-popup-bottom"
  66. @tap.stop="stopfun"
  67. ref="guiPopupBottom"
  68. :class="['gui-dark-bg-level-3', out ? 'gui-bottom-out' : 'gui-bottom-in']"
  69. :style="{animationDuration:duration+'ms'}">
  70. <slot></slot>
  71. </view>
  72. </view>
  73. <!-- 左侧 -->
  74. <view
  75. class="gui-popup gui-flex gui-column"
  76. v-if="position == 'left'"
  77. :class="[out ? 'gui-fade-out' : 'gui-fade-in']"
  78. ref="guipopup"
  79. @tap.stop="closebysd" @touchmove.stop.prevent="stopfun"
  80. :style="{
  81. backgroundColor:bgColor,
  82. zIndex:zIndex,
  83. top:top+'px',
  84. animationDuration:duration+'ms'
  85. }">
  86. <view
  87. class="gui-popup-content gui-flex1 gui-flex gui-column gui-popup-left"
  88. @tap.stop="stopfun"
  89. ref="guiPopupLeft"
  90. :class="[out ? 'gui-left-out' : 'gui-left-in']"
  91. :style="{width:width, animationDuration:duration+'ms'}">
  92. <slot></slot>
  93. </view>
  94. </view>
  95. <!-- 右侧 -->
  96. <view
  97. class="gui-popup gui-flex gui-column gui-align-items-end"
  98. v-if="position == 'right'"
  99. :class="[out ? 'gui-fade-out' : 'gui-fade-in']"
  100. ref="guipopup"
  101. @tap.stop="closebysd"
  102. @touchmove.stop.prevent="stopfun"
  103. :style="{
  104. backgroundColor:bgColor,
  105. zIndex:zIndex,
  106. top:top+'px',
  107. animationDuration:duration+'ms'
  108. }">
  109. <view
  110. class="gui-popup-content gui-flex1 gui-flex gui-column gui-popup-right"
  111. @tap.stop="stopfun"
  112. ref="guiPopupRight"
  113. :class="[out ? 'gui-right-out' : 'gui-right-in']"
  114. :style="{width:width, animationDuration:duration+'ms'}">
  115. <slot></slot>
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. // #ifdef APP-NVUE
  122. const animation = weex.requireModule('animation');
  123. import graceJS from "@/Grace6/js/grace.js";
  124. // #endif
  125. export default{
  126. name : "gui-popup",
  127. props : {
  128. bgColor : { type : String, default : 'rgba(0, 0, 0, 0.7)'},
  129. position : { type : String, default : 'center'},
  130. width : { type : String, default : '580rpx'},
  131. canCloseByShade : { type : Boolean, default : true },
  132. zIndex : { type : Number, default : 999},
  133. top : { type : Number, default : 0},
  134. duration : { type : Number, default : 280},
  135. isSwitchPage : { type : Boolean, default : false}
  136. },
  137. data(){
  138. return {
  139. show : false,
  140. out : false
  141. }
  142. },
  143. methods:{
  144. open : function(){
  145. this.out = false;
  146. this.show = true;
  147. // #ifdef APP-NVUE
  148. this.weexAnimateIn();
  149. // #endif
  150. this.$emit("open")
  151. },
  152. closebysd : function () {
  153. if(this.canCloseByShade){this.close();}
  154. },
  155. close : function(){
  156. this.out = true;
  157. // #ifdef APP-NVUE
  158. this.weexAnimateOut();
  159. // #endif
  160. setTimeout(()=>{
  161. this.show = false;
  162. this.$emit('close');
  163. },350);
  164. },
  165. stopfun : function(e){e.stopPropagation(); return null;},
  166. // #ifdef APP-NVUE
  167. weexAnimateIn : function(){
  168. graceJS.getRefs('guipopup', this, 0, (guipopupref)=>{
  169. animation.transition(guipopupref, {
  170. styles: { opacity : 1},
  171. duration: this.duration, //ms
  172. timingFunction: 'ease',
  173. delay: 0 //ms
  174. });
  175. });
  176. if(this.position == 'center'){
  177. graceJS.getRefs('guiPopupCenter', this, 0, (guipopupref)=>{
  178. animation.transition(guipopupref, {
  179. styles: { transform:'scale(1)'},
  180. duration: this.duration, //ms
  181. timingFunction: 'ease',
  182. delay: 0 //ms
  183. });
  184. });
  185. }else if(this.position == 'top'){
  186. graceJS.getRefs('guiPopupTop', this, 0, (guipopupref)=>{
  187. animation.transition(guipopupref, {
  188. styles: {transform:'translateY(0px)'},
  189. duration: this.duration, //ms
  190. timingFunction: 'ease',
  191. delay: 0 //ms
  192. });
  193. });
  194. }else if(this.position == 'bottom'){
  195. graceJS.getRefs('guiPopupBottom', this, 0, (guipopupref)=>{
  196. animation.transition(guipopupref, {
  197. styles: {transform:'translateY(0px)'},
  198. duration: this.duration, //ms
  199. timingFunction: 'ease',
  200. delay: 0 //ms
  201. });
  202. });
  203. }else if(this.position == 'left'){
  204. graceJS.getRefs('guiPopupLeft', this, 0, (guipopupref)=>{
  205. animation.transition(guipopupref, {
  206. styles: {transform:'translateX(0px)'},
  207. duration: this.duration, //ms
  208. timingFunction: 'ease',
  209. delay: 0 //ms
  210. });
  211. });
  212. }else{
  213. graceJS.getRefs('guiPopupRight', this, 0, (guipopupref)=>{
  214. animation.transition(guipopupref, {
  215. styles: {transform:'translateX(0px)'},
  216. duration: this.duration, //ms
  217. timingFunction: 'ease',
  218. delay: 0 //ms
  219. });
  220. });
  221. }
  222. },
  223. weexAnimateOut : function(){
  224. graceJS.getRefs('guipopup', this, 0, (guipopupref)=>{
  225. animation.transition(guipopupref, {
  226. styles: { opacity : 0},
  227. duration: this.duration, //ms
  228. timingFunction: 'ease',
  229. delay: 0 //ms
  230. });
  231. });
  232. if(this.position == 'center'){
  233. graceJS.getRefs('guiPopupCenter', this, 0, (guipopupref)=>{
  234. animation.transition(guipopupref, {
  235. styles: { transform:'scale(0.3)' },
  236. duration: this.duration, //ms
  237. timingFunction: 'ease',
  238. delay: 0 //ms
  239. });
  240. });
  241. }else if(this.position == 'top'){
  242. graceJS.getRefs('guiPopupTop', this, 0, (guipopupref)=>{
  243. animation.transition(guipopupref, {
  244. styles: {transform:'translateY(-600px)'},
  245. duration: this.duration, //ms
  246. timingFunction: 'ease',
  247. delay: 0 //ms
  248. });
  249. });
  250. }else if(this.position == 'bottom'){
  251. graceJS.getRefs('guiPopupBottom', this, 0, (guipopupref)=>{
  252. animation.transition(guipopupref, {
  253. styles: {transform:'translateY(600px)'},
  254. duration: this.duration, //ms
  255. timingFunction: 'ease',
  256. delay: 0 //ms
  257. });
  258. });
  259. }else if(this.position == 'left'){
  260. graceJS.getRefs('guiPopupLeft', this, 0, (guipopupref)=>{
  261. animation.transition(guipopupref, {
  262. styles: {transform:'translateX(-500px)'},
  263. duration: this.duration, //ms
  264. timingFunction: 'ease',
  265. delay: 0 //ms
  266. });
  267. });
  268. }else{
  269. graceJS.getRefs('guiPopupRight', this, 0, (guipopupref)=>{
  270. animation.transition(guipopupref, {
  271. styles: {transform:'translateX(600px)'},
  272. duration: this.duration, //ms
  273. timingFunction: 'ease',
  274. delay: 0 //ms
  275. });
  276. });
  277. }
  278. },
  279. // #endif
  280. },
  281. emits : ['close', 'open']
  282. }
  283. </script>
  284. <style scoped>
  285. /* 遮罩层 */
  286. .gui-popup{width:750rpx; position:fixed; z-index:999; left:0; top:0; bottom:0;}
  287. .gui-popup-content{overflow:hidden;}
  288. .gui-fade-out{opacity:0;}
  289. .gui-popup-center{transform:scale(0.3,0.3);}
  290. .gui-popup-top{transform:translateY(-1000px);}
  291. .gui-popup-bottom{transform:translateY(600px);}
  292. .gui-popup-left{transform:translateX(-600px);}
  293. .gui-popup-right{transform:translateX(600px);}
  294. </style>