You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoTNode/wwwroot/js/home/index.js

73 lines
2.0 KiB

//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();
});
};
}
}
});