Commit c3126569 by hank

控制端部分同步

parent 4746ced7
NODE_ENV='development'
VUE_APP_BASE_API='//123.57.209.57:8091'
\ No newline at end of file
VUE_APP_BASE_API='//172.16.4.63:8090'
\ No newline at end of file
import React from 'react';
import { Router, Route, Switch } from 'dva/router';
import config from './router/connfig'
import { checkState } from './utils/index'
function generateRouter(maps, Routes = []) {
// const Routes = []
(maps.map(item => {
......@@ -24,8 +25,9 @@ function RouterConfig({ history }) {
location.query = JSON.parse(sessionStorage.getItem('query'))
}
}
checkState(history)
})
//console.log(generateRouter(config), 'generateRouter(config)}') // 生成的路由表
return (
<Router history={history}>
......
......@@ -2,9 +2,10 @@ import React from 'react';
import { connect } from 'dva';
import './index.less';
import Layout from '@/components/Layout.js'
// import { send } from '@/services/ctr'
import { send } from '@/services/ctr'
function IntroductionWarning(props) {
send('/首页/预警介绍', [])
return (
<Layout>
<div className="warmingCenter-content animated fadeIn">
......
......@@ -2,7 +2,10 @@ import React from 'react';
import { connect } from 'dva';
import './index.less';
import Layout from '@/components/Layout.js'
import { send } from '@/services/ctr'
function IntroductionWarning(props) {
send('/首页参观场景', [])
return (
<Layout>
<div className="warmingCenter-content animated fadeIn">
......
......@@ -2,7 +2,10 @@ import React from 'react';
import { connect } from 'dva';
import './index.less';
import Layout from '@/components/Layout.js'
import { send } from '@/services/ctr'
function IntroductionWarning(props) {
send('/首页/事件监控', [])
return (
<Layout>
<div className="warmingCenter-content animated fadeIn">
......
......@@ -5,6 +5,7 @@ import Layout from '@/components/Layout.js'
import { send } from '@/services/ctr'
function WarmingCenter(props) {
send('/首页/信息中心', [])
return (
<Layout>
<div className="warmingCenter-content animated fadeIn">
......
......@@ -5,6 +5,7 @@ import Layout from '@/components/Layout.js'
import { send } from '@/services/ctr'
function IntroductionWarning(props) {
send('/首页/动画脚本')
return (
<Layout>
<div className="warmingCenter-content animated fadeIn">
......
......@@ -5,6 +5,7 @@ import Layout from '@/components/Layout.js'
import { send } from '@/services/ctr'
// import Breadcrumb from '@/components/Breadcrumb.js'
function WarmingCenter(props) {
send('/首页/全国', [])
return (
<Layout>
<div className="warmingCenter-content animated fadeIn">
......
import request from '../utils/request';
export function send(path, agr) {
window.sessionStorage.setItem('sendObj', JSON.stringify({path, agr}))
if(window.sessionStorage.getItem('isUse')) {
console.log('取消发送')
return Promise.reject('失败')
}
return request('/api/route', {
body: JSON.stringify({
path,
......@@ -13,3 +18,11 @@ export function send(path, agr) {
method: 'post'
});
}
export function getState() {
return request('/api/getState', {
headers: new Headers({
'Content-Type': 'application/json'
}),
method: 'get'
});
}
import { getState } from '../services/ctr'
import routerConfig from '@/router/connfig'
// var filterRouter = {}
function generateRouter(maps, Routes = []) {
// const Routes = []
(maps.map(item => {
Routes.push(item)
if (item.children && item.children.length) {
// generateRouter(item.children, Routes)
}
return item.children && item.children.length ? generateRouter(item.children, Routes) : (
item)
}))
return Routes
}
function filterRouter(path) {
var routes = generateRouter(routerConfig);
var filterRouter = null
// eslint-disable-next-line array-callback-return
routes.map((item) => {
if (item.meta.vPath === path) {
filterRouter = item
}
return item
})
console.log(filterRouter, 'filterRouter')
return filterRouter
}
export function checkState(history) { // 检查路由状态 与大屏保持同步
window._getState && clearInterval(window._getState)
window._getState = setInterval(() => {
getState().then(res => {
let data = JSON.parse(res.data.data)
let sendObj = window.sessionStorage.getItem('sendObj');
sendObj ? sendObj = JSON.parse(sendObj) : (sendObj = {})
console.log(data, sendObj)
window.sessionStorage.setItem('isUse', 'true')
if (data.route === sendObj.path) {
console.log('路由重复')
window.sessionStorage.setItem('isUse', 'true')
} else {
const result = filterRouter(data.route)
window.sessionStorage.removeItem('isUse')
history.replace(result.path)
}
})
}, 1000)
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ function checkStatus(response) {
const error = new Error(response.statusText);
error.response = response;
// return Promise.reject(error)
throw error;
}
......@@ -26,5 +27,5 @@ export default function request(url, options) {
.then(checkStatus)
.then(parseJSON)
.then(data => ({ data }))
.catch(err => ({ err }));
// .catch(err => ({ err }));
}
{
"ip" : "192.168.1.110",
"route" : "/首页/全国",
"volume" : 50,
"brightness" : 50,
"enableTouch" : true,
"music" : {
"isPlay" : true,
"fileIndex" : 2,
"repeat" : -1,
"volume" : 20
}
{
"ip" : "192.168.1.110",
"route" : "/首页",
"volume" : 50,
"brightness" : 50,
"enableTouch" : true,
"music" : {
"isPlay" : true,
"fileIndex" : 2,
"repeat" : -1,
"volume" : 20
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment