Procházet zdrojové kódy

Merge branch 'master' of http://git.ycjcjy.com/honghe/h5-draw-lots

Baozhangchao před 3 roky
rodič
revize
0ebdcc4894

+ 1
- 1
public/index.html Zobrazit soubor

@@ -6,7 +6,7 @@
6 6
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
7 7
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
8 8
     <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
9
-    <title>华侨城</title>
9
+    <title>抽取幸运签,解锁隐藏福利</title>
10 10
     <style>
11 11
       .page-loading-wrapper {
12 12
         position: absolute;

+ 6
- 1
src/components/FireFlies/fireflies.js Zobrazit soubor

@@ -21,7 +21,12 @@ Animation.prototype.draw = function () {
21 21
   var drawer = this.draw.bind(this);
22 22
 
23 23
   this.redraw();
24
-  window.requestAnimationFrame(drawer);
24
+  
25
+  var reqId = window.requestAnimationFrame(drawer);
26
+  return function () {
27
+    console.log('------cancelAnimationFrame----123')
28
+    cancelAnimationFrame(reqId);
29
+  }
25 30
 }
26 31
 
27 32
 Animation.prototype.redraw = function () {

+ 19
- 2
src/components/FireFlies/index.vue Zobrazit soubor

@@ -7,15 +7,32 @@ import Animation from "./fireflies"
7 7
 
8 8
 export default {
9 9
   name: 'FireFlies',
10
+  data() {
11
+    return {
12
+      animation: undefined,
13
+      deAnimation: undefined,
14
+    }
15
+  },
10 16
   mounted() {
11 17
     this.$nextTick(() => {
12
-      new Animation(this.$el, {
18
+      this.animation = new Animation(this.$el, {
13 19
         count: 20,
14 20
         color: 'rgba(236, 196, 94, 1)',
15 21
         speed: 0.7,
16 22
         radius: 3
17
-      }).draw();
23
+      })
24
+      const cancelDraw = this.animation.draw();
25
+
26
+      this.deAnimation = () => {
27
+        cancelDraw();
28
+        this.animation = undefined;
29
+      }
18 30
     })
31
+  },
32
+  beforeDestroy() {
33
+    if (this.deAnimation) {
34
+      this.deAnimation()
35
+    }
19 36
   }
20 37
 }
21 38
 </script>

+ 107
- 0
src/components/Modal.vue Zobrazit soubor

@@ -0,0 +1,107 @@
1
+<template>
2
+  <div class="modal-wrapper" v-show="show">
3
+    <div class="modal" :style="modalStyle" @click.stop="handleMaskClick">
4
+      <fire-flies v-if="showFireflies"></fire-flies>
5
+      <div class="modal-action back-btn" v-if="showBack" @click.stop="$emit('close')">
6
+        <img src="~@/assets/buttonImg/backImg.png" alt="">
7
+      </div>
8
+      <div class="modal-action share-guide" v-if="showShare">
9
+        <img src="~@/assets/buttonImg/shareText.png" alt="">
10
+      </div>
11
+      <div class="modal-action"><slot name="action"></slot></div>
12
+      <div class="modal-body"><slot></slot></div>
13
+
14
+    </div>
15
+
16
+  </div>
17
+</template>
18
+
19
+<script>
20
+export default {
21
+  name: 'Modal',
22
+  components: {
23
+    FireFlies: () => import('@/components/FireFlies')
24
+  },
25
+  props: {
26
+    show: Boolean,
27
+    mask: {
28
+      type: Boolean,
29
+      default: true,
30
+    },
31
+    maskClickCloseable: {
32
+      type: Boolean,
33
+      default: true,
34
+    },
35
+    showBack: Boolean,
36
+    showFireflies: {
37
+      type: Boolean,
38
+      default: true
39
+    },
40
+    showShare: Boolean
41
+  },
42
+  computed: {
43
+    modalStyle() {
44
+      return {
45
+        background: 'rgba(0, 0, 0, 0.6)'
46
+      }
47
+    }
48
+  },
49
+  methods: {
50
+    handleMaskClick() {
51
+      if (this.maskClickCloseable) {
52
+        this.$emit('close')
53
+      }
54
+    }
55
+  }
56
+}
57
+</script>
58
+
59
+<style lang="less" scoped>
60
+.modal-wrapper {
61
+  position: fixed;
62
+  overflow: hidden;
63
+  top: 0;
64
+  left: 0;
65
+  z-index: 999;
66
+
67
+  .modal {
68
+    position: relative;
69
+    width: 100vw;
70
+    height: 100vh;
71
+    overflow: hidden;
72
+    display: flex;
73
+    justify-content: center;
74
+    align-items: center;
75
+
76
+    .modal-action {
77
+      position: absolute;
78
+      z-index: 50;
79
+    }
80
+
81
+    .back-btn {
82
+      top: 4em;
83
+      left: 1.5em;
84
+      width: 4em;
85
+
86
+      & > img {
87
+        width: 100%;
88
+      }
89
+    }
90
+
91
+    .share-guide {
92
+      top: 0.5em;
93
+      right: 0em;
94
+      width: 3em;
95
+      
96
+      & > img {
97
+        width: 100%;
98
+      }
99
+    }
100
+
101
+    .modal-body {
102
+      position: relative;
103
+      z-index: 20;
104
+    }
105
+  }
106
+}
107
+</style>

+ 3
- 1
src/main.js Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 import Vue from 'vue'
2
+import Modal from '@/components/Modal.vue'
2 3
 import App from './App.vue'
3
-
4 4
 import router from './router/index'//路由
5 5
 
6 6
 import { redirect } from './utils/wx'
@@ -8,6 +8,8 @@ redirect()
8 8
 
9 9
 Vue.config.productionTip = false
10 10
 
11
+Vue.component('modal', Modal)
12
+
11 13
 const app = new Vue({
12 14
   router,
13 15
   render: h => h(App),