Browse Source

修改了单点登录,及特殊申购供应商模糊查询问题

duanxiaoduan 1 year ago
parent
commit
d42f19bea0
5 changed files with 137 additions and 138 deletions
  1. 0 0
      dist/index.html
  2. 17 18
      src/permission.js
  3. 89 70
      src/store/modules/user.js
  4. 2 2
      src/views/custom/subscribe/index.vue
  5. 29 48
      src/views/login/index.vue

File diff suppressed because it is too large
+ 0 - 0
dist/index.html


+ 17 - 18
src/permission.js

@@ -4,9 +4,10 @@ import { Message } from 'element-ui'
 import NProgress from 'nprogress' // progress bar
 import 'nprogress/nprogress.css' // progress bar style
 import { getToken,removeToken } from '@/utils/auth' // get token from cookie
-
+import Cookies from 'js-cookie'
 import getPageTitle from '@/utils/get-page-title'
-
+// 1为单点登录,其他不是
+Cookies.set('sso',0)
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
 
 const whiteList = ['/login'] // no redirect whitelist
@@ -74,24 +75,22 @@ router.beforeEach(async(to, from, next) => {
 
       next({ path: '/login' })
       NProgress.done()
-      // // 单点登录
-      // // 构建要跳转的URL
-      // var url = process.env.VUE_APP_BASE_API
-      // console.log(url,'url')
-      // //获取当前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="+url+'api/v1/oauth2/token';
-      // // 使用 $router.push 进行页面跳转
-      // // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
-      // window.open(externalURL, "_self");
+      if(Cookies.get('sso') == 1){
+        // 单点登录
+        // 构建要跳转的URL
+        var url = process.env.VUE_APP_BASE_API
+        console.log(url,'url')
+        //获取当前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="+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(() => {

+ 89 - 70
src/store/modules/user.js

@@ -99,46 +99,49 @@ const actions = {
     const { username, password } = userInfo
     return new Promise((resolve, reject) => {
       login({ username: username.trim(), password: password }).then(response => {
+        if(Cookies.get('sso') == 1){
         // 单点登录=============================
-        // 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", "");
-        //   }
-        //  //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 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", "");
+            }
+           //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)
+        }else{
+          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()
         }
-        setToken(data.token)
-        resolve()
       }).catch(error => {
         reject(error)
       })
@@ -161,29 +164,31 @@ const actions = {
         if (!role || role.length <= 0) {
           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()
-            // 单点登录
-            // var url = process.env.VUE_APP_BASE_API
-            // //获取当前url
+          if(Cookies.get('sso') == 1){
+            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()
+              // 单点登录
+              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)
+              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 => {
@@ -271,19 +276,33 @@ const actions = {
         removeToken()
         resetRouter()
         resolve()
+        if(Cookies.get('sso') == 1){
         // 单点登录
-        // var url = process.env.VUE_APP_BASE_API
-        // console.log(url,'url')
-        // //获取当前url
+          var url = process.env.VUE_APP_BASE_API
+          console.log(url,'url')
+          //获取当前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()
+          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()
+        }else{
+          commit('SET_BUTTONS', [])
+          // console.log('-------------', state)
+          commit('SET_TOKEN', '')
+          commit('SET_ROLES', [])
+          Cookies.remove('employename')
+          Cookies.remove('employeid')
+          Cookies.remove('pastureid')
+          removeToken()
+          resetRouter()
+          resolve()
+          location.reload()
+        }
       }).catch(error => {
         reject(error)
       })

+ 2 - 2
src/views/custom/subscribe/index.vue

@@ -188,7 +188,7 @@
             </el-col>
             <el-col v-if="dialogStatus==='special' && createTemp.purchaseType == '1' || createTemp.purchaseType == '3'" :span="8">
               <el-form-item label="供应商:" prop="providerId">
-                <el-select v-model="createTemp.providerId" placeholder="供应商" class="filter-item" style="width:100%" :disabled="dialogStatus==='update'">
+                <el-select v-model="createTemp.providerId" filterable placeholder="供应商" class="filter-item" style="width:100%" :disabled="dialogStatus==='update'">
                   <el-option v-for="item in providerList" :key="item.id" :label="item.providerName" :value="item.id" />
                 </el-select>
               </el-form-item>
@@ -2208,7 +2208,7 @@ export default {
     getProviderList(){
       let data = {
         "name":"getProviderList",
-        "page":1,"offset":1,"pagecount":100,
+        "page":1,"offset":1,"pagecount":0,
         "returntype":"Map","parammaps":{"providerName":""}
       }
       GetDataByName(data).then(response => {

+ 29 - 48
src/views/login/index.vue

@@ -1,5 +1,6 @@
 <template>
-  <!-- <div class="login-container">
+  <div v-if="isdisplay == 1"></div>
+  <div class="login-container" v-else>
     <div class="content">
       <div class="content-l"></div>
       <div class="login">
@@ -29,7 +30,8 @@
         </el-form>
       </div>
     </div>
-  </div> -->
+  </div>
+  
 </template>
 
 <script>
@@ -73,7 +75,8 @@ export default {
       },
       loading: false,
       passwordType: 'password',
-      redirect: undefined
+      redirect: undefined,
+      isdisplay:Cookies.get('sso')
     }
   },
   watch: {
@@ -93,7 +96,10 @@ export default {
     //     that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
     //   }
     // }
+    // 单点登录
+    if(Cookies.get('sso') == 1){
      this.getcodeList()
+    }
   },
   methods: {
     showPwd() {
@@ -106,56 +112,31 @@ 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
-      // }
     }
   }
 }

Some files were not shown because too many files changed in this diff