Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/SMS-COSMO/screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Whats-more committed Mar 5, 2025
2 parents 9fa7a32 + b20f8b2 commit 08e7723
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 41 deletions.
35 changes: 17 additions & 18 deletions pages/content/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<TableHead>
源文件
</TableHead>
<TableHead>
审核状态
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
Expand Down Expand Up @@ -87,6 +90,12 @@
/>
</div>
</TableCell>
<TableCell>
待实现
</TableCell>
<TableCell>
待实现
</TableCell>
<TableCell>
<Dialog>
<DialogTrigger as-child>
Expand All @@ -96,32 +105,22 @@
</DialogTrigger>
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>请输入新的内容名</DialogTitle>
<DialogTitle>源文件预览</DialogTitle>
</DialogHeader>
<div class="grid gap-4 py-4">
<div class="grid grid-cols-4 items-center gap-4">
<Label for="c-name" class="text-right">
内容名称
</Label>
<Input id="c-name" v-model="edit_new_content_name" class="col-span-3" />
</div>
<div>
待实现
</div>
<DialogClose>
<Button
v-if="!isPending2"
type="submit"
@click="editContentNameMutation({ id: content.id, new_name: edit_new_content_name })"
>
确认修改
</Button>
<Button v-if="isPending3" type="submit" disabled>
<Loader2 v-if="isPending3" class="w-4 h-4 mr-2 animate-spin" />
请稍候……
<Button type="submit">
返回
</Button>
</DialogClose>
</DialogContent>
</Dialog>
</TableCell>
<TableCell>
待实现
</TableCell>
</TableRow>
</TableBody>
</Table>
Expand Down
4 changes: 2 additions & 2 deletions pages/device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
创建时间
</TableHead>
<TableHead>
节目id
节目名称
</TableHead>
</TableRow>
</TableHeader>
Expand Down Expand Up @@ -173,7 +173,7 @@
</TableCell>
<TableCell>{{ device.createdAt.toLocaleDateString() }}</TableCell>
<TableCell>
{{ device.programId }}
待实现
</TableCell>
</TableRow>
</TableBody>
Expand Down
179 changes: 158 additions & 21 deletions pages/program.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,16 @@
<Table>
<TableHeader>
<TableRow>
<TableHead>
<TableHead class="w-8">
随机选取内容/单个内容
</TableHead>
<TableHead class="w-64">
<TableHead class="text-left">
内容类型/内容名称
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="content in sequence" :key="content.id">
<TableRow v-for="(content, index) in sequence" :key="content.id">
<TableCell>
<div v-if="content.type === 'pool'" class="flex">
<p class="w-48 truncate">
Expand All @@ -337,6 +337,118 @@
<p class="w-48 truncate">
{{ content.name }}
</p>
<Dialog>
<DialogTrigger as-child>
<Pencil
class="opacity-35 flex-initial w-5 text-right"
:size="12"
/>
</DialogTrigger>
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>
修改内容
</DialogTitle>
</DialogHeader>
<div class="grid gap-4 py-4">
<div class="flex gap-1.5">
<Checkbox v-model:checked="chooseRandomContent" />
<Label class="text-left">
使用随机内容
</Label>
</div>
<div class="grid gap-2">
<Label for="category">内容所属类别</Label>
<Popover v-model:open="unfoldCheckbox">
<PopoverTrigger as-child>
<Button
variant="outline"
role="combobox"
:aria-expanded="unfoldCheckbox"
class="flex w-full justify-between"
>
<p>
{{
checkedCategory.id !== -1
? checkedCategory.category
: '选择类别'
}}
</p>
<ChevronsUpDown class="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent class="w-[200px] p-2">
<Command>
<CommandEmpty>请选择类别</CommandEmpty>
<CommandList>
<CommandGroup>
<CommandItem
v-for="pool in categoryList"
:key="pool.id"
:value="pool.id"
@select="(ev: any) => {
if (typeof ev.detail.value === 'number') {
checkedCategory.id = ev.detail.value;
checkedCategory.category = pool.category;
queryClient.invalidateQueries({ queryKey: ['content'] });
}
unfoldCheckbox = false;
}"
>
{{ pool.category }}
<Check
v-if="checkedCategory.id === pool.id"
class="ml-auto h-4 w-4"
/>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
</div>
<div
v-if="checkedCategory.id !== -1 && !chooseRandomContent"
class="grid gap-2"
>
<Command class="rounded-lg border shadow-md max-w-[450px]">
<CommandInput placeholder="搜索内容……" />
<CommandEmpty>没有找到相关内容。</CommandEmpty>
<CommandList>
<CommandGroup>
<CommandItem
v-for="content_ in selectedContentList"
:key="content_.id"
:value="content_.name"
@click="selectedContentId = content_.id"
>
<span>{{ content_.name }}</span>
<Check
v-if="selectedContentId === content_.id"
class="ml-auto h-4 w-4"
/>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</div>
</div>
<DialogClose>
<Button v-if="!seqEditPending" type="submit" @click="replaceContent(index)">
修改内容
</Button>
<Button v-if="seqEditPending" type="submit" disabled>
<Loader2 class="w-4 h-4 mr-2 animate-spin" />
请稍候……
</Button>
</DialogClose>
</DialogContent>
</Dialog>
<Trash2
class="opacity-35 flex-initial w-5 text-right"
:size="12"
@click="deleteContent(index)"
/>
</div>
</TableCell>
</TableRow>
Expand Down Expand Up @@ -424,30 +536,55 @@ const { data: selectedContentList } = useQuery({
},
});
const { mutate: sequenceMutation, isPending: seqEditPending } = useMutation({
const {
mutate: sequenceMutation,
isPending: seqEditPending,
isSuccess: seqEditSuccess,
} = useMutation({
mutationFn: $api.program.setSequence.mutate,
onError: err => useErrorHandler(err),
});
function appendContent() {
if (sequence.value === undefined)
return;
if (chooseRandomContent.value) {
sequenceMutation({
id: idInEdit.value,
sequence: sequence.value.concat([{
type: 'pool',
id: checkedCategory.id,
}]),
});
} else {
sequenceMutation({
id: idInEdit.value,
sequence: sequence.value.concat([{
type: 'content',
id: selectedContentId.value,
}]),
});
}
sequenceMutation({
id: idInEdit.value,
sequence: sequence.value.concat([{
type: chooseRandomContent.value ? 'pool' : 'content',
id: chooseRandomContent.value ? checkedCategory.id : selectedContentId.value,
}]),
});
if (seqEditSuccess)
toast.success('添加内容成功');
queryClient.invalidateQueries({ queryKey: ['program'] });
}
function deleteContent(index: number) {
if (sequence.value === undefined)
return;
sequenceMutation({
id: idInEdit.value,
sequence: sequence.value.toSpliced(index, 1),
});
if (seqEditSuccess)
toast.success('删除内容成功');
queryClient.invalidateQueries({ queryKey: ['program'] });
}
function replaceContent(index: number) {
if (sequence.value === undefined)
return;
sequenceMutation({
id: idInEdit.value,
sequence: sequence.value.toSpliced(
index,
1,
{
type: chooseRandomContent.value ? 'pool' : 'content',
id: chooseRandomContent.value ? checkedCategory.id : selectedContentId.value,
},
),
});
if (seqEditSuccess)
toast.success('修改内容成功');
queryClient.invalidateQueries({ queryKey: ['program'] });
}
Expand Down

0 comments on commit 08e7723

Please sign in to comment.