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/WebMVC/wwwroot/js/iot.js

155 lines
5.0 KiB

Vue.prototype.getDeviceDataValue = function (device, name) {
var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault();
if (data) {
return data['value'];
}
return null;
};
Vue.prototype.getDeviceDataDescription = function (device, name) {
var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault();
if (data) {
return data['description'];
}
return null;
}
Vue.prototype.getDeviceDataUnit = function (device, name) {
var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault();
if (data) {
return data['unit'];
}
return null;
}
Vue.prototype.getDeviceData = function (device, name) {
var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault();
if (data) {
return data['value'] + ' ' + data['unit'];
}
return null;
}
Vue.prototype.getData = function (device, name) {
return Enumerable.from(device.data).where(o => o.name === name).firstOrDefault();
}
Vue.prototype.execApi = function (number, method, query) {
loading.show();
axios.post(config.baseUrl + '/IoTCenter/api/v1/api/execApi', { connectionId, number, method, query })
.then(function (response) {
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
loading.hide();
});
}
Vue.prototype.execScene = function (id) {
loading.show();
axios.post('/IoTCenter/api/v1/api/execScene', '"' + id + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
loading.hide();
});
}
Vue.prototype.execOrganScene = function (id) {
loading.show();
axios.post('/IoTCenter/api/v1/api/execOrganScene', '"' + id + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
loading.hide();
});
}
//devices
var iotComponents = [
'gateway',
'light',
'humiture',
'smoke',
'person',
'curtain',
'switch',
'switch3',
'socket',
'ir',
'color-light',
'door',
'camera',
'serial-port',
'ir-command'
];
for (var i = 0; i < iotComponents.length; i++) {
var name = 'iot-' + iotComponents[i];
var url = "components/iot/" + iotComponents[i] + ".html";
vueComponent(name, url);
}
var deviceInfo = [];
deviceInfo['网关'] = 'iot-gateway';
deviceInfo['光强检测器'] = 'iot-light';
deviceInfo['温湿度传感器'] = 'iot-humiture';
deviceInfo['烟雾报警器'] = 'iot-smoke';
deviceInfo['人体感应器'] = 'iot-person';
deviceInfo['窗帘电机'] = 'iot-curtain';
deviceInfo['一路开关'] = 'iot-switch';
deviceInfo['三路开关'] = 'iot-switch3';
deviceInfo['插座'] = 'iot-socket';
deviceInfo['智能插座'] = 'iot-socket';
deviceInfo['红外转发器'] = 'iot-ir';
deviceInfo['调色灯'] = 'iot-color-light';
deviceInfo['门锁'] = 'iot-door';
deviceInfo['摄像头'] = 'iot-camera';
deviceInfo['串口控制器'] = 'iot-serial-port';
///
function updateSelect(action, id, value) {
var select = $('select#' + id);
if (select.length) {
select.find("option[value!='']").remove();
select[0].dispatchEvent(new Event('change'));
if (value) {
var url = config.baseUrl + '/IoTCenter/Admin/Ajax/' + action + '?parentId=' + value;
$.getJSON(url, function (data) {
$.each(data, function (i, v) {
select.append('<option value="' + v.value + '">' + v.text + '</option>');
});
});
}
}
}
$(document).on('change', 'select#productId', function (e) {
var value = $(this).val();
updateSelect('getProductApiJson', 'apiId', value);
});
$(document).on('change', 'select#nodeId', function (e) {
var value = $(this).val();
updateSelect('getDeviceJson', 'deviceId', value);
updateSelect('getCommandJson', 'commandId', value);
if ($(this).parents('form.GlobalSceneCommand').length === 0) {
updateSelect('getSceneJson', 'sceneId', value);
}
});
$(document).on('change', 'select#deviceNodeId', function (e) {
var value = $(this).val();
updateSelect('getDeviceJson', 'deviceId', value);
});
$(document).on('change', 'select#deviceId', function (e) {
var value = $(this).val();
updateSelect('getApiJson', 'apiId', value);
updateSelect('getDataJson', 'dataId', value);
});
$(document).on('change', 'select#organId', function (e) {
var value = $(this).val();
updateSelect('GetOrganSceneJson', 'organSceneId', value);
updateSelect('GetOrganNodeJson', 'nodeId', value);
});
//$(document).on('change', 'select', function (e) {
// $(this).parents('form').find("button[type='submit']").click();
//});