diff --git a/package.json b/package.json index 2a8048e..11b96ef 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "ant-design-vue": "^1.7.0", + "axios": "^0.21.0", "core-js": "^3.6.5", "vue": "^2.6.11", "vue-router": "^3.4.8", diff --git a/src/assets/back.png b/src/assets/back.png new file mode 100644 index 0000000..e8db818 Binary files /dev/null and b/src/assets/back.png differ diff --git a/src/assets/login-img.png b/src/assets/login-img.png new file mode 100644 index 0000000..5c70852 Binary files /dev/null and b/src/assets/login-img.png differ diff --git a/src/assets/login-img3.png b/src/assets/login-img3.png new file mode 100644 index 0000000..ee46fcc Binary files /dev/null and b/src/assets/login-img3.png differ diff --git a/src/assets/login-logo.png b/src/assets/login-logo.png new file mode 100644 index 0000000..e40e842 Binary files /dev/null and b/src/assets/login-logo.png differ diff --git a/src/assets/login-portrait.png b/src/assets/login-portrait.png new file mode 100644 index 0000000..6b8e427 Binary files /dev/null and b/src/assets/login-portrait.png differ diff --git a/src/assets/phone.png b/src/assets/phone.png new file mode 100644 index 0000000..8ce104d Binary files /dev/null and b/src/assets/phone.png differ diff --git a/src/components/Login.vue b/src/components/Login.vue index 17bcab3..a627a1b 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -1,13 +1,196 @@ \ No newline at end of file diff --git a/src/components/admin/Index.vue b/src/components/admin/Index.vue new file mode 100644 index 0000000..17bcab3 --- /dev/null +++ b/src/components/admin/Index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/components/analysis/Index.vue b/src/components/analysis/Index.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/components/logs/Index.vue b/src/components/logs/Index.vue new file mode 100644 index 0000000..17bcab3 --- /dev/null +++ b/src/components/logs/Index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/components/map/Index.vue b/src/components/map/Index.vue new file mode 100644 index 0000000..17bcab3 --- /dev/null +++ b/src/components/map/Index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/components/search/Index.vue b/src/components/search/Index.vue new file mode 100644 index 0000000..17bcab3 --- /dev/null +++ b/src/components/search/Index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/utils/http.js b/src/utils/http.js index e69de29..ae37a73 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -0,0 +1,34 @@ +import axios from "axios"; + +const backendUrl = '/backend/' +const geoServerUrl = '/geoserver/' + +export const instance = axios.create({ + baseURL: backendUrl +}) + +export async function login(username, passwd, uuid, capthe) +{ + let response = await instance.post('auth', { + 'username':username, + 'password':passwd, + 'uuid':uuid, + 'captch':capthe + }) + let data = await response.data + let token = data.access_token + instance.defaults.headers['Authorization'] = "JWT " + token; + + response = await instance.get('current/') + data = await response.data + return data +} + +export function setAuth(auth) { + instance.defaults.headers['Authorization'] = 'JWT ' + auth; +} + +export async function logout() +{ + instance.defaults.headers['Authorization'] = '' +} \ No newline at end of file diff --git a/src/utils/router.js b/src/utils/router.js index d5ddbc5..e8cde89 100644 --- a/src/utils/router.js +++ b/src/utils/router.js @@ -1,6 +1,8 @@ import Vue from 'vue' import Router from 'vue-router' import Index from '@/components/Main' +import Login from '@/components/Login' +import store from './store' Vue.use(Router) @@ -14,11 +16,26 @@ const routes = [ name: 'index', component: Index, meta: { - requireAuth: false + requireAuth: true } + }, + { + path: '/login', + name: 'login', + component: Login } ] +if (sessionStorage.getItem("store")) { + store.replaceState(Object.assign({}, store.state, JSON.parse(sessionStorage.getItem("store")))) + if (store.state.login) { + if (store.state.uinfo) { + setAuth(store.state.uinfo.token); + } + } +} + + const router = new Router({ base: process.env.BASE_URL, routes diff --git a/src/utils/store.js b/src/utils/store.js index 6fb29b1..a648cc6 100644 --- a/src/utils/store.js +++ b/src/utils/store.js @@ -3,10 +3,103 @@ import Vuex from 'vuex' Vue.use(Vuex) +const storeToSession = store => { + // 当 store 初始化后调用 + store.subscribe((mutation, state) => { + if (sessionStorage.getItem('store')){ + sessionStorage.removeItem('store') + } + console.log(store) + sessionStorage.setItem('store', JSON.stringify(state)) + }) +} + const store = new Vuex.Store({ state: { - - } + userInfo:null, + phone: document.body.clientWidth < 800, + login:false, + loginTime:0, + second: 60 * 60 * 2, + logs:'', + data:{}, + currentComp: 'map', + cacheData:{} + }, + mutations: { + phone(state, o) { + state.phone = o; + }, + login(state, o) { + state.userInfo = o + state.login = true + state.loginTime = new Date().getTime() + }, + logout(state) + { + state.userInfo=null + state.login = false + }, + }, + getters: { + phone(state) { + return state.phone; + }, + isLogin(state) { + if (state.login && state.userInfo !== null ) + { + if ((new Date().getTime() - state.loginTime) < state.second * 1000 ) + { + return true + } + } + return false + }, + isSuper(state, getters) { + if(getters.isLogin) + { + if(state.userInfo.permission == 0xfff) + { + return true + } + } + return false + }, + isProject(state, getters) + { + if(getters.isLogin) + { + if(state.userInfo.permission == 0x0ff) + { + return true + } + } + return false + }, + isAnayone(state, getters) + { + if(getters.isLogin) + { + if(state.userInfo.permission == 0x000) + { + return true + } + } + return false + }, + isNormal(state, getters) + { + if(getters.isLogin) + { + if(state.userInfo.permission == 0x00f) + { + return true + } + } + return false + } + }, + plugins: [storeToSession] }) export default store \ No newline at end of file diff --git a/vue.config.js b/vue.config.js index b316a0d..2486ae5 100644 --- a/vue.config.js +++ b/vue.config.js @@ -10,7 +10,7 @@ module.exports = { proxy: { '/backend': { // target: 'http://223.75.53.208:8081', - target: 'http://127.0.0.1:8000', + target: 'http://127.0.0.1:7788', } } },