diff --git a/mini.project.json b/mini.project.json new file mode 100644 index 00000000..b2c89ae5 --- /dev/null +++ b/mini.project.json @@ -0,0 +1,10 @@ +{ + "format": 2, + "compileOptions": { + "component2": true, + "enableNodeModuleBabelTransform": true, + "transpile": {}, + "globalObjectMode": "enable" + } + } + \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index 208c9591..54c7a70b 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -9,7 +9,6 @@ - diff --git a/sheep/components/s-menu-grid/s-menu-grid.vue b/sheep/components/s-menu-grid/s-menu-grid.vue index 518d6edf..444a430a 100644 --- a/sheep/components/s-menu-grid/s-menu-grid.vue +++ b/sheep/components/s-menu-grid/s-menu-grid.vue @@ -1,33 +1,33 @@ diff --git a/sheep/components/s-tabbar/s-tabbar.vue b/sheep/components/s-tabbar/s-tabbar.vue index 369a8232..06add9b7 100644 --- a/sheep/components/s-tabbar/s-tabbar.vue +++ b/sheep/components/s-tabbar/s-tabbar.vue @@ -10,22 +10,21 @@ :midTabBar="tabbar.mode === 2" :customStyle="tabbarStyle" > - - - - + + + + + + diff --git a/sheep/platform/index.js b/sheep/platform/index.js index 36a54fc6..f74e902c 100644 --- a/sheep/platform/index.js +++ b/sheep/platform/index.js @@ -15,6 +15,7 @@ import { isWxBrowser } from '@/sheep/helper/utils'; // #endif import wechat from './provider/wechat/index.js'; import apple from './provider/apple'; +import alipay from './provider/alipay/index'; import share from './share'; import Pay from './pay'; @@ -53,6 +54,12 @@ platform = 'miniProgram'; provider = 'wechat'; // #endif +// #ifdef MP-ALIPAY +name = 'AlipayMiniProgram'; +platform = 'miniProgram'; +provider = 'alipay'; +// #endif + if (isEmpty(name)) { uni.showToast({ title: '暂不支持该平台', @@ -64,14 +71,20 @@ if (isEmpty(name)) { const load = () => { if (provider === 'wechat') { wechat.load(); + }else if (provider === 'alipay') { + alipay.load(); + } else { + console.log('未知平台', provider); } }; // 使用厂商独占sdk name = 'wechat' | 'alipay' | 'apple' const useProvider = (_provider = '') => { + console.error('useProvider', _provider, 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..c6ae5352 --- /dev/null +++ b/sheep/platform/provider/alipay/index.js @@ -0,0 +1,7 @@ + +// 这里 特指支付宝小程序,后面如果需要拓展什么阿里云小程序、淘宝小程序之类的,就自己新建 +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..920c236b --- /dev/null +++ b/sheep/platform/provider/alipay/miniProgram.js @@ -0,0 +1,214 @@ +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, +}; diff --git a/sheep/platform/provider/wechat/index.js b/sheep/platform/provider/wechat/index.js index 3bb2c7fe..2ceb9556 100644 --- a/sheep/platform/provider/wechat/index.js +++ b/sheep/platform/provider/wechat/index.js @@ -10,6 +10,12 @@ import service from './miniProgram'; import service from './openPlatform'; // #endif +// 给定一个默认值,因为还存在硬编码useProvider('wechat')的情况 +// 如果这里没有默认值,那么在其他平台编译的时候,就会报错,导致全部页面起不来 +// #ifdef MP-ALIPAY +import service from './miniProgram'; +// #endif + const wechat = service; export default wechat; diff --git a/sheep/request/index.js b/sheep/request/index.js index 700c7dda..7ae371c6 100644 --- a/sheep/request/index.js +++ b/sheep/request/index.js @@ -6,7 +6,6 @@ import Request from 'luch-request'; import { baseUrl, apiPath, tenantId } from '@/sheep/config'; import $store from '@/sheep/store'; -import $platform from '@/sheep/platform'; import { showAuthModal } from '@/sheep/hooks/useModal'; @@ -54,7 +53,7 @@ const http = new Request({ header: { Accept: 'text/json', 'Content-Type': 'application/json;charset=UTF-8', - platform: $platform.name, + platform: 'test', }, // #ifdef APP-PLUS sslVerify: false, diff --git a/sheep/ui/su-swiper/su-swiper.vue b/sheep/ui/su-swiper/su-swiper.vue index cff1c4b3..195e48bd 100644 --- a/sheep/ui/su-swiper/su-swiper.vue +++ b/sheep/ui/su-swiper/su-swiper.vue @@ -259,7 +259,7 @@ } return { - height: height + 'rpx', + height: height + 'rpx' + ' !important', }; });