Skip to content

Commit 8bf6b70

Browse files
author
oguzhan.onder
committed
Fetching menus from server
1 parent f6752f1 commit 8bf6b70

File tree

6 files changed

+87
-49
lines changed

6 files changed

+87
-49
lines changed

src/containers/menus.js

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
1+
import store from '../store/store';
2+
13
export default [
24
{
35
_name: 'CSidebarNav',
4-
_children: [
5-
{
6-
_name: 'CSidebarNavItem',
7-
name: 'Dashboard',
8-
to: '/dashboard',
9-
icon: 'cil-speedometer'
10-
},
11-
{
12-
_name: 'CSidebarNavDropdown',
13-
name: 'Ürün Yönetimi',
14-
icon: 'cil-puzzle',
15-
route: '/product',
16-
items: [
17-
/* {
18-
name: 'Ürün Listesi',
19-
to: '/product/productList'
20-
},*/
21-
{
22-
name: 'Ürün Listesi',
23-
to: '/product/purchase'
24-
},
25-
{
26-
name: 'Ürün Çıkışı',
27-
to: '/product/sell'
28-
},
29-
]
30-
},
6+
_children: store.getters.getShowMenus
317

32-
]
338
}
349
]

src/store/actions.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ export const registerConfirm = (vueContext, param) => {
3939
export const getUserAndMenus = (vueContext) => {
4040
return util.service.get("user/menus")
4141
.then(response => {
42-
console.log(response);
42+
if (response) {
43+
vueContext.commit("setUser", response.data);
44+
vueContext.commit("setShowMenus", response.data.menus);
45+
util.common.control(response);
46+
}
47+
48+
}).catch(error => {
49+
util.common.control(error);
4350
})
4451
}
4552

src/store/getters.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
export const getTradeResult = (state) => {
2-
return {
3-
purchase: state.purchase,
4-
sale : state.sale,
5-
balance : state.balance
6-
}
2+
return {
3+
purchase: state.purchase,
4+
sale: state.sale,
5+
balance: state.balance
6+
}
77
};
88

9-
export const getIsLogin = (state) =>{
9+
export const getIsLogin = (state) => {
1010
return state.isLogin;
11-
}
11+
};
1212

13-
export const getIsLoading = (state) =>{
13+
export const getIsLoading = (state) => {
1414
return state.isLoading;
15-
}
15+
};
1616

17-
export const getMyToast = (state)=>{
17+
export const getMyToast = (state) => {
1818
return state.myToast;
19+
};
20+
21+
export const getUser = (state) => {
22+
return state.user;
23+
};
24+
25+
export const getShowMenus = (state) => {
26+
return state.showMenus;
1927
}

src/store/mutations.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as util from '../util/util';
2+
13
export const updateTradeResult = (state, trade) => {
24
state.count = trade.count;
35
state.sale = trade.sale;
@@ -31,3 +33,12 @@ export const set = (state, [variable, value]) => {
3133
state[variable] = value
3234
};
3335

36+
export const setUser = (state, value) => {
37+
state.user = value;
38+
};
39+
40+
export const setShowMenus = (state,values) =>{
41+
let menus = util.common.prepareMenus(values);
42+
state.showMenus = menus;
43+
};
44+

src/store/store.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@ import * as actions from './actions';
77

88
Vue.use(Vuex);
99

10-
const store = new Vuex.Store({
10+
const store = new Vuex.Store({
1111
state: {
1212
purchase: 0.0,
1313
sale: 0.0,
1414
balance: 0.0,
15-
isLogin : null,
16-
isLoading : false,
17-
user : null,
15+
isLogin: null,
16+
isLoading: false,
17+
user: null,
18+
showMenus: [],
1819
sidebarShow: 'responsive',
1920
sidebarMinimize: false,
20-
myToast : {
21-
message : "",
22-
icon : "",
23-
type : "",
21+
myToast: {
22+
message: "",
23+
icon: "",
24+
type: "",
2425
header: "Bilgi Mesajı",
25-
show : false
26+
show: false
2627
}
2728
},
2829
getters: getters,
@@ -33,5 +34,5 @@ Vue.use(Vuex);
3334
}
3435
});
3536

36-
export default store;
37+
export default store;
3738

src/util/util.js

+36
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,43 @@ export const common = {
115115
toast.icon = toastIcon.WARNING;
116116
}
117117
return toast;
118+
},
119+
prepareMenus(values) {
120+
let menus = [];
121+
let children = [];
122+
let val;
123+
let child;
124+
if (values) {
125+
for (val in values) {
126+
let menu = {};
127+
if (values[val].code === "dashboard") {
128+
menu._name = "CSidebarNavItem"
129+
} else {
130+
menu._name = "CSidebarNavDropdown"
131+
}
132+
menu.name = values[val].name;
133+
menu.icon = values[val].icon;
134+
menu.to = values[val].path;
135+
menu.orderItem = values[val].orderItem;
136+
if (values[val].children.length > 0) {
137+
for (child in values[val].children) {
138+
let childMenu = {};
139+
childMenu.name = values[val].children[child].name;
140+
childMenu.to = values[val].children[child].path;
141+
childMenu.orderItem = values[val].children[child].orderItem;
142+
childMenu.code = values[val].children[child].code;
143+
childMenu.icon = values[val].children[child].icon;
144+
children.push(childMenu);
145+
}
146+
menu.items = children;
147+
}
148+
menus.push(menu);
149+
}
150+
}
151+
return menus;
118152
}
153+
154+
119155
};
120156

121157
export const randomCode = function (data) {

0 commit comments

Comments
 (0)