138 lines
3.7 KiB
Vue
138 lines
3.7 KiB
Vue
<template>
|
|
<view class="login">
|
|
<view class="headPortrait">
|
|
<image :src="headPortrait"></image>
|
|
</view>
|
|
<view class="name">{{ userName }}</view>
|
|
<view class="signature">
|
|
您暂未授权小程序获取您的信息,将无法使用小程序会员相关功能。如需正常使用,请点击“授权登录”按钮,进行授权登录绑定。登录绑定后享受消费返积分活动以及会员的对应福利。
|
|
</view>
|
|
<view class="buttonone">
|
|
<button open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
|
|
<uni-icons type="paperplane" size="18" color="#fff"></uni-icons>
|
|
<view style="margin-left: 0.2rem">授权并获取手机号</view>
|
|
</button>
|
|
</view>
|
|
<view @click="cancel" class="buttontow">取消</view>
|
|
<view @click="login" class="buttontow">微信</view>
|
|
<view @click="wx" class="buttontow">支付</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref } from 'vue';
|
|
import { APIuserLogin } from '@/api/user/index.js';
|
|
const headPortrait = ref('');
|
|
const userName = ref(null);
|
|
const cancel = () => {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
});
|
|
};
|
|
// 获取用户手机号
|
|
const onGetPhoneNumber = async (e) => {
|
|
const { detail } = e;
|
|
console.log(detail);
|
|
};
|
|
// 微信登录
|
|
const login = async () => {
|
|
await uni.login({
|
|
provider: 'weixin',
|
|
success: function (loginRes) {
|
|
console.log('获取用户信息', loginRes);
|
|
headPortrait.value = loginRes.code;
|
|
userLogin();
|
|
}
|
|
});
|
|
};
|
|
// 登录获取信息
|
|
const userLogin = async () => {
|
|
const res = await APIuserLogin(String(headPortrait.value));
|
|
console.log(res);
|
|
uni.setStorage({
|
|
key: 'storage_token',
|
|
data: res.data.token,
|
|
success: function () {
|
|
uni.showToast({
|
|
title: '登录成功'
|
|
});
|
|
}
|
|
});
|
|
uni.setStorage({
|
|
key: 'storage_uid',
|
|
data: res.data.wxUser.id,
|
|
success: function () {
|
|
console.log(1);
|
|
}
|
|
});
|
|
};
|
|
// 微信支付
|
|
// const wx = async () => {
|
|
// // 仅作为示例,非真实参数信息。
|
|
// uni.requestPayment({
|
|
// provider: 'wxpay',
|
|
// timeStamp: String(1718168976),
|
|
// nonceStr: 'zkm7YLNPxlCGArL05EEO5Lc4uHrp8btH',
|
|
// package: 'prepay_id=wx1213093640398592aa2114b3f4caf40001',
|
|
// signType: 'RSA',
|
|
// paySign:
|
|
// 'YyTswlJ9WwYEl+aOwXDm1iQORDQPz82zkjBrE0mUkZjHLoOJU8Hg8bdOieHJT/3EQGkQ8ByIYxdMcXei8fSTUpK7C7/ZAd70Rynz3HhXxpPPIZmOhiCcx3mBbLQQx00RhQveC+TFBWt/mBWCFb7RzyfdH6RYAr4bRBya7xnWb7E/YDES6ONOD/JMgjbAnkLmQhBoPH5y4F21VUarVvRj69pDGYJmkpA6JlR92DQbefXVjF1NlP5fFXksdeZzRI04wPGzyMgxsNnGFe4mSuDLb9vhokHgYJvCkGiyco7bsFTHq31grX2ivaZX17JtWtR2aPIc794VGprYcFLDoK3New==',
|
|
// success: function (res) {
|
|
// console.log('success:' + JSON.stringify(res));
|
|
// },
|
|
// fail: function (err) {
|
|
// console.log('fail:' + JSON.stringify(err));
|
|
// }
|
|
// });
|
|
// };
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.login {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
margin-top: 4rem;
|
|
.headPortrait {
|
|
image {
|
|
width: 6rem;
|
|
height: 6rem;
|
|
border-radius: 3rem;
|
|
}
|
|
}
|
|
.name {
|
|
font-weight: 700;
|
|
margin-top: 1.5rem;
|
|
}
|
|
.signature {
|
|
width: 90%;
|
|
font-size: 0.9rem;
|
|
margin-top: 2rem;
|
|
line-height: 1.2rem;
|
|
color: #9299b0;
|
|
}
|
|
.buttonone {
|
|
margin-top: 2rem;
|
|
button {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 22rem;
|
|
background-color: #00ba26;
|
|
color: #fff;
|
|
border-radius: 1.5rem;
|
|
}
|
|
}
|
|
.buttontow {
|
|
display: flex;
|
|
align-items: center;
|
|
background-color: #fff;
|
|
border: 1px solid #00ba26;
|
|
color: #00ba26;
|
|
padding: 0.7rem 9.8rem;
|
|
margin-top: 2.5rem;
|
|
border-radius: 1.8rem;
|
|
}
|
|
}
|
|
</style>
|