是在app要用到appsecret么?求指点,下边是代码
<template>
<wiki-container :isBack='isback' headerTitle='文档名称'>
<view class="container" slot='container'>
<view class="logo" style="margin-bottom: 655rpx;">
<image src="/static/logo.png" mode="" class="best_icon"></image>
<view class="name">
文档名称
</view>
</view>
<view class="flex justify-center" style="margin-bottom: 8rpx;">
<button type="" class="cu-btn round " open-type="" v-if="!agree" @click="showToast">手机号快捷登录</button>
<button type="" class="cu-btn round " open-type="getPhoneNumber" v-else id="login"
@getphonenumber="decryptPhoneBNumber">手机号快捷登录</button>
</view>
<view class="flex justify-center" style="margin-bottom: 100rpx;">
<button type="" class="cu-btn round default " open-type="" width='274rpx' @click="goBack">暂不登录</button>
</view>
<view class="text-sub text-center flex align-center justify-center" style="margin-bottom: 20rpx;">
<text class="lg" style="font-size: 18px;" :class="agree?'cuIcon-roundcheck text-blue' :'cuIcon-round'"
@click="agree=!agree"></text>
<view class="ml8 flex" style="font-size: 28rpx;">
我已阅读并同意
<view class="text-blue" @click.stop="toAgreements">
服务协议、隐私权限政策
</view>
</view>
</view>
</view>
</wiki-container>
</template>
<script>
export default {
data() {
return {
PageCur: 'home',
isback: true,
agree: false,
type: 'login',
logo: '',
title: '',
code: undefined,
yhxy: '',
yszc: '',
argeeLicense: false,
loginCode: '',
currentPageCur: ''
}
},
onLoad(options) {
this.currentPageCur = options.pageCur;
if (options.back && options.back === 'no') {
this.isback = false
}
if (uni.getStorageSync('open_id')) {
} else {
uni.login({
provider: 'weixin',
onlyAuthorize: true,
success: (res) => {
console.log('code', res)
this.loginCode = res.code
},
fail: function(res) {
uni.showToast({
title: '获取登录code失败',
icon: 'none'
})
}
})
}
// 获取缓存中是否有openId
},
onUnload() {
var pages = getCurrentPages(); //当前页面栈
if (pages.length > 1) {
var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
beforePage.data.refreshIfNeeded = true;
}
},
methods: {
toAgreements() {
uni.navigateTo({
url: '/pages/login/agreement'
})
},
showToast() {
uni.showToast({
title: '请阅读并勾选底部协议',
icon: 'none'
})
},
// 用户授权后调用后端接口获取用户的信息缓存token 在调用登陆的接口保存token
decryptPhoneBNumber(e) {
const vm = this
console.log(e)
if (e.detail.errMsg == "getPhoneNumber:ok") {
this.$my_api.login({
loginCode: this.loginCode,
code: e.detail.code
}).then(res => {
if (!uni.getStorageInfoSync('open_id')) {
uni.setStorageSync('open_id', res.data.user.openid)
}
this.$my_api.getOfficialPhone().then(res => {
uni.setStorage({
key: 'officePhone',
data: res.data.item ? res.data.item.phone : ''
})
})
uni.setStorage({
key: 'token',
data: res.data.user.token,
success() {
uni.setStorage({
key: 'user',
data: res.data.user,
success() {
var pages = getCurrentPages()
if (pages.length === 1) {
if (uni.getStorageSync('category_id')) {
uni.reLaunch({
url: '/pages/index/index',
})
} else {
uni.reLaunch({
url: 'pages/select-kind/select-kind'
})
}
} else {
if (vm.currentPageCur === 'mine') {
uni.reLaunch({
url: '/pages/index/index',
})
} else {
uni.navigateBack({
delta: 1,
})
}
}
}
})
}
})
})
}
},
goBack() {
uni.navigateBack({
delta: 1,
})
}
}
}
</script>
w***@163.com (作者)
应该不是这个的问题,感觉 decryptPhoneBNumber(e) 内的代码就没被执行,我加的那个console.log(e) ,在控制台都没有打印出来
2024-07-15 13:51
iosDev
回复 w***@163.com: 解决了吗
2024-07-15 16:42
w***@163.com (作者)
回复 iosDev: 没有
2024-07-16 10:52