import { CustomDialogPrivacy,PreferencesUtil } from '@nutpi/privacy_dialog'let preferencesUtil = new PreferencesUtil();
import('privacy_dialog/src/main/ets/components/PrivacyPage'); // 引入静态共享包中的命名路由页面
// 开始显示隐私协议对话框 /** * 如果localHtml参数为true,urlPage参数为空,显示默认隐私协议 * 如果localHtml参数为true,urlPage参数不为空,显示urlPage参数本地html文件 * 如果localHtml参数为false,urlPage参数为空,显示默认隐私协议 * 如果localHtml参数为false,urlPage参数不为空,显示urlPage参数http或https返回html文件 */ // privacyPage为三方库里的routeName private privacyPage: string = 'privacyPage' // RouterParams参数1为localHtml=true时,使用本地rawfile目录下html文件,为false时,使用远程http隐私协议 // RouterParams参数2根据参数1而定,为true时,写本地html文件名如:privacy.html,为false时,如:http://xxxx/zh-cn_userAgreement.html openPrivacyPage() { try { router.pushNamedRoute({ name: this.privacyPage, params: new RouterParams(true, 'privacy.html') }).then(() => { console.info("xx push page success"); }).catch((err: BusinessError) => { console.error(`xx pushUrl failed, code: ${err.code}, msg: ${err.message}`); }) } catch (err) { let message = (err as BusinessError).message let code = (err as BusinessError).code console.error(`xx pushNamedRoute failed, code is ${code}, message is ${message}`); } } privacyDialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialogPrivacy({ openPrivacy: this.openPrivacyPage }), autoCancel: false, alignment: DialogAlignment.Center, customStyle: true }) onPageShow() { console.info('xx onPageShow 显示隐私协议') preferencesUtil.getChangePrivacy().then((value) => { console.info(`xx onPageShow 获取隐私协议状态:${value}`) if (!value) { this.privacyDialogController.open() } }) } onPageHide() { console.info(`xx Index -> onPageHide Close Start`) this.privacyDialogController.close() console.info(`xx Index -> onPageHide Close End`) } aboutToDisappear() { console.info(`xx Index -> aboutToDisappear`) this.privacyDialogController.close() } // 结束显示隐私协议对话框
评论