gui-popup.vue 8.2 KB

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