mirror of
http://36.133.248.69:3088/admin/RentWeAppFront.git
synced 2026-03-07 17:32:25 +08:00
完成大体功能和样式
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// 全局配置文件
|
||||
// let baseUrl = 'https://sourcebyte.vip';
|
||||
// let staticUrl = 'https://sourcebyte.vip';
|
||||
let baseUrl = 'http://localhost:8089';
|
||||
let staticUrl = 'http://localhost:8089';
|
||||
// let baseUrl = 'http://219.138.32.164:8089';
|
||||
// let baseUrl = 'http://localhost:3000/api';
|
||||
// let staticUrl = 'http://localhost:3000';
|
||||
let baseUrl = 'https://www.wujiaguotou.com/api';
|
||||
let staticUrl = 'https://www.wujiaguotou.com';
|
||||
// 版本号 用于更新
|
||||
let version = 1;
|
||||
// vuex_version版本号 用于显示
|
||||
|
||||
@@ -5,16 +5,23 @@ const install = (Vue, vm) => {
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
// baseUrl打包app时放开,h5模式下会和vue.config.js代理冲突,导致失效
|
||||
baseUrl: config.baseUrl,
|
||||
|
||||
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'
|
||||
'content-type': 'application/json',
|
||||
...(userType ? { 'USERTYPE': userType } : {}) // 有 userType 才加
|
||||
}
|
||||
return config;
|
||||
};
|
||||
@@ -22,25 +29,25 @@ const install = (Vue, vm) => {
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
// 如果把originalData设置为了true,这里得到将会是服务器返回的所有的原始数据
|
||||
// 判断可能变成了res.statueCode,或者res.data.code之类的,请打印查看结果
|
||||
if(res.code == 200) {
|
||||
return res;
|
||||
} else if(res.code == 301) {
|
||||
if(res.statusCode == 200) {
|
||||
return res.data;
|
||||
} else if(res.statusCode == 301) {
|
||||
vm.$u.toast('警告:' + res.msg);
|
||||
return false;
|
||||
} else if(res.code == 401) {
|
||||
uni.reLaunch({
|
||||
url:'../login/login'
|
||||
} else if(res.statusCode == 401) {
|
||||
uni.navigateTo({
|
||||
url:'/pages-biz/login/login'
|
||||
})
|
||||
vm.$u.toast('认证失败,请重新登录')
|
||||
return false;
|
||||
} else if(res.code == 403) {
|
||||
uni.reLaunch({
|
||||
url:'../login/login'
|
||||
} else if(res.statusCode == 403) {
|
||||
uni.navigateTo({
|
||||
url:'/pages-biz/login/login'
|
||||
})
|
||||
vm.$u.toast('认证失败,请重新登录')
|
||||
return false;
|
||||
} else if(res.code == 500) {
|
||||
vm.$u.toast('错误:' + res.msg);
|
||||
} else if(res.statusCode == 500) {
|
||||
vm.$u.toast('请求错误:' + res.msg);
|
||||
return false;
|
||||
} else {
|
||||
// 其他情况都认为是不合法的
|
||||
@@ -48,6 +55,20 @@ const install = (Vue, vm) => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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 {
|
||||
|
||||
38
common/utils/auth.js
Normal file
38
common/utils/auth.js
Normal file
@@ -0,0 +1,38 @@
|
||||
export function getToken() {
|
||||
const lifeData = uni.getStorageSync('lifeData') || {}
|
||||
const token = lifeData.vuex_token
|
||||
return token;
|
||||
}
|
||||
|
||||
export function checkToken(token) {
|
||||
if (!token || (typeof token === 'object' && Object.keys(token).length === 0)) {
|
||||
uni.reLaunch({
|
||||
url: '/pages-biz/login/login'
|
||||
})
|
||||
return Promise.reject('no token')
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.$u.get('/login/checkExpiration', {}, {
|
||||
WT: token
|
||||
}).then(res => {
|
||||
if (res.data) {
|
||||
uni.reLaunch({
|
||||
url: '/pages-biz/login/login'
|
||||
})
|
||||
reject('token expired')
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.reLaunch({
|
||||
url: '/pages-biz/login/login'
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function getUserType(){
|
||||
let userInfo = uni.getStorageSync('userInfo')
|
||||
return userInfo.userType
|
||||
}
|
||||
13
common/utils/ras.js
Normal file
13
common/utils/ras.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import JSEncrypt from 'jsencrypt'
|
||||
|
||||
const PUBLIC_KEY = `
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk6Kvq4tCfQJFO3xqMN86ra6YPKEGgDJGVNAo8HAb9ZxL8fgckaHN4wpI8D8D0HDP/Xn8ZrS7wZFSAecUmWBtyBjZdMOdSMZm1LdX036+XpyGVktsrE15n85KG9+P4H4he9ZbiPPMGYvmkn/zaxMxUagSHhPpvrwRMovA8onKzSL67CFOWl95HXxhJ1GhlKIQVBz9R5OsHhwZFfPu2xtajCtiGtF2zjF3ojwpLNca+ADC6mZufRV/MD1+gMMS5GcwG5xALDyG+Aqv4xHto30SGks3FJ9k9bAwA8vyOU8SBeG8fW8lbO9XrtbupmxUm5RnSEtNUy/iUuO1hEmpSqQfBQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
`
|
||||
|
||||
export function rsaEncrypt(text) {
|
||||
const encryptor = new JSEncrypt()
|
||||
encryptor.setPublicKey(PUBLIC_KEY)
|
||||
return encryptor.encrypt(text)
|
||||
}
|
||||
@@ -16,6 +16,16 @@ export default [{
|
||||
"value": ""
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": '街道',
|
||||
"type": 'hierarchy',
|
||||
"submenu": [
|
||||
{
|
||||
"name": "不限",
|
||||
"value": ""
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": '方式',
|
||||
|
||||
16
common/utils/text.js
Normal file
16
common/utils/text.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 文本省略处理
|
||||
* @param {String} text 原始文本
|
||||
* @param {Number} maxLen 最大显示字数
|
||||
* @param {String} suffix 省略后缀,默认 ...
|
||||
* @returns {String}
|
||||
*/
|
||||
function ellipsisText(text, maxLen = 20, suffix = '...') {
|
||||
if (!text) return '';
|
||||
if (text.length <= maxLen) return text;
|
||||
return text.slice(0, maxLen) + suffix;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ellipsisText
|
||||
};
|
||||
Reference in New Issue
Block a user