mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
fix music request
This commit is contained in:
70
src/App.vue
70
src/App.vue
@@ -1,30 +1,32 @@
|
|||||||
<template>
|
<template>
|
||||||
<NMessageProvider>
|
<NConfigProvider :theme-overrides="themeOverrides" :theme="theme" style="height: 100vh" :locale="zhCN" :date-locale="dateZhCN">
|
||||||
<NNotificationProvider>
|
<NMessageProvider>
|
||||||
<NConfigProvider :theme-overrides="themeOverrides" :theme="theme" style="height: 100vh" :locale="zhCN" :date-locale="dateZhCN">
|
<NNotificationProvider>
|
||||||
<NLoadingBarProvider>
|
<NDialogProvider>
|
||||||
<Suspense>
|
<NLoadingBarProvider>
|
||||||
<TempComponent>
|
<Suspense>
|
||||||
<NLayoutContent style="height: 100%" v-if="layout != 'obs'">
|
<TempComponent>
|
||||||
<NElement>
|
<NLayoutContent style="height: 100%" v-if="layout != 'obs'">
|
||||||
<ViewerLayout v-if="layout == 'viewer'" />
|
<NElement>
|
||||||
<ManageLayout v-else-if="layout == 'manage'" />
|
<ViewerLayout v-if="layout == 'viewer'" />
|
||||||
<OpenLiveLayout v-else-if="layout == 'open-live'" />
|
<ManageLayout v-else-if="layout == 'manage'" />
|
||||||
<template v-else-if="layout == ''">
|
<OpenLiveLayout v-else-if="layout == 'open-live'" />
|
||||||
<RouterView />
|
<template v-else-if="layout == ''">
|
||||||
</template>
|
<RouterView />
|
||||||
</NElement>
|
</template>
|
||||||
</NLayoutContent>
|
</NElement>
|
||||||
<RouterView v-else />
|
</NLayoutContent>
|
||||||
</TempComponent>
|
<RouterView v-else />
|
||||||
<template #fallback>
|
</TempComponent>
|
||||||
<NSpin size="large" show />
|
<template #fallback>
|
||||||
</template>
|
<NSpin size="large" show />
|
||||||
</Suspense>
|
</template>
|
||||||
</NLoadingBarProvider>
|
</Suspense>
|
||||||
</NConfigProvider>
|
</NLoadingBarProvider>
|
||||||
</NNotificationProvider>
|
</NDialogProvider>
|
||||||
</NMessageProvider>
|
</NNotificationProvider>
|
||||||
|
</NMessageProvider>
|
||||||
|
</NConfigProvider>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -32,7 +34,21 @@ import { useProviderStore } from '@/store/useProviderStore'
|
|||||||
import ManageLayout from '@/views/ManageLayout.vue'
|
import ManageLayout from '@/views/ManageLayout.vue'
|
||||||
import ViewerLayout from '@/views/ViewerLayout.vue'
|
import ViewerLayout from '@/views/ViewerLayout.vue'
|
||||||
import { useStorage } from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
import { NConfigProvider, NElement, NLayoutContent, NLoadingBarProvider, NMessageProvider, NNotificationProvider, NSpin, darkTheme, dateZhCN, useLoadingBar, useOsTheme, zhCN } from 'naive-ui'
|
import {
|
||||||
|
NConfigProvider,
|
||||||
|
NDialogProvider,
|
||||||
|
NElement,
|
||||||
|
NLayoutContent,
|
||||||
|
NLoadingBarProvider,
|
||||||
|
NMessageProvider,
|
||||||
|
NNotificationProvider,
|
||||||
|
NSpin,
|
||||||
|
darkTheme,
|
||||||
|
dateZhCN,
|
||||||
|
useLoadingBar,
|
||||||
|
useOsTheme,
|
||||||
|
zhCN,
|
||||||
|
} from 'naive-ui'
|
||||||
import { computed, defineComponent, onMounted } from 'vue'
|
import { computed, defineComponent, onMounted } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { ThemeType } from './api/api-models'
|
import { ThemeType } from './api/api-models'
|
||||||
|
|||||||
25
src/Utils.ts
25
src/Utils.ts
@@ -1,5 +1,5 @@
|
|||||||
import { useStorage } from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
import { createDiscreteApi, useOsTheme } from 'naive-ui'
|
import { UploadFileInfo, createDiscreteApi, useOsTheme } from 'naive-ui'
|
||||||
import { ThemeType } from './api/api-models'
|
import { ThemeType } from './api/api-models'
|
||||||
|
|
||||||
const { message } = createDiscreteApi(['message'])
|
const { message } = createDiscreteApi(['message'])
|
||||||
@@ -80,3 +80,26 @@ export function getBase64(file: File | undefined | null): Promise<string | undef
|
|||||||
reader.onerror = (error) => reject(error)
|
reader.onerror = (error) => reject(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export async function getImageUploadModel(files: UploadFileInfo[] | undefined | null, maxSize: number = 10 * 1024 * 1024) {
|
||||||
|
let result = {
|
||||||
|
existImages: [],
|
||||||
|
newImagesBase64: [],
|
||||||
|
} as { existImages: string[]; newImagesBase64: string[] }
|
||||||
|
if (!files) return result
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i]
|
||||||
|
if ((file.file?.size ?? 0) > maxSize) {
|
||||||
|
message.error('文件大小不能超过 ' + maxSize / 1024 / 1024 + 'MB')
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
if (!file.file) {
|
||||||
|
result.existImages.push(file.id) //用id绝对路径当的文件名
|
||||||
|
} else {
|
||||||
|
const base64 = await getBase64(file.file)
|
||||||
|
if (base64) {
|
||||||
|
result.newImagesBase64.push(base64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
@@ -520,7 +520,9 @@ export enum GoodsTypes {
|
|||||||
export interface ResponsePointGoodModel {
|
export interface ResponsePointGoodModel {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
count: number
|
description: string
|
||||||
|
content?: string
|
||||||
|
count?: number
|
||||||
price: number
|
price: number
|
||||||
tags: TagInfo[]
|
tags: TagInfo[]
|
||||||
cover?: string
|
cover?: string
|
||||||
@@ -528,14 +530,17 @@ export interface ResponsePointGoodModel {
|
|||||||
status: GoodsStatus
|
status: GoodsStatus
|
||||||
type: GoodsTypes
|
type: GoodsTypes
|
||||||
}
|
}
|
||||||
|
export interface ImageUploadModel{
|
||||||
|
existImages: string[]
|
||||||
|
newImagesBase64: string[]
|
||||||
|
}
|
||||||
export interface PointGoodsModel {
|
export interface PointGoodsModel {
|
||||||
id?: number
|
id?: number
|
||||||
name: string
|
name: string
|
||||||
count: number
|
count: number
|
||||||
price: number
|
price: number
|
||||||
tags: TagInfo[]
|
tags: TagInfo[]
|
||||||
coverImageBase64?: string
|
cover?: ImageUploadModel
|
||||||
status: GoodsStatus
|
status: GoodsStatus
|
||||||
type: GoodsTypes
|
type: GoodsTypes
|
||||||
collectUrl?: string
|
collectUrl?: string
|
||||||
|
|||||||
@@ -1,20 +1,45 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ResponsePointGoodModel } from '@/api/api-models'
|
import { ResponsePointGoodModel } from '@/api/api-models'
|
||||||
import { NCard } from 'naive-ui'
|
import { NButton, NCard, NDropdown, NEllipsis, NFlex, NIcon, NImage, NPopselect, NText } from 'naive-ui'
|
||||||
import { ref } from 'vue'
|
import { FILE_BASE_URL, IMGUR_URL } from '@/data/constants'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { MoreHorizontal16Filled, MoreVertical16Filled } from '@vicons/fluent'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
goods: ResponsePointGoodModel
|
goods: ResponsePointGoodModel
|
||||||
}>()
|
}>()
|
||||||
|
const emptyCover = IMGUR_URL + 'None.png'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NCard>
|
<NCard style="max-width: 300px">
|
||||||
<template #cover>
|
<template #cover>
|
||||||
<img :src="goods.cover" />
|
<NImage :src="goods.cover ? FILE_BASE_URL + goods.cover : emptyCover" :fallback-src="emptyCover" height="150" object-fit="cover" :preview-disabled="!goods.cover" style="width: 100%" />
|
||||||
|
</template>
|
||||||
|
<template #header-extra>
|
||||||
|
<slot name="header-extra"></slot>
|
||||||
</template>
|
</template>
|
||||||
<template #header>
|
<template #header>
|
||||||
{{ goods.name }}
|
<NEllipsis>
|
||||||
|
{{ goods.name }}
|
||||||
|
</NEllipsis>
|
||||||
|
</template>
|
||||||
|
<NFlex vertical>
|
||||||
|
<NText depth="3">
|
||||||
|
{{ goods.description }}
|
||||||
|
</NText>
|
||||||
|
<NFlex justify="space-between">
|
||||||
|
<NFlex>
|
||||||
|
<NText> 库存: </NText>
|
||||||
|
<NText v-if="goods.count && goods.count > -1">
|
||||||
|
{{ goods.count }}
|
||||||
|
</NText>
|
||||||
|
<NText v-else> 不限 </NText>
|
||||||
|
</NFlex>
|
||||||
|
</NFlex>
|
||||||
|
</NFlex>
|
||||||
|
<template #footer>
|
||||||
|
<slot name="footer"></slot>
|
||||||
</template>
|
</template>
|
||||||
</NCard>
|
</NCard>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ const failoverAPI = `https://failover-api.vtsuru.suki.club/api/`
|
|||||||
export const isBackendUsable = ref(true)
|
export const isBackendUsable = ref(true)
|
||||||
|
|
||||||
export const AVATAR_URL = 'https://workers.vrp.moe/api/bilibili/avatar/'
|
export const AVATAR_URL = 'https://workers.vrp.moe/api/bilibili/avatar/'
|
||||||
|
export const FILE_BASE_URL = 'https://files.vtsuru.live'
|
||||||
|
export const IMGUR_URL = FILE_BASE_URL + '/imgur/'
|
||||||
export const apiFail = ref(false)
|
export const apiFail = ref(false)
|
||||||
|
|
||||||
export const BASE_API = () => (process.env.NODE_ENV === 'development' ? debugAPI : apiFail.value ? failoverAPI : releseAPI)
|
export const BASE_API = () => (process.env.NODE_ENV === 'development' ? debugAPI : apiFail.value ? failoverAPI : releseAPI)
|
||||||
|
|||||||
@@ -37,6 +37,15 @@ export default {
|
|||||||
title: '日程',
|
title: '日程',
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
},
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'ics',
|
||||||
|
beforeEnter(to: any) {
|
||||||
|
// 直接重定向到外部 URL
|
||||||
|
window.location.href = 'https://vtsuru.live/api/schedule/get-ics?id=' + to.query.id
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,18 +66,21 @@ export const useMusicRequestProvider = defineStore('MusicRequest', () => {
|
|||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
|
|
||||||
function addWaitingMusic(info: WaitMusicInfo) {
|
function addWaitingMusic(info: WaitMusicInfo) {
|
||||||
|
console.log(settings.value.orderMusicFirst + ' ' + isPlayingOrderMusic.value)
|
||||||
if ((settings.value.orderMusicFirst && !isPlayingOrderMusic.value) || aplayerRef.value?.audio.paused == true) {
|
if ((settings.value.orderMusicFirst && !isPlayingOrderMusic.value) || aplayerRef.value?.audio.paused == true) {
|
||||||
playMusic(info.music)
|
playMusic(info.music)
|
||||||
|
isPlayingOrderMusic.value = true
|
||||||
console.log(`正在播放 [${info.from.name}] 点的 ${info.music.name} - ${info.music.author?.join('/')}`)
|
console.log(`正在播放 [${info.from.name}] 点的 ${info.music.name} - ${info.music.author?.join('/')}`)
|
||||||
|
message.success(`正在播放 [${info.from.name}] 点的 ${info.music.name} - ${info.music.author?.join('/')}`)
|
||||||
} else {
|
} else {
|
||||||
waitingMusics.value.push(info)
|
waitingMusics.value.push(info)
|
||||||
message.success(`[${info.from.name}] 点了一首 ${info.music.name} - ${info.music.author?.join('/')}`)
|
message.success(`[${info.from.name}] 点了一首 ${info.music.name} - ${info.music.author?.join('/')}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onMusicEnd() {
|
function onMusicEnd() {
|
||||||
|
isPlayingOrderMusic.value = false
|
||||||
if (!playWaitingMusic()) {
|
if (!playWaitingMusic()) {
|
||||||
isPlayingOrderMusic.value = false
|
if (currentOriginMusic.value) {
|
||||||
if (currentOriginMusic) {
|
|
||||||
currentOriginMusic.value = undefined
|
currentOriginMusic.value = undefined
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -139,6 +142,14 @@ export const useMusicRequestProvider = defineStore('MusicRequest', () => {
|
|||||||
message.error('设置音频输出设备失败: ' + err)
|
message.error('设置音频输出设备失败: ' + err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function nextMusic() {
|
||||||
|
if (waitingMusics.value.length > 0) {
|
||||||
|
onMusicEnd()
|
||||||
|
} else {
|
||||||
|
isPlayingOrderMusic.value = false
|
||||||
|
aplayerRef.value?.onAudioEnded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
waitingMusics,
|
waitingMusics,
|
||||||
@@ -155,6 +166,7 @@ export const useMusicRequestProvider = defineStore('MusicRequest', () => {
|
|||||||
onMusicEnd,
|
onMusicEnd,
|
||||||
onMusicPlay,
|
onMusicPlay,
|
||||||
pauseMusic,
|
pauseMusic,
|
||||||
|
nextMusic,
|
||||||
aplayerRef,
|
aplayerRef,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ function onStartVerify() {
|
|||||||
currentStep.value = 1
|
currentStep.value = 1
|
||||||
timer.value = setInterval(checkStatus, 2500)
|
timer.value = setInterval(checkStatus, 2500)
|
||||||
startModel.value = data.data
|
startModel.value = data.data
|
||||||
|
} else {
|
||||||
|
message.error('无法开启认证流程: ' + data.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -154,7 +156,7 @@ onMounted(async () => {
|
|||||||
<NText> 你的登陆链接为: </NText>
|
<NText> 你的登陆链接为: </NText>
|
||||||
<NInputGroup>
|
<NInputGroup>
|
||||||
<NInput :value="`https://vtsuru.live/point?auth=${biliToken}`" type="textarea" :allow-input="() => false" />
|
<NInput :value="`https://vtsuru.live/point?auth=${biliToken}`" type="textarea" :allow-input="() => false" />
|
||||||
<NButton @click="copyCode" type="info" style="height: 100%;"> 复制登陆链接 </NButton>
|
<NButton @click="copyCode" type="info" style="height: 100%"> 复制登陆链接 </NButton>
|
||||||
</NInputGroup>
|
</NInputGroup>
|
||||||
<NButton @click="" type="primary"> 前往个人中心 </NButton>
|
<NButton @click="" type="primary"> 前往个人中心 </NButton>
|
||||||
</NFlex>
|
</NFlex>
|
||||||
|
|||||||
@@ -409,6 +409,9 @@ function logout() {
|
|||||||
cookie.value = undefined
|
cookie.value = undefined
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}
|
}
|
||||||
|
function onNextMusic() {
|
||||||
|
musicRquestStore.nextMusic();
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (accountInfo.value?.isEmailVerified == false) {
|
if (accountInfo.value?.isEmailVerified == false) {
|
||||||
@@ -532,7 +535,7 @@ onMounted(() => {
|
|||||||
/>
|
/>
|
||||||
<NSpace vertical>
|
<NSpace vertical>
|
||||||
<NTag :bordered="false" type="info" size="small"> 队列: {{ musicRquestStore.waitingMusics.length }} </NTag>
|
<NTag :bordered="false" type="info" size="small"> 队列: {{ musicRquestStore.waitingMusics.length }} </NTag>
|
||||||
<NButton size="small" type="info" @click="musicRquestStore.waitingMusics.length > 0 ? musicRquestStore.onMusicEnd() : musicRquestStore.aplayerRef?.onAudioEnded()"> 下一首 </NButton>
|
<NButton size="small" type="info" @click="onNextMusic"> 下一首 </NButton>
|
||||||
</NSpace>
|
</NSpace>
|
||||||
</div>
|
</div>
|
||||||
</NLayoutFooter>
|
</NLayoutFooter>
|
||||||
@@ -550,7 +553,7 @@ onMounted(() => {
|
|||||||
<RegisterAndLogin style="max-width: 500px; min-width: 350px" />
|
<RegisterAndLogin style="max-width: 500px; min-width: 350px" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NSpin :loading="isLoadingAccount" style="overflow: hidden;"> 正在请求账户数据... </NSpin>
|
<NSpin :loading="isLoadingAccount" style="overflow: hidden"> 正在请求账户数据... </NSpin>
|
||||||
</template>
|
</template>
|
||||||
</NLayoutContent>
|
</NLayoutContent>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getBase64 } from '@/Utils'
|
import { getBase64, getImageUploadModel } from '@/Utils'
|
||||||
import { DisableFunction, EnableFunction, useAccount } from '@/api/account'
|
import { DisableFunction, EnableFunction, useAccount } from '@/api/account'
|
||||||
import { ResponsePointGoodModel, FunctionTypes, PointGoodsModel, GoodsTypes, GoodsStatus, TagInfo } from '@/api/api-models'
|
import { ResponsePointGoodModel, FunctionTypes, PointGoodsModel, GoodsTypes, GoodsStatus, TagInfo } from '@/api/api-models'
|
||||||
import { QueryGetAPI, QueryPostAPI } from '@/api/query'
|
import { QueryGetAPI, QueryPostAPI } from '@/api/query'
|
||||||
import { POINT_API_URL } from '@/data/constants'
|
import PointGoodsItem from '@/components/manage/PointGoodsItem.vue'
|
||||||
import { Info24Filled } from '@vicons/fluent'
|
import { FILE_BASE_URL, POINT_API_URL } from '@/data/constants'
|
||||||
|
import { Info24Filled, MoreVertical16Filled } from '@vicons/fluent'
|
||||||
import { List } from 'linqts'
|
import { List } from 'linqts'
|
||||||
import {
|
import {
|
||||||
NAlert,
|
NAlert,
|
||||||
@@ -32,15 +33,21 @@ import {
|
|||||||
FormItemRule,
|
FormItemRule,
|
||||||
NScrollbar,
|
NScrollbar,
|
||||||
FormValidationError,
|
FormValidationError,
|
||||||
NSelect,
|
NSelect,
|
||||||
|
NGrid,
|
||||||
|
NGridItem,
|
||||||
|
NDropdown,
|
||||||
|
NImage,
|
||||||
|
useDialog,
|
||||||
} from 'naive-ui'
|
} from 'naive-ui'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
const accountInfo = useAccount()
|
const accountInfo = useAccount()
|
||||||
|
const dialog = useDialog()
|
||||||
|
|
||||||
const goods = ref<ResponsePointGoodModel[]>(await getGoods())
|
const goods = ref<ResponsePointGoodModel[]>(await getGoods())
|
||||||
const addGoodsModel = ref<PointGoodsModel>({
|
const currentGoodsModel = ref<PointGoodsModel>({
|
||||||
type: GoodsTypes.Virtual,
|
type: GoodsTypes.Virtual,
|
||||||
status: GoodsStatus.Normal,
|
status: GoodsStatus.Normal,
|
||||||
} as PointGoodsModel)
|
} as PointGoodsModel)
|
||||||
@@ -48,6 +55,7 @@ const addGoodsModel = ref<PointGoodsModel>({
|
|||||||
const showAddGoodsModal = ref(false)
|
const showAddGoodsModal = ref(false)
|
||||||
|
|
||||||
const isAllowedPrivacyPolicy = ref(false)
|
const isAllowedPrivacyPolicy = ref(false)
|
||||||
|
const isUpdating = ref(false)
|
||||||
|
|
||||||
const fileList = ref<UploadFileInfo[]>([])
|
const fileList = ref<UploadFileInfo[]>([])
|
||||||
|
|
||||||
@@ -64,32 +72,55 @@ const rules = {
|
|||||||
required: true,
|
required: true,
|
||||||
message: '请输入虚拟礼物的具体内容',
|
message: '请输入虚拟礼物的具体内容',
|
||||||
validator: (rule: FormItemRule, value: string) => {
|
validator: (rule: FormItemRule, value: string) => {
|
||||||
return addGoodsModel.value.type != GoodsTypes.Virtual || (value?.length ?? 0) > 0
|
return currentGoodsModel.value.type != GoodsTypes.Virtual || (value?.length ?? 0) > 0
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
privacy: {
|
privacy: {
|
||||||
required: true,
|
required: true,
|
||||||
message: '需要阅读并同意本站隐私政策',
|
message: '需要阅读并同意本站隐私政策',
|
||||||
validator: (rule: FormItemRule, value: boolean) => {
|
validator: (rule: FormItemRule, value: boolean) => {
|
||||||
return (addGoodsModel.value.type != GoodsTypes.Physical && addGoodsModel.value.collectUrl != undefined) || isAllowedPrivacyPolicy.value
|
return (currentGoodsModel.value.type != GoodsTypes.Physical && currentGoodsModel.value.collectUrl != undefined) || isAllowedPrivacyPolicy.value
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const formRef = ref()
|
const formRef = ref()
|
||||||
|
|
||||||
const existTags = computed(() => {
|
const existTags = computed(() => {
|
||||||
|
if (goods.value.length == 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
//获取所有已存在商品的tags并去重
|
//获取所有已存在商品的tags并去重
|
||||||
const tempSet = new Set<TagInfo>()
|
const tempSet = new Set<TagInfo>()
|
||||||
for (let i = 0; i < goods.value.length; i++) {
|
for (let i = 0; i < goods.value.length; i++) {
|
||||||
|
const goodsTags = goods.value[i].tags
|
||||||
|
if (!goodsTags || goodsTags.length == 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for (let j = 0; j < goods.value[i].tags.length; j++) {
|
for (let j = 0; j < goods.value[i].tags.length; j++) {
|
||||||
tempSet.add(goods.value[i].tags[j])
|
tempSet.add(goods.value[i].tags[j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Array.from(tempSet).map((item) => {
|
return Array.from(tempSet).map((item) => {
|
||||||
return { label: item.name, value: item.id }
|
return { label: item.name, value: item.name }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const dropDownActions = {
|
||||||
|
update: {
|
||||||
|
label: '修改',
|
||||||
|
key: 'update',
|
||||||
|
action: (item: ResponsePointGoodModel) => onUpdateClick(item),
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
label: '删除',
|
||||||
|
key: 'delete',
|
||||||
|
action: (item: ResponsePointGoodModel) => onDeleteClick(item),
|
||||||
|
},
|
||||||
|
} as { [key: string]: { label: string; key: string; action: (item: ResponsePointGoodModel) => void } }
|
||||||
|
const dropDownOptions = computed(() => {
|
||||||
|
return Object.values(dropDownActions)
|
||||||
|
})
|
||||||
|
|
||||||
async function getGoods() {
|
async function getGoods() {
|
||||||
try {
|
try {
|
||||||
var resp = await QueryGetAPI<ResponsePointGoodModel[]>(POINT_API_URL + 'get-goods', {
|
var resp = await QueryGetAPI<ResponsePointGoodModel[]>(POINT_API_URL + 'get-goods', {
|
||||||
@@ -119,18 +150,25 @@ async function setFunctionEnable(enable: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function updateGoods(e: MouseEvent) {
|
async function updateGoods(e: MouseEvent) {
|
||||||
|
if (isUpdating.value || !formRef.value) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!formRef.value) return
|
isUpdating.value = true
|
||||||
await formRef.value
|
await formRef.value
|
||||||
.validate()
|
.validate()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
if (fileList.value.length > 0) {
|
if (fileList.value.length > 0) {
|
||||||
addGoodsModel.value.coverImageBase64 = await getBase64(fileList.value[0].file)
|
currentGoodsModel.value.cover = await getImageUploadModel(fileList.value)
|
||||||
}
|
}
|
||||||
await QueryPostAPI<ResponsePointGoodModel>(POINT_API_URL + 'update-goods', addGoodsModel.value)
|
console.log(currentGoodsModel.value.cover)
|
||||||
|
await QueryPostAPI<ResponsePointGoodModel>(POINT_API_URL + 'update-goods', currentGoodsModel.value)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.code == 200) {
|
if (data.code == 200) {
|
||||||
message.success('成功')
|
message.success('成功')
|
||||||
|
if (goods.value.find((g) => g.id == data.data.id)) {
|
||||||
|
goods.value[goods.value.findIndex((g) => g.id == data.data.id)] = data.data
|
||||||
|
} else {
|
||||||
|
goods.value.push(data.data)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
message.error('失败: ' + data.message)
|
message.error('失败: ' + data.message)
|
||||||
}
|
}
|
||||||
@@ -144,6 +182,11 @@ async function updateGoods(e: MouseEvent) {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
message.error('表单验证失败')
|
message.error('表单验证失败')
|
||||||
})
|
})
|
||||||
|
.finally(() => {
|
||||||
|
isUpdating.value = false
|
||||||
|
showAddGoodsModal.value = false
|
||||||
|
currentGoodsModel.value = {} as PointGoodsModel
|
||||||
|
})
|
||||||
}
|
}
|
||||||
function OnFileListChange(files: UploadFileInfo[]) {
|
function OnFileListChange(files: UploadFileInfo[]) {
|
||||||
if (files.length == 1) {
|
if (files.length == 1) {
|
||||||
@@ -154,6 +197,50 @@ function OnFileListChange(files: UploadFileInfo[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function onUpdateClick(item: ResponsePointGoodModel) {
|
||||||
|
currentGoodsModel.value = {
|
||||||
|
...item,
|
||||||
|
count: item.count ?? 0,
|
||||||
|
cover: undefined,
|
||||||
|
}
|
||||||
|
fileList.value = [
|
||||||
|
{
|
||||||
|
id: item.cover ?? 'cover',
|
||||||
|
thumbnailUrl: FILE_BASE_URL + item.cover,
|
||||||
|
name: '封面',
|
||||||
|
status: 'finished',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
showAddGoodsModal.value = true
|
||||||
|
}
|
||||||
|
function onDeleteClick(item: ResponsePointGoodModel) {
|
||||||
|
const d = dialog.warning({
|
||||||
|
title: '警告',
|
||||||
|
content: '你确定要删除这个礼物吗?',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
d.loading = true
|
||||||
|
try {
|
||||||
|
const data = await QueryGetAPI(POINT_API_URL + 'delete-goods', {
|
||||||
|
id: item.id,
|
||||||
|
})
|
||||||
|
if (data.code == 200) {
|
||||||
|
message.success('成功')
|
||||||
|
goods.value = goods.value.filter((g) => g.id != item.id)
|
||||||
|
} else {
|
||||||
|
message.error('失败: ' + data.message)
|
||||||
|
console.error(data.message)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
message.error('失败: ' + err)
|
||||||
|
console.error(err)
|
||||||
|
} finally {
|
||||||
|
d.loading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -172,25 +259,44 @@ function OnFileListChange(files: UploadFileInfo[]) {
|
|||||||
<NButton type="primary" @click="showAddGoodsModal = true"> 添加礼物 </NButton>
|
<NButton type="primary" @click="showAddGoodsModal = true"> 添加礼物 </NButton>
|
||||||
</NFlex>
|
</NFlex>
|
||||||
<NDivider />
|
<NDivider />
|
||||||
|
<NGrid :cols="4">
|
||||||
|
<NGridItem v-for="item in goods" :key="item.id">
|
||||||
|
<PointGoodsItem :goods="item">
|
||||||
|
<template #header-extra>
|
||||||
|
<NDropdown :options="dropDownOptions" trigger="click" @select="(v) => dropDownActions[v].action(item)">
|
||||||
|
<NButton text style="font-size: 24px">
|
||||||
|
<template #icon>
|
||||||
|
<NIcon :component="MoreVertical16Filled" />
|
||||||
|
</template>
|
||||||
|
</NButton>
|
||||||
|
</NDropdown>
|
||||||
|
</template>
|
||||||
|
</PointGoodsItem>
|
||||||
|
</NGridItem>
|
||||||
|
</NGrid>
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
</NTabs>
|
</NTabs>
|
||||||
|
|
||||||
<NModal v-model:show="showAddGoodsModal" preset="card" style="width: 600px; max-width: 90%" title="添加礼物">
|
<NModal v-model:show="showAddGoodsModal" preset="card" style="width: 600px; max-width: 90%" title="添加/修改礼物信息">
|
||||||
<NScrollbar style="max-height: 80vh">
|
<NScrollbar style="max-height: 80vh">
|
||||||
<NForm ref="formRef" :model="addGoodsModel" :rules="rules">
|
<NForm ref="formRef" :model="currentGoodsModel" :rules="rules" style="width: 95%">
|
||||||
<NFormItem path="name" label="名称" required>
|
<NFormItem path="name" label="名称" required>
|
||||||
<NInput v-model:value="addGoodsModel.name" placeholder="填写礼物名称" />
|
<NInput v-model:value="currentGoodsModel.name" placeholder="必填, 礼物名称" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="price" label="所需积分" required>
|
<NFormItem path="price" label="所需积分" required>
|
||||||
<NInputNumber v-model:value="addGoodsModel.price" placeholder="填写需要的积分" min="0" />
|
<NInputNumber v-model:value="currentGoodsModel.price" placeholder="必填, 兑换所需要的积分" min="0" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="description" label="描述" type="textarea">
|
<NFormItem path="description" label="描述">
|
||||||
<NInput v-model:value="addGoodsModel.description" placeholder="填写礼物描述" />
|
<NInput v-model:value="currentGoodsModel.description" placeholder="可选, 礼物描述" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="tags" label="标签">
|
<NFormItem path="tags" label="标签">
|
||||||
<NSelect v-model:value="addGoodsModel.tags" filterable multiple clearable tag placeholder="可选,按回车确认" :options="existTags" />
|
<NSelect :value="currentGoodsModel.tags?.map((tag) => tag.name)" filterable multiple clearable tag placeholder="可选,输入后按回车添加" :options="existTags" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="cover" label="封面" type="textarea">
|
<NFormItem path="cover" label="封面">
|
||||||
|
<NFlex v-if="currentGoodsModel.cover">
|
||||||
|
<NText>当前封面: </NText>
|
||||||
|
<NImage :src="FILE_BASE_URL + currentGoodsModel.cover" height="50" object-fit="cover" />
|
||||||
|
</NFlex>
|
||||||
<NUpload
|
<NUpload
|
||||||
:max="1"
|
:max="1"
|
||||||
accept=".png,.jpg,.jpeg,.gif,.svg,.webp,.ico,.bmp,.tif,.tiff,.jfif,.jpe,.jp,.psd,."
|
accept=".png,.jpg,.jpeg,.gif,.svg,.webp,.ico,.bmp,.tif,.tiff,.jfif,.jpe,.jp,.psd,."
|
||||||
@@ -199,19 +305,19 @@ function OnFileListChange(files: UploadFileInfo[]) {
|
|||||||
v-model:file-list="fileList"
|
v-model:file-list="fileList"
|
||||||
@update:file-list="OnFileListChange"
|
@update:file-list="OnFileListChange"
|
||||||
>
|
>
|
||||||
+ 上传图片
|
+ {{ currentGoodsModel.cover ? '更换' : '上传' }}封面
|
||||||
</NUpload>
|
</NUpload>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem path="type" label="类型">
|
<NFormItem path="type" label="类型">
|
||||||
<NRadioGroup v-model:value="addGoodsModel.type">
|
<NRadioGroup v-model:value="currentGoodsModel.type">
|
||||||
<NRadioButton :value="GoodsTypes.Virtual">虚拟礼物</NRadioButton>
|
<NRadioButton :value="GoodsTypes.Virtual">虚拟礼物</NRadioButton>
|
||||||
<NRadioButton :value="GoodsTypes.Physical">实体礼物</NRadioButton>
|
<NRadioButton :value="GoodsTypes.Physical">实体礼物</NRadioButton>
|
||||||
</NRadioGroup>
|
</NRadioGroup>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<template v-if="addGoodsModel.type == GoodsTypes.Physical">
|
<template v-if="currentGoodsModel.type == GoodsTypes.Physical">
|
||||||
<NFormItem path="collectUrl" label="收货地址">
|
<NFormItem path="collectUrl" label="收货地址">
|
||||||
<NFlex vertical>
|
<NFlex vertical>
|
||||||
<NRadioGroup :value="addGoodsModel.collectUrl == undefined ? 0 : 1" @update:value="(v) => (addGoodsModel.collectUrl = v == 1 ? '' : undefined)">
|
<NRadioGroup :value="currentGoodsModel.collectUrl == undefined ? 0 : 1" @update:value="(v) => (currentGoodsModel.collectUrl = v == 1 ? '' : undefined)">
|
||||||
<NRadioButton :value="0">通过本站收集收货地址</NRadioButton>
|
<NRadioButton :value="0">通过本站收集收货地址</NRadioButton>
|
||||||
<NRadioButton :value="1">
|
<NRadioButton :value="1">
|
||||||
使用站外链接收集地址
|
使用站外链接收集地址
|
||||||
@@ -225,12 +331,12 @@ function OnFileListChange(files: UploadFileInfo[]) {
|
|||||||
</NRadioGroup>
|
</NRadioGroup>
|
||||||
</NFlex>
|
</NFlex>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<template v-if="addGoodsModel.collectUrl != undefined">
|
<template v-if="currentGoodsModel.collectUrl != undefined">
|
||||||
<NFormItem path="url" label="收集链接">
|
<NFormItem path="url" label="收集链接">
|
||||||
<NInput v-model:value="addGoodsModel.collectUrl" placeholder="用于给用户填写自己收货地址的表格的分享链接" />
|
<NInput v-model:value="currentGoodsModel.collectUrl" placeholder="用于给用户填写自己收货地址的表格的分享链接" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
<NFormItem label="内嵌收集链接">
|
<NFormItem label="内嵌收集链接">
|
||||||
<NCheckbox v-model:checked="addGoodsModel.embedCollectUrl"> 尝试将收集链接嵌入到网页中 </NCheckbox>
|
<NCheckbox v-model:checked="currentGoodsModel.embedCollectUrl"> 尝试将收集链接嵌入到网页中 </NCheckbox>
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
@@ -240,20 +346,20 @@ function OnFileListChange(files: UploadFileInfo[]) {
|
|||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NFormItem path="content" label="礼物内容" required>
|
<NFormItem path="content" required>
|
||||||
<NInput
|
<template #label>
|
||||||
v-model:value="addGoodsModel.content"
|
礼物内容
|
||||||
style="min-height: 100px"
|
<NTooltip>
|
||||||
type="textarea"
|
<template #trigger>
|
||||||
placeholder="虚拟礼物的具体内容, 网盘链接什么之类的"
|
<NIcon :component="Info24Filled" />
|
||||||
maxlength="10000"
|
</template>
|
||||||
show-count
|
虚拟礼物的具体内容, 网盘链接什么之类的
|
||||||
autosize
|
</NTooltip>
|
||||||
clearable
|
</template>
|
||||||
/>
|
<NInput v-model:value="currentGoodsModel.content" type="textarea" placeholder="写这里咯" maxlength="10000" show-count clearable />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</template>
|
</template>
|
||||||
<NButton @click="updateGoods" type="primary"> 添加 </NButton>
|
<NButton @click="updateGoods" type="primary" :loading="isUpdating"> 添加 </NButton>
|
||||||
</NForm>
|
</NForm>
|
||||||
</NScrollbar>
|
</NScrollbar>
|
||||||
</NModal>
|
</NModal>
|
||||||
|
|||||||
Reference in New Issue
Block a user