Navbar Menu
This commit is contained in:
@@ -1,68 +1,82 @@
|
||||
|
||||
const URL = "/westone-api/v1/system/auth";
|
||||
const URL = "../json/jsonformatter.json";
|
||||
const URLBread = "../json/breadcumb.json";
|
||||
const store = {
|
||||
namespaced: true,
|
||||
state() {
|
||||
return {
|
||||
count: 0,
|
||||
menu_level_0: [],
|
||||
menu_level_1: [],
|
||||
menu_level_2: [],
|
||||
drawer: true,
|
||||
data: null,
|
||||
email: "lashlkdsa",
|
||||
password: null,
|
||||
dialog_success: false
|
||||
bread_crumb: "",
|
||||
search_error_message: "",
|
||||
branch: {},
|
||||
is_page_allowed: true,
|
||||
dashboard: ""
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
increment(state) {
|
||||
state.count++;
|
||||
update_menu_level_0(state, data) {
|
||||
state.menu_level_0 = data
|
||||
},
|
||||
decrement(state) {
|
||||
state.count--;
|
||||
update_bread_crumb(state, val) {
|
||||
state.bread_crumb = val
|
||||
},
|
||||
setData(state, payload) {
|
||||
state.data = payload;
|
||||
update_menu_level_1(state, data) {
|
||||
state.menu_level_1 = data
|
||||
},
|
||||
setDrawer(state, payload) {
|
||||
update_menu_level_2(state, data) {
|
||||
state.menu_level_2 = data
|
||||
},
|
||||
update_branch(state, val) {
|
||||
state.branch = val
|
||||
},
|
||||
update_search_error_message(state, val) {
|
||||
state.search_error_message = val
|
||||
},
|
||||
update_page_allowed(state, val) {
|
||||
state.is_page_allowed = val
|
||||
},
|
||||
update_dashboard(state, val) {
|
||||
state.dashboard = val
|
||||
},
|
||||
update_drawer(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
|
||||
};
|
||||
async loadMenuData(context) {
|
||||
try {
|
||||
let resp = await axios.get(URL);
|
||||
|
||||
try {
|
||||
const response = await axios.post(URL + '/login', params);
|
||||
commit('setData', response.data);
|
||||
if (resp.data.status != "OK") {
|
||||
console.error('Gagal get api:');
|
||||
} else {
|
||||
let x = resp.data.data
|
||||
if (x[0])
|
||||
context.commit("update_menu_level_0", x[0]['p_0'])
|
||||
if (x[1])
|
||||
context.commit("update_menu_level_1", x[1])
|
||||
if (x[2])
|
||||
context.commit("update_menu_level_2", x[2])
|
||||
}
|
||||
// tambahan get bread_crumb
|
||||
resp = await axios.get(URLBread)
|
||||
if (resp.data.status != "OK") {
|
||||
context.commit("update_search_error_message", resp.message)
|
||||
} else {
|
||||
context.commit("update_search_error_message", "")
|
||||
console.log("menu", resp.data.data.bread_crumb)
|
||||
context.commit("update_bread_crumb", resp.data.data.bread_crumb)
|
||||
context.commit("update_branch", resp.data.data.branch)
|
||||
context.commit("update_page_allowed", resp.data.is_page_allowed)
|
||||
context.commit("update_dashboard", resp.data.dashboard)
|
||||
}
|
||||
} catch (error) {
|
||||
commit('setError', error);
|
||||
console.error('Error loading menu data:', 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