|
2 | 2 | BookIcon, |
3 | 3 | BookmarkIcon, |
4 | 4 | EyeHideIcon, |
| 5 | + EyeIcon, |
| 6 | + EyeOffIcon, |
5 | 7 | HeartIcon, |
6 | 8 | PlusIcon, |
7 | 9 | } from '~/components/icons' |
@@ -41,7 +43,7 @@ export const ManageNoteListView = defineComponent({ |
41 | 43 | page, |
42 | 44 | size, |
43 | 45 | select: |
44 | | - 'title _id nid id created modified mood weather hide publicAt bookmark coordinates location count meta', |
| 46 | + 'title _id nid id created modified mood weather publicAt bookmark coordinates location count meta isPublished', |
45 | 47 | ...(sortProps.sortBy |
46 | 48 | ? { sortBy: sortProps.sortBy, sortOrder: sortProps.sortOrder } |
47 | 49 | : {}), |
@@ -90,26 +92,27 @@ export const ManageNoteListView = defineComponent({ |
90 | 92 | filter: true, |
91 | 93 | filterOptions: [ |
92 | 94 | { label: '回忆项', value: 'bookmark' }, |
93 | | - { label: '隐藏项', value: 'hide' }, |
| 95 | + { label: '草稿项', value: 'unpublished' }, |
94 | 96 | ], |
95 | 97 |
|
96 | 98 | render(row) { |
97 | 99 | const isSecret = |
98 | 100 | row.publicAt && +new Date(row.publicAt) - Date.now() > 0 |
| 101 | + const isUnpublished = !row.isPublished |
99 | 102 | return ( |
100 | 103 | <TableTitleLink |
101 | 104 | inPageTo={`/notes/edit?id=${row.id}`} |
102 | 105 | title={row.title} |
103 | 106 | externalLinkTo={`/notes/${row.nid}`} |
104 | 107 | id={row.id} |
105 | | - withToken={row.hide || isSecret} |
| 108 | + withToken={isUnpublished || isSecret} |
106 | 109 | xLog={row.meta?.xLog} |
107 | 110 | > |
108 | 111 | {{ |
109 | 112 | default() { |
110 | 113 | return ( |
111 | 114 | <> |
112 | | - {row.hide || isSecret ? ( |
| 115 | + {isUnpublished || isSecret ? ( |
113 | 116 | <Icon color="#34495e"> |
114 | 117 | <EyeHideIcon /> |
115 | 118 | </Icon> |
@@ -255,6 +258,46 @@ export const ManageNoteListView = defineComponent({ |
255 | 258 | return <RelativeTime time={row.modified} /> |
256 | 259 | }, |
257 | 260 | }, |
| 261 | + { |
| 262 | + title: '状态', |
| 263 | + key: 'isPublished', |
| 264 | + width: 120, |
| 265 | + render(row) { |
| 266 | + return ( |
| 267 | + <NSpace size={4} align="center"> |
| 268 | + <div class={`inline-flex items-center gap-1 px-2 py-1 rounded text-xs ${ |
| 269 | + row.isPublished |
| 270 | + ? 'bg-green-100 text-green-800' |
| 271 | + : 'bg-yellow-100 text-yellow-800' |
| 272 | + }`}> |
| 273 | + <Icon size={12}> |
| 274 | + {row.isPublished ? <EyeIcon /> : <EyeOffIcon />} |
| 275 | + </Icon> |
| 276 | + {row.isPublished ? '已发布' : '草稿'} |
| 277 | + </div> |
| 278 | + <NButton |
| 279 | + size="tiny" |
| 280 | + quaternary |
| 281 | + type={row.isPublished ? "warning" : "primary"} |
| 282 | + onClick={async () => { |
| 283 | + const newStatus = !row.isPublished |
| 284 | + try { |
| 285 | + await RESTManager.api.notes(row.id)('publish').patch({ |
| 286 | + data: { isPublished: newStatus } |
| 287 | + }) |
| 288 | + row.isPublished = newStatus |
| 289 | + message.success(newStatus ? '已发布' : '已设为草稿') |
| 290 | + } catch (_error) { |
| 291 | + message.error('操作失败') |
| 292 | + } |
| 293 | + }} |
| 294 | + > |
| 295 | + {row.isPublished ? '取消发布' : '发布'} |
| 296 | + </NButton> |
| 297 | + </NSpace> |
| 298 | + ) |
| 299 | + } |
| 300 | + }, |
258 | 301 | { |
259 | 302 | title: '操作', |
260 | 303 | key: 'id', |
@@ -318,7 +361,7 @@ export const ManageNoteListView = defineComponent({ |
318 | 361 | sortProps.sortBy = props.sortBy |
319 | 362 | sortProps.sortOrder = props.sortOrder |
320 | 363 | }} |
321 | | - ></Table> |
| 364 | + /> |
322 | 365 | ) |
323 | 366 | }, |
324 | 367 | }) |
@@ -348,6 +391,52 @@ export const ManageNoteListView = defineComponent({ |
348 | 391 | fetchData() |
349 | 392 | }} |
350 | 393 | /> |
| 394 | + |
| 395 | + <HeaderActionButton |
| 396 | + name="批量发布" |
| 397 | + disabled={checkedRowKeys.value.length === 0} |
| 398 | + icon={<EyeIcon />} |
| 399 | + variant="success" |
| 400 | + onClick={async () => { |
| 401 | + try { |
| 402 | + await Promise.all( |
| 403 | + checkedRowKeys.value.map(id => |
| 404 | + RESTManager.api.notes(id as string)('publish').patch({ |
| 405 | + data: { isPublished: true } |
| 406 | + }) |
| 407 | + ) |
| 408 | + ) |
| 409 | + message.success('批量发布成功') |
| 410 | + fetchData() // 重新获取数据 |
| 411 | + checkedRowKeys.value = [] |
| 412 | + } catch (_error) { |
| 413 | + message.error('批量发布失败') |
| 414 | + } |
| 415 | + }} |
| 416 | + /> |
| 417 | + |
| 418 | + <HeaderActionButton |
| 419 | + name="批量设为草稿" |
| 420 | + disabled={checkedRowKeys.value.length === 0} |
| 421 | + icon={<EyeOffIcon />} |
| 422 | + variant="warning" |
| 423 | + onClick={async () => { |
| 424 | + try { |
| 425 | + await Promise.all( |
| 426 | + checkedRowKeys.value.map(id => |
| 427 | + RESTManager.api.notes(id as string)('publish').patch({ |
| 428 | + data: { isPublished: false } |
| 429 | + }) |
| 430 | + ) |
| 431 | + ) |
| 432 | + message.success('批量设置草稿成功') |
| 433 | + fetchData() // 重新获取数据 |
| 434 | + checkedRowKeys.value = [] |
| 435 | + } catch (_error) { |
| 436 | + message.error('批量设置草稿失败') |
| 437 | + } |
| 438 | + }} |
| 439 | + /> |
351 | 440 | <HeaderActionButton to={'/notes/edit'} icon={<PlusIcon />} /> |
352 | 441 | </> |
353 | 442 | ), |
|
0 commit comments