|
@@ -1,4 +1,8 @@
|
|
|
// pages/personal/personal.ts
|
|
|
+import ActionSheet, { ActionSheetTheme, ActionSheetShowOption } from 'tdesign-miniprogram/action-sheet/index';
|
|
|
+import { decrptPhone } from '../../api/user'
|
|
|
+
|
|
|
+const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -26,7 +30,10 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
-
|
|
|
+ const app = getApp<IAppOption>()
|
|
|
+ this.setData({
|
|
|
+ isLogin: app.globalData.isLogin
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -63,17 +70,56 @@ Page({
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
},
|
|
|
- handleGetPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
|
|
|
+ async checkSession(): Promise<boolean> {
|
|
|
+ let isExist = false
|
|
|
+ wx.checkSession({
|
|
|
+ success() {
|
|
|
+ isExist = true
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ isExist = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ await sleep(1000)
|
|
|
+ return Promise.resolve(isExist)
|
|
|
+
|
|
|
+ },
|
|
|
+ async handleGetPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
|
|
|
// debugger
|
|
|
console.log('event', event)
|
|
|
- // wx.checkSession({
|
|
|
- // success(res) {
|
|
|
- // console.log(res, '登录状态')
|
|
|
- // //session_key 未过期,并且在本生命周期一直有效
|
|
|
- // },
|
|
|
- // fail(err) {
|
|
|
- // console.log(err)
|
|
|
- // }
|
|
|
- // })
|
|
|
+ const isValid = await this.checkSession();
|
|
|
+ console.log('isValid', isValid)
|
|
|
+ if (isValid) {
|
|
|
+ const { code, iv, encryptedData } = event.detail
|
|
|
+ if (code && iv && encryptedData) {
|
|
|
+ const res = await decrptPhone({
|
|
|
+ iv: iv,
|
|
|
+ code: code,
|
|
|
+ encryptedData: encryptedData
|
|
|
+ })
|
|
|
+ console.log('res', res.phoneNumber)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleSexSelectShow() {
|
|
|
+ const basicListOption: ActionSheetShowOption = {
|
|
|
+ theme: ActionSheetTheme.List,
|
|
|
+ selector: '#t-action-sheet',
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ label: '男性',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '女性',
|
|
|
+ },
|
|
|
+
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ const handler = ActionSheet.show(basicListOption);
|
|
|
+ },
|
|
|
+ handleSelected(event: WechatMiniprogram.TouchEvent) {
|
|
|
+ console.log('event', event)
|
|
|
+ const { index } = event.detail
|
|
|
+
|
|
|
}
|
|
|
})
|