commit message
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,193 @@
|
||||
// 该文件用来存储localStorage 本地缓存的方法
|
||||
/**
|
||||
* 操作用户token
|
||||
*/
|
||||
export function setToken(value) {
|
||||
uni.setStorageSync('token', value);
|
||||
console.log('存储用户信息成功');
|
||||
}
|
||||
export function getToken() {
|
||||
let token = uni.getStorageSync('token');
|
||||
return token;
|
||||
}
|
||||
export function removeToken() {
|
||||
uni.removeStorageSync('token');
|
||||
}
|
||||
/**
|
||||
* 操作用户信息
|
||||
*/
|
||||
|
||||
export function setUserInfo(value) {
|
||||
try {
|
||||
let newValue = JSON.stringify(value);
|
||||
uni.setStorageSync('userinfo', newValue);
|
||||
console.log('存储用户信息成功');
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getUserInfo() {
|
||||
let userinfo = uni.getStorageSync('userinfo');
|
||||
console.log('userinfo', userinfo)
|
||||
if (userinfo) {
|
||||
return JSON.parse(userinfo);
|
||||
}
|
||||
}
|
||||
export function removeUserInfo(){
|
||||
uni.removeStorageSync('userinfo');
|
||||
}
|
||||
/**
|
||||
* 项目主题颜色
|
||||
*/
|
||||
|
||||
export function setConfig(value) {
|
||||
try {
|
||||
let config = JSON.stringify(value);
|
||||
uni.setStorageSync('config', config);
|
||||
console.log('存储主题成功');
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getConfig() {
|
||||
let config = uni.getStorageSync('config');
|
||||
|
||||
if (config) {
|
||||
return JSON.parse(config);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取推荐人id
|
||||
*/
|
||||
|
||||
export function setRecommend(value) {
|
||||
uni.setStorageSync('recommend', value);
|
||||
console.log('recommend', value);
|
||||
}
|
||||
export function getRecommend() {
|
||||
let recommend = uni.getStorageSync('recommend');
|
||||
return recommend;
|
||||
}
|
||||
/**
|
||||
* 存储商品信息
|
||||
*/
|
||||
|
||||
export function setGoodsData(value) {
|
||||
try {
|
||||
let newValue = JSON.stringify(value);
|
||||
uni.setStorageSync('goodsdata', newValue);
|
||||
console.log('存储商品信息成功');
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getGoodsData() {
|
||||
let goodsdata = uni.getStorageSync('goodsdata');
|
||||
|
||||
if (goodsdata) {
|
||||
return JSON.parse(goodsdata);
|
||||
}
|
||||
}
|
||||
// 存储用户地址
|
||||
export function setAddress(value) {
|
||||
try {
|
||||
let newValue = JSON.stringify(value);
|
||||
uni.setStorageSync('address', newValue);
|
||||
console.log('存储地址信息成功', newValue);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getAddress() {
|
||||
let address = uni.getStorageSync('address');
|
||||
|
||||
if (address) {
|
||||
return JSON.parse(address);
|
||||
}
|
||||
}
|
||||
export function removeAddress() {
|
||||
uni.removeStorageSync('address');
|
||||
} // 设置分类跳转
|
||||
|
||||
export function setTbIndex(value) { //设置菜单栏选项
|
||||
uni.setStorageSync('tabIndex', value);
|
||||
console.log('tabIndex', value);
|
||||
}
|
||||
export function getTbIndex() { //获取菜单栏选项
|
||||
let tabIndex = uni.getStorageSync('tabIndex');
|
||||
return tabIndex;
|
||||
}
|
||||
export function removeTbIndex() { //移除菜单栏选项
|
||||
uni.removeStorageSync('tabIndex');
|
||||
}
|
||||
export function setlocation(value){ //存储位置信息
|
||||
try {
|
||||
let newValue = JSON.stringify(value);
|
||||
uni.setStorageSync('location', newValue);
|
||||
console.log('存储地址信息成功', newValue);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getlocation() { //获取位置信息
|
||||
let location = uni.getStorageSync('location');
|
||||
if (location) {
|
||||
return JSON.parse(location);
|
||||
}
|
||||
}
|
||||
export function setCart(value){ //模拟存储购物车数据
|
||||
try {
|
||||
let data = getCart() || []
|
||||
data.push(value)
|
||||
let newValue = JSON.stringify(data);
|
||||
uni.setStorageSync('cart', newValue);
|
||||
console.log('存储购物车数据成功', newValue);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getCart() { //模拟获取购物车数据
|
||||
let cart = uni.getStorageSync('cart');
|
||||
if (cart) {
|
||||
return JSON.parse(cart);
|
||||
}
|
||||
}
|
||||
export function removeCart() { //模拟删除购物车数据
|
||||
uni.removeStorageSync('cart')
|
||||
}
|
||||
export function setPickaddress(value){ //存储收件地址
|
||||
try {
|
||||
let newValue = JSON.stringify(value);
|
||||
uni.setStorageSync('pickaddress', newValue);
|
||||
console.log('存储收件地址信息成功', newValue);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getPickaddress() { //获取收件地址
|
||||
let location = uni.getStorageSync('pickaddress');
|
||||
if (location) {
|
||||
return JSON.parse(location);
|
||||
}
|
||||
}
|
||||
export function removePickaddress() { //删除收件地址
|
||||
uni.removeStorageSync('pickaddress')
|
||||
}
|
||||
export function setToaddress(value){ //存储取件地址
|
||||
try {
|
||||
let newValue = JSON.stringify(value);
|
||||
uni.setStorageSync('toaddress', newValue);
|
||||
console.log('存储取件地址信息成功', newValue);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getToaddress() { //获取取件地址
|
||||
let location = uni.getStorageSync('toaddress');
|
||||
if (location) {
|
||||
return JSON.parse(location);
|
||||
}
|
||||
}
|
||||
export function removeToaddress() { //删除取件地址
|
||||
uni.removeStorageSync('toaddress')
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// 本js用来存储项目样式和主题颜色
|
||||
export default {
|
||||
themeList: [{
|
||||
title: '官方',
|
||||
name: 'default',
|
||||
color: '#fa436a',
|
||||
tabList: ["/static/images/tabBar/home-default.png", "/static/images/tabBar/class-default.png", "/static/images/tabBar/cart-default.png", "/static/images/tabBar/user-default.png"]
|
||||
}, {
|
||||
title: '嫣红',
|
||||
name: 'red',
|
||||
color: '#e54d42',
|
||||
tabList: ["/static/images/tabBar/tab-home-red.png", "/static/images/tabBar/tab-cate-red.png", "/static/images/tabBar/tab-cart-red.png", "/static/images/tabBar/tab-user-red.png"]
|
||||
}, {
|
||||
title: '桔橙',
|
||||
name: 'orange',
|
||||
color: '#f37b1d',
|
||||
tabList: ["/static/images/tabBar/tab-home-orange.png", "/static/images/tabBar/tab-cate-orange.png", "/static/images/tabBar/tab-cart-orange.png", "/static/images/tabBar/tab-user-orange.png"]
|
||||
}, {
|
||||
title: '明黄',
|
||||
name: 'yellow',
|
||||
color: '#fbbd08',
|
||||
tabList: ["/static/images/tabBar/tab-home-yellow.png", "/static/images/tabBar/tab-cate-yellow.png", "/static/images/tabBar/tab-cart-yellow.png", "/static/images/tabBar/tab-user-yellow.png"]
|
||||
}, {
|
||||
title: '橄榄',
|
||||
name: 'olive',
|
||||
color: '#8dc63f',
|
||||
tabList: ["/static/images/tabBar/tab-home-olive.png", "/static/images/tabBar/tab-cate-olive.png", "/static/images/tabBar/tab-cart-olive.png", "/static/images/tabBar/tab-user-olive.png"]
|
||||
}, {
|
||||
title: '森绿',
|
||||
name: 'green',
|
||||
color: '#39b54a',
|
||||
tabList: ["/static/images/tabBar/tab-home-green.png", "/static/images/tabBar/tab-cate-green.png", "/static/images/tabBar/tab-cart-green.png", "/static/images/tabBar/tab-user-green.png"]
|
||||
}, {
|
||||
title: '天青',
|
||||
name: 'cyan',
|
||||
color: '#1cbbb4',
|
||||
tabList: ["/static/images/tabBar/tab-home-cyan.png", "/static/images/tabBar/tab-cate-cyan.png", "/static/images/tabBar/tab-cart-cyan.png", "/static/images/tabBar/tab-user-cyan.png"]
|
||||
}, {
|
||||
title: '海蓝',
|
||||
name: 'blue',
|
||||
color: '#0081ff',
|
||||
tabList: ["/static/images/tabBar/tab-home-blue.png", "/static/images/tabBar/tab-cate-blue.png", "/static/images/tabBar/tab-cart-blue.png", "/static/images/tabBar/tab-user-blue.png"]
|
||||
}, {
|
||||
title: '姹紫',
|
||||
name: 'purple',
|
||||
color: '#6739b6',
|
||||
tabList: ["/static/images/tabBar/tab-home-purple.png", "/static/images/tabBar/tab-cate-purple.png", "/static/images/tabBar/tab-cart-purple.png", "/static/images/tabBar/tab-user-purple.png"]
|
||||
}, {
|
||||
title: '木槿',
|
||||
name: 'mauve',
|
||||
color: '#9c26b0',
|
||||
tabList: ["/static/images/tabBar/tab-home-mauve.png", "/static/images/tabBar/tab-cate-mauve.png", "/static/images/tabBar/tab-cart-mauve.png", "/static/images/tabBar/tab-user-mauve.png"]
|
||||
}, {
|
||||
title: '桃粉',
|
||||
name: 'pink',
|
||||
color: '#e03997',
|
||||
tabList: ["/static/images/tabBar/tab-home-pink.png", "/static/images/tabBar/tab-cate-pink.png", "/static/images/tabBar/tab-cart-pink.png", "/static/images/tabBar/tab-user-pink.png"]
|
||||
}, {
|
||||
title: '棕褐',
|
||||
name: 'brown',
|
||||
color: '#a5673f',
|
||||
tabList: ["/static/images/tabBar/tab-home-brown.png", "/static/images/tabBar/tab-cate-brown.png", "/static/images/tabBar/tab-cart-brown.png", "/static/images/tabBar/tab-user-brown.png"]
|
||||
}, {
|
||||
title: '玄灰',
|
||||
name: 'grey',
|
||||
color: '#8799a3',
|
||||
tabList: ["/static/images/tabBar/tab-home-grey.png", "/static/images/tabBar/tab-cate-grey.png", "/static/images/tabBar/tab-cart-grey.png", "/static/images/tabBar/tab-user-grey.png"]
|
||||
}, {
|
||||
title: '墨黑',
|
||||
name: 'black',
|
||||
color: '#333333',
|
||||
tabList: ["/static/images/tabBar/tab-home-black.png", "/static/images/tabBar/tab-cate-black.png", "/static/images/tabBar/tab-cart-black.png", "/static/images/tabBar/tab-user-black.png"]
|
||||
}]
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 本文件用来存储项目内使用的三方API key
|
||||
*/
|
||||
//和风天气的key 需要的用户去申请
|
||||
let hfKey = 'b2286b8feae44d1c926ca9033e5bf123';
|
||||
|
||||
//腾讯地图 需要用户自己去申请key
|
||||
let txMapKey = 'BIUBZ-UWKW3-FK53E-YIPVT-R4KG5-3DBA3'
|
||||
|
||||
export {
|
||||
hfKey,
|
||||
txMapKey
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @description 微信公众号支付准备
|
||||
* @data 微信支付请求成功之后返回的支付参数
|
||||
* @payParams {object} 微信支付需要的参数
|
||||
* */
|
||||
function onBridgeReady(data, payParams) {
|
||||
// alert('onBridgeReady:==========')
|
||||
window.WeixinJSBridge.invoke('getBrandWCPayRequest', {
|
||||
appId: data.appId,
|
||||
// 公众号名称,由商户传入
|
||||
timeStamp: data.timeStamp,
|
||||
// 时间戳,自1970年以来的秒数
|
||||
nonceStr: data.nonceStr,
|
||||
// 随机串
|
||||
package: data.package,
|
||||
signType: data.signType,
|
||||
// 微信签名方式:
|
||||
paySign: data.paySign // 微信签名
|
||||
|
||||
}, function (res) {
|
||||
console.log(res); // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
|
||||
|
||||
if (res.err_msg === 'get_brand_wcpay_request:ok') {
|
||||
// 支付成功页面
|
||||
if (payParams.type === 'SHYY') {
|
||||
toastMsg('correct', '支付成功');
|
||||
setTimeout(() => {
|
||||
router.push('/home');
|
||||
}, 500);
|
||||
} else {
|
||||
// console.log('-----测试----支付成功----')
|
||||
router.push({
|
||||
path: '/success',
|
||||
query: {
|
||||
orderId: payParams.orderId,
|
||||
totalFee: payParams.totalFee
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (res.err_msg === 'get_brand_wcpay_request:fail') {
|
||||
return alert(res.err_desc);
|
||||
} else {
|
||||
// 跳转订单详情
|
||||
toastMsg('warn', '支付取消');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝支付
|
||||
*/
|
||||
function alipay(res) {
|
||||
console.log('调起支付alipay',res );
|
||||
uni.requestPayment({
|
||||
provider: 'alipay',
|
||||
orderInfo: {
|
||||
"dealId": res.dealId,
|
||||
"appKey": res.appKey,
|
||||
"totalAmount": res.totalAmount,
|
||||
"tpOrderId": res.tpOrderId,
|
||||
"dealTitle": res.dealTitle,
|
||||
"rsaSign": res.rsaSign,
|
||||
"bizInfo": res.bizInfo
|
||||
}, //订单数据
|
||||
success: function(res) {
|
||||
console.log('success:' + JSON.stringify(res));
|
||||
},
|
||||
fail: function(err) {
|
||||
console.log('fail:' + JSON.stringify(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序支付
|
||||
*/
|
||||
function wxpay(ret, orderid) {
|
||||
console.log('调起支付wxpay', ret);
|
||||
let res = ret;
|
||||
let status = false;
|
||||
uni.requestPayment({
|
||||
timeStamp: res.timeStamp,
|
||||
nonceStr: res.nonceStr,
|
||||
package: res.package,
|
||||
signType: res.signType,
|
||||
paySign: res.paySign,
|
||||
appId: res.appId,
|
||||
success: function (res) {
|
||||
console.log('success:' + JSON.stringify(res), res);
|
||||
uni.showToast({
|
||||
title: '支付成功!'
|
||||
});
|
||||
},
|
||||
fail: function (err) {
|
||||
console.log('fail:' + JSON.stringify(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 数组去重
|
||||
*/
|
||||
function arrayUnique2(arr, name) {
|
||||
var hash = {};
|
||||
return arr.reduce(function (item, next) {
|
||||
hash[next[name]] ? '' : hash[next[name]] = true && item.push(next);
|
||||
return item;
|
||||
}, []);
|
||||
}
|
||||
|
||||
export {
|
||||
onBridgeReady,
|
||||
alipay,
|
||||
wxpay,
|
||||
arrayUnique2
|
||||
};
|
||||
+1062
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 封装的异步请求处理函数
|
||||
* 使用方法为:
|
||||
* request('接口名称',{key:value},'请求方式(默认为GET)')
|
||||
* .then(res=>{console.log(res)})
|
||||
*/
|
||||
import { getToken, removeToken } from "./auth";
|
||||
let baseUrl = "https://xxx.xxxxx.xxx"; // 后台请求域名
|
||||
async function request(mehtod, params, type, callBack) {
|
||||
//创建一个名为request请求的方法函数
|
||||
if (!type) {
|
||||
type = "GET";
|
||||
}
|
||||
let header = {
|
||||
//设置请求头信息
|
||||
Authorization: getToken(),
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
};
|
||||
let http = {
|
||||
url: baseUrl + mehtod,
|
||||
data: params,
|
||||
method: type,
|
||||
header: header,
|
||||
};
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
uni
|
||||
.request(http)
|
||||
.then((res) => {
|
||||
let newdata = res[1].data; // if (newdata.code == 403) {
|
||||
if (newdata == -1) {
|
||||
//如果错误码为 -1 提示
|
||||
uni.showToast({
|
||||
title: res[1].data.msg,
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
resolve(res[1].data);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
async function requestJson(mehtod, params, type, headerParams, callBack) {
|
||||
//创建一个名为request请求的方法函数
|
||||
let header = {
|
||||
//设置请求头信息
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
};
|
||||
if (headerParams) {
|
||||
header = Object.assign(header, headerParams);
|
||||
}
|
||||
let http = {
|
||||
url: mehtod,
|
||||
data: params,
|
||||
method: type,
|
||||
header: header,
|
||||
};
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
uni
|
||||
.request(http)
|
||||
.then((res) => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
async function requestForm(mehtod, params, type, callBack) {
|
||||
//创建一个名为request请求的方法函数
|
||||
let header = {
|
||||
//设置请求头信息
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
let http = {
|
||||
url: mehtod,
|
||||
data: params,
|
||||
method: type,
|
||||
header: header,
|
||||
};
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
uni
|
||||
.request(http)
|
||||
.then((res) => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
export default {
|
||||
request,
|
||||
requestJson,
|
||||
requestForm,
|
||||
};
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,19 @@
|
||||
const formatTime = date => {
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.getDate();
|
||||
const hour = date.getHours();
|
||||
const minute = date.getMinutes();
|
||||
const second = date.getSeconds();
|
||||
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':');
|
||||
};
|
||||
|
||||
const formatNumber = n => {
|
||||
n = n.toString();
|
||||
return n[1] ? n : '0' + n;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user