init master vue cli
parent
44eec40775
commit
3184dcd4f1
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"format": 2,
|
||||||
|
"compileOptions": {
|
||||||
|
"component2": true,
|
||||||
|
"enableNodeModuleBabelTransform": true,
|
||||||
|
"transpile": {},
|
||||||
|
"globalObjectMode": "enable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -245,7 +245,7 @@
|
||||||
isDay: true,
|
isDay: true,
|
||||||
};
|
};
|
||||||
const isLogin = computed(() => sheep.$store('user').isLogin);
|
const isLogin = computed(() => sheep.$store('user').isLogin);
|
||||||
const state = reactive({
|
let state = reactive({
|
||||||
goodsId: 0,
|
goodsId: 0,
|
||||||
skeletonLoading: true, // SPU 加载中
|
skeletonLoading: true, // SPU 加载中
|
||||||
goodsInfo: {}, // SPU 信息
|
goodsInfo: {}, // SPU 信息
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,18 @@
|
||||||
<view class="circle" />
|
<view class="circle" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 7.3 支付宝小程序登录 -->
|
||||||
|
<button
|
||||||
|
v-if="sheep.$platform.name === 'alipayMiniProgram'"
|
||||||
|
@tap="thirdLogin('alipay')"
|
||||||
|
class="ss-reset-button auto-login-btn"
|
||||||
|
>
|
||||||
|
<image
|
||||||
|
class="auto-login-img"
|
||||||
|
:src="sheep.$url.static('/static/img/shop/platform/alipay.png')"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
<!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
|
<!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
|
||||||
<button
|
<button
|
||||||
v-if="
|
v-if="
|
||||||
|
|
@ -185,7 +197,7 @@
|
||||||
} else {
|
} else {
|
||||||
sheep.$helper.toast('请选择是否同意协议');
|
sheep.$helper.toast('请选择是否同意协议');
|
||||||
}
|
}
|
||||||
return;
|
// return;
|
||||||
}
|
}
|
||||||
const loginRes = await sheep.$platform.useProvider(provider).login();
|
const loginRes = await sheep.$platform.useProvider(provider).login();
|
||||||
if (loginRes) {
|
if (loginRes) {
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,13 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 顶部导航栏-情况2:装修组件导航栏-标准 -->
|
<!-- 顶部导航栏-情况2:装修组件导航栏-标准 -->
|
||||||
|
<!--#ifndef MP-ALIPAY-->
|
||||||
<s-custom-navbar
|
<s-custom-navbar
|
||||||
v-else-if="navbar === 'custom' && navbarMode === 'normal'"
|
v-else-if="navbar === 'custom' && navbarMode === 'normal'"
|
||||||
:data="navbarStyle"
|
:data="navbarStyle"
|
||||||
:showLeftButton="showLeftButton"
|
:showLeftButton="showLeftButton"
|
||||||
/>
|
/>
|
||||||
|
<!--#endif-->
|
||||||
<view class="page-body" :style="[bgBody]">
|
<view class="page-body" :style="[bgBody]">
|
||||||
<!-- 顶部导航栏-情况3:沉浸式头部 -->
|
<!-- 顶部导航栏-情况3:沉浸式头部 -->
|
||||||
<su-inner-navbar v-if="navbar === 'inner'" :title="title" />
|
<su-inner-navbar v-if="navbar === 'inner'" :title="title" />
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { isEmpty } from 'lodash-es';
|
||||||
import { isWxBrowser } from '@/sheep/helper/utils';
|
import { isWxBrowser } from '@/sheep/helper/utils';
|
||||||
// #endif
|
// #endif
|
||||||
import wechat from './provider/wechat/index.js';
|
import wechat from './provider/wechat/index.js';
|
||||||
|
import alipay from './provider/alipay/index';
|
||||||
import apple from './provider/apple';
|
import apple from './provider/apple';
|
||||||
import share from './share';
|
import share from './share';
|
||||||
import Pay from './pay';
|
import Pay from './pay';
|
||||||
|
|
@ -53,6 +54,12 @@ platform = 'miniProgram';
|
||||||
provider = 'wechat';
|
provider = 'wechat';
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef MP-ALIPAY
|
||||||
|
name = 'alipayMiniProgram';
|
||||||
|
platform = 'alipayMiniProgram';
|
||||||
|
provider = 'alipay';
|
||||||
|
// #endif
|
||||||
|
|
||||||
if (isEmpty(name)) {
|
if (isEmpty(name)) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '暂不支持该平台',
|
title: '暂不支持该平台',
|
||||||
|
|
@ -64,6 +71,8 @@ if (isEmpty(name)) {
|
||||||
const load = () => {
|
const load = () => {
|
||||||
if (provider === 'wechat') {
|
if (provider === 'wechat') {
|
||||||
wechat.load();
|
wechat.load();
|
||||||
|
} else if (provider === 'alipay') {
|
||||||
|
alipay.load();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -72,6 +81,7 @@ const useProvider = (_provider = '') => {
|
||||||
if (_provider === '') _provider = provider;
|
if (_provider === '') _provider = provider;
|
||||||
if (_provider === 'wechat') return wechat;
|
if (_provider === 'wechat') return wechat;
|
||||||
if (_provider === 'apple') return apple;
|
if (_provider === 'apple') return apple;
|
||||||
|
if (_provider === 'alipay') return alipay;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 支付服务转发
|
// 支付服务转发
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
// 这里 特指支付宝小程序,后面如果需要拓展什么阿里云小程序、淘宝小程序之类的,就自己新建
|
||||||
|
import service from './miniProgram';
|
||||||
|
|
||||||
|
const alipay = service;
|
||||||
|
|
||||||
|
export default alipay;
|
||||||
|
|
@ -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,
|
||||||
|
};
|
||||||
|
|
@ -10,6 +10,8 @@ import service from './miniProgram';
|
||||||
import service from './openPlatform';
|
import service from './openPlatform';
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
const wechat = service;
|
let wechat = {};
|
||||||
|
if (typeof service !== 'undefined') {
|
||||||
|
wechat = service;
|
||||||
|
}
|
||||||
export default wechat;
|
export default wechat;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<view
|
<view
|
||||||
class="ui-fixed-box"
|
class="ui-fixed-box"
|
||||||
:id="`fixed-${uuid}`"
|
:id="`fixed-${uuid}`"
|
||||||
:class="[{ fixed: state.fixed }]"
|
:class="['fixed']"
|
||||||
:style="[
|
:style="[
|
||||||
{
|
{
|
||||||
left: sticky ? 'auto' : '0px',
|
left: sticky ? 'auto' : '0px',
|
||||||
|
|
@ -150,10 +150,13 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const computedQuery = () => {
|
const computedQuery = () => {
|
||||||
|
console.log('uuid', uuid)
|
||||||
|
console.log('computedQuery', sheep.$platform.device.windowHeight)
|
||||||
uni.createSelectorQuery()
|
uni.createSelectorQuery()
|
||||||
.in(vm)
|
.in(vm)
|
||||||
.select(`#fixed-${uuid}`)
|
.select(`#fixed-${uuid}`)
|
||||||
.boundingClientRect((data) => {
|
.boundingClientRect((data) => {
|
||||||
|
console.log('createSelectorQuery', data)
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
state.content = data;
|
state.content = data;
|
||||||
if (unref(props.sticky)) {
|
if (unref(props.sticky)) {
|
||||||
|
|
@ -165,7 +168,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const setFixed = (value) => {
|
const setFixed = (value) => {
|
||||||
|
console.log('setFixed1', sheep.$platform.device.windowHeight)
|
||||||
if (unref(props.bottom)) {
|
if (unref(props.bottom)) {
|
||||||
|
console.log('setFixed2', sheep.$platform.device.windowHeight)
|
||||||
state.fixed =
|
state.fixed =
|
||||||
value >=
|
value >=
|
||||||
state.content.bottom -
|
state.content.bottom -
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,7 @@
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
this.safeAreaInsets = screenHeight - safeArea.bottom;
|
this.safeAreaInsets = screenHeight - safeArea.bottom;
|
||||||
// #endif
|
// #endif
|
||||||
// #ifndef MP-WEIXIN
|
// #ifndef MP-WEIXIN || MP-ALIPAY
|
||||||
this.safeAreaInsets = safeAreaInsets.bottom;
|
this.safeAreaInsets = safeAreaInsets.bottom;
|
||||||
// #endif
|
// #endif
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue