mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
Initial commit.
This commit is contained in:
21
client/src/store/index.js
Normal file
21
client/src/store/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import vuexI18n from 'vuex-i18n';
|
||||
import sidebar from '@/store/modules/sidebar';
|
||||
import app from '@/store/modules/app';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
sidebar,
|
||||
},
|
||||
strict: debug,
|
||||
});
|
||||
|
||||
Vue.use(vuexI18n.plugin, store);
|
||||
|
||||
export default store;
|
||||
26
client/src/store/modules/app.js
Normal file
26
client/src/store/modules/app.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
const state = {
|
||||
appName: 'Ratteb',
|
||||
appVersion: '1.0.0',
|
||||
appBuild: '1000',
|
||||
|
||||
pageTitle: 'Welcome',
|
||||
actions: [],
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getAppName: s => s.appName,
|
||||
getAppVersion: s => s.appVersion,
|
||||
getAppBuild: s => s.appBuild,
|
||||
getPageTitle: s => s.pageTitle,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
|
||||
setPageTitle(s, title) {
|
||||
s.title = title;
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, actions, getters };
|
||||
58
client/src/store/modules/auth.js
Normal file
58
client/src/store/modules/auth.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import ApiService from '~/plugins/api-service';
|
||||
|
||||
let state = {
|
||||
token: localStorage.getItem('token') || '',
|
||||
errors: {},
|
||||
role: {}
|
||||
};
|
||||
|
||||
const getters = {
|
||||
authCheck: s => s.token,
|
||||
authToken: s => s.token,
|
||||
authorizedUserRole: s => s.role,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* User login authentication request.
|
||||
*/
|
||||
async authRequest({ commit }, { form }) {
|
||||
const response = await ApiService.post('auth/login', form);
|
||||
const { data } = response;
|
||||
|
||||
if (data.token) {
|
||||
commit('setToken', data.token);
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Send reset password email or SMS.
|
||||
*/
|
||||
sendResetPassword({}, { email }) {
|
||||
return ApiService.post('auth/send_reset_password', { email });
|
||||
},
|
||||
|
||||
/**
|
||||
* Verify reset password verification code.
|
||||
*/
|
||||
verifyResetPasswordToken({ commit, dispatch }, { token }) {
|
||||
return ApiService.post(`reset/${token}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const mutations = {
|
||||
|
||||
setToken(state, token) {
|
||||
localStorage.setItem('token', token);
|
||||
state.token = token;
|
||||
},
|
||||
|
||||
removeToken(state) {
|
||||
localStorage.removeItem('token');
|
||||
state.token = '';
|
||||
},
|
||||
};
|
||||
|
||||
export default {state, actions, mutations, getters};
|
||||
48
client/src/store/modules/sidebar.js
Normal file
48
client/src/store/modules/sidebar.js
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
const state = {
|
||||
items: [
|
||||
{
|
||||
name: 'Home',
|
||||
to: 'dashboard.home',
|
||||
icon: 'home',
|
||||
count: null,
|
||||
},
|
||||
{
|
||||
name: 'Products',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
{
|
||||
name: 'Customers',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
{
|
||||
name: 'Suppliers',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
{
|
||||
name: 'Reports',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getSidebarItems: s => s.items,
|
||||
getSidebarItem: s => name => s.items.find(item => item.name === name),
|
||||
};
|
||||
|
||||
const actions = {
|
||||
|
||||
/**
|
||||
* Set count to the given sidebar item.
|
||||
*/
|
||||
setSidebarItemCount(s, { name, count }) {
|
||||
s.items.forEach((item) => {
|
||||
if (item.name === name) {
|
||||
item.count = count;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default { state, getters, actions };
|
||||
Reference in New Issue
Block a user