From d2d583ef184437c8b135944f9cb5a52fde4e4813 Mon Sep 17 00:00:00 2001 From: SMFMgit <3534253741@qq.com> Date: Sun, 9 Mar 2025 14:21:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=AE=9E=E7=8E=B0=E4=BA=86=E8=8A=82=E7=9B=AE?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/device.vue | 87 +++++++++++++++++++++++++++++-- server/trpc/controllers/device.ts | 6 +++ server/trpc/routers/device.ts | 8 +++ 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/pages/device.vue b/pages/device.vue index 0a94f6c..a546596 100644 --- a/pages/device.vue +++ b/pages/device.vue @@ -173,7 +173,44 @@ {{ device.createdAt.toLocaleDateString() }} - 待实现 +
+ + + + + + + + 请选择节目 + + + + {{ program.name }} + + + + + + + +
@@ -186,6 +223,7 @@ diff --git a/server/trpc/controllers/device.ts b/server/trpc/controllers/device.ts index 495e3f6..b225ca5 100644 --- a/server/trpc/controllers/device.ts +++ b/server/trpc/controllers/device.ts @@ -21,6 +21,12 @@ export class DeviceController { .where(eq(devices.id, id)); return '设备名修改成功'; } + async bindProgram(id: number, programId: number) { + await db.update(devices) + .set({ programId }) + .where(eq(devices.id, id)); + return '节目绑定成功'; + } async getInfo(id: number) { const device = await db.query.devices.findFirst({ diff --git a/server/trpc/routers/device.ts b/server/trpc/routers/device.ts index b8aa16b..587e924 100644 --- a/server/trpc/routers/device.ts +++ b/server/trpc/routers/device.ts @@ -4,6 +4,7 @@ import { protectedProcedure, requireRoles, router } from '../trpc'; const locationZod = z.string() .max(20, { message: '设备名不能超过20个字符' }); const deviceIdZod = z.number(); +const programIdZod = z.number(); export const deviceRouter = router({ create: protectedProcedure @@ -27,6 +28,13 @@ export const deviceRouter = router({ return await ctx.deviceController.edit(input.id, input.new_location); }), + bindProgram: protectedProcedure + .use(requireRoles(['admin'])) + .input(z.object({ id: deviceIdZod, programId: programIdZod })) + .mutation(async ({ ctx, input }) => { + return await ctx.deviceController.bindProgram(input.id, input.programId); + }), + info: protectedProcedure .use(requireRoles(['admin'])) .input(z.object({ id: deviceIdZod }))