Skip to content

Commit 4880b1f

Browse files
authored
refactor: prompt store table to use raw data and improve UI (#630)
* refactor: prompt store table to use raw data and improve UI Signed-off-by: Bob Du <i@bobdu.cc> * refactor: prompt store table improve UI in mobile Signed-off-by: Bob Du <i@bobdu.cc> --------- Signed-off-by: Bob Du <i@bobdu.cc>
1 parent 9412c88 commit 4880b1f

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare module 'vue' {
1818
NDatePicker: typeof import('naive-ui')['NDatePicker']
1919
NDivider: typeof import('naive-ui')['NDivider']
2020
NDropdown: typeof import('naive-ui')['NDropdown']
21+
NEllipsis: typeof import('naive-ui')['NEllipsis']
2122
NIcon: typeof import('naive-ui')['NIcon']
2223
NInput: typeof import('naive-ui')['NInput']
2324
NInputNumber: typeof import('naive-ui')['NInputNumber']

src/components/common/PromptStore/index.vue

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import PromptRecommend from '../../../assets/recommend.json'
1111
1212
interface DataProps {
1313
_id?: string
14-
renderKey: string
15-
renderValue: string
16-
renderType: string
1714
title: string
1815
value: string
1916
type: 'built-in' | 'user-defined'
@@ -277,12 +274,8 @@ async function downloadPromptTemplate() {
277274
278275
// 移动端自适应相关
279276
function renderTemplate() {
280-
const [keyLimit, valueLimit] = isMobile.value ? [10, 30] : [15, 50]
281277
return promptList.value.map((item: UserPrompt) => {
282278
return {
283-
renderKey: item.title.length <= keyLimit ? item.title : `${item.title.substring(0, keyLimit)}...`,
284-
renderValue: item.value.length <= valueLimit ? item.value : `${item.value.substring(0, valueLimit)}...`,
285-
renderType: item.type === 'built-in' ? t('store.builtIn') : t('store.userDefined'),
286279
title: item.title,
287280
value: item.value,
288281
_id: item._id,
@@ -304,15 +297,27 @@ function createColumns(): DataTableColumns<DataProps> {
304297
return [
305298
{
306299
title: 'type',
307-
key: 'renderType',
300+
key: 'type',
301+
width: 100,
302+
align: 'center',
303+
render: (row: DataProps) => row.type === 'built-in' ? t('store.builtIn') : t('store.userDefined'),
308304
},
309305
{
310306
title: t('store.title'),
311-
key: 'renderKey',
307+
key: 'title',
308+
width: 200,
312309
},
313310
{
314311
title: t('store.description'),
315-
key: 'renderValue',
312+
key: 'value',
313+
ellipsis: {
314+
lineClamp: 6,
315+
tooltip: {
316+
contentClass: 'whitespace-pre-line text-xs max-h-100 max-w-200',
317+
scrollable: true,
318+
},
319+
},
320+
className: 'whitespace-pre-line',
316321
},
317322
{
318323
title: t('common.action'),
@@ -371,7 +376,7 @@ const dataSource = computed(() => {
371376
const value = searchValue.value
372377
if (value && value !== '') {
373378
return data.filter((item: DataProps) => {
374-
return item.renderKey.includes(value) || item.renderValue.includes(value)
379+
return item.title.includes(value) || item.value.includes(value)
375380
})
376381
}
377382
return data
@@ -445,9 +450,19 @@ async function handleGetUserPromptList() {
445450
/>
446451
<NList v-if="isMobile" style="max-height: 400px; overflow-y: auto;">
447452
<NListItem v-for="(item, index) of dataSource" :key="index">
448-
<NThing :title="item.renderKey" :description="item.renderValue" />
453+
<NThing :title="item.title" :description="item.value" description-class="text-xs">
454+
<template #description>
455+
<NEllipsis
456+
class="max-w-240 whitespace-pre-line"
457+
:tooltip="{ contentClass: 'whitespace-pre-line text-xs max-h-100 max-w-90', scrollable: true }"
458+
:line-clamp="3"
459+
>
460+
{{ item.value }}
461+
</NEllipsis>
462+
</template>
463+
</NThing>>
449464
<template #suffix>
450-
<div class="flex flex-col items-center gap-2">
465+
<div v-if="item.type !== 'built-in'" class="flex flex-col items-center gap-2">
451466
<NButton tertiary size="small" type="info" @click="changeShowModal('modify', item)">
452467
{{ t('common.edit') }}
453468
</NButton>

0 commit comments

Comments
 (0)