TODO: router

This commit is contained in:
eson 2020-08-31 18:10:38 +08:00
parent 6fd40fa634
commit 065254c672
18 changed files with 447 additions and 493 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ npm-debug.log
#go
debug.test
intimate_server
screenlog.*

14
.vscode/launch.json vendored
View File

@ -4,13 +4,13 @@
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"webRoot": "${workspaceFolder}"
},
// {
// "type": "chrome",
// "request": "attach",
// "name": "Attach to Chrome",
// "port": 9222,
// "webRoot": "${workspaceFolder}"
// },
{
"type": "chrome",
"request": "launch",

View File

@ -178,34 +178,6 @@ func countTagInfo(cxt *gin.Context, ret func(cxt *gin.Context, cw *tagcounter))
cw = icw
}
// rows, err := StoreStreamer.Query(sql)
// if err != nil {
// cxt.Error(err)
// return
// }
// cw = &tagcounter{}
// cw.CountWord = make(map[string]*taginfo)
// cw.Name = platform
// cw.LastTime = time.Now()
// for rows.Next() {
// var stag string
// err = rows.Scan(&stag)
// if err != nil {
// log.Println(err)
// }
// var tag []string
// json.Unmarshal([]byte(stag), &tag)
// for _, t := range tag {
// if _, ok := cw.CountWord[t]; ok {
// cw.CountWord[t].Value++
// } else {
// cw.CountWord[t] = &taginfo{Name: t, Value: 1}
// }
// }
// }
cw.Name = platform
heap := heap.New(func(a, b interface{}) int {
if a.(*taginfo).Value >= b.(*taginfo).Value {

View File

@ -7,6 +7,5 @@ require (
github.com/Pallinder/go-randomdata v1.2.0
github.com/gin-gonic/gin v1.6.3
github.com/go-sql-driver/mysql v1.5.0
github.com/jinzhu/gorm v1.9.16 // indirect
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v2 v2.2.8
)

View File

@ -4,16 +4,14 @@ github.com/Pallinder/go-randomdata v1.1.0 h1:gUubB1IEUliFmzjqjhf+bgkg1o6uoFIkRsP
github.com/Pallinder/go-randomdata v1.1.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y=
github.com/Pallinder/go-randomdata v1.2.0 h1:DZ41wBchNRb/0GfsePLiSwb0PHZmT67XY00lCDlaYPg=
github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
@ -23,54 +21,36 @@ github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -2,9 +2,6 @@ package main
import (
"database/sql"
"fmt"
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
@ -27,42 +24,6 @@ type Result struct {
Data interface{}
}
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method //请求方法
origin := c.Request.Header.Get("Origin") //请求头部
var headerKeys []string // 声明请求头keys
for k, _ := range c.Request.Header {
headerKeys = append(headerKeys, k)
}
headerStr := strings.Join(headerKeys, ", ")
if headerStr != "" {
headerStr = fmt.Sprintf("access-control-allow-origin, access-control-allow-headers, %s", headerStr)
} else {
headerStr = "access-control-allow-origin, access-control-allow-headers"
}
if origin != "" {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Origin", "*") // 这是允许访问所有域
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE") //服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求
// header的类型
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma")
// 允许跨域设置 可以返回其他子段
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") // 跨域关键设置 让浏览器可以解析
c.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒
c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true
c.Set("content-type", "application/json") // 设置返回格式是json
}
//放行所有OPTIONS方法
if method == "OPTIONS" {
c.JSON(http.StatusOK, "Options Request!")
}
// 处理请求
c.Next() // 处理请求
}
}
type ObjectQuery struct {
Uid int64
Platform string

45
goserver/middleware.go Normal file
View File

@ -0,0 +1,45 @@
package main
import (
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method //请求方法
origin := c.Request.Header.Get("Origin") //请求头部
var headerKeys []string // 声明请求头keys
for k := range c.Request.Header {
headerKeys = append(headerKeys, k)
}
headerStr := strings.Join(headerKeys, ", ")
if headerStr != "" {
headerStr = fmt.Sprintf("access-control-allow-origin, access-control-allow-headers, %s", headerStr)
} else {
headerStr = "access-control-allow-origin, access-control-allow-headers"
}
if origin != "" {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Origin", "*") // 这是允许访问所有域
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE") //服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求
// header的类型
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma")
// 允许跨域设置 可以返回其他子段
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") // 跨域关键设置 让浏览器可以解析
c.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒
c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true
c.Set("content-type", "application/json") // 设置返回格式是json
}
//放行所有OPTIONS方法
if method == "OPTIONS" {
c.JSON(http.StatusOK, "Options Request!")
}
// 处理请求
c.Next() // 处理请求
}
}

View File

@ -1,30 +1,34 @@
import Icon, {
import {
MenuFoldOutlined, MenuUnfoldOutlined,
DatabaseOutlined, DatabaseFilled
DatabaseFilled
} from '@ant-design/icons';
import { Row, Col, Divider } from 'antd';
import { Button, Layout, Menu, Tabs } from 'antd';
import 'antd/dist/antd.css';
import {Swtich, Route, Router, HashHistory, Link} from 'react-router-dom';
import React from 'react';
import React, {useRef} from 'react';
import './App.less';
import DataTable from './Table';
import ContentTable from './ContentTable';
import DataTableTest from './TableTest';
import ChartsCount from './ChartsCount';
import TableData from './TableData';
import TabsRoute from './Router';
import { Link, Route, Router, HashRouter, Switch } from 'react-router-dom';
const { TabPane } = Tabs;
const bstyle = { width: "100px" };
const { TabPane } = Tabs;
const { Header, Content, Footer, Sider } = Layout;
class App extends React.Component {
state = {
platform: "openrec",
collapsed: false,
tkey: "content_table",
};
constructor(props) {
super(props)
this.state = {
platform: "openrec",
collapsed: false,
tkey: "content_table",
location: null,
}
}
toggleCollapsed = () => {
this.setState({
@ -33,90 +37,110 @@ class App extends React.Component {
};
changePlatform = (p) => {
this.setState({platform: p});
if (this.refs.tcharts && this.refs.tcharts.state.platform !== p) {
this.refs.tcharts.changePlatform(p)
}
this.refs.ctable.changePlatform(p);
// this.setState({ platform: p });
// if (this.chartscount && this.chartscount.state.platform !== p) {
// this.chartscount.changePlatform(p)
// }
// this.tabledata.changePlatform(p);
}
render() {
return (
<HashRouter>
<Layout>
<Sider
trigger={null}
collapsible
collapsed={this.state.collapsed}
inlineCollapsed={this.state.collapsed}
trigger={null}
collapsible
collapsed={this.state.collapsed}
inlineCollapsed={this.state.collapsed}
>
<Button type="primary" onClick={this.toggleCollapsed} style={{ background: '#6739b6', width: "100%", colorRendering: "optimizeSpeed" }}>
<Button type="primary" onClick={this.toggleCollapsed} style={{ background: '#6739b6', width: "100%", colorRendering: "optimizeSpeed" }}>
{React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined)}
</Button>
</Button>
<Menu theme="dark" mode="inline" defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
defaultOpenKeys={['sub1']}
>
<Menu.Item key="openrec" icon={<DatabaseFilled/>} onClick={(e)=>{ this.changePlatform(e.key); }} >
openrec
</Menu.Item>
<Menu.Item key="twitcasting" icon={<DatabaseFilled/>} onClick={(e)=>{ this.changePlatform(e.key); ; }} >
twitcasting
</Menu.Item>
<Menu.Item key="twitch" icon={<DatabaseFilled/>} onClick={(e)=>{ this.changePlatform(e.key); }} >
twitch
</Menu.Item>
<Menu.Item key="openrec" icon={<DatabaseFilled />} onClick={(e) => { this.changePlatform(e.key); }} >
openrec
</Menu.Item>
<Menu.Item key="twitcasting" icon={<DatabaseFilled />} onClick={(e) => { this.changePlatform(e.key);; }} >
twitcasting
</Menu.Item>
<Menu.Item key="twitch" icon={<DatabaseFilled />} onClick={(e) => { this.changePlatform(e.key); }} >
twitch
</Menu.Item>
</Menu>
</Sider>
<Layout>
<Header style={{ background: '#000', padding:"0" }}>
</Header>
<Content ref="content" style={{ margin: '0 8px' }}>
<Tabs
onChange={(e)=>{
const { platform } = this.state;
this.setState({key: e})
</Sider>
<Layout>
<Header style={{ background: '#000', padding: "0" }}>
switch (e) {
case "content_table":
if (this.refs.ctable) {
this.refs.ctable.changePlatform(platform);
</Header>
<Content ref="content" style={{ margin: '0 8px' }}>
<Switch>
<Tabs
onChange={(e) => {
const { platform } = this.state;
this.setState({ key: e })
switch (e) {
case "content_table":
this.props.history.push("#/data")
if (this.refs.ctable) {
this.refs.ctable.changePlatform(platform);
}
break;
case "tag_count":
this.props.history.push("#/count")
if (this.refs.tcharts) {
this.refs.tcharts.changePlatform(platform);
}
break
default:
break;
}
break;
case "tag_count":
if( this.refs.tcharts ) {
this.refs.tcharts.changePlatform(platform);
}
break
default:
break;
}
}} >
}} >
<TabPane tab="数据表格" key="content_table">
<ContentTable ref="ctable" platform={this.state.platform}></ContentTable>
</TabPane>
<TabPane tab="tag统计" key="tag_count">
<ChartsCount platform={this.state.platform} ref="tcharts"> </ChartsCount>
</TabPane>
</Tabs>
</Content>
<Footer style={{ textAlign: 'center' }}>
Intimate ©2020 Created by eson
</Footer>
</Layout>
</Layout>
);
<TabPane tab="数据表格" key="content_table">
<Route path="/data" render={()=>{
return <TableData platform={this.state.platform} ></TableData>
}} ></Route>
<Route path="/count" render={()=>{
return <ChartsCount platform={this.state.platform} ></ChartsCount>
}} ></Route>
</TabPane>
<TabPane tab="tag统计" key="tag_count">
<Route path="/data" render={()=>{
return <TableData platform={this.state.platform} ></TableData>
}} ></Route>
<Route path="/count" render={()=>{
return <ChartsCount platform={this.state.platform} ></ChartsCount>
}} ></Route>
</TabPane>
</Tabs>
</Switch>
</Content>
<Footer style={{ textAlign: 'center' }}>
Intimate ©2020 Created by eson
</Footer>
</Layout>
</Layout>
</HashRouter>
);
}
}
// ReactDOM.render(<App />, mountNode);
export default App;

View File

@ -82,14 +82,17 @@ function getOption(state = {}) {
}
class ChartsCount extends React.Component {
state = {
option: {},
platform: this.props.platform,
data: {},
countkey: "count",
title: "统计数量关系",
}
constructor(props) {
super(props)
this.state = {
option: {},
platform: this.props.platform,
data: {},
countkey: "count",
title: "与数量关系",
}
}
changePlatform = (p) => {
this.setState({ platform: p }, () => {
@ -141,7 +144,6 @@ class ChartsCount extends React.Component {
option={getOption(this.state)}
style={{ height: '600px', width: '100%' }}
className='react_for_echarts' />
</div>
);
}

View File

@ -1,19 +0,0 @@
import React from 'react';
import DataTable from './Table.js';
class ContentTable extends React.Component {
changePlatform = (p) => {
this.refs.table.updatePlatform(p);
}
render() {
// const {platform} = this.state;
return (<div style={{ padding: 24, background: '#fff', minHeight: 780 }}>
<DataTable ref="table" ></DataTable >
</div>)
}
}
export default ContentTable;

33
src/Router.js Normal file
View File

@ -0,0 +1,33 @@
import React from 'react';
import App from './App';
import { HashRouter, Route, Switch, BrowserRouter, Redirect } from 'react-router-dom';
import TableData from "./TableData";
import ChartsCount from "./ChartsCount";
import { Link } from 'react-router-dom';
import { Button, Layout, Menu, Tabs } from 'antd';
const { TabPane } = Tabs;
const MainRouter = () => {
return (
<BrowserRouter>
<Switch>
{/* <Redirect from="/" to="#/data" ></Redirect> */}
<Route exact path="/" component={
App
} >
</Route>
<Route exact path="/login" component={
ChartsCount
}>
</Route>
</Switch>
</BrowserRouter>
)
};
export default MainRouter;

View File

@ -1,278 +0,0 @@
import React, { useState } from 'react';
import { Table, Input, Select, Tag, Row, Col } from 'antd';
import './Table.less';
import apihost from './Var';
const { Option } = Select;
class DataTable extends React.Component {
state = {
data: [],
platform: "openrec",
pagination: {
current: 1,
pageSize: 20,
position: ["topLeft"],
},
loading: false,
filters: null,
sorter: null,
};
expandedRow = (record) => {
const ecolumns = [
{
title: 'uid',
dataIndex: 'Uid',
key: 'Uid',
dataField:'uid',
},
{
title: '直播地址',
dataIndex: 'LiveUrl',
key: 'LiveUrl',
dataField: 'live_url'
},
{
title: '直播标题',
dataIndex: 'LiveTitle',
key: 'LiveTitle',
dataField:'live_title',
},
{
title: '近直播开始时间',
dataIndex: 'LiveStartTime',
key: 'LiveStartTime',
dataField:'live_start_time',
},
{
title: '近直播结束时间',
dataIndex: 'LiveEndTime',
key: 'LiveEndTime',
dataField:'live_end_time',
},
];
var data = [record];
return <Table rowClassName="subtable" size="small" bordered={true} columns={ecolumns} dataSource={data} pagination={false} />;
};
updatePlatform(p) {
const { pagination, sorter, filters } = this.state;
// console.log("filters", filters); // ${filters?`&filters=${filters}`:""}
// console.log("sorter", sorter);
pagination.current = 1;
this.setState({ platform: p }, () => {
this.fetchapi({
pagination,
sorter,
filters
});
});
}
componentDidMount() {
const { platform } = this.state;
this.updatePlatform(platform);
}
handleTableChange = (pagination, filters, sorter) => {
this.fetchapi({
pagination,
sorter,
filters,
});
};
fetchapi = (params = {}) => {
const { pagination, sorter, filters } = params;
const { platform, } = this.state;
this.setState({ loading: true });
// console.log("filters", filters); // ${filters?`&filters=${filters}`:""}
// console.log("sorter", sorter);
fetch(`${apihost}/${platform}/query?page=${pagination.current}&psize=${pagination.pageSize}${sorter?`&orderfield=${sorter.column?sorter.column.dataField:""}&ordertype=${sorter.order}`:""}`, { mode: "cors" }).then((response) => {
// console.log(response);
response.json().then(
(data) => {
var result = JSON.parse(data)
this.setState({
loading: false,
data: result.Data ? result.Data : [],
pagination: {
...params.pagination,
total: 100000,
},
filters: filters,
sorter: sorter
});
}
)
})
};
render() {
let { data, pagination, loading, sorter, filters } = this.state;
// sorter = sorter || {};
// filters = filters || {};
const columns = [
{
title: '平台',
dataIndex: 'Platform',
editable: false,
key: 'Platform',
// width: "8%",
dataField: 'platform',
},
{
title: 'userid',
dataIndex: 'UserId',
editable: false,
key: 'UserId',
dataField: 'user_id',
// width: "7%",
},
{
title: '名称',
dataIndex: 'UserName',
editable: false,
key: 'UserName',
dataField: 'user_name',
// width: "7%",
},
{
title: '观众数',
dataIndex: 'Views',
editable: false,
key: 'Views',
dataField: 'views',
sorter: (a, b) => a.Views - b.Views,
sortDirections: ['descend', 'ascend'],
ellipsis: false,
// width: "7%",
},
{
title: '标签',
dataIndex: 'Tags',
editable: false,
dataField: 'tags',
render: tags => (
<>
{
tags != null ?
tags.map(tag => {
let color = "purple";
if (tag.length < 3) {
color = 'green';
} else if (tag.length < 6) {
color = 'geekblue';
} else if (tag.length < 9) {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag}
</Tag>
);
}
) : null}
</>)
},
{
title: '粉丝数(关注)',
dataIndex: 'Followers',
key: 'Followers',
width: "8%",
dataField: 'followers',
sorter: (a, b) => a.Followers - b.Followers,
// sortOrder: sorter.columnKey === 'Gratuity' && sorter.order,
sortDirections: ['descend', 'ascend'],
ellipsis: false,
},
{
title: '礼物数(币|钱)',
dataIndex: 'Gratuity',
key: 'Gratuity',
width: "8%",
dataField: 'gratuity',
// defaultSortOrder: 'ascend',
// filterMultiple: false,
// onFilter: (value, record)=>{ console.log(record, value) ;return record.Gratuity >= value;},
sorter: (a, b) => a.Gratuity - b.Gratuity,
// sortOrder: sorter.columnKey === 'Gratuity' && sorter.order,
sortDirections: ['descend', 'ascend'],
ellipsis: false,
},
{
title: '数据更新时间',
dataIndex: 'UpdateTime',
key: 'UpdateTime',
dataField: 'update_time',
// width: "7%",
},
];
return (
<div>
{/* <Row justify="start">
<Col span={6}>
<Input.Group compact size="small">
<Select size="small" defaultValue="operator">
<Option value="operator">operator</Option>
<Option value="uid">uid</Option>
</Select>
<Input size="small" style={{ width: '50%' }} defaultValue="123" />
</Input.Group>
</Col>
<Col span={6}>
<Input.Group compact size="small">
<Select size="small" defaultValue="Zhejiang">
<Option value="Zhejiang">Zhejiang</Option>
<Option value="Jiangsu">Jiangsu</Option>
</Select>
<Input size="small" style={{ width: '50%' }} defaultValue="Xihu District, Hangzhou" />
</Input.Group>
</Col>
</Row> */}
<Table
bordered={true}
size={"middle"}
columns={columns}
dataSource={data}
pagination={pagination}
loading={loading}
onChange={this.handleTableChange}
expandable={{
expandedRowRender: this.expandedRow
}} />
</div>
);
}
};
export default DataTable;
//

233
src/TableData.js Normal file
View File

@ -0,0 +1,233 @@
import React from 'react';
import { Table, Tag } from 'antd';
import './TableData.less';
import apihost from './Var';
class TableData extends React.Component {
constructor(props) {
super(props)
this.state = {
data: [],
platform: "openrec",
pagination: {
current: 1,
pageSize: 20,
position: ["topLeft"],
},
loading: false,
filters: null,
sorter: null,
}
}
expandedRow = (record) => {
const ecolumns = [
{
title: 'uid',
dataIndex: 'Uid',
key: 'Uid',
dataField: 'uid',
},
{
title: '直播地址',
dataIndex: 'LiveUrl',
key: 'LiveUrl',
dataField: 'live_url'
},
{
title: '直播标题',
dataIndex: 'LiveTitle',
key: 'LiveTitle',
dataField: 'live_title',
},
{
title: '近直播开始时间',
dataIndex: 'LiveStartTime',
key: 'LiveStartTime',
dataField: 'live_start_time',
},
{
title: '近直播结束时间',
dataIndex: 'LiveEndTime',
key: 'LiveEndTime',
dataField: 'live_end_time',
},
];
var data = [record];
return <Table rowClassName="subtable" size="small" bordered={true} columns={ecolumns} dataSource={data} pagination={false} />;
};
changePlatform(p) {
const { pagination, sorter, filters } = this.state;
pagination.current = 1;
this.setState({ platform: p }, () => {
this.fetchapi({
pagination,
sorter,
filters
});
});
}
componentDidMount() {
const { platform } = this.state;
this.changePlatform(platform);
}
handleTableChange = (pagination, filters, sorter) => {
this.fetchapi({
pagination,
sorter,
filters,
});
};
fetchapi = (params = {}) => {
const { pagination, sorter, filters } = params;
const { platform, } = this.state;
this.setState({ loading: true });
fetch(`${apihost}/${platform}/query?page=${pagination.current}&psize=${pagination.pageSize}${sorter ? `&orderfield=${sorter.column ? sorter.column.dataField : ""}&ordertype=${sorter.order}` : ""}`, { mode: "cors" }).then((response) => {
response.json().then(
(data) => {
var result = JSON.parse(data)
this.setState({
loading: false,
data: result.Data ? result.Data : [],
pagination: {
...params.pagination,
total: 100000,
},
filters: filters,
sorter: sorter
});
}
)
})
};
render() {
let { data, pagination, loading } = this.state;
const columns = [
{
title: '平台',
dataIndex: 'Platform',
editable: false,
key: 'Platform',
// width: "8%",
dataField: 'platform',
},
{
title: 'userid',
dataIndex: 'UserId',
editable: false,
key: 'UserId',
dataField: 'user_id',
// width: "7%",
},
{
title: '名称',
dataIndex: 'UserName',
editable: false,
key: 'UserName',
dataField: 'user_name',
// width: "7%",
},
{
title: '观众数',
dataIndex: 'Views',
editable: false,
key: 'Views',
dataField: 'views',
sorter: (a, b) => a.Views - b.Views,
sortDirections: ['descend', 'ascend'],
ellipsis: false,
// width: "7%",
},
{
title: '标签',
dataIndex: 'Tags',
editable: false,
dataField: 'tags',
render: tags => (
<>
{
tags != null ?
tags.map(tag => {
let color = "purple";
if (tag.length < 3) {
color = 'green';
} else if (tag.length < 6) {
color = 'geekblue';
} else if (tag.length < 9) {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag}
</Tag>
);
}
) : null}
</>)
},
{
title: '粉丝数(关注)',
dataIndex: 'Followers',
key: 'Followers',
width: "8%",
dataField: 'followers',
sorter: (a, b) => a.Followers - b.Followers,
// sortOrder: sorter.columnKey === 'Gratuity' && sorter.order,
sortDirections: ['descend', 'ascend'],
ellipsis: false,
},
{
title: '礼物数(币|钱)',
dataIndex: 'Gratuity',
key: 'Gratuity',
width: "8%",
dataField: 'gratuity',
// defaultSortOrder: 'ascend',
// filterMultiple: false,
// onFilter: (value, record)=>{ console.log(record, value) ;return record.Gratuity >= value;},
sorter: (a, b) => a.Gratuity - b.Gratuity,
// sortOrder: sorter.columnKey === 'Gratuity' && sorter.order,
sortDirections: ['descend', 'ascend'],
ellipsis: false,
},
{
title: '数据更新时间',
dataIndex: 'UpdateTime',
key: 'UpdateTime',
dataField: 'update_time',
// width: "7%",
},
];
return (
<div style={{ padding: 24, background: '#fff', minHeight: 780 }}>
<Table
bordered={true}
size={"middle"}
columns={columns}
dataSource={data}
pagination={pagination}
loading={loading}
onChange={this.handleTableChange}
expandable={{
expandedRowRender: this.expandedRow
}} />
</div>
);
}
};
export default TableData;
//

View File

@ -1,6 +1,5 @@
import React, { useState } from 'react';
import { Table, Badge, Menu, Dropdown, Space } from 'antd';
import { DownOutlined } from '@ant-design/icons';
import React from 'react';
import { Table } from 'antd';

View File

@ -1,5 +1,5 @@
var apihost = "http://192.168.16.130:5500"
var apihost = "http://localhost:5500"
export default apihost;

View File

@ -2,11 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import MainRouter from './Router';
import * as serviceWorker from './serviceWorker';
import { Route } from 'react-router-dom';
ReactDOM.render(
<React.StrictMode>
<App />
<MainRouter />
</React.StrictMode>,
document.getElementById('root')
);

View File

@ -1,2 +1,2 @@
cd goserver && screen -dmS initmate_web -L ./intimate_server && cd ..
screen -dmS yarn-intimate yarn start
screen -L -dmS yarn-intimate yarn start