corp-mp/src/components/privacy-consent/index.tsx

53 lines
1.7 KiB
TypeScript

import { Checkbox, CheckboxGroup, Text, View } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { requestPlatformPrivacyAuthorization } from '@/lib/consent'
import './index.scss'
type Props = {
agreed: boolean
className?: string
onChange: (agreed: boolean) => void
}
function openAgreement (type: 'service' | 'privacy') {
Taro.navigateTo({ url: `/pages/agreement/index?type=${type}` })
}
export default function PrivacyConsent ({ agreed, className = '', onChange }: Props) {
return (
<View className={`privacy-consent ${className}`.trim()}>
<CheckboxGroup
className='privacy-consent__group'
onChange={(event) => {
const nextAgreed = event.detail.value.includes('agreed')
if (!nextAgreed) {
onChange(false)
return
}
void requestPlatformPrivacyAuthorization().then((authorized) => {
onChange(authorized)
if (!authorized) {
Taro.showToast({ title: '需同意隐私保护指引后才能继续', icon: 'none' })
}
})
}}
>
<Checkbox
className='privacy-consent__checkbox'
value='agreed'
checked={agreed}
color='#165dff'
/>
<Text className='privacy-consent__text'></Text>
</CheckboxGroup>
<Text className='privacy-consent__link' onClick={() => openAgreement('service')}>
</Text>
<Text className='privacy-consent__text'></Text>
<Text className='privacy-consent__link' onClick={() => openAgreement('privacy')}>
</Text>
</View>
)
}