duanxiaoduan 1 anno fa
parent
commit
e2c96a765e
4 ha cambiato i file con 61 aggiunte e 32 eliminazioni
  1. 2 2
      .env.development
  2. 7 0
      src/permission.js
  3. 49 28
      src/views/login/index.vue
  4. 3 2
      vue.config.js

+ 2 - 2
.env.development

@@ -6,9 +6,9 @@ ENV = 'development'
 # 线上正式地址
 #  VUE_APP_BASE_API = 'http://eam.modernfarming.cn:8000/'
 # 白少后台本地
-VUE_APP_BASE_API = 'http://192.168.1.77:8082/'
+# VUE_APP_BASE_API = 'http://192.168.1.77:8082/'
 # 线上测试
-# VUE_APP_BASE_API = 'http://tmrwatch.cn:8082/'
+VUE_APP_BASE_API = 'http://tmrwatch.cn:8082/'
 # VUE_APP_BASE_API = 'http://tmrwatch.cn:8082/'
 # VUE_APP_BASE_API = 'http://127.0.0.1:8082/'
 

+ 7 - 0
src/permission.js

@@ -71,6 +71,13 @@ router.beforeEach(async(to, from, next) => {
 
       next({ path: '/login' })
       NProgress.done()
+       // next({ path: '/login' })
+      console.log(123)
+      // 构建要跳转的URL
+       const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri=http://tmrwatch.cn:8082";
+      // 使用 $router.push 进行页面跳转
+      // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+      window.open(externalURL, "_self");
     }
   }
 })

+ 49 - 28
src/views/login/index.vue

@@ -40,7 +40,7 @@
 
 <script>
 import { validUsername } from '@/utils/validate'
-
+import { getJson } from '@/api/common'
 export default {
   name: 'Login',
   data() {
@@ -88,14 +88,15 @@ export default {
     }
   },
   created() {
-    var that = this
-    document.onkeydown = function(e) {
-      e = window.event || e
-      // eslint-disable-next-line eqeqeq
-      if (that.$route.path == '/login' && (e.code == 'Enter' || e.code == 'Num Enter')) { // 验证在登录界面和按得键是回车键enter
-        that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
-      }
-    }
+    // var that = this
+    // document.onkeydown = function(e) {
+    //   e = window.event || e
+    //   // eslint-disable-next-line eqeqeq
+    //   if (that.$route.path == '/login' && (e.code == 'Enter' || e.code == 'Num Enter')) { // 验证在登录界面和按得键是回车键enter
+    //     that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
+    //   }
+    // }
+     this.getcodeList()
   },
   methods: {
     showPwd() {
@@ -108,25 +109,45 @@ export default {
         this.$refs.password.focus()
       })
     },
-    handleLogin() {
-      this.$refs.loginForm.validate(valid => {
-        if (valid) {
-          this.$store.dispatch('user/login', this.loginForm) .then(() => {
-            // const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
-            // if (!re.test(this.loginForm.password)) {
-            //   this.$router.push('/console/Changpwd')
-            //   console.log('密码不符合要求')
-            // }
-            this.$router.push({ path: this.redirect || '/' })
-            this.loading = false
-          }).catch(() => {
-            this.loading = false
-          })
-        } else {
-          console.log('error submit!!')
-          return false
-        }
-      })
+    // handleLogin() {
+    //   this.$refs.loginForm.validate(valid => {
+    //     if (valid) {
+    //       this.$store.dispatch('user/login', this.loginForm) .then(() => {
+    //         // const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
+    //         // if (!re.test(this.loginForm.password)) {
+    //         //   this.$router.push('/console/Changpwd')
+    //         //   console.log('密码不符合要求')
+    //         // }
+    //         this.$router.push({ path: this.redirect || '/' })
+    //         this.loading = false
+    //       }).catch(() => {
+    //         this.loading = false
+    //       })
+    //     } else {
+    //       console.log('error submit!!')
+    //       return false
+    //     }
+    //   })
+    // }
+    getcodeList(){
+      // 获取完整的URL
+      const fullURL = window.location.href;
+      // 使用正则表达式提取code参数的值
+      const codeMatch = fullURL.match(/[\?&]code=([^&]+)/);
+      if (codeMatch) {
+        // 如果匹配成功,将code的值存储在组件的data中
+        this.code = codeMatch[1];
+        let url = 'http://tmrwatch.cn:8082/api/v1/oauth2/token'
+        let data = '?code='+this.code
+        console.log('logincode====>',this.code)
+        getJson(url,data).then(response => {
+          console.log(response)
+          //TODO 保存token
+        })
+      } else {
+        console.log('error submit!!')
+        return false
+      }
     }
   }
 }

+ 3 - 2
vue.config.js

@@ -10,8 +10,8 @@ const name = defaultSettings.title || 'vue Admin Template' // page title
 // If your port is set to 80,
 // use administrator privileges to execute the command line.
 // For example, Mac: sudo npm run
-const port = 9529 // dev port
-
+// const port = 9529 // dev port
+const port = 8082 // dev port
 // All configuration item explanations can be find in https://cli.vuejs.org/config/
 module.exports = {
   /**
@@ -27,6 +27,7 @@ module.exports = {
   lintOnSave: process.env.NODE_ENV === 'development',
   productionSourceMap: false,
   devServer: {
+    allowedHosts: ['tmrwatch.cn'],
     port: port,
     open: true,
     overlay: {