ソースを参照

Merge branch 'sso-login' of Epans/modernDairy into master

duanxiaoduan 1 年間 前
コミット
62429555dd

+ 3 - 3
.env.development

@@ -5,10 +5,10 @@ ENV = 'development'
 # VUE_APP_BASE_API = '/dev-api'
 # 线上正式地址
 #  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/'
 

ファイルの差分が大きいため隠しています
+ 0 - 0
dist/index.html


+ 2 - 2
src/api/user.js

@@ -19,7 +19,7 @@ export function getInfo() { // token
 
 export function logout() {
   return request({
-    url: '/authdata/logout',
-    method: 'post'
+    url: '/api/v1/logout',
+    method: 'get'
   })
 }

+ 1 - 1
src/layout/components/Navbar.vue

@@ -104,7 +104,7 @@ export default {
     async logout() {
       await this.$store.dispatch('user/logout')
       this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
-        this.$router.push(`/login`) // 跳转到主页
+        console.log("注销了")
       })
       // this.$router.push(`/login?redirect=${this.$route.fullPath}`)   //跳转到登陆前页面
     },

+ 25 - 2
src/permission.js

@@ -3,7 +3,8 @@ import store from './store'
 import { Message } from 'element-ui'
 import NProgress from 'nprogress' // progress bar
 import 'nprogress/nprogress.css' // progress bar style
-import { getToken } from '@/utils/auth' // get token from cookie
+import { getToken,removeToken } from '@/utils/auth' // get token from cookie
+
 import getPageTitle from '@/utils/get-page-title'
 
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
@@ -20,6 +21,7 @@ router.beforeEach(async(to, from, next) => {
   // determine whether the user has logged in
   const hasToken = getToken()
 
+    console.log('hasToken==>',hasToken)
   if (hasToken) {
     if (to.path === '/login') {
       // if is logged in, redirect to the home page
@@ -40,7 +42,7 @@ router.beforeEach(async(to, from, next) => {
 
           // generate accessible routes map based on roles
           const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
-
+          console.log(accessRoutes,'accessRoutes')
           // dynamically add accessible routes
           router.addRoutes(accessRoutes)
 
@@ -53,6 +55,7 @@ router.beforeEach(async(to, from, next) => {
           await store.dispatch('user/resetToken')
           Message.error(error || 'Has Error')
           // next(`/login?redirect=${to.path}`)    //跳转到退出前界面
+          removeToken()
           next(`/login`)
           NProgress.done()
         }
@@ -71,8 +74,28 @@ router.beforeEach(async(to, from, next) => {
 
       next({ path: '/login' })
       NProgress.done()
+       // next({ path: '/login' })
+      // 构建要跳转的URL
+      // const url = window.location.protocol + "//"+window.location.host + '/'
+      // const url = 'http://192.168.61.41/'
+      // const url = 'http://tmrwatch.cn:8082/'
+      var url = process.env.VUE_APP_BASE_API
+      //获取当前url
+      
+      if(url.indexOf('/')==0 && url.length==1){
+        url= window.location.protocol + "//"+window.location.host+url
+      }
+      //        const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri=http://tmrwatch.cn:8082/api/v1/oauth2/token";
+      const externalURL = "https://id.xiandaimuye.com/api/v1/oauth2/authorize?response_type=code&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I&redirect_uri="+url+'api/v1/oauth2/token';
+      // 使用 $router.push 进行页面跳转
+      // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+      window.open(externalURL, "_self");
     }
   }
+
+  // 使用 $router.push 进行页面跳转
+  // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+  // window.open(url1, "_self");
 })
 
 router.afterEach(() => {

+ 82 - 17
src/store/modules/user.js

@@ -99,21 +99,47 @@ const actions = {
     const { username, password } = userInfo
     return new Promise((resolve, reject) => {
       login({ username: username.trim(), password: password }).then(response => {
-        const { data, msg } = response
-        if (msg !== 'ok') {
-          Message({
-            message: data,
-            type: 'error',
-            duration: 5 * 1000
-          })
-          reject(data)
-        }
-        commit('SET_TOKEN', data.token)
-        if (Cookies == null) {
-          console.log(1)
-        }
-        setToken(data.token)
-        resolve()
+        // =============================
+        const fullURL = window.location.href;
+        // 使用正则表达式提取code参数的值
+        const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
+        console.log('codeMatch===>',codeMatch)
+        if (codeMatch) {
+          // 如果匹配成功,将code的值存储在组件的data中
+          var code = codeMatch[1];
+            //TODO 保存token
+            // 去除后面的#/login
+          if ( code &&  code.includes("#/login")) {
+            code =  code.replace("#/login", "");
+          }
+          console.log('token',code)
+           //base64解密this.cose
+            console.log('解密token',atob(code))
+            let token = atob(code)
+            commit('SET_TOKEN', token)
+            setToken(token)
+            resolve()
+            let url = window.location.href;
+            // 使用split方法将URL拆分为数组
+            let jmpurl = url.split('?')[0]+'#/dashboard'
+            window.open(jmpurl, "_self");
+          }
+        // =============================
+        // const { data, msg } = response
+        // if (msg !== 'ok') {
+        //   Message({
+        //     message: data,
+        //     type: 'error',
+        //     duration: 5 * 1000
+        //   })
+        //   reject(data)
+        // }
+        // commit('SET_TOKEN', data.token)
+        // if (Cookies == null) {
+        //   console.log(1)
+        // }
+        // setToken(data.token)
+        // resolve()
       }).catch(error => {
         reject(error)
       })
@@ -134,7 +160,33 @@ const actions = {
 
         // roles must be a non-empty array
         if (!role || role.length <= 0) {
-          reject('getInfo: roles must be a non-null array!')
+          reject('该用户未分配角色!')
+          console.log('no=============')
+          setTimeout(()=>{
+            commit('SET_BUTTONS', [])
+            // console.log('-------------', state)
+            commit('SET_TOKEN', '')
+            commit('SET_ROLES', [])
+            Cookies.remove('employename')
+            Cookies.remove('employeid')
+            Cookies.remove('pastureid')
+            removeToken()
+            resetRouter()
+            resolve()
+            // const url = process.env.VUE_APP_BASE_API
+            // const url = 'http://192.168.61.41/'
+            // const url = 'http://tmrwatch.cn:8082/'
+            var url = process.env.VUE_APP_BASE_API
+            //获取当前url
+
+            if(url.indexOf('/')==0 && url.length==1){
+              url= window.location.protocol + "//"+window.location.host+url
+            }
+            const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url="+url+ '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
+            // 使用 $router.push 进行页面跳转
+            // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+            window.open(externalURL, "_self");
+          },2000)
         }
 
         GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': username }}).then(response => {
@@ -222,7 +274,20 @@ const actions = {
         removeToken()
         resetRouter()
         resolve()
-        location.reload()
+        // const url = process.env.VUE_APP_BASE_API
+        // const url = 'http://192.168.61.41/'
+        // const url = 'http://tmrwatch.cn:8082/'
+        var url = process.env.VUE_APP_BASE_API
+        //获取当前url
+        
+        if(url.indexOf('/')==0 && url.length==1){
+          url= window.location.protocol + "//"+window.location.host+url
+        }
+        const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url=" + url + '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
+        // 使用 $router.push 进行页面跳转
+        // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
+        window.open(externalURL, "_self");
+        // location.reload()
       }).catch(error => {
         reject(error)
       })

+ 1 - 0
src/utils/auth.js

@@ -7,6 +7,7 @@ export function getToken() {
 }
 
 export function setToken(token) {
+  // console.log(token,'token')
   return Cookies.set(TokenKey, token)
 }
 

+ 2 - 1
src/utils/request.js

@@ -110,13 +110,14 @@ service.interceptors.response.use(
     config.__retryCount = config.__retryCount || 0
    if (config.__retryCount >= 3) {
       // Message({ message:error.message, type: 'error', duration: 5 * 1000 })
+      console.log('err' + error)
       Message({ message:'请求超时', type: 'error', duration: 5 * 1000 })
       // Message.error((error && error.data && error.data.msg) || '请求超时')
       return Promise.reject(error)
     }
     config.__retryCount += 1
 
- 
+
     let backoff = new Promise((resolve) => {
       setTimeout(() => {
         resolve()

+ 25 - 12
src/views/console/user/index.vue

@@ -90,7 +90,7 @@
             <el-select v-model="dataform.deviceId" style="width:500px;" placeholder="请选择" @change="change_deviceId">
               <el-option v-for="item in viedoAccountList" :key="item.deviceId" :label="item.deviceId" :value="item.deviceId" />
             </el-select>
-          </el-form-item> 
+          </el-form-item>
           <el-form-item label="是否保养工" prop="keeper">
             <el-switch ref="keeper" v-model="dataform.keeper" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
           </el-form-item>
@@ -214,7 +214,7 @@ export default {
         { name: 'getEmpall', offset: 0, pagecount: 0, params: [] },
         { name: 'getMaintenanceTypeList', offset: 0, pagecount: 0, params: [] },
         { name: 'getMcsAccounts', offset: 0, pagecount: 0, params: [] },
-        
+
       ],
       requestFilterParams: { returntype: 'Map', parammaps: {}},
       UpdateDataRelationParam: { name: '', dataname: '', datavalue: '', valuename: '', values: [] },
@@ -392,17 +392,17 @@ export default {
 
 
 
-                var pastureId = Cookies.get('pastureid') 
+                var pastureId = Cookies.get('pastureid')
 
 
                 console.log(pastureid)
 
-                var deviceId = this.dataform.deviceId  
+                var deviceId = this.dataform.deviceId
                 var uId = this.dataform.uId
                 var pwd = this.dataform.pwd
 
-             
-                
+
+
 
                 console.log('pastureId', pastureId)
                 var send_data = {
@@ -439,7 +439,7 @@ export default {
 
                   ]
                 }
- 
+
 
                 console.log('记录仪保存发送参数===========', send_data)
                 ExecDataByConfig(send_data).then(response => {
@@ -454,8 +454,14 @@ export default {
                           'deviceId': this.dataform.deviceId
                         }
                       }
-
-                      MessageBox.confirm('该设备已经绑定,是否重新绑定?', {
+                      let str1 = '启用'
+                      if(this.dataform.enable == 1){
+                        str1 = '启用'
+                      }else{
+                        str1 = '禁用'
+                      }
+                      let str = '是否'+ str1 +'该用户?'
+                      MessageBox.confirm(str, {
                         confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
                       }).then(() => {
                         PostDataByName(send_data3).then(() => {
@@ -550,7 +556,7 @@ export default {
         } else {
             this.requestParam.params[4] = this.dataform.maintenancePerson
         }
-          
+
 
 
           this.requestParam.params[5] = this.dataform.keeper
@@ -617,8 +623,15 @@ export default {
                             'deviceId': this.dataform.deviceId
                           }
                         }
-
-                        MessageBox.confirm('该设备已经绑定,是否重新绑定?', {
+                        let str1 = '启用'
+                        if(this.dataform.enable == 1){
+                          str1 = '启用'
+                        }else{
+                          str1 = '禁用'
+                        }
+                        let str = '是否'+ str1 +'该用户?'
+                        MessageBox.confirm(str, {
+                        // MessageBox.confirm('该设备已经绑定,是否重新绑定?', {
                           confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
                         }).then(() => {
                           PostDataByName(send_data3).then(() => {

+ 4 - 4
src/views/dashboard/editor/index.vue

@@ -91,7 +91,7 @@
           <div class="Title">费用统计</div>
           <div class="costStatistics">
             <div class="content">
-              <dv-border-box-8 :dur="-1" style="height:260px; ">
+              <dv-border-box-8 :dur="-1" style="height:275px; ">
                 <div class="title">
                   <svg-icon icon-class="维修成本分析" />
                   维修费
@@ -112,7 +112,7 @@
               </dv-border-box-8>
             </div>
             <div class="content">
-              <dv-border-box-8 :dur="-1" style="height:260px;">
+              <dv-border-box-8 :dur="-1" style="height:275px;">
                 <div class="title">
                   <svg-icon icon-class="水量分析" />
                   水费
@@ -133,7 +133,7 @@
               </dv-border-box-8>
             </div>
             <div class="content">
-              <dv-border-box-8 :dur="-1" style="height:260px;">
+              <dv-border-box-8 :dur="-1" style="height:275px;">
                 <div class="title">
                   <svg-icon icon-class="电量分析" />
                   电费
@@ -154,7 +154,7 @@
               </dv-border-box-8>
             </div>
             <div class="content">
-              <dv-border-box-8 :dur="-1" style="height:260px;">
+              <dv-border-box-8 :dur="-1" style="height:275px;">
                 <div class="title">
                   <svg-icon icon-class="燃动分析" />
                   燃动费

+ 64 - 35
src/views/login/index.vue

@@ -1,7 +1,5 @@
 <template>
-  <div class="login-container">
-    <!-- <img src="@/assets/images/logo.png" alt class="logo">
-    <img src="@/assets/images/login-bujian.png" alt="" class="bujian"> -->
+  <!-- <div class="login-container">
     <div class="content">
       <div class="content-l"></div>
       <div class="login">
@@ -31,16 +29,15 @@
         </el-form>
       </div>
     </div>
-    <!-- <div class="login">
-      <div class="logo" />
-
-    </div> -->
-  </div>
+  </div> -->
 </template>
 
 <script>
 import { validUsername } from '@/utils/validate'
-
+import { getJson } from '@/api/common'
+import Cookies from 'js-cookie'
+import axios from 'axios';
+import { setToken } from '@/utils/auth' // get token from cookie
 export default {
   name: 'Login',
   data() {
@@ -88,14 +85,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 +106,56 @@ 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(){
+      this.$store.dispatch('user/login', this.loginForm) .then(() => {
+        
+      }).catch(() => {
+        this.loading = false
       })
+      // // 获取完整的URL
+      // const fullURL = window.location.href;
+      // // 使用正则表达式提取code参数的值
+      // const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
+      // if (codeMatch) {
+      //   // 如果匹配成功,将code的值存储在组件的data中
+      //   this.code = codeMatch[1];
+      //   console.log(this.code)
+      //     //TODO 保存token
+      //     // 去除后面的#/login
+      //   if ( this.code &&  this.code.includes("#/login")) {
+      //      this.code =  this.code.replace("#/login", "");
+      //   }
+      //    console.log(this.code)
+      //    //base64解密this.cose
+      //     // atob(this.code)
+      //     console.log( atob(this.code))
+      //     let token = atob(this.code)
+      //     setToken(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: {

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません