张延森 3 anni fa
parent
commit
a8b62ac215

+ 96
- 0
src/components/FireFlies/fireflies.js Vedi File

@@ -0,0 +1,96 @@
1
+function Animation(selector, option) {
2
+  this.canvas = this.init(selector);
3
+  this.fireflies = new Array(option.count).fill({}).map(function () {
4
+    return new Firefly(option);
5
+  });
6
+}
7
+
8
+Animation.prototype.init = function (canvas) {
9
+  var resize = function () {
10
+    canvas.width = window.innerWidth;
11
+    canvas.height = window.innerHeight;
12
+  }
13
+
14
+  resize();
15
+  window.addEventListener('resize', resize);
16
+
17
+  return canvas;
18
+}
19
+
20
+Animation.prototype.draw = function () {
21
+  var drawer = this.draw.bind(this);
22
+
23
+  this.redraw();
24
+  window.requestAnimationFrame(drawer);
25
+}
26
+
27
+Animation.prototype.redraw = function () {
28
+  var ctx = this.canvas.getContext('2d');
29
+
30
+  ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
31
+  this.fireflies.forEach(function (firefly) {
32
+    firefly.fly();
33
+    firefly.flicker();
34
+
35
+    ctx.beginPath();
36
+    ctx.arc(firefly.x, firefly.y, firefly.radius, 0, Math.PI * 2);
37
+    ctx.closePath();
38
+    ctx.fillStyle = firefly.color;
39
+    ctx.shadowBlur = firefly.radius * 5;
40
+    ctx.shadowColor = "yellow";
41
+    ctx.fill();
42
+  })
43
+}
44
+
45
+export default Animation;
46
+
47
+function Firefly(option) {
48
+  this.x = random(window.innerWidth, option.radius, true);
49
+  this.y = random(window.innerHeight, option.radius, true);
50
+  this.radius = random(option.radius + 0.5, option.radius - 0.5);
51
+  this.veer = false;
52
+  this.angle = random(360, 0, true);
53
+  this.rate = random(30 / 1000, 6 / 1000);
54
+  this.speed = random(option.speed, option.speed / 8);
55
+  this.opacity = random(1, 0.001);
56
+  this.flare = this.opacity > 0.5;
57
+  this.color = option.color;
58
+}
59
+
60
+Firefly.prototype.fly = function () {
61
+  if (this.angle >= 360 || this.angle <= 0 || Math.random() * 360 < 6) {
62
+    this.veer = !this.veer;
63
+  }
64
+
65
+  // this.speed -= this.veer ? -.01 : .01;
66
+  this.angle -= this.veer ? -this.speed : this.speed;
67
+  this.x += Math.sin((Math.PI / 180) * this.angle) * this.speed;
68
+  this.y += Math.cos((Math.PI / 180) * this.angle) * this.speed;
69
+
70
+  if (this.x < 0) this.x += window.innerWidth;
71
+  if (this.x > window.innerWidth) this.x -= window.innerWidth;
72
+  if (this.y < 0) this.y += window.innerHeight;
73
+  if (this.y > window.innerHeight) this.y -= window.innerHeight;
74
+}
75
+
76
+Firefly.prototype.flicker = function () {
77
+  if (this.opacity >= 1 || this.opacity <= 0.001) {
78
+    this.flare = !this.flare;
79
+  }
80
+
81
+  this.opacity -= this.flare ? -this.rate : this.rate;
82
+  this.color = setOpacity(this.color, this.opacity.toFixed(3));
83
+}
84
+
85
+function random(max, min, isInt) {
86
+  return isInt
87
+    ? Math.floor((Math.random() * (max - min) + min))
88
+    : Number((Math.random() * (max - min) + min).toFixed(3));
89
+}
90
+
91
+function setOpacity(color, opacity) {
92
+  var colors = color.match(/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\S+)\)$/);
93
+
94
+  return "rgba(" + colors[1] + ", " + colors[2] + ", " + colors[3] + ", " + opacity + ")";
95
+}
96
+

+ 33
- 0
src/components/FireFlies/index.vue Vedi File

@@ -0,0 +1,33 @@
1
+<template>
2
+  <canvas class="fireflies"></canvas>
3
+</template>
4
+
5
+<script>
6
+import Animation from "./fireflies"
7
+
8
+export default {
9
+  name: 'FireFlies',
10
+  mounted() {
11
+    this.$nextTick(() => {
12
+      new Animation(this.$el, {
13
+        count: 20,
14
+        color: 'rgba(236, 196, 94, 1)',
15
+        speed: 0.7,
16
+        radius: 3
17
+      }).draw();
18
+    })
19
+  }
20
+}
21
+</script>
22
+
23
+<style lang="less" scoped>
24
+.fireflies {
25
+  width: 100%;
26
+  height: 100%;
27
+  background: transparent;
28
+
29
+  position: absolute;
30
+  top: 0;
31
+  left: 0;
32
+}
33
+</style>

+ 3
- 1
src/components/Popup.vue Vedi File

@@ -21,6 +21,7 @@
21 21
       </div>
22 22
       <transition name="dialog">
23 23
         <div class="dialog-sprite">
24
+          <fire-flies></fire-flies>
24 25
           <div class="dialog-body">
25 26
             <div class="card-wrapper">
26 27
               <div :class="`dialog-popuImag ${classDivAA?'flipped':''}`">
@@ -68,7 +69,8 @@ export default {
68 69
   name: 'Popup',
69 70
   components: {
70 71
     CalendarPoster: () => import('@/components/CalendarPoster.vue'),
71
-    MyWinning: () => import('@/components/MyWinning.vue')
72
+    MyWinning: () => import('@/components/MyWinning.vue'),
73
+    FireFlies: () => import('@/components/FireFlies')
72 74
   },
73 75
   props: {
74 76
     show: {

+ 1
- 1
src/utils/wx.js Vedi File

@@ -33,7 +33,7 @@ export function share (opt) {
33 33
   const defaultLink = origin + pathname
34 34
   const defaultImg = `${origin}${pathname}images/share.jpg`
35 35
 
36
-  const link = opt.link || defaultLink
36
+  const link = window.location.href // opt.link || defaultLink
37 37
   const imgUrl = opt.imgUrl || defaultImg
38 38
 
39 39
   initSDK(link)

+ 1
- 1
vue.config.js Vedi File

@@ -11,7 +11,7 @@ module.exports = {
11 11
   devServer: {
12 12
     proxy: {
13 13
       '/api': {
14
-        target: "http://192.168.89.147:8080/",
14
+        target: "http://192.168.89.147:9000/",
15 15
         // ws: true,
16 16
         changeOrigin: true,
17 17
         // pathRewrite: {