初始项目

This commit is contained in:
liupopo
2023-02-11 12:55:02 +08:00
parent 1748bda84a
commit 0b89e36064
3363 changed files with 506201 additions and 1 deletions

View File

@@ -0,0 +1,408 @@
import {
apiBaseUrl
} from './config.js';
import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
import Api from '@/common/api';
import * as common from './common.js' //引入common
import * as db from './db.js' //引入common
// 需要登陆的,都写到这里,否则就是不需要登陆的接口
const methodsToken = [
'user.info',
'user.editinfo',
'user.changeavatar',
'user.logout',
'user.addgoodsbrowsing',
'user.delgoodsbrowsing',
'user.goodsbrowsing',
'user.goodscollection',
'user.goodscollectionlist',
'user.vuesaveusership',
'user.saveusership',
'user.getshipdetail',
'user.setdefship',
'user.editship',
'user.removeship',
'user.getusership',
'user.pay',
'user.orderevaluate',
'user.getuserdefaultship',
'user.issign',
'user.sign',
'user.mypoint',
'user.userpointlog',
'user.getbankcardlist',
'user.getdefaultbankcard',
'user.addbankcard',
'user.removebankcard',
'user.setdefaultbankcard',
'user.getbankcardinfo',
'user.editpwd',
'user.forgotpwd',
'user.recommend',
'user.balancelist',
'user.sharecode',
'user.cash',
'user.cashlist',
'user.myinvite',
'user.activationinvite',
'coupon.getcoupon',
'coupon.usercoupon',
'cart.add',
'cart.del',
'cart.getlist',
'cart.setnums',
'cart.getnumber',
'order.cancel',
'order.del',
'order.details',
'order.confirm',
'order.getlist',
'order.create',
'order.getship',
'order.getorderlist',
'order.getorderstatusnum',
'order.aftersaleslist',
'order.aftersalesinfo',
'order.aftersalesstatus',
'order.addaftersales',
'order.sendreship',
'order.iscomment',
'payments.getinfo',
'user.getuserpoint',
'coupon.getcouponkey',
'store.isclerk',
'store.storeladinglist',
'store.ladinginfo',
'store.lading',
'store.ladingdel',
'distribution_center-api-info',
'distribution_center-api-applydistribution',
'distribution_center-api-setstore',
'distribution_center-api-myorder',
'pintuan.pintuanteam',
'lottery-api-getLotteryConfig',
'lottery-api-lottery',
'lottery-api-lotteryLog'
];
const post = (method, data, callback) => {
uni.showLoading({
title: '加载中'
});
// 判断token是否存在
if (methodsToken.indexOf(method) >= 0) {
// 获取用户token
let userToken = db.get("userToken");
if (!userToken) {
common.jumpToLogin();
return false;
} else {
data.token = userToken;
}
}
data.method = method;
uni.request({
url: apiBaseUrl + 'api.html',
data: data,
header: {
'Accept': 'application/json',
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
},
method: 'POST',
success: (response) => {
uni.hideLoading();
const result = response.data
if (!result.status) {
// 登录信息过期或者未登录
if (result.data === 14007 || result.data === 14006) {
db.del("userToken");
uni.showToast({
title: result.msg,
icon: 'none',
duration: 1000,
complete: function() {
setTimeout(function() {
uni.hideToast();
// #ifdef H5 || APP-PLUS
uni.navigateTo({
url: '/pages/login/login/index1'
})
// #endif
// #ifdef MP-WEIXIN || MP-ALIPAY
uni.navigateTo({
url: '/pages/login/choose/index',
animationType: 'pop-in',
animationDuration: 200
});
// #endif
}, 1000)
}
});
}
}
callback(result);
},
complete: () => {
uni.hideLoading();
},
fail: (error) => {
uni.hideLoading();
if (error && error.response) {
showError(error.response);
}
},
});
}
//插件post
const pluginsPost = (method, data, callback) => {
uni.showLoading({
title: '加载中'
});
// 判断token是否存在
if (methodsToken.indexOf(method) >= 0) {
// 获取用户token
let userToken = db.get("userToken");
if (!userToken) {
common.jumpToLogin();
return false;
} else {
data.token = userToken;
}
}
uni.request({
url: apiBaseUrl + 'plugins/' + method + '.html',
data: data,
header: {
'Accept': 'application/json',
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
},
method: 'POST',
success: (response) => {
uni.hideLoading();
const result = response.data
if (!result.status) {
// 登录信息过期或者未登录
if (result.data === 14007 || result.data === 14006) {
db.del("userToken");
uni.showToast({
title: result.msg,
icon: 'none',
duration: 1000,
complete: function() {
setTimeout(function() {
uni.hideToast();
// #ifdef H5 || APP-PLUS
uni.navigateTo({
url: '/pages/login/login/index1'
})
// #endif
// #ifdef MP-WEIXIN || MP-ALIPAY
uni.navigateTo({
url: '/pages/login/choose/index',
animationType: 'pop-in',
animationDuration: 200
});
// #endif
}, 1000);
}
});
}
}
callback(result);
},
fail: (error) => {
uni.hideLoading();
if (error && error.response) {
showError(error.response);
}
},
complete: () => {
setTimeout(function() {
uni.hideLoading();
}, 250);
}
});
}
const get = (url, callback) => {
uni.showLoading({
title: '加载中'
});
uni.request({
url: url,
header: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
},
method: 'GET',
success: (response) => {
uni.hideLoading();
callback(response.data);
},
fail: (error) => {
uni.hideLoading();
if (error && error.response) {
showError(error.response);
}
},
complete: () => {
setTimeout(function() {
uni.hideLoading();
}, 250);
}
});
}
const showError = error => {
let errorMsg = ''
switch (error.status) {
case 400:
errorMsg = '请求参数错误'
break
case 401:
errorMsg = '未授权,请登录'
break
case 403:
errorMsg = '跨域拒绝访问'
break
case 404:
errorMsg = `请求地址出错: ${error.config.url}`
break
case 408:
errorMsg = '请求超时'
break
case 500:
errorMsg = '服务器内部错误'
break
case 501:
errorMsg = '服务未实现'
break
case 502:
errorMsg = '网关错误'
break
case 503:
errorMsg = '服务不可用'
break
case 504:
errorMsg = '网关超时'
break
case 505:
errorMsg = 'HTTP版本不受支持'
break
default:
errorMsg = error.msg
break
}
uni.showToast({
title: errorMsg,
icon: 'none',
duration: 1000,
complete: function() {
setTimeout(function() {
uni.hideToast();
}, 1000);
}
});
}
// 文件上传
export const uploadFiles = (callback) => {
uni.chooseImage({
success: (chooseImageRes) => {
uni.showLoading({
title: '上传中...'
});
const tempFilePaths = chooseImageRes.tempFilePaths;
const uploadTask = uni.uploadFile({
url: Api.BASEURI +'upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
fileType: 'image',
name: 'file',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
formData: {
'method': 'images.upload',
'upfile': tempFilePaths[0]
},
success: (uploadFileRes) => {
callback(JSON.parse(uploadFileRes.data));
},
fail: (error) => {
if (error && error.response) {
showError(error.response);
}
},
complete: () => {
setTimeout(function() {
uni.hideLoading();
}, 250);
}
});
// uploadTask.onProgressUpdate((res) => {
// console.log('上传进度' + res.progress);
// console.log('已经上传的数据长度' + res.totalBytesSent);
// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
//
// // 测试条件,取消上传任务。
// if (res.progress > 50) {
// uploadTask.abort();
// }
// });
}
});
}
// 上传图片
export const uploadImage = (num, callback) => {
uni.chooseImage({
count: num,
success: (res) => {
uni.showLoading({
title: '上传中...'
});
let tempFilePaths = res.tempFilePaths
for (var i = 0; i < tempFilePaths.length; i++) {
uni.uploadFile({
url: apiBaseUrl + 'api.html',
filePath: tempFilePaths[i],
fileType: 'image',
name: 'file',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
formData: {
'method': 'images.upload',
'upfile': tempFilePaths[i]
},
success: (uploadFileRes) => {
callback(JSON.parse(uploadFileRes.data));
},
fail: (error) => {
if (error && error.response) {
showError(error.response);
}
},
complete: () => {
setTimeout(function() {
uni.hideLoading();
}, 250);
},
});
}
}
});
}

View File

@@ -0,0 +1,51 @@
let baseUrl = "";
let socketUrl = "";
if (process.env.NODE_ENV === 'development') {
// 开发环境
// baseUrl = "http://localhost:7001/";
// socketUrl = "ws://localhost:8001/";
// baseUrl = "http://26077a35f5.wicp.vip:43609/";
baseUrl = "http://192.168.3.108:8083/";
socketUrl = "ws://192.168.3.108:8083/";
} else if (process.env.NODE_ENV === 'production') {
// 生产环境
baseUrl = "http://192.168.3.108:8083/";
// baseUrl = "http://192.168.43.195:8083/";
socketUrl = "ws://192.168.3.108:8083/";
}
const courtConfig = {
//微信公众号APPID
publicAppId: "",
//请求接口
baseUrl: baseUrl,
//webSocket地址
socketUrl: socketUrl,
//平台名称
platformName: "uniApp-案例",
//项目logo
logoUrl: "https://qn.kemean.cn/upload/201906/19/3f3b4751f3ed4a97be804450c3ec4c79",
//页面分享配置
share: {
title: 'uniApp-案例',
// #ifdef MP-WEIXIN
path: '/pages/home/home', //小程序分享路径
// #endif
// #ifdef H5 || APP-PLUS
//公众号||APP分享
desc: "uniApp-案例", // 分享描述
link: "https://www.kemean.com/sameCity/18031201/index.html", // 分享链接该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: "http://qn.kemean.cn/upload/201901/28/23bedfc34597482292ecd6dc107f6342", // 分享图标
// #endif
}
};
//手机号验证正则表达式
const phoneRegular = /^1\d{10}$/;
//邮箱验证正则表达式
const mailRegular = /^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/;
//密码验证正则表达式
const passwordRegular = /^[a-zA-Z0-9]{4,10}$/;
export default Object.assign({
phoneRegular,
mailRegular,
passwordRegular
}, courtConfig);

View File

@@ -0,0 +1,485 @@
import * as db from './db.js' //引入common
import store from './../store'
//把obj对象里的值覆盖到newobj里面
function deepCopy(newobj, obj) {
if (typeof obj != 'object') {
return obj
}
for (var attr in obj) {
var a = {}
if (newobj[attr]) {
a = newobj[attr]
}
newobj[attr] = deepCopy(a, obj[attr])
}
return newobj
}
//跳转到登陆页面
function jumpToLogin(method) {
var now_time = Date.parse(new Date())
var value = db.get('jump_to_login')
if (!value) {
value = 0
}
if (now_time - value > 3000) {
//db.set('jump_to_login',now_time); //暂时屏蔽登录时间查询
// 将当前页面route存vuex中 登录注册后跳转
let pages = getCurrentPages()
let page = pages[pages.length - 1]
// 获取页面参数信息
let pagePath = ''
// #ifdef H5 || MP-WEIXIN || APP-PLUS || APP-PLUS-NVUE
if (page.route.indexOf('pages/goods/index/index') !== -1) {
//商品详情页
if(page.goodsId) {
pagePath = '/' + page.route + '?id=' + page.goodsId;
}else{
pagePath = '/pages/index/index';
}
}
if (page.route.indexOf('pages/goods/index/group') !== -1) {
//团购秒杀详情页
if(page.goodsId && page.groupId) {
pagePath = '/' + page.route + '?id=' + page.goodsId + '&group_id' + page.groupId;
}else{
pagePath = '/pages/index/index';
}
}
// #endif
// #ifdef MP-ALIPAY
if (page.__proto__.route.indexOf('pages/goods/index/index') !== -1)
{
//商品详情页
if(page.rootVM.goodsId) {
pagePath = '/' + page.__proto__.route + '?id=' + page.rootVM.goodsId;
}else{
pagePath = '/pages/index/index';
}
}
if (page.__proto__.route.indexOf('pages/goods/index/group') !== -1) {
//团购秒杀详情页
if(page.rootVM.goodsId && page.rootVM.groupId) {
pagePath = '/' + page.__proto__.route + '?id=' + page.rootVM.goodsId + '&group_id' + page.rootVM.groupId;
}else{
pagePath = '/pages/index/index';
}
}
// #endif
if(pagePath){
store.commit({
type: 'redirect',
page: pagePath
})
}
uni.showToast({
title: '请先登录!',
icon: 'none',
duration: 1000,
success: function(res) {
// #ifdef H5 || APP-PLUS
setTimeout(() => {
uni.hideToast();
uni.navigateTo({
url: '/pages/public/index1'
})
}, 1000)
// #endif
// #ifdef MP-WEIXIN || MP-ALIPAY
setTimeout(() => {
uni.hideToast();
uni.navigateTo({
url: '/pages/public/choose/index',
animationType: 'pop-in',
animationDuration: 200
})
}, 500)
// #endif
}
})
}
}
//当出错的时候,显示错误信息,并且跳转 弃用
/* function errorToBack(msg = '出错了,请重试',delta=1){
uni.showToast({
title: msg,
icon: 'none',
duration: 2000,
});
if(delta > 0){
setTimeout(function () {
uni.navigateBack({
delta: delta
})
}, 1000);
}
} */
//操作成功后,的提示信息
function successToShow(msg = '保存成功', callback = function() {}) {
uni.showToast({
title: msg,
icon: 'success',
duration: 1000
})
setTimeout(function() {
callback()
}, 500)
}
//操作失败的提示信息
function errorToShow(msg = '操作失败', callback = function() {}) {
uni.showToast({
title: msg,
icon: 'none',
duration: 1500
})
setTimeout(function() {
callback()
}, 1500)
}
//加载显示
function loadToShow(msg = '加载中') {
uni.showToast({
title: msg,
icon: 'loading'
})
}
//加载隐藏
function loadToHide() {
uni.hideToast()
}
// 提示框
function modelShow(
title = '提示',
content = '确认执行此操作吗?',
callback = () => {},
showCancel = true,
cancelText = '取消',
confirmText = '确定'
) {
uni.showModal({
title: title,
content: content,
showCancel: showCancel,
cancelText: cancelText,
confirmText: confirmText,
cancelText: cancelText,
success: function(res) {
if (res.confirm) {
// 用户点击确定操作
setTimeout(() => {
callback()
}, 500)
} else if (res.cancel) {
// 用户取消操作
}
}
})
}
//时间戳转时间格式
function timeToDate(date, flag = false) {
var date = new Date(date * 1000) //如果date为13位不需要乘1000
var Y = date.getFullYear() + '-'
var M =
(date.getMonth() + 1 < 10
? '0' + (date.getMonth() + 1)
: date.getMonth() + 1) + '-'
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
var m =
(date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
if(flag)
{
return Y + M + D
}
else
{
return Y + M + D + h + m + s
}
}
function time2date(micro_second) {
var time = {}
// 总秒数
var second = Math.floor(micro_second)
// 天数
time.day = PrefixInteger(Math.floor(second / 3600 / 24), 2)
// 小时
time.hour = PrefixInteger(Math.floor((second / 3600) % 24), 2)
// 分钟
time.minute = PrefixInteger(Math.floor((second / 60) % 60), 2)
// 秒
time.second = PrefixInteger(Math.floor(second % 60), 2)
var newtime = ''
if (time.day > 0) {
newtime =
time.day +
'天' +
time.hour +
'小时' +
time.minute +
'分' +
time.second +
'秒'
} else {
if (time.hour != 0) {
newtime = time.hour + '小时' + time.minute + '分' + time.second + '秒'
} else {
newtime = time.minute + '分' + time.second + '秒'
}
}
return newtime
}
function timeToDateObj(micro_second) {
var time = {}
// 总秒数
var second = Math.floor(micro_second)
// 天数
time.day = Math.floor(second / 3600 / 24)
// 小时
time.hour = Math.floor((second / 3600) % 24)
// 分钟
time.minute = Math.floor((second / 60) % 60)
// 秒
time.second = Math.floor(second % 60)
return time
}
//货币格式化
function formatMoney(number, places, symbol, thousand, decimal) {
number = number || 0
places = !isNaN((places = Math.abs(places))) ? places : 2
symbol = symbol !== undefined ? symbol : '¥'
thousand = thousand || ','
decimal = decimal || '.'
var negative = number < 0 ? '-' : '',
i = parseInt((number = Math.abs(+number || 0).toFixed(places)), 10) + '',
j = (j = i.length) > 3 ? j % 3 : 0
return (
symbol +
negative +
(j ? i.substr(0, j) + thousand : '') +
i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) +
(places
? decimal +
Math.abs(number - i)
.toFixed(places)
.slice(2)
: '')
)
}
function throttle(fn, context, delay) {
clearTimeout(fn.timeoutId)
fn.timeoutId = setTimeout(function() {
fn.call(context)
}, delay)
}
// 时间格式化输出如11:03 25:19 每1s都会调用一次
function dateformat(micro_second) {
var time = {}
// 总秒数
var second = Math.floor(micro_second / 1000) // 天数
time.day = PrefixInteger(Math.floor(second / 3600 / 24), 2) // 小时
time.hour = PrefixInteger(Math.floor((second / 3600) % 24), 2) // 分钟
time.minute = PrefixInteger(Math.floor((second / 60) % 60), 2) // 秒
time.second = PrefixInteger(Math.floor(second % 60), 2)
return time
}
//不足位数前面补0
function PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length)
}
//验证是否是手机号
function isPhoneNumber(str) {
var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
if (!myreg.test(str)) {
return false
} else {
return true
}
}
/**
*
* 对象参数转为url参数
*
*/
function builderUrlParams(url, data) {
if (typeof url == 'undefined' || url == null || url == '') {
return ''
}
if (typeof data == 'undefined' || data == null || typeof data != 'object') {
return ''
}
url += url.indexOf('?') != -1 ? '' : '?'
for (var k in data) {
url += (url.indexOf('=') != -1 ? '&' : '') + k + '=' + encodeURI(data[k])
}
return url
}
/**
* 使用循环的方式判断一个元素是否存在于一个数组中
* @param {Object} arr 数组
* @param {Object} value 元素值
*/
function isInArray(arr, value) {
for (var i = 0; i < arr.length; i++) {
if (value === arr[i]) {
return true
}
}
return false
}
/**
* 统一跳转
*/
function navigateTo(url) {
uni.navigateTo({
url: url,
animationType: 'pop-in',
animationDuration: 300
})
}
/**
* 关闭当前页面并跳转
*/
function redirectTo(url) {
uni.redirectTo({
url: url,
animationType: 'pop-in',
animationDuration: 300
})
}
/**
* 获取url参数
*
* @param {*} name
* @param {*} [url=window.location.serach]
* @returns
*/
function getQueryString(name, url) {
var url = url || window.location.href
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null
}
/**
*
* 判断是否在微信浏览器 true是
*/
function isWeiXinBrowser() {
// #ifdef H5
// window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息这个属性可以用来判断浏览器类型
let ua = window.navigator.userAgent.toLowerCase()
// 通过正则表达式匹配ua中是否含有MicroMessenger字符串
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true
} else {
return false
}
// #endif
return false
}
/**
* 金额相加
* @param {Object} value1
* @param {Object} value2
*/
function moneySum(value1,value2){
return (parseFloat(value1)+parseFloat(value2)).toFixed(2);
}
/**
* 金额相减
* @param {Object} value1
* @param {Object} value2
*/
function moneySub(value1,value2){
let res = (parseFloat(value1)-parseFloat(value2)).toFixed(2);
return res>0?res:0;
}
/**
* 分享URL解压缩
* @param {Object} url
*/
function shareParameterEncode(url){
let urlArray = url.split('-');
let newUrl = 'type=' + urlArray[0] + '&invite=' + urlArray[1] + '&id=' + urlArray[2] + '&team_id=' + urlArray[3] + '&id_type=' + urlArray[4] + '&page_code=' + urlArray[5] + '&group_id=' + urlArray[6];
return newUrl;
}
/**
* 分享URL压缩
* @param {Object} url
*/
function shareParameterDecode(url){
var urlArray = url.split('&');
var allParameter = {
'type': '',
'invite': '',
'id': '',
'team_id': '',
'id_type': '',
'page_code': '',
'group_id': '',
};
for(var i = 0; i < urlArray.length; i++) {
var parameter = urlArray[i].split('=');
allParameter[parameter[0]] = parameter[1];
}
var newUrl = allParameter.type + '-' + allParameter.invite + '-' + allParameter.id + '-' + allParameter.team_id + '-' + allParameter.id_type + '-' + allParameter.page_code + '-' + allParameter.group_id;
return newUrl;
}
export {
deepCopy,
jumpToLogin,
timeToDate,
formatMoney,
/* errorToBack, */
successToShow,
throttle,
errorToShow,
time2date,
isPhoneNumber,
isInArray,
loadToShow,
loadToHide,
navigateTo,
redirectTo,
modelShow,
builderUrlParams,
isWeiXinBrowser,
dateformat,
getQueryString,
timeToDateObj,
moneySum,
moneySub,
shareParameterEncode,
shareParameterDecode
}

View File

@@ -0,0 +1,14 @@
// // export const apiBaseUrl = 'http://www.b2c.com/'
// export const apiBaseUrl = 'http://192.168.43.195:8081/'
export const apiBaseUrl = 'http://www.yyundong.com:8081/'
//export const apiBaseUrl = 'https://demo.jihainet.com/'
// #ifdef H5
export const baseUrl=process.env.NODE_ENV === 'development'?window.location.origin+'/':apiBaseUrl
// #endif
export const paymentType = {
//支付单类型
order: 1, //订单
recharge: 2, //充值
form_order: 5, //表单付款码
form_pay: 6 //表单订单
}

View File

@@ -0,0 +1,84 @@
import * as common from './common.js' //引入common
//取值
function get(key,sync = true) {
try {
if(sync){
return uni.getStorageSync(key);
}else{
let data = '';
uni.getStorage({
key:key,
success: function (res) {
data = res.data;
}
});
return data;
}
} catch (e) {
return false;
}
}
//赋值
function set(key, value, sync = true) {
try {
if (sync) {
return uni.setStorageSync(key, value);
} else {
uni.setStorage({
key: key,
data: value
});
}
} catch (e) {
}
}
//移除
function del(key, sync = true){
try {
if (sync) {
return uni.removeStorageSync(key);
} else {
uni.removeStorage({
key: key
});
}
} catch (e) {
return false;
}
}
//清空
function clear(sync = true){
try {
if (sync) {
return uni.clearStorageSync();
} else {
uni.clearStorage();
}
} catch (e) {
return false;
}
}
//获取用户token如果缓存有直接返回如果没有就先微信登陆然后服务器登陆最后返回token
function userToken(callback) {
var token = get('userToken');
if (token){
callback(token);
}else{
//如果没有登陆,就去登陆
common.jumpToLogin();
}
}
export {
get,
set,
del,
clear,
userToken
}

View File

@@ -0,0 +1,176 @@
export const orders = {
mounted() {},
methods: {
// 查看订单详情
orderDetail(orderId) {
this.$common.navigateTo(
'/pages/member/order/orderdetail?order_id=' + orderId
)
},
// 取消订单
// 去支付
toPay(orderId) {
this.$common.navigateTo(
'/pages/order/payment/index?order_id=' + orderId + '&type=1'
)
},
// 确认收货
// 去评价
toEvaluate(orderId) {
this.$common.navigateTo(
'/pages/member/order/evaluate?order_id=' + orderId
)
},
// 申请售后
// 查看物流信息
showExpress(code, no, address = '') {
let params = encodeURIComponent(
'code=' + code + '&no=' + no + '&add=' + address
)
this.$common.navigateTo(
'/pages/member/order/express_delivery?params=' + params
)
}
}
}
/**
* 商品接口信息
*
*/
export const goods = {
mounted() {},
methods: {
// 查看商品详情
goodsDetail(goodsId) {
this.$common.navigateTo('/pages/goods/index/index?id=' + goodsId)
},
// 跳转商品列表页
goodsList(obj = {}) {
let url = '/pages/classify/index'
if (Object.keys(obj).length) {
url = this.$common.builderUrlParams(url, obj)
}
this.$common.navigateTo(url)
},
// 团购秒杀详情
groupDetail(id, group_id) {
this.$common.navigateTo(
'/pages/goods/index/group?id=' + id + '&group_id=' + group_id
)
},
//拼团详情页
pintuanDetail(id, team_id) {
if (team_id) {
this.$common.navigateTo(
'/pages/goods/index/pintuan?id=' + id + '&team_id=' + team_id
)
} else {
this.$common.navigateTo('/pages/goods/index/pintuan?id=' + id)
}
}
}
}
/**
*
* 返回操作处理
*
*/
export const goBack = {
onBackPress(options) {
if (options.from === 'navigateBack') {
return false
}
let loginPages = ['/pages/cart/index/index', '/pages/member/index/index']
let backPage = this.$store.state.redirectPage
if (loginPages.indexOf(backPage) > -1) {
this.$store.commit({
type: 'redirect',
page: ''
})
uni.switchTab({
url: '/pages/index/index'
})
return true
}
}
}
/* Function Info
* Author: zhf
* CreateTime: 2019/7/12 下午12:10:00
* LastEditor: zhf
* ModifyTime: 2019/7/12 下午12:10:00
* Description: 登录成功统一跳转处理
*/
export const jumpBackPage = {
methods: {
handleBack() {
let redirect = this.$store.state.redirectPage
this.$store.commit({
type: 'redirect',
page: ''
})
let switchTabs = ['/pages/index/index', '/pages/member/index/index']
if (switchTabs.indexOf(redirect) > -1) {
uni.switchTab({
url: redirect
})
} else if (redirect) {
uni.redirectTo({
url: redirect
})
} else {
uni.switchTab({
url: '/pages/index/index'
})
}
}
}
}
/* Function Info
* Author: zhf
* CreateTime: 2019/7/12 下午12:10:28
* LastEditor: zhf
* ModifyTime: 2019/7/12 下午12:10:28
* Description: 操作判断登录处理
*/
export const checkLogin = {
methods: {
checkIsLogin() {
uni.showToast({
title: '请先登录!',
icon: 'none',
duration: 800,
success: function(res) {
// #ifdef H5 || APP-PLUS
setTimeout(() => {
uni.hideToast()
uni.navigateTo({
url: '/pages/public/index1'
})
}, 800)
// #endif
// #ifdef MP-WEIXIN || MP-ALIPAY
setTimeout(() => {
uni.hideToast()
uni.navigateTo({
url: '/pages/public/choose/index',
animationType: 'pop-in',
animationDuration: 200
})
}, 500)
// #endif
}
})
}
}
}

View File

@@ -0,0 +1,211 @@
import request from "@/plugins/request";
import store from '@/config/store';
import base from '@/config/baseUrl';
// #ifdef H5
import {
h5Login
} from '@/config/html5Utils';
// #endif
// #ifdef MP-WEIXIN
import {
onLogin
} from '@/config/login';
// #endif
let version_code = '';
// #ifdef APP-PLUS
import { getCurrentNo } from '@/plugins/APPUpdate';
setTimeout(() => {
getCurrentNo(function(res){
console.log("版本号",res);
version_code = res.versionCode;
});
},200);
// #endif
//可以new多个request来支持多个域名请求
let $http = new request({
//接口请求地址
baseUrl: base.baseUrl,
//服务器本地上传文件地址
fileUrl: base.baseUrl,
//设置请求头如果使用报错跨域问题可能是content-type请求类型和后台那边设置的不一致
header: {
'Content-Type': 'application/json;charset=UTF-8',
'project_token': base.projectToken, //项目token可删除
}
});
// 添加获取七牛云token的方法
$http.getQnToken = function(callback){
//该地址需要开发者自行配置(每个后台的接口风格都不一样)
$http.get("api/common/v1/qn_upload").then(data => {
/*
*接口返回参数:
*visitPrefix:访问文件的域名
*token:七牛云上传token
*folderPath:上传的文件夹
*region: 地区 默认为SCN
*/
callback({
visitPrefix: data.visitPrefix,
token: data.token,
folderPath: data.folderPath
});
});
}
//请求开始拦截器
$http.requestStart = function(options) {
console.log("请求开始", options);
if (options.load) {
//打开加载动画
store.commit("setLoadingShow", true);
}
// 图片上传大小限制
if (options.method == "FILE" && options.maxSize) {
// 文件最大字节: options.maxSize 可以在调用方法的时候加入参数
maxSize = options.maxSize;
for (let item of options.files) {
if (item.size > maxSize) {
setTimeout(() => {
uni.showToast({
title: "图片过大,请重新上传",
icon: "none"
});
}, 500);
return false;
}
}
}
// #ifdef APP-PLUS
// 添加当前版本号
if(version_code){
options.header['version_code'] = version_code;
}
// #endif
//请求前加入token
if (store.state.userInfo.token) {
options.header['user_token'] = store.state.userInfo.token;
};
return options;
}
//请求结束
$http.requestEnd = function(options, resolve) {
//判断当前接口是否需要加载动画
if (options.load) {
// 关闭加载动画
store.commit("setLoadingShow", false);
}
if (resolve.errMsg && resolve.statusCode && resolve.statusCode > 300) {
setTimeout(() => {
uni.showToast({
title: "网络错误,请检查一下网络",
icon: "none"
});
}, 500);
}
}
let loginPopupNum = 0;
//所有接口数据处理(此方法需要开发者根据各自的接口返回类型修改,以下只是模板)
$http.dataFactory = function(res) {
console.log("接口请求数据", {
url: res.url,
resolve: res.response,
header: res.header,
data: res.data,
method: res.method,
});
if (res.response.statusCode && res.response.statusCode == 200) {
let httpData = res.response.data;
/*********以下只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/
//判断数据是否请求成功
if (httpData.success || httpData.code == 200) {
// 返回正确的结果(then接受数据)
res.resolve(httpData.data);
} else if (httpData.code == "1000" || httpData.code == "1001" || httpData.code == 1100) {
// 失败重发
// $http.request({
// url: res.url,
// data: res.data,
// method: res.method,
// header: res.header,
// isPrompt: res.isPrompt,//(默认 true 说明:本接口抛出的错误是否提示)
// load: res.load,//(默认 true 说明:本接口是否提示加载动画)
// isFactory: res.isFactory, //(默认 true 说明本接口是否调用公共的数据处理方法设置false后isPrompt参数将失去作用
// }).then(data => {
// res.resolve(data);
// });
store.commit("emptyUserInfo");
// #ifdef MP-WEIXIN
onLogin();
// #endif
// #ifdef H5
h5Login("force");
// #endif
// #ifdef APP-PLUS
var content = '此时此刻需要您登录喔~';
if (httpData.code == "1000") {
content = '此时此刻需要您登录喔';
}
if (loginPopupNum <= 0) {
loginPopupNum++;
uni.showModal({
title: '温馨提示',
content: content,
confirmText: "去登录",
cancelText: "再逛会",
success: function(res) {
loginPopupNum--;
if (res.confirm) {
uni.navigateTo({
url: "/pages/user/login"
});
}
}
});
}
// #endif
// 返回错误的结果(catch接受数据)
res.reject(res.response);
} else if (httpData.code == "1004") {
if (loginPopupNum <= 0) {
loginPopupNum++;
uni.showModal({
title: "提示",
content: "您还未绑定手机号,请先绑定~",
confirmText: "去绑定",
cancelText: "再逛会",
success: (res) => {
loginPopupNum--;
if (res.confirm) {
uni.navigateTo({
url: '/pages/user/bindPhone'
});
}
}
});
}
// 返回错误的结果(catch接受数据)
res.reject(res.response);
} else { //其他错误提示
if (res.isPrompt) {
setTimeout(function() {
uni.showToast({
title: httpData.info || httpData.msg,
icon: "none",
duration: 3000
});
}, 500);
}
// 返回错误的结果(catch接受数据)
res.reject(res.response);
}
/*********以上只是模板(及共参考),需要开发者根据各自的接口返回类型修改*********/
} else {
// 返回错误的结果(catch接受数据)
res.reject(res.response);
}
};
export default $http;

View File

@@ -0,0 +1,124 @@
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
//变量
const state = {
//用户数据
userInfo: {},
//webView地址
webViewUrl: "",
loadingShow: false,
//微信场景参数
chatScenesInfo: {},
//登录弹窗状态
loginPopupShow: false,
//当前位置
currentAddress: {
areaName: "请选择",
areaId: ''
},
};
//缓存浏览器的数据名称
const cacheNameList = ["userInfo"];
let clearTime;
const mutations = {
//取出缓存数据打开APP就取出
setCacheData(state) {
for (let name of cacheNameList) {
// #ifndef H5
let data = uni.getStorageSync(name);
// #endif
// #ifdef H5
let data = sessionStorage.getItem(name) || localStorage.getItem(name);
// #endif
if (data) {
// #ifdef H5
try {
data = JSON.parse(data);
} catch (e) {
}
// #endif
state[name] = data;
}
}
},
//储存用户信息
setUserInfo(state, data) {
if (data) {
state.userInfo = Object.assign(state.userInfo,data);
// #ifdef H5
window.sessionStorage.setItem('userInfo', JSON.stringify(state.userInfo));
// #endif
// #ifndef H5
uni.setStorageSync('userInfo', state.userInfo);
// #endif
}
},
// 退出APP
emptyUserInfo(state) {
state.userInfo = {};
// #ifdef H5
window.sessionStorage.removeItem("userInfo");
// #endif
// #ifndef H5
uni.removeStorageSync("userInfo");
// #endif
},
//WebView地址
setWebViewUrl(state, data) {
if (data) {
state.webViewUrl = data;
// #ifdef H5
window.sessionStorage.setItem('webViewUrl', data);
// #endif
}
},
//数据加载状态
setLoadingShow(state, data) {
if(state.loadingShow){
clearTime && clearTimeout(clearTime);
clearTime = setTimeout(function(){
state.loadingShow = data;
},300);
} else {
state.loadingShow = data;
}
},
//微信场景参数
setChatScenesInfo(state, data) {
if (data) {
state.chatScenesInfo = data;
}
},
//登录弹窗状态
setLoginPopupShow(state, data) {
state.loginPopupShow = data;
},
//当前地址
setCurrentAddress(state, data) {
if (data) {
state.currentAddress = Object.assign(state.currentAddress, data);
let addressInfo = {
"provinceId": state.currentAddress.provinceId,
"provinceName": state.currentAddress.provinceName,
"cityId": state.currentAddress.cityId,
"cityName": state.currentAddress.cityName,
"areaId": state.currentAddress.areaId,
"areaName": state.currentAddress.areaName,
};
// #ifdef H5
window.sessionStorage.setItem('currentAddress', JSON.stringify(addressInfo));
// #endif
// #ifndef H5
uni.setStorageSync('currentAddress', addressInfo);
// #endif
}
}
};
//异步处理
const actions = {};
export default new Vuex.Store({
state,
mutations,
actions
});