diff --git a/src/components/EditSites.vue b/src/components/EditSites.vue index 51f0d14..de0c5cf 100644 --- a/src/components/EditSites.vue +++ b/src/components/EditSites.vue @@ -6,21 +6,22 @@ 新增 导出 导入 - 检测 - 清空 + 检测{{ this.checkAllSitesLoading ? this.checkProgress + '/' + this.sites.length : '' }} 重置
- + 保存 + 删除
@@ -47,7 +49,7 @@ prop="group" label="分组" :filters="getFilters" - :filter-method="filterHandle" + :filter-method="(value, row) => value === row.group" filter-placement="bottom-end"> 置顶 编辑 - 检测 + 检测 删除 @@ -131,7 +133,7 @@ export default { api: '', download: '', group: '', - isActive: 1 + isActive: true }, siteGroup: [], rules: { @@ -144,9 +146,14 @@ export default { }, enableBatchEdit: false, batchGroupName: '', - batchIsActive: 1, + batchIsActive: true, + shiftDown: false, + selectionBegin: '', + selectionEnd: '', multipleSelection: [], - checkAllSiteLoading: false, + checkAllSitesLoading: false, + checkProgress: 0, + stopFlag: false, editOldkey: '' } }, @@ -159,14 +166,6 @@ export default { this.SET_SETTING(val) } }, - editSites: { - get () { - return this.$store.getters.getEditSites - }, - set (val) { - this.SET_EDITSITES(val) - } - }, getFilters () { const groups = [...new Set(this.sites.map(site => site.group))] var filters = [] @@ -180,21 +179,48 @@ export default { return filters } }, + watch: { + enableBatchEdit () { + if (this.checkAllSitesLoading) { + this.$message.info('正在检测, 请勿操作.') + this.enableBatchEdit = false + } + } + }, methods: { - ...mapMutations(['SET_SETTING', 'SET_EDITSITES']), + ...mapMutations(['SET_SETTING']), excludeR18FilmsChangeEvent () { setting.find().then(res => { res.excludeR18Films = this.setting.excludeR18Films setting.update(res) }) }, - filterHandle (value, row) { - return row.group === value + selectionCellClick (selection, row) { + if (this.shiftDown && this.selectionBegin !== '' && selection.includes(row)) { + this.selectionEnd = row.id + const start = Math.min(this.selectionBegin, this.selectionEnd) - 1 + const end = Math.max(this.selectionBegin, this.selectionEnd) + const selections = this.sites.slice(start, end) + this.$nextTick(() => { + selections.forEach(e => this.$refs.editSitesTable.toggleRowSelection(e, true)) + }) + this.selectionBegin = this.selectionEnd = '' + return + } + if (selection.includes(row)) { + this.selectionBegin = row.id + } else { + this.selectionBegin = '' + } }, handleSelectionChange (rows) { this.multipleSelection = rows }, handleSortChange (column, prop, order) { + if (this.checkAllSitesLoading) { + this.$message.info('正在检测, 请勿操作.') + return false + } this.updateDatabase(this.sites) }, saveBatchEdit () { @@ -208,10 +234,12 @@ export default { }, getSites () { sites.all().then(res => { + res.forEach(ele => { + if (ele.isActive === undefined) { + ele.isActive = true + } + }) this.sites = res - this.editSites = { - sites: res - } }) }, getSitesGroup () { @@ -224,6 +252,10 @@ export default { this.siteGroup = arr }, addSite () { + if (this.checkAllSitesLoading) { + this.$message.info('正在检测, 请勿操作.') + return false + } this.getSitesGroup() this.dialogType = 'new' this.dialogVisible = true @@ -233,15 +265,15 @@ export default { api: '', download: '', group: '', - isActive: 1 + isActive: true } }, editSite (siteInfo) { - this.getSitesGroup() - if (this.checkAllSiteLoading) { + if (this.checkAllSitesLoading) { this.$message.info('正在检测, 请勿操作.') return false } + this.getSitesGroup() this.dialogType = 'edit' this.dialogVisible = true this.siteInfo = siteInfo @@ -252,7 +284,7 @@ export default { this.getSites() }, removeEvent (e) { - if (this.checkAllSiteLoading) { + if (this.checkAllSitesLoading) { this.$message.info('正在检测, 请勿操作.') return false } @@ -329,6 +361,10 @@ export default { }) }, importSites () { + if (this.checkAllSitesLoading) { + this.$message.info('正在检测, 请勿操作.') + return false + } const options = { filters: [ { name: 'JSON file', extensions: ['json'] }, @@ -346,7 +382,7 @@ export default { if (ele.api && this.sites.filter(x => x.key === ele.key).length === 0 && this.sites.filter(x => x.name === ele.name && x.api === ele.api).length === 0) { // 不含该key 同时也不含名字和url一样的 if (ele.isActive === undefined) { - ele.isActive = 1 + ele.isActive = true } if (ele.group === undefined) { ele.group = '导入' @@ -363,11 +399,16 @@ export default { }) }, resetSitesEvent () { + this.stopFlag = true + if (this.checkAllSitesLoading) { + this.$message.info('部分检测还未完全终止, 请稍等...') + return + } sites.clear().then(sites.bulkAdd(defaultSites).then(this.getSites())) this.$message.success('重置源成功') }, moveToTopEvent (i) { - if (this.checkAllSiteLoading) { + if (this.checkAllSitesLoading) { this.$message.info('正在检测, 请勿操作.') return false } @@ -375,7 +416,7 @@ export default { this.updateDatabase() }, syncTableData () { - if (this.$refs.editSitesTable.tableData && this.$refs.editSitesTable.tableData.length === this.sites.length) { + if (this.$refs.editSitesTable.tableData) { this.sites = this.$refs.editSitesTable.tableData } }, @@ -402,10 +443,18 @@ export default { sites.bulkAdd(this.sites).then(this.getSites()) }) }, - removeAllSites () { - sites.clear().then(this.getSites()) + removeSelectedSites () { + this.multipleSelection.forEach(e => sites.remove(e.id)) + this.$refs.editSitesTable.clearFilter() + this.getSites() + this.updateDatabase() + this.enableBatchEdit = false }, rowDrop () { + if (this.checkAllSitesLoading) { + this.$message.info('正在检测, 请勿操作.') + return false + } const tbody = document.getElementById('sites-table').querySelector('.el-table__body-wrapper tbody') var _this = this Sortable.create(tbody, { @@ -417,20 +466,30 @@ export default { }) }, async checkAllSite () { - this.checkAllSiteLoading = true - Promise.all(this.sites.map(site => this.checkSingleSite(site))).then(res => { - this.checkAllSiteLoading = false + this.checkAllSitesLoading = true + this.stopFlag = false + this.checkProgress = 0 + const uncheckedList = this.sites.filter(e => e.status === undefined || e.status === ' ') // 未检测过的优先 + const other = this.sites.filter(e => !uncheckedList.includes(e)) + await Promise.all(uncheckedList.map(site => this.checkSingleSite(site))) + await Promise.all(other.map(site => this.checkSingleSite(site))).then(res => { + this.checkAllSitesLoading = false this.getSites() }) }, async checkSingleSite (row) { row.status = ' ' + if (this.stopFlag) { + this.checkProgress += 1 + return row.status + } const flag = await zy.check(row.key) + this.checkProgress += 1 if (flag) { row.status = '可用' } else { row.status = '失效' - row.isActive = 0 + row.isActive = false } sites.remove(row.id) sites.add(row) @@ -439,6 +498,8 @@ export default { }, mounted () { this.rowDrop() + addEventListener('keydown', code => { if (code.keyCode === 16) this.shiftDown = true }) + addEventListener('keyup', code => { if (code.keyCode === 16) this.shiftDown = false }) }, created () { this.getSites() diff --git a/src/components/IPTV.vue b/src/components/IPTV.vue index 4b1a7df..796da18 100644 --- a/src/components/IPTV.vue +++ b/src/components/IPTV.vue @@ -45,7 +45,7 @@ prop="isActive" width="120" align="center" - :filters = "[{text:'启用', value: 1}, {text:'停用', value: 0}]" + :filters = "[{text:'启用', value: true}, {text:'停用', value: false}]" :filter-method="(value, row) => value === row.isActive" label="启用">