53 lines
1.7 KiB
TypeScript
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>
|
|
)
|
|
}
|