Set Light is now functional when clic on a switch button.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<inline-desc v-if="inlineDesc">{{inlineDesc}}</inline-desc>
|
||||
</div>
|
||||
<div class="weui_cell_ft">
|
||||
<input class="weui_switch" type="checkbox" :disabled="disabled" v-model="value"/>
|
||||
<input class="weui_switch" type="checkbox" :disabled="disabled" v-model="data.state"/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -27,27 +27,19 @@ export default {
|
||||
}
|
||||
},
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
data: {},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
value: {
|
||||
type: Boolean,
|
||||
twoWay: true
|
||||
},
|
||||
inlineDesc: {
|
||||
type: String
|
||||
}
|
||||
},
|
||||
ready: function () {},
|
||||
watch: {
|
||||
value: function (newVal) {
|
||||
this.$dispatch('on-change', newVal)
|
||||
'data.state': function (newState) {
|
||||
this.$dispatch('on-change', this.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
<template>
|
||||
<h1>Lights</h1>
|
||||
<group>
|
||||
|
||||
<!--<div v-for="(index, item) in items">
|
||||
{{ index }} {{ item.message }}
|
||||
-->
|
||||
<light v-for="item in lights" :data="item" :value="item.state" @on-change="change"></light>
|
||||
<light v-for="item in lights" :data="item" @on-change="setLight"></light>
|
||||
</group>
|
||||
</template>
|
||||
|
||||
@@ -33,9 +29,7 @@ export default {
|
||||
Light
|
||||
},
|
||||
methods: {
|
||||
change (e) {
|
||||
console.log(e)
|
||||
},
|
||||
/* Get Lights */
|
||||
getLights () {
|
||||
this.$http.get('http://192.168.1.6:8081/v1/capabilities/lights')
|
||||
.then(function (response) {
|
||||
@@ -44,64 +38,21 @@ export default {
|
||||
}, function (err) {
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
/* Set Light */
|
||||
setLight (data) {
|
||||
var msg = ''
|
||||
console.log(data)
|
||||
msg = '{"id": ' + data.id + ', "state": ' + data.state + '}'
|
||||
console.log(msg)
|
||||
this.$http.post('http://192.168.1.6:8081/v1/capabilities/lights', msg)
|
||||
.then(function (response) {
|
||||
console.log('Success!:', response.data)
|
||||
}, function (err) {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<!--
|
||||
|
||||
// GET request
|
||||
this.$http({url: '/someUrl', method: 'GET'}).then(function (response) {
|
||||
// success callback
|
||||
}, function (response) {
|
||||
// error callback
|
||||
});
|
||||
|
||||
quote: ''
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
getQuote() {
|
||||
this.$http
|
||||
.get('http://localhost:3001/api/random-quote', (data) => {
|
||||
this.quote = data;
|
||||
})
|
||||
.error((err) => console.log(err))
|
||||
}
|
||||
|
||||
lightProvider.service ('LightService', function ($http, $q) {
|
||||
|
||||
// Get the Array of All the Lights.
|
||||
this.getLights = function() {
|
||||
return $http.get('/v1/capabilities/lights').then (function (results) {
|
||||
// Result of the Get.
|
||||
if (results.data.response_code == 200)
|
||||
return results.data.Lights;
|
||||
else
|
||||
return $q.reject(results.data.status);
|
||||
}, function(error) {
|
||||
return $q.reject('Failed to make the Request');
|
||||
});
|
||||
};
|
||||
|
||||
// Set a new Light State.
|
||||
this.setLight = function ($id, $state) {
|
||||
|
||||
msg = '{"id": '+ $id + ', "state": ' + $state + '}';
|
||||
return $http.post('/v1/capabilities/lights', msg).then (function (results) {
|
||||
|
||||
if (results.data.response_code == 200)
|
||||
return $q.resolve(results.data.status);
|
||||
else
|
||||
return $q.reject(results.data.status);
|
||||
}, function(error) {
|
||||
return $q.reject('Failed to make the Request');
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
-->
|
||||
|
||||
Reference in New Issue
Block a user