diff --git a/src/components/Detail.vue b/src/components/Detail.vue index 44803c2..5de474a 100644 --- a/src/components/Detail.vue +++ b/src/components/Detail.vue @@ -141,61 +141,56 @@ export default { this.m3u8List = dd._t.split('#') } }, - playEvent (n) { + async playEvent (n) { if (!this.playOnline) { - history.find({ site: this.detail.key, ids: this.detail.info.id }).then(res => { - if (res) { - this.video = { key: res.site, info: { id: res.ids, name: res.name, index: n, site: this.detail.site } } - } else { - this.video = { key: this.detail.key, info: { id: this.detail.info.id, name: this.detail.info.name, index: n, site: this.detail.site } } - } - }) + const db = await history.find({ site: this.detail.key, ids: this.detail.info.id }) + if (db) { + this.video = { key: db.site, info: { id: db.ids, name: db.name, index: n, site: this.detail.site } } + } else { + this.video = { key: this.detail.key, info: { id: this.detail.info.id, name: this.detail.info.name, index: n, site: this.detail.site } } + } this.view = 'Play' this.detail.show = false } else { - history.find({ site: this.detail.key, ids: this.detail.info.id }).then(res => { - if (res) { - res.index = n - history.update(res.id, res) - } else { - const doc = { - site: this.detail.key, - ids: this.detail.info.id, - name: this.detail.info.name, - type: this.detail.info.type, - year: this.detail.info.year, - index: n, - time: '' - } - history.add(doc) + const db = await history.find({ site: this.detail.key, ids: this.detail.info.id }) + if (db) { + db.index = n + history.update(db.id, db) + } else { + const doc = { + site: this.detail.key, + ids: this.detail.info.id, + name: this.detail.info.name, + type: this.detail.info.type, + year: this.detail.info.year, + index: n, + time: '' } - }) + history.add(doc) + } onlineVideo.playVideoOnline(this.selectedOnlineSite, this.detail.info.name, n) } }, - starEvent () { - star.find({ key: this.detail.key, ids: this.info.id }).then(res => { - if (res) { - this.$message.info('该影片已被收藏') - } else { - const docs = { - key: this.detail.key, - ids: this.info.id, - site: this.detail.site, - name: this.info.name, - type: this.info.type, - year: this.info.year, - note: this.info.note, - last: this.info.last + async starEvent () { + const db = await star.find({ key: this.detail.key, ids: this.info.id }) + if (db) { + this.$message.info('该影片已被收藏') + } else { + const docs = { + key: this.detail.key, + ids: this.info.id, + site: this.detail.site, + name: this.info.name, + type: this.info.type, + year: this.info.year, + note: this.info.note, + last: this.info.last - } - star.add(docs).then(res => { - this.$message.success('收藏成功') - }) } - }).catch(() => { - this.$message.warning('收藏失败') - }) + star.add(docs).then(res => { + this.$message.success('收藏成功') + }) + } }, togglePlayOnlineEvent () { this.playOnline = !this.playOnline diff --git a/src/components/Film.vue b/src/components/Film.vue index dffddb3..71d619f 100644 --- a/src/components/Film.vue +++ b/src/components/Film.vue @@ -314,38 +314,34 @@ export default { info: e } }, - playEvent (site, e) { - history.find({ site: site.key, ids: e.id }).then(res => { - if (res) { - this.video = { key: res.site, info: { id: res.ids, name: res.name, index: res.index, site: site } } - } else { - this.video = { key: site.key, info: { id: e.id, name: e.name, index: 0, site: site } } - } - }) + async playEvent (site, e) { + const db = await history.find({ site: site.key, ids: e.id }) + if (db) { + this.video = { key: db.site, info: { id: db.ids, name: db.name, index: db.index, site: site } } + } else { + this.video = { key: site.key, info: { id: e.id, name: e.name, index: 0, site: site } } + } this.view = 'Play' }, - starEvent (site, e) { - star.find({ key: site.key, ids: e.id }).then(res => { - if (res) { - this.$message.info('已存在') - } else { - const docs = { - key: site.key, - ids: e.id, - site: site, - name: e.name, - type: e.type, - year: e.year, - last: e.last, - note: e.note - } - star.add(docs).then(res => { - this.$message.success('收藏成功') - }) + async starEvent (site, e) { + const db = await star.find({ key: site.key, ids: e.id }) + if (db) { + this.$message.info('已存在') + } else { + const docs = { + key: site.key, + ids: e.id, + site: site, + name: e.name, + type: e.type, + year: e.year, + last: e.last, + note: e.note } - }).catch(() => { - this.$message.warning('收藏失败') - }) + star.add(docs).then(res => { + this.$message.success('收藏成功') + }) + } }, shareEvent (site, e) { this.share = { diff --git a/src/components/History.vue b/src/components/History.vue index 5232dcd..701dcb0 100644 --- a/src/components/History.vue +++ b/src/components/History.vue @@ -113,14 +113,13 @@ export default { } } }, - playEvent (e) { - history.find({ site: e.site, ids: e.ids }).then(res => { - if (res) { - this.video = { key: res.site, info: { id: res.ids, name: res.name, index: res.index } } - } else { - this.video = { key: e.site, info: { id: e.ids, name: e.name, index: 0 } } - } - }) + async playEvent (e) { + const db = await history.find({ site: e.site, ids: e.ids }) + if (db) { + this.video = { key: db.site, info: { id: db.ids, name: db.name, index: db.index } } + } else { + this.video = { key: e.site, info: { id: e.ids, name: e.name, index: 0 } } + } this.view = 'Play' }, shareEvent (e) { diff --git a/src/components/Play.vue b/src/components/Play.vue index ce30ee2..8e11600 100644 --- a/src/components/Play.vue +++ b/src/components/Play.vue @@ -287,7 +287,7 @@ export default { }, methods: { ...mapMutations(['SET_VIEW', 'SET_DETAIL', 'SET_VIDEO', 'SET_SHARE']), - getUrls () { + async getUrls () { this.name = '' if (this.timer !== null) { clearInterval(this.timer) @@ -307,14 +307,13 @@ export default { } else { const index = this.video.info.index | 0 let time = 0 - history.find({ site: this.video.key, ids: this.video.info.id }).then(res => { - if (res) { - if (res.index === index) { - time = res.time - } + const db = await history.find({ site: this.video.key, ids: this.video.info.id }) + if (db) { + if (db.index === index) { + time = db.time } this.playVideo(index, time) - }) + } } }, playUrl (url) { @@ -393,34 +392,33 @@ export default { }) }) }, - videoPlaying () { + async videoPlaying () { this.changeVideo() - history.find({ site: this.video.key, ids: this.video.info.id }).then(res => { - if (res) { - const doc = { - site: res.site, - ids: res.ids, - name: res.name, - type: res.type, - year: res.year, - index: this.video.info.index, - time: res.time - } - history.remove(res.id) - history.add(doc) - } else { - const doc = { - site: this.video.key, - ids: this.video.info.id, - name: this.video.info.name, - type: this.video.info.type, - year: this.video.info.year, - index: this.video.info.index, - time: '' - } - history.add(doc) + const db = await history.find({ site: this.video.key, ids: this.video.info.id }) + if (db) { + const doc = { + site: db.site, + ids: db.ids, + name: db.name, + type: db.type, + year: db.year, + index: this.video.info.index, + time: db.time } - }) + history.remove(db.id) + history.add(doc) + } else { + const doc = { + site: this.video.key, + ids: this.video.info.id, + name: this.video.info.name, + type: this.video.info.type, + year: this.video.info.year, + index: this.video.info.index, + time: '' + } + history.add(doc) + } this.updateStar() this.timerEvent() }, @@ -429,15 +427,14 @@ export default { this.checkTop() }, timerEvent () { - this.timer = setInterval(() => { - history.find({ site: this.video.key, ids: this.video.info.id }).then(res => { - if (res) { - const doc = { ...res } - doc.time = this.xg.currentTime - delete doc.id - history.update(res.id, doc) - } - }) + this.timer = setInterval(async () => { + const db = await history.find({ site: this.video.key, ids: this.video.info.id }) + if (db) { + const doc = { ...db } + doc.time = this.xg.currentTime + delete doc.id + history.update(db.id, doc) + } }, 10000) }, prevEvent () { @@ -502,21 +499,21 @@ export default { this.right.history = res.reverse() }) }, - updateStar () { + async updateStar () { const info = this.video.info - star.find({ key: this.video.key, ids: info.id }).then(res => { - if (res) { - res.index = info.index - star.update(res.id, res) - } - }).catch(() => { - this.$message.warning('检查收藏失败') - }) + const db = await star.find({ key: this.video.key, ids: info.id }) + if (db) { + db.index = info.index + star.update(db.id, db) + } }, - starEvent () { + async starEvent () { const info = this.video.info - star.find({ key: this.video.key, ids: info.id }).then(res => { - const doc = { + const db = await star.find({ key: this.video.key, ids: info.id }) + if (db) { + this.$message.info('已存在') + } else { + const docs = { key: this.video.key, ids: info.id, name: info.name, @@ -526,17 +523,11 @@ export default { note: info.note, index: info.index } - if (res) { - star.update(res.id, doc) - } else { - star.add(doc).then(starRes => { - this.$message.success('收藏成功') - this.isStar = true - }) - } - }).catch(() => { - this.$message.warning('检查收藏失败') - }) + star.add(docs).then(res => { + this.$message.success('收藏成功') + this.isStar = true + }) + } }, detailEvent () { this.detail = { @@ -628,14 +619,13 @@ export default { fs.writeFileSync(filePath, str) return filePath }, - checkStar () { - star.find({ key: this.video.key, ids: this.video.info.id }).then(res => { - if (res) { - this.isStar = true - } else { - this.isStar = false - } - }) + async checkStar () { + const db = await star.find({ key: this.video.key, ids: this.video.info.id }) + if (db) { + this.isStar = true + } else { + this.isStar = false + } }, checkTop () { const win = remote.getCurrentWindow() @@ -1085,16 +1075,15 @@ export default { mounted () { this.playerInstall() this.xg = new Hls(this.config) - ipcRenderer.on('miniClosed', () => { - history.find({ site: this.video.key, ids: this.video.info.id }).then(res => { - if (res) { - if (this.video.info.index !== res.index) { - this.video.info.index = res.index - } else { - this.getUrls() - } + ipcRenderer.on('miniClosed', async () => { + const db = await history.find({ site: this.video.key, ids: this.video.info.id }) + if (db) { + if (this.video.info.index !== db.index) { + this.video.info.index = db.index + } else { + this.getUrls() } - }) + } }) this.bindEvent() this.minMaxEvent() diff --git a/src/components/Star.vue b/src/components/Star.vue index 892dadc..f06ce46 100644 --- a/src/components/Star.vue +++ b/src/components/Star.vue @@ -158,14 +158,13 @@ export default { this.clearHasUpdateFlag(e) } }, - playEvent (e) { - history.find({ site: e.key, ids: e.ids }).then(res => { - if (res) { - this.video = { key: e.key, info: { id: res.ids, name: res.name, index: res.index } } - } else { - this.video = { key: e.key, info: { id: e.ids, name: e.name, index: 0 } } - } - }) + async playEvent (e) { + const db = await history.find({ site: e.key, ids: e.ids }) + if (db) { + this.video = { key: e.key, info: { id: db.ids, name: db.name, index: db.index } } + } else { + this.video = { key: e.key, info: { id: e.ids, name: e.name, index: 0 } } + } if (e.hasUpdate) { this.clearHasUpdateFlag(e) } @@ -193,12 +192,13 @@ export default { return 'highlight' } }, - clearHasUpdateFlag (e) { - star.find({ id: e.id }).then(res => { - res.hasUpdate = false - star.update(e.id, res) + async clearHasUpdateFlag (e) { + const db = await star.find({ id: e.id }) + if (db) { + db.hasUpdate = false + star.update(e.id, db) this.getFavorites() - }) + } }, updateEvent (e) { zy.detail(e.key, e.ids).then(res => { @@ -353,26 +353,24 @@ export default { this.$message.error(err) }) }, - upgradeFavorites () { - star.all().then(res => { - res.forEach(element => { - const docs = { - key: element.key, - ids: element.ids, - name: element.name, - type: element.type, - year: element.year, - last: element.last, - note: element.note - } - star.find({ key: element.key, ids: element.ids }).then(res => { - if (!res) { - star.add(docs) - } - }) - }) - this.getFavorites() + async upgradeFavorites () { + const allStar = star.all() + allStar.forEach(async element => { + const docs = { + key: element.key, + ids: element.ids, + name: element.name, + type: element.type, + year: element.year, + last: element.last, + note: element.note + } + const db = await star.find({ key: element.key, ids: element.ids }) + if (!db) { + star.add(docs) + } }) + this.getFavorites() }, clearFavoritesEvent () { star.clear().then(e => { diff --git a/src/lib/dexie/dexie.js b/src/lib/dexie/dexie.js index 204f367..86d4140 100644 --- a/src/lib/dexie/dexie.js +++ b/src/lib/dexie/dexie.js @@ -3,14 +3,14 @@ import { setting, sites, localKey, iptv } from './initData' const db = new Dexie('zy') -db.version(3).stores({ +db.version(4).stores({ search: '++id, keywords', iptvSearch: '++id, keywords', setting: 'id, theme, site, shortcut, view, externalPlayer, searchAllSites, excludeRootClasses, excludeR18Films, forwardTimeInSec', shortcut: 'name, key, desc', - star: '++id, key, ids, site, name, type, year, note, index, last, hasUpdate', + star: '++id, [key+ids], site, name, type, year, note, index, last, hasUpdate', sites: '++id, key, name, api, download, isActive, group', - history: '++id, site, ids, name, type, year, index, time', + history: '++id, [site+ids], name, type, year, index, time', mini: 'id, site, ids, name, index, time', iptv: '++id, name, url, group' }) diff --git a/src/lib/dexie/history.js b/src/lib/dexie/history.js index 06b6f33..fc4062a 100644 --- a/src/lib/dexie/history.js +++ b/src/lib/dexie/history.js @@ -8,7 +8,7 @@ export default { return await history.bulkAdd(doc) }, async find (doc) { - return await history.get(doc) + return await history.where(doc).first() }, async update (id, docs) { return await history.update(id, docs) diff --git a/src/lib/dexie/star.js b/src/lib/dexie/star.js index f0bc0d7..da69b8f 100644 --- a/src/lib/dexie/star.js +++ b/src/lib/dexie/star.js @@ -8,7 +8,7 @@ export default { return await star.bulkAdd(doc) }, async find (doc) { - return await star.get(doc) + return await star.where(doc).first() }, async update (id, docs) { return await star.update(id, docs) diff --git a/src/mini/Mini.vue b/src/mini/Mini.vue index 477bff1..61a2b3b 100644 --- a/src/mini/Mini.vue +++ b/src/mini/Mini.vue @@ -175,49 +175,48 @@ export default { }) }) }, - videoPlaying () { - history.find({ site: this.video.site, ids: this.video.ids }).then(res => { - if (res) { - res.index = this.video.index - history.update(res.id, res) - } else { - const doc = { - site: this.video.site, - ids: this.video.ids, - name: this.video.name, - index: this.video.index, - time: 0 - } - history.add(doc) + async videoPlaying () { + const db = await history.find({ site: this.video.site, ids: this.video.ids }) + if (db) { + db.index = this.video.index + history.update(db.id, db) + } else { + const doc = { + site: this.video.site, + ids: this.video.ids, + name: this.video.name, + index: this.video.index, + time: 0 } - }) + history.add(doc) + } this.timerEvent() }, timerEvent () { - this.timer = setInterval(() => { + this.timer = setInterval(async () => { const endTime = this.xg.duration const currentTime = this.xg.currentTime const progress = (currentTime / endTime) * 100 this.progress = progress.toFixed(2) - history.find({ site: this.video.site, ids: this.video.ids }).then(res => { - if (res) { - const v = res - v.time = this.xg.currentTime - v.index = this.video.index - const id = v.id - delete v.id - history.update(id, v) - } - }) + const db = await history.find({ site: this.video.site, ids: this.video.ids }) + if (db) { + const v = db + v.time = this.xg.currentTime + v.index = this.video.index + const id = v.id + delete v.id + history.update(id, v) + } }, 10000) }, - prevEvent () { + async prevEvent () { if (this.video.index === 0) { this.$message.info('已是第一集.') return false } - history.find({ site: this.video.site, ids: this.video.ids }).then(res => { - const v = res + const db = await history.find({ site: this.video.site, ids: this.video.ids }) + if (db) { + const v = db const id = v.id v.index-- delete v.id @@ -225,15 +224,16 @@ export default { this.xg.src = this.m3u8Arr[v.index] this.video.index-- }) - }) + } }, - nextEvent () { + async nextEvent () { if (this.video.index >= this.m3u8Arr.length - 1) { this.$message.info('已是最后一集.') return false } - history.find({ site: this.video.site, ids: this.video.ids }).then(res => { - const v = res + const db = await history.find({ site: this.video.site, ids: this.video.ids }) + if (db) { + const v = db v.index++ const id = v.id delete v.id @@ -241,7 +241,7 @@ export default { this.xg.src = this.m3u8Arr[v.index] this.video.index++ }) - }) + } }, playbackRateEvent (e) { let rate = this.xg.playbackRate