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/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/unobtrusive-bootstrap.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/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/kindeditor/kindeditor-all-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/tree-multiselect/dist/jquery.tree-multiselect.min.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">

@ -146,6 +146,11 @@
"library": "../lib/node_modules/linq/",
"destination": "wwwroot/lib/linq/",
"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 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 ExecScene = nameof(ExecScene);
public const string ApiCallback = nameof(ApiCallback);
public const string UpdateNodeResponse = nameof(UpdateNodeResponse); //上传节点
public const string UpdateProductResponse = nameof(UpdateProductResponse);//上传产品

@ -256,7 +256,11 @@ namespace IoTCenter.Services
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);
}

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

@ -147,7 +147,7 @@ namespace IoTCenter.Controllers
var message = $"{method}{query2}";
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());
}
@ -165,7 +165,7 @@ namespace IoTCenter.Controllers
{
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);
this._hub.ServerToClient(Methods.ExecScene, id, scene.Node.Number, connectionId);
this._hub.ServerToClient(Methods.ExecSceneRequest, id, scene.Node.Number, connectionId);
return Json(ApiResponse.AsyncSuccess());
}
catch (Exception ex)
@ -397,7 +397,7 @@ namespace IoTCenter.Controllers
{
var api = device.Product.Apis.FirstOrDefault(o => o.Command == command);
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)
{

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

@ -146,7 +146,7 @@
<h3 class="card-title"><img src="/images/batch.png" />{{model.Name}}</h3>
</div>
<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>

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

Binary file not shown.

@ -98,6 +98,11 @@
"library": "../../../lib/node_modules/linq/",
"destination": "wwwroot/lib/linq/",
"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 {
/*background-color: white;*/
}
.toast-top-center .toast {
left: auto !important;
}

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

@ -21,6 +21,8 @@ var volume = 0.5;
if (isApp) {
Framework7.use(Framework7Vue);
}
toastr.options.timeOut = 500;
toastr.options.positionClass = "toast-top-center";
/*fun*/
function alert(message,title) {
if (isApp) {
@ -31,14 +33,10 @@ function alert(message,title) {
alert(message);
}
}
function hideLoading() {
if (isApp) {
}
else {
function hideLoading(message) {
toastr.success(message||'请求成功');
$('.overlay').hide();
}
}
function loadData() {
var formData = new FormData();
formData.append('number', new URI().search(true).number);
@ -57,7 +55,7 @@ function loadData() {
}
})
.catch(function (error) {
alert(error)
toastr.error('数据加载失败!');
})
.then(hideLoading);
}
@ -183,7 +181,7 @@ function ajax(url, data, type) {
data: data,
success: AjaxCallBack
}).fail(function (result) {
console.log('error');
toastr.error('请求发送失败!');
console.log(result);
}).always(function () {
$('.overlay').hide();
@ -255,19 +253,17 @@ function connect() {
}
if (connection.state === signalR.HubConnectionState.Disconnected) {
connection.start().then(function () {
toastr.success('客户端与服务器连接成功!');
}).catch(function (err) {
console.error(err.toString());
toastr.error('客户端与服务器连接失败!');
setTimeout(connect, 15 * 1000);
});
}
}
connection.on('Connected', function (id) {
connectionId = id;
console.log(connectionId);
});
connection.onclose(function (err) {
console.error(err);
setTimeout(connect, 15 * 1000);
});
connection.on("ServerToClient", function (method, json, to,from) {
@ -276,24 +272,33 @@ connection.on("ServerToClient", function (method, json, to,from) {
});
function onMessage(method, json,to, from) {
var item = JSON.parse(json);
if (method === 'ApiCallback') {
if (method === 'ExecApiRsponse') {
console.log(json);
toastr.success('操作调用成功');
}
else if
(method == 'DataEntityInserted' || method == 'DataEntityUpdated') {
else if (method === 'ExecSceneRsponse') {
console.log(json);
toastr.success('场景调用成功');
}
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+'更新');
}
}
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+'删除');
}
}
}
/*vue*/
function init() {
$('#template style').each(function (i, n) {
@ -373,6 +378,9 @@ function init() {
CallApi(number, method, query) {
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) {
ajax('/App/ExecScene', { token: token, connectionId: connectionId, id: id }, 'post');
},

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

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">
<link rel="stylesheet" href="lib/framework7/css/framework7.bundle.min.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">
</head>
<body>
@ -130,7 +131,7 @@
<div class="card-header">场景</div>
<div class="card-content card-content-padding">
<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>
@ -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-vue.bundle.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>
var debug = true;

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

@ -6,6 +6,7 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="lib/framework7/css/framework7.bundle.min.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">
</head>
<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-vue.bundle.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>
var debug = true;

Binary file not shown.

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

Loading…
Cancel
Save