yujialong 3 weeks ago
parent 95122c9dd9
commit e48bea77a9
  1. 206
      src/components/getPhoneModal/index.tsx
  2. 2
      src/components/gift/index.tsx
  3. 7
      src/pages/Subscribe/index.tsx
  4. 4
      src/pages/UserHome/UserSubscribe/index.less
  5. 25
      src/pages/UserHome/index.tsx

@ -31,79 +31,118 @@ export default function GetPhoneNumber({ onClose, scene = null, modalVisible, on
const handleGetUserPhone = (e: any) => {
console.log(e.detail)
Taro.request({
url: 'https://interapi.jm-kid.com/api/register',
method: 'POST',
data: {
MCODE: e.detail.code,
channel: 'wusehua_mini',
open_id: Taro.getStorageSync('LoginKey'),
invite_code: inviteCode
},
success: (res: any) => {
console.log('用户注册信息=>',res)
Taro.setStorageSync('UserAvatar', res.data.user.Avatar)
Taro.setStorageSync('UserNickName', res.data.user.NickName)
Taro.setStorageSync('UserPhoneNumber', res.data.user.Mobile)
Taro.setStorageSync('UserInviteCode', res.data.user.InviteCode)
Taro.setStorageSync('UserToken', res.data.token)
if(scene){
const open_id = Taro.getStorageSync('LoginKey')
if (open_id) {
Taro.request({
url: 'https://interapi.jm-kid.com/api/register',
method: 'POST',
data: {
MCODE: e.detail.code,
channel: 'wusehua_mini',
open_id,
invite_code: inviteCode
},
success: (res: any) => {
console.log('用户注册信息=>',res)
Taro.setStorageSync('UserAvatar', res.data.user.Avatar)
Taro.setStorageSync('UserNickName', res.data.user.NickName)
Taro.setStorageSync('UserPhoneNumber', res.data.user.Mobile)
Taro.setStorageSync('UserInviteCode', res.data.user.InviteCode)
Taro.setStorageSync('UserToken', res.data.token)
if(scene){
Taro.request({
url: 'https://interapi.jm-kid.com/api/product/exchange',
method: 'POST',
header: {
authorization: `bearer ${Taro.getStorageSync('UserToken')}`
},
data: {
timestamp: Date.now(),
change_code: scene
},
success: (s_res: any) => {
console.log('兑换成功=>', s_res.data)
if(s_res.data.state === '200'){
let modalContent = ''
s_res.data.data.Subscribed.forEach(element => {
modalContent += `兑换成功: ${element.PrdtTitle}\n`
})
Taro.showModal({
title: '兑换成功',
content: modalContent,
showCancel: true,
success: (modal_res) => {
if (modal_res.confirm) {
console.log('用户点击确定')
Taro.navigateTo({
url: '/pages/CollectionDetail/index?id=' + s_res.data.data.Subscribed[0].PrdtId
})
} else if (modal_res.cancel) {
console.log('用户点击取消')
}
}
})
}else if(s_res.data.state === '207'){
Taro.showToast({
title: '兑换码已使用',
icon: 'error'
})
}
},
fail: (err: any) => {
console.log('兑换失败=>', err)
}
})
}
//注册成功
onClose(true)
//关闭弹窗
onModalClose()
},
fail: (err: any) => {
console.log('用户注册失败=>',err)
}
})
} else {
// 如果没有openId,则先调登录
Taro.login({
success:function(res) {
console.log('微信登录成功', res.code)
Taro.request({
url: 'https://interapi.jm-kid.com/api/product/exchange',
method: 'POST',
header: {
authorization: `bearer ${Taro.getStorageSync('UserToken')}`
},
url: 'https://interapi.jm-kid.com/api/login',
data: {
timestamp: Date.now(),
change_code: scene
CODE: res.code,
channel: 'wusehua_mini',
},
success: (s_res: any) => {
console.log('兑换成功=>', s_res.data)
if(s_res.data.state === '200'){
let modalContent = ''
s_res.data.data.Subscribed.forEach(element => {
modalContent += `兑换成功: ${element.PrdtTitle}\n`
})
Taro.showModal({
title: '兑换成功',
content: modalContent,
showCancel: true,
success: (modal_res) => {
if (modal_res.confirm) {
console.log('用户点击确定')
Taro.navigateTo({
url: '/pages/CollectionDetail/index?id=' + s_res.data.data.Subscribed[0].PrdtId
})
} else if (modal_res.cancel) {
console.log('用户点击取消')
}
}
})
}else if(s_res.data.state === '207'){
Taro.showToast({
title: '兑换码已使用',
icon: 'error'
})
success: function(sres) {
console.log('静默授权登录成功', sres.data)
if(sres.data.state === 200){
Taro.setStorageSync('UserAvatar', sres.data.data.user.Avatar)
Taro.setStorageSync('UserNickName', sres.data.data.user.NickName)
Taro.setStorageSync('UserPhoneNumber', sres.data.data.user.Mobile)
Taro.setStorageSync('UserInviteCode', sres.data.data.user.InviteCode)
Taro.setStorageSync('UserToken', sres.data.token)
//注册成功
onClose(true)
//关闭弹窗
onModalClose()
}else{
//注册key
Taro.setStorageSync('LoginKey', sres.data.open_id)
}
},
fail: (err: any) => {
console.log('兑换失败=>', err)
}
})
}
//注册成功
onClose(true)
//关闭弹窗
onModalClose()
},
fail: (err: any) => {
console.log('用户注册失败=>',err)
}
})
})
}
}
return (
@ -121,18 +160,31 @@ export default function GetPhoneNumber({ onClose, scene = null, modalVisible, on
<View className='phone_modal'>
<View className='phone_modal_logo'></View>
<Button
className='phone_modal_container'
openType='getPhoneNumber'
onGetPhoneNumber={handleGetUserPhone}
>
{/* <View className='phone_modal_icon'></View> */}
<View
className='phone_modal_title'
>
</View>
</Button>
{
Taro.getStorageSync('LoginKey') ?
<Button
className='phone_modal_container'
openType='getPhoneNumber'
onGetPhoneNumber={handleGetUserPhone}
>
<View
className='phone_modal_title'
>
</View>
</Button> :
<Button
className='phone_modal_container'
onClick={handleGetUserPhone}
>
<View
className='phone_modal_title'
>
</View>
</Button>
}
<Text
className='phone_modal_desc'
onClick={handleOverlayClick}

@ -10,6 +10,6 @@ export default function Gift() {
}
return (
<Image src='https://oss.jm-kid.com/wx_5colorflower/icons/gift.svg' mode='widthFix' className='gift_icon' onClick={toCustomer}></Image>
<Image src='https://oss.jm-kid.com/wx_5colorflower/icons/gift.svg?v=1' mode='widthFix' className='gift_icon' onClick={toCustomer}></Image>
)
}

@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from 'react'
import Taro, { useDidShow, useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
import Taro, { useDidShow, useDidHide, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
import { Image, Input, ScrollView, View, Text } from '@tarojs/components'
import PopupHalfScreen from '../../components/Popup'
@ -319,13 +319,16 @@ export default function Subscribe() {
}
useDidShow(() => {
console.log('componentDidShow')
if(Taro.getStorageSync('UserToken')){
setisGetUsePhone(true)
}
requestUserSubscribe()
})
useDidHide(() => {
setisGetUsePhone(false)
})
useEffect(() => {
if(isGetUsePhone){
requestUserSubscribe()

@ -1,6 +1,8 @@
page {
background: #fafafa;
}
.subscribe_bg {
height: 100vh;
background: #fafafa;
padding: 1rem;
.subscribe_header {

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect, useState, useCallback } from 'react'
import Taro, { useDidHide, useDidShow, useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
import { Image, View, Text } from '@tarojs/components'
import UserExchangeModal from '../../components/UserExchangeModal'
@ -80,6 +80,8 @@ export default function UserHome() {
//管理登录弹窗
const [isLoginOpen, setisLoginOpen] = useState(false)
const [initialized, setInitialized] = useState(true);
const handleGetUserProfile = () => {
if(!Taro.getStorageSync('UserToken')){
setisLoginOpen(true)
@ -101,13 +103,12 @@ export default function UserHome() {
// })
}
//更新用户信息
useDidShow(() => {
console.log('更新用户信息', Taro.getStorageSync('UserNickName'))
const handleUserInfo = useCallback(() => {
setInitialized(false)
console.log('更新用户信息', isGetUsePhone,Taro.getStorageSync('UserNickName'))
setuserAvator(Taro.getStorageSync('UserAvatar') || '')
setuserNickName(Taro.getStorageSync('UserNickName') || '')
if(Taro.getStorageSync('UserToken')){
setuserAvator(Taro.getStorageSync('UserAvatar'))
setuserNickName(Taro.getStorageSync('UserNickName'))
Taro.request({
url: 'https://interapi.jm-kid.com/api/info/num',
method: 'POST',
@ -138,6 +139,15 @@ export default function UserHome() {
setOperationList([...list])
setisLoginOpen(true)
}
}, [])
useEffect(() => {
initialized || handleUserInfo()
}, [isGetUsePhone])
//更新用户信息
useDidShow(() => {
handleUserInfo()
})
useDidHide(() => {
@ -145,6 +155,7 @@ export default function UserHome() {
setuserAvator(Taro.getStorageSync('UserAvatar'))
setuserNickName(Taro.getStorageSync('UserNickName'))
}
setisGetUsePhone(false)
})
// useLoad((query) => {

Loading…
Cancel
Save