mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-07 08:46:40 +08:00
fix(settings): AccountSettingSite bug
- 拆分 CC 与 站点刷新,解决CC保存时,站点刷新也会被提交保存的问题。
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useToast } from 'vue-toast-notification'
|
import { useToast } from 'vue-toast-notification'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
|
import debounce from 'lodash/debounce'
|
||||||
|
|
||||||
|
// 防抖时间
|
||||||
|
const debounceTime = 500
|
||||||
|
|
||||||
// 提示框
|
// 提示框
|
||||||
const $toast = useToast()
|
const $toast = useToast()
|
||||||
@@ -16,16 +20,20 @@ const resetSitesDisabled = ref(false)
|
|||||||
|
|
||||||
const isPasswordVisible = ref(false)
|
const isPasswordVisible = ref(false)
|
||||||
|
|
||||||
// CookieCloud设置项
|
// 站点设置默认值
|
||||||
const siteSetting = ref({
|
const siteSetting = ref<any>({
|
||||||
COOKIECLOUD_HOST: '',
|
CookieCloud: {
|
||||||
COOKIECLOUD_KEY: '',
|
COOKIECLOUD_HOST: '',
|
||||||
COOKIECLOUD_PASSWORD: '',
|
COOKIECLOUD_KEY: '',
|
||||||
COOKIECLOUD_INTERVAL: 0,
|
COOKIECLOUD_PASSWORD: '',
|
||||||
USER_AGENT: '',
|
COOKIECLOUD_INTERVAL: 0,
|
||||||
COOKIECLOUD_ENABLE_LOCAL: false,
|
USER_AGENT: '',
|
||||||
COOKIECLOUD_BLACKLIST: '',
|
COOKIECLOUD_ENABLE_LOCAL: false,
|
||||||
SITEDATA_REFRESH_INTERVAL: 0,
|
COOKIECLOUD_BLACKLIST: '',
|
||||||
|
},
|
||||||
|
Site:{
|
||||||
|
SITEDATA_REFRESH_INTERVAL: 0,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 同步间隔下拉框
|
// 同步间隔下拉框
|
||||||
@@ -50,7 +58,7 @@ const SiteDataRefreshIntervalItems = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// 重置站点
|
// 重置站点
|
||||||
async function resetSites() {
|
const resetSites = debounce(async () => {
|
||||||
try {
|
try {
|
||||||
resetSitesDisabled.value = true
|
resetSitesDisabled.value = true
|
||||||
resetSitesText.value = '正在重置...'
|
resetSitesText.value = '正在重置...'
|
||||||
@@ -64,32 +72,24 @@ async function resetSites() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
}
|
}, debounceTime)
|
||||||
|
|
||||||
// 加载站点设置
|
// 加载站点设置
|
||||||
async function loadSiteSettings() {
|
async function loadSiteSettings() {
|
||||||
try {
|
try {
|
||||||
const result: { [key: string]: any } = await api.get('system/env')
|
const result: { [key: string]: any } = await api.get('system/env')
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const {
|
// 将API返回的值赋值给SystemSettings
|
||||||
COOKIECLOUD_HOST,
|
for (const sectionKey of Object.keys(siteSetting.value) as Array<keyof typeof siteSetting.value>) {
|
||||||
COOKIECLOUD_KEY,
|
Object.keys(siteSetting.value[sectionKey]).forEach((key: string) => {
|
||||||
COOKIECLOUD_PASSWORD,
|
let v: any
|
||||||
COOKIECLOUD_INTERVAL,
|
if (result.data.hasOwnProperty(key)) {
|
||||||
USER_AGENT,
|
v = result.data[key]
|
||||||
COOKIECLOUD_ENABLE_LOCAL,
|
// 空字符串转为null,避免空字符串导致前端显示问题
|
||||||
COOKIECLOUD_BLACKLIST,
|
if (v === '') { v = null }
|
||||||
SITEDATA_REFRESH_INTERVAL,
|
(siteSetting.value[sectionKey] as any)[key] = v
|
||||||
} = result.data
|
}
|
||||||
siteSetting.value = {
|
})
|
||||||
COOKIECLOUD_HOST,
|
|
||||||
COOKIECLOUD_KEY,
|
|
||||||
COOKIECLOUD_PASSWORD,
|
|
||||||
COOKIECLOUD_INTERVAL,
|
|
||||||
USER_AGENT,
|
|
||||||
COOKIECLOUD_ENABLE_LOCAL,
|
|
||||||
COOKIECLOUD_BLACKLIST,
|
|
||||||
SITEDATA_REFRESH_INTERVAL,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -97,17 +97,19 @@ async function loadSiteSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用API保存CookieCloud设置
|
// 调用API保存设置
|
||||||
async function saveSiteSetting() {
|
const saveSiteSetting = debounce(async (value: { [key: string]: any }) => {
|
||||||
|
console.log(`正在保存设置:${JSON.stringify(value)}`)
|
||||||
try {
|
try {
|
||||||
const result: { [key: string]: any } = await api.post('system/env', siteSetting.value)
|
const result: { [key: string]: any } = await api.post('system/env', value)
|
||||||
|
if (result.success) {
|
||||||
if (result.success) $toast.success('保存站点设置成功')
|
$toast.success('保存设置成功')
|
||||||
else $toast.error('保存站点设置失败!')
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
$toast.error('保存设置失败!')
|
||||||
}
|
}
|
||||||
}
|
}, debounceTime)
|
||||||
|
|
||||||
// 加载数据
|
// 加载数据
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -128,7 +130,7 @@ onMounted(() => {
|
|||||||
<VRow>
|
<VRow>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VCheckbox
|
<VCheckbox
|
||||||
v-model="siteSetting.COOKIECLOUD_ENABLE_LOCAL"
|
v-model="siteSetting.CookieCloud.COOKIECLOUD_ENABLE_LOCAL"
|
||||||
label="启用本地CookieCloud服务器"
|
label="启用本地CookieCloud服务器"
|
||||||
hint="使用内建CookieCloud服务同步站点数据,服务地址为:http://localhost:3000/cookiecloud"
|
hint="使用内建CookieCloud服务同步站点数据,服务地址为:http://localhost:3000/cookiecloud"
|
||||||
persistent-hint
|
persistent-hint
|
||||||
@@ -138,17 +140,17 @@ onMounted(() => {
|
|||||||
<VRow>
|
<VRow>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VTextField
|
<VTextField
|
||||||
v-model="siteSetting.COOKIECLOUD_HOST"
|
v-model="siteSetting.CookieCloud.COOKIECLOUD_HOST"
|
||||||
label="服务地址"
|
label="服务地址"
|
||||||
placeholder="https://movie-pilot.org/cookiecloud"
|
placeholder="https://movie-pilot.org/cookiecloud"
|
||||||
:disabled="!!siteSetting.COOKIECLOUD_ENABLE_LOCAL"
|
:disabled="siteSetting.CookieCloud.COOKIECLOUD_ENABLE_LOCAL"
|
||||||
hint="远端CookieCloud服务地址,格式:https://movie-pilot.org/cookiecloud"
|
hint="远端CookieCloud服务地址,格式:https://movie-pilot.org/cookiecloud"
|
||||||
persistent-hint
|
persistent-hint
|
||||||
/>
|
/>
|
||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VTextField
|
<VTextField
|
||||||
v-model="siteSetting.COOKIECLOUD_KEY"
|
v-model="siteSetting.CookieCloud.COOKIECLOUD_KEY"
|
||||||
label="用户KEY"
|
label="用户KEY"
|
||||||
hint="CookieCloud浏览器插件生成的用户KEY"
|
hint="CookieCloud浏览器插件生成的用户KEY"
|
||||||
persistent-hint
|
persistent-hint
|
||||||
@@ -156,7 +158,7 @@ onMounted(() => {
|
|||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VTextField
|
<VTextField
|
||||||
v-model="siteSetting.COOKIECLOUD_PASSWORD"
|
v-model="siteSetting.CookieCloud.COOKIECLOUD_PASSWORD"
|
||||||
:type="isPasswordVisible ? 'text' : 'password'"
|
:type="isPasswordVisible ? 'text' : 'password'"
|
||||||
:append-inner-icon="isPasswordVisible ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
|
:append-inner-icon="isPasswordVisible ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
|
||||||
@click:append-inner="isPasswordVisible = !isPasswordVisible"
|
@click:append-inner="isPasswordVisible = !isPasswordVisible"
|
||||||
@@ -167,7 +169,7 @@ onMounted(() => {
|
|||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VSelect
|
<VSelect
|
||||||
v-model="siteSetting.COOKIECLOUD_INTERVAL"
|
v-model="siteSetting.CookieCloud.COOKIECLOUD_INTERVAL"
|
||||||
label="自动同步间隔"
|
label="自动同步间隔"
|
||||||
:items="CookieCloudIntervalItems"
|
:items="CookieCloudIntervalItems"
|
||||||
hint="从CookieCloud服务器自动同步站点Cookie到MoviePilot的时间间隔"
|
hint="从CookieCloud服务器自动同步站点Cookie到MoviePilot的时间间隔"
|
||||||
@@ -176,7 +178,7 @@ onMounted(() => {
|
|||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VTextField
|
<VTextField
|
||||||
v-model="siteSetting.COOKIECLOUD_BLACKLIST"
|
v-model="siteSetting.CookieCloud.COOKIECLOUD_BLACKLIST"
|
||||||
label="同步域名黑名单"
|
label="同步域名黑名单"
|
||||||
placeholder="多个域名,分割"
|
placeholder="多个域名,分割"
|
||||||
hint="CookieCloud同步域名黑名单,多个域名,分割"
|
hint="CookieCloud同步域名黑名单,多个域名,分割"
|
||||||
@@ -185,7 +187,7 @@ onMounted(() => {
|
|||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VTextField
|
<VTextField
|
||||||
v-model="siteSetting.USER_AGENT"
|
v-model="siteSetting.CookieCloud.USER_AGENT"
|
||||||
label="浏览器User-Agent"
|
label="浏览器User-Agent"
|
||||||
hint="CookieCloud插件所在的浏览器的User-Agent"
|
hint="CookieCloud插件所在的浏览器的User-Agent"
|
||||||
persistent-hint
|
persistent-hint
|
||||||
@@ -195,7 +197,11 @@ onMounted(() => {
|
|||||||
</VForm>
|
</VForm>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<VBtn type="submit" @click="saveSiteSetting"> 保存 </VBtn>
|
<VForm @submit.prevent="() => {}">
|
||||||
|
<div class="d-flex flex-wrap gap-4 mt-4">
|
||||||
|
<VBtn type="submit" @click="saveSiteSetting(siteSetting.CookieCloud)"> 保存 </VBtn>
|
||||||
|
</div>
|
||||||
|
</VForm>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
</VCard>
|
</VCard>
|
||||||
</VCol>
|
</VCol>
|
||||||
@@ -207,7 +213,7 @@ onMounted(() => {
|
|||||||
<VRow>
|
<VRow>
|
||||||
<VCol cols="12" md="6">
|
<VCol cols="12" md="6">
|
||||||
<VSelect
|
<VSelect
|
||||||
v-model="siteSetting.SITEDATA_REFRESH_INTERVAL"
|
v-model="siteSetting.Site.SITEDATA_REFRESH_INTERVAL"
|
||||||
label="站点数据刷新间隔"
|
label="站点数据刷新间隔"
|
||||||
:items="SiteDataRefreshIntervalItems"
|
:items="SiteDataRefreshIntervalItems"
|
||||||
hint="刷新站点用户上传下载等数据的时间间隔"
|
hint="刷新站点用户上传下载等数据的时间间隔"
|
||||||
@@ -218,7 +224,11 @@ onMounted(() => {
|
|||||||
</VForm>
|
</VForm>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardText>
|
<VCardText>
|
||||||
<VBtn type="submit" @click="saveSiteSetting"> 保存 </VBtn>
|
<VForm @submit.prevent="() => {}">
|
||||||
|
<div class="d-flex flex-wrap gap-4 mt-4">
|
||||||
|
<VBtn type="submit" @click="saveSiteSetting(siteSetting.Site)"> 保存 </VBtn>
|
||||||
|
</div>
|
||||||
|
</VForm>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
</VCard>
|
</VCard>
|
||||||
</VCol>
|
</VCol>
|
||||||
|
|||||||
Reference in New Issue
Block a user