shishuangxi

登录问题修复

... ... @@ -62,7 +62,7 @@ export class HttpBizUtil {
Logger.debug(TAG, 'post: ' + resDTO.code)
Logger.debug(TAG, 'post: ' + resDTO.message)
// 403:临时token;406:强制下线、封禁、清空登录信息还要跳转登录页面
if (resDTO.code == 0 || resDTO.code == 406) {
if (resDTO.code == 403 || resDTO.code == 406) {
HttpBizUtil.refreshToken().then((token: string) => {
if (headers) {
headers.replace('RMRB-X-TOKEN', token)
... ...
... ... @@ -18,6 +18,7 @@ import promptAction from '@ohos.promptAction';
import { LogoutViewModel } from '../../viewmodel/LogoutViewModel';
import { CustomLogoutDialog } from './CustomLogoutDialog';
import { emitter } from '@kit.BasicServicesKit';
import { ConfirmLogoutDialog } from './ConfirmLogoutDialog';
export { SettingPasswordParams } from "wdLogin"
... ... @@ -42,6 +43,19 @@ export struct AccountAndSecurityLayout {
alignment: DialogAlignment.Center
})
confirmDialogController: CustomDialogController = new CustomDialogController({
builder: ConfirmLogoutDialog({
cancel: () => {
},
confirm: () => {
this.logout()
}
}),
customStyle: true,
alignment: DialogAlignment.Center
})
aboutToAppear() {
// 获取设置页面数据
... ... @@ -172,11 +186,8 @@ export struct AccountAndSecurityLayout {
Column() {
Button('退出登录',{ stateEffect: true ,type: ButtonType.Normal}).width('90%').height('80lpx').backgroundColor('#da3e22').fontColor('#fff').margin('20lpx').borderRadius('8lpx').onClick(()=>{
let login = new LoginViewModel;
promptAction.showToast({ message: '退出登录' })
login.logOut();
router.back();
router.back();
this.confirmDialogController.open()
// AlertDialog.show({
// title: '🥟id : ' + "button",
// message: '标题:' + '退出登录',
... ... @@ -415,6 +426,16 @@ export struct AccountAndSecurityLayout {
.height('54lpx')
}
logout(){
let login = new LoginViewModel;
login.logOut().then(()=>{
promptAction.showToast({ message: '退出登录' })
router.back();
router.back();
}).catch((error:string)=>{
promptAction.showToast({ message: error })
});
}
//注销账号
requestLogout() {
... ...
/**退出登录确认弹框*/
@CustomDialog
export struct ConfirmLogoutDialog {
controller: CustomDialogController
cancel: () => void = () => {
}
confirm: () => void = () => {
}
build() {
Column() {
Text("确认退出登录吗?")
.fontColor("#222222")
.fontSize(18)
.width("100%")
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Center)
.margin({ top: 20 })
Divider().color("#999999").width("100%").margin({ top: 20 }).height('1vp')
Row() {
Text('确认')
.fontSize(16)
.fontColor("#648DF2")
.layoutWeight(1)
.fontWeight(FontWeight.Medium)
.textAlign(TextAlign.Center)
.onClick(() => {
this.controller.close()
if (this.confirm) {
this.confirm()
}
})
.height('100%')
// Divider().color("#999999").height('100%').width('0.5vp')
Text('取消')
.fontSize(16)
.fontColor("#648DF2")
.layoutWeight(1)
.fontWeight(FontWeight.Medium)
.textAlign(TextAlign.Center)
.border({
width: { left: 1 },
color: "#999999",
style: { left: BorderStyle.Solid }
})
.onClick(() => {
this.controller.close()
if (this.cancel) {
this.cancel()
}
})
.height('100%')
}.layoutWeight(1).justifyContent(FlexAlign.Center)
}.height(110).backgroundColor(Color.White).borderRadius(6).width('74%')
}
}
\ No newline at end of file
... ...
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils, ResponseDTO } from 'wdNetwork';
import { HttpBizUtil, HttpUrlUtils, ResponseDTO } from 'wdNetwork';
import { Logger, SPHelper, StringUtils } from 'wdKit';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { LoginBean } from './LoginBean';
... ... @@ -224,7 +224,7 @@ export class LoginModel {
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return new Promise<string>((success, fail) => {
HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getLogoutUrl(), bean, headers).then((data: ResponseDTO<string>) => {
HttpBizUtil.post<string>(HttpUrlUtils.getLogoutUrl(), bean, headers).then((data: ResponseDTO<string>)=>{
if (!data) {
fail("数据为空")
return
... ... @@ -234,10 +234,24 @@ export class LoginModel {
return
}
success('')
}, (error: Error) => {
}).catch((error:Error)=>{
fail(error.message)
Logger.debug("LoginViewModel:error ", error.toString())
})
// HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getLogoutUrl(), bean, headers).then((data: ResponseDTO<string>) => {
// if (!data) {
// fail("数据为空")
// return
// }
// if (data.code != 0) {
// fail(data.message)
// return
// }
// success('')
// }, (error: Error) => {
// fail(error.message)
// Logger.debug("LoginViewModel:error ", error.toString())
// })
})
}
... ...
... ... @@ -185,7 +185,7 @@ struct LoginPage {
.height(48)
.backgroundColor("#F5F5F5")
.borderRadius(4)
.type(InputType.PhoneNumber)
.type(InputType.Normal)
.onChange((content) => {
this.accountContent = content
this.isSubmit = (this.accountContent.length >= 11 && this.passwordContent.length >= 6)
... ...