feat: change names with change category from server

pull/1/head
Saeid 5 years ago
parent a87839bd30
commit 14e74e1c65

@ -1,6 +1,7 @@
import { TokenService, PermissionService, UserService } from "@Global/services/storage.services"; import { TokenService, PermissionService, UserService, CategoryNameService } from "@Global/services/storage.services";
import ApiService from "@Global/services/api.services"; import ApiService from "@Global/services/api.services";
import store from "@Core/store/index"; import store from "@Core/store/index";
import Globalstore from "@Global/store/index";
ApiService.init(); ApiService.init();
// If token exists set Authorizion header // If token exists set Authorizion header
if (TokenService.getToken()) { if (TokenService.getToken()) {
@ -17,4 +18,10 @@ if (UserService.get()) {
store.commit('auth/SET_AUTH_USER', UserService.get()) store.commit('auth/SET_AUTH_USER', UserService.get())
} }
if (CategoryNameService.get()) {
Globalstore.commit('common/SET_CATEGORY_NAME', CategoryNameService.get())
} else {
Globalstore.dispatch('common/loadCategoryName');
}
import '@Global/services/errorHandler.services' import '@Global/services/errorHandler.services'

@ -2,6 +2,7 @@ import qs from 'qs';
const TOKEN_KEY = 'access_token' const TOKEN_KEY = 'access_token'
const USER = 'user' const USER = 'user'
const CATEGORYNAME = 'category_name'
const PERMISSION = 'permission' const PERMISSION = 'permission'
const VIRTUALACTIVITY = 'virtual_activity' const VIRTUALACTIVITY = 'virtual_activity'
/** /**
@ -23,6 +24,23 @@ const TokenService = {
localStorage.removeItem(TOKEN_KEY) localStorage.removeItem(TOKEN_KEY)
}, },
} }
const CategoryNameService = {
get() {
if (localStorage.getItem(CATEGORYNAME)) {
return qs.parse(localStorage.getItem(CATEGORYNAME))
}
return null;
},
save(category_name = null) {
category_name = qs.stringify(category_name);
localStorage.setItem(CATEGORYNAME, category_name)
},
remove() {
localStorage.removeItem(CATEGORYNAME)
},
}
const UserService = { const UserService = {
get() { get() {
@ -77,4 +95,4 @@ const VirtualActivityService = {
}, },
} }
export { TokenService, UserService, PermissionService, VirtualActivityService } export { TokenService, UserService, PermissionService, VirtualActivityService, CategoryNameService }

@ -1,4 +1,8 @@
import { getTime } from "@Global/utils/date/time"; import { getTime } from "@Global/utils/date/time";
import { CategoryNameService } from "@Global/services/storage.services";
// import { url } from "@Auth/mixins/urls";
import axios from "axios";
export default { export default {
setCurrentTime:({ commit }) => { setCurrentTime:({ commit }) => {
commit('SET_CURRENT_TIME', getTime()); commit('SET_CURRENT_TIME', getTime());
@ -6,4 +10,16 @@ export default {
commit('SET_CURRENT_TIME', getTime()); commit('SET_CURRENT_TIME', getTime());
}, 2000); }, 2000);
}, },
async loadCategoryName({ commit }) {
try {
const response = await axios.get("/api/config");
if (response && response.status == 200) {
CategoryNameService.save(response.data);
commit("SET_CATEGORY_NAME", response.data);
return response;
}
} catch (e) {
return false;
}
},
} }

@ -2,4 +2,5 @@ export default {
getCurrentModule: state => state.current_module, getCurrentModule: state => state.current_module,
getCurrentModuleInfo: state => state.current_module_info, getCurrentModuleInfo: state => state.current_module_info,
getCurrentTime: state => state.time_now, getCurrentTime: state => state.time_now,
getCategoryName: state => state.category_name,
} }

@ -8,4 +8,7 @@ export default {
SET_CURRENT_TIME(state, currentTime) { SET_CURRENT_TIME(state, currentTime) {
state.time_now = currentTime; state.time_now = currentTime;
}, },
SET_CATEGORY_NAME(state, category_name) {
state.category_name = category_name;
},
}; };

@ -1,6 +1,7 @@
export default { export default {
time_now: "", time_now: "",
current_module: "", current_module: "",
category_name: {modules: {}},
current_module_info: { current_module_info: {
name: "" name: ""
} }

@ -1,9 +1,9 @@
import Name from './index'; import Name from './index';
import GlobalState from "@Global/store/modules/common/state";
// $_name in text replace // $_name in text replace
export default (path, text = '$_name') => { export default (path, text = '$_name') => {
let arrayPath = path.split('.'); let arrayPath = path.split('.');
//should be get from storage let name = GlobalState.category_name.modules;
let name = Name.modules;
for (const component of arrayPath) { for (const component of arrayPath) {
if (name[component]) { if (name[component]) {

Loading…
Cancel
Save