OneKeyLoginPage.ets
5.09 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
import { router } from '@kit.ArkUI'
import { Params } from 'wdBean/Index'
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'
import HuaweiAuth from '../../utils/HuaweiAuth'
import { BusinessError } from '@kit.BasicServicesKit'
import { Logger, ToastUtils, CustomToast, EmitterUtils, EmitterEventId } from 'wdKit/Index'
import { LoginViewModel } from './LoginViewModel'
import {InterestsHobbiesModel} from '../../../../../../../products/phone/src/main/ets/pages/viewModel/InterestsHobbiesModel'
const TAG = "OneKeyLoginPage"
@Entry
@Component
struct OneKeyLoginPage {
anonymousPhone: string = ''
@State agreeProtocol: boolean = false
viewModel: LoginViewModel = new LoginViewModel()
@State toastText:string = ""
dialogToast: CustomDialogController = new CustomDialogController({
builder: CustomToast({
msg: this.toastText,
}),
autoCancel: false,
alignment: DialogAlignment.Center,
offset: { dx: 0, dy: -20 },
gridCount: 1,
customStyle: true,
maskColor:"#00000000"
})
aboutToAppear(): void {
this.anonymousPhone = HuaweiAuth.sharedInstance().anonymousPhone||""
}
build() {
Column() {
this.CloseRow()
Image($r("app.media.login_logo"))
.width(120)
.height(66)
.margin({ top: 78, bottom: 74})
.align(Alignment.Center)
Text(this.anonymousPhone)
.fontSize(30)
.fontWeight(600)
.fontColor("#222222")
.margin({bottom: 10})
.align(Alignment.Center)
this.ProtocolRow()
Row() {
Button() {
Row() {
Image($r("app.media.huawei_one_key_login_icon"))
.width(24).height(24)
Text("华为账号一键登录")
.fontColor(Color.White)
}
}
.type(ButtonType.Normal)
.height(48)
.backgroundColor(!this.agreeProtocol ? "#60ED2800" : "#ED2800")
.width("100%")
.onClick((event) => {
if (!this.agreeProtocol) {
return
}
this.requestLogin()
})
}
.padding({ left: 25, right: 25 })
.margin({top: 15})
Button("账号密码登录")
.type(ButtonType.Normal)
.align(Alignment.Center)
.foregroundColor("#666666")
.backgroundColor(Color.White)
.onClick((event) => {
router.replaceUrl({url: WDRouterPage.loginPage.url()})
})
}
}
@Builder ProtocolRow() {
Row({space: 4}) {
Image(this.agreeProtocol ? $r('app.media.login_checkbox_select') : $r('app.media.login_checkbox_unselected'))
.width(15)
.height(15)
.margin({top: 3})
.onClick(() => {
this.agreeProtocol = !this.agreeProtocol
})
Text() {
Span("我已阅读并同意").fontColor("#999999").fontSize(12).lineHeight(18)
Span("《用户协议》").fontColor("#ED2800").fontSize(12).lineHeight(18).onClick(() => {
let bean = { contentID: "1", pageID: "" } as Params
WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage, bean)
})
Span("、").fontColor("#999999").fontSize(12).lineHeight(18)
Span("《隐私政策》").fontColor("#ED2800").fontSize(12).lineHeight(18).onClick(() => {
let bean = { contentID: "2", pageID: "" } as Params
WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage, bean)
})
Span("及").fontColor("#999999").fontSize(12).lineHeight(18)
Span("《华为账号用户认证协议》").fontColor("#ED2800").fontSize(12).lineHeight(18).onClick(() => {
let bean = { contentID: "4", pageID: "" } as Params
WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage, bean)
})
}
.layoutWeight(1)
}
.alignItems(VerticalAlign.Top)
.margin({top: 15})
.padding({ left: 25, right: 25 })
.width('100%')
}
@Builder CloseRow() {
Row() {
Blank()
Image($r('app.media.login_closed'))
.width(24)
.height(24)
.onClick(() => router.back())
}.margin({ top: 15, right: 15 })
.width("100%")
}
async requestLogin() {
try {
let authorizeCode = await HuaweiAuth.sharedInstance().oneKeyLogin()
let data = await this.viewModel.huaweiOneKeyLogin(authorizeCode)
Logger.debug(TAG, "requestLogin: " + data.jwtToken)
this.showToastTip('登录成功')
///同步兴趣tag
let interestsModel = new InterestsHobbiesModel()
interestsModel.updateInterests()
this.queryUserDetail()
EmitterUtils.sendEvent(EmitterEventId.PEOPLE_SHIP_ATTENTION)
} catch (error) {
if (typeof error == "string") {
this.showToastTip(error)
} else {
(error as BusinessError)
this.showToastTip("登录失败")
}
}
}
showToastTip(msg:string){
this.toastText = msg
this.dialogToast.open()
}
queryUserDetail(){
this.viewModel.queryUserDetail().then(()=>{
router.back({
url: `${WDRouterPage.getBundleInfo()}`
}
)
}).catch(()=>{
router.back({
url: `${WDRouterPage.getBundleInfo()}`
})
})
}
}