subnvue.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="content">
  3. <page-head :title="title"></page-head>
  4. <view class="example">
  5. <view class="example-title">从左侧滑出</view>
  6. <button @click="showDrawer">显示抽屉</button>
  7. </view>
  8. <view class="example">
  9. <view class="example-title">从上侧竖向滑出</view>
  10. <button @click="showPopup">显示 弹出层</button>
  11. </view>
  12. <view style="width: 100%;">
  13. <video v-if="showVideo" id="video"
  14. @play="playVideo"
  15. @pause="closeMask"
  16. :controls="false"
  17. src="https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20181126-lite.m4v"
  18. @error="videoErrorCallback" poster="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/b1476d40-4e5f-11eb-b997-9918a5dda011.png"></video>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. title: 'SubNvue',
  27. showVideo: false
  28. };
  29. },
  30. onLoad() {
  31. this.closeMask();
  32. // 接收 popup 的消息
  33. uni.$on('popup-page', (data) => {
  34. switch(data.type){
  35. case 'interactive':
  36. uni.showModal({
  37. title: '来自Popup的消息',
  38. content: data.info
  39. })
  40. break;
  41. default:
  42. uni.showToast({
  43. title: data.title,
  44. })
  45. break;
  46. }
  47. })
  48. // 监听 drawer 消息
  49. uni.$on('drawer-page', (data) => {
  50. uni.showToast({
  51. title: '点击了第' + data + '项',
  52. icon:"none"
  53. });
  54. })
  55. },
  56. onUnload() {
  57. uni.$off('popup-page')
  58. uni.$off('drawer-page')
  59. },
  60. onReady() {
  61. this.showVideo = true
  62. },
  63. methods: {
  64. showDrawer() {
  65. uni.getSubNVueById('drawer').show('slide-in-left', 200);
  66. },
  67. showPopup() {
  68. // 向 popup 传递消息
  69. uni.$emit('page-popup', {
  70. title: '请阅读软件内容',
  71. content: 'uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS、Android、H5、小程序等多个平台。'
  72. });
  73. const subNVue = uni.getSubNVueById('popup')
  74. subNVue.show('slide-in-top', 250)
  75. },
  76. videoErrorCallback: function() {
  77. uni.showModal({
  78. content: '视频加载失败',
  79. showCancel: false
  80. })
  81. },
  82. playVideo() {
  83. let subNVue = uni.getSubNVueById('video_mask')
  84. subNVue.show('fade-in', 200, () => {
  85. uni.$emit('play-video', {
  86. status: 'open',
  87. })
  88. })
  89. },
  90. closeMask() {
  91. let subNVue = uni.getSubNVueById('video_mask')
  92. uni.$emit('close-video', {
  93. status: 'close',
  94. })
  95. subNVue.hide('fade-out', 200)
  96. },
  97. }
  98. }
  99. </script>
  100. <style>
  101. .content {
  102. align-content: center;
  103. height: 100%;
  104. background-color: #F4F5F6;
  105. }
  106. .example {
  107. padding: 0 10px 10px
  108. }
  109. .example-title {
  110. font-size: 14px;
  111. line-height: 14px;
  112. color: #777;
  113. margin: 40px 2rpx;
  114. position: relative
  115. }
  116. video {
  117. position: absolute;
  118. bottom: 30px;
  119. left: 0;
  120. width: 100%;
  121. height: 200px;
  122. }
  123. .example .example-title {
  124. margin: 40rpx 0
  125. }
  126. button {
  127. background-color: #f8f8f8;
  128. }
  129. .title {
  130. font-size: 20px;
  131. text-align: center;
  132. color: #8f8f94;
  133. }
  134. </style>