Pre Merge pull request !160 from 卢越/master
commit
d690529a2e
|
@ -197,7 +197,7 @@
|
|||
|
||||
<!-- 满减送/限时折扣活动弹窗 -->
|
||||
<s-activity-pop
|
||||
v-model="state"
|
||||
v-model="state.showActivityModel"
|
||||
:show="state.showActivityModel"
|
||||
@close="state.showActivityModel = false"
|
||||
@get="onTakeCoupon"
|
||||
|
|
|
@ -75,7 +75,7 @@ const AuthUtil = {
|
|||
},
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
loadingMsg: '登录中',
|
||||
},
|
||||
});
|
||||
},
|
||||
|
@ -91,7 +91,7 @@ const AuthUtil = {
|
|||
},
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
loadingMsg: '登录中',
|
||||
},
|
||||
});
|
||||
},
|
||||
|
@ -107,7 +107,7 @@ const AuthUtil = {
|
|||
},
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
loadingMsg: '登录中',
|
||||
successMsg: '登录成功',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ export default {
|
|||
data,
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
loadingMsg: '登录中',
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<view
|
||||
class="page-app"
|
||||
:class="['theme-' + sys?.mode, 'main-' + sys?.theme, 'font-' + sys?.fontSize]"
|
||||
:class="['theme-' + sys.mode, 'main-' + sys.theme, 'font-' + sys.fontSize]"
|
||||
>
|
||||
<view class="page-main" :style="[bgMain]">
|
||||
<!-- 顶部导航栏-情况1:默认通用顶部导航栏 -->
|
||||
|
@ -213,11 +213,11 @@
|
|||
// #endif
|
||||
|
||||
// 组件中使用 onMounted 监听页面加载,不是页面组件不使用 onShow
|
||||
onMounted(()=>{
|
||||
onMounted(() => {
|
||||
if (!isEmpty(shareInfo.value)) {
|
||||
sheep.$platform.share.updateShareInfo(shareInfo.value);
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
@ -198,7 +198,8 @@
|
|||
// 简单长度验证
|
||||
url.length >= 10
|
||||
);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,18 +9,18 @@
|
|||
* @param {Object} device - 设备信息
|
||||
*/
|
||||
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import { isEmpty } from 'lodash';
|
||||
// #ifdef H5
|
||||
import { isWxBrowser } from '@/sheep/helper/utils';
|
||||
// #endif
|
||||
import wechat from './provider/wechat/index.js';
|
||||
import apple from './provider/apple';
|
||||
import platformService from '@/sheep/platform/provider/index/index';
|
||||
import apple from './provider/apple/index';
|
||||
import share from './share';
|
||||
import Pay from './pay';
|
||||
|
||||
const device = uni.getWindowInfo();
|
||||
const device = uni.getSystemInfoSync();
|
||||
|
||||
const os = uni.getDeviceInfo().platform;
|
||||
const os = device.platform;
|
||||
|
||||
let name = '';
|
||||
let provider = '';
|
||||
|
@ -53,6 +53,12 @@ platform = 'miniProgram';
|
|||
provider = 'wechat';
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
name = 'AlipayMiniProgram';
|
||||
platform = 'miniProgram';
|
||||
provider = 'alipay';
|
||||
// #endif
|
||||
|
||||
if (isEmpty(name)) {
|
||||
uni.showToast({
|
||||
title: '暂不支持该平台',
|
||||
|
@ -60,18 +66,40 @@ if (isEmpty(name)) {
|
|||
});
|
||||
}
|
||||
|
||||
// 定义需要加载的平台列表
|
||||
const PLATFORMS = ['wechat', 'alipay'];
|
||||
|
||||
// 加载当前平台前置行为
|
||||
const load = () => {
|
||||
if (provider === 'wechat') {
|
||||
wechat.load();
|
||||
if (PLATFORMS.includes(provider)) {
|
||||
platformService.load();
|
||||
} else if (provider === 'apple') {
|
||||
// 苹果平台的特殊加载逻辑(如果需要)
|
||||
apple.load && apple.load();
|
||||
} else if (provider) {
|
||||
console.log(`平台 ${provider} 无需前置加载`);
|
||||
} else {
|
||||
console.log('未知平台');
|
||||
}
|
||||
};
|
||||
|
||||
// 使用厂商独占sdk name = 'wechat' | 'alipay' | 'apple'
|
||||
// 根据平台标识返回对应服务,使用厂商独占sdk name = 'wechat' | 'alipay' | 'apple'
|
||||
const useProvider = (_provider = '') => {
|
||||
if (_provider === '') _provider = provider;
|
||||
if (_provider === 'wechat') return wechat;
|
||||
if (_provider === 'apple') return apple;
|
||||
const targetProvider = _provider || provider;
|
||||
|
||||
// 苹果平台特殊处理
|
||||
if (targetProvider === 'apple') {
|
||||
return apple;
|
||||
}
|
||||
|
||||
// 校验是否是已登记的平台
|
||||
if (PLATFORMS.includes(targetProvider)) {
|
||||
return platformService;
|
||||
}
|
||||
|
||||
// 未登记的平台返回 null 或抛出提示
|
||||
console.warn(`未注册的平台:${targetProvider}`);
|
||||
return null;
|
||||
};
|
||||
|
||||
// 支付服务转发
|
||||
|
|
|
@ -0,0 +1,211 @@
|
|||
import SocialApi from '@/sheep/api/member/social';
|
||||
import AuthUtil from '@/sheep/api/member/auth';
|
||||
import UserApi from '@/sheep/api/member/user';
|
||||
|
||||
const socialType = 40; // 社交类型 - 支付宝小程序
|
||||
|
||||
let subscribeEventList = [];
|
||||
|
||||
function load() {
|
||||
checkUpdate();
|
||||
getSubscribeTemplate();
|
||||
}
|
||||
|
||||
// ================= 登录相关逻辑===================
|
||||
|
||||
// 基本上的登录逻辑是和微信小程序一样的
|
||||
|
||||
//支付宝小程序静默授权登录
|
||||
const login = async () => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// 1. 获取支付宝的code
|
||||
const codeResult = await uni.login();
|
||||
if (codeResult.errMsg !== 'login:ok') {
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
// 2. 社交登录
|
||||
const loginResult = await AuthUtil.socialLogin(socialType, codeResult.code, 'default');
|
||||
if (loginResult.code === 0) {
|
||||
setOpenid(loginResult.data.openid);
|
||||
return resolve(true);
|
||||
} else {
|
||||
return resolve(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 支付宝小程序手机号授权登录
|
||||
const mobileLogin = async (e) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (e.errMsg !== 'getPhoneNumber:ok') {
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
// 1. 获得支付宝 code
|
||||
const codeResult = await uni.login();
|
||||
if (codeResult.errMsg !== 'login:ok') {
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
// TODO 2. 一键登录
|
||||
// const loginResult = await AuthUtil.weixinMiniAppLogin(e.code, codeResult.code, 'default');
|
||||
// if (loginResult.code === 0) {
|
||||
// setOpenid(loginResult.data.openid);
|
||||
// return resolve(true);
|
||||
// } else {
|
||||
// return resolve(false);
|
||||
// }
|
||||
// TODO 芋艿:shareInfo: uni.getStorageSync('shareLog') || {},
|
||||
});
|
||||
};
|
||||
|
||||
// 支付宝小程序绑定
|
||||
const bind = () => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// 1. 获得微信 code
|
||||
const codeResult = await uni.login();
|
||||
if (codeResult.errMsg !== 'login:ok') {
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
// 2. 绑定账号
|
||||
const bindResult = await SocialApi.socialBind(socialType, codeResult.code, 'default');
|
||||
if (bindResult.code === 0) {
|
||||
setOpenid(bindResult.data);
|
||||
return resolve(true);
|
||||
} else {
|
||||
return resolve(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 支付宝小程序解除绑定
|
||||
const unbind = async (openid) => {
|
||||
const { code } = await SocialApi.socialUnbind(socialType, openid);
|
||||
return code === 0;
|
||||
};
|
||||
|
||||
// 绑定用户手机号
|
||||
const bindUserPhoneNumber = (e) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// todo 待完善
|
||||
// const { code } = await UserApi.updateUserMobileByWeixin(e.code);
|
||||
// if (code === 0) {
|
||||
// resolve(true);
|
||||
// }
|
||||
resolve(false);
|
||||
});
|
||||
};
|
||||
|
||||
// 设置 openid 到本地存储,目前只有 pay 支付时会使用
|
||||
function setOpenid(openid) {
|
||||
uni.setStorageSync('openid', openid);
|
||||
}
|
||||
|
||||
// 获得 openid
|
||||
async function getOpenid(force = false) {
|
||||
let openid = uni.getStorageSync('openid');
|
||||
if (!openid && force) {
|
||||
const info = await getInfo();
|
||||
if (info && info.openid) {
|
||||
openid = info.openid;
|
||||
setOpenid(openid);
|
||||
}
|
||||
}
|
||||
return openid;
|
||||
}
|
||||
|
||||
// 获得社交信息
|
||||
async function getInfo() {
|
||||
const { code, data } = await SocialApi.getSocialUser(socialType);
|
||||
if (code !== 0) {
|
||||
return undefined;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// ========== 非登录相关的逻辑 ==========
|
||||
|
||||
// 小程序更新
|
||||
const checkUpdate = (silence = true) => {
|
||||
if (uni.canIUse('getUpdateManager')) {
|
||||
const updateManager = uni.getUpdateManager();
|
||||
updateManager.onCheckForUpdate(function (res) {
|
||||
// 请求完新版本信息的回调
|
||||
if (res.hasUpdate) {
|
||||
updateManager.onUpdateReady(function () {
|
||||
uni.showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!silence) {
|
||||
uni.showToast({
|
||||
title: '当前为最新版本',
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 获取订阅消息模板
|
||||
async function getSubscribeTemplate() {
|
||||
const { code, data } = await SocialApi.getSubscribeTemplateList();
|
||||
if (code === 0) {
|
||||
subscribeEventList = data;
|
||||
}
|
||||
}
|
||||
|
||||
// 订阅消息
|
||||
function subscribeMessage(event, callback = undefined) {
|
||||
let tmplIds = [];
|
||||
if (typeof event === 'string') {
|
||||
const temp = subscribeEventList.find((item) => item.title.includes(event));
|
||||
}
|
||||
if (temp) {
|
||||
tmplIds.push(temp.id);
|
||||
}
|
||||
if (typeof event === 'object') {
|
||||
event.forEach((e) => {
|
||||
const temp = subscribeEventList.find((item) => item.title.includes(e));
|
||||
if (temp) {
|
||||
tmplIds.push(temp.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (tmplIds.length === 0) return;
|
||||
uni.requestSubscribeMessage({
|
||||
tmplIds,
|
||||
success: () => {
|
||||
// 不管是拒绝还是同意都触发
|
||||
callback && callback();
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log(err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
load,
|
||||
login,
|
||||
bind,
|
||||
unbind,
|
||||
bindUserPhoneNumber,
|
||||
mobileLogin,
|
||||
getInfo,
|
||||
getOpenid,
|
||||
subscribeMessage,
|
||||
checkUpdate,
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
// #ifdef H5
|
||||
import service from '../wechat/officialAccount';
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
import service from '../wechat/miniProgram';
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
import service from '../wechat/openPlatform';
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
import service from '../alipay/miniProgram';
|
||||
// #endif
|
||||
|
||||
const platformService = service;
|
||||
|
||||
export default platformService;
|
|
@ -104,7 +104,7 @@
|
|||
// 控制徽标的位置,对象或者字符串形式,可以设置top和right属性
|
||||
badgeStyle: {
|
||||
type: Object,
|
||||
default: ()=>{},
|
||||
default: () => {},
|
||||
},
|
||||
isCenter: {
|
||||
type: Boolean,
|
||||
|
|
Loading…
Reference in New Issue