Skip to content

Commit

Permalink
adding page titles
Browse files Browse the repository at this point in the history
  • Loading branch information
KishinZW committed Jul 28, 2024
1 parent 9a7887d commit 3f54d8d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
20 changes: 7 additions & 13 deletions pages/device.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<Title>设备管理</Title>
<div class="grid gap-4 md:grid-cols-2 md:gap-8 lg:grid-cols-4">
<Card>
<CardHeader class="flex flex-row items-center justify-between space-y-0 pb-2">
Expand Down Expand Up @@ -79,10 +80,7 @@
</DialogTrigger>
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>创建设备</DialogTitle>
<DialogDescription>
请输入设备名称
</DialogDescription>
<DialogTitle>请输入设备名称</DialogTitle>
</DialogHeader>
<div class="grid gap-4 py-4">
<div class="grid grid-cols-4 items-center gap-4">
Expand Down Expand Up @@ -141,10 +139,7 @@
</DialogTrigger>
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>编辑设备名</DialogTitle>
<DialogDescription>
请输入新的设备名
</DialogDescription>
<DialogTitle>请输入新的设备名</DialogTitle>
</DialogHeader>
<div class="grid gap-4 py-4">
<div class="grid grid-cols-4 items-center gap-4">
Expand All @@ -156,14 +151,14 @@
</div>
<DialogClose>
<Button
v-if="!isPending"
v-if="!isPending2"
type="submit"
@click="editMutation({ id: device.id, new_location: edit_new_location })"
>
确认修改
</Button>
<Button v-if="isPending" type="submit" disabled>
<Loader2 v-if="isPending" class="w-4 h-4 mr-2 animate-spin" />
<Button v-if="isPending2" type="submit" disabled>
<Loader2 v-if="isPending2" class="w-4 h-4 mr-2 animate-spin" />
请稍候……
</Button>
</DialogClose>
Expand Down Expand Up @@ -203,7 +198,6 @@ import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
Expand Down Expand Up @@ -236,7 +230,7 @@ const { mutate: deleteMutation } = useMutation({
},
onError: err => useErrorHandler(err),
});
const { mutate: editMutation } = useMutation({
const { mutate: editMutation, isPending: isPending2 } = useMutation({
mutationFn: $api.device.edit.mutate,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['device.list'] });
Expand Down
1 change: 1 addition & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<Title>食堂显示屏管理系统</Title>
<div class="grid gap-4 md:grid-cols-2 md:gap-8 lg:grid-cols-4">
<Card>
<CardHeader class="flex flex-row items-center justify-between space-y-0 pb-2">
Expand Down
1 change: 1 addition & 0 deletions pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<Title>登录</Title>
<div class="w-full lg:grid h-full">
<div class="flex items-center justify-center">
<div class="mx-auto grid w-[400px] gap-6">
Expand Down
36 changes: 34 additions & 2 deletions pages/program.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<Title>节目管理</Title>
<div class="grid gap-4 md:grid-cols-2 md:gap-8 lg:grid-cols-4">
<Card>
<CardHeader class="flex flex-row items-center justify-between space-y-0 pb-2">
Expand Down Expand Up @@ -158,7 +159,6 @@
<Button
v-if="!isPending"
type="submit"
@click="editMutation({ id: program.id, new_name: edit_new_name })"
>
确认修改
</Button>
Expand All @@ -178,7 +178,39 @@
</TableCell>
<TableCell>{{ program.createdAt.toLocaleDateString() }}</TableCell>
<TableCell>
施工中
<Dialog>
<DialogTrigger as-child>
<Button variant="outline" class="h-8">
编辑
</Button>
</DialogTrigger>
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>节目内容</DialogTitle>
</DialogHeader>
<div class="grid gap-4 py-4">
<div class="grid grid-cols-4 items-center gap-4">
<Label for="name" class="text-right">
节目名称
</Label>
<Input id="name" v-model="edit_new_name" class="col-span-3" />
</div>
</div>
<DialogClose>
<Button
v-if="!isPending"
type="submit"
@click="editMutation({ id: program.id, new_name: edit_new_name })"
>
确认修改
</Button>
<Button v-if="isPending" type="submit" disabled>
<Loader2 v-if="isPending" class="w-4 h-4 mr-2 animate-spin" />
请稍候……
</Button>
</DialogClose>
</DialogContent>
</Dialog>
</TableCell>
</TableRow>
</TableBody>
Expand Down
10 changes: 10 additions & 0 deletions server/trpc/controllers/program.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { eq } from 'drizzle-orm';
import { TRPCError } from '@trpc/server';
import type { TNewProgram } from '../../db/db';
import { db } from '../../db/db';
import { programs } from '../../db/schema';
Expand All @@ -25,4 +26,13 @@ export class ProgramController {
const res = await db.query.programs.findMany();
return res;
}

async getSequence(id: number) {
const res = await db.query.programs.findFirst({
where: eq(programs.id, id),
});
if (!res)
throw new TRPCError({ code: 'NOT_FOUND', message: '节目不存在' });
return res.sequence;
}
}
7 changes: 7 additions & 0 deletions server/trpc/routers/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ export const programRouter = router({
.query(async ({ ctx }) => {
return await ctx.programController.getList();
}),

getSequence: protectedProcedure
.use(requireRoles(['admin']))
.input(z.object({ id: programIdZod }))
.query(async ({ ctx, input }) => {
return await ctx.programController.getSequence(input.id);
}),
});

0 comments on commit 3f54d8d

Please sign in to comment.