登录
This commit is contained in:
parent
1172832d9b
commit
66f597f514
@ -3,4 +3,5 @@ NODE_ENV = 'development'
|
|||||||
|
|
||||||
# 开发模式连生产服
|
# 开发模式连生产服
|
||||||
VUE_APP_BASE_API = '/api-prod'
|
VUE_APP_BASE_API = '/api-prod'
|
||||||
VUE_APP_COOKIE = ''
|
VUE_APP_COOKIE = ''
|
||||||
|
VUE_APP_INNER='http://nbxt.oa.x-lf.cn'
|
8
components.d.ts
vendored
8
components.d.ts
vendored
@ -1,9 +1,9 @@
|
|||||||
// generated by unplugin-vue-components
|
// generated by unplugin-vue-components
|
||||||
// We suggest you to commit this file into source control
|
// We suggest you to commit this file into source control
|
||||||
// Read more: https://github.com/vuejs/core/pull/3399
|
// Read more: https://github.com/vuejs/core/pull/3399
|
||||||
import '@vue/runtime-core';
|
import '@vue/runtime-core'
|
||||||
|
|
||||||
export {};
|
export {}
|
||||||
|
|
||||||
declare module '@vue/runtime-core' {
|
declare module '@vue/runtime-core' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
@ -32,13 +32,9 @@ declare module '@vue/runtime-core' {
|
|||||||
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||||
ElOption: typeof import('element-plus/es')['ElOption']
|
ElOption: typeof import('element-plus/es')['ElOption']
|
||||||
ElProgress: typeof import('element-plus/es')['ElProgress']
|
ElProgress: typeof import('element-plus/es')['ElProgress']
|
||||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
|
||||||
ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
|
|
||||||
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
|
||||||
ElRow: typeof import('element-plus/es')['ElRow']
|
ElRow: typeof import('element-plus/es')['ElRow']
|
||||||
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
||||||
ElSelect: typeof import('element-plus/es')['ElSelect']
|
ElSelect: typeof import('element-plus/es')['ElSelect']
|
||||||
ElSlider: typeof import('element-plus/es')['ElSlider']
|
|
||||||
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
|
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
|
||||||
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
||||||
ElTable: typeof import('element-plus/es')['ElTable']
|
ElTable: typeof import('element-plus/es')['ElTable']
|
||||||
|
@ -1,25 +1,39 @@
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
|
||||||
|
|
||||||
|
function getCurrentTimestamp() {
|
||||||
|
return new Date().getTime();
|
||||||
|
}
|
||||||
export function login(data) {
|
export function login(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/vue-element-admin/user/login',
|
url: '/auth/login',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data,
|
||||||
|
headers: {
|
||||||
|
'Timestamp':getCurrentTimestamp()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInfo(token) {
|
export function getInfo(token) {
|
||||||
return request({
|
return request({
|
||||||
url: '/vue-element-admin/user/info',
|
url: '/user/profile/get',
|
||||||
method: 'get',
|
method: 'post',
|
||||||
params: { token }
|
params: {token},
|
||||||
|
headers: {
|
||||||
|
'Timestamp': getCurrentTimestamp()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function logout(token) {
|
export function logout(token) {
|
||||||
return request({
|
return request({
|
||||||
url: '/vue-element-admin/user/logout',
|
url: '/auth/logout',
|
||||||
method: 'post',
|
method: 'get',
|
||||||
params: { token }
|
params: { token },
|
||||||
|
headers: {
|
||||||
|
'Timestamp': getCurrentTimestamp()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
|
|
||||||
// determine whether the user has logged in
|
// determine whether the user has logged in
|
||||||
const hasToken = getToken();
|
const hasToken = getToken();
|
||||||
|
console.log('88888',hasToken)
|
||||||
if (hasToken) {
|
if (hasToken) {
|
||||||
if (to.path === '/login') {
|
if (to.path === '/login') {
|
||||||
// if is logged in, redirect to the home page
|
// if is logged in, redirect to the home page
|
||||||
@ -28,7 +28,9 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
next({ path: '/' });
|
next({ path: '/' });
|
||||||
} else {
|
} else {
|
||||||
// determine whether the user has obtained his permission roles through getInfo
|
// determine whether the user has obtained his permission roles through getInfo
|
||||||
const hasRoles = userStore().roles && userStore().roles.length > 0;
|
// const hasRoles = userStore().roles && userStore().roles.length > 0;
|
||||||
|
const hasRoles = true;
|
||||||
|
|
||||||
// console.log('hasRoles=', hasRoles);
|
// console.log('hasRoles=', hasRoles);
|
||||||
if (hasRoles) {
|
if (hasRoles) {
|
||||||
next();
|
next();
|
||||||
@ -38,6 +40,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
|
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const infoRes = await userStore().getInfo() as any;
|
const infoRes = await userStore().getInfo() as any;
|
||||||
|
console.log('permissionuserinfor:',infoRes)
|
||||||
let roles = [];
|
let roles = [];
|
||||||
if (infoRes.roles) {
|
if (infoRes.roles) {
|
||||||
roles = infoRes.roles;
|
roles = infoRes.roles;
|
||||||
|
@ -60,7 +60,7 @@ export const constantRoutes:RouteRecordRaw[] = [
|
|||||||
path: 'dashboard',
|
path: 'dashboard',
|
||||||
component: () => import('@/views/dashboard/index.vue'),
|
component: () => import('@/views/dashboard/index.vue'),
|
||||||
name: 'Dashboard',
|
name: 'Dashboard',
|
||||||
meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
|
meta: { title: '我管理的', icon: 'dashboard', affix: true }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -121,7 +121,7 @@ export const asyncRoutes:RouteRecordRaw[] = [
|
|||||||
alwaysShow: true, // will always show the root menu
|
alwaysShow: true, // will always show the root menu
|
||||||
title: 'Permission',
|
title: 'Permission',
|
||||||
icon: 'lock',
|
icon: 'lock',
|
||||||
roles: ['admin', 'editor'] // you can set roles in root nav
|
roles: ['admin', 'editor','teacher_user'] // you can set roles in root nav
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@ -130,7 +130,7 @@ export const asyncRoutes:RouteRecordRaw[] = [
|
|||||||
name: 'PagePermission',
|
name: 'PagePermission',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Page Permission',
|
title: 'Page Permission',
|
||||||
roles: ['admin'] // or you can only set roles in sub nav
|
roles: ['admin','teacher_user'] // or you can only set roles in sub nav
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -148,7 +148,7 @@ export const asyncRoutes:RouteRecordRaw[] = [
|
|||||||
name: 'RolePermission',
|
name: 'RolePermission',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Role Permission',
|
title: 'Role Permission',
|
||||||
roles: ['admin']
|
roles: ['admin','teacher']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -56,7 +56,7 @@ export default defineStore({
|
|||||||
},
|
},
|
||||||
generateRoutes(roles: string[]) {
|
generateRoutes(roles: string[]) {
|
||||||
let accessedRoutes;
|
let accessedRoutes;
|
||||||
if (roles.includes('admin')) {
|
if (roles.includes('teacher_user')) {
|
||||||
accessedRoutes = asyncRoutes || [];
|
accessedRoutes = asyncRoutes || [];
|
||||||
} else {
|
} else {
|
||||||
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles);
|
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { login as apiLogin, logout as apiLogout, getInfo as apiGetInfo } from '@/api/user';
|
import {login as apiLogin, logout as apiLogout, getInfo as apiGetInfo, } from '@/api/user';
|
||||||
import { getToken, setToken, removeToken } from '@/utils/auth';
|
import { getToken, setToken, removeToken } from '@/utils/auth';
|
||||||
import router, { resetRouter } from '@/router';
|
import router, { resetRouter } from '@/router';
|
||||||
import tagsViewStore from './tagsView';
|
import tagsViewStore from './tagsView';
|
||||||
@ -16,26 +16,52 @@ export interface IUserState {
|
|||||||
|
|
||||||
export default defineStore({
|
export default defineStore({
|
||||||
id: 'user',
|
id: 'user',
|
||||||
state: ():IUserState => ({
|
state: ():{
|
||||||
|
address: string;
|
||||||
|
signature: string;
|
||||||
|
sex: string;
|
||||||
|
roles: any[];
|
||||||
|
description: string;
|
||||||
|
avatar: string;
|
||||||
|
token: any;
|
||||||
|
phone: string;
|
||||||
|
nickname: string;
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
age: string;
|
||||||
|
username: string
|
||||||
|
} => ({
|
||||||
token: getToken(),
|
token: getToken(),
|
||||||
userId: '',
|
id:'',
|
||||||
name: '',
|
username:'',
|
||||||
avatar: '',
|
address:'',
|
||||||
introduction: '',
|
phone:'',
|
||||||
roles: []
|
email:'',
|
||||||
|
age:'',
|
||||||
|
signature:'',
|
||||||
|
avatar:'',
|
||||||
|
nickname:'',
|
||||||
|
sex:'',
|
||||||
|
description:'',
|
||||||
|
roles:['admin']
|
||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
// user login
|
// user login
|
||||||
|
|
||||||
|
|
||||||
login(userInfo):Promise<void> {
|
login(userInfo):Promise<void> {
|
||||||
const { username, password } = userInfo;
|
const { username, password } = userInfo;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
apiLogin({ username: username.trim(), password: password }).then(response => {
|
apiLogin({ user: username.trim(), password: password }).then(response => {
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
this.token = data.token;
|
this.token = data.token;
|
||||||
setToken(data.token);
|
setToken(data.token);
|
||||||
|
router.push('/')
|
||||||
resolve();
|
resolve();
|
||||||
|
console.log('2222',response)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
console.log('3333',error)
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -46,22 +72,28 @@ export default defineStore({
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
apiGetInfo(this.token).then(response => {
|
apiGetInfo(this.token).then(response => {
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
|
console.log('66666',data)
|
||||||
if (!data) {
|
if (!data) {
|
||||||
reject('Verification failed, please Login again.');
|
reject('Verification failed, please Login again.');
|
||||||
}
|
}
|
||||||
|
const { id,username,address,phone,email,age,signature,avatar,nickname,sex,description,roles } = data;
|
||||||
const { roles, name, avatar, introduction } = data;
|
|
||||||
|
|
||||||
// roles must be a non-empty array
|
// roles must be a non-empty array
|
||||||
if (!roles || roles.length <= 0) {
|
if (!roles || roles.length <= 0) {
|
||||||
reject('getInfo: roles must be a non-null array!');
|
reject('getInfo: roles must be a non-null array!');
|
||||||
}
|
}
|
||||||
|
this.id = id;
|
||||||
this.roles = roles;
|
// this.roles = roles;
|
||||||
this.name = name;
|
// this.roles =['admin'];
|
||||||
|
this.username = username;
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
this.introduction = introduction;
|
this.description = description;
|
||||||
|
this.sex = sex;
|
||||||
|
this.age = age;
|
||||||
|
this.address = address;
|
||||||
|
this.phone = phone;
|
||||||
|
this.email = email;
|
||||||
|
this.signature = signature;
|
||||||
|
this.nickname = nickname;
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -2,11 +2,12 @@ import axios from 'axios';
|
|||||||
import store from '@/store';
|
import store from '@/store';
|
||||||
import { getToken } from '@/utils/auth';
|
import { getToken } from '@/utils/auth';
|
||||||
|
|
||||||
|
const BaseURL ='https://nbxt.oa.x-lf.cn'
|
||||||
// create an axios instance
|
// create an axios instance
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
baseURL: BaseURL, // url = base url + request url
|
||||||
// withCredentials: true, // send cookies when cross-domain requests
|
// withCredentials: true, // send cookies when cross-domain requests
|
||||||
timeout: 5000 // request timeout
|
timeout: 10000 // request timeout
|
||||||
});
|
});
|
||||||
|
|
||||||
// request interceptor
|
// request interceptor
|
||||||
@ -18,7 +19,7 @@ service.interceptors.request.use(
|
|||||||
// let each request carry token
|
// let each request carry token
|
||||||
// ['X-Token'] is a custom headers key
|
// ['X-Token'] is a custom headers key
|
||||||
// please modify it according to the actual situation
|
// please modify it according to the actual situation
|
||||||
config.headers['X-Token'] = getToken();
|
config.headers['token'] = getToken();
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
@ -43,9 +44,9 @@ service.interceptors.response.use(
|
|||||||
*/
|
*/
|
||||||
response => {
|
response => {
|
||||||
const res = response.data;
|
const res = response.data;
|
||||||
|
console.log('999999',res)
|
||||||
// if the custom code is not 20000, it is judged as an error.
|
// if the custom code is not 20000, it is judged as an error.
|
||||||
if (res.code !== 20000) {
|
if (res.code !== 20000 && res.code !== 200) {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: res.message || 'Error',
|
message: res.message || 'Error',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
|
@ -15,7 +15,7 @@ export function isExternal(path) {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
export function validUsername(str) {
|
export function validUsername(str) {
|
||||||
const valid_map = ['admin', 'editor'];
|
const valid_map = ['admin', 'editor', 'teacher_user'];
|
||||||
return valid_map.indexOf(str.trim()) >= 0;
|
return valid_map.indexOf(str.trim()) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: 'admin',
|
username: 'teacher_user',
|
||||||
password: '111111'
|
password: '123456'
|
||||||
},
|
},
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
||||||
|
@ -65,13 +65,12 @@ export default defineConfig(({ command, mode }) => {
|
|||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 8001,
|
port: 8001,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api-test': {
|
'/api-prod': {
|
||||||
target: 'https://api.midfar.com/dspt_test/api',
|
target: 'https://nbxt.oa.x-lf.cn',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api-test/, '')
|
pathRewrite: {
|
||||||
},
|
'^/api-prod': ''
|
||||||
headers: {
|
}
|
||||||
Cookie: env.VUE_APP_COOKIE
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user