Merge branch 'TangShanKaiPing' of http://49.4.92.112:3000/root/ZHXY into TangShanKaiPing

Former-commit-id: 85168e5649922297a16960ebe47f06302f7fcf6d
Former-commit-id: fc687ecb57e4c2e2f4c542f95376c52f8d21bb77
TangShanKaiPing
wanggang 5 years ago
commit 653e821de5

@ -15,7 +15,7 @@ body{
height:100%;
}
.Center-Container {
background-color: #07c160;
background-color: #35A9FE;
position: relative;
}
@ -35,6 +35,22 @@ body{
<img src="loading.svg?v=202004211141" class="Absolute-Center" />
</body>
<script>
/**
* [通过参数名获取url中的参数值]
* 示例URL:http://iot.edusoa.com/IoTCenter/index.html?organname=测试学校
* @param {[string]} queryName [参数名]
* @return {[string]} [参数值]
*/
function GetQueryValue(queryName) {
var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if ( r != null ){
return decodeURIComponent(r[2]);
}else{
return null;
}
}
/*
* username 账号
* realname 姓名
@ -47,27 +63,33 @@ body{
var baseUrl= "http://221.194.113.154:8100/IoTCenter/api/v1/Project/Update";
var timestamp = parseInt(new Date().getTime() / 1000); // 秒级时间戳
var query = "username=cuishuying&realname="+encodeURIComponent('崔淑英')+"&organname="+encodeURIComponent('唐山市税东中学')+"&organnumber=1234567&timestamp=" +timestamp+ "&role=" + encodeURIComponent('市级管理员,区管理员');
// var query = "username=cuishuying&realname="+encodeURIComponent('崔淑英')+"&organname="+encodeURIComponent('唐山市税东中学')+"&organnumber=1234567&timestamp=" +timestamp+ "&role=" + encodeURIComponent('市级管理员,区管理员');
var query = "username=" +GetQueryValue('username')+ "&realname="+encodeURIComponent(GetQueryValue('realname'))+"&organname="+encodeURIComponent(GetQueryValue('organname'))+"&organnumber=" +GetQueryValue('organnumber')+ "&timestamp=" +GetQueryValue('timestamp')+ "&role=" + encodeURIComponent(GetQueryValue('role'));
// console.log(GetQueryValue('role'));
/*
* 算法 MD5盐值 salt=123456
* https://cdn.bootcdn.net/ajax/libs/blueimp-md5/2.16.0/js/md5.js
*/
var salt = "123456";
var token = md5(query + ',' + salt); // 加盐方式
var token = GetQueryValue('token');
var url = baseUrl + "?" + query + "&token=" + token;
console.log(url);
// alert(url);
var api_url = "http://221.194.113.154:8100/IoTCenter/api/v1/Project/Update" + "?" + query + "&token=" + token;
axios.get(api_url).then(function (response) {
console.log(response);
localStorage.setItem('accessToken', response.data.accessToken);
localStorage.setItem('refreshToken', response.data.refreshToken);
var secScript = document.createElement("script");
secScript.setAttribute("type", "text/javascript");
secScript.setAttribute("src", 'redirect.js?v=' + new Date().toLocaleTimeString());
document.body.insertBefore(secScript, document.body.lastChild);
console.log(response);
if(response.data.accessToken){
localStorage.setItem('accessToken', response.data.accessToken);
localStorage.setItem('refreshToken', response.data.refreshToken);
var secScript = document.createElement("script");
secScript.setAttribute("type", "text/javascript");
secScript.setAttribute("src", 'redirect.js?v=' + new Date().toLocaleTimeString());
document.body.insertBefore(secScript, document.body.lastChild);
}else{
window.location.href="/400.html?v=3"
}
});
</script>

@ -1,29 +1,12 @@
/**
* [通过参数名获取url中的参数值]
* 示例URL:http://iot.edusoa.com/IoTCenter/index.html?organ=测试学校
* @param {[string]} queryName [参数名]
* @return {[string]} [参数值]
*/
function GetQueryValue(queryName) {
var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if ( r != null ){
return decodeURI(r[2]);
}else{
return null;
}
}
var url = '';
var school = GetQueryValue('organ').replace(/\'/g, '');
var school = (GetQueryValue('organname') || '').replace(/\'/g, '');
switch(school) {
case '东师理想':
url = 'http://iot.edusoa.com'
break;
case '唐山市税东中学':
url = 'http://tsssdzx.iot.edusoa.com'
url = 'http://221.194.113.154:8100'
break;
default:
url = 'http://iot.edusoa.com'
url = 'http://221.194.113.154:8100'
}
window.location.href = url;

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<body>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="lib/weui/weui.min.css">
<link rel="stylesheet" href="css/weui.ext.css">
<link rel="stylesheet" href="css/app.css">
</head>
<div class="page js_show">
<div style="background-color: #fff; height: 100%; min-height: 480px;">
<div class="weui-header" v-if="typeof api !== 'undefined'">
<div class="weui-header-left"> <a class="icon icon-109" style="color:#fff" href="javascript:" onclick="closeWindow()">关闭</a> </div>
<h1 class="weui-header-title"></h1>
<div class="weui-header-right"></div>
</div>
<div style="margin-top:46px;padding:40px;text-align:center">
<img src="400.svg" style="display:inline-block;max-width:80%">
<p class="weui-footer__text" style="padding:20px;color:#ccc;text-align:center">暂未开通相关服务</p>
</div>
</div>
</div>
</body>
<script>
// 人人通原生返回键回调
var closeWindow = function (){
if(window.api){
window.api.execScript(
{
name: window.api.winName,
script: "api.closeWin()"
}
)
}
}
</script>
</html>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 17 KiB

@ -24,9 +24,9 @@
</div>
</div>
<script>
var version = '0.1.0.202005260900'; // 版本信息全局变量
var version = '0.1.0.202006221700'; // 版本信息全局变量
</script>
<script src="js/config.js?v=0.1.0.202005181416"></script>
<script src="js/config.js?v=0.1.0.202006221700"></script>
<script src="lib/linq/linq.min.js"></script>
<script src="lib/jquery/jquery.min.js"></script>
<script src="lib/jquery-serializejson/jquery.serializejson.min.js"></script>
@ -39,10 +39,10 @@
<script src="lib/Chart.js/Chart.bundle.min.js"></script>
<script src="lib/flv.js/flv.min.js"></script>
<script src="lib/WXInlinePlayer/index.js"></script>
<script src="js/util.js?v=0.1.0.202005181416"></script>
<script src="js/store.js?v=0.1.0.202005181416"></script>
<script src="js/message.js?v=0.1.0.202005181416"></script>
<script src="js/iot.js?v=0.1.0.202005181416"></script>
<script src="js/app.js?v=0.1.0.202005181416"></script>
<script src="js/util.js?v=0.1.0.202006221700"></script>
<script src="js/store.js?v=0.1.0.202006221700"></script>
<script src="js/message.js?v=0.1.0.202006221700"></script>
<script src="js/iot.js?v=0.1.0.202006221700"></script>
<script src="js/app.js?v=0.1.0.202006221700"></script>
</body>
</html>

@ -3,7 +3,9 @@ var isApp = userAgent.indexOf('isapp') !== -1;
var localStoreMsg = false; // 是否本地存储消息
/* API 网关 */
var apigateway = config.apigateway;
/* 从存储载入消息 */
console.log('config:');
console.log(apigateway);
var isLoadedMSG = false;
/**
@ -19,6 +21,7 @@ axios.interceptors.request.use(
config.headers['x-requested-with'] = 'XMLHttpRequest';
config.headers['Authorization'] = 'Bearer ' + store.state.accessToken;
config.headers['X-APP-VERSION'] = '2.0.0';
console.log('url:' + config.url + 'auth token:' + config.headers['Authorization']);
}
// 绝对路径替换为网关+路径 (防止多次请求重复拼接URL)
config.url = config.url.indexOf('/') == 0 ? apigateway + config.url : config.url;
@ -29,6 +32,8 @@ axios.interceptors.request.use(
return config;
},
function (error) {
console.log('axios.interceptors.request.error:');
console.log(error);
$('#loading').fadeOut(100);
return Promise.reject(error);
}
@ -39,6 +44,8 @@ axios.interceptors.request.use(
* 前端网络请求异常统一处理
*/
axios.interceptors.response.use(function (response) {
console.log('axios.interceptors.response:');
console.log(response);
$('#loading').fadeOut(100);
//根据config内容动态设置url
@ -81,7 +88,7 @@ axios.interceptors.response.use(function (response) {
error.config.headers['Authorization'] = 'Bearer ' + store.state.accessToken;
console.log('刷新token后重发api请求');
/* 重新发送原请求 */
delete error.config.headers.Authorization // 移除旧的AccessToken信息避免拦截器无法设置新AccessToken
delete error.config.headers.Authorization //移除旧的AccessToken信息避免拦截器无法设置新AccessToken
axios.request(error.config);
})
.catch(function (error) { // 如果为RefreshToken失败则跳转登录页面
@ -104,7 +111,11 @@ const router = new VueRouter({
});
router.beforeEach((to, from, next) => {
$('#loading').show();
console.log('before...')
console.log('store.state.accessToken', store.state.accessToken)
console.log('to.path', to.path)
if (!store.state.accessToken && to.path !== '/pages/login') {
console.log('router.push')
router.push('/pages/login');
return;
}
@ -117,10 +128,14 @@ router.beforeEach((to, from, next) => {
route = routeList[i];
}
}
console.log('route', route)
if (!route) {
console.log('<<<!route to.path>>>', to.path)
var path = to.path === '/' ? '/pages/home' : to.path;
var url = path + '.js';
var method = path.replace(/\//g, '_').substr(1) + "()";
console.log('preRoute:from ' + from.path + ' to path ' + to.path);
$.getScript(url, function () {
var response = eval(method);
var route = {
@ -134,6 +149,8 @@ router.beforeEach((to, from, next) => {
});
}
else {
console.log('!route else', route)
console.log('route from:' + from.path + ' to:' + to.path);
next();
}
});
@ -168,6 +185,7 @@ if(indexedDB){
console.log('不支持');
}
console.log(indexedDB);
var db = null;
var request = indexedDB.open('app', 1);
request.onupgradeneeded = function(e) {
@ -183,22 +201,29 @@ request.onsuccess = function() {
/**
* 初始化消息列表
*/
console.log('loading message');
//loadMessage();
}
function saveMessage(msg){
if(db){
console.log("数据库打开");
console.log(db);
var transaction = db.transaction('message','readwrite');
var objectStore = transaction.objectStore('message');
console.log("数据:");
console.log(msg);
console.log("类型:");
var jsonMsg = JSON.parse(msg);
console.log(typeof JSON.parse(msg));
// 校验数据格式(当前只存储带key的消息后续会有调整)
if( jsonMsg.key ){
console.log('IS MSG');
// 本地存储
if(localStoreMsg){
objectStore.add({data: jsonMsg});
}
// objectStore.delete(store.state.messages[0]._id);
store.commit('setMessages', [{data: jsonMsg}]);
}
}else{
@ -206,32 +231,50 @@ function saveMessage(msg){
}
}
function loadMessage(callback, limit = 99){
function loadMessage(callback, limit = 10){
if(db){
console.log("数据库打开");
console.log(db);
var transaction = db.transaction('message','readwrite');
var objectStore = transaction.objectStore('message');
console.log('objectStore:')
console.log(objectStore);
var req = objectStore.openCursor();
console.log('req:')
console.log(req);
var items = [];
// 回调会被多次调用
req.onsuccess = function (evt) {
var cursor = evt.target.result;
console.log('cursor:')
console.log(cursor);
if(cursor){ // 必要检查
var item = cursor.value;
//console.log(item);
if(item.data.device){
items.push(item);
console.log('append item !!!');
//console.log(items);
console.log('####### item #######');
console.log('displayName: ' + item.data.device.displayName);
console.log('Name: ' + item.data.name);
console.log('Value: ' + item.data.value);
}
cursor.continue(); // 移动到下一项
}else{
// 回调函数
console.log('call back!!!');
callback(items);
// 加载后删除数据库,只缓存上次应用开启数据
//indexedDB.deleteDatabase('app');
objectStore.clear();
//alert(items.length -100)
}
};
console.log(limit);
var req = objectStore.get(limit);
req.onerror = function(event) {
console.log('事务失败');
@ -249,6 +292,7 @@ const app = new Vue({
data: {
},
mounted: function () {
console.log('mounted:app');
// 判断是否登录
if(localStorage.getItem('accessToken') === null){
//
@ -256,9 +300,8 @@ const app = new Vue({
}
},
destroyed: function(){
//Todo
alert('des');
},
methods: {
//Todo
},
}).$mount('#app');

@ -5,3 +5,4 @@ var config = (function(global){
global.liverUrl = global.apigateway; // 流媒体服务器地址
return global;
})(window.config||{});
console.log('config init');

@ -38,16 +38,17 @@ function getData(device, name) {
}
//devices
function parseModel(response) {
console.log('parseModel');
var html = new DOMParser().parseFromString(response.data, 'text/html');
console.log(html);
var template = html.getElementsByTagName('template')[0].innerHTML;
console.log(template);
var script = html.getElementsByTagName('script')[0].innerHTML;
console.log(script);
var model = eval(script);
model.template = template;
console.log('model:::::');
console.log(model);
return model;
}
Vue.component('iot-gateway', function (resolve, reject) {
@ -77,6 +78,7 @@ Vue.component('iot-person', function (resolve, reject) {
});
Vue.component('iot-curtain', function (resolve, reject) {
axios.get("/pages/iot/device/curtain.html").then(function (response) {
console.log(response);
resolve(parseModel(response));
});
});

@ -34,9 +34,25 @@ connection.on("ServerToClient", function (method, message, to, from) {
var model = JSON.parse(message);
router.currentRoute.meta.onMessage(event, model, to, from);
console.log('receive:');
console.log(method); // 调用方法
console.log(message); // 消息内容
// 本地存储消息
saveMessage(message);
console.log('old messages:');
console.log('===');
console.log(store.state.messages);
console.log('save message');
console.log('===event===');
console.log(event);
console.log('-------------');
//store.commit('setMessages', []);
console.log('-------------');
/**
* 调用定义的update事件处理
* 设备移除
@ -48,6 +64,15 @@ connection.on("ServerToClient", function (method, message, to, from) {
* from: null
*/
console.log('message.js event:');
console.log(event);
console.log('message.js model:');
console.log(model);
console.log('message.js to:');
console.log(to);
console.log('message.js from:');
console.log(from);
/**
* 事件过滤处理绑定到对应异步操作
* 除设备操作事件外Event > Mutations > State其他事件只做Action触发不直接刷新数据

@ -22,6 +22,7 @@ function update(list, item, key) {
list.push(item);
result = true;
}
console.log(result?'insert':'update'+' data by '+key);
return result;
}
//delete

@ -131,8 +131,8 @@
</div>
<div class="col-5 align-self-center">
<div class="row" style="line-height:28px; text-align: right;">
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 10px;" v-if="getDeviceDataValue(device,'状态')=='开'" v-on:click="execApi(device.number,'/Switch/Off')" src="/images/on.svg" />
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 10px;" v-if="getDeviceDataValue(device,'状态')=='关'" v-on:click="execApi(device.number,'/Switch/On')" src="/images/off.svg" />
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 0px;" v-if="getDeviceDataValue(device,'状态')=='开'" v-on:click="execApi(device.number,'/Switch/Off')" src="/images/on.svg" />
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 0px;" v-if="getDeviceDataValue(device,'状态')=='关'" v-on:click="execApi(device.number,'/Switch/On')" src="/images/off.svg" />
</div>
</div>
</div>
@ -166,8 +166,8 @@
</div>
<div class="col-5 align-self-center">
<div class="row" style="line-height:28px;">
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 10px;" v-if="getDeviceDataValue(device,'状态')==='开'" v-on:click="execApi(device.number,'/Socket/Off')" :src="config.apigateway+'/IoTCenter/images/on.png'" />
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 10px;" v-else="getDeviceDataValue(device,'状态')==='关'" v-on:click="execApi(device.number,'/Socket/On')" :src="config.apigateway+'/IoTCenter/images/off.png'" />
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 0px;" v-if="getDeviceDataValue(device,'状态')==='开'" v-on:click="execApi(device.number,'/Socket/Off')" :src="config.apigateway+'/IoTCenter/images/on.png'" />
<img style="height:32px;width:32px;padding:5px;border:solid #cccccc 1px;border-radius:50%;margin-left: 0px;" v-else="getDeviceDataValue(device,'状态')==='关'" v-on:click="execApi(device.number,'/Socket/On')" :src="config.apigateway+'/IoTCenter/images/off.png'" />
</div>
</div>
</div>

@ -7,13 +7,17 @@
</div>
<div class="main">
<div class="row" v-if="product">
<router-link v-for="device in product.devices" :to="{path:'/pages/iot/device',query:{number:device.number}}" class="col-lg-3 col-md-4 col-sm-6 p-3">
<div class="weui-grid__icon">
<img v-if="product.name === '一路开关' && device.data[0].value === '关'" :src="product.image.replace('.png', '.svg')" class="grayscale" />
<img v-if="(product.name !== '一路开关') || (device.data[0].value !== '关')" :src="product.image.replace('.png', '.svg')" />
<div v-for="device in product.devices" class="col-md-3 col-sm-4 col-6 p-1">
<div class="card">
<router-link :to="{path:'/pages/iot/device',query:{number:device.number}}">
<div class="weui-grid__icon">
<img v-if="product.name === '一路开关' && device.data[0].value === '关'" :src="product.image.replace('.png', '.svg')" class="grayscale" />
<img v-if="(product.name !== '一路开关') || (device.data[0].value !== '关')" :src="product.image.replace('.png', '.svg')" />
</div>
<p class="weui-grid__label">{{device.displayName}}</p>
</router-link>
</div>
<p class="weui-grid__label">{{device.displayName}}</p>
</router-link>
</div>
</div>
</div>
</div>
Loading…
Cancel
Save