EditUserNikeNamePage.ets
3.05 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
import { CustomTitleUI } from '../reusable/CustomTitleUI'
import router from '@ohos.router'
import { editModel, editModelParams, WDEditDataModelType } from '../../model/EditInfoModel'
import EditInfoViewModel from '../../viewmodel/EditInfoViewModel';
// import { encryptMessage } from '../../../utils/cryptoUtil'
import { encryptMessage } from 'wdLogin/src/main/ets/utils/cryptoUtil'
@Entry
@Component
struct EditUserNikeNamePage {
///接收传参
@State numCount: number = 0
@State textColor : string = '#222222'
@State nikeName: string = ''
@State params:editModelParams = router.getParams() as editModelParams;
@State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
build() {
Column(){
CustomTitleUI({titleName:'修改昵称'})
Row(){
TextInput({placeholder:'请输入昵称',text:this.params.editContent})
.width('100%')
.maxLength(16)
.height(50)
.backgroundColor(Color.White)
.placeholderColor('#999999')
.onChange(value => {
this.numCount = value.length
if (this.numCount === 16) {
this.textColor = '#ED2800'
}else if(this.numCount === 0){
this.textColor = '#999999'
}else {
this.textColor = '#222222'
}
this.nikeName = value
})
Row(){
Text(this.numCount.toString())
.fontColor(this.textColor)
Text('/16')
.fontColor('#999999')
}.margin({left: -50})
}
.alignItems(VerticalAlign.Center)
Divider()
.margin({ top:0,bottom:20,left:20 ,right:20 })
Row(){
Text('1、账号中(头像、昵称等)不允许含有违禁违规内容;\n2、最多16个字,只能输入中文、数字、英文字母。')
.fontSize(13)
.fontColor(Color.Gray).lineHeight(25)
}.padding({left:16}).width('100%')
Button('保存')
.type(ButtonType.Normal)
.width('90%')
.backgroundColor('#ED2800')
.opacity(this.numCount === 0 ? 0.6 : 1)
.fontColor(this.numCount === 0 ? '#999999' : Color.White)
.borderRadius(5)
.margin(30)
.onClick(()=>{
///内部更新
this.updateEditModel()
})
}.padding({top:px2vp(this.topSafeHeight),bottom:px2vp(this.bottomSafeHeight)})
}
async updateEditModel(){
if (this.params.editContent === this.nikeName) {
this.goBack()
return
}
let currentUserInfo:editModel = new editModel()
currentUserInfo.userName = await encryptMessage(this.nikeName);
currentUserInfo.editDataType = WDEditDataModelType.WDEditDataModelType_nickname
EditInfoViewModel.updateUserInfo(currentUserInfo).then(()=>{
this.goBack()
}).catch(()=>{
this.goBack()
})
}
goBack(){
let params: editModelParams = {
userName: this.nikeName
}
router.back({
url:'',
params:params
})
}
}