Bläddra i källkod

tbtools-登录

panyong 4 år sedan
förälder
incheckning
e1c447f33b

+ 1 - 1
htmldev/TBTools/config/index.js

@@ -14,7 +14,7 @@ module.exports = {
     // 代理列表, 是否开启代理通过[./dev.env.js]配置
     proxyTable: devEnv.OPEN_PROXY === false ? {} : {
       '/proxyApi': {
-        target: 'http://demo.open.renren.io/renren-fast-server/',
+        target: 'http://81.68.233.51',
         changeOrigin: true,
         pathRewrite: {
           '^/proxyApi': '/'

+ 1 - 99
htmldev/TBTools/src/router/index.js

@@ -6,8 +6,6 @@
  */
 import Vue from 'vue'
 import Router from 'vue-router'
-import http from '@/utils/httpRequest'
-import { isURL } from '@/utils/validate'
 // import { clearLoginInfo } from '@/utils'
 
 Vue.use(Router)
@@ -88,103 +86,7 @@ const router = new Router({
 })
 
 router.beforeEach((to, from, next) => {
-  // 添加动态(菜单)路由
-  // 1. 已经添加 or 全局路由, 直接访问
-  // 2. 获取菜单列表, 添加并保存本地存储
-  if (router.options.isAddDynamicMenuRoutes || fnCurrentRouteType(to, globalRoutes) === 'global') {
-    next()
-  } else {
-    http({
-      url: http.adornUrl('/sys/menu/nav'),
-      method: 'get',
-      params: http.adornParams()
-    }).then(({ data }) => {
-      if (data && data.code === 0) {
-        fnAddDynamicMenuRoutes(data.menuList)
-        router.options.isAddDynamicMenuRoutes = true
-        sessionStorage.setItem('menuList', JSON.stringify(data.menuList || '[]'))
-        sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]'))
-        next({ ...to, replace: true })
-      } else {
-        sessionStorage.setItem('menuList', '[]')
-        sessionStorage.setItem('permissions', '[]')
-        next()
-      }
-    }).catch((e) => {
-      console.log(`%c${e} 请求菜单列表和权限失败,跳转至登录页!!`, 'color:blue')
-      router.push({ name: 'login' })
-    })
-  }
+  next()
 })
 
-/**
- * 判断当前路由类型, global: 全局路由, main: 主入口路由
- * @param {*} route 当前路由
- */
-function fnCurrentRouteType (route, globalRoutes = []) {
-  var temp = []
-  for (var i = 0; i < globalRoutes.length; i++) {
-    if (route.path === globalRoutes[i].path) {
-      return 'global'
-    } else if (globalRoutes[i].children && globalRoutes[i].children.length >= 1) {
-      temp = temp.concat(globalRoutes[i].children)
-    }
-  }
-  return temp.length >= 1 ? fnCurrentRouteType(route, temp) : 'main'
-}
-
-/**
- * 添加动态(菜单)路由
- * @param {*} menuList 菜单列表
- * @param {*} routes 递归创建的动态(菜单)路由
- */
-function fnAddDynamicMenuRoutes (menuList = [], routes = []) {
-  var temp = []
-  for (var i = 0; i < menuList.length; i++) {
-    if (menuList[i].list && menuList[i].list.length >= 1) {
-      temp = temp.concat(menuList[i].list)
-    } else if (menuList[i].url && /\S/.test(menuList[i].url)) {
-      menuList[i].url = menuList[i].url.replace(/^\//, '')
-      var route = {
-        path: menuList[i].url.replace('/', '-'),
-        component: null,
-        name: menuList[i].url.replace('/', '-'),
-        meta: {
-          menuId: menuList[i].menuId,
-          title: menuList[i].name,
-          isDynamic: true,
-          isTab: true,
-          iframeUrl: ''
-        }
-      }
-      // url以http[s]://开头, 通过iframe展示
-      if (isURL(menuList[i].url)) {
-        route['path'] = `i-${menuList[i].menuId}`
-        route['name'] = `i-${menuList[i].menuId}`
-        route['meta']['iframeUrl'] = menuList[i].url
-      } else {
-        try {
-          route['component'] = _import(`modules/${menuList[i].url}`) || null
-        } catch (e) {}
-      }
-      routes.push(route)
-    }
-  }
-  if (temp.length >= 1) {
-    fnAddDynamicMenuRoutes(temp, routes)
-  } else {
-    mainRoutes.name = 'main-dynamic'
-    mainRoutes.children = routes
-    router.addRoutes([
-      mainRoutes,
-      { path: '*', redirect: { name: '404' } }
-    ])
-    sessionStorage.setItem('dynamicMenuRoutes', JSON.stringify(mainRoutes.children || '[]'))
-    console.log('\n')
-    console.log('%c!<-------------------- 动态(菜单)路由 s -------------------->', 'color:blue')
-    console.log(mainRoutes.children)
-    console.log('%c!<-------------------- 动态(菜单)路由 e -------------------->', 'color:blue')
-  }
-}
-
 export default router

+ 5 - 5
htmldev/TBTools/src/utils/httpRequest.js

@@ -1,9 +1,9 @@
 import Vue from 'vue'
 import axios from 'axios'
-// import router from '@/router'
+import router from '@/router'
 import qs from 'qs'
 import merge from 'lodash/merge'
-// import { clearLoginInfo } from '@/utils'
+import { clearLoginInfo } from '@/utils'
 
 const http = axios.create({
   timeout: 1000 * 30,
@@ -28,8 +28,8 @@ http.interceptors.request.use(config => {
  */
 http.interceptors.response.use(response => {
   if (response.data && response.data.code === 401) { // 401, token失效
-    // clearLoginInfo()
-    // router.push({ name: 'login' })
+    clearLoginInfo()
+    router.push({ name: 'login' })
   }
   return response
 }, error => {
@@ -42,7 +42,7 @@ http.interceptors.response.use(response => {
  */
 http.adornUrl = (actionName) => {
   // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
-  return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName
+  return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi' : window.SITE_CONFIG.baseUrl) + actionName
 }
 
 /**

+ 41 - 27
htmldev/TBTools/src/views/modules/account/login.vue

@@ -7,19 +7,19 @@
         </h3>
         <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
                  status-icon>
-          <el-form-item prop="userName">
-            <el-input v-model="dataForm.userName" placeholder="帐号"></el-input>
+          <el-form-item prop="userPhone">
+            <el-input type="tel" v-model="dataForm.userPhone" placeholder="帐号"></el-input>
           </el-form-item>
-          <el-form-item prop="password">
-            <el-input v-model="dataForm.password" type="password" placeholder="密码"></el-input>
+          <el-form-item prop="userPassword">
+            <el-input v-model="dataForm.userPassword" type="password" placeholder="密码"></el-input>
           </el-form-item>
           <el-form-item prop="captcha">
             <el-row :gutter="20">
               <el-col :span="17">
-                <el-input v-model="dataForm.captcha" placeholder="验证码">
+                <el-input v-model="dataForm.captcha" placeholder="图形验证码">
                 </el-input>
               </el-col>
-              <el-col :span="7" class="login-captcha">
+              <el-col :span="7" class="captcha">
                 <img :src="captchaPath" @click="getCaptcha()" alt="">
               </el-col>
             </el-row>
@@ -41,23 +41,24 @@ export default {
   data () {
     return {
       dataForm: {
-        userName: '',
-        password: '',
+        userPhone: '18768452697',
+        userPassword: '123456',
         uuid: '',
-        captcha: ''
+        captcha: '123456'
       },
       dataRule: {
-        userName: [
+        userPhone: [
           { required: true, message: '帐号不能为空', trigger: 'blur' }
         ],
-        password: [
+        userPassword: [
           { required: true, message: '密码不能为空', trigger: 'blur' }
         ],
         captcha: [
           { required: true, message: '验证码不能为空', trigger: 'blur' }
         ]
       },
-      captchaPath: ''
+      captchaPath: '',
+      isDisabled: false
     }
   },
   created () {
@@ -66,26 +67,39 @@ export default {
   methods: {
     // 提交表单
     dataFormSubmit () {
-      // this.$router.replace({ name: 'home' })
+      const { userPhone, userPassword, uuid, captcha } = this.dataForm
+      const postData = {
+        'userPhone': userPhone,
+        'userPassword': userPassword,
+        'uuid': uuid,
+        'captcha': captcha
+      }
       this.$refs['dataForm'].validate((valid) => {
         if (valid) {
+          if (this.isDisabled) {
+            return
+          }
+          this.isDisabled = true
           this.$http({
-            url: this.$http.adornUrl('/sys/login'),
+            url: this.$http.adornUrl('/user/login11'),
             method: 'post',
-            data: this.$http.adornData({
-              'username': this.dataForm.userName,
-              'password': this.dataForm.password,
-              'uuid': this.dataForm.uuid,
-              'captcha': this.dataForm.captcha
-            })
+            data: this.$http.adornData(postData)
           }).then(({ data }) => {
-            if (data && data.code === 0) {
-              this.$cookie.set('token', data.token)
+            this.isDisabled = false
+            if (data.status) {
+              const { token } = data.data
+              this.$cookie.set('token', token)
               this.$router.replace({ name: 'home' })
-            } else {
-              this.getCaptcha()
-              this.$message.error(data.msg)
+              return
             }
+            this.$message.error(data.msg)
+          }).catch((err) => {
+            this.isDisabled = false
+            this.$message({
+              message: JSON.stringify(err),
+              type: 'error',
+              duration: 2000
+            })
           })
         }
       })
@@ -93,7 +107,7 @@ export default {
     // 获取验证码
     getCaptcha () {
       this.dataForm.uuid = getUUID()
-      this.captchaPath = this.$http.adornUrl(`/captcha.jpg?uuid=${this.dataForm.uuid}`)
+      this.captchaPath = this.$http.adornUrl(`/api/captcha?uuid=${this.dataForm.uuid}`)
     },
     gotoRegister () {
       this.$router.push({
@@ -153,7 +167,7 @@ export default {
   margin: 0 auto;
 }
 
-.login-captcha {
+.captcha {
   display: flex;
   justify-content: flex-end;
   align-items: center;

+ 1 - 1
htmldev/TBTools/static/config/index-qa.js

@@ -5,7 +5,7 @@
   window.SITE_CONFIG = {};
 
   // api接口请求地址
-  window.SITE_CONFIG['baseUrl'] = 'http://localhost:8080/renren-fast';
+  window.SITE_CONFIG['baseUrl'] = 'http://81.68.233.51';
 
   // cdn地址 = 域名 + 版本号
   window.SITE_CONFIG['domain']  = './'; // 域名

+ 1 - 1
htmldev/TBTools/static/config/index.js

@@ -5,7 +5,7 @@
   window.SITE_CONFIG = {};
 
   // api接口请求地址
-  window.SITE_CONFIG['baseUrl'] = 'http://localhost:8080/renren-fast';
+  window.SITE_CONFIG['baseUrl'] = 'http://81.68.233.51';
 
   // cdn地址 = 域名 + 版本号
   window.SITE_CONFIG['domain']  = './'; // 域名