Merge pull request #342 from buvta/forPR

部分功能优化
This commit is contained in:
cuiocean
2020-11-05 21:06:51 +01:00
committed by GitHub
3 changed files with 146 additions and 115 deletions

View File

@@ -13,7 +13,7 @@
<div class="listpage-header" v-show="enableBatchEdit">
<el-switch v-model="enableBatchEdit" active-text="批处理分组"></el-switch>
<el-input placeholder="新组名" v-model="batchGroupName"></el-input>
<el-switch v-model="batchIsActive" :active-value="1" :inactive-value="0" active-text="自选源"></el-switch>
<el-switch v-model="batchIsActive" :active-value="1" :inactive-value="0" active-text="启用"></el-switch>
<el-button type="primary" icon="el-icon-edit" @click.stop="saveBatchEdit">保存</el-button>
</div>
<div class="listpage-body" id="sites-body">
@@ -33,13 +33,13 @@
</el-table-column>
<el-table-column
prop="isActive"
label="自选源">
label="启用">
<template slot-scope="scope">
<el-switch
v-model="scope.row.isActive"
:active-value="1"
:inactive-value="0"
@change='isActiveChangeEvent'>
@change='isActiveChangeEvent(scope.row)'>
</el-switch>
</template>
</el-table-column>
@@ -49,9 +49,6 @@
:filters="getFilters"
:filter-method="filterHandle"
filter-placement="bottom-end">
<template slot-scope="scope">
<el-button type="text">{{scope.row.group}}</el-button>
</template>
</el-table-column>
<el-table-column
label="状态"
@@ -59,11 +56,11 @@
:sort-by="['status']"
width="120">
<template slot-scope="scope">
<span v-show="scope.row.status === ''">
<span v-if="scope.row.status === ' '">
<i class="el-icon-loading"></i>
检测中...
</span>
<span v-show="scope.row.status !== ''">{{scope.row.status}}</span>
<span v-else>{{scope.row.status}}</span>
</template>
</el-table-column>
<el-table-column
@@ -73,7 +70,8 @@
<template slot-scope="scope">
<el-button size="mini" @click.stop="moveToTopEvent(scope.row)" type="text">置顶</el-button>
<el-button size="mini" @click.stop="editSite(scope.row)" type="text">编辑</el-button>
<el-button size="mini" @click.stop="checkSimpleSite(scope.row)" type="text">检测</el-button>
<!-- 检测时先强制批量检测一遍如果不强制直接单个检测时第一次不会显示检测中 -->
<el-button size="mini" v-if="sites.every(site => site.status)" v-show="!checkAllSiteLoading" @click.stop="checkSingleSite(scope.row)" type="text">检测</el-button>
<el-button size="mini" @click.stop="removeEvent(scope.row)" type="text">删除</el-button>
</template>
</el-table-column>
@@ -142,18 +140,14 @@ export default {
],
api: [
{ required: true, message: 'API地址不能为空', trigger: 'blur' }
],
download: [
{ required: false, trigger: 'blur' }
]
},
enableBatchEdit: false,
batchGroupName: '',
batchIsActive: 1,
multipleSelection: [],
tableKey: 1,
checkAllSiteLoading: false,
editeOldkey: ''
editOldkey: ''
}
},
computed: {
@@ -219,9 +213,6 @@ export default {
sites: res
}
})
for (const i of this.sites) {
delete i.status
}
},
getSitesGroup () {
const arr = []
@@ -254,7 +245,7 @@ export default {
this.dialogType = 'edit'
this.dialogVisible = true
this.siteInfo = siteInfo
this.editeOldkey = siteInfo.key
this.editOldkey = siteInfo.key
},
closeDialog () {
this.dialogVisible = false
@@ -271,19 +262,8 @@ export default {
this.$message.warning('删除源失败, 错误信息: ' + err)
})
},
listUpdatedEvent () {
sites.clear().then(res1 => {
// 重新排序
var id = 1
this.sites.forEach(element => {
element.id = id
sites.add(element)
id += 1
})
})
},
checkSiteKey (e) {
if (this.dialogType === 'edit' && this.editeOldkey === this.siteInfo.key) {
if (this.dialogType === 'edit' && this.editOldkey === this.siteInfo.key) {
return true
} else {
for (const i of this.sites) {
@@ -326,7 +306,7 @@ export default {
this.dialogVisible = false
this.getSites()
})
this.editeOldkey = ''
this.editOldkey = ''
},
exportSites () {
this.getSites()
@@ -400,7 +380,8 @@ export default {
}
},
isActiveChangeEvent (row) {
this.updateDatabase()
sites.remove(row.id)
sites.add(row)
},
resetId (inArray) {
var id = 1
@@ -437,23 +418,13 @@ export default {
},
async checkAllSite () {
this.checkAllSiteLoading = true
for (const i of this.sites) {
i.status = ''
this.tableKey = Math.random()
const flag = await zy.check(i.key)
if (flag) {
i.status = '可用'
} else {
i.status = '失效'
i.isActive = 0
}
this.tableKey = Math.random()
}
this.checkAllSiteLoading = false
this.updateDatabase()
Promise.all(this.sites.map(site => this.checkSingleSite(site))).then(res => {
this.checkAllSiteLoading = false
this.getSites()
})
},
async checkSimpleSite (row) {
this.checkAllSiteLoading = true
async checkSingleSite (row) {
row.status = ' '
const flag = await zy.check(row.key)
if (flag) {
row.status = '可用'
@@ -461,14 +432,13 @@ export default {
row.status = '失效'
row.isActive = 0
}
this.updateDatabase()
this.tableKey = Math.random()
this.checkAllSiteLoading = false
sites.remove(row.id)
sites.add(row)
return row.status
}
},
mounted () {
this.rowDrop()
this.checkAllSiteLoading = false
},
created () {
this.getSites()

View File

@@ -71,6 +71,7 @@
<el-table size="mini"
:data="list.filter(res => !setting.excludeR18Films || !containsR18Keywords(res.type))"
height="100%"
:empty-text="statusText"
@row-click="(row) => detailEvent(site, row)"
style="width: 100%">
<el-table-column
@@ -127,62 +128,63 @@
</div>
<div class="show-table" v-show="show.find">
<el-table size="mini"
:data="searchContents.filter(res => !setting.excludeR18Films || (res.type !== undefined && !containsR18Keywords(res.type)))"
height="100%"
row-key="id"
@row-click="(row) => detailEvent(row.site, row)"
style="width: 100%">
<el-table-column
prop="name"
label="片名">
</el-table-column>
<el-table-column v-if="setting.searchAllSites"
prop="site"
label="源站"
width="120">
<template slot-scope="scope">
<span>{{ scope.row.site.name }}</span>
</template>
</el-table-column>
<el-table-column
prop="type"
label="类型"
width="100">
</el-table-column>
<el-table-column
prop="year"
label="上映"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="area"
label="地区"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="lang"
label="语言"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="note"
label="备注">
</el-table-column>
<el-table-column
label="操作"
header-align="center"
align="right"
width="200">
<template slot-scope="scope">
<el-button @click.stop="playEvent(scope.row.site, scope.row)" type="text">播放</el-button>
<el-button @click.stop="starEvent(scope.row.site, scope.row)" type="text">收藏</el-button>
<el-button @click.stop="shareEvent(scope.row.site, scope.row)" type="text">分享</el-button>
<el-button @click.stop="downloadEvent(scope.row.site, scope.row)" type="text">下载</el-button>
</template>
</el-table-column>
:data="searchContents.filter(res => !setting.excludeR18Films || (res.type !== undefined && !containsR18Keywords(res.type)))"
height="100%"
row-key="id"
:empty-text="statusText"
@row-click="(row) => detailEvent(row.site, row)"
style="width: 100%">
<el-table-column
prop="name"
label="片名">
</el-table-column>
<el-table-column v-if="setting.searchAllSites"
prop="site"
label="源站"
width="120">
<template slot-scope="scope">
<span>{{ scope.row.site.name }}</span>
</template>
</el-table-column>
<el-table-column
prop="type"
label="类型"
width="100">
</el-table-column>
<el-table-column
prop="year"
label="上映"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="area"
label="地区"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="lang"
label="语言"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="note"
label="备注">
</el-table-column>
<el-table-column
label="操作"
header-align="center"
align="right"
width="200">
<template slot-scope="scope">
<el-button @click.stop="playEvent(scope.row.site, scope.row)" type="text">播放</el-button>
<el-button @click.stop="starEvent(scope.row.site, scope.row)" type="text">收藏</el-button>
<el-button @click.stop="shareEvent(scope.row.site, scope.row)" type="text">分享</el-button>
<el-button @click.stop="downloadEvent(scope.row.site, scope.row)" type="text">下载</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
@@ -213,6 +215,7 @@ export default {
type: {},
pagecount: 0,
list: [],
statusText: ' ',
infiniteId: +new Date(),
searchList: [],
searchTxt: '',
@@ -261,9 +264,6 @@ export default {
setting () {
return this.$store.getters.getSetting
},
sitesList () {
return this.$store.getters.getEditSites.sites // 需要监听的数据
},
filterSettings () {
return this.$store.getters.getSetting.excludeR18Films // 需要监听的数据
}
@@ -281,9 +281,6 @@ export default {
searchTxt () {
this.searchChangeEvent()
},
sitesList () {
this.getAllsites()
},
filterSettings () {
this.siteClick(this.site)
}
@@ -370,8 +367,10 @@ export default {
const key = this.site.key
const type = this.type.tid
const page = this.pagecount
if (page < 1) {
this.statusText = ' '
if (key && page < 1) { // OK资源前几类硬是去不掉
$state.complete()
this.statusText = '暂无数据'
return false
}
zy.list(key, page, type).then(res => {
@@ -391,6 +390,7 @@ export default {
$state.loaded()
} else {
$state.complete()
this.statusText = '暂无数据'
}
})
},
@@ -478,6 +478,7 @@ export default {
},
changeView () {
if (this.view === 'Film') {
this.getAllsites()
if (this.setting.view === 'picture') {
this.$refs.filmWaterfall.refresh()
this.getPage().then(() => {
@@ -504,6 +505,7 @@ export default {
this.pagecount = 0
this.show.search = false
this.show.find = true
this.statusText = ' '
if (wd) {
search.find({ keywords: wd }).then(res => {
if (!res) {
@@ -519,6 +521,7 @@ export default {
zy.detail(site.key, element.id).then(detailRes => {
detailRes.site = site
this.searchContents.push(detailRes)
this.statusText = '暂无数据'
})
})
}
@@ -526,6 +529,7 @@ export default {
zy.detail(site.key, res.id).then(detailRes => {
detailRes.site = site
this.searchContents.push(detailRes)
this.statusText = '暂无数据'
})
}
})
@@ -580,6 +584,7 @@ export default {
}
},
created () {
this.getAllsites()
this.getAllSearch()
}
}

View File

@@ -3,6 +3,62 @@ import axios from 'axios'
import parser from 'fast-xml-parser'
import cheerio from 'cheerio'
// 请求超时时限
axios.defaults.timeout = 5000
// 重试次数共请求3次
axios.defaults.retry = 2
// 请求的间隙
axios.defaults.retryDelay = 1000
// 添加请求拦截器(配置发送请求的信息)
axios.interceptors.request.use(function (config) {
// 处理请求之前的配置
// 引入代理,播放器代理怎么搞?
return config
}, function (error) {
// 请求失败的处理
return Promise.reject(error)
})
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
// 对响应数据做些事
if (response.status && response.status === 200 && response.request.responseURL.includes('api.php') && !response.data.startsWith('<?xml')) {
console.log(response)
}
return response
}, function (err) { // 请求错误时做些事
// 请求超时的之后,抛出 err.code = ECONNABORTED的错误..错误信息是 timeout of xxx ms exceeded
if (err.code === 'ECONNABORTED' && err.message.indexOf('timeout') !== -1) {
var config = err.config
config.__retryCount = config.__retryCount || 0
if (config.__retryCount >= config.retry) {
err.message = '多次请求均超时'
return Promise.reject(err)
}
config.__retryCount += 1
var backoff = new Promise(function (resolve) {
setTimeout(function () {
resolve()
}, config.retryDelay || 1)
})
return backoff.then(function () {
return axios(config)
})
} else {
if (err && !err.response) {
err.message = '连接服务器失败!'
}
return Promise.reject(err)
}
})
const zy = {
xmlConfig: { // XML 转 JSON 配置
trimValues: true,