allow all gifts rebuy

This commit is contained in:
2025-01-10 02:40:42 +08:00
parent e71c84d572
commit 02e24a5783
5 changed files with 423 additions and 96 deletions

View File

@@ -165,6 +165,7 @@ export interface Setting_LiveRequest {
showUserName: boolean
showFanMadelInfo: boolean
obsTitle: string
obsTitleToday: string
isReverse: boolean
}

View File

@@ -16,7 +16,15 @@ export default {
alias: 'song-request',
component: () => import('@/views/obs/LiveRequestOBS.vue'),
meta: {
title: '弹幕点歌 (歌势'
title: '弹幕点'
}
},
{
path: 'live-request-today',
name: 'obs-live-request-today',
component: () => import('@/views/obs/LiveRequestProcessedOBS.vue'),
meta: {
title: '弹幕点播-今日'
}
},
{

View File

@@ -355,33 +355,23 @@ onMounted(() => {})
<template>
<NFlex>
<NAlert
:type="
<NAlert :type="
accountInfo.settings.enableFunctions.includes(FunctionTypes.Point) && accountInfo.eventFetcherState.online
? 'success'
: 'warning'
"
style="min-width: 400px"
>
" style="min-width: 400px">
启用
<NButton text type="primary" tag="a" href="https://www.yuque.com/megghy/dez70g/ohulp2torghlqqn8" target="_blank">
积分系统
</NButton>
<NDivider vertical />
<NSwitch
:value="accountInfo?.settings.enableFunctions.includes(FunctionTypes.Point)"
@update:value="setFunctionEnable"
/>
<NSwitch :value="accountInfo?.settings.enableFunctions.includes(FunctionTypes.Point)"
@update:value="setFunctionEnable" />
<br />
<NText depth="3">
此功能需要部署
<NButton
text
type="primary"
tag="a"
href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p"
target="_blank"
>
<NButton text type="primary" tag="a" href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p"
target="_blank">
VtsuruEventFetcher
</NButton>
, 否则将无法记录各种事件
@@ -417,10 +407,7 @@ onMounted(() => {})
</NGridItem>
</NGrid>
<NDivider>已下架</NDivider>
<NEmpty
v-if="goods.filter((g) => g.status == GoodsStatus.Discontinued).length == 0"
description="暂无已下架的礼物"
/>
<NEmpty v-if="goods.filter((g) => g.status == GoodsStatus.Discontinued).length == 0" description="暂无已下架的礼物" />
<NGrid v-else cols="1 500:2 700:3 1000:4 1200:5" :x-gap="12" :y-gap="8">
<NGridItem v-for="item in goods.filter((g) => g.status == GoodsStatus.Discontinued)" :key="item.id">
<PointGoodsItem :goods="item">
@@ -465,65 +452,40 @@ onMounted(() => {})
<NInputNumber v-model:value="currentGoodsModel.goods.price" placeholder="必填, 兑换所需要的积分" min="0" />
</NFormItem>
<NFormItem path="goods.count" label="库存">
<NCheckbox
:checked="!currentGoodsModel.goods.count"
@update:checked="(v) => (currentGoodsModel.goods.count = v ? undefined : 100)"
>
<NCheckbox :checked="!currentGoodsModel.goods.count"
@update:checked="(v) => (currentGoodsModel.goods.count = v ? undefined : 100)">
不限
</NCheckbox>
<NInputNumber
v-if="currentGoodsModel.goods.count"
v-model:value="currentGoodsModel.goods.count"
placeholder="可选, 礼物库存"
style="max-width: 120px"
/>
<NInputNumber v-if="currentGoodsModel.goods.count" v-model:value="currentGoodsModel.goods.count"
placeholder="可选, 礼物库存" style="max-width: 120px" />
</NFormItem>
<NFormItem path="goods.description" label="描述">
<NInput
v-model:value="currentGoodsModel.goods.description"
placeholder="可选, 礼物描述"
maxlength="500"
type="textarea"
/>
<NInput v-model:value="currentGoodsModel.goods.description" placeholder="可选, 礼物描述" maxlength="500"
type="textarea" />
</NFormItem>
<NFormItem path="goods.tags" label="标签">
<NSelect
v-model:value="currentGoodsModel.goods.tags"
filterable
multiple
clearable
tag
placeholder="可选,输入后按回车添加"
:options="existTags"
/>
<NSelect v-model:value="currentGoodsModel.goods.tags" filterable multiple clearable tag
placeholder="可选,输入后按回车添加" :options="existTags" />
</NFormItem>
<NFormItem path="goods.cover" label="封面">
<NFlex v-if="currentGoodsModel.goods.cover">
<NText>当前封面: </NText>
<NImage :src="FILE_BASE_URL + currentGoodsModel.goods.cover" height="50" object-fit="cover" />
</NFlex>
<NUpload
:max="1"
accept=".png,.jpg,.jpeg,.gif,.svg,.webp,.ico,.bmp,.tif,.tiff,.jfif,.jpe,.jp,.psd,."
list-type="image-card"
:default-upload="false"
v-model:file-list="currentGoodsModel.fileList"
@update:file-list="OnFileListChange"
>
<NUpload :max="1" accept=".png,.jpg,.jpeg,.gif,.svg,.webp,.ico,.bmp,.tif,.tiff,.jfif,.jpe,.jp,.psd,."
list-type="image-card" :default-upload="false" v-model:file-list="currentGoodsModel.fileList"
@update:file-list="OnFileListChange">
+ {{ currentGoodsModel.goods.cover ? '更换' : '上传' }}封面
</NUpload>
</NFormItem>
<NFormItem path="goods.guardFree" label="兑换规则">
<NFlex vertical>
<NCheckbox
:checked="currentGoodsModel.goods.setting?.guardFree != undefined"
@update:checked="
<NCheckbox :checked="currentGoodsModel.goods.setting?.guardFree != undefined" @update:checked="
(v) => {
// @ts-ignore
currentGoodsModel.goods.setting.guardFree = v ? { year: undefined, month: undefined } : undefined
}
"
>
">
允许舰长免费兑换
<NTooltip>
<template #trigger>
@@ -535,16 +497,10 @@ onMounted(() => {})
</NTooltip>
</NCheckbox>
<NFlex v-if="currentGoodsModel.goods.setting?.guardFree">
<NSelect
v-model:value="currentGoodsModel.goods.setting.guardFree.year"
:options="allowedYearOptions"
placeholder="请选择份"
/>
<NSelect
v-model:value="currentGoodsModel.goods.setting.guardFree.month"
:options="allowedMonthOptions"
placeholder="请选择月份"
/>
<NSelect v-model:value="currentGoodsModel.goods.setting.guardFree.year" :options="allowedYearOptions"
placeholder="请选择年份" />
<NSelect v-model:value="currentGoodsModel.goods.setting.guardFree.month" :options="allowedMonthOptions"
placeholder="请选择份" />
</NFlex>
<NText>
最低兑换等级
@@ -572,23 +528,17 @@ onMounted(() => {})
<NRadioButton :value="GoodsTypes.Physical">实体礼物</NRadioButton>
</NRadioGroup>
</NFormItem>
<template v-if="currentGoodsModel.goods.type == GoodsTypes.Physical">
<NFormItem path="settings" label="选项">
<NCheckbox v-model:checked="currentGoodsModel.goods.isAllowRebuy">允许重复兑换</NCheckbox>
</NFormItem>
<template v-if="currentGoodsModel.goods.type == GoodsTypes.Physical">
<NFormItem path="goods.maxBuyCount" label="最大兑换数量">
<NInputNumber
v-model:value="currentGoodsModel.goods.maxBuyCount"
placeholder="必填, 最大兑换数量"
min="1"
/>
<NInputNumber v-model:value="currentGoodsModel.goods.maxBuyCount" placeholder="必填, 最大兑换数量" min="1" />
</NFormItem>
<NFormItem path="address" label="收货地址">
<NFlex vertical>
<NRadioGroup
:value="currentGoodsModel.goods.collectUrl == undefined ? 0 : 1"
@update:value="(v) => (currentGoodsModel.goods.collectUrl = v == 1 ? '' : undefined)"
>
<NRadioGroup :value="currentGoodsModel.goods.collectUrl == undefined ? 0 : 1"
@update:value="(v) => (currentGoodsModel.goods.collectUrl = v == 1 ? '' : undefined)">
<NRadioButton :value="0">通过本站收集收货地址</NRadioButton>
<NRadioButton :value="1">
使用站外链接收集地址
@@ -605,11 +555,8 @@ onMounted(() => {})
<template v-if="currentGoodsModel.goods.collectUrl != undefined">
<NFormItem path="goods.collectUrl" label="收集链接">
<NFlex vertical style="width: 100%">
<NInput
v-model:value="currentGoodsModel.goods.collectUrl"
placeholder="用于给用户填写自己收货地址的表格的分享链接"
maxlength="300"
/>
<NInput v-model:value="currentGoodsModel.goods.collectUrl" placeholder="用于给用户填写自己收货地址的表格的分享链接"
maxlength="300" />
<NCheckbox v-model:checked="currentGoodsModel.goods.embedCollectUrl">
尝试将收集链接嵌入到网页中
</NCheckbox>
@@ -633,14 +580,8 @@ onMounted(() => {})
虚拟礼物的具体内容, 网盘链接什么之类的
</NTooltip>
</template>
<NInput
v-model:value="currentGoodsModel.goods.content"
type="textarea"
placeholder="写这里咯"
maxlength="10000"
show-count
clearable
/>
<NInput v-model:value="currentGoodsModel.goods.content" type="textarea" placeholder="写这里咯" maxlength="10000"
show-count clearable />
</NFormItem>
</template>
<NButton @click="updateGoods" type="primary" :loading="isUpdating">

View File

@@ -14,6 +14,7 @@ import { useRoute } from 'vue-router'
import { Vue3Marquee } from 'vue3-marquee'
import { NCard, NDivider, NEmpty, NMessageProvider, NSpace, NText, useMessage } from 'naive-ui'
import { List } from 'linqts'
import { useWebRTC } from '@/store/useRTC'
const props = defineProps<{
id?: number
@@ -24,6 +25,7 @@ const route = useRoute()
const currentId = computed(() => {
return props.id ?? route.query.id
})
const rtc = await useWebRTC().Init('slave')
const cardRef = ref()
const listContainerRef = ref()
@@ -114,6 +116,9 @@ async function update() {
}
}
}
async function onAddedItem() {
}
const direction = ref<'normal' | 'reverse'>('normal')
@@ -122,7 +127,11 @@ const active = ref(true)
let timer: any
onMounted(() => {
update()
timer = setInterval(update, 2000)
timer = setInterval(() => update(), 2000)
// 接收点播结果消息
rtc.on('function.live-request.add', () => update())
//@ts-expect-error 这里获取不了
if (window.obsstudio) {
//@ts-expect-error 这里获取不了
@@ -141,7 +150,6 @@ onUnmounted(() => {
</script>
<template>
<NMessageProvider :to="cardRef" />
<div ref="cardRef" class="live-request-background" v-bind="$attrs">
<p class="live-request-header">{{ settings.obsTitle ?? '点播' }}</p>
<NDivider class="live-request-divider">

View File

@@ -0,0 +1,369 @@
<script setup lang="ts">
import {
QueueSortType,
Setting_LiveRequest,
SongRequestFrom,
SongRequestInfo
} from '@/api/api-models'
import { QueryGetAPI } from '@/api/query'
import { SONG_REQUEST_API_URL } from '@/data/constants'
import { useElementSize } from '@vueuse/core'
import { List } from 'linqts'
import { NDivider, NEmpty, NMessageProvider, useMessage } from 'naive-ui'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { Vue3Marquee } from 'vue3-marquee'
const props = defineProps<{
id?: number
}>()
const message = useMessage()
const route = useRoute()
const currentId = computed(() => {
return props.id ?? route.query.id
})
const cardRef = ref()
const listContainerRef = ref()
const { height, width } = useElementSize(listContainerRef)
const itemHeight = 40
const key = ref(Date.now())
const originSongs = ref<SongRequestInfo[]>([])
const songs = computed(() => {
let result = new List(originSongs.value)
switch (settings.value.sortType) {
case QueueSortType.TimeFirst: {
result = result.ThenBy((q) => q.createAt)
break
}
case QueueSortType.GuardFirst: {
result = result
.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: {
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
return result.Reverse().ToArray()
} else {
return result.ToArray()
}
})
const isMoreThanContainer = computed(() => {
return songs.value.length * itemHeight > height.value
})
const settings = ref<Setting_LiveRequest>({} as Setting_LiveRequest)
async function get() {
try {
const data = await QueryGetAPI<{ songs: SongRequestInfo[]; setting: Setting_LiveRequest }>(
SONG_REQUEST_API_URL + 'get-today',
{
id: currentId.value,
},
)
if (data.code == 200) {
return data.data
}
} catch (err) { }
return {} as { songs: SongRequestInfo[]; setting: Setting_LiveRequest }
}
const allowGuardTypes = computed(() => {
const types = []
if (settings.value.needTidu) {
types.push('提督')
}
if (settings.value.needZongdu) {
types.push('总督')
}
if (settings.value.needJianzhang) {
types.push('舰长')
}
return types
})
async function update() {
if (!visiable.value || !active.value) return
const r = await get()
if (r) {
const isCountChange = originSongs.value.length != r.songs.length
originSongs.value = r.songs.sort((a, b) => {
return b.createAt - a.createAt
})
settings.value = r.setting
if (isCountChange) {
key.value = Date.now()
}
}
}
const direction = ref<'normal' | 'reverse'>('normal')
const visiable = ref(true)
const active = ref(true)
let timer: any
onMounted(() => {
update()
timer = setInterval(update, 2000)
//@ts-expect-error 这里获取不了
if (window.obsstudio) {
//@ts-expect-error 这里获取不了
window.obsstudio.onVisibilityChange = function (visibility: boolean) {
visiable.value = visibility
}
//@ts-expect-error 这里获取不了
window.obsstudio.onActiveChange = function (a: boolean) {
active.value = a
}
}
})
onUnmounted(() => {
clearInterval(timer)
})
</script>
<template>
<NMessageProvider :to="cardRef" />
<div ref="cardRef" class="live-request-background" v-bind="$attrs">
<p class="live-request-header">{{ settings.obsTitleToday ?? '今日已唱' }}</p>
<NDivider class="live-request-divider">
<p class="live-request-header-count">{{ songs.length ?? 0 }} </p>
</NDivider>
<div class="live-request-content" ref="listContainerRef">
<template v-if="songs.length > 0">
<Vue3Marquee class="live-request-list" :key="key" vertical :duration="20" :pause="!isMoreThanContainer"
:style="`height: ${height}px;width: ${width}px;`">
<div class="live-request-list-item" :from="song.from as number" :status="song.status as number"
v-for="(song, index) in songs" :key="song.id" :style="`height: ${itemHeight}px`">
<div class="live-request-list-item-index" :index="index + 1">
{{ index + 1 }}
</div>
<div class="live-request-list-item-song-name">
{{ song.songName }}
</div>
<p v-if="settings.showUserName" class="live-request-list-item-name">
{{ song.from == SongRequestFrom.Manual ? '主播添加' : song.user?.name }}
</p>
<div v-if="settings.showFanMadelInfo" class="live-request-list-item-level"
:has-level="(song.user?.fans_medal_level ?? 0) > 0">
{{ `${song.user?.fans_medal_name} ${song.user?.fans_medal_level}` }}
</div>
</div>
<NDivider v-if="isMoreThanContainer" class="live-request-footer-divider" style="margin: 10px 0 10px 0" />
</Vue3Marquee>
</template>
<div v-else style="position: relative; top: 20%">
<NEmpty class="live-request-empty" description="今日暂无" />
</div>
</div>
</div>
</template>
<style scoped>
.live-request-background {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
min-height: 100px;
min-width: 100px;
background-color: #0f0f0f48;
border-radius: 10px;
color: white;
}
.live-request-header {
margin: 0;
color: #fff;
text-align: center;
font-size: 20px;
font-weight: bold;
text-shadow:
0 0 10px #ca7b7b6e,
0 0 20px #ffffff8e,
0 0 30px #61606086,
0 0 40px rgba(64, 156, 179, 0.555);
}
.live-request-header-count {
color: #ffffffbd;
text-align: center;
font-size: 14px;
}
.live-request-divider {
margin: 0 auto;
margin-top: -15px;
margin-bottom: -15px;
width: 90%;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
.n-divider__line {
background-color: #ffffffd5;
}
.live-request-content {
background-color: #0f0f0f4f;
margin: 10px;
padding: 10px;
height: 100%;
border-radius: 10px;
overflow-x: hidden;
}
.marquee {
justify-items: left;
}
.live-request-list-item {
display: flex;
width: 100%;
align-self: flex-start;
position: relative;
align-items: center;
justify-content: left;
gap: 10px;
}
.live-request-list-item-song-name {
font-size: 18px;
font-weight: bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 80%;
}
/* 手动添加 */
.live-request-list-item[from='0'] .live-request-list-item-name {
font-style: italic;
font-weight: bold;
color: #d2d8d6;
font-size: 12px;
}
.live-request-list-item[from='0'] .live-request-list-item-avatar {
display: none;
}
/* 弹幕点歌 */
.live-request-list-item[from='1'] {}
.live-request-list-item-name {
font-style: italic;
font-size: 12px;
color: rgba(204, 204, 204, 0.993);
text-overflow: ellipsis;
white-space: nowrap;
margin-left: auto;
}
.live-request-list-item-index {
text-align: center;
height: 18px;
padding: 2px;
min-width: 15px;
border-radius: 5px;
background-color: #0f0f0f48;
color: rgba(204, 204, 204, 0.993);
font-size: 12px;
}
.live-request-list-item-level {
text-align: center;
height: 18px;
padding: 2px;
min-width: 15px;
border-radius: 5px;
background-color: #0f0f0f48;
color: rgba(204, 204, 204, 0.993);
font-size: 12px;
}
.live-request-list-item-level[has-level='false'] {
display: none;
}
.live-request-footer {
margin: 0 5px 5px 5px;
height: 60px;
border-radius: 5px;
background-color: #0f0f0f4f;
display: flex;
align-items: center;
}
.live-request-tag {
display: flex;
margin: 5px 0 5px 5px;
height: 40px;
border-radius: 3px;
background-color: #0f0f0f4f;
padding: 4px;
padding-right: 6px;
display: flex;
flex-direction: column;
justify-content: left;
}
.live-request-tag-key {
font-style: italic;
color: rgb(211, 211, 211);
font-size: 12px;
}
.live-request-tag-value {
font-size: 14px;
}
.live-request-list-item-index[index='1'] {
background-color: #ebc34c;
color: white;
font-weight: bold;
text-shadow: 0 0 6px #ebc34c;
}
.live-request-list-item-index[index='2'] {
background-color: #c0c0c0;
color: white;
font-weight: bold;
}
.live-request-list-item-index[index='3'] {
background-color: #b87333;
color: white;
font-weight: bold;
}
@keyframes animated-border {
0% {
box-shadow: 0 0 0px #589580;
}
100% {
box-shadow: 0 0 0 6px rgba(255, 255, 255, 0);
}
}
</style>