Skip to content

Commit

Permalink
feat(admin, hitokoto): add uuids search
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Oct 5, 2023
1 parent dd65358 commit 45500c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
46 changes: 29 additions & 17 deletions components/admin/sentence/SearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dayjs, { Dayjs } from 'dayjs'
import { HitokotoType } from '~/enums/hitokoto'
export interface State {
uuid?: string
uuids?: string[]
keywords?: string
type?: HitokotoType
from?: string
Expand Down Expand Up @@ -42,14 +42,25 @@ const dateRange = reactive({
}
})
})
const uuid = computed({
get() {
return formState.value.uuids?.join('\n')
},
set(val) {
formState.value.uuids = val
? val.split('\n').map((v) => v.replace(/\n|\t|\r/g, '').trim())
: undefined
}
})
const resetFormState = () => {
formState.value = {}
}
const sentenceTypeOptions = Object.keys(HitokotoType).reduce(
(acc, key) => {
return [...acc, { label: convertHitokotoType(key), value: key }]
const type = HitokotoType[key as keyof typeof HitokotoType]
return [...acc, { label: convertHitokotoType(type), value: type }]
},
[] as Array<{ label: string; value: string }>
)
Expand All @@ -64,6 +75,7 @@ watch(
}
)
const handleOk = async () => {
console.log(formState.value)
emit('update:open', false)
emit('ok', formState.value)
}
Expand All @@ -86,8 +98,8 @@ const handleCancel = () => {
<a-button key="submit" type="primary" @click="handleOk">确认</a-button>
</template>
<a-form :model="formState" layout="vertical" name="search-sentences">
<a-form-item name="uuid" label="UUID">
<a-input v-model:value="formState.uuid" placeholder="单一 UUID" />
<a-form-item name="uuids" label="UUIDs">
<a-textarea v-model:value="uuid" placeholder="UUIDs 用回车分割" />
</a-form-item>
<a-form-item name="keywords" label="关键字">
<a-input v-model:value="formState.keywords" placeholder="句子关键字" />
Expand All @@ -111,19 +123,19 @@ const handleCancel = () => {
placeholder="提交者(UID 或者名字)"
/>
</a-form-item>
<a-form-item name="range" label="时间范围">
<div class="flex gap-3">
<a-date-picker
v-model:value="dateRange.start"
class="block w-1/2"
placeholder="开始时间"
/>
<a-date-picker
v-model:value="dateRange.end"
class="block w-1/2"
placeholder="结束时间"
/>
</div>
<a-form-item name="start_time" label="开始时间">
<a-date-picker
v-model:value="dateRange.start"
class="block w-full"
placeholder="开始时间"
/>
</a-form-item>
<a-form-item name="end_time" label="结束时间">
<a-date-picker
v-model:value="dateRange.end"
class="block w-full"
placeholder="结束时间"
/>
</a-form-item>
</a-form>
</a-modal>
Expand Down
2 changes: 1 addition & 1 deletion composables/api/reviewer/hitokoto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type HitokotoAdminListReq = {
from_who?: string
creator?: string
keywords?: string
uuid?: string
uuids?: string[]
}

export function useAdminHitokotoList(
Expand Down
3 changes: 2 additions & 1 deletion composables/api/reviewer/useHTTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Ref } from 'vue'
import type { UseFetchOptions } from '#app'
import { useUserStore } from '~/stores/user'
import IconEmoticonDead from '~icons/mdi/emoticon-dead'
import { cloneDeep } from 'lodash-es'

export interface R<T> {
code: number
Expand Down Expand Up @@ -55,7 +56,7 @@ const handleError = <T>(
// get方法传递数组形式参数
const paramsSerializer = (params?: SearchParameters) => {
if (!params) return
const query = structuredClone({ ...params })
const query = cloneDeep({ ...params })
Object.entries(query).forEach(([key, val]) => {
if (typeof val === 'object' && Array.isArray(val) && val !== null) {
query[`${key}[]`] = toRaw(val).map((v: unknown) => JSON.stringify(v))
Expand Down
7 changes: 7 additions & 0 deletions pages/admin/sentences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ const {
} = await useAdminHitokotoList(requestParams)
const cardData = computed(() => hitokotoListRes.value?.data.collection ?? [])
watch(
() => error.value,
async () => {
console.log(error.value)
}
)
// segments
const statusFilterOptions = [
{
Expand Down

0 comments on commit 45500c1

Please sign in to comment.