zuozhengqing
2023-12-20 5888e32fb99675ac64a4c25ee66d1909083b1c02
jwt为空时跳转至aps登录页
4个文件已修改
72 ■■■■ 已修改文件
src/common/untils/request.js 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/layout/components/appsidebar/index.vue 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/purchaseManage/purchase/components/AddPurchase.vue 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/supplierManage/supplier/index.vue 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/common/untils/request.js
@@ -2,11 +2,36 @@
import { Message } from "element-ui"
// import router from '@/router'
// 开发环境下将自己的token复制到这里, 也可以在浏览器中手动添加token到cookie中,cookie中的token优先
const DEV_TOKEN =  ''
function environmentType(){
  let type
  if (location.href.includes('192.168.20.119')) {
      type = 'test'
  } else if (location.href.includes('192.168') || location.href.includes('localhost')) {
      type = 'dev'
  } else {
      type = 'prod'
  }
  return type
}
const isDev = environmentType() === 'dev'
const Axios = axios.create({
  responseType: "json",
  withCredentials: true // 是否允许带cookie这些
})
const getApsPage = () => {
  // 首页部署在各个环境的端口
  const loginPathMap = {
      prod:`//${window.location.hostname}:9080`,
      test:`//192.168.20.119:9080`,
      dev: `//192.168.8.107:8080`
  }
  return loginPathMap[environmentType()]
}
/* //POST传参序列化(添加请求拦截器) */
Axios.interceptors.request.use(
@@ -20,6 +45,9 @@
      /(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/,
      "$1",
    );
    if (isDev){
      token = token || DEV_TOKEN
    }
    if (token) {
      config.headers.Authorization = "Bearer " + token;
    }
@@ -36,16 +64,32 @@
    /* //对响应数据做些事 */
    if (res.data.code === 200) {
      return res.data ? res.data : {}
    } else {
      Message({
        message: res.data.msg,
        type: "error",
        duration: 5 * 1000
      })
    } else if([2012,2013,2014,2015].includes(res.data.code)){
      if (isDev){
        alert("JWT失效,即将跳转至登录页..")
        window.location = getApsPage()+'/login'
      }else {
        //   JWT鉴权失效 跳转到登录页
        window.location = getApsPage()+'/login'
      }
      // Message({
      //   message: res.data.msg,
      //   type: "error",
      //   duration: 5 * 1000
      // })
      return Promise.reject(res.data)
    }
  },
  (error) => {
    if(error.response.status === 401){
      if (isDev){
        alert("JWT失效,即将跳转至登录页..")
        window.location = getApsPage()+'/login'
      }else {
        //   JWT鉴权失效 跳转到登录页
        window.location = getApsPage()+'/login'
      }
    }
    let { message } = error
    if (message === "Network Error") {
      message = "后端接口连接异常"
src/components/layout/components/appsidebar/index.vue
@@ -25,6 +25,7 @@
        </el-submenu>
        
      </el-menu>
      <el-empty v-if="this.menus===null||this.menus===undefined||this.menus.length===0" :image-size="130" description="没有侧栏菜单"></el-empty>
    </div>
  </div>
</template>
@@ -61,4 +62,11 @@
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import "./index.scss";
::v-deep .el-empty{
  .el-empty__description{
    p{
      color: #dddd;
    }
  }
}
</style>
src/views/purchaseManage/purchase/components/AddPurchase.vue
@@ -54,7 +54,7 @@
                  >
                    <el-option
                      v-for="ele in plcBrandList"
                      :key="ele.name"
                      :key="ele.purchaseTypeId"
                      :label="ele.name"
                      :value="ele.id"
                    ></el-option>
@@ -373,6 +373,7 @@
    }
  },
  created() {
    console.log(this.editConfig,"参数")
    this.handleGetBomKindDictList()
    this.$store.dispatch("getSupplier")
    this.formInfo()
@@ -446,13 +447,15 @@
        this.plcBrandList = res.data
        this.setTableForm()
        if (val) {
          // this.plcBrandList.map((item)=>{
          //   item.purchaseTypeId=item.id
          // })
          for (let i in this.plcBrandList) {
            if (this.plcBrandList[i][this.editRow.isDefault]) {
              this.editConfig.infomation.purchaseTypeId = this.editConfig.infomation.purchaseTypeId
                ? this.editConfig.infomation.purchaseTypeId
                : this.plcBrandList[i].id
              this.$set(this.editConfig.infomation, "purchaseTypeId", this.editConfig.infomation.purchaseTypeId)
              break
            }
          }
src/views/supplierManage/supplier/index.vue
@@ -447,6 +447,7 @@
      this.editPurchaseConfig.title = "新建"
      this.editPurchaseConfig.infomation = {
        supplierId: this.selectRow.id,
        purchaseTypeId:"2",
        supplierName: this.selectRow.name
      }
    }