diff --git a/projects/Infrastructure/Views/Shared/_Layout.cshtml b/projects/Infrastructure/Views/Shared/_Layout.cshtml index 9f2182af..11d55d48 100644 --- a/projects/Infrastructure/Views/Shared/_Layout.cshtml +++ b/projects/Infrastructure/Views/Shared/_Layout.cshtml @@ -138,6 +138,13 @@ + + @RenderSection("scripts", required: false) diff --git a/projects/IoTNode/Views/Home/Index.cshtml b/projects/IoTNode/Views/Home/Index.cshtml index c3e34f75..addbf3f2 100644 --- a/projects/IoTNode/Views/Home/Index.cshtml +++ b/projects/IoTNode/Views/Home/Index.cshtml @@ -29,64 +29,5 @@ @section scripts{ - - - - + } \ No newline at end of file diff --git a/projects/IoTNode/wwwroot/js/home/index.js b/projects/IoTNode/wwwroot/js/home/index.js new file mode 100644 index 00000000..7629be37 --- /dev/null +++ b/projects/IoTNode/wwwroot/js/home/index.js @@ -0,0 +1,73 @@ +//tools +$('a.ajax.api').click(function () { + if (confirm('确认操作编号为:' + $(this).attr('data-number') + '的设备吗?')) { + $.get($(this).attr('href'), function () { + window.location.href = window.location.href; + }); + }; + return false; +}); +function subscribes(events, action) { + if (!events || !action) { + return; + } + for (var i = 0; i < events.length; i++) { + PubSub.subscribe(events[i], function (m, d) { action(m, d); }); + } +} + +function unsubscribes(events) { + if (!events) { + return; + } + for (var i = 0; i < events.length; i++) { + PubSub.unsubscribe(events[i]); + } +} +// + +var app = new Vue({ + el: '#app', + data() { + return { + title: "产品", + url: config.baseUrl + '/Home/IndexData', + gateway: null, + events: ['IoTDeviceEntityInserted', 'IoTDeviceEntityUpdated', 'IoTDeviceEntityDeleted'] + }; + }, + mounted: function () { + this.subscribe(); + this.load(); + }, + beforeDestroy: function () { + unsubscribes(this.events); + }, + methods: { + subscribe: function () { + var app = this; + subscribes(this.events, function (method, data) { + app.load(); + }); + }, + load: function () { + var app = this; + axios.post(this.url).then(function (response) { + app.gateway = response.data; + }); + }, + upload: function () { + $.get(config.baseUrl + 'Home/Upload', function () { + this.load(); + }); + }, + remove: function (gateway, number) { + if (confirm('确认操作编号为:' + 'number' + '的设备吗?')) { + var app = this; + $.get(config.baseUrl + '/Gateway/X95")' + '?gateway=' + gateway + '&number=' + number, function () { + app.load(); + }); + }; + } + } +}); \ No newline at end of file diff --git a/projects/IoTNode/wwwroot/js/signalr.js b/projects/IoTNode/wwwroot/js/signalr.js index 0378a807..0e946902 100644 --- a/projects/IoTNode/wwwroot/js/signalr.js +++ b/projects/IoTNode/wwwroot/js/signalr.js @@ -22,6 +22,7 @@ connection.on('Connected', function (id) { }); connection.on("ServerToClient", function (method, message, to, from) { + console.log(method); PubSub.publish(method, { message: message, to: to, from: from }); }); connect(); \ No newline at end of file