@@ -25,8 +25,8 @@ import { FileHandler } from 'ets/common/utils/FileHandler'
25
25
@Component
26
26
export default struct SubscriptionIndex {
27
27
@State isShowImport: boolean = false
28
- @State isShowNewSources:boolean = false
29
- @Prop @Watch('currentTabIndexChange')currentTabIndex: number
28
+ @State isShowNewSources: boolean = false
29
+ @Prop @Watch('currentTabIndexChange') currentTabIndex: number
30
30
@StorageLink('topRectHeight') topRectHeight: number = 0
31
31
@State
32
32
moreList: IconTitleVo[] = [
@@ -36,25 +36,22 @@ export default struct SubscriptionIndex {
36
36
new IconTitleVo($r('app.media.icon_rule_batch'), '批量管理'),
37
37
]
38
38
@State RecentlyUsed: rssSourcesHistory[] = []
39
-
40
39
@State loading: boolean = false
40
+ @State subscriptionList: rssSources[] = []
41
+ @State rssSourcesList: rssSources[] = []
42
+ @State groupList: rssGroupList[] = []
41
43
//刷新
42
- refresh = ()=> {
44
+ refresh = () => {
43
45
this.resetState()
44
46
this.getList()
45
- setTimeout(()=> {
46
- rssSourcesHistoryDao.search().then((rssSourcesHistoryList:rssSourcesHistory[])=> {
47
+ setTimeout(() => {
48
+ rssSourcesHistoryDao.search().then((rssSourcesHistoryList: rssSourcesHistory[]) => {
47
49
this.RecentlyUsed = rssSourcesHistoryList
48
50
})
49
- },100)
51
+ }, 100)
50
52
}
51
53
52
- @State subscriptionList:rssSources[]=[]
53
-
54
-
55
- @State rssSourcesList:rssSources[] = []
56
- @State groupList: rssGroupList[] =[]
57
- currentTabIndexChange(){
54
+ currentTabIndexChange() {
58
55
this.refresh()
59
56
}
60
57
@@ -96,41 +93,46 @@ export default struct SubscriptionIndex {
96
93
this.groupList = Object.values(groupMap)
97
94
}
98
95
99
-
100
-
101
96
build() {
102
- Column(){
97
+ Column() {
103
98
//搜索Start
104
99
Flex(
105
100
{
106
- direction:FlexDirection.Row,
101
+ direction: FlexDirection.Row,
107
102
alignItems: ItemAlign.Center,
108
103
justifyContent: FlexAlign.SpaceBetween
109
104
}
110
105
) {
111
106
Row({
112
- space:CommonConstants.SPACE_20
107
+ space: CommonConstants.SPACE_20
113
108
}) {
114
- Image($r('app.media.icon_subscription_index')).width(CommonConstants.COMMON_WIDTH_45_36).height(CommonConstants.COMMON_HEIGHT_21_6)
109
+ Image($r('app.media.icon_subscription_index'))
110
+ .width(CommonConstants.COMMON_WIDTH_45_36)
111
+ .height(CommonConstants.COMMON_HEIGHT_21_6)
115
112
Search({ placeholder: '搜索订阅', icon: "/common/images/search.svg" })
116
113
.layoutWeight(1)
117
114
.height(CommonConstants.COMMON_HEIGHT_40)
118
115
.backgroundColor(Color.White)
119
- .onClick(()=> {
116
+ .onClick(() => {
120
117
router.pushUrl({
121
118
url: 'pages/view/Subscription/components/SubscriptionSearch'
122
119
})
123
120
})
124
121
.focusOnTouch(false) //不可获取焦点
125
122
}
126
- .padding({right: PaddingConstants.PADDING_16})
127
- Image($r('app.media.addSubscription')).width(ImageConstants.IMG_WIDTH_24).height(ImageConstants.IMG_HEIGHT_24).bindMenu(this.MenuBuilder)
123
+ .padding({ right: PaddingConstants.PADDING_16 })
124
+
125
+ Image($r('app.media.addSubscription'))
126
+ .width(ImageConstants.IMG_WIDTH_24)
127
+ .height(ImageConstants.IMG_HEIGHT_24)
128
+ .bindMenu(this.MenuBuilder)
128
129
}
129
130
.height('8%')
131
+
130
132
//搜索End
131
133
//最近使用Start
132
134
RssSourcesHistory({
133
- RecentlyUsed:this.RecentlyUsed
135
+ RecentlyUsed: this.RecentlyUsed
134
136
})
135
137
if (this.loading) {
136
138
Column() {
@@ -144,45 +146,45 @@ export default struct SubscriptionIndex {
144
146
} else if (!this.groupList.length) {
145
147
SubscriptionContent({
146
148
subscriptionTitle: '收藏',
147
- showAddDialog:()=> {
149
+ showAddDialog: () => {
148
150
this.isShowNewSources = true
149
151
}
150
152
})
151
153
} else {
152
- Scroll(){
153
- Column(){
154
- ForEach(this.groupList,(item:rssGroupList)=> {
154
+ Scroll() {
155
+ Column() {
156
+ ForEach(this.groupList, (item: rssGroupList) => {
155
157
SubscriptionContent({
156
158
subscriptionTitle: item.title,
157
159
contentList: item.list,
158
- refresh:this.refresh
160
+ refresh: this.refresh
159
161
})
160
162
})
161
163
}
162
164
}
163
165
.align(Alignment.Top)
164
- .padding({bottom:20 })
166
+ .padding({ bottom: 20 })
165
167
.layoutWeight(1)
166
168
.scrollBar(BarState.Off)
167
169
.scrollable(ScrollDirection.Vertical)
168
170
}
169
171
170
172
Flex()
171
- .bindSheet($$this.isShowImport,this.dialogImportFunction(),{
173
+ .bindSheet($$this.isShowImport, this.dialogImportFunction(), {
172
174
detents: [SheetSize.FIT_CONTENT, SheetSize.LARGE, 200],
173
175
dragBar: true,
174
- showClose:false,
175
- onDisappear:()=> {
176
+ showClose: false,
177
+ onDisappear: () => {
176
178
this.isShowImport = false
177
179
}
178
180
})
179
181
180
182
Flex()
181
- .bindSheet($$this.isShowNewSources,this.dialogNewSourcesFunction(),{
183
+ .bindSheet($$this.isShowNewSources, this.dialogNewSourcesFunction(), {
182
184
height: 200,
183
185
dragBar: true,
184
- showClose:false,
185
- onDisappear:()=> {
186
+ showClose: false,
187
+ onDisappear: () => {
186
188
this.isShowNewSources = false
187
189
}
188
190
})
@@ -200,24 +202,26 @@ export default struct SubscriptionIndex {
200
202
.height('100%')
201
203
}
202
204
203
- @Builder dialogImportFunction() {
205
+ @Builder
206
+ dialogImportFunction() {
204
207
Flex() {
205
208
SubscriptionImport({
206
- subscriptionList:this.subscriptionList
207
- ,show: this.isShowImport
208
- }).onDisAppear(()=> {
209
+ subscriptionList: this.subscriptionList
210
+ , show: this.isShowImport
211
+ }).onDisAppear(() => {
209
212
this.refresh()
210
213
})
211
214
}
212
215
}
213
216
214
- @Builder dialogNewSourcesFunction() {
215
- Column(){
217
+ @Builder
218
+ dialogNewSourcesFunction() {
219
+ Column() {
216
220
dialogNewSources({
217
- btnClick:()=> {
221
+ btnClick: () => {
218
222
this.isShowNewSources = false
219
223
}
220
- }).onDisAppear(()=> {
224
+ }).onDisAppear(() => {
221
225
this.refresh()
222
226
})
223
227
@@ -245,7 +249,7 @@ export default struct SubscriptionIndex {
245
249
this.MenuOnclick(index)
246
250
})
247
251
248
- if(index !== 5){
252
+ if (index !== 5) {
249
253
Divider()
250
254
}
251
255
}
@@ -257,31 +261,27 @@ export default struct SubscriptionIndex {
257
261
.width(100)
258
262
}
259
263
260
-
261
-
262
- async MenuOnclick(value:number|string){
263
- switch (value){
264
+ async MenuOnclick(value: number | string) {
265
+ switch (value) {
264
266
case 0:
265
- this.pasteAnalyze();
267
+ // 粘贴导入
268
+ this.pasteAnalyze(0);
266
269
break;
267
270
case 1:
268
- //todo:本地导入
269
- let result = await FileHandler.documentPickerFile(1, ['.json'])
270
- showMessage('订阅源本地导入成功')
271
+ // 本地导入
272
+ this.pasteAnalyze(1);
271
273
break
272
274
case 2:
273
- this.isShowNewSources =true
275
+ this.isShowNewSources = true
274
276
break;
275
277
case 3:
276
278
break
277
279
case 4:
278
-
279
280
break
280
-
281
281
}
282
282
}
283
283
284
- async pasteAnalyze() {
284
+ async pasteAnalyze(value: number ) {
285
285
try {
286
286
const url = getPasteDataSync()
287
287
if (!url) {
@@ -294,10 +294,18 @@ export default struct SubscriptionIndex {
294
294
// showMessage('复制的链接不正确')
295
295
// return
296
296
// }
297
- const res: AxiosResponse = await axios
298
- .get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json');
299
- console.log('res', JSON.stringify(res))
300
- this.subscriptionList = res.data;
297
+ if (value === 1) {
298
+ let FileResult = await FileHandler.documentPickerFile(1, ['.json'])
299
+ FileHandler.ReadJSONFile(FileResult[0]).then(result => {
300
+ // console.log('result:' + result)
301
+ this.subscriptionList = JSON.parse(result) as rssSources[]
302
+ })
303
+ } else if (value === 0) {
304
+ const res: AxiosResponse = await axios
305
+ .get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json');
306
+ console.log('res', JSON.stringify(res))
307
+ this.subscriptionList = res.data;
308
+ }
301
309
this.isShowImport = true;
302
310
} catch (err) {
303
311
console.error('错误 ' + err);
0 commit comments