Skip to content

Commit 2cb0cf7

Browse files
committed
feat: support recording cas time in ActivityRecord
1 parent 598305a commit 2cb0cf7

File tree

11 files changed

+173
-2
lines changed

11 files changed

+173
-2
lines changed

components/custom/CAS/Record/NewActivityRecord.vue

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import { Button } from '@/components/ui/button'
33
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
44
import { Multiselect } from '@/components/ui/multiselect'
5+
import {
6+
NumberField,
7+
NumberFieldContent,
8+
NumberFieldDecrement,
9+
NumberFieldIncrement,
10+
NumberFieldInput,
11+
} from '@/components/ui/number-field'
512
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
613
import { Textarea } from '@/components/ui/textarea'
714
import { useToast } from '@/components/ui/toast/use-toast'
@@ -30,6 +37,9 @@ const formSchema = toTypedSchema(z.object({
3037
date: z.date(),
3138
text: z.string().min(10).max(300),
3239
members: z.array(z.string().uuid()),
40+
cTime: z.number().min(0).max(5),
41+
aTime: z.number().min(0).max(5),
42+
sTime: z.number().min(0).max(5),
3343
}))
3444
3545
const { data } = await useAsyncData<AllClubs>('allClubs', () => {
@@ -46,8 +56,13 @@ if (!data.value) {
4656
})
4757
}
4858
49-
const { handleSubmit, resetForm } = useForm({
59+
const { handleSubmit, resetForm, setFieldValue } = useForm({
5060
validationSchema: formSchema,
61+
initialValues: {
62+
cTime: 0,
63+
aTime: 0,
64+
sTime: 0,
65+
},
5166
})
5267
5368
const onSubmit = handleSubmit(async (values) => {
@@ -138,6 +153,40 @@ const onSubmit = handleSubmit(async (values) => {
138153
</FormItem>
139154
</FormField>
140155

156+
<div class="flex space-x-2 w-full">
157+
<FormField v-for="(slot, index) in ['cTime', 'aTime', 'sTime']" :key="index" v-slot="{ value }" :name="slot">
158+
<FormItem>
159+
<FormLabel>{{ ['C', 'A', 'S'][index] }}时间</FormLabel>
160+
<NumberField
161+
class="gap-2 w-max"
162+
:min="0"
163+
:model-value="value"
164+
:step="0.5"
165+
:format-options="{
166+
minimumFractionDigits: 1,
167+
}"
168+
@update:model-value="(v: number) => {
169+
if (v) {
170+
setFieldValue(slot as Parameters<typeof setFieldValue>[0], v)
171+
}
172+
else {
173+
setFieldValue(slot as Parameters<typeof setFieldValue>[0], undefined)
174+
}
175+
}"
176+
>
177+
<NumberFieldContent>
178+
<NumberFieldDecrement />
179+
<FormControl>
180+
<NumberFieldInput />
181+
</FormControl>
182+
<NumberFieldIncrement />
183+
</NumberFieldContent>
184+
</NumberField>
185+
<FormMessage />
186+
</FormItem>
187+
</FormField>
188+
</div>
189+
141190
<FormField v-slot="{ componentField }" name="text">
142191
<FormItem>
143192
<FormLabel>活动概要</FormLabel>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup lang="ts">
2+
import type { NumberFieldRootEmits, NumberFieldRootProps } from 'radix-vue'
3+
import { NumberFieldRoot, useForwardPropsEmits } from 'radix-vue'
4+
import { type HTMLAttributes, computed } from 'vue'
5+
import { cn } from '@/lib/utils'
6+
7+
const props = defineProps<NumberFieldRootProps & { class?: HTMLAttributes['class'] }>()
8+
const emits = defineEmits<NumberFieldRootEmits>()
9+
10+
const delegatedProps = computed(() => {
11+
const { class: _, ...delegated } = props
12+
13+
return delegated
14+
})
15+
16+
const forwarded = useForwardPropsEmits(delegatedProps, emits)
17+
</script>
18+
19+
<template>
20+
<NumberFieldRoot v-bind="forwarded" :class="cn('grid gap-1.5', props.class)">
21+
<slot />
22+
</NumberFieldRoot>
23+
</template>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup lang="ts">
2+
import type { HTMLAttributes } from 'vue'
3+
import { cn } from '@/lib/utils'
4+
5+
const props = defineProps<{
6+
class?: HTMLAttributes['class']
7+
}>()
8+
</script>
9+
10+
<template>
11+
<div :class="cn('relative [&>[data-slot=input]]:has-[[data-slot=increment]]:pr-5 [&>[data-slot=input]]:has-[[data-slot=decrement]]:pl-5', props.class)">
12+
<slot />
13+
</div>
14+
</template>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup lang="ts">
2+
import type { NumberFieldDecrementProps } from 'radix-vue'
3+
import { NumberFieldDecrement, useForwardProps } from 'radix-vue'
4+
import { type HTMLAttributes, computed } from 'vue'
5+
import { Minus } from 'lucide-vue-next'
6+
import { cn } from '@/lib/utils'
7+
8+
const props = defineProps<NumberFieldDecrementProps & { class?: HTMLAttributes['class'] }>()
9+
10+
const delegatedProps = computed(() => {
11+
const { class: _, ...delegated } = props
12+
13+
return delegated
14+
})
15+
16+
const forwarded = useForwardProps(delegatedProps)
17+
</script>
18+
19+
<template>
20+
<NumberFieldDecrement data-slot="decrement" v-bind="forwarded" :class="cn('absolute top-1/2 -translate-y-1/2 left-0 p-3 disabled:cursor-not-allowed disabled:opacity-20', props.class)">
21+
<slot>
22+
<Minus class="h-4 w-4" />
23+
</slot>
24+
</NumberFieldDecrement>
25+
</template>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup lang="ts">
2+
import type { NumberFieldIncrementProps } from 'radix-vue'
3+
import { NumberFieldIncrement, useForwardProps } from 'radix-vue'
4+
import { type HTMLAttributes, computed } from 'vue'
5+
import { Plus } from 'lucide-vue-next'
6+
import { cn } from '@/lib/utils'
7+
8+
const props = defineProps<NumberFieldIncrementProps & { class?: HTMLAttributes['class'] }>()
9+
10+
const delegatedProps = computed(() => {
11+
const { class: _, ...delegated } = props
12+
13+
return delegated
14+
})
15+
16+
const forwarded = useForwardProps(delegatedProps)
17+
</script>
18+
19+
<template>
20+
<NumberFieldIncrement data-slot="increment" v-bind="forwarded" :class="cn('absolute top-1/2 -translate-y-1/2 right-0 disabled:cursor-not-allowed disabled:opacity-20 p-3', props.class)">
21+
<slot>
22+
<Plus class="h-4 w-4" />
23+
</slot>
24+
</NumberFieldIncrement>
25+
</template>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script setup lang="ts">
2+
import { NumberFieldInput } from 'radix-vue'
3+
import type { HTMLAttributes } from 'vue'
4+
import { cn } from '@/lib/utils'
5+
6+
const props = defineProps<{
7+
class?: HTMLAttributes['class']
8+
}>()
9+
</script>
10+
11+
<template>
12+
<NumberFieldInput
13+
data-slot="input"
14+
:class="cn('flex h-9 w-full rounded-md border border-input bg-transparent py-1 text-sm text-center shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50', props.class)"
15+
/>
16+
</template>

components/ui/number-field/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { default as NumberField } from './NumberField.vue'
2+
export { default as NumberFieldInput } from './NumberFieldInput.vue'
3+
export { default as NumberFieldIncrement } from './NumberFieldIncrement.vue'
4+
export { default as NumberFieldDecrement } from './NumberFieldDecrement.vue'
5+
export { default as NumberFieldContent } from './NumberFieldContent.vue'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- AlterTable
2+
ALTER TABLE "ActivityRecord" ADD COLUMN "aTime" DOUBLE PRECISION NOT NULL DEFAULT 0,
3+
ADD COLUMN "cTime" DOUBLE PRECISION NOT NULL DEFAULT 0,
4+
ADD COLUMN "sTime" DOUBLE PRECISION NOT NULL DEFAULT 0;

db/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ model ActivityRecord {
6767
clubId Int // Link to Club model
6868
date DateTime // Start date of the leave
6969
text String
70+
cTime Float @default(0)
71+
aTime Float @default(0)
72+
sTime Float @default(0)
7073
7174
// Relations
7275
club Club @relation(fields: [clubId], references: [id])

sentry.client.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as Sentry from '@sentry/nuxt'
22

33
Sentry.init({
4-
// There isn't any way to get the dsn from env var here
4+
// eslint-disable-next-line no-undef
55
environment: useRuntimeConfig().public.sentry.environment,
6+
// eslint-disable-next-line no-undef
67
dsn: useRuntimeConfig().public.sentry.dsn,
78
// This sets the sample rate to be 10%. You may want this to be 100% while
89
// in development and sample at a lower rate in production

0 commit comments

Comments
 (0)