diff --git a/src/api/api-models.ts b/src/api/api-models.ts index 90a93dc..029c393 100644 --- a/src/api/api-models.ts +++ b/src/api/api-models.ts @@ -104,6 +104,7 @@ export interface UserSetting { queue: Setting_Queue point: Setting_Point questionDisplay: Setting_QuestionDisplay + index: Setting_Index enableFunctions: FunctionTypes[] @@ -111,6 +112,13 @@ export interface UserSetting { songListTemplate: string | null scheduleTemplate: string | null } +export interface Setting_Index { + videos: string[] + notification: string + links: { + [key: string]: string + } +} export interface Setting_LiveRequest { orderPrefix: string sortType?: QueueSortType @@ -474,7 +482,7 @@ export enum SongRequestFrom { Danmaku, SC, Web, - Gift + Gift, } export enum QueueFrom { Manual, @@ -716,3 +724,11 @@ export enum PointFrom { Manual, Use, } + +export interface ResponseUserIndexModel{ + notification: string + videos: VideoCollectVideo[] + links: { + [key: string]: string + } +} diff --git a/src/components/SimpleVideoCard.vue b/src/components/SimpleVideoCard.vue new file mode 100644 index 0000000..c3d4473 --- /dev/null +++ b/src/components/SimpleVideoCard.vue @@ -0,0 +1,34 @@ + + + + + + + + + + + {{ video.title }} + + + + + + {{ video.description }} + + + {{ video.description }} + + + + + + diff --git a/src/data/constants.ts b/src/data/constants.ts index a0f902f..4b6f0df 100644 --- a/src/data/constants.ts +++ b/src/data/constants.ts @@ -48,6 +48,7 @@ export const VTSURU_API_URL = { toString: () => `${BASE_API_URL}vtsuru/` } export const POINT_API_URL = { toString: () => `${BASE_API_URL}point/` } export const BILI_AUTH_API_URL = { toString: () => `${BASE_API_URL}bili-auth/` } export const FORUM_API_URL = { toString: () => `${BASE_API_URL}forum/` } +export const USER_INDEX_API_URL = { toString: () => `${BASE_API_URL}user-index/` } export const ScheduleTemplateMap = { '': { diff --git a/src/views/manage/SettingsManageView.vue b/src/views/manage/SettingsManageView.vue index 48bcada..cc4bf7b 100644 --- a/src/views/manage/SettingsManageView.vue +++ b/src/views/manage/SettingsManageView.vue @@ -6,10 +6,28 @@ import { downloadConfigDirect, useAccount, } from '@/api/account' -import { FunctionTypes, ScheduleWeekInfo, SongFrom, SongLanguage, SongRequestOption, SongsInfo } from '@/api/api-models' +import { + FunctionTypes, + ResponseUserIndexModel, + ScheduleWeekInfo, + SongFrom, + SongLanguage, + SongRequestOption, + SongsInfo, + VideoCollectVideo, +} from '@/api/api-models' +import { QueryGetAPI, QueryPostAPI } from '@/api/query' import DynamicForm from '@/components/DynamicForm.vue' +import SimpleVideoCard from '@/components/SimpleVideoCard.vue' import { TemplateConfig } from '@/data/VTsuruTypes' -import { FETCH_API, IndexTemplateMap, ScheduleTemplateMap, SongListTemplateMap } from '@/data/constants' +import { + FETCH_API, + IndexTemplateMap, + ScheduleTemplateMap, + SongListTemplateMap, + USER_INDEX_API_URL, +} from '@/data/constants' +import { Delete24Regular } from '@vicons/fluent' import { NAlert, NButton, @@ -18,15 +36,21 @@ import { NCheckboxGroup, NDivider, NEmpty, + NFlex, + NIcon, + NInput, NList, NListItem, NModal, + NPopconfirm, NSelect, NSpace, NSpin, NTabPane, NTabs, + NTag, NText, + NTooltip, SelectOption, useMessage, } from 'naive-ui' @@ -225,6 +249,15 @@ const selectedTemplateConfig = computed(() => { const biliUserInfo = ref() const settingModalVisiable = ref(false) +const showAddVideoModal = ref(false) +const showAddLinkModal = ref(false) + +const indexDisplayInfo = ref() +const addVideoUrl = ref('') +const isLoading = ref(false) +const addLinkName = ref('') +const addLinkUrl = ref('') +const linkKey = ref(0) async function RequestBiliUserData() { await fetch(FETCH_API + `https://account.bilibili.com/api/member/getCardByMid?mid=10021741`).then(async (respone) => { @@ -303,6 +336,96 @@ async function SaveTemplateSetting() { await SaveComboSetting() } } +async function updateIndexSettings() { + await QueryPostAPI(USER_INDEX_API_URL + 'update-setting', accountInfo.value.settings.index) + .then((data) => { + if (data.code == 200) { + message.success('已保存') + } else { + message.error('保存失败: ' + data.message) + } + }) + .catch((err) => { + message.error('保存失败: ' + err) + }) +} +async function addVideo() { + if (!addVideoUrl.value) { + message.error('请输入视频链接') + return + } + isLoading.value = true + await QueryGetAPI(USER_INDEX_API_URL + 'add-video', { + video: addVideoUrl.value, + }) + .then((data) => { + if (data.code == 200) { + message.success('已添加') + indexDisplayInfo.value?.videos.push(data.data) + accountInfo.value?.settings.index.videos.push(data.data.id) + addVideoUrl.value = '' + } else { + message.error('保存失败: ' + data.message) + } + }) + .catch((err) => { + message.error('保存失败: ' + err) + }) + .finally(() => { + isLoading.value = false + }) +} +async function removeVideo(id: string) { + isLoading.value = true + await QueryGetAPI(USER_INDEX_API_URL + 'del-video', { + video: id, + }) + .then((data) => { + if (data.code == 200) { + message.success('已删除') + if (indexDisplayInfo.value) { + indexDisplayInfo.value.videos = indexDisplayInfo.value?.videos.filter((v) => v.id != id) + } + + accountInfo.value.settings.index.videos = accountInfo.value.settings.index.videos.filter((v) => v != id) + } else { + message.error('删除失败: ' + data.message) + } + }) + .catch((err) => { + message.error('删除失败: ' + err) + }) + .finally(() => { + isLoading.value = false + }) +} +async function addLink() { + if (!addLinkName.value || !addLinkUrl.value) { + message.error('请输入名称和链接') + return + } + try { + new URL(addLinkUrl.value) + } catch (e) { + message.error('请输入正确的链接') + return + } + if (Object.keys(accountInfo.value.settings.index.links).includes(addLinkName.value)) { + message.error(addLinkName.value + '已存在') + return + } + accountInfo.value.settings.index.links[addLinkName.value] = addLinkUrl.value + await updateIndexSettings() + addLinkName.value = '' + addLinkUrl.value = '' + location.reload() +} +async function removeLink(name: string) { + delete accountInfo.value.settings.index.links[name] + await updateIndexSettings() + + location.reload() +} async function onOpenTemplateSettings() { settingModalVisiable.value = true nextTick(async () => { @@ -354,6 +477,23 @@ function unblockUser(id: number) { message.error(err) }) } +async function getIndexInfo() { + try { + isLoading.value = true + const data = await QueryGetAPI(USER_INDEX_API_URL + 'get', { id: accountInfo.value.id }) + if (data.code == 200) { + return data.data + } else if (data.code != 404) { + message?.error('无法获取数据: ' + data.message) + return undefined + } + } catch (err) { + message?.error('无法获取数据: ' + err) + return undefined + } finally { + isLoading.value = false + } +} onActivated(() => { if (route.query.tab) { @@ -365,6 +505,10 @@ onActivated(() => { }) onMounted(async () => { await RequestBiliUserData() + indexDisplayInfo.value = await getIndexInfo() + if (route.query.tab) { + message.info('已切换到指定面板, 在页面下方') + } }) @@ -403,6 +547,57 @@ onMounted(async () => { + + 通知 + + + 保存 + 展示视频 + 添加视频 + + + + + + + 删除 + + + + 其他链接 + 添加链接 + + + + + + + + {{ item[0] }} + + + {{ item[1] }} + + + + + + + + + + 确定要删除这个链接吗? + + + + + + + + 添加 + + + @@ -470,4 +665,15 @@ onMounted(async () => { :config="selectedTemplateConfig" /> + + + + 添加视频 + diff --git a/src/views/view/indexTemplate/DefaultIndexTemplate.vue b/src/views/view/indexTemplate/DefaultIndexTemplate.vue index 9b36a6d..07b7fea 100644 --- a/src/views/view/indexTemplate/DefaultIndexTemplate.vue +++ b/src/views/view/indexTemplate/DefaultIndexTemplate.vue @@ -1,9 +1,15 @@