first commit
This commit is contained in:
87
common/cache.js
Normal file
87
common/cache.js
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 缓存数据优化
|
||||
* var cache = require('utils/cache.js');
|
||||
* import cache from '../cache'
|
||||
* 使用方法 【
|
||||
* 一、设置缓存
|
||||
* string cache.put('k', 'string你好啊');
|
||||
* json cache.put('k', { "b": "3" }, 2);
|
||||
* array cache.put('k', [1, 2, 3]);
|
||||
* boolean cache.put('k', true);
|
||||
* 二、读取缓存
|
||||
* 默认值 cache.get('k')
|
||||
* string cache.get('k', '你好')
|
||||
* json cache.get('k', { "a": "1" })
|
||||
* 三、移除/清理
|
||||
* 移除: cache.remove('k');
|
||||
* 清理:cache.clear();
|
||||
* 】
|
||||
* @type {String}
|
||||
*/
|
||||
var postfix = '_mallStore'; // 缓存前缀
|
||||
/**
|
||||
* 设置缓存
|
||||
* @param {[type]} k [键名]
|
||||
* @param {[type]} v [键值]
|
||||
* @param {[type]} t [时间、单位秒]
|
||||
*/
|
||||
function put(k, v, t) {
|
||||
uni.setStorageSync(k, v)
|
||||
var seconds = parseInt(t);
|
||||
if (seconds > 0) {
|
||||
var timestamp = Date.parse(new Date());
|
||||
timestamp = timestamp / 1000 + seconds;
|
||||
uni.setStorageSync(k + postfix, timestamp + "")
|
||||
} else {
|
||||
uni.removeStorageSync(k + postfix)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取缓存
|
||||
* @param {[type]} k [键名]
|
||||
* @param {[type]} def [获取为空时默认]
|
||||
*/
|
||||
function get(k, def) {
|
||||
var deadtime = parseInt(uni.getStorageSync(k + postfix))
|
||||
if (deadtime) {
|
||||
if (parseInt(deadtime) < Date.parse(new Date()) / 1000) {
|
||||
if (def) {
|
||||
return def;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
var res = uni.getStorageSync(k);
|
||||
if (res) {
|
||||
return res;
|
||||
} else {
|
||||
if (def == undefined || def == "") {
|
||||
def = false;
|
||||
}
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
function remove(k) {
|
||||
uni.removeStorageSync(k);
|
||||
uni.removeStorageSync(k + postfix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有缓存
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
function clear() {
|
||||
uni.clearStorageSync();
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
put: put,
|
||||
get: get,
|
||||
remove: remove,
|
||||
clear: clear,
|
||||
}
|
||||
29
common/config.js
Normal file
29
common/config.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const ROOTPATH1 = "https://duanju.xianmxkj.com/sqx_fast"; //
|
||||
const ROOTPATH = "https://duanju.xianmxkj.com/sqx_fast"; //后台服务域名
|
||||
const ROOTPATH2 = "https://duanju.xianmxkj.com"; //后台服务域名
|
||||
|
||||
// const ROOTPATH1 = location.origin + "/sqx_fast"; //
|
||||
// const ROOTPATH = location.origin + "/sqx_fast"; //后台服务域名
|
||||
// const ROOTPATH2 = location.origin; //后台服务域名
|
||||
|
||||
// const ROOTPATH1 = "https://duanju12.xianmxkj.com/sqx_fast"; //
|
||||
// const ROOTPATH = "https://duanju12.xianmxkj.com/sqx_fast"; //后台服务域名
|
||||
// const ROOTPATH2 = "https://duanju12.xianmxkj.com"; //后台服务域名
|
||||
|
||||
// const ROOTPATH1 = "https://wap.xingqiu1985.com/sqx_fast"; //
|
||||
// const ROOTPATH = "https://wap.xingqiu1985.com/sqx_fast"; //后台服务域名
|
||||
// const ROOTPATH2 = "https://wap.xingqiu1985.com"; //后台服务域名
|
||||
|
||||
|
||||
// const ROOTPATH1 = "https://jc.118zp.com/sqx_fast"; //
|
||||
// const ROOTPATH = "https://jc.118zp.com/sqx_fast"; //后台服务域名
|
||||
// const ROOTPATH2 = "https://jc.118zp.com"; //后台服务域名
|
||||
|
||||
// const ROOTPATH1 = "http://192.168.0.132:8100/sqx_fast"; //后台服务域名
|
||||
// const ROOTPATH = "http://192.168.0.132:8100/sqx_fast"; //后台服务域名
|
||||
// const ROOTPATH2 = "http://192.168.0.132:8100"; //后台服务域名
|
||||
module.exports = {
|
||||
APIHOST: ROOTPATH,
|
||||
APIHOST1: ROOTPATH1,
|
||||
APIHOST2: ROOTPATH2
|
||||
};
|
||||
120
common/http.api.js
Normal file
120
common/http.api.js
Normal file
@@ -0,0 +1,120 @@
|
||||
// 如果没有通过拦截器配置域名的话,可以在这里写上完整的URL(加上域名部分)
|
||||
// let hotSearchUrl = 'http://192.168.1.16:8080/sqx_fast/';
|
||||
// let indexUrl = 'http://192.168.1.16:8080/sqx_fast/';
|
||||
|
||||
// 此处第二个参数vm,就是我们在页面使用的this,你可以通过vm获取vuex等操作,更多内容详见uView对拦截器的介绍部分:
|
||||
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
|
||||
const install = (Vue, vm) => {
|
||||
let wxLogin = (params = {}) => vm.$u.get('app/Login/wxLogin', params); //微信小程序登陆
|
||||
let insertWxUser = (params = {}) => vm.$u.post('app/Login/insertWxUser', params); //小程序登录新增或修改个人信息
|
||||
let selectPhone = (params = {}) => vm.$u.post('app/Login/selectPhone', params); //获取手机号
|
||||
let userVip = (params = {}) => vm.$u.get('app/UserVip/selectUserVip', params); //用户会员信息
|
||||
let userinfo = (params = {}) => vm.$u.get('app/user/selectUserById', params); //个人信息
|
||||
let updateUser = (params = {}) => vm.$u.post('app/user/updateUser', params); //修改个人信息
|
||||
|
||||
let bannerList = (params = {}) => vm.$u.get('banner/selectBannerList', params); //轮播图
|
||||
let gaidList = (params = {}) => vm.$u.get('app/banner/clickBanner', params); //金刚图列表
|
||||
let msg = (params = {}) => vm.$u.get('app/message/selectMessage', params); //公告
|
||||
let selectBannerPage = (params = {}) => vm.$u.get('app/banner/selectBannerPage', params); //剧情壁纸
|
||||
|
||||
let courseClass = (params = {}) => vm.$u.get('app/courseClassification/selectClassification', params); //资源分类
|
||||
let courseList = (params = {}) => vm.$u.get('app/course/selectCourse', params); //资源列表
|
||||
let courseDet = (params = {}) => vm.$u.get('app/course/selectCourseById', params); //资源详情
|
||||
let courseComment = (params = {}) => vm.$u.get('app/courseComment/selectCourseComment', params); //获取资源评论列表
|
||||
let insertComment = (params = {}) => vm.$u.post('app/courseComment/insertCourseComment', params); //发表评论
|
||||
let courseCollect = (params = {}) => vm.$u.post('app/courseCollect/insertCourseCollect', params); //收藏资源
|
||||
let courseOrder = (params = {}) => vm.$u.get('/app/order/insertCourseOrders', params); //获取订单号
|
||||
let updateGood = (params = {}) => vm.$u.get('/app/courseComment/updateGoodsNum', params); //获取点赞
|
||||
|
||||
let SearchList = (params = {}) => vm.$u.get('app/appSearchController/selectAppSearchNum', params); //热搜记录
|
||||
let SearchDet = (params = {}) => vm.$u.get('app/appSearchController/deleteAppSearch', params); //删除历史记录
|
||||
let search = (params = {}) => vm.$u.get('app/course/selectCourseTitle', params); //搜索
|
||||
let searchs = (params = {}) => vm.$u.get('app/course/selectCourseTitles', params); //搜索
|
||||
// app/course/selectCourse
|
||||
|
||||
// 学习
|
||||
let latelyCourse = (params = {}) => vm.$u.get('app/CourseUser/selectLatelyCourse', params); //最近学习
|
||||
let selectCourse = (params = {}) => vm.$u.get('app/CourseUser/selectCourseUser', params); //已购资源
|
||||
let collectList = (params = {}) => vm.$u.get('app/courseCollect/selectByUserId', params); //资源收藏列表
|
||||
|
||||
// 我的
|
||||
let orderList = (params = {}) => vm.$u.get('app/order/selectOrderByUserId', params); //我的订单
|
||||
let inviter = (params = {}) => vm.$u.get('app/invite/selectInviteByUserIdLists', params); //我的邀请
|
||||
let moneyList = (params = {}) => vm.$u.get('app/invite/queryUserMoneyDetails', params); //钱包明细
|
||||
let queryInviter = (params = {}) => vm.$u.get('app/invite/selectInviteMoney', params); //邀请战绩
|
||||
let vipDet = (params = {}) => vm.$u.get('app/VipDetails/selectVipDetails', params); //会员价格列表
|
||||
let VipOrders = (params = {}) => vm.$u.get('app/order/insertVipOrders', params); //购买会员
|
||||
let integral = (params = {}) => vm.$u.get('app/integral/selectByUserId', params); //查看用户积分
|
||||
let integralDet = (params = {}) => vm.$u.get('app/integral/details', params); //查看积分获取列表
|
||||
let message = (params = {}) => vm.$u.get('app/message/selectMessageByUserId', params); //查询用户消息
|
||||
let wxPay = (params = {}) => vm.$u.post('app/wxPay/wxPayJsApiOrder', params); //微信支付
|
||||
|
||||
let userMoney = (params = {}) => vm.$u.get('app/invite/selectUserMoney', params); //查看钱包
|
||||
let cashMoney = (params = {}) => vm.$u.get('app/cash/cashMoney', params); //申请提现
|
||||
let selectPay = (params = {}) => vm.$u.get('app/cash/selectPayDetails', params); //提现记录
|
||||
let moneyDet = (params = {}) => vm.$u.get('app/cash/queryUserMoneyDetails', params); //钱包明细
|
||||
let type = (params = {}) => vm.$u.get('app/common/type', params); //钱包明细
|
||||
|
||||
|
||||
let help = (params = {}) => vm.$u.get('app/helpWord/selectHelpList', params); //帮助中心
|
||||
let helpDet = (params = {}) => vm.$u.get('app/helpWord/selectHelpWordDetails', params); //帮助中心 详情
|
||||
|
||||
//获取视频
|
||||
let selectCourseDetailsById = (params = {}) => vm.$u.get('app/course/selectCourseDetailsById', params);
|
||||
|
||||
// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
|
||||
vm.$u.api = {
|
||||
wxLogin,
|
||||
insertWxUser,
|
||||
selectPhone,
|
||||
userVip,
|
||||
userinfo,
|
||||
updateUser,
|
||||
|
||||
bannerList,
|
||||
gaidList,
|
||||
msg,
|
||||
selectBannerPage,
|
||||
courseClass,
|
||||
courseList,
|
||||
courseDet,
|
||||
courseComment,
|
||||
insertComment,
|
||||
collectList,
|
||||
updateGood,
|
||||
|
||||
SearchList,
|
||||
SearchDet,
|
||||
search,
|
||||
searchs,
|
||||
|
||||
courseCollect,
|
||||
courseOrder,
|
||||
latelyCourse,
|
||||
selectCourse,
|
||||
|
||||
orderList,
|
||||
inviter,
|
||||
queryInviter,
|
||||
vipDet,
|
||||
integral,
|
||||
integralDet,
|
||||
message,
|
||||
VipOrders,
|
||||
wxPay,
|
||||
moneyList,
|
||||
userMoney,
|
||||
cashMoney,
|
||||
selectPay,
|
||||
moneyDet,
|
||||
type,
|
||||
|
||||
help,
|
||||
helpDet,
|
||||
selectCourseDetailsById
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
install
|
||||
}
|
||||
80
common/http.interceptor.js
Normal file
80
common/http.interceptor.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量
|
||||
import {APIHOST} from './config.js'
|
||||
const install = (Vue, vm) => {
|
||||
// 此为自定义配置参数,具体参数见上方说明
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
// baseUrl: 'http://192.168.0.119:8080/sqx_fast',
|
||||
baseUrl: APIHOST,
|
||||
// loadingText: '努力加载中~',
|
||||
loadingTime: 800,
|
||||
});
|
||||
|
||||
// 请求拦截,配置Token等参数
|
||||
Vue.prototype.$u.http.interceptor.request = (config) => {
|
||||
// 引用token
|
||||
// 方式一,存放在vuex的token,假设使用了uView封装的vuex方式
|
||||
// 见:https://uviewui.com/components/globalVariable.html
|
||||
// config.header.token = vm.token;
|
||||
|
||||
// 方式二,如果没有使用uView封装的vuex方法,那么需要使用$store.state获取
|
||||
// config.header.token = vm.$store.state.token;
|
||||
|
||||
// 方式三,如果token放在了globalData,通过getApp().globalData获取
|
||||
// config.header.token = getApp().globalData.username;
|
||||
|
||||
// 方式四,如果token放在了Storage本地存储中,拦截是每次请求都执行的
|
||||
// 所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
|
||||
const token = uni.getStorageSync('token');
|
||||
config.header.token = token;
|
||||
// config.header.Token = 'xxxxxx';
|
||||
|
||||
// 可以对某个url进行特别处理,此url参数为this.$u.get(url)中的url值
|
||||
// if(config.url == '/user/login') config.header.noToken = true;
|
||||
// 最后需要将config进行return
|
||||
return config;
|
||||
// 如果return一个false值,则会取消本次请求
|
||||
// if(config.url == '/user/rest') return false; // 取消某次请求
|
||||
}
|
||||
|
||||
// 响应拦截,判断状态码是否通过
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
if (res.code == 0) {
|
||||
// res为服务端返回值,可能有code,result等字段
|
||||
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
|
||||
// 如果配置了originalData为true,请留意这里的返回值
|
||||
return res;
|
||||
} else if (res.code == 201) {
|
||||
// 假设201为token失效,这里跳转登录
|
||||
vm.$u.toast('验证失败,请重新登录');
|
||||
setTimeout(() => {
|
||||
// 此为uView的方法,详见路由相关文档
|
||||
vm.$u.route('/pages/login/login')
|
||||
}, 1500)
|
||||
return false;
|
||||
} else if (res.code == 401) {
|
||||
// 假设201为token失效,这里跳转登录
|
||||
vm.$u.toast('验证失败,请重新登录');
|
||||
uni.removeStorageSync("token")
|
||||
uni.removeStorageSync("userId")
|
||||
uni.removeStorageSync("phone")
|
||||
uni.removeStorageSync("openid")
|
||||
uni.removeStorageSync("userName")
|
||||
uni.removeStorageSync("relation")
|
||||
uni.removeStorageSync("relation_id")
|
||||
uni.removeStorageSync("isInvitation")
|
||||
uni.removeStorageSync("zhiFuBao")
|
||||
uni.removeStorageSync("zhiFuBaoName")
|
||||
// 此为uView的方法,详见路由相关文档
|
||||
vm.$u.route('/pages/login/login')
|
||||
return false;
|
||||
} else {
|
||||
// 如果返回false,则会调用Promise的reject回调,
|
||||
// 并将进入this.$u.post(url).then().catch(res=>{})的catch回调中,res为服务端的返回值
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
install
|
||||
}
|
||||
356
common/httpRequest.js
Normal file
356
common/httpRequest.js
Normal file
@@ -0,0 +1,356 @@
|
||||
import configdata from './config'
|
||||
import cache from './cache'
|
||||
|
||||
module.exports = {
|
||||
config: function(name) {
|
||||
var info = null;
|
||||
if (name) {
|
||||
var name2 = name.split("."); //字符分割
|
||||
if (name2.length > 1) {
|
||||
info = configdata[name2[0]][name2[1]] || null;
|
||||
} else {
|
||||
info = configdata[name] || null;
|
||||
}
|
||||
if (info == null) {
|
||||
let web_config = cache.get("web_config");
|
||||
if (web_config) {
|
||||
if (name2.length > 1) {
|
||||
info = web_config[name2[0]][name2[1]] || null;
|
||||
} else {
|
||||
info = web_config[name] || null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return info;
|
||||
},
|
||||
logout: function() {
|
||||
let that = this;
|
||||
uni.removeStorageSync("token")
|
||||
uni.removeStorageSync("userId")
|
||||
uni.removeStorageSync("phone")
|
||||
uni.removeStorageSync("openid")
|
||||
uni.removeStorageSync("userName")
|
||||
uni.removeStorageSync("relation")
|
||||
uni.removeStorageSync("relation_id")
|
||||
uni.removeStorageSync("isInvitation")
|
||||
uni.removeStorageSync("zhiFuBao")
|
||||
uni.removeStorageSync("zhiFuBaoName")
|
||||
|
||||
uni.showToast({
|
||||
title: '用户信息失效,请重新登录!',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
},
|
||||
post: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST") + url;
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postT: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST1") + url;
|
||||
// let token = uni.getStorageSync("token");
|
||||
let token = uni.getStorageSync("token");
|
||||
if (token) {
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header,
|
||||
"token": token
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header,
|
||||
},
|
||||
success: function(result) {
|
||||
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
postJson: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/json";
|
||||
url = that.config("APIHOST1") + url;
|
||||
// let token = uni.getStorageSync("token");
|
||||
let token = uni.getStorageSync("token");
|
||||
if (token) {
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header,
|
||||
"token": token
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header,
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
getT: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST1") + url;
|
||||
// let token = uni.getStorageSync("token");
|
||||
let token = uni.getStorageSync("token");
|
||||
if (token) {
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": header,
|
||||
"token": token
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
posts: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postF: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/json";
|
||||
url = that.config("APIHOST") + url;
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postFs: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/json";
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
get: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = that.config("APIHOST") + url;
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
getJd: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": header
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
get1: function(url, data, header) {
|
||||
let that = this;
|
||||
header = header || "application/json";
|
||||
url = that.config("APIHOST") + url;
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
that.logout();
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
207
common/queue.js
Normal file
207
common/queue.js
Normal file
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
*
|
||||
* @author maxd
|
||||
* @date 2019.8.1
|
||||
*/
|
||||
module.exports = {
|
||||
//微信的appId
|
||||
getWxAppid() {
|
||||
return 'wxef277af6b5cf522e'
|
||||
},
|
||||
//全局邀请码
|
||||
getInvitation() {
|
||||
return uni.getStorageSync("publicRelation")
|
||||
},
|
||||
//获取APP下载地址
|
||||
getAppDownUrl() {
|
||||
return uni.getStorageSync("appurl")
|
||||
},
|
||||
//全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
|
||||
publicYuMing() {
|
||||
return 'https://duanju.xianmxkj.com'
|
||||
},
|
||||
//全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
|
||||
publicYuMingAll() {
|
||||
return 'https://duanju.xianmxkj.com/sqx_fast'
|
||||
},
|
||||
minMoney() {
|
||||
return uni.getStorageSync("minMoney") ? uni.getStorageSync("minMoney") : '0.3'
|
||||
},
|
||||
invitaionNum() {
|
||||
return uni.getStorageSync("invitaionNum")
|
||||
},
|
||||
maxMoney() {
|
||||
return uni.getStorageSync("maxMoney") ? uni.getStorageSync("maxMoney") : '0.7'
|
||||
},
|
||||
teamMoney() {
|
||||
return uni.getStorageSync("teamMoney")
|
||||
},
|
||||
logout() {
|
||||
this.remove("token");
|
||||
this.remove("userId");
|
||||
this.remove("mobile");
|
||||
this.remove("openid");
|
||||
this.remove("nickName");
|
||||
this.remove("relation");
|
||||
this.remove("avatar");
|
||||
this.remove("relation_id");
|
||||
this.remove("isInvitation");
|
||||
this.remove("member");
|
||||
this.remove("sex");
|
||||
},
|
||||
loginClear() {
|
||||
this.remove("token");
|
||||
this.remove("userId");
|
||||
this.remove("mobile");
|
||||
this.remove("nickName");
|
||||
this.remove("avatar");
|
||||
this.remove("relation_id");
|
||||
this.remove("isInvitation");
|
||||
this.remove("member");
|
||||
this.remove("sex");
|
||||
},
|
||||
showLoading(title) {
|
||||
uni.showLoading({
|
||||
title: title
|
||||
});
|
||||
},
|
||||
showToast(title) {
|
||||
uni.showToast({
|
||||
title: title,
|
||||
mask: false,
|
||||
duration: 4000,
|
||||
icon: "none"
|
||||
});
|
||||
},
|
||||
getSearchKeys: function(key) {
|
||||
let list = "套套,情趣用品,避孕,男用,女用,成人用品,保健品,冈本 杜蕾斯 杰士邦 第六感 倍力乐 诺丝 多乐士 斯香妮 双一 雨蝶 玛尼仕,充气娃娃,娃娃充气 阴蒂 刺激 超薄 螺纹 震动 润滑 女液体 延时 ";
|
||||
return list.includes(key);
|
||||
},
|
||||
setJson: function(key, value) {
|
||||
let jsonString = JSON.stringify(value);
|
||||
try {
|
||||
uni.setStorageSync(key, jsonString);
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
},
|
||||
setData: function(key, value) {
|
||||
try {
|
||||
uni.setStorageSync(key, value);
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
},
|
||||
getData: function(key) {
|
||||
try {
|
||||
const value = uni.getStorageSync(key);
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
|
||||
},
|
||||
getJson: function(key) {
|
||||
try {
|
||||
const value = uni.getStorageSync(key);
|
||||
if (value) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
|
||||
},
|
||||
clear: function() {
|
||||
uni.clearStorage();
|
||||
},
|
||||
get: function(key) { //获取队列里面全部的数据
|
||||
let data = this.getJson(key);
|
||||
if (data instanceof Array) {
|
||||
return data;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
insert: function(param) { //队列插入数据
|
||||
param.capacityNum = param.capacityNum || 100; //队列容量 默认队列中超过100条数据,自动删除尾部
|
||||
let data = this.getJson(param.key);
|
||||
if (data instanceof Array) {
|
||||
if (data.length > param.capacityNum) {
|
||||
let total = data.length - param.capacityNum;
|
||||
for (let i = 0; i < total; i++) {
|
||||
data.pop();
|
||||
}
|
||||
}
|
||||
data.unshift(param.value);
|
||||
} else {
|
||||
data = [];
|
||||
data.push(param.value);
|
||||
}
|
||||
this.setJson(param.key, data);
|
||||
},
|
||||
removeItem: function(key, itemIds) { //提供itemIds数组 批量删除队列中的某项数据
|
||||
let data = this.getJson(key);
|
||||
if (data instanceof Array) {
|
||||
for (let i = 0; i < itemIds.length; i++) {
|
||||
for (let p = 0; p < data.length; p++) {
|
||||
if (itemIds[i] === data[p].itemid) {
|
||||
data.splice(p, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setJson(key, data);
|
||||
}
|
||||
},
|
||||
isExist: function(key, itemId) { //检测某条数据在队列中是否存在
|
||||
let data = this.getJson(key);
|
||||
if (data instanceof Array) {
|
||||
for (let p = 0; p < data.length; p++) {
|
||||
if (itemId === data[p].itemid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isExistPdd: function(key, itemId) { //检测某条数据在队列中是否存在
|
||||
let data = this.getJson(key);
|
||||
if (data instanceof Array) {
|
||||
for (let p = 0; p < data.length; p++) {
|
||||
if (itemId === data[p].goodsId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isExistJd: function(key, itemId) { //检测某条数据在队列中是否存在
|
||||
let data = this.getJson(key);
|
||||
if (data instanceof Array) {
|
||||
for (let p = 0; p < data.length; p++) {
|
||||
if (itemId === data[p].skuId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
remove: function(key) { //删除某条队列
|
||||
try {
|
||||
uni.removeStorageSync(key);
|
||||
//localStorage.removeItem(key)
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
},
|
||||
getCount: function(key) { //获取队列中全部数据数量
|
||||
|
||||
let data = this.getJson(key);
|
||||
if (data instanceof Array) {
|
||||
return data.length;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user