mirror of
http://36.133.248.69:3088/admin/RentWeAppFront.git
synced 2026-06-07 06:22:27 +08:00
优化,完善代码
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// 全局配置文件
|
||||
// let baseUrl = 'http://219.138.32.164:8089';
|
||||
// let baseUrl = 'http://localhost:3000/api';
|
||||
// let staticUrl = 'http://localhost:3000';
|
||||
// let baseUrl = 'http://localhost:8089';
|
||||
// let staticUrl = 'http://localhost:3080';
|
||||
let baseUrl = 'https://www.wujiaguotou.com/api';
|
||||
let staticUrl = 'https://www.wujiaguotou.com';
|
||||
// 版本号 用于更新
|
||||
|
||||
@@ -5,25 +5,22 @@ const install = (Vue, vm) => {
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
// baseUrl打包app时放开,h5模式下会和vue.config.js代理冲突,导致失效
|
||||
baseUrl: config.baseUrl,
|
||||
originalData:true,
|
||||
originalData: true,
|
||||
timeout: 10000,
|
||||
});
|
||||
// 请求拦截,配置Token等参数
|
||||
Vue.prototype.$u.http.interceptor.request = (config) => {
|
||||
// config.header.Token = '5d33018e653d897fc259b42cf022c1b3';
|
||||
// 方式一,存放在vuex的token,假设使用了uView封装的vuex方式,见:https://uviewui.com/components/globalVariable.html
|
||||
// 自定义token头
|
||||
// 1️⃣ 获取本地 userInfo
|
||||
const userInfo = uni.getStorageSync('userInfo') || {};
|
||||
|
||||
// 2️⃣ 提取 userType
|
||||
const userType = userInfo.userType;
|
||||
config.header = {
|
||||
...config.header, // ⭐ 保留你外部传入的 header
|
||||
'content-type': 'application/json',
|
||||
...(userType ? { 'USERTYPE': userType } : {}) // 有 userType 才加
|
||||
}
|
||||
return config;
|
||||
const userType = userInfo.userType;
|
||||
config.header = {
|
||||
...config.header, // ⭐ 保留外部传入的 header
|
||||
'content-type': 'application/json',
|
||||
...(userType ? { 'USERTYPE': userType } : {}) // 有 userType 才加
|
||||
}
|
||||
return config;
|
||||
};
|
||||
// 响应拦截,判断状态码是否通过
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
@@ -34,17 +31,19 @@ const install = (Vue, vm) => {
|
||||
} else if(res.statusCode == 301) {
|
||||
vm.$u.toast('警告:' + res.msg);
|
||||
return false;
|
||||
} else if(res.statusCode == 401) {
|
||||
uni.navigateTo({
|
||||
url:'/pages-biz/login/login'
|
||||
})
|
||||
vm.$u.toast('认证失败,请重新登录')
|
||||
return false;
|
||||
} else if(res.statusCode == 403) {
|
||||
uni.navigateTo({
|
||||
url:'/pages-biz/login/login'
|
||||
})
|
||||
vm.$u.toast('认证失败,请重新登录')
|
||||
} else if(res.statusCode == 401 || res.statusCode == 403) {
|
||||
const currentPage = vm.$route.path;
|
||||
// 判断当前页面是否为登录页
|
||||
// 登录成功修改token与用户信息
|
||||
vm.$u.vuex('vuex_token', '');
|
||||
vm.$u.vuex('vuex_user', {});
|
||||
uni.removeStorageSync('userInfo');
|
||||
if (currentPage !== '/pages-biz/login/login') {
|
||||
uni.navigateTo({
|
||||
url: '/pages-biz/login/login'
|
||||
});
|
||||
vm.$u.toast('认证失败,请重新登录');
|
||||
}
|
||||
return false;
|
||||
} else if(res.statusCode == 500) {
|
||||
vm.$u.toast('请求错误:' + res.msg);
|
||||
@@ -56,21 +55,19 @@ const install = (Vue, vm) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Vue.prototype.$u.http.interceptor.responseError = (err) => {
|
||||
// err 是 uni.request 的 fail 对象
|
||||
// 超时一般是 err.errMsg 包含 timeout
|
||||
|
||||
if (err.errMsg && err.errMsg.includes('timeout')) {
|
||||
vm.$u.toast('请求超时,请稍后重试');
|
||||
} else {
|
||||
vm.$u.toast('网络异常,请检查网络');
|
||||
}
|
||||
|
||||
return Promise.reject(err);
|
||||
};
|
||||
// 请求错误拦截(超时/网络异常)
|
||||
Vue.prototype.$u.http.interceptor.responseError = (err) => {
|
||||
// err 是 uni.request 的 fail 对象
|
||||
// 超时一般是 err.errMsg 包含 timeout
|
||||
if (err.errMsg && err.errMsg.includes('timeout')) {
|
||||
vm.$u.toast('请求超时,请稍后重试');
|
||||
} else {
|
||||
vm.$u.toast('网络异常,请检查网络');
|
||||
}
|
||||
return Promise.reject(err);
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
install
|
||||
}
|
||||
}
|
||||
@@ -46,40 +46,40 @@ export default [
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
"name": '租金',
|
||||
"type": 'hierarchy',
|
||||
"submenu": [
|
||||
{
|
||||
"name": "不限",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "<1000元",
|
||||
"value": "0-1000"
|
||||
},
|
||||
{
|
||||
"name": "1000-1500元",
|
||||
"value": "1000-1500"
|
||||
},
|
||||
{
|
||||
"name": "1500-2000元",
|
||||
"value": "1500-2000"
|
||||
},
|
||||
{
|
||||
"name": "2000-3000元",
|
||||
"value": "2000-3000"
|
||||
},
|
||||
{
|
||||
"name": "3000-4500元",
|
||||
"value": "3000-4500"
|
||||
},
|
||||
{
|
||||
"name": ">4500元",
|
||||
"value": "4500"
|
||||
}
|
||||
]
|
||||
},
|
||||
// {
|
||||
// "name": '租金',
|
||||
// "type": 'hierarchy',
|
||||
// "submenu": [
|
||||
// {
|
||||
// "name": "不限",
|
||||
// "value": ""
|
||||
// },
|
||||
// {
|
||||
// "name": "<1000元",
|
||||
// "value": "0-1000"
|
||||
// },
|
||||
// {
|
||||
// "name": "1000-1500元",
|
||||
// "value": "1000-1500"
|
||||
// },
|
||||
// {
|
||||
// "name": "1500-2000元",
|
||||
// "value": "1500-2000"
|
||||
// },
|
||||
// {
|
||||
// "name": "2000-3000元",
|
||||
// "value": "2000-3000"
|
||||
// },
|
||||
// {
|
||||
// "name": "3000-4500元",
|
||||
// "value": "3000-4500"
|
||||
// },
|
||||
// {
|
||||
// "name": ">4500元",
|
||||
// "value": "4500"
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
"name": '筛选',
|
||||
"type": 'radio',
|
||||
@@ -110,11 +110,11 @@ export default [
|
||||
"submenu": [
|
||||
{
|
||||
"name": "简装",
|
||||
"value": "简装",
|
||||
"value": "简装"
|
||||
},
|
||||
{
|
||||
"name": "中装",
|
||||
"value": "中装",
|
||||
"value": "中装"
|
||||
},
|
||||
{
|
||||
"name": "精修",
|
||||
|
||||
Reference in New Issue
Block a user