wangyuan пре 2 година
родитељ
комит
4d56e7faae

+ 44 - 10
ittpc/package-lock.json

@@ -345,8 +345,7 @@
     "asynckit": {
       "version": "0.4.0",
       "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz",
-      "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
-      "dev": true
+      "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
     },
     "atob": {
       "version": "2.1.2",
@@ -393,6 +392,28 @@
       "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
       "dev": true
     },
+    "axios": {
+      "version": "1.1.2",
+      "resolved": "https://registry.npmmirror.com/axios/-/axios-1.1.2.tgz",
+      "integrity": "sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==",
+      "requires": {
+        "follow-redirects": "^1.15.0",
+        "form-data": "^4.0.0",
+        "proxy-from-env": "^1.1.0"
+      },
+      "dependencies": {
+        "form-data": {
+          "version": "4.0.0",
+          "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz",
+          "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+          "requires": {
+            "asynckit": "^0.4.0",
+            "combined-stream": "^1.0.8",
+            "mime-types": "^2.1.12"
+          }
+        }
+      }
+    },
     "babel-code-frame": {
       "version": "6.26.0",
       "resolved": "https://registry.npmmirror.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
@@ -1998,7 +2019,6 @@
       "version": "1.0.8",
       "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz",
       "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
-      "dev": true,
       "requires": {
         "delayed-stream": "~1.0.0"
       }
@@ -3438,8 +3458,7 @@
     "delayed-stream": {
       "version": "1.0.0",
       "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz",
-      "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
-      "dev": true
+      "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
     },
     "delegates": {
       "version": "1.0.0",
@@ -4373,8 +4392,7 @@
     "follow-redirects": {
       "version": "1.15.2",
       "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz",
-      "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
-      "dev": true
+      "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
     },
     "for-in": {
       "version": "1.0.2",
@@ -6298,14 +6316,12 @@
     "mime-db": {
       "version": "1.52.0",
       "resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
-      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
-      "dev": true
+      "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
     },
     "mime-types": {
       "version": "2.1.35",
       "resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
       "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
-      "dev": true,
       "requires": {
         "mime-db": "1.52.0"
       }
@@ -9658,6 +9674,11 @@
         "ipaddr.js": "1.9.1"
       }
     },
+    "proxy-from-env": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
+      "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
+    },
     "prr": {
       "version": "1.0.1",
       "resolved": "https://registry.npmmirror.com/prr/-/prr-1.0.1.tgz",
@@ -11395,6 +11416,11 @@
       "integrity": "sha512-qsdtZH+vMoCARQtyod4imc2nIJwg9Cc7lPRrw9CzF8ZKR0khdr8+2nX80PBhET3tcyTtJDxAffGh2rXH4tyU8A==",
       "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": {
       "version": "1.0.1",
       "resolved": "https://registry.npmmirror.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz",
@@ -11927,6 +11953,14 @@
         "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": {
       "version": "2.3.4",
       "resolved": "https://registry.npmmirror.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz",

+ 2 - 0
ittpc/package.json

@@ -10,8 +10,10 @@
     "build": "node build/build.js"
   },
   "dependencies": {
+    "axios": "^1.1.2",
     "element-ui": "^2.15.10",
     "vue": "^2.5.2",
+    "vue-cookie": "^1.1.4",
     "vue-router": "^3.0.1",
     "vuex": "^3.4.0"
   },

+ 2 - 0
ittpc/src/main.js

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

+ 32 - 0
ittpc/src/request/axios.js

@@ -0,0 +1,32 @@
+import axios from 'axios'
+import Vue from 'vue'
+
+const service = axios.create({
+  baseURL: 'https://some-domain.com/api/',
+  timeout: 1000,
+  headers: {'X-Custom-Header': 'foobar'},
+
+});
+
+/**
+ * 请求拦截
+ */
+ service.interceptors.request.use(config => {
+  console.log('请求拦截', config)
+  config.headers['token'] = Vue.cookie.get('token')  // 请求头带上token
+  return config
+}, error => {
+  return Promise.reject(error)
+})
+
+/**
+ * 响应拦截
+ */
+ service.interceptors.response.use(response => {
+  console.log('响应拦截', response)
+  return response
+}, error => {
+  return Promise.reject(error)
+})
+
+export default service

+ 7 - 0
ittpc/src/request/request.js

@@ -0,0 +1,7 @@
+import request from './axios'
+
+const loginURL = 'user/login'
+
+export const login = (data) => {
+  return request.post(loginURL, data)
+}

+ 13 - 3
ittpc/src/router/index.js

@@ -9,12 +9,12 @@ import Config from '@/views/modules/config/config'
 
 Vue.use(Router)
 
-export default new Router({
+const router = new Router({
   mode: 'history',
   routes: [
     {
-      path: '/',
-      alias: '/login',
+      path: '/login',
+      alias: '/',
       name: 'Login',
       component: Login
     },
@@ -47,3 +47,13 @@ export default new Router({
     }
   ]
 })
+
+router.beforeEach((to, from, next) => {
+  if (to.name !== 'Login' && sessionStorage.getItem('accessToken') == null) {
+    next({ path: '/login',replace: true })
+  } else {
+    next()
+  }
+})
+
+export default router

+ 15 - 6
ittpc/src/views/login/login.vue

@@ -8,7 +8,7 @@
         </div>
         <div class="bottom-image"></div>
       </div>
-      <div class="right form main-item">
+      <div class="right form main-item" v-loading="loading" element-loading-text="登录中" element-loading-spinner="el-icon-loading">
         <div class="form-top">
           <div class="logo"></div>
         </div>
@@ -22,7 +22,7 @@
               <el-input v-model="loginForm.password" type="password" placeholder="请输入登录密码"></el-input>
             </el-form-item>
             <el-form-item label="">
-              <el-button style="width: 100%;" :loading="loginLoading" type="primary" round @click="submitForm('loginForm')">登录</el-button>
+              <el-button style="width: 100%;" type="primary" @click="submitForm('loginForm')">登录</el-button>
             </el-form-item>
           </el-form>
         </div>
@@ -36,7 +36,7 @@ export default {
   name: 'Login',
   data() {
     return {
-      loginLoading: false,
+      loading: false,
       rules: {
         password: [
           { required: true, message: '请输入登录密码', trigger: 'change' }
@@ -51,16 +51,25 @@ export default {
       }
     };
   },
+  created () {
+    if (sessionStorage.getItem("accessToken")) {
+      this.$router.replace({
+        path: '/main/user'
+      })
+    }
+  },
   mounted() {
-    sessionStorage.clear()
+    this.$cookie.set('token', '999')
+    console.log('login mounted');
   },
   methods: {
     submitForm (formName) {
       this.$refs[formName].validate((valid) => {
         if (valid) {
-          this.loginLoading = true
+          this.loading = true
           setTimeout(() => {
-            this.loginLoading = false
+            this.loading = false
+            sessionStorage.setItem("accessToken", '4322423423')
             this.$router.replace({
               path: '/main/user'
             })

+ 1 - 1
ittpc/src/views/modules/main.vue

@@ -121,7 +121,7 @@ export default {
   .el-main {
     background-color: #f3f5f7;
     color: #333;
-    padding: 10px;
+    padding: 1px;
     .el-card {
       height: 99%;
     }