132 lines
4.1 KiB
JavaScript
132 lines
4.1 KiB
JavaScript
|
|
// const URL = "/westone-api/v1/system/auth";
|
|
|
|
const URL = "https://devcpone.aplikasi.web.id/westone-api/v1/system/auth/";
|
|
|
|
const store = {
|
|
namespaced: true,
|
|
state() {
|
|
return {
|
|
count: 0,
|
|
data: null,
|
|
email: "",
|
|
password: "",
|
|
dialog_success: false,
|
|
loading: false,
|
|
errorMessage: "",
|
|
iin: window.i18n.global.t('message.login'),
|
|
alert: {
|
|
show: false,
|
|
type: 'info',
|
|
message: window.i18n.global.t('message.msgInfo')
|
|
}
|
|
};
|
|
},
|
|
mutations: {
|
|
increment(state) {
|
|
state.count++;
|
|
},
|
|
decrement(state) {
|
|
state.count--;
|
|
},
|
|
setData(state, payload) {
|
|
state.data = payload;
|
|
},
|
|
setEmail(state, data) {
|
|
state.email = data;
|
|
},
|
|
setPassword(state, data) {
|
|
state.password = data;
|
|
},
|
|
setDialogSuccess(state, data) {
|
|
state.dialog_success = data;
|
|
},
|
|
setLoading(state, data) {
|
|
state.loading = data;
|
|
},
|
|
setAlert(state, data) {
|
|
state.alert = data;
|
|
}
|
|
},
|
|
actions: {
|
|
increment({ commit }) {
|
|
commit('increment');
|
|
},
|
|
decrement({ commit }) {
|
|
commit('decrement');
|
|
},
|
|
async login({ state, commit }) {
|
|
commit('setLoading', true);
|
|
let alert = {
|
|
show: false,
|
|
type: 'info',
|
|
message: window.i18n.global.t('message.msgInfo')
|
|
}
|
|
let params = {
|
|
username: state.email,
|
|
password: state.password
|
|
};
|
|
console.log(params);
|
|
try {
|
|
const response = await axios.post(URL + '/login', params);
|
|
console.log(response.data)
|
|
if (response.data.status != 'OK') {
|
|
commit('setLoading', false);
|
|
if (response.data.message !== 'Invalid') {
|
|
alert.message = window.i18n.global.t('message.errorQuery');
|
|
} else {
|
|
alert.message = window.i18n.global.t('message.invalid');
|
|
}
|
|
alert.type = "error"
|
|
} else {
|
|
commit('setLoading', false);
|
|
commit('setData', response.data.data);
|
|
localStorage.setItem("token", response.data.data.token)
|
|
localStorage.setItem('user', JSON.stringify(response.data.data.user))
|
|
//console.log(localStorage.getItem("token"))
|
|
// if (data.user.is_courier === 'Y' && window.innerWidth < 600)
|
|
// window.location = "/one-ui/test/vuex/one-courier-mobile/";
|
|
// else
|
|
// window.location = "/" + response.data.data.user.M_UserGroupDashboard;
|
|
|
|
}
|
|
commit('setAlert', alert)
|
|
} catch (error) {
|
|
console.log(error)
|
|
commit('setLoading', false);
|
|
|
|
}
|
|
},
|
|
async loginState({ state, commit }) {
|
|
commit('setLoading', true);
|
|
const params = {
|
|
email: state.email,
|
|
password: state.pasword
|
|
};
|
|
|
|
try {
|
|
const response = await axios.post(URL + '/login', params);
|
|
if (response.status != 'OK') {
|
|
commit('setLoading', false);
|
|
|
|
} else {
|
|
commit('setLoading', false);
|
|
commit('setData', response.data);
|
|
|
|
}
|
|
} catch (error) {
|
|
commit('setLoading', false);
|
|
commit('setError', error);
|
|
}
|
|
},
|
|
async LoginParam({ commit }, params) {
|
|
try {
|
|
const response = await axios.post(URL + '/login', params);
|
|
commit('setData', response.data);
|
|
} catch (error) {
|
|
commit('setError', error);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
export default store |