胡家华 5 gadi atpakaļ
vecāks
revīzija
3058951b38
9 mainītis faili ar 130 papildinājumiem un 907 dzēšanām
  1. 0 1
      .babelrc
  2. 0 13
      config-overrides.js
  3. 3 0
      home.tmpl
  4. 6 5
      package.json
  5. 0 1
      src/App.css
  6. 0 1
      src/index.css
  7. 18 8
      src/views/Home/index.less
  8. 56 27
      src/views/Home/index.jsx
  9. 47 851
      yarn.lock

+ 0 - 1
.babelrc

@@ -1,6 +1,5 @@
1 1
 {
2 2
     "plugins": [
3
-        ["import", { "libraryName": "antd", "libraryDirectory": "lib"}, "ant"],
4 3
         "dva-hmr"
5 4
       ]
6 5
 }

+ 0 - 13
config-overrides.js

@@ -1,13 +0,0 @@
1
-// import { override, fixBabelImports }  from 'customize-cra'
2
-const { override, fixBabelImports, addLessLoader } = require('customize-cra');
3
- module.exports = override(
4
-    fixBabelImports('import', {
5
-        libraryName: 'antd',
6
-        libraryDirectory: 'es',
7
-        style: true
8
-    }),
9
-    addLessLoader({
10
-        javascriptEnabled: true,
11
-        modifyVars: { '@primary-color': '#1DA57A' },
12
-    })
13
-);

+ 3 - 0
home.tmpl

@@ -0,0 +1,3 @@
1
+{{template "base/head" .}}
2
+<iframe src='./build/index.html' style="position:absolute;top:0;left:0;width:100%;height:100%;" />
3
+{{template "base/footer" .}}

+ 6 - 5
package.json

@@ -3,14 +3,14 @@
3 3
   "version": "0.1.0",
4 4
   "private": true,
5 5
   "dependencies": {
6
-    "antd": "^3.20.2",
6
+    "add": "^2.0.6",
7
+    "axios": "^0.19.0",
7 8
     "babel-plugin-dva-hmr": "^0.4.2",
8 9
     "babel-plugin-import": "^1.12.0",
9 10
     "customize-cra": "^0.2.14",
10 11
     "dva": "^2.4.1",
11 12
     "less": "^3.9.0",
12 13
     "less-loader": "^5.0.0",
13
-    "mall_utils_pro": "^1.0.6",
14 14
     "mobx": "^5.11.0",
15 15
     "node-ssh": "^6.0.0",
16 16
     "opn": "^6.0.0",
@@ -24,10 +24,11 @@
24 24
     "redux": "^4.0.4",
25 25
     "redux-logger": "^3.0.6",
26 26
     "redux-persist": "^5.10.0",
27
-    "redux-thunk": "^2.3.0"
27
+    "redux-thunk": "^2.3.0",
28
+    "yarn": "^1.17.3"
28 29
   },
29 30
   "scripts": {
30
-    "start": "react-app-rewired start",
31
+    "start": "set PORT=9000 HOST=192.168.2.217 && react-app-rewired start",
31 32
     "build": "react-app-rewired build",
32 33
     "test": "node ./server/",
33 34
     "build_theme": "node ./scripts/build-theme.js",
@@ -49,5 +50,5 @@
49 50
       "last 1 safari version"
50 51
     ]
51 52
   },
52
-  "devDependencies": {}
53
+  "proxy": "http://hujiahua.site:8004"
53 54
 }

+ 0 - 1
src/App.css

@@ -1 +0,0 @@
1
-@import '~antd/dist/antd.css';

+ 0 - 1
src/index.css

@@ -1 +0,0 @@
1
-@import '~antd/dist/antd.css';

+ 18 - 8
src/views/Home/index.less

@@ -2,11 +2,12 @@
2 2
     margin: 0;
3 3
     padding: 0;
4 4
 }
5
+body{
6
+    overflow: hidden;
7
+}
5 8
 .wrap{
6 9
     position: relative;
7
-    height: 100%;
8 10
     width: 100%;
9
-    overflow: hidden;
10 11
 }
11 12
 .input{
12 13
     position: absolute;
@@ -16,16 +17,25 @@
16 17
 }
17 18
 .video{
18 19
     position: absolute;
19
-    top: 40px;
20
+    top: 0;
20 21
     left: 0;
21
-    z-index: -1;
22
-    background-color: peru;
22
+    opacity: 0;
23 23
 }
24 24
 .canvas{
25
-    background-color: #f1f1f1;
25
+    background-color: transparent;
26
+    z-index: 1;
27
+
28
+}
29
+.loading{
26 30
     position: absolute;
27 31
     top: 0;
28 32
     left: 0;
29
-    bottom:0;
30
-    right: 0;
33
+    height: 100%;
34
+    width: 100%;
35
+    background-color: white;
36
+    text-align: center;
37
+    font-size: 24;
38
+    color: '#222';
39
+    z-index: 2;
40
+    padding-top: 200px;
31 41
 }

+ 56 - 27
src/views/Home/index.jsx

@@ -1,14 +1,20 @@
1 1
 import React, { Component } from 'react';
2 2
 import { connect } from 'dva'
3
-import { Row, Col } from 'antd';
4
-import './index.less'
3
+import './index.css'
4
+const NODE_ENV = process.env.NODE_ENV;
5
+const videoUrl = NODE_ENV === 'development' ? '/api/video' : 'http://hujiahua.site:8004/api/video'
5 6
 class Home extends Component {
6
-  state = {
7
-    videoSrc: ''
8
-  }
9 7
   canvasVideoRef;
10 8
   videoRef;
11
-  
9
+  state = {
10
+    showLoading: true
11
+  }
12
+  componentDidMount () {
13
+    this.videoRef.addEventListener('canplay',() => {
14
+      console.log('canplay')
15
+      this.play()
16
+    })
17
+  }
12 18
   changeState = (key, value, callback = () => {}) => {
13 19
     this.setState({
14 20
       [key]: value
@@ -29,6 +35,12 @@ class Home extends Component {
29 35
     }
30 36
   }
31 37
   getVideoSizeAndDrawPosi = () => {
38
+    if(!this.videoRef)return {
39
+      videoWid: 0,
40
+      videoHei: 0,
41
+      drawY: 0,
42
+      drawX: 0
43
+    }
32 44
     const { winHeight, winWidth } = this.getWindowSize()
33 45
     let offsetWid = this.videoRef.offsetWidth;
34 46
     let offsetHei = this.videoRef.offsetHeight;
@@ -45,6 +57,7 @@ class Home extends Component {
45 57
     }
46 58
   }
47 59
   drawVideo = (target, targetWid = 300, targetHei = 300, drawX, drawY) => {
60
+    if (!targetWid || !targetHei) return
48 61
     let cxt = this.canvasVideoRef.getContext('2d');
49 62
     cxt.drawImage(target, 0, 0, targetWid, targetHei)
50 63
     const { data } = cxt.getImageData(0, 0, targetWid, targetHei);
@@ -59,6 +72,7 @@ class Home extends Component {
59 72
         const b = data[index + 2];
60 73
         const gray = .299 * r + .587 * g + .114 * b;
61 74
         cxt.fillText(this.img2Text(gray), _w, _h + 8);
75
+        cxt.fillStyle = `rgba(${r},${g},${b})`
62 76
       }
63 77
     }
64 78
   }
@@ -67,31 +81,46 @@ class Home extends Component {
67 81
     const i = g % 16 === 0 ? parseInt(g / 16) - 1 : parseInt(g / 16);
68 82
       return ['#', '&', '@', '%', '$', 'w', '*', '+', 'o', '?', '!', ';', '^', ',', '.', ' '][i];
69 83
   }
70
-  onChangeInput = (e) => {
71
-    let file = e.target.files[0];
72
-    if (file) {
73
-      // this.setState({ videoSrc: 'http://hujiahua.site:9999/test/testVideo.mp4' }, () => {
74
-        this.setState({ videoSrc: URL.createObjectURL(file) }, () => {
75
-        this.videoRef.addEventListener('play',() => {
76
-        let { videoWid, videoHei, drawX, drawY } = this.getVideoSizeAndDrawPosi()
77
-          let play = () => {
78
-            this.drawVideo(this.videoRef, videoWid, videoHei, drawX, drawY)
79
-            requestAnimationFrame(play);
80
-          };
81
-          play();
82
-        }, false)
84
+  play = () => {
85
+    this.videoRef.addEventListener('play',() => {
86
+      this.setState({ showLoading: false }, () => {
87
+        let play = () => {
88
+          let { videoWid, videoHei, drawX, drawY } = this.getVideoSizeAndDrawPosi()
89
+          console.log('this.getVideoSizeAndDrawPosi()',this.getVideoSizeAndDrawPosi())
90
+          this.drawVideo(this.videoRef, videoWid, videoHei, drawX, drawY)
91
+          requestAnimationFrame(play);
92
+        };
93
+        play();
83 94
       })
84
-    }
95
+    }, false)
85 96
   }
86 97
   render () {
87
-    const { videoSrc } = this.state
88
-    const { winHeight,  winWidth} = this.getWindowSize()
98
+    const { winHeight,  winWidth} = this.getWindowSize();
99
+    const { showLoading } = this.state
100
+    let { videoWid, videoHei, drawX, drawY } = this.getVideoSizeAndDrawPosi()
89 101
     return (
90
-      <div className='wrap'>
91
-        <input type="file" id="inputFile" accept=".mp4" onChange={this.onChangeInput}  className='input' />
92
-        <canvas ref={(ref) => { this.canvasVideoRef = ref }} id="canvasShow" width={winWidth} height={winHeight} className='canvas'/>
93
-        <video id="video" ref={(ref) => { this.videoRef = ref }} autoPlay src={videoSrc} className='video' loop></video>
94
-      </div>
102
+      <React.Fragment>
103
+        <div className='wrap'>
104
+          <canvas ref={(ref) => { this.canvasVideoRef = ref }} id="canvasShow" width={winWidth} height={winHeight} className='canvas'/>
105
+          <video 
106
+          id="video" 
107
+          crossOrigin="*" 
108
+          ref={(ref) => { this.videoRef = ref }} 
109
+          autoPlay src={videoUrl} 
110
+          className='video' 
111
+          width={videoWid && videoWid > winWidth ? winWidth: '100%'} 
112
+          height={videoHei && videoHei > winHeight ? winHeight : '100%'} 
113
+          loop/>
114
+        </div>
115
+        {
116
+          showLoading && (
117
+            <div className='loading'>
118
+              加载中,请稍候...
119
+            </div>
120
+          )
121
+        }
122
+      </React.Fragment>
123
+      
95 124
     )
96 125
   }
97 126
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 47 - 851
yarn.lock