yangsunyue_wd

desc:隐私设置、忘记密码

... ... @@ -3,6 +3,8 @@ import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import common from '@ohos.app.ability.common';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
import Want from '@ohos.app.ability.Want';
import { AppUtils } from './AppUtils';
export class PermissionUtil {
async checkAccessToken(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus> {
... ... @@ -43,42 +45,53 @@ export class PermissionUtil {
return hasPermissions;
}
static reqPermissionsFromUser(permissions: Array<Permissions>): void {
// let context = getContext(this) as common.UIAbilityContext;
// let atManager = abilityAccessCtrl.createAtManager();
// // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
// atManager.requestPermissionsFromUser(context, permissions).then((data) => {
// let grantStatus: Array<number> = data.authResults;
// let length: number = grantStatus.length;
// for (let i = 0; i < length; i++) {
// if (grantStatus[i] === 0) {
// // 用户授权,可以继续访问目标操作
//
// } else {
//
// this.jumpSetting();
// // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
// AlertDialog.show({
// title: '权限设置',
// message: '到系统设置中打开相应的权限',
// confirm: {
// value: "OK",
// action: () => {
//
// },
// }
// })
// return;
// }
// }
// // 授权成功
// }).catch((err) => {
// console.error(`requestPermissionsFromUser failed, code is ${err.code}, message is ${err.message}`);
// })
}
static reqPermissionsFromUser(permissions: Array<Permissions>, component: Object): void {
let context = getContext(component) as common.UIAbilityContext;
let atManager = abilityAccessCtrl.createAtManager();
// requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
atManager.requestPermissionsFromUser(context, permissions).then((data) => {
let grantStatus: Array<number> = data.authResults;
let length: number = grantStatus.length;
for (let i = 0; i < length; i++) {
if (grantStatus[i] === 0) {
// 用户授权,可以继续访问目标操作
} else {
static jumpSetting() {
PermissionUtil.openPermissionsInSystemSettings(component);
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
// AlertDialog.show({
// title: '权限设置',
// message: '到系统设置中打开相应的权限',
// confirm: {
// value: "OK",
// action: () => {
//
// },
// }
// })
return;
}
}
// 授权成功
}).catch((err:Error) => {
// console.error(`requestPermissionsFromUser failed, code is ${err.code}, message is ${err.message}`);
})
}
static openPermissionsInSystemSettings(component: Object): void {
let context = getContext(component) as common.UIAbilityContext;
let wantInfo:Want = {
action: 'action.settings.app.info',
parameters: {
settingsParamBundleName: AppUtils.getPackageName(context) // 打开指定应用的详情页面
}
}
context.startAbility(wantInfo).then(() => {
// ...
}).catch((err:Error) => {
// ...
})
}
}
... ...
... ... @@ -265,6 +265,21 @@ export class HttpUrlUtils {
return url;
}
static getForgetPasswordUrl() {
let url = HttpUrlUtils.hostUrl + "/api/rmrb-user-center/auth/zh/c/forgotPassword";
return url;
}
static queryUserDetail() {
let url = HttpUrlUtils.hostUrl + "/api/rmrb-user-center/user/zh/c/queryUserDetail";
return url;
}
static editUserDetail() {
let url = HttpUrlUtils.hostUrl + "/user/zh/c/editUserDetail";
return url;
}
static getAppLoginUrl() :string{
let url = HttpUrlUtils.getHost() + "/api/rmrb-user-center/auth/zh/c/appLogin";
return url;
... ...
... ... @@ -55,9 +55,7 @@ export class WDRouterPage {
static aboutPage = new WDRouterPage("wdComponent", "ets/components/page/SettingAboutPage");
// 设置页
static settingPage = new WDRouterPage("wdComponent", "ets/components/page/SettingPage");
// 账户与安全页
// static loginProtocolPage = new WDRouterPage("wdLogin", "ets/pages/login/LoginProtocolWebview");
// 设置密码页、设置手机号页等等 (需要传参)
// static loginProtocolPage = new WDRouterPage("wdLogin", "ets/pages/login/LoginProtocolWebview");
static settingPasswordPage = new WDRouterPage("wdLogin", "ets/pages/login/SettingPasswordPage");
}
... ...
... ... @@ -12,6 +12,7 @@
"wdWebComponent": "file:../../commons/wdWebComponent",
"wdBean": "file:../../features/wdBean",
"wdRouter": "file:../../commons/wdRouter",
"wdNetwork": "file:../../commons/wdNetwork"
"wdNetwork": "file:../../commons/wdNetwork",
"wdLogin": "file:../../features/wdLogin"
}
}
... ...
import { Params } from 'wdBean';
import { WDRouterPage, WDRouterRule } from 'wdRouter';
const TAG = 'AboutPageUI';
@Component
... ... @@ -41,7 +44,15 @@ export struct AboutPageUI {
ForEach(this.listData, (item:string, index : number) =>{
ListItem() {
this.getArrowCell(item, index)
}
}.onClick(() =>{
if (index == 0) {
let bean={contentId:"1",pageID:""} as Params
WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage,bean)
}else{
let bean={contentId:"2",pageID:""} as Params
WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage,bean)
}
})
})
}.divider({
strokeWidth: 1,
... ...
... ... @@ -2,20 +2,17 @@
import { BottomNavi, CommonConstants } from 'wdConstant';
import { Logger } from 'wdKit';
import { TopNavigationComponent } from '../page/TopNavigationComponent';
// import { BottomNavDTO } from '../../repository/bean/BottomNavDTO';
// import { UIUtils } from '../../repository/UIUtils';
// import { MinePageComponent } from './MinePageComponent';
import PageViewModel from '../../viewmodel/PageViewModel';
import {MineMainSettingFunctionItem} from '../../viewmodel/MineMainSettingFunctionItem';
import MineSettingDatasModel from '../../model/MineSettingDatasModel';
// import MineMainSettingFunctionItem from '../../model/MineSettingDatasModel';
// import { MineMainSettingFunctionItem } from '../setting/MineSettingDatasModel'
import storageStatistics from "@ohos.file.storageStatistics";
import { BusinessError } from '@ohos.base';
import ArrayList from '@ohos.util.ArrayList';
import router from '@ohos.router';
import { WDRouterPage, WDRouterRule } from 'wdRouter';
import { Params } from 'wdBean';
import { SettingPasswordParams } from 'wdLogin';
export { SettingPasswordParams } from "wdLogin"
@Component
export struct AccountAndSecurityLayout {
... ... @@ -61,11 +58,14 @@ export struct AccountAndSecurityLayout {
}
.onClick(() => {
console.log(index + "")
if (index == 1) {
router.pushUrl({
url:"pages/SettingPasswordPage",
params : {'currentType' : 4}
})
if (index == 0){
}else if (index == 1) {
let params: SettingPasswordParams = {
pageID:'1',
}
WDRouterRule.jumpWithPage(WDRouterPage.settingPasswordPage, params)
}
})
... ...
... ... @@ -23,7 +23,7 @@ export struct MineSettingComponent {
if (err) {
console.error(`Invoke getCurrentBundleStats failed, code is ${err.code}, message is ${err.message}`);
} else {
this.cacheSice = bundleStats.appSize / 1024.00 / 1024.00;
this.cacheSice = bundleStats.cacheSize / 1024.00 / 1024.00;
}
});
}
... ... @@ -68,13 +68,13 @@ export struct MineSettingComponent {
// pageType:'AccountAndSecurityLayout'
// };
console.log(subIndex + "")
if (subIndex == 0) {
if (subIndex == 0 && index == 0) {
let params: Params = {
pageID: 'AccountAndSecurityLayout'
}
WDRouterRule.jumpWithPage(WDRouterPage.settingPage, params)
}else if (subIndex == 2) {
}else if (subIndex == 2 && index == 0) {
WDRouterRule.jumpWithPage(WDRouterPage.privacySettingPage)
}
... ... @@ -157,11 +157,11 @@ export struct MineSettingComponent {
// 左侧logo和标题
Row() {
// 判断有没有图片
if (this.privacySwitch) {
Image('https://pic.rmb.bdstatic.com/e182cf67c341d1128d2a6cc05886bf62.jpeg@s_0,h_2000')
.height('38lpx')
.margin({ right: '5lpx' })
}
// if (this.privacySwitch) {
// Image('https://pic.rmb.bdstatic.com/e182cf67c341d1128d2a6cc05886bf62.jpeg@s_0,h_2000')
// .height('38lpx')
// .margin({ right: '5lpx' })
// }
Text(`${item}`)
.margin({ top: '8lpx' })
.height('38lpx')
... ...
... ... @@ -24,7 +24,8 @@ export struct PrivacySettingComponents {
async getPermissionStatus() {
const permissionUtil = new PermissionUtil();
for (const element of this.listData) {
if (element.privacyName = '开启个性推荐') {
if (element.privacyName == '开启个性推荐') {
element.queryUserDetail();
continue;
}
const result = await permissionUtil.checkPermissions(element.permissionKey);
... ... @@ -58,7 +59,7 @@ export struct PrivacySettingComponents {
if (!item.permission) {
//跳转权限设置
const permissionUtil = new PermissionUtil();
PermissionUtil.reqPermissionsFromUser([item.permissionKey]);
PermissionUtil.reqPermissionsFromUser([item.permissionKey], this);
}
}
})
... ...
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils, ResponseDTO } from 'wdNetwork';
import { Logger } from 'wdKit';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
@Observed
export class PrivacySettingModel{
privacyName: string
... ... @@ -10,4 +16,59 @@ export class PrivacySettingModel{
this.permission = permission;
this.permissionKey = permissionKey;
}
queryUserDetail() {
let bean: Record<string, string> = {};
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return new Promise<string>((success, fail) => {
HttpRequest.get<ResponseDTO<string>>(HttpUrlUtils.queryUserDetail(), headers).then((data: ResponseDTO<string>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
// this.permission = data.data.userExtend.airec as boolean;
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug("LoginViewModel:error ", error.toString())
})
})
}
editUserDetail(airec:string) {
let bean: Record<string, string> = {};
bean['airec'] = airec;
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return new Promise<string>((success, fail) => {
HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.editUserDetail(), bean, headers).then((data: ResponseDTO<string>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug("LoginViewModel:error ", error.toString())
})
})
}
}
\ No newline at end of file
... ...
export { add } from "./src/main/ets/utils/Calc"
\ No newline at end of file
export { add } from "./src/main/ets/utils/Calc"
export { SettingPasswordParams } from "./src/main/ets/pages/login/SettingPasswordLayout"
\ No newline at end of file
... ...
... ... @@ -3,6 +3,10 @@ import { LoginInputComponent } from './LoginInputComponent'
import { LoginViewModel } from './LoginViewModel'
import router from '@ohos.router'
import promptAction from '@ohos.promptAction'
import { Params } from '../../../../../../../commons/wdRouter/oh_modules/wdBean/Index'
import { WDRouterRule, WDRouterPage } from 'wdRouter';
import { SettingPasswordParams } from './SettingPasswordLayout'
const TAG = 'ForgetPasswordPage'
/**
... ... @@ -85,7 +89,13 @@ struct ForgetPasswordPage {
}
this.loginViewModel.checkVerifyCode(this.phoneContent, this.codeContent).then(() => {
//todo 跳转密码设置页面
let params: SettingPasswordParams = {
pageID:'1',
phoneContent:this.phoneContent,
codeContent:this.codeContent,
}
WDRouterRule.jumpWithPage(WDRouterPage.settingPasswordPage, params)
promptAction.showToast({message:"校验成功,准备跳转设置页面"})
Logger.debug(TAG,"校验成功")
}).catch((error:string)=>{
... ...
... ... @@ -112,5 +112,30 @@ export class LoginModel {
})
})
}
//忘记密码 设置新密码
resetPassword(password: string, tempToken: string) {
let bean: Record<string, string> = {};
bean['password'] = password;
bean['tempToken'] = tempToken;
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return new Promise<string>((success, fail) => {
HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getForgetPasswordUrl(), bean, headers).then((data: ResponseDTO<string>) => {
if (!data || !data.data) {
fail("数据为空")
return
}
if (data.code != 0) {
fail(data.message)
return
}
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug("LoginViewModel:error ", error.toString())
})
})
}
}
... ...
... ... @@ -92,6 +92,20 @@ export class LoginViewModel {
})
}
//重置密码
resetPassword(password: string, tempToken: string) {
return new Promise<string>(async (success, fail) => {
let passwordNew = await this.doMd(password)
this.loginModel.resetPassword(passwordNew, tempToken).then((data) => {
success(data)
}).catch((message: string) => {
fail(message)
})
})
}
async doMd(content: string): Promise<string> {
let mdAlgName = 'SHA256'; // 摘要算法名
... ...
import ArrayList from '@ohos.util.ArrayList';
import promptAction from '@ohos.promptAction';
import { Params } from '../../../../../../../commons/wdRouter/oh_modules/wdBean/Index';
import router from '@ohos.router';
import { LoginViewModel } from './LoginViewModel';
import { Logger, SPHelper } from 'wdKit';
import {
SpConstants
} from '../../../../../../../commons/wdNetwork/oh_modules/wdConstant/src/main/ets/constants/SpConstants'
import data_preferences from '@ohos.data.preferences';
const TAG = "SettingPasswordLayout"
export interface SettingPasswordParams {
pageID: string;
phoneContent?: string;
codeContent?: string;
tempToken?:string;
}
export default class AccoutPageDataModel {
// 页面数据
compType: number // 0:标题 / 1:密码输入框 / 2:验证码输入框 / 3:desc描述 / 4:按钮 / 5:logo / 6:子标题 7:手机号输入框 7:空白
compLogo: string
compTitle: string
// compSubTitle: string
compSubTitle: string = '';
compDesc: string
compButtonTitle: string
inputPlacholder: string
... ... @@ -23,16 +39,28 @@ export default class AccoutPageDataModel {
}
}
@Entry
@Component
export struct SettingPasswordLayout {
@State listData: Array<AccoutPageDataModel> = new Array(); // 页面配置数据
@State btnStatus: boolean = false
@State btnStatus: boolean = false;
pageId:number = 0;
phoneContent:string = '';
codeContent:string = '';
tempToken:string = '';
password01: string = '';
password02: string = '';
passwordOri: string = '';
loginViewModel = new LoginViewModel()
aboutToAppear() {
this.getPageListData(4)
let params:SettingPasswordParams = router.getParams() as SettingPasswordParams;
this.pageId = parseInt(params.pageID);
this.getPageListData(this.pageId)
this.phoneContent = params.phoneContent!;
this.codeContent = params.codeContent!;
}
getPageListData(pageId:number) {
... ... @@ -50,8 +78,8 @@ export struct SettingPasswordLayout {
this.listData.push(new AccoutPageDataModel(0, '设置密码', '', '', '', '', 0))
this.listData.push(new AccoutPageDataModel(1, '', '', '', '', '请输入密码', 10086))
this.listData.push(new AccoutPageDataModel(1, '', '', '', '', '再次输入密码', 10087))
this.listData.push(new AccoutPageDataModel(4, '', '', '提示:密码长度6-20位,需答谢字母、小写字母、数字、特殊字符中组合三种及三种以上组成', '', '', 0))
this.listData.push(new AccoutPageDataModel(5, '', '', '', '确认', '', 0))
this.listData.push(new AccoutPageDataModel(3, '', '', '提示:密码长度6-20位,需答谢字母、小写字母、数字、特殊字符中组合三种及三种以上组成', '', '', 0))
this.listData.push(new AccoutPageDataModel(4, '', '', '', '确认', '', 0))
break;
case 2:
... ... @@ -75,7 +103,7 @@ export struct SettingPasswordLayout {
case 4:
// 有logo的
this.listData.push(new AccoutPageDataModel(5, '', 'https://img-blog.csdnimg.cn/24f43f4d626d428891ebb2adb5c2c2e9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5YyX5aSn5Z-55paH5byg6ICB5biI,size_20,color_FFFFFF,t_70,g_se,x_16', '', '', '' , 0))
this.listData.push(new AccoutPageDataModel(5, '', '', '', '', '' , 0))
this.listData.push(new AccoutPageDataModel(0, '修改密码', '', '', '', '', 0))
this.listData.push(new AccoutPageDataModel(1, '', '', '', '', '请输入原密码', 10010))
this.listData.push(new AccoutPageDataModel(1, '', '', '', '', '请输入新密码', 10086))
... ... @@ -277,8 +305,21 @@ export struct SettingPasswordLayout {
return
}
promptAction.showToast({ message: '请求接口' })
}
if(this.pageId == 1){ //设置密码
if (this.password01.length < 6 || this.password01.length > 20) {
promptAction.showToast({ message: '密码不符合密码规范' })
return
}
if (this.password01 != this.password02) {
promptAction.showToast({ message: '密码不一致' })
return
}
}
}
// 输入框数据变动:输入数据处理
... ... @@ -292,11 +333,21 @@ export struct SettingPasswordLayout {
}
if (this.password01) {
if (this.password01 == this.password02 && this.password01.length >= 6 && this.password01.length <= 20) {
if ((this.password01.length >= 6 && this.password01.length <= 20) && (this.password02.length >= 6 && this.password02.length <= 20)) {
this.btnStatus = true;
} else {
this.btnStatus = false;
}
SPHelper.default.get(SpConstants.USER_JWT_TOKEN, '').then((str) => {
this.loginViewModel.resetPassword(this.password01, str.toString()).then((data =>{
}))
}).catch((err: Error) => {
Logger.error(TAG, 'catch err:' + JSON.stringify(err));
});
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -4,6 +4,7 @@
"pages/login/LoginPage",
"pages/login/ForgetPasswordPage",
"pages/login/LoginProtocolWebview",
"pages/login/SettingPasswordPage"
"pages/login/SettingPasswordPage",
"pages/login/SettingPasswordLayout"
]
}
... ...