123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- import $http from '@/config/requestConfig'
- import store from '@/store';
- import base from '@/config/baseUrl';
- import {
- getAppWxLatLon
- } from '@/plugins/utils';
- import {
- getStaffStatus
- } from '@/config/login';
- // #ifdef H5
- import {
- getLatLonH5,
- publicShareFun,
- wxPublicPay,
- getBrowser,
- appMutual
- } from '@/config/html5Utils';
- // 公众号分享
- export const publicShare = publicShareFun;
- // #endif
- // #ifdef APP-PLUS
- import appShareFun, {
- closeShare
- } from '@/plugins/share';
- // APP分享
- export const appShare = function(data, callbcak) {
- return appShareFun({
- shareTitle: data.shareTitle || base.share.title,
- shareUrl: data.shareUrl || base.share.link,
- shareContent: data.shareContent || base.share.desc,
- shareImg: data.shareImg || base.share.imgUrl,
- }, callbcak);
- };
- export const closeAppShare = closeShare;
- // #endif
- // #ifdef MP-WEIXIN
- // 微信小程序分享
- export const wxShare = function(data = {}) {
- let shareInfo = {
- title: data.title || base.share.title,
- };
- if (data.path && typeof(data.path) == "string") {
- shareInfo.path = data.path;
- } else if (data.path != 1) {
- shareInfo.path = "pages/home/home";
- }
- if (data.imageUrl) {
- shareInfo.imageUrl = data.imageUrl;
- }
- let userInfo = store.state.userInfo;
- if (!(userInfo && userInfo.uid)) {
- userInfo = uni.getStorageSync("userInfo");
- }
- if (userInfo && userInfo.uid) {
- if (data.query && typeof(data.query) == "object") {
- data.query.recommendCode = userInfo.uid;
- } else {
- data.query = {
- recommendCode: userInfo.uid
- };
- }
- }
- if (data.query && typeof(data.query) == "object") {
- Object.keys(data.query).forEach((key, index) => {
- if (index > 0 && shareInfo.query) {
- shareInfo.query += "&" + key + "=" + data.query[key];
- shareInfo.path += "&" + key + "=" + data.query[key];
- } else {
- shareInfo.query = key + "=" + data.query[key];
- shareInfo.path += "?" + key + "=" + data.query[key];
- }
- });
- }
- return shareInfo;
- }
- // #endif
- //支付(APP微信支付、APP支付宝支付、微信小程序支付)
- export const setPay = function(payInfo, callback) {
- let httpUrl = "";
- if (payInfo.type == 'wxpay') {
- // APP微信支付
- httpUrl = 'api/pay/v1/pay_sign_wx'
- } else if (payInfo.type == 'alipay') {
- // APP支付宝支付
- httpUrl = 'api/pay/v1/pay_sign_ali'
- } else if (payInfo.type == 'smallPay') {
- // 微信小程序支付
- httpUrl = 'api/pay/v1/small_pay_sign_wx'
- }
- $http.get(httpUrl, {
- orderNo: payInfo.orderNo
- }).then(data => {
- let payData = {
- success: function(res) {
- callback && callback({
- success: true,
- data: res
- });
- console.log('success:' + JSON.stringify(res));
- },
- fail: function(err) {
- callback && callback({
- success: false,
- data: err
- });
- console.log('fail:' + JSON.stringify(err));
- }
- };
- if (payInfo.type == 'smallPay') {
- // 小程序
- payData.provider = 'wxpay';
- payData.timeStamp = data.timeStamp;
- payData.nonceStr = data.nonceStr;
- payData.package = data.package;
- // payData.package = "prepay_id=" + data.prepayid;
- payData.signType = "MD5";
- payData.paySign = data.sign;
- } else if (payInfo.type == 'wxpay') {
- // app微信
- payData.provider = 'wxpay';
- payData.orderInfo = data;
- } else if (payInfo.type == 'alipay') {
- // app 支付宝
- payData.provider = 'alipay';
- payData.orderInfo = data;
- } else if (payInfo.type == 'baidu') {
- payData.provider = 'baidu';
- payData.orderInfo = data;
- }
- console.log("支付参数", payData);
- uni.requestPayment(payData);
- }, err => {
- callback && callback({
- success: false,
- data: err
- });
- });
- }
- // 支付统一分配
- export const setPayAssign = function(orderInfo, callback) {
- orderInfo.price = orderInfo.price || orderInfo.pricePay;
- orderInfo.title = orderInfo.title || orderInfo.orderTitle;
- //支付
- // #ifdef APP-PLUS
- uni.navigateTo({
- url: '/pages/home/weChatPay?orderNo=' + orderInfo.orderNo + '&price=' + orderInfo.price +
- '&title=' + orderInfo.title
- });
- // #endif
- // #ifdef MP-WEIXIN
- setPay({
- ...orderInfo,
- type: "smallPay"
- }, res => {
- if (res.success) {
- uni.redirectTo({
- url: "/pages/shopCar/paySuccess?orderNo=" + orderInfo.orderNo
- });
- }
- });
- // #endif
- // #ifdef H5
- if (getBrowser() === '微信') {
- wxPublicPay({
- orderNo: orderInfo.orderNo
- }, function() {
- uni.redirectTo({
- url: "/pages/shopCar/paySuccess?orderNo=" + orderInfo.orderNo
- });
- });
- } else {
- appMutual('setJumpPay', orderInfo);
- }
- // #endif
- }
- // 获取地址信息 (微信小程序、APP、公众号)
- export const getLatLon = function(tip) {
- return new Promise((resolve, reject) => {
- const successProcess = function(res) {
- store.commit("setCurrentAddress", {
- latitude: res.latitude,
- longitude: res.longitude
- });
- resolve(res);
- };
- const errProcess = function(err) {
- reject(err);
- if (tip) {
- uni.showToast({
- title: err,
- icon: "none"
- });
- }
- };
- // #ifdef H5
- getLatLonH5(successProcess, errProcess);
- // #endif
- // #ifndef H5
- getAppWxLatLon(successProcess, errProcess);
- // #endif
- });
- }
- // 页面跳转
- export const navigate = async function(options, type = "navigateTo", isRequireLogin = false) {
- uni.hideKeyboard();
- jumpPage(options, type);
- // 是否登录验证
- // if (isRequireLogin == true) {
- // // 进行判断是否用户已登录,如果未登录,则弹出要求登录框,并return false进行截断
- // if (!!store.state.token) {
- // if((store.state.userStatus==='1') || (store.state.userStatus==='2') || (store.state.userStatus==='3') || (store.state.userStatus==='4') ){
- // await getStaffStatus(store.state.userLoginId).then(res => {
- // if(store.state.userStatus==='1'){
- // return uni.showModal({
- // content: '您的帐号未完成认证,暂无相关权限。',
- // cancelText:'关闭',
- // confirmText:'去认证',
- // success:(res)=> {
- // if (res.confirm) {
- // uni.navigateTo({ url:"/pages/user/infoInput" })
- // }
- // }
- // });
- // }else if((store.state.userStatus==='2') || (store.state.userStatus==='3') || (store.state.userStatus==='4')){
- // let title="";
- // if(store.state.userStatus==='2'){
- // title = '您的认证信息正在审核,请耐心等待。'
- // }else if(store.state.userStatus==='3'){
- // title = '您的认证信息已被管理人员驳回,无法进行认证,暂无相关权限。如有疑问请联系管理员或推荐人。'
- // }else if(store.state.userStatus==='4'){
- // title = '您的认证信息已被管理人员退回,请按照要求修改后重新提交。'
- // }
- // return uni.showModal({
- // content: title,
- // cancelText:'关闭',
- // confirmText:'去查看',
- // success:(res)=> {
- // if (res.confirm) {
- // uni.navigateTo({ url:"/pages/user/infoExamine" })
- // }
- // }
- // });
- // }else{
- // jumpPage(options,type)
- // }
- // })
- // }else{
- // // 跳转
- // jumpPage(options,type)
- // }
- // }else{
- // uni.showModal({
- // title: "登录提示",
- // content: "此时此刻需要您登录喔~",
- // confirmText: "去登录",
- // cancelText: "再逛会",
- // showCancel:false,
- // success: (res) => {
- // if (res.confirm) {
- // return uni.reLaunch({
- // url: "/pages/login/login"
- // });
- // }
- // }
- // });
- // }
- // }else{
- // // 跳转
- // jumpPage(options,type)
- // }
- }
- // 跳转页面
- function jumpPage(options, type) {
- switch (type) {
- case "navigateTo":
- uni.navigateTo(options);
- break;
- case "redirectTo":
- uni.redirectTo(options);
- break;
- case "reLaunch":
- uni.reLaunch(options);
- break;
- case "switchTab":
- uni.switchTab(options);
- break;
- }
- }
|