|
@@ -3,65 +3,26 @@ import axios from "axios";
|
|
|
import {ElMessage,ElMessageBox} from 'element-plus'
|
|
|
import CryptoJS from './crypto'
|
|
|
import router from '@/router/index'
|
|
|
+import { isMobile,copyText } from "../utils/common";
|
|
|
|
|
|
-let config = {
|
|
|
- baseURL: import.meta.env.VITE_APP_API_URL,
|
|
|
- timeout: 60 * 1000, // Timeout
|
|
|
-};
|
|
|
-
|
|
|
-const _axios = axios.create(config);
|
|
|
-
|
|
|
-const isPhone=()=>{
|
|
|
- return !(window.innerWidth>768)
|
|
|
-}
|
|
|
+// 复制邮箱
|
|
|
const copyEmail=()=>{
|
|
|
- if (navigator.clipboard && window.isSecureContext) {
|
|
|
- // navigator clipboard 向剪贴板写文本
|
|
|
- navigator.clipboard.writeText('stephanie@hzinsights.com').then(() => {
|
|
|
- ElMessage.success('Email address copied')
|
|
|
- });
|
|
|
- }else{
|
|
|
- const input = document.createElement('input');
|
|
|
- input.setAttribute('readonly', 'readonly');
|
|
|
- input.setAttribute('value', 'stephanie@hzinsights.com');
|
|
|
- document.body.appendChild(input);
|
|
|
- input.setSelectionRange(0, input.value.length);
|
|
|
- input.select();
|
|
|
- document.execCommand('copy');
|
|
|
- document.body.removeChild(input);
|
|
|
+ copyText('stephanie@hzinsights.com').then(res=>{
|
|
|
ElMessage.success('Email address copied')
|
|
|
- }
|
|
|
+ }).catch(()=>{})
|
|
|
}
|
|
|
|
|
|
-_axios.interceptors.request.use(
|
|
|
- function (config) {
|
|
|
- config.headers.shareEmailId=sessionStorage.getItem('shareId')||0
|
|
|
- config.headers.Authorization=localStorage.getItem('yben_token')||''
|
|
|
- return config;
|
|
|
- },
|
|
|
- function (error) {
|
|
|
- // Do something with request error
|
|
|
- return Promise.reject(error);
|
|
|
- }
|
|
|
-);
|
|
|
-
|
|
|
-// Add a response interceptor
|
|
|
-_axios.interceptors.response.use(
|
|
|
- function (response) {
|
|
|
- let data
|
|
|
- if(import.meta.env.MODE==='production'){
|
|
|
- data=JSON.parse(CryptoJS.Des3Decrypt(response.data));//解密
|
|
|
- }else{
|
|
|
- data=response.data
|
|
|
- }
|
|
|
-
|
|
|
- if(data.code === 400 || data.code === 500) {
|
|
|
- ElMessage.error(data.msg)
|
|
|
- }else if(data.code==401){
|
|
|
+// 检查返回的code
|
|
|
+const checkResCode=(code,msg)=>{
|
|
|
+ switch (code) {
|
|
|
+ case 400 || 500:
|
|
|
+ ElMessage.error(msg)
|
|
|
+ break;
|
|
|
+ case 401:
|
|
|
// 非法访问
|
|
|
ElMessage({
|
|
|
type:'error',
|
|
|
- message:data.msg,
|
|
|
+ message:msg,
|
|
|
duration:1000
|
|
|
})
|
|
|
setTimeout(()=>{
|
|
@@ -70,53 +31,91 @@ _axios.interceptors.response.use(
|
|
|
localStorage.removeItem('user_info')
|
|
|
router.replace('/login')
|
|
|
},1000)
|
|
|
- }else if(data.code==4013){
|
|
|
+ break;
|
|
|
+ case 4013:
|
|
|
// 未注册
|
|
|
ElMessageBox.confirm("This email adress is not registered. Please try again.","Prompt",
|
|
|
{
|
|
|
- customClass:isPhone()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
- confirmButtonClass:isPhone()?'mobile-confirm-button':'',
|
|
|
+ customClass:isMobile()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
+ confirmButtonClass:isMobile()?'mobile-confirm-button':'',
|
|
|
confirmButtonText: 'Create account',
|
|
|
showCancelButton:false,
|
|
|
}).then(res=>{
|
|
|
router.push('/register')
|
|
|
}).catch(()=>{})
|
|
|
- }else if(data.code==4014){
|
|
|
+ break;
|
|
|
+ case 4014:
|
|
|
// 未绑定
|
|
|
ElMessageBox.confirm("This phone number is not registered. Please try again.","Prompt",
|
|
|
{
|
|
|
- customClass:isPhone()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
- confirmButtonClass:isPhone()?'mobile-confirm-button':'',
|
|
|
+ customClass:isMobile()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
+ confirmButtonClass:isMobile()?'mobile-confirm-button':'',
|
|
|
confirmButtonText: 'Got it',
|
|
|
showCancelButton:false,
|
|
|
}).then(res=>{
|
|
|
console.log('This phone number is not registered. Please try again.');
|
|
|
}).catch(()=>{})
|
|
|
- }else if(data.code==4012){
|
|
|
+ break;
|
|
|
+ case 4012:
|
|
|
// 权限到期
|
|
|
localStorage.removeItem('user_info')
|
|
|
localStorage.removeItem('yben_token')
|
|
|
ElMessageBox.confirm("Your trial has ended Enjoyed your experience with us? Contact us at stephanie@hzinsights.com to extend your trial.","Prompt",
|
|
|
{
|
|
|
- customClass:isPhone()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
- confirmButtonClass:isPhone()?'mobile-confirm-button':'',
|
|
|
+ customClass:isMobile()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
+ confirmButtonClass:isMobile()?'mobile-confirm-button':'',
|
|
|
confirmButtonText: 'Get the contact email',
|
|
|
showCancelButton:false,
|
|
|
}).then(res=>{
|
|
|
copyEmail()
|
|
|
}).catch(()=>{})
|
|
|
- }else if(data.code==4015){
|
|
|
+ break;
|
|
|
+ case 4015:
|
|
|
// 已注册
|
|
|
ElMessageBox.confirm("There is already a user account associated with this email address. Please log in instead.","Prompt",
|
|
|
{
|
|
|
- customClass:isPhone()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
- confirmButtonClass:isPhone()?'mobile-confirm-button':'',
|
|
|
+ customClass:isMobile()?'mobile-message-confirm':'PC-message-confirm',
|
|
|
+ confirmButtonClass:isMobile()?'mobile-confirm-button':'',
|
|
|
confirmButtonText: 'Log in',
|
|
|
showCancelButton:false,
|
|
|
}).then(res=>{
|
|
|
router.push('/login')
|
|
|
}).catch(()=>{})
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+let config = {
|
|
|
+ baseURL: import.meta.env.VITE_APP_API_URL,
|
|
|
+ timeout: 60 * 1000, // Timeout
|
|
|
+};
|
|
|
+
|
|
|
+const _axios = axios.create(config);
|
|
|
+
|
|
|
+_axios.interceptors.request.use(
|
|
|
+ function (config) {
|
|
|
+ config.headers.shareEmailId=sessionStorage.getItem('shareId')||0
|
|
|
+ config.headers.Authorization=localStorage.getItem('yben_token')||''
|
|
|
+ return config;
|
|
|
+ },
|
|
|
+ function (error) {
|
|
|
+ // Do something with request error
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+// Add a response interceptor
|
|
|
+_axios.interceptors.response.use(
|
|
|
+ function (response) {
|
|
|
+ let data
|
|
|
+ if(import.meta.env.MODE==='production'){
|
|
|
+ data=JSON.parse(CryptoJS.Des3Decrypt(response.data));//解密
|
|
|
+ }else{
|
|
|
+ data=response.data
|
|
|
}
|
|
|
+
|
|
|
+ checkResCode(data.code,data.msg)
|
|
|
+
|
|
|
return data;
|
|
|
},
|
|
|
function (error) {
|