gui-popup.vue 7.6 KB

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