110 lines
2.1 KiB
JavaScript
110 lines
2.1 KiB
JavaScript
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
|
|
Vue.use(Vuex);
|
|
|
|
export default new Vuex.Store({
|
|
state: {
|
|
notification: null,
|
|
notificationTimeout: null,
|
|
saving: false,
|
|
|
|
|
|
connection: {
|
|
hostname: null,
|
|
accesspoint: true,
|
|
station: false,
|
|
ssid: null,
|
|
password: null,
|
|
dhcp: true,
|
|
ip: null,
|
|
subnetmask: null,
|
|
gateway: null
|
|
},
|
|
|
|
|
|
system: {
|
|
pins: {
|
|
ledAP: null,
|
|
ledSTA: null,
|
|
apButton: null,
|
|
},
|
|
ledCount: null
|
|
}
|
|
|
|
/*
|
|
settingStatic: false,
|
|
loadingIndicator: '|',
|
|
uploadProgress: false,
|
|
|
|
static: {
|
|
r: 0,
|
|
g: 0,
|
|
b: 0,
|
|
w: 0
|
|
}
|
|
*/
|
|
},
|
|
|
|
mutations: {
|
|
_setNotification(state, payload)
|
|
{
|
|
state.notification = payload.notification;
|
|
state.notificationTimeout = payload.notificationTimeout;
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
showNotification(context, payload)
|
|
{
|
|
const self = this;
|
|
if (context.state.notificationTimeout !== null)
|
|
clearTimeout(context.state.notificationTimeout);
|
|
|
|
const notificationTimeout = setTimeout(() =>
|
|
{
|
|
context.dispatch('hideNotification');
|
|
}, 5000);
|
|
|
|
context.commit('_setNotification', {
|
|
notification: payload,
|
|
notificationTimeout
|
|
});
|
|
},
|
|
|
|
|
|
hideNotification(context)
|
|
{
|
|
if (context.state.notificationTimeout !== null)
|
|
clearTimeout(context.state.notificationTimeout);
|
|
|
|
context.commit('_setNotification', {
|
|
notification: null,
|
|
notificationTimeout: null
|
|
});
|
|
},
|
|
|
|
|
|
notifyAPIError(context, payload)
|
|
{
|
|
console.log(payload.error);
|
|
let errorMessage = '';
|
|
|
|
if (payload.error.response)
|
|
{
|
|
errorMessage = 'HTTP response code ' + payload.error.response.status;
|
|
}
|
|
else if (payload.error.request)
|
|
{
|
|
errorMessage = 'No response';
|
|
}
|
|
else
|
|
{
|
|
errorMessage = payload.error.message;
|
|
}
|
|
|
|
context.dispatch('showNotification', { message: payload.message + '\n\n' + errorMessage, isError: true });
|
|
}
|
|
},
|
|
})
|