首次提交
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,
|
||||
}
|
||||
16
common/config.js
Normal file
16
common/config.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const ROOTPATH1 = "https://takeoutservice.sxczgkj.cn/sqx_fast";
|
||||
const ROOTPATH = "https://takeoutservice.sxczgkj.cn/sqx_fast";
|
||||
const ROOTPATH2 = "wss://tcwm.xianmaxiong.com/wss/websocket/"; //联系客服
|
||||
const ROOTPATH3 = "wss://tcwm.xianmaxiong.com/wss/ordersChat/"; //聊天
|
||||
|
||||
// const ROOTPATH1 = "http://192.168.0.119:8171/sqx_fast";
|
||||
// const ROOTPATH = "http://192.168.0.119:8171/sqx_fast";
|
||||
// const ROOTPATH2 = "wss://192.168.0.119:8171/wss/websocket/"; //联系客服
|
||||
// const ROOTPATH3 = "wss://192.168.0.119:8171/wss/ordersChat/"; //聊天
|
||||
|
||||
module.exports = {
|
||||
APIHOST: ROOTPATH,
|
||||
APIHOST1: ROOTPATH1,
|
||||
WSHOST: ROOTPATH2,
|
||||
WSHOST1: ROOTPATH3,
|
||||
};
|
||||
587
common/httpRequest.js
Normal file
587
common/httpRequest.js
Normal file
@@ -0,0 +1,587 @@
|
||||
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;
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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("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) {
|
||||
console.error(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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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("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) {
|
||||
// console.error(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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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("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 && 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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
posts: function(url, data, header) {
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postF: function(url, data, header) {
|
||||
header = header || "application/json";
|
||||
url = this.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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
postFs: function(url, data, header) {
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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;
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
getJd: function(url, data, header) {
|
||||
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) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
succ.call(self, result.data)
|
||||
},
|
||||
fail: function(e) {
|
||||
error.call(self, e)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
get1: function(url, data, header) {
|
||||
header = header || "application/json";
|
||||
url = this.config("APIHOST") + url;
|
||||
return new Promise((succ, error) => {
|
||||
uni.request({
|
||||
url: url,
|
||||
data: data,
|
||||
method: "GET",
|
||||
success: function(result) {
|
||||
if (result.data.code == 401) {
|
||||
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/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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://tcwm.xianmaxiong.com'
|
||||
},
|
||||
//全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
|
||||
publicYuMingAll() {
|
||||
return 'https://tcwm.xianmaxiong.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;
|
||||
},
|
||||
};
|
||||
16
common/share.js
Normal file
16
common/share.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export default {
|
||||
onShareAppMessage(res) { //发送给朋友
|
||||
return {
|
||||
title: uni.getStorageSync('tuiguang'),
|
||||
path:'/pages/index/index',
|
||||
imageUrl: uni.getStorageSync('tuiguangImg'),
|
||||
}
|
||||
},
|
||||
onShareTimeline(res) { //分享到朋友圈
|
||||
return {
|
||||
title: uni.getStorageSync('tuiguang'),
|
||||
path:'/pages/index/index',
|
||||
imageUrl: uni.getStorageSync('tuiguangImg'),
|
||||
}
|
||||
},
|
||||
}
|
||||
61
common/time.js
Normal file
61
common/time.js
Normal file
@@ -0,0 +1,61 @@
|
||||
function commentTimeHandle(dateStr) {
|
||||
// dateStr = 2018-09-06 18:47:00" 测试时间
|
||||
var publishTime = dateStr / 1000, //获取dataStr的秒数 打印结果--1536230820000
|
||||
date = new Date(publishTime * 1000), //获取dateStr的标准格式 console.log(date) 打印结果 Thu Sep 06 2018 18:47:00 GMT+0800 (中国标准时间)
|
||||
// 获取date 中的 年 月 日 时 分 秒
|
||||
Y = date.getFullYear(),
|
||||
M = date.getMonth() + 1,
|
||||
D = date.getDate(),
|
||||
H = date.getHours(),
|
||||
m = date.getMinutes(),
|
||||
s = date.getSeconds();
|
||||
// 对 月 日 时 分 秒 小于10时, 加0显示 例如: 09-09 09:01
|
||||
if (M < 10) {
|
||||
M = '0' + M;
|
||||
}
|
||||
if (D < 10) {
|
||||
D = '0' + D;
|
||||
}
|
||||
if (H < 10) {
|
||||
H = '0' + H;
|
||||
}
|
||||
if (m < 10) {
|
||||
m = '0' + m;
|
||||
}
|
||||
if (s < 10) {
|
||||
s = '0' + s;
|
||||
}
|
||||
// console.log("年", Y); // 年 2018
|
||||
// console.log("月", M); // 月 09
|
||||
// console.log("日", D); // 日 06
|
||||
// console.log("时", H); // 时 18
|
||||
// console.log("分", m); // 分 47
|
||||
// console.log("秒", s); // 秒 00
|
||||
var nowTime = new Date().getTime() / 1000, //获取此时此刻日期的秒数
|
||||
diffValue = nowTime - publishTime, // 获取此时 秒数 与 要处理的日期秒数 之间的差值
|
||||
diff_days = parseInt(diffValue / 86400), // 一天86400秒 获取相差的天数 取整
|
||||
diff_hours = parseInt(diffValue / 3600), // 一时3600秒
|
||||
diff_minutes = parseInt(diffValue / 60),
|
||||
diff_secodes = parseInt(diffValue);
|
||||
|
||||
if (diff_days > 0 && diff_days < 3) { //相差天数 0 < diff_days < 3 时, 直接返出
|
||||
return diff_days + "天前";
|
||||
} else if (diff_days <= 0 && diff_hours > 0) {
|
||||
return diff_hours + "小时前";
|
||||
} else if (diff_hours <= 0 && diff_minutes > 0) {
|
||||
return diff_minutes + "分钟前";
|
||||
} else if (diff_secodes < 60) {
|
||||
if (diff_secodes <= 0) {
|
||||
return "刚刚";
|
||||
} else {
|
||||
return diff_secodes + "秒前";
|
||||
}
|
||||
} else if (diff_days >= 3 && diff_days < 30) {
|
||||
return M + '-' + D + ' ' + H + ':' + m;
|
||||
} else if (diff_days >= 30) {
|
||||
return Y + '-' + M + '-' + D + ' ' + H + ':' + m;
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
timeHandle: commentTimeHandle
|
||||
}
|
||||
Reference in New Issue
Block a user