笔记:跳转(不通用)

vuea 接口方式跳转(axios)(不存在跨域)

1.公司封装了axios,如果接口不返回code= 0,自己封装的axios会拦截报错可以用
let url = http://ucenter.xatasoft.com/api/
axios.get(‘url’).then(async response => {});

跳转代码

let data = {
    
    username: '12345678901', password: '123456'}
  
let res = await this.$api.getIOTToken(data).then((res) => {
    
    
	let url = 'http://iot.xatasoft.com/#/?token=' + res.result.access_token //拿Token登录
}
window.open(url) //跳转

prod.server.js

let port = '6070'
if (process.env.port) {
    
    
  port = process.env.port
}
export default {
    
    
  data: 'http://g528.xatasoft.com/serv/',
  fileUrl: 'http://files.xatasoft.com',
  ucenter: 'http://ucenter.xatasoft.com/api/',
  panoramaUrl: 'http://g528.xatasoft.com/',
  websoket: 'ws://hhy.xatasoft.com:' + port + '/',
  Realspace: 'http://iserver.xatasoft.com/iserver/services/',
  iserver: 'https://iserver.xatasoft.com/iserver/services/'
}

//api

export function getIOTToken(data) {
    
    
  return request({
    
    
    url: 'ucenter!user/login/in',
    method: 'post',
    data
  })
}

Ajax跳转(存在跨域)

Ajax跳转1,南平528中的跳转梁场

import {
    
     getLiangToken } from '@/utils/getLiangToken'
if (tab.name === '梁场管理') {
    
    
 getLiangToken(localStorage.getItem('loginMsg') || Cookies.get('hhyuser') || Cookies.get('hhyToken'))
   
   return
 }
export function getLiangToken(obj) {
    
    
	// getLiangToken js
  let baseUrl = ''
  if (process.env.NODE_ENV === 'production') {
    
    
    baseUrl = 'http://g528liang.xatasoft.com/'
  } else {
    
    
    baseUrl = 'http://dev_liang.t/'
  }
  $.ajax({
    
    
    'url': baseUrl + 'serv/user/Login/in',
    'contentType': "application/json; charset=utf-8",
    'type': "post",
    'data': obj,
    'dataType': "json",
    success: function(res) {
    
    
      if (res.code == 0) {
    
    
        let url = ''
        if (process.env.NODE_ENV === 'production') {
    
    
          url = 'http://g528liang.xatasoft.com/#/dashboard?token=' + res.result.access_token
        } else {
    
    
          url = 'http://dev_liang.t/#/dashboard?token=' + res.result.access_token
        }
        window.open(url)
      }else{
    
    
        Message.warning("获取token失败,请重新获取!")
      }
    },
    error: function(error) {
    
    
      Message.warning("获取token失败,请重新获取!")
    }
  })
}

Ajax跳转2,作战指挥首页平台跳转

let params = {
    
    
account: "邱杰"
created_at: "2021-09-28 15:54:16"
id: 28
index_url: "http://hhy.com/#/headquarters"
login_url: "https://hhy.com/serv/user/Login/in"
password: "789798"
platform_name: "hhy"
project_id: 18
updated_at: "2021-09-28 15:54:16
}
this.linkToHHY(params)
async linkToHHY(v){
    
    
 let obj = this.linkOpts.filter(item => item.id === v)[0]
  let linkUrl = obj.login_url
  const data = {
    
    
    password: obj.password,
    username: obj.account
  }
  await Ajax.post(linkUrl, data, function(response){
    
    
    const res = JSON.parse(response)
    Cookies.set('hhyuser', JSON.stringify({
    
    password: obj.password, username: obj.account}), {
    
    
      expires: 7,
      domain: 'xatasoft.com'
    })
    Cookies.remove('hhyuser', {
    
    
      expires: 7,
      domain: 'xatasoft.com'
    })
    let url = obj.index_url + '?token=' + res.result.access_token
    window.open(url)
  })
},

猜你喜欢

转载自blog.csdn.net/qq_43780814/article/details/120530486