yangsunyue_wd

desc:隐私设置、忘记密码、关于,用户登录后的token存储调整

@@ -5,6 +5,7 @@ import featureAbility from '@ohos.ability.featureAbility'; @@ -5,6 +5,7 @@ import featureAbility from '@ohos.ability.featureAbility';
5 import wantConstant from '@ohos.ability.wantConstant'; 5 import wantConstant from '@ohos.ability.wantConstant';
6 import Want from '@ohos.app.ability.Want'; 6 import Want from '@ohos.app.ability.Want';
7 import { AppUtils } from './AppUtils'; 7 import { AppUtils } from './AppUtils';
  8 +import { Callback } from '@ohos.base';
8 9
9 export class PermissionUtil { 10 export class PermissionUtil {
10 async checkAccessToken(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus> { 11 async checkAccessToken(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus> {
@@ -45,38 +46,34 @@ export class PermissionUtil { @@ -45,38 +46,34 @@ export class PermissionUtil {
45 return hasPermissions; 46 return hasPermissions;
46 } 47 }
47 48
48 - static reqPermissionsFromUser(permissions: Array<Permissions>, component: Object): void {  
49 - let context = getContext(component) as common.UIAbilityContext;  
50 - let atManager = abilityAccessCtrl.createAtManager();  
51 - // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗  
52 - atManager.requestPermissionsFromUser(context, permissions).then((data) => {  
53 - let grantStatus: Array<number> = data.authResults;  
54 - let length: number = grantStatus.length;  
55 - for (let i = 0; i < length; i++) {  
56 - if (grantStatus[i] === 0) {  
57 - // 用户授权,可以继续访问目标操作 49 + static reqPermissionsFromUser(permissions: Array<Permissions>, component: Object): Promise<boolean> {
  50 + // let hasPermissions = false;
58 51
59 - } else {  
60 52
61 - PermissionUtil.openPermissionsInSystemSettings(component);  
62 - // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限  
63 - // AlertDialog.show({  
64 - // title: '权限设置',  
65 - // message: '到系统设置中打开相应的权限',  
66 - // confirm: {  
67 - // value: "OK",  
68 - // action: () => {  
69 - //  
70 - // },  
71 - // }  
72 - // })  
73 - return; 53 + return new Promise((resolve) => {
  54 + let context = getContext(component) as common.UIAbilityContext;
  55 + let atManager = abilityAccessCtrl.createAtManager();
  56 + // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
  57 + atManager.requestPermissionsFromUser(context, permissions).then((data) => {
  58 + let grantStatus: Array<number> = data.authResults;
  59 + let length: number = grantStatus.length;
  60 + for (let i = 0; i < length; i++) {
  61 + if (grantStatus[i] === 0) {
  62 + // 用户授权,可以继续访问目标操作
  63 + resolve(true);
  64 + } else {
  65 + PermissionUtil.openPermissionsInSystemSettings(component);
  66 + }
74 } 67 }
75 - }  
76 - // 授权成功  
77 - }).catch((err:Error) => {  
78 - // console.error(`requestPermissionsFromUser failed, code is ${err.code}, message is ${err.message}`);  
79 - }) 68 + // 授权成功
  69 + }).catch((err:Error) => {
  70 +
  71 + })
  72 + });
  73 +
  74 +
  75 +
  76 + // return hasPermissions;
80 } 77 }
81 78
82 79
@@ -150,8 +150,8 @@ export class HttpUrlUtils { @@ -150,8 +150,8 @@ export class HttpUrlUtils {
150 headers.set('timestamp', HttpUrlUtils.getTimestamp()) 150 headers.set('timestamp', HttpUrlUtils.getTimestamp())
151 headers.set('RMRB-X-TOKEN', HttpUrlUtils.getXToken()) 151 headers.set('RMRB-X-TOKEN', HttpUrlUtils.getXToken())
152 headers.set('device_id', HttpUrlUtils.getDeviceId()) 152 headers.set('device_id', HttpUrlUtils.getDeviceId())
153 - if(HttpUrlUtils.token!=''){  
154 - headers.set('cookie', 'RMRB-X-TOKEN='+HttpUrlUtils.token) 153 + if(HttpUrlUtils.getXToken()!=''){
  154 + headers.set('cookie', 'RMRB-X-TOKEN='+HttpUrlUtils.getXToken())
155 } 155 }
156 headers.set('build_version', HttpUrlUtils.getVersion()) 156 headers.set('build_version', HttpUrlUtils.getVersion())
157 headers.set('adcode', HttpUrlUtils.getAdCode()) 157 headers.set('adcode', HttpUrlUtils.getAdCode())
@@ -232,6 +232,10 @@ export class HttpUrlUtils { @@ -232,6 +232,10 @@ export class HttpUrlUtils {
232 } 232 }
233 233
234 private static getXToken() { 234 private static getXToken() {
  235 + let jwttoken = SPHelper.default.getSync(SpConstants.USER_JWT_TOKEN,"")
  236 + if(StringUtils.isNotEmpty(jwttoken)) {
  237 + return jwttoken as string;
  238 + }
235 return 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc'; 239 return 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc';
236 } 240 }
237 241
@@ -293,14 +297,19 @@ export class HttpUrlUtils { @@ -293,14 +297,19 @@ export class HttpUrlUtils {
293 297
294 private static getUserId() { 298 private static getUserId() {
295 // TODO 对接登录 299 // TODO 对接登录
296 - // let userid = await SPHelper.default.get(SpConstants.USER_ID,"")  
297 - // if(StringUtils.isNotEmpty(userid)) {  
298 - // return userid as string;  
299 - // } 300 + let userid = SPHelper.default.getSync(SpConstants.USER_ID,"")
  301 + if(StringUtils.isNotEmpty(userid)) {
  302 + return userid as string;
  303 + }
300 return HttpUrlUtils.userId; 304 return HttpUrlUtils.userId;
301 } 305 }
302 306
303 private static getUserType() { 307 private static getUserType() {
  308 + let userType = SPHelper.default.getSync(SpConstants.USER_Type,"")
  309 + if(StringUtils.isNotEmpty(userType)) {
  310 + return userType as string;
  311 + }
  312 +
304 return HttpUrlUtils.userType; 313 return HttpUrlUtils.userType;
305 } 314 }
306 315
@@ -331,7 +340,7 @@ export class HttpUrlUtils { @@ -331,7 +340,7 @@ export class HttpUrlUtils {
331 } 340 }
332 341
333 static editUserDetail() { 342 static editUserDetail() {
334 - let url = HttpUrlUtils.hostUrl + "/user/zh/c/editUserDetail"; 343 + let url = HttpUrlUtils.hostUrl + "/api/rmrb-user-center/user/zh/c/editUserDetail";
335 return url; 344 return url;
336 } 345 }
337 346
1 import { Params } from 'wdBean'; 1 import { Params } from 'wdBean';
2 import { WDRouterPage, WDRouterRule } from 'wdRouter'; 2 import { WDRouterPage, WDRouterRule } from 'wdRouter';
  3 +import featureAbility from '@ohos.ability.featureAbility';
3 4
4 const TAG = 'AboutPageUI'; 5 const TAG = 'AboutPageUI';
5 6
@@ -7,7 +8,7 @@ const TAG = 'AboutPageUI'; @@ -7,7 +8,7 @@ const TAG = 'AboutPageUI';
7 export struct AboutPageUI { 8 export struct AboutPageUI {
8 @State listData: Array<string | Array<string>> = ['隐私授权协议', '软件许可及用户协议']; 9 @State listData: Array<string | Array<string>> = ['隐私授权协议', '软件许可及用户协议'];
9 @State message: string = '京ICP备16066560号-6A Copyright © 人民日报客户端\nall rights reserved.' 10 @State message: string = '京ICP备16066560号-6A Copyright © 人民日报客户端\nall rights reserved.'
10 - @State version: string = '版本号:v8.0.1.1' 11 + @State version: string = '版本号:v'
11 12
12 13
13 build() { 14 build() {
@@ -18,6 +19,11 @@ export struct AboutPageUI { @@ -18,6 +19,11 @@ export struct AboutPageUI {
18 .title('关于') 19 .title('关于')
19 } 20 }
20 21
  22 + aboutToAppear(){
  23 + let context = getContext();
  24 + context.getApplicationContext();
  25 + }
  26 +
21 @Builder aboutUi() { 27 @Builder aboutUi() {
22 Column() { 28 Column() {
23 Image($r('app.media.setting_about_logo')) 29 Image($r('app.media.setting_about_logo'))
@@ -3,12 +3,14 @@ import { PermissionUtil } from 'wdKit' @@ -3,12 +3,14 @@ import { PermissionUtil } from 'wdKit'
3 import { SPHelper } from 'wdKit' 3 import { SPHelper } from 'wdKit'
4 import hilog from '@ohos.hilog'; 4 import hilog from '@ohos.hilog';
5 import { PrivacySettingModel } from '../../model/PrivacySettingModel' 5 import { PrivacySettingModel } from '../../model/PrivacySettingModel'
  6 +import { Params } from 'wdBean';
  7 +import { WDRouterPage, WDRouterRule } from 'wdRouter';
6 8
7 const TAG = 'PrivacySettingComponents'; 9 const TAG = 'PrivacySettingComponents';
8 10
9 @Component 11 @Component
10 export struct PrivacySettingComponents { 12 export struct PrivacySettingComponents {
11 - @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')]; 13 + @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.APPROXIMATELY_LOCATION'), new PrivacySettingModel('麦克风权限', false, 'ohos.permission.MICROPHONE')];
12 @State tips: string = '设置前可查阅' 14 @State tips: string = '设置前可查阅'
13 @State privacyTips: string = '《隐私政策》' 15 @State privacyTips: string = '《隐私政策》'
14 16
@@ -26,6 +28,7 @@ export struct PrivacySettingComponents { @@ -26,6 +28,7 @@ export struct PrivacySettingComponents {
26 for (const element of this.listData) { 28 for (const element of this.listData) {
27 if (element.privacyName == '开启个性推荐') { 29 if (element.privacyName == '开启个性推荐') {
28 element.queryUserDetail(); 30 element.queryUserDetail();
  31 + // element.permission = true;
29 continue; 32 continue;
30 } 33 }
31 const result = await permissionUtil.checkPermissions(element.permissionKey); 34 const result = await permissionUtil.checkPermissions(element.permissionKey);
@@ -59,7 +62,9 @@ export struct PrivacySettingComponents { @@ -59,7 +62,9 @@ export struct PrivacySettingComponents {
59 if (!item.permission) { 62 if (!item.permission) {
60 //跳转权限设置 63 //跳转权限设置
61 const permissionUtil = new PermissionUtil(); 64 const permissionUtil = new PermissionUtil();
62 - PermissionUtil.reqPermissionsFromUser([item.permissionKey], this); 65 + PermissionUtil.reqPermissionsFromUser([item.permissionKey], this).then((res)=>{
  66 + item.permission = res;
  67 + });
63 } 68 }
64 } 69 }
65 }) 70 })
@@ -82,6 +87,8 @@ export struct PrivacySettingComponents { @@ -82,6 +87,8 @@ export struct PrivacySettingComponents {
82 .margin({ top: '46lpx' }) 87 .margin({ top: '46lpx' })
83 .onClick(() => { 88 .onClick(() => {
84 //跳转隐私政策 89 //跳转隐私政策
  90 + let bean={contentId:"2",pageID:""} as Params
  91 + WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage,bean)
85 }) 92 })
86 } 93 }
87 94
@@ -150,6 +157,7 @@ struct getTuiJianCell { @@ -150,6 +157,7 @@ struct getTuiJianCell {
150 // .selectedColor(Color.Pink) 157 // .selectedColor(Color.Pink)
151 .onChange((isOn: boolean) => { 158 .onChange((isOn: boolean) => {
152 // this.privacySwitch = isOn; 159 // this.privacySwitch = isOn;
  160 + this.item.editUserDetail(isOn?'1':'0');
153 }) 161 })
154 } 162 }
155 163
@@ -24,6 +24,8 @@ export interface EditInfoModel{ @@ -24,6 +24,8 @@ export interface EditInfoModel{
24 birthday:string 24 birthday:string
25 //性别 25 //性别
26 sex:string 26 sex:string
  27 + // 推荐开关 0:关 1:开(默认)
  28 + airec:number
27 } 29 }
28 30
29 export interface editModel{ 31 export interface editModel{
@@ -3,6 +3,8 @@ import HashMap from '@ohos.util.HashMap'; @@ -3,6 +3,8 @@ import HashMap from '@ohos.util.HashMap';
3 import { HttpUrlUtils, ResponseDTO } from 'wdNetwork'; 3 import { HttpUrlUtils, ResponseDTO } from 'wdNetwork';
4 import { Logger } from 'wdKit'; 4 import { Logger } from 'wdKit';
5 import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; 5 import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
  6 +import EditInfoViewModel from '../viewmodel/EditInfoViewModel';
  7 +import { editModel } from './EditInfoModel';
6 8
7 9
8 @Observed 10 @Observed
@@ -20,10 +22,12 @@ export class PrivacySettingModel{ @@ -20,10 +22,12 @@ export class PrivacySettingModel{
20 22
21 23
22 queryUserDetail() { 24 queryUserDetail() {
  25 + // EditInfoViewModel
  26 +
23 let bean: Record<string, string> = {}; 27 let bean: Record<string, string> = {};
24 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); 28 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
25 - return new Promise<string>((success, fail) => {  
26 - HttpRequest.get<ResponseDTO<string>>(HttpUrlUtils.queryUserDetail(), headers).then((data: ResponseDTO<string>) => { 29 + return new Promise<editModel>((success, fail) => {
  30 + HttpRequest.get<ResponseDTO<editModel>>(HttpUrlUtils.queryUserDetail(), headers).then((data: ResponseDTO<editModel>) => {
27 if (!data || !data.data) { 31 if (!data || !data.data) {
28 fail("数据为空") 32 fail("数据为空")
29 return 33 return
@@ -32,7 +36,8 @@ export class PrivacySettingModel{ @@ -32,7 +36,8 @@ export class PrivacySettingModel{
32 fail(data.message) 36 fail(data.message)
33 return 37 return
34 } 38 }
35 - // this.permission = data.data.userExtend.airec as boolean; 39 + this.permission = Boolean(data.data.userExtend.airec)
  40 + console.log('this.permission',this.permission);
36 success(data.data) 41 success(data.data)
37 }, (error: Error) => { 42 }, (error: Error) => {
38 fail(error.message) 43 fail(error.message)
@@ -202,6 +202,7 @@ export class LoginModel { @@ -202,6 +202,7 @@ export class LoginModel {
202 let JwtToken = SPHelper.default.getSync(SpConstants.USER_JWT_TOKEN, '') as string; 202 let JwtToken = SPHelper.default.getSync(SpConstants.USER_JWT_TOKEN, '') as string;
203 203
204 headers.set('JwtToken',(JwtToken)); 204 headers.set('JwtToken',(JwtToken));
  205 + headers.set('rmrb-x-token',(JwtToken));
205 return new Promise<string>((success, fail) => { 206 return new Promise<string>((success, fail) => {
206 HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getForgetPasswordUrl(), bean, headers).then((data: ResponseDTO<string>) => { 207 HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getForgetPasswordUrl(), bean, headers).then((data: ResponseDTO<string>) => {
207 if (!data || !data.data) { 208 if (!data || !data.data) {
@@ -188,6 +188,7 @@ export struct SettingPasswordLayout { @@ -188,6 +188,7 @@ export struct SettingPasswordLayout {
188 Row() { 188 Row() {
189 TextInput({ placeholder: item.inputPlacholder }) 189 TextInput({ placeholder: item.inputPlacholder })
190 .type(InputType.Password) 190 .type(InputType.Password)
  191 + .showPasswordIcon(false)
191 .backgroundColor('#00000000') 192 .backgroundColor('#00000000')
192 .onChange((value: string) => { 193 .onChange((value: string) => {
193 this.inputTextChange(value, item.inputTag) 194 this.inputTextChange(value, item.inputTag)
@@ -66,7 +66,7 @@ @@ -66,7 +66,7 @@
66 } 66 }
67 }, 67 },
68 { 68 {
69 - "name": "ohos.permission.LOCATION", 69 + "name": "ohos.permission.APPROXIMATELY_LOCATION",
70 "reason": "$string:EntryAbility_desc", 70 "reason": "$string:EntryAbility_desc",
71 "usedScene": { 71 "usedScene": {
72 "abilities": [ 72 "abilities": [