Skip to content

Commit 57fb4d9

Browse files
committed
feat: get file selection util
1 parent 8030699 commit 57fb4d9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/shared/utils/index.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import {
1414
import bitTorrentPeerId from 'bittorrent-peerid'
1515

1616
import { userKeys, systemKeys, needRestartKeys } from '@shared/configKeys'
17-
import { APP_THEME, ENGINE_RPC_HOST, GRAPHIC, UNKNOWN_PEERID } from '@shared/constants'
17+
import {
18+
APP_THEME,
19+
ENGINE_RPC_HOST,
20+
GRAPHIC,
21+
NONE_SELECTED_FILES,
22+
SELECTED_ALL_FILES,
23+
UNKNOWN_PEERID
24+
} from '@shared/constants'
1825

1926
export function bytesToSize (bytes) {
2027
const b = parseInt(bytes, 10)
@@ -174,6 +181,25 @@ export function ellipsis (str = '', maxLen = 64) {
174181
return result
175182
}
176183

184+
export function getFileSelection (files = []) {
185+
console.log('getFileSelection===>', files)
186+
const selectedFiles = files.filter((file) => file.selected)
187+
if (files.length === 0 || selectedFiles.length === 0) {
188+
return NONE_SELECTED_FILES
189+
}
190+
191+
if (files.length === selectedFiles.length) {
192+
return SELECTED_ALL_FILES
193+
}
194+
195+
const indexArr = []
196+
files.forEach((_, index) => {
197+
indexArr.push(index)
198+
})
199+
const result = indexArr.join(',')
200+
return result
201+
}
202+
177203
export function getTaskName (task, options = {}) {
178204
const o = {
179205
defaultName: '',

0 commit comments

Comments
 (0)