PrivacySettingComponents.ets
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import dataPreferences from '@ohos.data.preferences';
import { PermissionUtil } from 'wdKit'
import { SPHelper } from 'wdKit'
import hilog from '@ohos.hilog';
import { PrivacySettingModel } from '../../model/PrivacySettingModel'
const TAG = 'PrivacySettingComponents';
@Component
export struct PrivacySettingComponents {
@State listData: Array<PrivacySettingModel> = [new PrivacySettingModel('开启个性推荐', false, 'ohos.permission.READ_MEDIA'), new PrivacySettingModel('相册权限', false, 'ohos.permission.READ_MEDIA'), new PrivacySettingModel('相机权限', false, 'ohos.permission.CAMERA'), new PrivacySettingModel('定位权限', false, 'ohos.permission.LOCATION'), new PrivacySettingModel('麦克风权限', false, 'ohos.permission.MICROPHONE')];
@State tips: string = '设置前可查阅'
@State privacyTips: string = '《隐私政策》'
aboutToAppear() {
// 获取权限=
// SPHelper.default.save('sdf','sdf');
// this.initListData();
this.getPermissionStatus();
// RefreshStatus;
}
async getPermissionStatus() {
const permissionUtil = new PermissionUtil();
for (const element of this.listData) {
if (element.privacyName = '开启个性推荐') {
continue;
}
const result = await permissionUtil.checkPermissions(element.permissionKey);
element.permission = result;
}
}
build() {
Navigation() {
//滑动区域
this.PrivacySettingComponentsUI()
}.titleMode(NavigationTitleMode.Mini)
.title('隐私设置')
.backgroundColor('#F8F8F8')
}
@Builder PrivacySettingComponentsUI() {
Column() {
List({ space: '23lpx' }) {
ForEach(this.listData, (item: PrivacySettingModel, index:number) => {
ListItem() {
if (index == 0) {
getTuiJianCell({ item:item, index:index });
} else {
getArrowCell({ item:item, index:index });
}
}.onClick(() => {
if (index != 0) {
if (!item.permission) {
//跳转权限设置
const permissionUtil = new PermissionUtil();
PermissionUtil.reqPermissionsFromUser([item.permissionKey]);
}
}
})
})
}
.padding({ left: '29lpx', right: '29lpx' })
.margin({ top: '38lpx' })
Row() {
Text(this.tips)
.fontSize('25lpx')
.textAlign(TextAlign.Start)
.fontColor($r("app.color.color_666666"))
.margin({ left: '29lpx', top: '46lpx' })
// .backgroundColor(Color.Orange)
Text(this.privacyTips)
.fontSize('25lpx')
.textAlign(TextAlign.Start)
.fontColor('#ED2800')
.margin({ top: '46lpx' })
.onClick(() => {
//跳转隐私政策
})
}
}
.width('100%')
.height('100%')
.backgroundColor('#F8F8F8')
.alignItems(HorizontalAlign.Start)
}
}
@Component
struct getArrowCell {
@ObjectLink item: PrivacySettingModel;
index:number = 0;
// 右文字+箭头cell
// @Builder getArrowCell(item:PrivacySettingModel, index) {
build() {
Row() {
// 左侧标题
Text(this.item.privacyName)
.fontColor('#666666')
.fontSize('31lpx')
Row() {
Text(this.item.permission ? '已开启' : '去设置')
.fontColor(this.item.permission ? '#666666' : '#CCCCCC')
.fontSize('31lpx')
.margin({ right: '8lpx' })
Image($r('app.media.mine_user_arrow'))
.width('27lpx')
.height('27lpx')
.objectFit(ImageFit.Auto)
}
}
.alignItems(VerticalAlign.Center)
.justifyContent(FlexAlign.SpaceBetween)
.height('97lpx')
.width('100%')
.padding({ left: '29lpx', right: '29lpx' })
.backgroundColor('#FFFFFF')
.borderRadius('8lpx')
}
}
@Component
struct getTuiJianCell {
@ObjectLink item: PrivacySettingModel;
index:number = 0;
build() {
Column() {
Row() {
// 左侧标题
Text(this.item.privacyName)
.fontColor('#666666')
.fontSize('31lpx')
Row() {
Toggle({ type: ToggleType.Switch, isOn: this.item.permission })
.height('58lpx')
.width('96lpx')
// .selectedColor(Color.Pink)
.onChange((isOn: boolean) => {
// this.privacySwitch = isOn;
})
}
}
.alignItems(VerticalAlign.Center)
.justifyContent(FlexAlign.SpaceBetween)
.height('97lpx')
.width('100%')
Blank()
.backgroundColor('#EDEDED')
.height('1lpx')
Text('关闭后,将无法看到个性化推荐的服务')
.fontColor('#999999')
.fontSize('23lpx')
.margin({ right: '8lpx' })
.height('69lpx')
}
.alignItems(HorizontalAlign.Start)
.backgroundColor('#FFFFFF')
.borderRadius('8lpx')
.padding({ left: '29lpx', right: '29lpx' })
}
}