mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-06 18:36:55 +08:00
improve setting save
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { QueryGetAPI, QueryPostAPI } from '@/api/query'
|
||||
import { QueryGetAPI, QueryPostAPI, QueryPostAPIWithParams } from '@/api/query'
|
||||
import { ACCOUNT_API_URL, VTSURU_API_URL } from '@/data/constants'
|
||||
import { useLocalStorage } from '@vueuse/core'
|
||||
import { isSameDay } from 'date-fns'
|
||||
@@ -63,6 +63,19 @@ export async function SaveAccountSettings() {
|
||||
export async function SaveEnableFunctions(functions: FunctionTypes[]) {
|
||||
return await QueryPostAPI(ACCOUNT_API_URL + 'update-enable-functions', functions)
|
||||
}
|
||||
export async function SaveSetting(
|
||||
name: 'Queue' | 'Point' | 'Index' | 'General' | 'QuestionDisplay' | 'SongRequest' | 'QuestionBox' | 'SendEmail',
|
||||
setting: unknown,
|
||||
) {
|
||||
const result = await QueryPostAPIWithParams(
|
||||
ACCOUNT_API_URL + 'update-single-setting',
|
||||
{
|
||||
name,
|
||||
},
|
||||
setting,
|
||||
)
|
||||
return result.message
|
||||
}
|
||||
export async function UpdateFunctionEnable(func: FunctionTypes) {
|
||||
if (ACCOUNT.value) {
|
||||
const oldValue = JSON.parse(JSON.stringify(ACCOUNT.value.settings.enableFunctions))
|
||||
|
||||
@@ -242,6 +242,7 @@ export enum QueueSortType {
|
||||
GuardFirst,
|
||||
PaymentFist,
|
||||
TimeFirst,
|
||||
FansMedalFirst
|
||||
}
|
||||
|
||||
export enum QueueGiftFilterType {
|
||||
|
||||
@@ -48,7 +48,7 @@ QueryGetAPI<string>(BASE_API_URL + 'vtsuru/version')
|
||||
isHaveNewVersion = true
|
||||
currentVersion = version.data
|
||||
localStorage.setItem('Version', currentVersion)
|
||||
|
||||
console.log('[vtsuru] 发现新版本: ' + currentVersion)
|
||||
const route = useRoute()
|
||||
if (!route.path.startsWith('/obs')) {
|
||||
const n = notification.info({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { copyToClipboard, downloadImage } from '@/Utils'
|
||||
import { DisableFunction, EnableFunction, SaveAccountSettings, useAccount } from '@/api/account'
|
||||
import { DisableFunction, EnableFunction, SaveAccountSettings, SaveSetting, useAccount } from '@/api/account'
|
||||
import { FunctionTypes, QAInfo } from '@/api/api-models'
|
||||
import { QueryGetAPI } from '@/api/query'
|
||||
import { QUESTION_API_URL } from '@/data/constants'
|
||||
@@ -117,18 +117,19 @@ function saveQRCode() {
|
||||
downloadImage(`https://api.qrserver.com/v1/create-qr-code/?data=${shareUrl.value}`, 'vtsuru-提问箱二维码.png')
|
||||
}
|
||||
async function saveSettings() {
|
||||
try {
|
||||
useQB.isLoading = true
|
||||
const data = await SaveAccountSettings()
|
||||
if (data.code == 200) {
|
||||
message.success('保存成功')
|
||||
await SaveSetting('QuestionBox', accountInfo.value.settings.questionBox)
|
||||
.then((msg) => {
|
||||
if (msg) {
|
||||
message.success('已保存')
|
||||
return true
|
||||
} else {
|
||||
message.error('保存失败: ' + data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('保存失败:' + error)
|
||||
message.error('保存失败: ' + msg)
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
useQB.isLoading = false
|
||||
})
|
||||
}
|
||||
|
||||
const parentRef = ref<HTMLElement | null>(null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { useAccount } from '@/api/account'
|
||||
import { SaveSetting, useAccount } from '@/api/account'
|
||||
import { EventDataTypes, SettingPointGiftAllowType, Setting_Point } from '@/api/api-models'
|
||||
import { QueryPostAPI } from '@/api/query'
|
||||
import { POINT_API_URL } from '@/data/constants'
|
||||
@@ -68,12 +68,12 @@ async function updateSettings() {
|
||||
isLoading.value = true
|
||||
setting.value.giftPercentMap ??= {}
|
||||
try {
|
||||
const data = await QueryPostAPI(POINT_API_URL + 'update-setting', setting.value)
|
||||
if (data.code == 200) {
|
||||
const msg = await SaveSetting('Point', setting.value)
|
||||
if (msg) {
|
||||
message.success('已保存')
|
||||
return true
|
||||
} else {
|
||||
message.error('保存失败: ' + data.message)
|
||||
message.error('保存失败: ' + msg)
|
||||
}
|
||||
} catch (err) {
|
||||
message.error('保存失败: ' + err)
|
||||
|
||||
@@ -48,6 +48,9 @@ const songs = computed(() => {
|
||||
case QueueSortType.PaymentFist: {
|
||||
result = result.OrderByDescending((q) => q.price ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
case QueueSortType.FansMedalFirst: {
|
||||
result = result.OrderByDescending((q) => q.user?.fans_medal_level ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
}
|
||||
if (settings.value.isReverse) {
|
||||
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
|
||||
|
||||
@@ -53,12 +53,15 @@ const activeItems = computed(() => {
|
||||
break
|
||||
}
|
||||
case QueueSortType.GuardFirst: {
|
||||
list = list.OrderBy((q) => q.user?.guard_level).ThenBy((q) => q.createAt)
|
||||
list = list.OrderBy((q) => (q.user?.guard_level == 0 || q.user?.guard_level == null ? 4 : q.user.guard_level)).ThenBy((q) => q.createAt)
|
||||
break
|
||||
}
|
||||
case QueueSortType.PaymentFist: {
|
||||
list = list.OrderByDescending((q) => q.giftPrice ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
case QueueSortType.FansMedalFirst: {
|
||||
list = list.OrderByDescending((q) => q.user?.fans_medal_level ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
}
|
||||
if (settings.value.isReverse) {
|
||||
list = list.Reverse()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { AddBiliBlackList, SaveEnableFunctions, useAccount } from '@/api/account'
|
||||
import { AddBiliBlackList, SaveEnableFunctions, SaveSetting, useAccount } from '@/api/account'
|
||||
import {
|
||||
DanmakuUserInfo,
|
||||
EventDataTypes,
|
||||
@@ -172,6 +172,9 @@ const songs = computed(() => {
|
||||
case QueueSortType.PaymentFist: {
|
||||
result = result.OrderByDescending((q) => q.price ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
case QueueSortType.FansMedalFirst: {
|
||||
result = result.OrderByDescending((q) => q.user?.fans_medal_level ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
}
|
||||
if (configCanEdit.value ? settings.value.isReverse : isReverse.value) {
|
||||
return result.Reverse().ToArray()
|
||||
@@ -438,17 +441,15 @@ async function onUpdateFunctionEnable() {
|
||||
async function updateSettings() {
|
||||
if (accountInfo.value) {
|
||||
isLoading.value = true
|
||||
await QueryPostAPI(SONG_REQUEST_API_URL + 'update-setting', settings.value)
|
||||
.then((data) => {
|
||||
if (data.code == 200) {
|
||||
//message.success('已保存')
|
||||
await SaveSetting('SongRequest', settings.value)
|
||||
.then((msg) => {
|
||||
if (msg) {
|
||||
message.success('已保存')
|
||||
return true
|
||||
} else {
|
||||
message.error('保存失败: ' + data.message)
|
||||
message.error('保存失败: ' + msg)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
message.error('保存失败')
|
||||
})
|
||||
.finally(() => {
|
||||
isLoading.value = false
|
||||
})
|
||||
@@ -868,6 +869,7 @@ onUnmounted(() => {
|
||||
<NRadioButton :value="QueueSortType.TimeFirst"> 加入时间优先 </NRadioButton>
|
||||
<NRadioButton :value="QueueSortType.PaymentFist"> 付费价格优先 </NRadioButton>
|
||||
<NRadioButton :value="QueueSortType.GuardFirst"> 舰长优先 (按等级) </NRadioButton>
|
||||
<NRadioButton :value="QueueSortType.FansMedalFirst"> 粉丝牌等级优先 </NRadioButton>
|
||||
</NRadioGroup>
|
||||
<NCheckbox v-if="configCanEdit" v-model:checked="settings.isReverse" @update:checked="updateSettings">
|
||||
倒序
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { AddBiliBlackList, SaveEnableFunctions, useAccount } from '@/api/account'
|
||||
import { AddBiliBlackList, SaveEnableFunctions, SaveSetting, useAccount } from '@/api/account'
|
||||
import {
|
||||
DanmakuUserInfo,
|
||||
EventDataTypes,
|
||||
@@ -163,12 +163,17 @@ const queue = computed(() => {
|
||||
break
|
||||
}
|
||||
case QueueSortType.GuardFirst: {
|
||||
list = list.OrderBy((q) => q.user?.guard_level).ThenBy((q) => q.createAt)
|
||||
list = list
|
||||
.OrderBy((q) => (q.user?.guard_level == 0 || q.user?.guard_level == null ? 4 : q.user.guard_level))
|
||||
.ThenBy((q) => q.createAt)
|
||||
break
|
||||
}
|
||||
case QueueSortType.PaymentFist: {
|
||||
list = list.OrderByDescending((q) => q.giftPrice ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
case QueueSortType.FansMedalFirst: {
|
||||
list = list.OrderByDescending((q) => q.user?.fans_medal_level ?? 0).ThenBy((q) => q.createAt)
|
||||
}
|
||||
}
|
||||
if (configCanEdit.value ? settings.value.isReverse : isReverse.value) {
|
||||
list = list.Reverse()
|
||||
@@ -420,17 +425,15 @@ async function onUpdateFunctionEnable() {
|
||||
async function updateSettings() {
|
||||
if (accountInfo.value) {
|
||||
isLoading.value = true
|
||||
await QueryPostAPI(QUEUE_API_URL + 'update-setting', settings.value)
|
||||
.then((data) => {
|
||||
if (data.code == 200) {
|
||||
await SaveSetting('Queue', settings.value)
|
||||
.then((msg) => {
|
||||
if (msg) {
|
||||
message.success('已保存')
|
||||
return true
|
||||
} else {
|
||||
message.error('保存失败: ' + data.message)
|
||||
message.error('保存失败: ' + msg)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
message.error('保存失败')
|
||||
})
|
||||
.finally(() => {
|
||||
isLoading.value = false
|
||||
})
|
||||
@@ -832,6 +835,7 @@ onUnmounted(() => {
|
||||
<NRadioButton :value="QueueSortType.TimeFirst"> 加入时间优先 </NRadioButton>
|
||||
<NRadioButton :value="QueueSortType.PaymentFist"> 付费价格优先 </NRadioButton>
|
||||
<NRadioButton :value="QueueSortType.GuardFirst"> 舰长优先 (按等级) </NRadioButton>
|
||||
<NRadioButton :value="QueueSortType.FansMedalFirst"> 粉丝牌等级优先 </NRadioButton>
|
||||
</NRadioGroup>
|
||||
<NCheckbox v-if="configCanEdit" v-model:checked="settings.isReverse" @update:checked="updateSettings">
|
||||
倒序
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- eslint-disable @typescript-eslint/no-explicit-any -->
|
||||
<script setup lang="ts">
|
||||
import { useAccount } from '@/api/account'
|
||||
import { SaveSetting, useAccount } from '@/api/account'
|
||||
import { QuestionDisplayAlign, Setting_QuestionDisplay } from '@/api/api-models'
|
||||
import { QueryPostAPI } from '@/api/query'
|
||||
import QuestionItem from '@/components/QuestionItem.vue'
|
||||
@@ -86,17 +86,15 @@ const setting = computed({
|
||||
async function updateSettings() {
|
||||
if (accountInfo.value) {
|
||||
isLoading.value = true
|
||||
await QueryPostAPI(QUESTION_API_URL + 'update-setting', setting.value)
|
||||
.then((data) => {
|
||||
if (data.code == 200) {
|
||||
//message.success('已保存')
|
||||
await SaveSetting('QuestionDisplay', setting.value)
|
||||
.then((msg) => {
|
||||
if (msg) {
|
||||
message.success('已保存')
|
||||
return true
|
||||
} else {
|
||||
message.error('保存失败: ' + data.message)
|
||||
message.error('保存失败: ' + msg)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
message.error('保存失败')
|
||||
})
|
||||
.finally(() => {
|
||||
isLoading.value = false
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user