Browse Source

- 增加 封装接口地址

- 修改 登录账号密码 telpo telpo#1234
master
2183691628 3 years ago
parent
commit
a731f54ec0
18 changed files with 188 additions and 61 deletions
  1. +2
    -1
      .env.development
  2. +2
    -2
      .env.production
  3. +2
    -1
      .env.test
  4. +9
    -2
      README.md
  5. +22
    -0
      src/api/off-limits-manage.js
  6. +15
    -7
      src/api/user.js
  7. BIN
      src/assets/telpo.png
  8. +13
    -7
      src/layout/components/Navbar.vue
  9. +8
    -2
      src/permission.js
  10. +8
    -0
      src/store/getters.js
  11. +31
    -21
      src/store/modules/user.js
  12. +7
    -0
      src/utils/appId.js
  13. +22
    -0
      src/utils/auth-token.js
  14. +8
    -1
      src/utils/auth.js
  15. +3
    -3
      src/utils/request.js
  16. +4
    -1
      src/views/dashboard/index.vue
  17. +14
    -11
      src/views/login/index.vue
  18. +18
    -2
      src/views/off-limits-manage/alarm-recognition/index.vue

+ 2
- 1
.env.development View File

@@ -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'

+ 2
- 2
.env.production View File

@@ -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'


+ 2
- 1
.env.test View File

@@ -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'


+ 9
- 2
README.md View File

@@ -1,7 +1,7 @@
<!--
* @Date: 2021-11-29 11:14:13
* @LastEditors: JinxuChen
* @LastEditTime: 2021-12-03 17:11:59
* @LastEditTime: 2021-12-06 18:13:14
* @FilePath: \GpsCardAdmin\README.md
* @description:
-->
@@ -38,4 +38,11 @@ FEATURE
- 取消 右键标签刷新操作
- 修改 右键标签为中文
- 增加 标签刷新
- 修复 刷新错误的问题
- 修复 刷新错误的问题


## v1.0.4F
`2021年12月6日`
FEATURE
- 增加 封装接口地址
- 修改 登录账号密码 telpo telpo#1234

+ 22
- 0
src/api/off-limits-manage.js View File

@@ -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,
});
}

+ 15
- 7
src/api/user.js View File

@@ -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
})
}



BIN
src/assets/telpo.png View File

Before After
Width: 50  |  Height: 50  |  Size: 7.2KB

+ 13
- 7
src/layout/components/Navbar.vue View File

@@ -7,13 +7,15 @@
/>

<breadcrumb class="breadcrumb-container" />
<div class="left-menu">
<span class="current-user">当前用户:{{currentUser}}</span>
<!-- todo 接口暂没有名称 暂时取消显示 -->
<div class="left-menu" v-show="false">
<span class="current-user">当前用户:{{name}}</span>
</div>
<div class="right-menu">
<el-dropdown class="avatar-container" trigger="click">
<div class="avatar-wrapper">
<img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar" />
<!-- <img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar" /> -->
<img :src="avatarImg" />
<i class="el-icon-caret-bottom" />
</div>
<el-dropdown-menu slot="dropdown" class="user-dropdown">
@@ -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}`);
}
}


+ 8
- 2
src/permission.js View File

@@ -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


+ 8
- 0
src/store/getters.js View File

@@ -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,


+ 31
- 21
src/store/modules/user.js View File

@@ -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 {


+ 7
- 0
src/utils/appId.js View File

@@ -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;

+ 22
- 0
src/utils/auth-token.js View File

@@ -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)
}

+ 8
- 1
src/utils/auth.js View File

@@ -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)


+ 3
- 3
src/utils/request.js View File

@@ -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',


+ 4
- 1
src/views/dashboard/index.vue View File

@@ -1,7 +1,7 @@
<!--
* @Date: 2021-11-29 11:20:35
* @LastEditors: JinxuChen
* @LastEditTime: 2021-11-30 14:07:24
* @LastEditTime: 2021-12-06 14:26:50
* @FilePath: \GpsCardAdmin\src\views\dashboard\index.vue
* @description:
-->
@@ -20,6 +20,9 @@ export default {
...mapGetters([
'name'
])
},
mounted() {
console.log(this.$store.getters.name);
}
}
</script>


+ 14
- 11
src/views/login/index.vue View File

@@ -3,7 +3,7 @@
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">

<div class="title-container">
<h3 class="title">Login Form</h3>
<h3 class="title">登录</h3>
</div>

<el-form-item prop="username">
@@ -12,8 +12,8 @@
</span>
<el-input
ref="username"
v-model="loginForm.username"
placeholder="Username"
v-model="loginForm.loginName"
placeholder="用户名"
name="username"
type="text"
tabindex="1"
@@ -30,7 +30,7 @@
ref="password"
v-model="loginForm.password"
:type="passwordType"
placeholder="Password"
placeholder="密码"
name="password"
tabindex="2"
auto-complete="on"
@@ -43,7 +43,7 @@

<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">Login</el-button>

<div class="tips">
<div class="tips" v-show="false">
<span style="margin-right:20px;">username: admin</span>
<span> password: any</span>
</div>
@@ -60,25 +60,25 @@ export default {
data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
callback(new Error('Please enter the correct user name'))
callback(new Error('请输入账号'))
} else {
callback()
}
}
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('The password can not be less than 6 digits'))
callback(new Error('密码长度不能少于6位'))
} else {
callback()
}
}
return {
loginForm: {
username: 'admin',
password: '111111'
loginName: 'telpo',
password: 'telpo#1234'
},
loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
loginName: [{ required: true, trigger: 'blur', validator: validateUsername }],
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
},
loading: false,
@@ -106,10 +106,13 @@ export default {
})
},
handleLogin() {
let _this = this;
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true
this.$store.dispatch('user/login', this.loginForm).then(() => {
this.$store.dispatch('user/login', this.loginForm).then(res => {
console.log("res", res.userName);
_this.$store.dispatch('user/getInfo');
this.$router.push({ path: this.redirect || '/' })
this.loading = false
}).catch(() => {


+ 18
- 2
src/views/off-limits-manage/alarm-recognition/index.vue View File

@@ -1,7 +1,7 @@
<!--
* @Date: 2021-11-30 09:44:24
* @LastEditors: JinxuChen
* @LastEditTime: 2021-12-01 17:33:03
* @LastEditTime: 2021-12-06 18:28:18
* @FilePath: \GpsCardAdmin\src\views\off-limits-manage\alarm-recognition\index.vue
* @description:
-->
@@ -133,6 +133,7 @@ import TopMenu from "@/components/TopMenu";
import TTable from "../../../components/TTable/TTable";
import Pagination from "@/components/Pagination";
import UploadExcelComponent from "@/components/UploadExcel/index.vue";
import APILimits from '@/api/off-limits-manage'
export default {
name: "",
components: { TTable, TopMenu, Pagination, UploadExcelComponent },
@@ -269,7 +270,19 @@ export default {
.catch(() => {});
},
// 获取分页数据
getList() {},
getList() {
let reqBody = {
pageNumber: 1,
begNumber: 20,
categoryId: '',
keyword: '',

}
APILimits.getRecognition(reqBody).then(res => {
console.log("res", res);
/* this.list = res.data; */
});
},
beforeUpload(file) {
const isLt1M = file.size / 1024 / 1024 < 1;

@@ -290,6 +303,9 @@ export default {
});
this.dialogUpload = false;
}
},
mounted() {
this.getList()
}
};
</script>


Loading…
Cancel
Save