If the same account is logged in in a different location, the popup window notifies the customer. How to do this?
For example, the code code is 402 when the remote login is performed. 2. Popup prompt is performed according to the code in the post-interceptor.
import router from '@/router' import { Message, Modal } from 'view-design' const toLogin = () => { router.replace({ path: '/login' }) } const myRequest = axios.create({ timeout: 1000 * 60 * 5 }) myRequest.interceptors.response.use( response => { if (response.status === 200) { const { code } = Response. data // Remote login if (code === 402) {// Global check whether the popup caused by 402 has been opened, if not, open the popup. Otherwise, multiple repeated pop-ups will be opened when multiple requests are triggered in succession. if (! Window. hasPoped402Modal) {// Popup window modal.warning ({title: 'prompt ', content: '<p> Your account logs in to another device. If it is not done by yourself, please change the login password in time. </p>', onOk: () => {toLogin() // Click ok to jump to the login page. At this time, the popup window has been closed by the user. Reset the popup state to false. Window.haspoped402modal = false}}) // Global flag, Open the window.haspoped402Modal = true}} return promise.resolve (response.data)} else {return Promise.reject(response) } } ) export default myRequestCopy the code