增加数据缓存,去除部分请求的重复/
This commit is contained in:
@@ -8,13 +8,13 @@
|
||||
// const ROOTPATH2 = "https://video-h5.hnsiyao.cn"; //后台服务域名
|
||||
|
||||
// h5
|
||||
const ROOTPATH1 = "https://web.hnsiyao.cn/czg/"; //
|
||||
const ROOTPATH = "https://web.hnsiyao.cn/czg/"; //后台服务域名
|
||||
const ROOTPATH2 = "https://dj-h5.hnsiyao.cn"; //后台服务域名
|
||||
// const ROOTPATH1 = "https://web.hnsiyao.cn/czg/"; //
|
||||
// const ROOTPATH = "https://web.hnsiyao.cn/czg/"; //后台服务域名
|
||||
// const ROOTPATH2 = "https://dj-h5.hnsiyao.cn"; //后台服务域名
|
||||
|
||||
// const ROOTPATH1 = "https://web-api.hnsiyao.cn/czg/"; //
|
||||
// const ROOTPATH = "https://web-api.hnsiyao.cn/czg/"; //后台服务域名
|
||||
// const ROOTPATH2 = "https://video-h5.hnsiyao.cn"; //后台服务域名
|
||||
const ROOTPATH1 = "https://web-api.hnsiyao.cn/czg/"; //
|
||||
const ROOTPATH = "https://web-api.hnsiyao.cn/czg/"; //后台服务域名
|
||||
const ROOTPATH2 = "https://video-h5.hnsiyao.cn"; //后台服务域名
|
||||
|
||||
// const ROOTPATH1 = "http://192.168.1.5:8100/czg/"; //
|
||||
// const ROOTPATH = "http://192.168.1.5:8100/czg/"; //后台服务域名
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量
|
||||
import {APIHOST} from './config.js'
|
||||
import {cacheClearAll} from '@/store/cashe.js'
|
||||
const install = (Vue, vm) => {
|
||||
// 此为自定义配置参数,具体参数见上方说明
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
@@ -26,8 +27,8 @@ const install = (Vue, vm) => {
|
||||
// 所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
|
||||
const token = uni.getStorageSync('token');
|
||||
config.header.token = token;
|
||||
config.url=config.url.slice(0,1)==='/'?config.url.slice(1,config.url.length):config.url
|
||||
// config.header.Token = 'xxxxxx';
|
||||
|
||||
// 可以对某个url进行特别处理,此url参数为this.$u.get(url)中的url值
|
||||
// if(config.url == '/user/login') config.header.noToken = true;
|
||||
// 最后需要将config进行return
|
||||
@@ -38,6 +39,7 @@ const install = (Vue, vm) => {
|
||||
|
||||
// 响应拦截,判断状态码是否通过
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
console.log(res);
|
||||
if (res.code == 0) {
|
||||
// res为服务端返回值,可能有code,result等字段
|
||||
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
|
||||
@@ -75,6 +77,7 @@ const install = (Vue, vm) => {
|
||||
uni.removeStorageSync("isInvitation")
|
||||
uni.removeStorageSync("zhiFuBao")
|
||||
uni.removeStorageSync("zhiFuBaoName")
|
||||
cacheClearAll()
|
||||
// 此为uView的方法,详见路由相关文档
|
||||
vm.$u.route('/pages/login/login')
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import configdata from './config'
|
||||
import cache from './cache'
|
||||
|
||||
import {
|
||||
cacheClearAll
|
||||
} from '@/store/cashe.js'
|
||||
module.exports = {
|
||||
config: function(name) {
|
||||
var info = null;
|
||||
@@ -22,6 +24,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(info);
|
||||
return info;
|
||||
},
|
||||
logout: function() {
|
||||
@@ -47,17 +50,20 @@ module.exports = {
|
||||
uni.removeStorageSync("isInvitation")
|
||||
uni.removeStorageSync("zhiFuBao")
|
||||
uni.removeStorageSync("zhiFuBaoName")
|
||||
|
||||
cacheClearAll()
|
||||
uni.showToast({
|
||||
title: '用户信息失效,请重新登录!',
|
||||
icon: 'none'
|
||||
})
|
||||
uni.navigateTo({ url: "/pages/login/login" })
|
||||
|
||||
uni.navigateTo({
|
||||
url: "/pages/login/login"
|
||||
})
|
||||
},
|
||||
post: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST") + url;
|
||||
url = that.config("APIHOST") + url.replace(/^\//, "");
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
@@ -81,7 +87,7 @@ module.exports = {
|
||||
postT: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST1") + url;
|
||||
url = that.config("APIHOST1") + url.replace(/^\//, "");
|
||||
// let token = uni.getStorageSync("token");
|
||||
let token = uni.getStorageSync("token");
|
||||
if (token) {
|
||||
@@ -130,7 +136,7 @@ module.exports = {
|
||||
postJson: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/json";
|
||||
url = that.config("APIHOST1") + url;
|
||||
url = that.config("APIHOST1") + url.replace(/^\//, "");
|
||||
// let token = uni.getStorageSync("token");
|
||||
let token = uni.getStorageSync("token");
|
||||
if (token) {
|
||||
@@ -179,7 +185,8 @@ module.exports = {
|
||||
getT: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST1") + url;
|
||||
url = that.config("APIHOST1") + url.replace(/^\//, "");
|
||||
console.log(url);
|
||||
// let token = uni.getStorageSync("token");
|
||||
let token = uni.getStorageSync("token");
|
||||
if (token) {
|
||||
@@ -299,7 +306,8 @@ module.exports = {
|
||||
get: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST") + url;
|
||||
url = that.config("APIHOST") + url.replace(/^\//, "");
|
||||
console.log(url);
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
@@ -346,7 +354,7 @@ module.exports = {
|
||||
get1: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/json";
|
||||
url = that.config("APIHOST") + url;
|
||||
url = that.config("APIHOST") + url.replace(/^\//, "");
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
|
||||
Reference in New Issue
Block a user