Browse Source

feat: user login funciton

wangyuan 2 years ago
parent
commit
cd1d19dc09

+ 9 - 1
ittpc/config/index.js

@@ -10,7 +10,15 @@ module.exports = {
     // Paths
     // Paths
     assetsSubDirectory: 'static',
     assetsSubDirectory: 'static',
     assetsPublicPath: '/',
     assetsPublicPath: '/',
-    proxyTable: {},
+    proxyTable: {
+      '/ittApi': {
+        target: 'http://tconsole.itthealth.com', // devEnv.BASEDOMAIN,
+        changeOrigin: true,
+        pathRewrite: {
+          '^/ittApi': ''
+        }
+      }
+    },
 
 
     // Various Dev Server settings
     // Various Dev Server settings
     host: 'localhost', // can be overwritten by process.env.HOST
     host: 'localhost', // can be overwritten by process.env.HOST

+ 0 - 13
ittpc/package-lock.json

@@ -11416,11 +11416,6 @@
       "integrity": "sha512-qsdtZH+vMoCARQtyod4imc2nIJwg9Cc7lPRrw9CzF8ZKR0khdr8+2nX80PBhET3tcyTtJDxAffGh2rXH4tyU8A==",
       "integrity": "sha512-qsdtZH+vMoCARQtyod4imc2nIJwg9Cc7lPRrw9CzF8ZKR0khdr8+2nX80PBhET3tcyTtJDxAffGh2rXH4tyU8A==",
       "dev": true
       "dev": true
     },
     },
-    "tiny-cookie": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmmirror.com/tiny-cookie/-/tiny-cookie-1.0.1.tgz",
-      "integrity": "sha512-4KJ21HYTNumxnHvCbLrtrrhSwtWXzpmaRJIUg4biBii5AiSe2izod5bauXiiQxVuf2Fta57U2DTW1Fa4/6Cmgw=="
-    },
     "to-arraybuffer": {
     "to-arraybuffer": {
       "version": "1.0.1",
       "version": "1.0.1",
       "resolved": "https://registry.npmmirror.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz",
       "resolved": "https://registry.npmmirror.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz",
@@ -11953,14 +11948,6 @@
         "csstype": "^3.1.0"
         "csstype": "^3.1.0"
       }
       }
     },
     },
-    "vue-cookie": {
-      "version": "1.1.4",
-      "resolved": "https://registry.npmmirror.com/vue-cookie/-/vue-cookie-1.1.4.tgz",
-      "integrity": "sha512-lxWIzmUTCVra0H7YPbNpYx0wbTQThV+n7ueUOcqtK8dlckmfB8fcyf4OEiRuQUd7iiVub2T3IDlWiisEM5Ku0Q==",
-      "requires": {
-        "tiny-cookie": "^1.0"
-      }
-    },
     "vue-hot-reload-api": {
     "vue-hot-reload-api": {
       "version": "2.3.4",
       "version": "2.3.4",
       "resolved": "https://registry.npmmirror.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz",
       "resolved": "https://registry.npmmirror.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz",

+ 0 - 1
ittpc/package.json

@@ -13,7 +13,6 @@
     "axios": "^1.1.2",
     "axios": "^1.1.2",
     "element-ui": "^2.15.10",
     "element-ui": "^2.15.10",
     "vue": "^2.5.2",
     "vue": "^2.5.2",
-    "vue-cookie": "^1.1.4",
     "vue-router": "^3.0.1",
     "vue-router": "^3.0.1",
     "vuex": "^3.4.0"
     "vuex": "^3.4.0"
   },
   },

+ 0 - 2
ittpc/src/main.js

@@ -10,8 +10,6 @@ import './elementui/index.css'
 Vue.use(ElementUI);
 Vue.use(ElementUI);
 
 
 import store from './store/store' 
 import store from './store/store' 
-import VueCookie from 'vue-cookie' 
-Vue.use(VueCookie)
 
 
 Vue.config.productionTip = false
 Vue.config.productionTip = false
 
 

+ 16 - 8
ittpc/src/request/axios.js

@@ -1,19 +1,16 @@
 import axios from 'axios'
 import axios from 'axios'
+import { Message } from 'element-ui';
 import Vue from 'vue'
 import Vue from 'vue'
 
 
 const service = axios.create({
 const service = axios.create({
-  baseURL: 'https://some-domain.com/api/',
-  timeout: 1000,
-  headers: {'X-Custom-Header': 'foobar'},
-
+  timeout: 10000
 });
 });
 
 
 /**
 /**
  * 请求拦截
  * 请求拦截
  */
  */
  service.interceptors.request.use(config => {
  service.interceptors.request.use(config => {
-  console.log('请求拦截', config)
-  config.headers['token'] = Vue.cookie.get('token')  // 请求头带上token
+  config.headers['AccessToken'] = sessionStorage.getItem('AccessToken') || ''
   return config
   return config
 }, error => {
 }, error => {
   return Promise.reject(error)
   return Promise.reject(error)
@@ -23,9 +20,20 @@ const service = axios.create({
  * 响应拦截
  * 响应拦截
  */
  */
  service.interceptors.response.use(response => {
  service.interceptors.response.use(response => {
-  console.log('响应拦截', response)
-  return response
+  console.log(response);
+  if (response.status !== 200) {
+    Message.error('请求失败')
+    return Promise.reject('请求失败: status code !== 200')
+  } else {
+    if (response.data.code !== '200') {
+      Message.error(response.data.msg || '请求失败')
+      return Promise.reject(response.data.msg || '请求失败')
+    } else {
+      return  Promise.resolve(response.data)
+    }
+  }
 }, error => {
 }, error => {
+  Message.error(error.message)
   return Promise.reject(error)
   return Promise.reject(error)
 })
 })
 
 

+ 13 - 3
ittpc/src/request/request.js

@@ -1,7 +1,17 @@
 import request from './axios'
 import request from './axios'
 
 
-const loginURL = 'user/login'
+const BASE_API = process.env.NODE_ENV !== 'production' ? '/ittApi/console' : '/console'
 
 
-export const login = (data) => {
-  return request.post(loginURL, data)
+// 登录
+const pwdLoginURL = BASE_API + '/pwd/login/v1'
+
+// 用户列表
+const getUserListURL = BASE_API + '/get/user/list/v1'
+
+export const pwdLogin = (data) => {
+  return request.post(pwdLoginURL, data)
+}
+
+export const getUserList = (data) => {
+  return request.post(getUserListURL, data)
 }
 }

+ 1 - 1
ittpc/src/router/index.js

@@ -49,7 +49,7 @@ const router = new Router({
 })
 })
 
 
 router.beforeEach((to, from, next) => {
 router.beforeEach((to, from, next) => {
-  if (to.name !== 'Login' && sessionStorage.getItem('accessToken') == null) {
+  if (to.name !== 'Login' && sessionStorage.getItem('AccessToken') == null) {
     next({ path: '/login',replace: true })
     next({ path: '/login',replace: true })
   } else {
   } else {
     next()
     next()

+ 26 - 17
ittpc/src/views/login/login.vue

@@ -15,8 +15,8 @@
         <div class="app-title">ITT运营后台</div>
         <div class="app-title">ITT运营后台</div>
         <div class="elform">
         <div class="elform">
           <el-form label-position="right" label-width="80px" :model="loginForm" :rules='rules' ref="loginForm">
           <el-form label-position="right" label-width="80px" :model="loginForm" :rules='rules' ref="loginForm">
-            <el-form-item label="账号" prop="account">
-              <el-input v-model="loginForm.account" placeholder="请输入登录账号"></el-input>
+            <el-form-item label="账号" prop="userName">
+              <el-input v-model="loginForm.userName" placeholder="请输入登录账号"></el-input>
             </el-form-item>
             </el-form-item>
             <el-form-item label="密码" prop="password">
             <el-form-item label="密码" prop="password">
               <el-input v-model="loginForm.password" type="password" placeholder="请输入登录密码"></el-input>
               <el-input v-model="loginForm.password" type="password" placeholder="请输入登录密码"></el-input>
@@ -32,6 +32,7 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import { pwdLogin } from './../../request/request'
 export default {
 export default {
   name: 'Login',
   name: 'Login',
   data() {
   data() {
@@ -41,13 +42,13 @@ export default {
         password: [
         password: [
           { required: true, message: '请输入登录密码', trigger: 'change' }
           { required: true, message: '请输入登录密码', trigger: 'change' }
         ],
         ],
-        account: [
+        userName: [
           { required: true, message: '请输入登录账号', trigger: 'change' }
           { required: true, message: '请输入登录账号', trigger: 'change' }
         ]
         ]
       },
       },
       loginForm: {
       loginForm: {
         password: '',
         password: '',
-        account: ''
+        userName: ''
       }
       }
     };
     };
   },
   },
@@ -58,27 +59,35 @@ export default {
       })
       })
     }
     }
   },
   },
-  mounted() {
-    this.$cookie.set('token', '999')
-    console.log('login mounted');
-  },
   methods: {
   methods: {
     submitForm (formName) {
     submitForm (formName) {
       this.$refs[formName].validate((valid) => {
       this.$refs[formName].validate((valid) => {
         if (valid) {
         if (valid) {
-          this.loading = true
-          setTimeout(() => {
-            this.loading = false
-            sessionStorage.setItem("accessToken", '4322423423')
-            this.$router.replace({
-              path: '/main/user'
-            })
-          }, 1000);
+          this.pwdLoginFn(this.loginForm.userName, this.loginForm.password)
         } else {
         } else {
-          console.log('error submit!!');
           return false;
           return false;
         }
         }
       });
       });
+    },
+    pwdLoginFn (userName,password) {
+      let data = {
+        userName: userName,
+        password: password
+      }
+      this.loading = true
+      pwdLogin(data).then(res => {
+        console.log(res,'loginvue');
+        const AccessToken = res.data.token
+        sessionStorage.setItem('AccessToken', AccessToken)
+        sessionStorage.setItem('userInfo', JSON.stringify(res.data))
+        this.$router.replace({
+          path: '/main/user'
+        })
+      }).finally(f => {
+        this.loading = false
+      }).catch(e => {
+        console.log(e);
+      })
     }
     }
   }
   }
 };
 };