元服务那些事儿 | 舞刀解决隐私声明,斩断上架牵绊

话说元服务初上的年间,鸿蒙江湖高手云起,都是一顿键盘手猛敲,元服务推陈出新,创意层出不穷,无不风生水起。

江湖规矩:每个元服务必须提供规范的隐私声明,否则提交元服务发布上架后,将导致审核无法通过。用户使用元服务前,必须引导其了解隐私声明信息,获取用户授权后,才能继续使用元服务。

话说上回,挥剑解决无需登录场景下元服务的隐私声明。

这回,好多高手慕名要求解决需要登录场景下元服务的隐私声明。

不少元服务服务直达后,需要通过用户登录获取用户信息,提供更加极致更加领先的元服务体验。那就推荐在登录界面提供隐私声明提示,引导用户阅读和授权,获取授权后才可继续使用。

声明范例如下图。

狂舞四刀后,元服务效果如下图。

【一 拖刀如林】

拖刀式积蓄大招,犹如丛林之势。

潇洒走江湖,必先熟读江湖规矩。隐私声明具体要求请参见隐私声明规范。

【二 抽刀如花】

抽刀式抹去网络权限烦恼。

隐私声明详情必然需要通过访问互联网读取加载,所以需要在config.json配置文件中增加网络访问权限。

代码示例:

javascript 复制代码
"reqPermissions": [
  {
    "name": "ohos.permission.INTERNET"
  }
]

【三 劈刀如虎】

劈刀式,如猛虎下山,一刀定乾坤。

隐私声明实现的代码结构如下:

新建detailman 页面用来显示上图声明范例中超链接跳转的H5页面,common下新增images资源实现checkBox组件效果。其中index页面是元服务首页。

协议详情页面的detailman.hml文件,可以使用web组件显示H5页面内容。

注意 :web组件会覆盖页面其他组件,无法使用组件事件实现回退。如果需要回退,可以考虑使用Java 的WebView实现。

代码示例:

javascript 复制代码
<div class="container">
    <web src="{{param}}"></web> </div>

协议详情页面的detailman.js 文件,定义param 变量接受index 页面router传过来的参数。

代码示例:

javascript 复制代码
	export default {
    data: {
        param: ""
    },
    onInit() {
    }
}

协议详情页面的detailman.css文件。

代码示例:

javascript 复制代码
.container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
}

【四 撩刀如龙】

撩刀式,如神龙飞舞,威武霸气。

元服务首页的index.hml 文件,因为JS UI中不支持checkBox 组件,于是使用image来实现选择效果。

代码示例:

javascript 复制代码
<div class="container">
<!--方式二:首页使用check框-->
    <div style="flex-direction: row; align-items: center; justify-content: center;"> <image id="checkImage" style="width: 25px; height: 25px;margin: 3%;" src="{{imagePath}}" onclick="agreeCheck"></image> <text style="width: 80%; text-align: start; padding: 2%; line-height: 25px;justify-content: center;"> <span class="fontStyle" style="color: #ff181717;">我已阅读并同意</span> <span class="fontStyle" style="color: #ff0800ff;" onclick="go(rule)">{{ rule }}</span> <span class="fontStyle">与</span> <span class="fontStyle" style="color: #ff0800ff;" onclick="go(privacy)">{{ privacy }}</span> </text> </div> </div>

image资源可参考下图。

元服务首页的index.js 文件,在onshow中查询存储数据,初始化check状态。

代码示例:

javascript 复制代码
import Router from '@system.router';
import storage from '@ohos.data.storage';
import featureAbility from '@ohos.ability.featureAbility';
export default {
    data: {
        privacy: "《隐私政策》", rule: "《用户协议》", imagePath: "/common/images/uncheck.png", context: "" }, onInit() { this.context = featureAbility.getContext(); }, onShow() { //方式二:打开页面时初始化用户是否已同意 this.context.getFilesDir().then((filePath) => { storage.getStorage(filePath + '/myDatastore').then((dataStorage) => { dataStorage.get("hasAgree", "false").then((value) => { if (value == "false") { this.imagePath = "/common/images/uncheck.png" } else { this.imagePath = "/common/images/check.png" } }) }) }) }, go(flag) { let url = "https://www.51miz.com/so-wendang/11963302.html?utm_term=12452681&utm_source=baidu3&bd_vid=8250967139616741558" if (flag == "《用户协议》") { url = "https://www.51miz.com/so-wendang/11963302.html?utm_term=12452681&utm_source=baidu3&bd_vid=8250967139616741558" } else { url = "https://www.tukuppt.com/wordmuban/yinsizhengce.html?plan=11177-37593-12085827&bd_vid=8439929694061694080" } Router.push({ uri: "pages/detailman/detailman", params: { param: url } }) this.$element('dragDialog').close(); }, agreeCheck() { this.context.getFilesDir().then((filePath) => { storage.getStorage(filePath + '/myDatastore').then((dataStorage) => { dataStorage.get("hasAgree", "false").then((value) => { if (value == "false") { //处理同意逻辑并保存已同意参数 dataStorage.putSync("hasAgree", "true"); dataStorage.flushSync(); this.imagePath = "/common/images/check.png" } else { //处理不同意逻辑并保存已同意参数 dataStorage.putSync("hasAgree", "false"); dataStorage.flushSync(); this.imagePath = "/common/images/uncheck.png" } }) }); }) } }

元服务首页的index.css文件

javascript 复制代码
.container {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
}
.fontStyle{
    font-size: 16px
}

继承D意志的游侠们,他们三招解一题,千里不留行,事了拂衣去,深藏身与名。鸿蒙江湖高手勿发愁,勿上头,又一个场景的隐私声明问题已帮您解决,斩断了上架的牵绊,快快开启夏日多巴胺,二次激发元服务开发豪情。。。。。。

相关推荐
程序猿追5 小时前
kotlin-retry 接入鸿蒙后,怎样确认它真的会停止重试
开发语言·kotlin·harmonyos
懿路向前8 小时前
HarmonyOS 粒子特效实战:emitter.size 是双刃剑:粒子精确定位 [0,0] 与条带随机出生(HarmonyOS)
华为·harmonyos
马剑威(威哥爱编程)8 小时前
【共创稿事节】HarmonyOS 7 Agent 开发实战 04:云端 RAG 搭企业私有知识库问答
人工智能·华为·harmonyos
贾伟康9 小时前
【晨迹相机|20】HarmonyOS ArkTS AppGallery 发布复查实战:核对包名、版本、设备、素材和离线声明
harmonyos·arkts·appgallery·发布审核·上架复查
特立独行的猫a10 小时前
用仓颉写桌面应用:从 npx 建工程到串口实时示波器
开源·harmonyos·tauri·仓颉·cj-tarui
懿路向前11 小时前
HarmonyOS 粒子特效实战:马赛克切块提速 17.6×~38×:desiredRegion 重复读盘与一次解码管线(HarmonyOS)
华为·harmonyos
天府云创13 小时前
Agentic开发时代到来——鸿蒙PC三大原生开发工具公测
华为·操作系统·harmonyos·鸿蒙系统·cli·deveco·agentic
程序猿追13 小时前
Fleks 鸿蒙适配:从八个小球看实体和组件的变化
华为·harmonyos
Sunny_GMF14 小时前
Markdown 导出 HTML 实战:2.6MB 编辑器快照如何瘦身 71%(DOM 净化 + CSSOM 运行时裁剪)
编辑器·html·ai编程·harmonyos
m0_7381858214 小时前
Flutter 鸿蒙化实战:the_apple_sign_in 适配 OpenHarmony,Apple 登录
flutter·华为·harmonyos·鸿蒙