global script dan global store
This commit is contained in:
24
globalscript/global.js
Normal file
24
globalscript/global.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
function one_money(inp, format) {
|
||||||
|
return numeral(inp).format(format ? format : '0,000')
|
||||||
|
}
|
||||||
|
window.one_money = one_money
|
||||||
|
|
||||||
|
function one_token() {
|
||||||
|
return localStorage.getItem('token')
|
||||||
|
}
|
||||||
|
window.one_token = one_token
|
||||||
|
|
||||||
|
function one_user() {
|
||||||
|
return JSON.parse(localStorage.getItem('user'))
|
||||||
|
}
|
||||||
|
window.one_user = one_user
|
||||||
|
function one_float(inp) {
|
||||||
|
try {
|
||||||
|
let val = parseFloat(inp)
|
||||||
|
if (isNaN(val)) return 0.0
|
||||||
|
return val
|
||||||
|
} catch (e) {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.one_float = one_float
|
||||||
68
globalstore/globalstore.js
Normal file
68
globalstore/globalstore.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
const URL = "/westone-api/v1/system/auth";
|
||||||
|
const store = {
|
||||||
|
namespaced: true,
|
||||||
|
state() {
|
||||||
|
return {
|
||||||
|
count: 0,
|
||||||
|
drawer: true,
|
||||||
|
data: null,
|
||||||
|
email: "lashlkdsa",
|
||||||
|
password: null,
|
||||||
|
dialog_success: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
increment(state) {
|
||||||
|
state.count++;
|
||||||
|
},
|
||||||
|
decrement(state) {
|
||||||
|
state.count--;
|
||||||
|
},
|
||||||
|
setData(state, payload) {
|
||||||
|
state.data = payload;
|
||||||
|
},
|
||||||
|
setDrawer(state, payload) {
|
||||||
|
state.drawer = payload;
|
||||||
|
},
|
||||||
|
setEmail(state, data) {
|
||||||
|
state.email = data;
|
||||||
|
},
|
||||||
|
setPassword(state, data) {
|
||||||
|
state.password = data;
|
||||||
|
},
|
||||||
|
setDialogSuccess(state, data) {
|
||||||
|
state.dialog_success = data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
increment({ commit }) {
|
||||||
|
commit('increment');
|
||||||
|
},
|
||||||
|
decrement({ commit }) {
|
||||||
|
commit('decrement');
|
||||||
|
},
|
||||||
|
async loginState({ state, commit }) {
|
||||||
|
const params = {
|
||||||
|
email: state.email,
|
||||||
|
password: state.pasword
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post(URL + '/login', params);
|
||||||
|
commit('setData', response.data);
|
||||||
|
} catch (error) {
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user