diff --git a/.env.development b/.env.development index de583d0..0b34745 100644 --- a/.env.development +++ b/.env.development @@ -2,4 +2,5 @@ ENV = 'development' # base api -VUE_APP_BASE_API = '/dev-api' +#VUE_APP_BASE_API = '/dev-api' +VUE_APP_BASE_API = 'https://id.ssjlai.com/gateway/core' diff --git a/.env.production b/.env.production index 80c8103..0b6c033 100644 --- a/.env.production +++ b/.env.production @@ -1,6 +1,6 @@ # just a flag ENV = 'production' -# base api -VUE_APP_BASE_API = '/prod-api' +#VUE_APP_BASE_API = '/dev-api' +VUE_APP_BASE_API = 'https://ai.ssjlai.com/gateway/core' diff --git a/.env.test b/.env.test index 7586884..9c2e43b 100644 --- a/.env.test +++ b/.env.test @@ -4,5 +4,6 @@ NODE_ENV = production ENV = 'test' # base api -VUE_APP_BASE_API = '/stage-api' +#VUE_APP_BASE_API = '/dev-api' +VUE_APP_BASE_API = 'https://id.ssjlai.com/gateway/core' diff --git a/README.md b/README.md index a868564..f443f1e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ @@ -38,4 +38,11 @@ FEATURE - 取消 右键标签刷新操作 - 修改 右键标签为中文 - 增加 标签刷新 -- 修复 刷新错误的问题 \ No newline at end of file +- 修复 刷新错误的问题 + + +## v1.0.4F +`2021年12月6日` +FEATURE +- 增加 封装接口地址 +- 修改 登录账号密码 telpo telpo#1234 \ No newline at end of file diff --git a/src/api/off-limits-manage.js b/src/api/off-limits-manage.js new file mode 100644 index 0000000..93db29c --- /dev/null +++ b/src/api/off-limits-manage.js @@ -0,0 +1,22 @@ +/* + * @Date: 2021-12-06 17:31:43 + * @LastEditors: JinxuChen + * @LastEditTime: 2021-12-06 18:07:02 + * @FilePath: \GpsCardAdmin\src\api\off-limits-manage.js + * @description: 封装告警识别内容接口 + */ +import request from '@/utils/request' +export const APILimits = { + getRecognition +}; +export default APILimits; + + +// 自动报警通用关键词查询 +function getRecognition(params) { + return request({ + url: '/api/v1/Fence/AreaGeneralFilterQuery', + method: 'post', + data: params, + }); +} \ No newline at end of file diff --git a/src/api/user.js b/src/api/user.js index 8ff4389..7a06c2c 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -1,18 +1,26 @@ +/* + * @Date: 2021-11-30 15:35:16 + * @LastEditors: JinxuChen + * @LastEditTime: 2021-12-06 17:23:57 + * @FilePath: \GpsCardAdmin\src\api\user.js + * @description: + */ import request from '@/utils/request' -export function login(data) { +const baseUrl = process.env.VUE_APP_BASE_API.replace('core', 'auth'); +export function login(params) { return request({ - url: '/vue-admin-template/user/login', + url: `${baseUrl}/identityController/login`, method: 'post', - data + data: params }) } -export function getInfo(token) { +export function getInfo(params) { return request({ - url: '/vue-admin-template/user/info', - method: 'get', - params: { token } + url: '/api/v1/Ability/study_ai/terminal/auth', + method: 'post', + data: params }) } diff --git a/src/assets/telpo.png b/src/assets/telpo.png new file mode 100644 index 0000000..ed759ac Binary files /dev/null and b/src/assets/telpo.png differ diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index c28b843..aae9253 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -7,13 +7,15 @@ /> -
- 当前用户:{{currentUser}} + +
+ 当前用户:{{name}}
- + +
@@ -36,18 +38,20 @@ import { mapGetters } from "vuex"; import Breadcrumb from "@/components/Breadcrumb"; import Hamburger from "@/components/Hamburger"; - +import { getToken, setToken, removeToken } from '@/utils/auth'; +import { resetRouter } from '@/router' export default { components: { Breadcrumb, Hamburger }, computed: { - ...mapGetters(["sidebar", "avatar"]) + ...mapGetters(["sidebar", "avatar", "name"]) }, data() { return { - currentUser: this.$store.getters.name + /* currentUser: this.$store.getters.name, */ + avatarImg: require('../../assets/telpo.png') } }, methods: { @@ -55,7 +59,9 @@ export default { this.$store.dispatch("app/toggleSideBar"); }, async logout() { - await this.$store.dispatch("user/logout"); + /* await this.$store.dispatch("user/logout"); */ + removeToken() // must remove token first + resetRouter() this.$router.push(`/login?redirect=${this.$route.fullPath}`); } } diff --git a/src/permission.js b/src/permission.js index fa1ea19..75e5eb6 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,3 +1,10 @@ +/* + * @Date: 2021-11-30 15:34:49 + * @LastEditors: JinxuChen + * @LastEditTime: 2021-12-06 18:06:34 + * @FilePath: \GpsCardAdmin\src\permission.js + * @description: + */ import router from './router' import store from './store' import { Message } from 'element-ui' @@ -32,8 +39,7 @@ router.beforeEach(async(to, from, next) => { } else { try { // get user info - await store.dispatch('user/getInfo') - + /* await store.dispatch('user/getInfo'); */ next() } catch (error) { // remove token and go to login page to re-login diff --git a/src/store/getters.js b/src/store/getters.js index aa9203f..9b52ad6 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,9 +1,17 @@ +/* + * @Date: 2021-11-30 15:35:16 + * @LastEditors: JinxuChen + * @LastEditTime: 2021-12-06 16:07:16 + * @FilePath: \GpsCardAdmin\src\store\getters.js + * @description: + */ const getters = { sidebar: state => state.app.sidebar, device: state => state.app.device, visitedViews: state => state.tagsView.visitedViews, cachedViews: state => state.tagsView.cachedViews, token: state => state.user.token, + authToken: state => state.user.authToken, avatar: state => state.user.avatar, name: state => state.user.name, roles: state => state.user.roles, diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 2f6423f..28abfb7 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,10 +1,13 @@ -import { login, logout, getInfo } from '@/api/user' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { login, logout, getInfo } from '@/api/user'; +import { getToken, setToken, removeToken } from '@/utils/auth'; +import { getAuthToken, setAuthToken, removeAuthToken } from '@/utils/auth-token'; +import APPId from '@/utils/appId' import { resetRouter } from '@/router' const getDefaultState = () => { return { token: getToken(), + authToken: getAuthToken(), name: '', avatar: '' } @@ -19,44 +22,51 @@ const mutations = { SET_TOKEN: (state, token) => { state.token = token }, + SET_AUTH_TOKEN: (state, authToken) => { + state.authToken = authToken + }, SET_NAME: (state, name) => { state.name = name }, SET_AVATAR: (state, avatar) => { state.avatar = avatar + }, + SET_ROLES: (state, roles) => { + state.roles = roles } } const actions = { // user login login({ commit }, userInfo) { - const { username, password } = userInfo + const { loginName, password } = userInfo return new Promise((resolve, reject) => { - login({ username: username.trim(), password: password }).then(response => { - const { data } = response - commit('SET_TOKEN', data.token) - setToken(data.token) - resolve() + login({ loginName: loginName.trim(), password: password, appId: APPId }).then(response => { + console.log("response", response); + const { data } = response; + commit('SET_TOKEN', data.authToken); + setToken(data.authToken) + resolve(data) }).catch(error => { reject(error) }) }) }, - // get user info - getInfo({ commit, state }) { + getInfo({ commit}) { return new Promise((resolve, reject) => { - getInfo(state.token).then(response => { - const { data } = response - + let manufactorId = '5bf13062-a41e-4d00-ba14-1101aad12650' + getInfo({manufactorId: manufactorId}).then(response => { + const { data } = response; + /* data['roles'] = ['admin'] */ if (!data) { - return reject('Verification failed, please Login again.') + return reject('验证过期,请重新登录!') } - - const { name, avatar } = data - - commit('SET_NAME', name) - commit('SET_AVATAR', avatar) + /* const { roles, name} = data + commit('SET_ROLES', roles) + commit('SET_NAME', name) */ + commit('SET_AUTH_TOKEN', data); + setAuthToken(data); resolve(data) }).catch(error => { reject(error) @@ -79,13 +89,13 @@ const actions = { }, // remove token - resetToken({ commit }) { + resetToken({ commit, state }) { return new Promise(resolve => { removeToken() // must remove token first commit('RESET_STATE') resolve() }) - } + }, } export default { diff --git a/src/utils/appId.js b/src/utils/appId.js new file mode 100644 index 0000000..b536af3 --- /dev/null +++ b/src/utils/appId.js @@ -0,0 +1,7 @@ +const APPID = process.env.NODE_ENV === 'production' + ? + '0e2654a6-b323-4147-aa92-43ec1b092694' /* pro 生产环境 appid */ + : + // 'fe76405a-4b2c-4403-bef8-91728f23ef0c'; /* dev 开发环境 appid */ + '0e2654a6-b323-4147-aa92-43ec1b092694'; /* 开发环境使用正式环境的 appid 方便调试 */ +export default APPID; \ No newline at end of file diff --git a/src/utils/auth-token.js b/src/utils/auth-token.js new file mode 100644 index 0000000..1f1d259 --- /dev/null +++ b/src/utils/auth-token.js @@ -0,0 +1,22 @@ +/* + * @Date: 2021-11-30 15:34:34 + * @LastEditors: JinxuChen + * @LastEditTime: 2021-12-06 16:10:40 + * @FilePath: \GpsCardAdmin\src\utils\auth-token.js + * @description: + */ +import Cookies from 'js-cookie' + +const TokenKey = 'authtoken' + +export function getAuthToken() { + return Cookies.get(TokenKey) +} + +export function setAuthToken(token) { + return Cookies.set(TokenKey, token) +} + +export function removeAuthToken() { + return Cookies.remove(TokenKey) +} diff --git a/src/utils/auth.js b/src/utils/auth.js index 059af18..eadc9df 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -1,6 +1,13 @@ +/* + * @Date: 2021-11-30 15:34:34 + * @LastEditors: JinxuChen + * @LastEditTime: 2021-12-06 14:32:08 + * @FilePath: \GpsCardAdmin\src\utils\auth.js + * @description: + */ import Cookies from 'js-cookie' -const TokenKey = 'vue_admin_template_token' +const TokenKey = 'token' export function getToken() { return Cookies.get(TokenKey) diff --git a/src/utils/request.js b/src/utils/request.js index 2fb95ac..bbc37c5 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -7,7 +7,7 @@ import { getToken } from '@/utils/auth' const service = axios.create({ baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url // withCredentials: true, // send cookies when cross-domain requests - timeout: 5000 // request timeout + /* timeout: 5000 */// request timeout }) // request interceptor @@ -19,7 +19,7 @@ service.interceptors.request.use( // let each request carry token // ['X-Token'] is a custom headers key // please modify it according to the actual situation - config.headers['X-Token'] = getToken() + config.headers['AuthToken'] = store.getters.token; } return config }, @@ -46,7 +46,7 @@ service.interceptors.response.use( const res = response.data // if the custom code is not 20000, it is judged as an error. - if (res.code !== 20000) { + if (res.code !== 0) { Message({ message: res.message || 'Error', type: 'error', diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 387d813..ab8086b 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -1,7 +1,7 @@ @@ -20,6 +20,9 @@ export default { ...mapGetters([ 'name' ]) + }, + mounted() { + console.log(this.$store.getters.name); } } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 1db2464..f19dd3e 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -3,7 +3,7 @@