103 lines
3.4 KiB
JavaScript
103 lines
3.4 KiB
JavaScript
|
|
const URL = "../json/jsonformatter.json";
|
|
const URLBread = "../json/breadcumb.json";
|
|
const store = {
|
|
namespaced: true,
|
|
state() {
|
|
return {
|
|
menu_level_0: [],
|
|
menu_level_1: [],
|
|
menu_level_2: [],
|
|
quick_menu: [],
|
|
active_menu: {},
|
|
drawer: false,
|
|
bread_crumb: "",
|
|
search_error_message: "",
|
|
branch: {},
|
|
is_page_allowed: true,
|
|
dashboard: ""
|
|
};
|
|
},
|
|
mutations: {
|
|
update_menu_level_0(state, data) {
|
|
state.menu_level_0 = data
|
|
},
|
|
update_bread_crumb(state, val) {
|
|
state.bread_crumb = val
|
|
},
|
|
update_menu_level_1(state, data) {
|
|
state.menu_level_1 = data
|
|
},
|
|
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;
|
|
},
|
|
update_quick_menu(state, data) {
|
|
state.quick_menu = data;
|
|
},
|
|
update_active_menu(state, data) {
|
|
state.active_menu = data;
|
|
}
|
|
},
|
|
actions: {
|
|
async loadMenuData(context) {
|
|
try {
|
|
let resp = await axios.get(URL);
|
|
|
|
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", "")
|
|
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) {
|
|
console.error('Error loading menu data:', error);
|
|
}
|
|
},
|
|
async loadQuickMenu(context) {
|
|
try {
|
|
let resp = await axios.get(URL);
|
|
if (resp.data.status != "OK") {
|
|
console.error('get api failed');
|
|
} else {
|
|
let item = resp.data.data;
|
|
if (item[1])
|
|
context.commit("update_quick_menu", item[1]['p_1'])
|
|
}
|
|
} catch (error) {
|
|
console.error('Error load quick menu data', error);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
export default store |