VideoDetail.ets
4.9 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
import { getDownloadUrl, downloadUrl } from '../api/originalRecords'
import { AxiosResponse } from '@ohos/axios'
import { downFile } from '../utils/downFile'
import { router } from '@kit.ArkUI'
import PhotoBrowser from '../dialog/PhotoBrowserDialog'
import NavHeader from '../components/NavHeader'
interface showVideoOrImg {
cosKey: string | null;
itemName: string;
videoList?: string[];
imgList?: string[];
}
interface VideoOrImgList {
videoList: string[];
imgList: string[];
}
interface routerParams {
cosKeyList: showVideoOrImg[]
}
let routerQuery = router.getParams() as routerParams
@Entry
@Component
struct DownLoadImage {
@State cosKeyData: showVideoOrImg[] = routerQuery?.cosKeyList
@State showCosKeyList: showVideoOrImg[] = []
@State viewImg: string[] = []
@State viewVideo: string[] = []
@State saveButtonOptions: SaveButtonOptions = {
icon: SaveIconStyle.FULL_FILLED,
text: SaveDescription.SAVE,
buttonType: ButtonType.Capsule
}
photoBrowserController: CustomDialogController = new CustomDialogController({
builder: PhotoBrowser({ imagesList: this.viewImg}),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Top,
})
async aboutToAppear() {
this.showCosKeyList = await Promise.all(this.cosKeyData.map(async (item: showVideoOrImg) => {
if (item.cosKey) {
const arrList: VideoOrImgList | [] = await this.getVideoOrImgUrl(item.cosKey)
if (!Array.isArray(arrList)) {
item.videoList = arrList.videoList
item.imgList = arrList.imgList
}
}
return item
}))
}
// 请求获取图片或视频链接
getVideoOrImgUrl = async (cosKey: string | null) => {
let result: VideoOrImgList | [] = this.filterVideoOrImg(cosKey)
if (!Array.isArray(result)) {
let videoData: string[] = await Promise.all(result.videoList.map(async (item: string) => {
const res: AxiosResponse<downloadUrl> = await getDownloadUrl(item, 0)
return res.data.data
}))
let imgData: string[] = await Promise.all(result.imgList.map(async (item: string) => {
const res: AxiosResponse<downloadUrl> = await getDownloadUrl(item, 0)
return res.data.data
}))
result = {
videoList: videoData,
imgList: imgData
}
}
return result
}
// 筛选图片或者视频
filterVideoOrImg = (cosKey: string | null): VideoOrImgList | [] => {
let urlList: string[] | undefined = cosKey?.split(';')
let videoList: string[] = []
let imgList: string[] = []
if(urlList === undefined) return []
urlList.forEach((item: string) => {
let newItemList: string[] = item.split('.')
if(newItemList[newItemList.length - 1] == 'mp4' || newItemList[newItemList.length - 1] == 'mkv'){
videoList.push(item)
} else {
imgList.push(item)
}
})
return {
videoList,
imgList
}
}
build() {
Column(){
NavHeader({title: '视频/图片下载'})
List(){
ForEach(this.showCosKeyList, (item:showVideoOrImg ) => {
ListItem(){
Column({ space: 10 }) {
Row({space: 5}){
Text().width(2).height(20).backgroundColor('#1890ff')
Text(item.itemName).fontSize(14).fontWeight(600)
}.width('100%')
GridRow({ columns: 2, gutter: 10 }) {
ForEach(item.imgList, (childrenImg: string) => {
GridCol() {
Column({space: 10}){
Image(childrenImg)
.width('100%')
.height(150)
.borderRadius(4)
Row(){
SaveButton(this.saveButtonOptions)
// 创建安全控件按钮
.onClick(async (event, result: SaveButtonOnClickResult) => {
if (result == SaveButtonOnClickResult.SUCCESS) {
downFile(childrenImg, 'jpg')
}
})
}
}
}
})
}
GridRow({ columns: 1}) {
ForEach(item.videoList, (childrenVideo: string) => {
GridCol() {
Column({ space: 10}){
Video({ src: childrenVideo }).width('100%').height(300)
SaveButton(this.saveButtonOptions)
// 创建安全控件按钮
.onClick(async (event, result: SaveButtonOnClickResult) => {
if (result == SaveButtonOnClickResult.SUCCESS) {
downFile(childrenVideo, 'mp4')
}
})
}
}.margin({ top: 10 })
})
}
}
}
})
}.padding(10)
}
}
}