Former-commit-id: 01fd0374e8f9ad8d90c1fed52a4698e1b1b762d7
TangShanKaiPing
wanggang 6 years ago
parent 92be8b0af2
commit 00a86984a9

@ -7,7 +7,6 @@
<script src="~/lib/linq/linq.min.js"></script> <script src="~/lib/linq/linq.min.js"></script>
<script src="~/lib/jquery-validation/jquery.validate.min.js"></script> <script src="~/lib/jquery-validation/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script> <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
@*<script src="~/lib/jquery-validation-unobtrusive/unobtrusive-bootstrap.js"></script>*@
<script src="~/lib/jquery-ajax-unobtrusive/jquery.unobtrusive-ajax.min.js"></script> <script src="~/lib/jquery-ajax-unobtrusive/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/lib/fancybox/jquery.fancybox.min.js"></script> <script src="~/lib/fancybox/jquery.fancybox.min.js"></script>
<script src="~/lib/jquery-datetimepicker/jquery.datetimepicker.full.min.js"></script> <script src="~/lib/jquery-datetimepicker/jquery.datetimepicker.full.min.js"></script>
@ -19,3 +18,4 @@
<script src="~/lib/chart.js/Chart.bundle.min.js"></script> <script src="~/lib/chart.js/Chart.bundle.min.js"></script>
<script src="~/lib/kindeditor/kindeditor-all-min.js"></script> <script src="~/lib/kindeditor/kindeditor-all-min.js"></script>
<script src="~/lib/flv.js/flv.min.js"></script> <script src="~/lib/flv.js/flv.min.js"></script>
<script src="~/lib/toastr/toastr.min.js"></script>

@ -13,4 +13,5 @@
<link rel="stylesheet" href="~/lib/select2/css/select2-bootstrap4.min.css" /> <link rel="stylesheet" href="~/lib/select2/css/select2-bootstrap4.min.css" />
<link rel="stylesheet" href="~/lib/tree-multiselect/dist/jquery.tree-multiselect.min.css" /> <link rel="stylesheet" href="~/lib/tree-multiselect/dist/jquery.tree-multiselect.min.css" />
<link rel="stylesheet" href="~/lib/kindeditor/themes/default/default.css" /> <link rel="stylesheet" href="~/lib/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="~/lib/toastr/toastr.min.css">
<link rel="stylesheet" href="~/css/site.css"> <link rel="stylesheet" href="~/css/site.css">

@ -146,6 +146,11 @@
"library": "../lib/node_modules/linq/", "library": "../lib/node_modules/linq/",
"destination": "wwwroot/lib/linq/", "destination": "wwwroot/lib/linq/",
"files": [ "linq.min.js" ] "files": [ "linq.min.js" ]
},
{
"library": "../lib/node_modules/toastr/build",
"destination": "wwwroot/lib/toastr/",
"files": [ "toastr.min.css", "toastr.min.js" ]
} }
] ]
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -5,10 +5,11 @@
public const string ServerToClient = nameof(ServerToClient); public const string ServerToClient = nameof(ServerToClient);
public const string ClientToServer = nameof(ClientToServer); public const string ClientToServer = nameof(ClientToServer);
public const string ExecApi = nameof(ExecApi); public const string ExecApiRequest = nameof(ExecApiRequest);
public const string ExecApiResponse = nameof(ExecApiResponse);
public const string ExecSceneRequest = nameof(ExecSceneRequest);
public const string ExecSceneRsponse = nameof(ExecSceneRsponse);
public const string ExecCommand = nameof(ExecCommand); public const string ExecCommand = nameof(ExecCommand);
public const string ExecScene = nameof(ExecScene);
public const string ApiCallback = nameof(ApiCallback);
public const string UpdateNodeResponse = nameof(UpdateNodeResponse); //上传节点 public const string UpdateNodeResponse = nameof(UpdateNodeResponse); //上传节点
public const string UpdateProductResponse = nameof(UpdateProductResponse);//上传产品 public const string UpdateProductResponse = nameof(UpdateProductResponse);//上传产品

@ -256,7 +256,11 @@ namespace IoTCenter.Services
this._dataService.Delete<IoTTiggerCommand, EditIoTTiggerCommandModel>(model); this._dataService.Delete<IoTTiggerCommand, EditIoTTiggerCommandModel>(model);
} }
// //
else if (method == Methods.ApiCallback) else if (method == Methods.ExecApiResponse)
{
this.ServerToClient(method, message, to, from);
}
else if (method == Methods.ExecSceneRsponse)
{ {
this.ServerToClient(method, message, to, from); this.ServerToClient(method, message, to, from);
} }

@ -334,17 +334,16 @@ namespace IoT.Shared.Services
dataService.Delete<IoTTiggerCommand, EditIoTTiggerCommandModel>(model); dataService.Delete<IoTTiggerCommand, EditIoTTiggerCommandModel>(model);
this.ClientToServer(method, model, null); this.ClientToServer(method, model, null);
} }
else if (method == Methods.ExecApi) else if (method == Methods.ExecApiRequest)
{ {
var cfg = scope.ServiceProvider.GetService<IConfiguration>(); var cfg = scope.ServiceProvider.GetService<IConfiguration>();
var port = cfg["server.urls"].Split(':')[2]; var port = cfg["server.urls"].Split(':')[2];
var url = $"http://localhost:{port}{message.FromJson<string>()}"; var url = $"http://localhost:{port}{message.FromJson<string>()}";
var httpClient = scope.ServiceProvider.GetService<IHttpClientFactory>().CreateClient(); var httpClient = scope.ServiceProvider.GetService<IHttpClientFactory>().CreateClient();
var result = httpClient.GetStringAsync(url).Result; var result = httpClient.GetStringAsync(url).Result;
this.ClientToServer(Methods.ApiCallback, result, from); this.ClientToServer(Methods.ExecApiResponse, result, from);
} }
/////////////////////////////////////////////////////////// else if (method == Methods.ExecSceneRequest)
else if (method == Methods.ExecScene)
{ {
var sceneId = message.FromJson<Guid>(); var sceneId = message.FromJson<Guid>();
var sceneCommandRepo = scope.ServiceProvider.GetService<IRepository<SceneCommand>>(); var sceneCommandRepo = scope.ServiceProvider.GetService<IRepository<SceneCommand>>();
@ -355,7 +354,9 @@ namespace IoT.Shared.Services
.Select(o => o.Command) .Select(o => o.Command)
.ToList(); .ToList();
this.ExecCommands(commands); this.ExecCommands(commands);
this.ClientToServer(Methods.ExecSceneRsponse, null, from);
} }
///////////////////////////////////////////////////////////
else if (method == Methods.ExecCommand) else if (method == Methods.ExecCommand)
{ {
var id = message.FromJson<Guid>(); var id = message.FromJson<Guid>();

@ -147,7 +147,7 @@ namespace IoTCenter.Controllers
var message = $"{method}{query2}"; var message = $"{method}{query2}";
var group = device.Node.Number; var group = device.Node.Number;
this._hub.ServerToClient(Methods.ExecApi, message, group, connectionId); this._hub.ServerToClient(Methods.ExecApiRequest, message, group, connectionId);
} }
return Json(ApiResponse.AsyncSuccess()); return Json(ApiResponse.AsyncSuccess());
} }
@ -165,7 +165,7 @@ namespace IoTCenter.Controllers
{ {
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString(); var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
var scene = this._sceneRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Id == id); var scene = this._sceneRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Id == id);
this._hub.ServerToClient(Methods.ExecScene, id, scene.Node.Number, connectionId); this._hub.ServerToClient(Methods.ExecSceneRequest, id, scene.Node.Number, connectionId);
return Json(ApiResponse.AsyncSuccess()); return Json(ApiResponse.AsyncSuccess());
} }
catch (Exception ex) catch (Exception ex)
@ -397,7 +397,7 @@ namespace IoTCenter.Controllers
{ {
var api = device.Product.Apis.FirstOrDefault(o => o.Command == command); var api = device.Product.Apis.FirstOrDefault(o => o.Command == command);
var message = $"{api.Path}{api.Command}?number={device.Number}"; var message = $"{api.Path}{api.Command}?number={device.Number}";
this._hub.Clients.Group(device.Node.Number).SendAsync(Methods.ServerToClient, Methods.ExecApi, message, connectionId); this._hub.Clients.Group(device.Node.Number).SendAsync(Methods.ServerToClient, Methods.ExecApiRequest, message, connectionId);
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -69,7 +69,6 @@
console.log(connectionId); console.log(connectionId);
}); });
connection.onclose(function (err) { connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
connection.on("ServerToClient", function (method, json, from) { connection.on("ServerToClient", function (method, json, from) {

@ -146,7 +146,7 @@
<h3 class="card-title"><img src="/images/batch.png" />{{model.Name}}</h3> <h3 class="card-title"><img src="/images/batch.png" />{{model.Name}}</h3>
</div> </div>
<div class="card-body" v-if="model.Scenes.length>0"> <div class="card-body" v-if="model.Scenes.length>0">
<button class="btn btn-success margin ajax Scene" v-for="scene in model.Scenes" :data-scene-id="scene.Id">{{scene.Name}}</button> <button class="btn btn-success" v-for="scene in GetScenes()" v-on:click="CallScene(scene.Id)">{{scene.Name}}</button>
</div> </div>
</div> </div>
</div> </div>

@ -66,7 +66,6 @@
console.log(connectionId); console.log(connectionId);
}); });
connection.onclose(function (err) { connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
connection.on("ServerToClient", function (method, json, from) { connection.on("ServerToClient", function (method, json, from) {

Binary file not shown.

@ -98,6 +98,11 @@
"library": "../../../lib/node_modules/linq/", "library": "../../../lib/node_modules/linq/",
"destination": "wwwroot/lib/linq/", "destination": "wwwroot/lib/linq/",
"files": [ "linq.min.js" ] "files": [ "linq.min.js" ]
},
{
"library": "../../../lib/node_modules/toastr/build",
"destination": "wwwroot/lib/toastr/",
"files": [ "toastr.min.css", "toastr.min.js" ]
} }
] ]
} }

@ -10,3 +10,6 @@
.page { .page {
/*background-color: white;*/ /*background-color: white;*/
} }
.toast-top-center .toast {
left: auto !important;
}

@ -89,7 +89,6 @@
console.log(connectionId); console.log(connectionId);
}); });
connection.onclose(function (err) { connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
connection.on("ServerToClient", function (method, json, from) { connection.on("ServerToClient", function (method, json, from) {

@ -21,6 +21,8 @@ var volume = 0.5;
if (isApp) { if (isApp) {
Framework7.use(Framework7Vue); Framework7.use(Framework7Vue);
} }
toastr.options.timeOut = 500;
toastr.options.positionClass = "toast-top-center";
/*fun*/ /*fun*/
function alert(message,title) { function alert(message,title) {
if (isApp) { if (isApp) {
@ -31,13 +33,9 @@ function alert(message,title) {
alert(message); alert(message);
} }
} }
function hideLoading() { function hideLoading(message) {
if (isApp) { toastr.success(message||'请求成功');
$('.overlay').hide();
}
else {
$('.overlay').hide();
}
} }
function loadData() { function loadData() {
var formData = new FormData(); var formData = new FormData();
@ -57,7 +55,7 @@ function loadData() {
} }
}) })
.catch(function (error) { .catch(function (error) {
alert(error) toastr.error('数据加载失败!');
}) })
.then(hideLoading); .then(hideLoading);
} }
@ -183,7 +181,7 @@ function ajax(url, data, type) {
data: data, data: data,
success: AjaxCallBack success: AjaxCallBack
}).fail(function (result) { }).fail(function (result) {
console.log('error'); toastr.error('请求发送失败!');
console.log(result); console.log(result);
}).always(function () { }).always(function () {
$('.overlay').hide(); $('.overlay').hide();
@ -255,19 +253,17 @@ function connect() {
} }
if (connection.state === signalR.HubConnectionState.Disconnected) { if (connection.state === signalR.HubConnectionState.Disconnected) {
connection.start().then(function () { connection.start().then(function () {
toastr.success('客户端与服务器连接成功!');
}).catch(function (err) { }).catch(function (err) {
console.error(err.toString()); toastr.error('客户端与服务器连接失败!');
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
} }
} }
connection.on('Connected', function (id) { connection.on('Connected', function (id) {
connectionId = id; connectionId = id;
console.log(connectionId);
}); });
connection.onclose(function (err) { connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
connection.on("ServerToClient", function (method, json, to,from) { connection.on("ServerToClient", function (method, json, to,from) {
@ -276,23 +272,32 @@ connection.on("ServerToClient", function (method, json, to,from) {
}); });
function onMessage(method, json,to, from) { function onMessage(method, json,to, from) {
var item = JSON.parse(json); var item = JSON.parse(json);
if (method === 'ApiCallback') { if (method === 'ExecApiRsponse') {
console.log(json); console.log(json);
toastr.success('操作调用成功');
} }
else if else if (method === 'ExecSceneRsponse') {
(method == 'DataEntityInserted' || method == 'DataEntityUpdated') { console.log(json);
var device = Enumerable.from(vm.model.Devices).firstOrDefault(function (o) { return o.Id === item.DeviceId; }) toastr.success('场景调用成功');
if (device) {
updateItem(device.Data, item);
}
} }
else if (method == 'SceneEntityInserted' ||method == 'SceneEntityUpdated') { else {
updateItem(vm.model.Scenes, item); if(method == 'DataEntityInserted' || method == 'DataEntityUpdated') {
var device = Enumerable.from(vm.model.Devices).firstOrDefault(function (o) { return o.Id === item.DeviceId; })
if (device) {
updateItem(device.Data, item);
toastr.info(device.DisplayName+'更新');
}
}
else if (method == 'SceneEntityInserted' || method == 'SceneEntityUpdated') {
updateItem(vm.model.Scenes, item);
toastr.info(item.Name+'更新');
}
else if (method == 'SceneEntityDeleted') {
deleteItem(vm.model.Scenes, item);
toastr.info(item.Name+'删除');
}
} }
else if (method == 'SceneEntityDeleted') {
deleteItem(vm.model.Scenes, item);
}
} }
/*vue*/ /*vue*/
function init() { function init() {
@ -373,6 +378,9 @@ function init() {
CallApi(number, method, query) { CallApi(number, method, query) {
ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: number, method: method, query: query }, 'post'); ajax('/App/ExecApi', { token: token, connectionId: connectionId, number: number, method: method, query: query }, 'post');
}, },
GetScenes() {
return Enumerable.from(this.model.Scenes).orderBy('o=>o.DisplayOrder').toArray();
},
CallScene(id) { CallScene(id) {
ajax('/App/ExecScene', { token: token, connectionId: connectionId, id: id }, 'post'); ajax('/App/ExecScene', { token: token, connectionId: connectionId, id: id }, 'post');
}, },

@ -21,6 +21,8 @@ var volume = 0.5;
if (isApp) { if (isApp) {
Framework7.use(Framework7Vue); Framework7.use(Framework7Vue);
} }
toastr.options.timeOut = 500;
toastr.options.positionClass = "toast-top-center";
/*fun*/ /*fun*/
function alert(message, title) { function alert(message, title) {
if (isApp) { if (isApp) {
@ -47,6 +49,7 @@ function loadData() {
else { else {
init(); init();
} }
toastr.success('数据加载成功!');
}) })
.catch(function (error) { .catch(function (error) {
alert(error) alert(error)
@ -258,7 +261,6 @@ connection.on('Connected', function (id) {
console.log(connectionId); console.log(connectionId);
}); });
connection.onclose(function (err) { connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
connection.on("ServerToClient", function (method, json, from) { connection.on("ServerToClient", function (method, json, from) {
@ -268,10 +270,17 @@ connection.on("ServerToClient", function (method, json, from) {
function onMessage(method, json, from) { function onMessage(method, json, from) {
var item = JSON.parse(json); var item = JSON.parse(json);
if (method == 'DeviceEntityInserted' || method == 'DeviceEntityUpdated') { if (method == 'DeviceEntityInserted' || method == 'DeviceEntityUpdated') {
toastr.info(item.DisplayName+'更新');
updateItem(vm.model.Devices, item); updateItem(vm.model.Devices, item);
} else if (method == 'DeviceEntityDeleted') { } else if (method == 'DeviceEntityDeleted') {
deleteItem(vm.model.Devices, item); deleteItem(vm.model.Devices, item);
toastr.info(item.DisplayName + '删除');
} else if (method == 'DataEntityInserted' || method == 'DataEntityUpdated') {
var device = Enumerable.from(vm.model.Devices).firstOrDefault(function (o) { return o.Id === item.DeviceId; })
if (device) {
updateItem(device.Data, item);
toastr.info(device.DisplayName + '更新');
}
} }
} }
/*vue*/ /*vue*/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -6,6 +6,7 @@
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="lib/framework7/css/framework7.bundle.min.css"> <link rel="stylesheet" href="lib/framework7/css/framework7.bundle.min.css">
<link rel="stylesheet" href="css/framework7-icons.css"> <link rel="stylesheet" href="css/framework7-icons.css">
<link rel="stylesheet" href="lib/toastr/toastr.min.css">
<link rel="stylesheet" href="css/app.css"> <link rel="stylesheet" href="css/app.css">
</head> </head>
<body> <body>
@ -130,7 +131,7 @@
<div class="card-header">场景</div> <div class="card-header">场景</div>
<div class="card-content card-content-padding"> <div class="card-content card-content-padding">
<div class="row"> <div class="row">
<label class="button button-raised" v-for="scene in model.Scenes" v-on:click="CallScene(scene.Id)">{{scene.Name}}</label> <label class="button button-raised" v-for="scene in GetScenes()" v-on:click="CallScene(scene.Id)">{{scene.Name}}</label>
</div> </div>
</div> </div>
</div> </div>
@ -602,6 +603,7 @@
<script type="text/javascript" src="lib/framework7/js/framework7.bundle.min.js"></script> <script type="text/javascript" src="lib/framework7/js/framework7.bundle.min.js"></script>
<script type="text/javascript" src="lib/framework7/js/framework7-vue.bundle.min.js"></script> <script type="text/javascript" src="lib/framework7/js/framework7-vue.bundle.min.js"></script>
<script type="text/javascript" src="lib/flv.js/flv.min.js"></script> <script type="text/javascript" src="lib/flv.js/flv.min.js"></script>
<script type="text/javascript" src="lib/toastr/toastr.min.js"></script>
<script type="text/javascript" src="js/node.js"></script> <script type="text/javascript" src="js/node.js"></script>
<script> <script>
var debug = true; var debug = true;

@ -89,7 +89,6 @@
console.log(connectionId); console.log(connectionId);
}); });
connection.onclose(function (err) { connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000); setTimeout(connect, 15 * 1000);
}); });
connection.on("ServerToClient", function (method, json, from) { connection.on("ServerToClient", function (method, json, from) {

@ -6,6 +6,7 @@
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="lib/framework7/css/framework7.bundle.min.css"> <link rel="stylesheet" href="lib/framework7/css/framework7.bundle.min.css">
<link rel="stylesheet" href="css/framework7-icons.css"> <link rel="stylesheet" href="css/framework7-icons.css">
<link rel="stylesheet" href="lib/toastr/toastr.min.css">
<link rel="stylesheet" href="css/app.css"> <link rel="stylesheet" href="css/app.css">
</head> </head>
<body> <body>
@ -599,6 +600,7 @@
<script type="text/javascript" src="lib/framework7/js/framework7.bundle.min.js"></script> <script type="text/javascript" src="lib/framework7/js/framework7.bundle.min.js"></script>
<script type="text/javascript" src="lib/framework7/js/framework7-vue.bundle.min.js"></script> <script type="text/javascript" src="lib/framework7/js/framework7-vue.bundle.min.js"></script>
<script type="text/javascript" src="lib/flv.js/flv.min.js"></script> <script type="text/javascript" src="lib/flv.js/flv.min.js"></script>
<script type="text/javascript" src="lib/toastr/toastr.min.js"></script>
<script type="text/javascript" src="js/product.js"></script> <script type="text/javascript" src="js/product.js"></script>
<script> <script>
var debug = true; var debug = true;

Binary file not shown.

@ -32,7 +32,7 @@
"urijs": "1.19.2", "urijs": "1.19.2",
"vue": "2.6.10", "vue": "2.6.10",
"metro4": "4.3.3", "metro4": "4.3.3",
"pace-js": "1.0.2" "toastr": "2.1.4"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {

Loading…
Cancel
Save