1
+ import { updateAppData } from '../../storage/appData'
2
+ import customizeDialogExample from '../common/customizeDialog'
3
+ import { showMessage } from '../common/promptShow'
4
+
1
5
@Component
2
6
export default struct groupTypePanel{
3
7
@Link groupCoverShow:boolean
8
+ @State isShowIcon:boolean = false
9
+ @State groupType:string[] = ['分组','全部','未分组','本地','书单']
10
+ @State groupTypes:string[] = []
11
+ @State hideGroupType:string[] = ['游戏','玄幻','都市', '历史', '军事', '科幻', '灵异', '二次元', '耽美', '同人']
12
+ @StorageProp('APP_INDEX_SCROLLABLE') APP_INDEX_SCROLLABLE: boolean = true
4
13
build() {
5
14
Column({
6
15
space:15
@@ -14,32 +23,68 @@ export default struct groupTypePanel{
14
23
Text('点击进入').fontSize(12).fontWeight(400).lineHeight(20).fontColor('rgba(0, 0, 0, 0.45)')
15
24
}.alignItems(VerticalAlign.Bottom)
16
25
Row({space:12}){
17
- Text('管理').fontSize(12).fontWeight(400).lineHeight(20).fontColor($r('app.color.theme_color'))
26
+ Text(this.isShowIcon?'完成':'管理').fontSize(12).fontWeight(400).lineHeight(20).fontColor($r('app.color.theme_color'))
27
+ .onClick(()=>{
28
+ this.isShowIcon = !this.isShowIcon
29
+ })
18
30
Image($r('app.media.close')).width(24).height(20).onClick(()=>{
19
31
this.groupCoverShow = false
32
+ this.isShowIcon = false
20
33
})
21
34
}
22
35
}
23
36
Flex({
24
37
direction: FlexDirection.Row, wrap: FlexWrap.Wrap,
25
38
justifyContent:FlexAlign.Start
26
39
}){
27
- Row(){
28
- this.GroupType()
29
- }.width('25%')
30
- Row(){
31
- this.GroupType1('全部')
32
- //后续添加右上角图
33
- }.width('25%')
34
- Row(){
35
- this.GroupType1('未分组')
36
- }.width('25%')
37
- Row(){
38
- this.GroupType1('本地')
39
- }.width('25%')
40
- Row(){
41
- this.GroupType1('书单')
42
- }.width('25%')
40
+ ForEach(this.groupTypes.length > 0?this.groupTypes:this.groupType,(item:string,index:number)=>{
41
+ if (index === 0) {
42
+ Row(){
43
+ this.GroupTypeColor(item)
44
+ if (this.isShowIcon) {
45
+ Image($r('app.media.sort')).width(12).height(12).offset({x:-20,y:-20})
46
+ }
47
+ }.width('25%')
48
+ .onTouch((event: TouchEvent) => {
49
+ if (event.type === TouchType.Down) {
50
+ this.dragIndex = index // 获取当前拖拽子组件的索引
51
+ console.info('onTouch' + this.dragIndex)
52
+ }
53
+ })
54
+ .draggable(this.isShowIcon)
55
+ .onDragStart(()=>{
56
+ console.log('onDragStart')
57
+ })
58
+ .onDrop((event: DragEvent, extraParams: string) => {
59
+ console.log('onDrop')
60
+ this.changeIndex(this.dragIndex, index,0)
61
+ this.groupTypes = []
62
+ })
63
+
64
+ } else {
65
+ Row(){
66
+ this.GroupType(item)
67
+ if (this.isShowIcon) {
68
+ Image($r('app.media.sort')).width(12).height(12).offset({x:-20,y:-20})
69
+ }
70
+ }.width('25%')
71
+ .draggable(this.isShowIcon)
72
+ .onTouch((event: TouchEvent) => {
73
+ if (event.type === TouchType.Down) {
74
+ this.dragIndex = index // 获取当前拖拽子组件的索引
75
+ console.info('onTouch' + this.dragIndex)
76
+ }
77
+ })
78
+ .onDragStart(()=>{
79
+ console.log('onDragStart')
80
+ })
81
+ .onDrop((event: DragEvent, extraParams: string) => {
82
+ console.log('onDrop')
83
+ this.changeIndex(this.dragIndex, index,0)
84
+ })
85
+ }
86
+ })
87
+
43
88
}
44
89
45
90
Flex({
@@ -51,79 +96,140 @@ export default struct groupTypePanel{
51
96
Text('点击进入,长按编辑').fontSize(12).fontWeight(400).lineHeight(20).fontColor('rgba(0, 0, 0, 0.45)')
52
97
}.alignItems(VerticalAlign.Bottom)
53
98
Row({space:8}){
54
- Image($r('app.media.help')).width(20).height(20)
99
+ Image($r('app.media.help')).width(20).height(20).onClick(()=>{
100
+ this.tagLockDialog?.open()
101
+ })
55
102
Text('标签锁').fontSize(16).fontWeight(500).lineHeight(24).fontColor('rgba(0, 0, 0, 0.45)')
56
- Toggle({ type: ToggleType.Switch, isOn: false })
103
+ Toggle({ type: ToggleType.Switch, isOn: $$this.APP_INDEX_SCROLLABLE })
57
104
.selectedColor("#F60").hoverEffect(HoverEffect.None)
105
+ .onChange(()=>{
106
+ updateAppData(this.APP_INDEX_SCROLLABLE)
107
+ showMessage(this.APP_INDEX_SCROLLABLE?'开启标签锁':'关闭标签锁')
108
+ })
58
109
}.alignItems(VerticalAlign.Bottom).justifyContent(FlexAlign.End)
59
110
}
60
- Scroll(){
61
- if (true){
62
- Flex({
63
- direction: FlexDirection.Row
64
- }){
65
- Row(){
66
- this.GroupType1('游戏')
67
- }.width('25%')
68
- Row(){
69
- this.GroupType1('未分组')
70
- }.width('25%')
71
- Row(){
72
- this.GroupType1('本地')
73
- }.width('25%')
111
+ if (this.hideGroupType.length > 0){
112
+ Flex({
113
+ direction: FlexDirection.Row, wrap: FlexWrap.Wrap,alignContent:FlexAlign.Center
114
+ }){
115
+ ForEach(this.hideGroupType,(item:string,index:number)=>{
74
116
Row(){
75
- this.GroupType1('书单')
76
- }.width('25%')
77
- Row(){
78
- this.GroupType1('书单')
79
- }.width('25%')
80
- }
81
- } else {
82
- Flex({
83
- justifyContent:FlexAlign.Center
84
- }){
85
- Text('暂无隐藏分组').fontSize(12).fontWeight(400).fontColor('rgba(0, 0, 0, 0.45)')
86
- }
87
- .borderRadius(4)
88
- .width('100%')
89
- .backgroundColor('rgba(0, 0, 0, 0.04)')
90
- .padding({top:6,bottom:6})
117
+ this.GroupType(item)
118
+ if (this.isShowIcon) {
119
+ Image($r('app.media.add_new_fill')).width(12).height(12).offset({x:-20,y:-20})
120
+ }
121
+ }
122
+ .onTouch((event: TouchEvent) => {
123
+ if (event.type === TouchType.Down) {
124
+ this.dragIndex = index // 获取当前拖拽子组件的索引
125
+ console.info('onTouch' + this.dragIndex)
126
+ }
127
+ })
128
+ .draggable(this.isShowIcon)
129
+ .onDragStart(()=>{
130
+ console.log('onDragStart')
131
+ })
132
+ .onDrop((event: DragEvent, extraParams: string) => {
133
+ console.log('onDrop')
134
+ this.changeIndex(this.dragIndex, index,1)
135
+ })
136
+ .width('25%')
137
+ })
138
+ }
91
139
140
+ } else {
141
+ Flex({
142
+ justifyContent:FlexAlign.Center
143
+ }){
144
+ Text('暂无隐藏分组').fontSize(12).fontWeight(400).fontColor('rgba(0, 0, 0, 0.45)')
92
145
}
93
- }.scrollBar(BarState.Off)
94
- .scrollable(ScrollDirection.Horizontal)
146
+ .borderRadius(4)
147
+ .width('100%')
148
+ .backgroundColor('rgba(0, 0, 0, 0.04)')
149
+ .padding({top:6,bottom:6})
150
+
151
+ }
95
152
96
153
}
97
154
.borderRadius({bottomLeft:20,bottomRight:20})
98
155
.padding({left:20,right:20,top:12,bottom:20})
99
156
.width('100%').backgroundColor(Color.White)
100
157
}
101
- @Builder GroupType(){
102
- Row(){
103
- Text('分组').fontWeight(500).fontSize(12).textOverflow({
104
- overflow:TextOverflow.Ellipsis
105
- }).ellipsisMode(EllipsisMode.END)
106
- .maxLines(1).fontColor($r('app.color.theme_color'))
107
- .textAlign(TextAlign.Center)
158
+ @State tagLockContent:string = '长按底部tab栏书架图标可锁定分组标签栏,再次长按解锁,锁定后左右滑动将直接切换小说,漫画,有声书分组大类。'
159
+ tagLockDialog: CustomDialogController | null = new CustomDialogController({
160
+ builder: customizeDialogExample({
161
+ confirm: ()=> { this.onAccept() },
162
+ title: '标签锁',
163
+ content:this.tagLockContent
164
+ }),
165
+ width:'90%',
166
+ autoCancel: true,
167
+ alignment: DialogAlignment.Center,
168
+ // offset: { dx: 0, dy: '-40%' },
169
+ gridCount: 4,
170
+ customStyle: false,
171
+ cornerRadius: 25
172
+ })
173
+
174
+ onAccept() {
175
+ this.tagLockDialog?.close()
176
+ }
177
+
178
+ @State dragIndex: number = 0
179
+ changeIndex(index1: number, index2: number,type:number = 2) { // 交换数组位置
180
+ //@State hideGroupType:string[] = ['游戏','玄幻','都市', '历史', '军事', '科幻', '灵异', '二次元', '耽美', '同人']
181
+ //hideGroupType数组位置交换
182
+ if (!this.isShowIcon) {
183
+ showMessage('请在管理状态下拖到改变顺序')
184
+ return
185
+ }
186
+ console.log('changeIndex' + index1 + ',' + index2)
187
+ switch (type){
188
+ case 0:
189
+ let temp1 = this.groupType[index1];
190
+ this.groupType[index1] = this.groupType[index2];
191
+ this.groupType[index2] = temp1;break;
192
+ case 1:
193
+ let temp = this.hideGroupType[index1];
194
+ this.hideGroupType[index1] = this.hideGroupType[index2];
195
+ this.hideGroupType[index2] = temp;break;
108
196
}
109
- .margin({ right: 16, bottom: 16 })
110
- .justifyContent(FlexAlign.Center)
111
- .alignItems(VerticalAlign.Center)
112
- .width(68)
113
- .backgroundColor('rgba(0, 0, 0, 0.04)').padding({left:16,right:16,top:6,bottom:6})
114
197
}
115
- @Builder GroupType1(title:string){
116
- Row(){
117
- Text(title).fontWeight(500).fontSize(12).textOverflow({
118
- overflow:TextOverflow.Ellipsis
119
- }).ellipsisMode(EllipsisMode.END)
120
- .maxLines(1).fontColor(Color.Black)
121
- .textAlign(TextAlign.Center)
198
+ @Builder GroupTypeColor(title:string){
199
+ Column(){
200
+ Row(){
201
+ Text(title).fontWeight(500).fontSize(12).textOverflow({
202
+ overflow:TextOverflow.Ellipsis
203
+ }).ellipsisMode(EllipsisMode.END)
204
+ .maxLines(1).fontColor($r('app.color.theme_color'))
205
+ .textAlign(TextAlign.Center)
206
+ }
207
+ .margin({ right: 16, bottom: 16 })
208
+ .justifyContent(FlexAlign.Center)
209
+ .alignItems(VerticalAlign.Center)
210
+ .width(68)
211
+ .backgroundColor('rgba(252, 121, 0, 0.12)')
212
+ .padding({left:16,right:16,top:6,bottom:6})
122
213
}
123
-
124
- .justifyContent(FlexAlign.Center)
125
- .alignItems(VerticalAlign.Center)
126
- .width(68)
127
- .backgroundColor('rgba(0, 0, 0, 0.04)').padding({left:16,right:16,top:6,bottom:6})
214
+ }
215
+ @Builder GroupType(title:string){
216
+ Column(){
217
+ Row(){
218
+ Text(title).fontWeight(500).fontSize(12).textOverflow({
219
+ overflow:TextOverflow.Ellipsis
220
+ }).ellipsisMode(EllipsisMode.END)
221
+ .maxLines(1).fontColor(Color.Black)
222
+ .textAlign(TextAlign.Center)
223
+ // Image($r('app.media.sort')).width(12).height(12).offset({x:18,y:-12})
224
+ }
225
+ // .backgroundImage($r('app.media.sort'))
226
+ // .backgroundImagePosition({x:-12,y:12})
227
+ // .backgroundImageSize({width:'100%',height:12})
228
+ .margin({ right: 16, bottom: 16 })
229
+ .justifyContent(FlexAlign.Center)
230
+ .alignItems(VerticalAlign.Center)
231
+ .width(68)
232
+ .backgroundColor('rgba(0, 0, 0, 0.04)').padding({left:16,right:16,top:6,bottom:6})
233
+ }
128
234
}
129
235
}
0 commit comments