MinePageComponent.ets
4.84 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 MinePagePersonalFunctionsItem from '../../viewmodel/MinePagePersonalFunctionsItem'
import MinePageCreatorFunctionsItem from '../../viewmodel/MinePageCreatorFunctionsItem'
import MinePageMoreFunctionModel from '../../viewmodel/MinePageMoreFunctionModel'
import MinePageDatasModel from '../../model/MinePageDatasModel'
import MinePageUserSimpleInfoUI from '../mine/MinePageUserSimpleInfoUI'
import MinePagePersonFunctionUI from '../mine/MinePagePersonFunctionUI'
import MinePageMoreFunctionUI from '../mine/MinePageMoreFunctionUI'
import { SPHelper, StringUtils } from 'wdKit'
import { SpConstants } from 'wdConstant'
import dataPreferences from '@ohos.data.preferences';
import { MergeRecordDialog } from '../../dialog/MergeRecordDialog'
const TAG = 'MinePageComponent';
/**
* 我的页面
*/
@Component
export struct MinePageComponent {
//是否是创作者
@State isCreator:boolean = false
@State isLogin:boolean = false //默认 false 测试放开
@State personalData:MinePagePersonalFunctionsItem[] = []
@State creatorData:MinePageCreatorFunctionsItem[] = []
@State moreData:MinePageMoreFunctionModel[] = []
scroller: Scroller = new Scroller()
preferences: dataPreferences.Preferences | null = null;
observer = (key: string) => {
if(key == SpConstants.USER_ID){
if(StringUtils.isEmpty(SPHelper.default.getSync(SpConstants.USER_ID,""))){
this.isLogin = false
}else {
this.isLogin = true
this.addRecordDialog()
if(this.personalData.length > 0){
this.getMessageData()
}
}
}
}
mergeDialogController: CustomDialogController = new CustomDialogController({
builder: MergeRecordDialog({
cancel: () => {
this.clearMergeRecord()
},
confirm: () => {
this.dealMergeRecordData()
}
}),
customStyle: true,
alignment: DialogAlignment.Center,
autoCancel: false
})
aboutToAppear(){
this.getUserLogin()
this.getFunctionData()
this.addLoginStatusObserver()
this.getMessageData()
}
getMessageData(){
MinePageDatasModel.getMessageUnReadData().then((value) => {
if(value !=null) {
if(value.activeCount >0 ||value.subscribeCount > 0 || value.systemCount > 0){
this.personalData.forEach((value) => {
if(value.msg == "消息")
value.isShowRedPoint = true
})
}
}
}).catch((err: Error) => {
console.log(TAG, JSON.stringify(err))
})
}
async addLoginStatusObserver(){
this.preferences = await SPHelper.default.getPreferences();
this.preferences.on('change', this.observer);
}
aboutToDisappear(): void {
if(this.preferences){
this.preferences.off('change', this.observer);
}
}
getFunctionData(){
//个人功能数据
this.personalData = MinePageDatasModel.getPersonalFunctionsData()
//创作者功能数据
// this.creatorData = MinePageDatasModel.getCreatorFunctionsData()
//更多功能数据
this.moreData = MinePageDatasModel.getMoreFunctionsData()
}
build() {
Scroll(this.scroller){
Stack(){
Image($r('app.media.mine_head_bg'))
.width('100%')
.height('657lpx')
.objectFit(ImageFit.Auto)
this.MinePageUI()
}
.alignContent(Alignment.Top)
}
.setFullWidthAndHeight()
.backgroundColor($r('app.color.color_F9F9F9'))
.scrollable(ScrollDirection.Vertical)
.scrollBar(BarState.Off)
}
@Builder MinePageUI(){
Column(){
//头像层
MinePageUserSimpleInfoUI({isLogin:this.isLogin})
//Grid 区域
MinePagePersonFunctionUI({personalData:$personalData,isLogin:this.isLogin})
//Card
//MinePageCardUI()
//创作者区域
//MinePageCreatorFunctionUI({creatorData:$creatorData})
//更多功能
MinePageMoreFunctionUI({moreData:$moreData})
}.width('100%')
.height('100%')
.justifyContent(FlexAlign.Start)
}
@Styles setFullWidthAndHeight(){
.width('100%')
.height('100%')
}
async getUserLogin() {
// let userid = SPHelper.default.getSync(SpConstants.USER_ID,"") as string
let userid = await SPHelper.default.get(SpConstants.USER_ID,"")
if(StringUtils.isNotEmpty(userid)){
this.isLogin = true
}else{
this.isLogin = false
}
}
addRecordDialog() {
setTimeout(() => {
this.dealMergeRecordDialog()
}, 300)
}
dealMergeRecordDialog() {
let commentTime = SPHelper.default.getSync(SpConstants.FIRSTCOMMENTTIME, "")
if (StringUtils.isNotEmpty(commentTime)) {
this.mergeDialogController.open()
}
}
dealMergeRecordData() {
MinePageDatasModel.visitorMergeComment().then(() => {
this.mergeDialogController.close()
}).catch(() => {
this.mergeDialogController.close()
})
}
clearMergeRecord(){
SPHelper.default.saveSync(SpConstants.FIRSTCOMMENTTIME, "")
}
}