首次提交
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,
|
||||
}
|
||||
18
common/config.js
Normal file
18
common/config.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const ROOTPATHA = "https://tcwm.xianmaxiong.com/sqx_fast";
|
||||
const ROOTPATH = "https://tcwm.xianmaxiong.com/sqx_fast";
|
||||
const ROOTPATH1 = "https://tcwm.xianmaxiong.com/sqx_fast";
|
||||
const ROOTPATH2 = "wss://tcwm.xianmaxiong.com/wss/websocket/"; //联系客服
|
||||
const ROOTPATH3 = "wss://tcwm.xianmaxiong.com/wss/ordersChat/"; //聊天
|
||||
|
||||
// const ROOTPATHA = "http://192.168.0.132:8171/sqx_fast";
|
||||
// const ROOTPATH = "http://192.168.0.132:8171/sqx_fast";
|
||||
// const ROOTPATH1 = "http://192.168.0.132:8171/sqx_fast";
|
||||
// const ROOTPATH2 = "ws://192.168.0.128:8171/sqx_fast/websocket/"; //联系客服
|
||||
// const ROOTPATH3 = "ws://192.168.0.128:8171/sqx_fast/ordersChat/"; //聊天
|
||||
module.exports = {
|
||||
APIHOST: ROOTPATH,
|
||||
APIHOST1: ROOTPATH1,
|
||||
WSHOST: ROOTPATH2,
|
||||
WSHOST1: ROOTPATH3,
|
||||
APIHOSTA: ROOTPATHA,
|
||||
};
|
||||
559
common/httpRequest.js
Normal file
559
common/httpRequest.js
Normal file
@@ -0,0 +1,559 @@
|
||||
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;
|
||||
},
|
||||
post: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOST") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
// let token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzMwIiwiaWF0IjoxNjQzMTAyNTcyLCJleHAiOjE2NDU2OTQ1NzJ9.UJhS7Nmj495d-CfCNm9VTenuwxV0z4J8Vl9CAlftXt89zrmQtebXDLmS8f25l8He_dnTUxAfjlKVWSsyYnKs6A'
|
||||
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 && token) {
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postT: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOST1") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
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 && token) {
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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) {
|
||||
header = header || "application/json";
|
||||
url = this.config("APIHOST1") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
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 && token) {
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
getT: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOST1") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
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 && token) {
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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) {
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
get: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOST") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
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 && token) {
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
getMsg: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOST2") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
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 && token) {
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 家政
|
||||
getJ: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOSTJ") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
header: {
|
||||
"content-type": header,
|
||||
"token": token
|
||||
},
|
||||
success: function(result) {
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 商户接口
|
||||
getA: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOSTA") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
// let token =uni.getStorageSync("shopToken")?uni.getStorageSync("shopToken"):'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzMwIiwiaWF0IjoxNjQzMTAyNTcyLCJleHAiOjE2NDU2OTQ1NzJ9.UJhS7Nmj495d-CfCNm9VTenuwxV0z4J8Vl9CAlftXt89zrmQtebXDLmS8f25l8He_dnTUxAfjlKVWSsyYnKs6A'
|
||||
|
||||
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 && token) {
|
||||
uni.removeStorageSync("shopToken")
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postA: function(url, data, header) {
|
||||
header = header || "application/x-www-form-urlencoded";
|
||||
url = this.config("APIHOSTA") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
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 && token) {
|
||||
uni.removeStorageSync("shopToken")
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postJsonA: function(url, data, header) {
|
||||
header = header || "application/json";
|
||||
url = this.config("APIHOSTA") + url;
|
||||
let token = uni.getStorageSync("shopToken");
|
||||
// let token =uni.getStorageSync("shopToken")?uni.getStorageSync("shopToken"):'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzMwIiwiaWF0IjoxNjQzMTAyNTcyLCJleHAiOjE2NDU2OTQ1NzJ9.UJhS7Nmj495d-CfCNm9VTenuwxV0z4J8Vl9CAlftXt89zrmQtebXDLmS8f25l8He_dnTUxAfjlKVWSsyYnKs6A'
|
||||
|
||||
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 && token) {
|
||||
uni.removeStorageSync("shopToken")
|
||||
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.showModal({
|
||||
title: '提示',
|
||||
content: '用户信息失效,请重新登录!',
|
||||
showCancel: false, // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true // 是否显示取消按钮,默认为 true
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/my/loginphone'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
190
common/queue.js
Normal file
190
common/queue.js
Normal file
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
*
|
||||
* @author maxd
|
||||
* @date 2019.8.1
|
||||
*/
|
||||
module.exports = {
|
||||
getUUID () {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
||||
return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
|
||||
})
|
||||
},
|
||||
//微信的appId
|
||||
getWxAppid() {
|
||||
return 'wx41da4b0848b8baae'
|
||||
},
|
||||
//全局邀请码
|
||||
getInvitation() {
|
||||
return uni.getStorageSync("publicRelation")
|
||||
},
|
||||
//获取APP下载地址
|
||||
getAppDownUrl() {
|
||||
return uni.getStorageSync("appurl")
|
||||
},
|
||||
//全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
|
||||
publicYuMing() {
|
||||
return 'https://diancan.xianmxkj.com'
|
||||
},
|
||||
logout() {
|
||||
this.remove("token");
|
||||
this.remove("userId");
|
||||
this.remove("mobile");
|
||||
this.remove("openid");
|
||||
this.remove("nickName");
|
||||
this.remove("relation");
|
||||
this.remove("image_url");
|
||||
this.remove("relation_id");
|
||||
this.remove("isInvitation");
|
||||
this.remove("member");
|
||||
},
|
||||
loginClear() {
|
||||
this.remove("token");
|
||||
this.remove("userId");
|
||||
this.remove("mobile");
|
||||
this.remove("nickName");
|
||||
this.remove("image_url");
|
||||
this.remove("relation_id");
|
||||
this.remove("isInvitation");
|
||||
this.remove("member");
|
||||
},
|
||||
showLoading(title) {
|
||||
uni.showLoading({
|
||||
title: title
|
||||
});
|
||||
},
|
||||
showToast(title) {
|
||||
uni.showToast({
|
||||
title: title,
|
||||
mask: false,
|
||||
duration: 2000,
|
||||
icon: "none"
|
||||
});
|
||||
},
|
||||
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;
|
||||
},
|
||||
};
|
||||
14
common/share.js
Normal file
14
common/share.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export default {
|
||||
onShareAppMessage(res) { //发送给朋友
|
||||
return {
|
||||
title: uni.getStorageSync('tuiguang'),
|
||||
imageUrl: uni.getStorageSync('tuiguangImg'),
|
||||
}
|
||||
},
|
||||
onShareTimeline(res) { //分享到朋友圈
|
||||
return {
|
||||
title: uni.getStorageSync('tuiguang'),
|
||||
imageUrl: uni.getStorageSync('tuiguangImg'),
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user