第一次发布

This commit is contained in:
caolc
2023-04-18 17:02:02 +08:00
commit dfe2ace2c9
927 changed files with 187479 additions and 0 deletions

56
src/store/getters.js Normal file
View File

@@ -0,0 +1,56 @@
import Cookies from 'js-cookie'
const getters = {
sidebar: state => state.app.sidebar,
size: state => state.app.size,
markData: state => state.global.markData,
device: state => state.app.device,
visitedViews: state => state.tagsView.visitedViews,
cachedViews: state => state.tagsView.cachedViews,
token: state => state.user.token,
avatar: state => state.user.avatar,
name: state => state.user.name,
introduction: state => state.user.introduction,
role: state => state.user.role,
auths: state => state.user.auths,
permission_routes: state => state.permission.routes,
sysUserList: state => state.user.sysUserList,
user: state => state.user.user,
areaTree: state => state.global.areaTree,
networkList: state => state.global.networkList,
departmentList: state => state.global.departmentList,
fleetList: state => state.global.fleetList,
waybillId: state => state.global.waybillId,
plateNumber: state => state.global.plateNumber,
bannerInfoList: state => state.global.bannerInfoList,
trackCss: state => state.global.trackCss,
Link: state => state.global.Link,
helpInfo: state => state.global.helpInfo,
drawerFixed: state => state.global.drawerFixed,
vehicleTypeList: state => state.global.vehicleTypeList,
largeAreaList: state => state.global.largeAreaList,
incomeBankList: state => state.global.incomeBankList,
currentIncomeBank: state => {
let incomeBank = state.global.currentIncomeBank
if (!incomeBank.incomeBankId) {
incomeBank = Cookies.get('currentIncome')
if (incomeBank) {
incomeBank = JSON.parse(incomeBank)
}
}
return incomeBank
},
autoCheckDocument: state => state.status.autoCheckDocument,
uploadToken: state => {
const token = state.global.uploadToken.pop()
return token
},
tokenEncrypt: state => {
const token = state.global.tokenEncrypt.pop()
return token
}
}
export default getters

33
src/store/global.js Normal file
View File

@@ -0,0 +1,33 @@
import areaCodeApi from '@/api/base/areaCode'
const state = {
areaTree: [] // 省市县树
}
const mutations = {
SET_AREA: (state, areaTree) => {
state.areaTree = areaTree
}
}
const actions = {
getAreaTree() {
// 获取地区树
return areaCodeApi.getTree()
},
getAreaTreeNoCounty() {
// 获取地区树
return areaCodeApi.treeListNoCounty()
}
}
export default {
namespaced: true,
state,
actions,
mutations
}

30
src/store/index.js Normal file
View File

@@ -0,0 +1,30 @@
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
const modulesFiles = require.context('./modules', true, /\.js$/)
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
const value = modulesFiles(modulePath)
modules[moduleName] = value.default
return modules
}, {})
const store = new Vuex.Store({
modules,
getters,
plugins: [createPersistedState({
storage: window.localStorage,
reducer(val) {
return {
// 只储存state中的markData
global: val.global
}
}
})]
})
export default store

56
src/store/modules/app.js Normal file
View File

@@ -0,0 +1,56 @@
import Cookies from 'js-cookie'
const state = {
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
withoutAnimation: false
},
device: 'desktop',
size: Cookies.get('size') || 'medium'
}
const mutations = {
TOGGLE_SIDEBAR: state => {
state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false
if (state.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
CLOSE_SIDEBAR: (state, withoutAnimation) => {
Cookies.set('sidebarStatus', 0)
state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation
},
TOGGLE_DEVICE: (state, device) => {
state.device = device
},
SET_SIZE: (state, size) => {
state.size = size
Cookies.set('size', size)
}
}
const actions = {
toggleSideBar({ commit }) {
commit('TOGGLE_SIDEBAR')
},
closeSideBar({ commit }, { withoutAnimation }) {
commit('CLOSE_SIDEBAR', withoutAnimation)
},
toggleDevice({ commit }, device) {
commit('TOGGLE_DEVICE', device)
},
setSize({ commit }, size) {
commit('SET_SIZE', size)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,46 @@
import areaCodeApi from '@/api/base/areaCode'
const state = {
Link: '',
bannerInfoList: [],
trackCss: { random: 0, status: 0 },
areaTree: [], // 省市县树
markData: {}, // 数据字典
drawerFixed: false // 抽屉是否固定
}
const mutations = {
SET_LINK: (state, Link) => {
state.Link = Link
},
SET_bannerInfoList: (state, list) => {
state.bannerInfoList = list
},
SET_AREA: (state, areaTree) => {
state.areaTree = areaTree
},
SET_FIXED: (state, drawerFixed) => {
state.drawerFixed = drawerFixed
},
SET_MARK: (state, markData) => {
state.markData = markData
}
}
const actions = {
getAreaTree() {
// 获取地区树
return areaCodeApi.getTree()
},
getAreaTreeNoCounty() {
// 获取地区树
return areaCodeApi.treeListNoCounty()
}
}
export default {
namespaced: true,
state,
actions,
mutations
}

View File

@@ -0,0 +1,69 @@
import { constantRoutes } from '@/router'
import { getRouters } from '@/api/auth/oilOmsMenu'
import Layout from '@/layout'
/**
* 获取路由
* @param routes asyncRoutes
* @param auths
*/
export function filterAsyncRouter(asyncRouterMap) {
return asyncRouterMap.filter(route => {
if (route.component) {
// Layout组件特殊处理
if (route.component === 'Layout') {
route.component = Layout
} else {
route.component = loadView(route.component)
}
}
if (route.children != null && route.children && route.children.length) {
route.children = filterAsyncRouter(route.children)
}
return true
})
}
const state = {
routes: [],
addRoutes: []
}
const mutations = {
SET_ROUTES: (state, routes) => {
Object.assign(routes[0],{
path: '/',
component: Layout,
redirect: routes[0].children[0].path,
})
console.log(routes,'路由');
console.log(JSON.stringify(routes[0]),'路由');
// routes[0].children[0].path='/SysCustomerInfoList'
state.addRoutes = routes
state.routes = constantRoutes.concat(routes)
}
}
const actions = {
generateRoutes({ commit, dispatch }) {
return new Promise(resolve => {
// 向后端请求路由数据
getRouters().then(res => {
const accessedRoutes = filterAsyncRouter(res.data)
accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
commit('SET_ROUTES', accessedRoutes)
resolve(accessedRoutes)
})
})
}
}
export const loadView = (view) => { // 路由懒加载
return (resolve) => require([`@/views/${view}`], resolve)
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,34 @@
import variables from '@/styles/element-variables.scss'
import defaultSettings from '@/settings'
const { showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings
const state = {
theme: variables.theme,
showSettings: showSettings,
tagsView: tagsView,
fixedHeader: fixedHeader,
sidebarLogo: sidebarLogo
}
const mutations = {
CHANGE_SETTING: (state, { key, value }) => {
if (state.hasOwnProperty(key)) {
state[key] = value
}
}
}
const actions = {
changeSetting({ commit }, data) {
commit('CHANGE_SETTING', data)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,22 @@
import Cookies from 'js-cookie'
const state = {
autoCheckDocument: Cookies.get('autoCheckDocument') === 'true' // 无车承运自动校验
}
const mutations = {
SET_AUTO_CHECK: (state, autoCheckDocument) => {
state.autoCheckDocument = autoCheckDocument
}
}
const actions = {
}
export default {
namespaced: true,
state,
actions,
mutations
}

View File

@@ -0,0 +1,172 @@
const state = {
visitedViews: [],
cachedViews: []
};
const mutations = {
ADD_VISITED_VIEW: (state, view) => {
if (state.visitedViews.some(v => v.path === view.path)) return;
state.visitedViews.push(
Object.assign({}, view, {
title: view.meta.title || "no-name"
})
);
},
ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name)) return;
if (!view.meta.noCache) {
state.cachedViews.push(view.name);
}
},
DEL_VISITED_VIEW: (state, view) => {
for (const [i, v] of state.visitedViews.entries()) {
if (v.path === view.path) {
state.visitedViews.splice(i, 1);
break;
}
}
},
DEL_CACHED_VIEW: (state, view) => {
for (const i of state.cachedViews) {
if (i === view.name) {
const index = state.cachedViews.indexOf(i);
state.cachedViews.splice(index, 1);
break;
}
}
},
DEL_OTHERS_VISITED_VIEWS: (state, view) => {
state.visitedViews = state.visitedViews.filter(v => {
return v.meta.affix || v.path === view.path;
});
},
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
for (const i of state.cachedViews) {
if (i === view.name) {
const index = state.cachedViews.indexOf(i);
state.cachedViews = state.cachedViews.slice(index, index + 1);
break;
}
}
},
DEL_ALL_VISITED_VIEWS: state => {
// keep affix tags
const affixTags = state.visitedViews.filter(tag => tag.meta.affix);
state.visitedViews = affixTags;
},
DEL_ALL_CACHED_VIEWS: state => {
state.cachedViews = [];
},
UPDATE_VISITED_VIEW: (state, view) => {
for (let v of state.visitedViews) {
if (v.path === view.path) {
v = Object.assign(v, view);
break;
}
}
},
CLEAN_VISITED_VIEWS: state => {
state.visitedViews = [];
}
};
const actions = {
cleanVisiter: ({ commit }, view) => {
commit("CLEAN_VISITED_VIEWS");
},
addView({ dispatch }, view) {
dispatch("addVisitedView", view);
dispatch("addCachedView", view);
},
addVisitedView({ commit }, view) {
commit("ADD_VISITED_VIEW", view);
},
addCachedView({ commit }, view) {
commit("ADD_CACHED_VIEW", view);
},
delView({ dispatch, state }, view) {
return new Promise(resolve => {
dispatch("delVisitedView", view);
dispatch("delCachedView", view);
resolve({
visitedViews: [...state.visitedViews],
cachedViews: [...state.cachedViews]
});
});
},
delVisitedView({ commit, state }, view) {
return new Promise(resolve => {
commit("DEL_VISITED_VIEW", view);
resolve([...state.visitedViews]);
});
},
delCachedView({ commit, state }, view) {
return new Promise(resolve => {
commit("DEL_CACHED_VIEW", view);
resolve([...state.cachedViews]);
});
},
delOthersViews({ dispatch, state }, view) {
return new Promise(resolve => {
dispatch("delOthersVisitedViews", view);
dispatch("delOthersCachedViews", view);
resolve({
visitedViews: [...state.visitedViews],
cachedViews: [...state.cachedViews]
});
});
},
delOthersVisitedViews({ commit, state }, view) {
return new Promise(resolve => {
commit("DEL_OTHERS_VISITED_VIEWS", view);
resolve([...state.visitedViews]);
});
},
delOthersCachedViews({ commit, state }, view) {
return new Promise(resolve => {
commit("DEL_OTHERS_CACHED_VIEWS", view);
resolve([...state.cachedViews]);
});
},
delAllViews({ dispatch, state }, view) {
return new Promise(resolve => {
dispatch("delAllVisitedViews", view);
dispatch("delAllCachedViews", view);
resolve({
visitedViews: [...state.visitedViews],
cachedViews: [...state.cachedViews]
});
});
},
delAllVisitedViews({ commit, state }) {
return new Promise(resolve => {
commit("DEL_ALL_VISITED_VIEWS");
resolve([...state.visitedViews]);
});
},
delAllCachedViews({ commit, state }) {
return new Promise(resolve => {
commit("DEL_ALL_CACHED_VIEWS");
resolve([...state.cachedViews]);
});
},
updateVisitedView({ commit }, view) {
commit("UPDATE_VISITED_VIEW", view);
}
};
export default {
namespaced: true,
state,
mutations,
actions
};

156
src/store/modules/user.js Normal file
View File

@@ -0,0 +1,156 @@
import { login, loginSms, logout, getInfo } from "@/api/identity/user";
import websocket from "@/api/websocket/websocket-util";
import {
getToken,
setToken,
removeToken,
setUsername,
setPassword,
setChecked,
removeChecked,
removeUsername,
removePassword
} from "@/utils/auth";
import md5 from "js-md5";
import store from "@/store";
const state = {
token: getToken(),
role: null, // 角色
auths: [], // 权限
user: {} // 存储用户信息
};
const mutations = {
SET_TOKEN: (state, token) => {
state.token = token;
},
SET_ROLE: (state, role) => {
state.role = role;
},
SET_AUTHS: (state, auths) => {
state.auths = auths;
},
SET_USER: (state, user) => {
state.user = user;
}
};
const actions = {
login({ commit }, userInfo) {
const { username, password, checked, verifyCode, networkId } = userInfo;
return new Promise((resolve, reject) => {
let params = {
username: username.trim(),
password: md5(password),
verifyCode
};
networkId && (params.networkId = networkId);
login(params)
.then(res => {
if (res.code === 42014 || res.data.state === 1) {
resolve(res);
return;
}
// 存到vuex
commit("SET_TOKEN", res.data.accessToken);
// 存到cookie
setToken(res.data.accessToken);
// 将账号密码和公司存入cookie中
if (checked) {
setChecked(checked);
setUsername(username.trim());
setPassword(md5(password));
}
resolve();
})
.catch(error => {
reject(error);
});
});
},
loginSms({ commit }, userInfo) {
return new Promise((resolve, reject) => {
loginSms(userInfo)
.then(res => {
// 存到vuex
commit("SET_TOKEN", res.data.accessToken);
// 存到cookie
setToken(res.data.accessToken);
resolve();
})
.catch(error => {
reject(error);
});
});
},
getInfo({ commit }) {
return new Promise((resolve, reject) => {
getInfo()
.then(response => {
const data = response.data;
store.dispatch("user/createWebsocket", data.id);
commit("SET_ROLE", data.role);
commit("SET_AUTHS", data.authList);
commit("SET_USER", data);
resolve(data);
})
.catch(error => {
reject(error);
});
});
},
createWebsocket({ commit }, userId) {
return new Promise((resolve, reject) => {
websocket
.createWebsocket(userId)
.then(response => {
const data = response.data;
resolve(data);
})
.catch(error => {
reject(error.message);
});
});
},
// user logout
logout({ commit }) {
return new Promise((resolve, reject) => {
logout()
.then(() => {
commit("SET_TOKEN", "");
commit("SET_ROLE", null);
commit("SET_AUTHS", []);
store.dispatch("tagsView/cleanVisiter");
removeToken();
removeChecked();
removeUsername();
removePassword();
websocket.closeWebSocket();
resolve();
})
.catch(error => {
reject(error);
});
});
},
resetToken({ commit }) {
return new Promise(resolve => {
commit("SET_TOKEN", "");
commit("SET_ROLE", null);
commit("SET_AUTHS", []);
commit("SET_USER", {});
removeToken();
resolve();
});
}
};
export default {
namespaced: true,
state,
mutations,
actions
};