2023-10-11 22:20:34 +08:00
|
|
|
<script setup>
|
|
|
|
// 引入依赖
|
|
|
|
import { onLoad } from "@dcloudio/uni-app"
|
|
|
|
import mySwiper from "@/components/mySwiper.vue"
|
|
|
|
import {ref,onMounted,nextTick} from "vue"
|
|
|
|
import {useStore} from '@/store/index.js'
|
|
|
|
const store = useStore()
|
|
|
|
import api from "@/api/index"
|
|
|
|
// 函数
|
|
|
|
function getPhoneNumber (e) {
|
|
|
|
// tel_code.value = e.detail.code
|
|
|
|
console.log(e)
|
|
|
|
getAccess_token({code:e.detail.code})
|
|
|
|
// console.log(e.detail.code) // 动态令牌
|
|
|
|
// console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
|
|
|
|
// console.log(e.detail.errno) // 错误码(失败时返回)
|
|
|
|
}
|
|
|
|
async function getAccess_token(params={}){//获取token 获取手机号
|
|
|
|
//清除token缓存
|
|
|
|
// wx.clearStorageSync();
|
|
|
|
//访问接口
|
|
|
|
const data={
|
|
|
|
username:params.code,//手机号按钮获取的code
|
|
|
|
type:'wechat_mini_app',
|
|
|
|
identity:'user',
|
|
|
|
password:'111'
|
|
|
|
}
|
|
|
|
// console.log('登录参数:',data)
|
|
|
|
const res = await api.getToken(data)
|
|
|
|
wx_login()
|
|
|
|
|
|
|
|
}
|
|
|
|
async function wx_login(token_res){
|
|
|
|
let res=await new Promise(resolve=>{
|
|
|
|
uni.login({
|
|
|
|
provider: 'weixin', //使用微信登录
|
|
|
|
success: function (loginRes) {
|
|
|
|
resolve(loginRes);
|
|
|
|
console.log(loginRes,'微信登录返回信息');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let userId = ''
|
|
|
|
// const res = await api.wx_login(data)
|
|
|
|
let res2=await api.wx_login({code:res.code},userId);
|
|
|
|
}
|
2023-10-08 21:21:21 +08:00
|
|
|
</script>
|
2023-10-11 22:20:34 +08:00
|
|
|
<template>
|
|
|
|
<view class="user-box page-box">
|
|
|
|
<button class="submit-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
|
|
|
|
<!-- <image class="wx_loin_img" :src="wx_login" mode=""></image> -->
|
|
|
|
<text>登录</text>
|
|
|
|
</button>
|
|
|
|
</view>
|
|
|
|
</template>
|
2023-10-08 21:21:21 +08:00
|
|
|
<style>
|
|
|
|
</style>
|