diff --git a/mini.project.json b/mini.project.json
new file mode 100644
index 00000000..1e6d60a2
--- /dev/null
+++ b/mini.project.json
@@ -0,0 +1,9 @@
+{
+ "format": 2,
+ "compileOptions": {
+ "component2": true,
+ "enableNodeModuleBabelTransform": true,
+ "transpile": {},
+ "globalObjectMode": "enable"
+ }
+}
\ No newline at end of file
diff --git a/pages/goods/index.vue b/pages/goods/index.vue
index 901c8919..e08ce65c 100644
--- a/pages/goods/index.vue
+++ b/pages/goods/index.vue
@@ -245,7 +245,7 @@
isDay: true,
};
const isLogin = computed(() => sheep.$store('user').isLogin);
- const state = reactive({
+ let state = reactive({
goodsId: 0,
skeletonLoading: true, // SPU 加载中
goodsInfo: {}, // SPU 信息
diff --git a/sheep/components/s-auth-modal/s-auth-modal.vue b/sheep/components/s-auth-modal/s-auth-modal.vue
index 2b396893..d1b73787 100644
--- a/sheep/components/s-auth-modal/s-auth-modal.vue
+++ b/sheep/components/s-auth-modal/s-auth-modal.vue
@@ -46,6 +46,18 @@
+
+
+
+
diff --git a/sheep/platform/index.js b/sheep/platform/index.js
index bf48e521..b53544fa 100644
--- a/sheep/platform/index.js
+++ b/sheep/platform/index.js
@@ -14,6 +14,7 @@ import { isEmpty } from 'lodash-es';
import { isWxBrowser } from '@/sheep/helper/utils';
// #endif
import wechat from './provider/wechat/index.js';
+import alipay from './provider/alipay/index';
import apple from './provider/apple';
import share from './share';
import Pay from './pay';
@@ -53,6 +54,12 @@ platform = 'miniProgram';
provider = 'wechat';
// #endif
+// #ifdef MP-ALIPAY
+name = 'alipayMiniProgram';
+platform = 'alipayMiniProgram';
+provider = 'alipay';
+// #endif
+
if (isEmpty(name)) {
uni.showToast({
title: '暂不支持该平台',
@@ -64,6 +71,8 @@ if (isEmpty(name)) {
const load = () => {
if (provider === 'wechat') {
wechat.load();
+ } else if (provider === 'alipay') {
+ alipay.load();
}
};
@@ -72,6 +81,7 @@ const useProvider = (_provider = '') => {
if (_provider === '') _provider = provider;
if (_provider === 'wechat') return wechat;
if (_provider === 'apple') return apple;
+ if (_provider === 'alipay') return alipay;
};
// 支付服务转发
diff --git a/sheep/platform/provider/alipay/index.js b/sheep/platform/provider/alipay/index.js
new file mode 100644
index 00000000..89861bcb
--- /dev/null
+++ b/sheep/platform/provider/alipay/index.js
@@ -0,0 +1,6 @@
+// 这里 特指支付宝小程序,后面如果需要拓展什么阿里云小程序、淘宝小程序之类的,就自己新建
+import service from './miniProgram';
+
+const alipay = service;
+
+export default alipay;
\ No newline at end of file
diff --git a/sheep/platform/provider/alipay/miniProgram.js b/sheep/platform/provider/alipay/miniProgram.js
new file mode 100644
index 00000000..e9555cf0
--- /dev/null
+++ b/sheep/platform/provider/alipay/miniProgram.js
@@ -0,0 +1,217 @@
+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({
+ provider: 'alipay',
+ scopes: 'auth_user',
+ });
+ 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,
+};
\ No newline at end of file
diff --git a/sheep/platform/provider/wechat/index.js b/sheep/platform/provider/wechat/index.js
index 3bb2c7fe..a0c48f19 100644
--- a/sheep/platform/provider/wechat/index.js
+++ b/sheep/platform/provider/wechat/index.js
@@ -10,6 +10,8 @@ import service from './miniProgram';
import service from './openPlatform';
// #endif
-const wechat = service;
-
+let wechat = {};
+if (typeof service !== 'undefined') {
+ wechat = service;
+}
export default wechat;
diff --git a/sheep/ui/su-fixed/su-fixed.vue b/sheep/ui/su-fixed/su-fixed.vue
index e2a98088..0aa6416a 100644
--- a/sheep/ui/su-fixed/su-fixed.vue
+++ b/sheep/ui/su-fixed/su-fixed.vue
@@ -3,7 +3,7 @@