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.
90 lines
3.6 KiB
90 lines
3.6 KiB
<template>
|
|
<layout v-bind:title="title">
|
|
<div class="row overlay-wrapper">
|
|
<div class="col-md-2 col-sm-4 col-xs-6" v-for="item in product.devices">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">{{item.displayName||item.name}}</h3>
|
|
<div class="card-tools"><span data-toggle="tooltip" class="badge bg-green">{{item.count}}</span></div>
|
|
</div>
|
|
<router-link :to="{path:'/pages/device.html',query:{number:item.number}}" class="card-body" style="display: block; text-align: center;">
|
|
<img :src="config.baseUrl+product.image" style="margin: 0px auto; width: 64px;">
|
|
</router-link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</layout>
|
|
</template>
|
|
<script>
|
|
export default {
|
|
data: function () {
|
|
return {
|
|
title: '产品',
|
|
url: '/IoTCenter/api/v1/product/getProduct?number=' + this.$route.query.number,
|
|
product: {
|
|
devices: []
|
|
},
|
|
events: ['ProductEntityInserted', 'ProductEntityUpdated', 'ProductEntityDeleted',
|
|
'DeviceEntityInserted', 'DeviceEntityUpdated', 'DeviceEntityDeleted',
|
|
'DataEntityInserted', 'DataEntityUpdated', 'DataEntityDeleted']
|
|
}
|
|
},
|
|
mounted: function () {
|
|
this.subscribe();
|
|
this.load();
|
|
},
|
|
methods: {
|
|
load() {
|
|
var url = config.baseUrl + this.url;
|
|
var vm = this;
|
|
axios.post(url).then(function (response) {
|
|
vm.product = response.data;
|
|
});
|
|
},
|
|
subscribe() {
|
|
var vm = this;
|
|
subscribe(this.events, function (method, data) {
|
|
var item = JSON.product(data.message);
|
|
if (method.indexOf('Product') == 0) {
|
|
vm.load();
|
|
}
|
|
else {
|
|
var list;
|
|
if (method.indexOf('Device') == 0) {
|
|
if (vm.product.id === device.productId) {
|
|
list = device.devices;
|
|
}
|
|
}
|
|
else {
|
|
if (method.indexOf('Device') == 0) {
|
|
if (vm.product.id === device.productId) {
|
|
list = product.devices;
|
|
}
|
|
}
|
|
else if (method.indexOf('Data') == 0) {
|
|
var device = Enumerable.from(vm.product.devices).firstOrDefault(function (o) { return o.id === item.deviceId; });
|
|
if (device) {
|
|
list = device.data;
|
|
}
|
|
}
|
|
}
|
|
if (list) {
|
|
if (method.indexOf('Deleted') >= 0) {
|
|
removeById(list, item);
|
|
}
|
|
else {
|
|
updateById(list, item);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
},
|
|
unsubscribe() {
|
|
unsubscribe(this.events);
|
|
}
|
|
},
|
|
beforeDestroy: function () {
|
|
this.unsubscribe();
|
|
}
|
|
}
|
|
</script> |