perf: table demo

This commit is contained in:
张传龙 2022-08-26 22:48:03 +08:00
parent 606c5a2df0
commit 006f730457

View File

@ -2,6 +2,7 @@ import { h } from 'vue'
import { NButton, NSwitch } from 'naive-ui' import { NButton, NSwitch } from 'naive-ui'
import { formatDateTime } from '@/utils' import { formatDateTime } from '@/utils'
import api from './api' import api from './api'
import { renderIcon } from '@/utils/icon'
export const usePostTable = () => { export const usePostTable = () => {
// refs // refs
@ -34,8 +35,9 @@ export const usePostTable = () => {
if (row && row.id) { if (row && row.id) {
row.recommending = true row.recommending = true
setTimeout(() => { setTimeout(() => {
$message.success(row.isRecommend ? '已取消推荐' : '已推荐') row.isRecommend = !row.isRecommend
row.recommending = false row.recommending = false
$message.success(row.isRecommend ? '已推荐' : '已取消推荐')
}, 800) }, 800)
} }
} }
@ -44,8 +46,9 @@ export const usePostTable = () => {
if (row && row.id) { if (row && row.id) {
row.publishing = true row.publishing = true
setTimeout(() => { setTimeout(() => {
$message.success(row.isPublish ? '已取消推荐' : '已推荐') row.isPublish = !row.isPublish
row.publishing = false row.publishing = false
$message.success(row.isPublish ? '已发布' : '已取消发布')
}, 800) }, 800)
} }
} }
@ -86,7 +89,8 @@ export const usePostTable = () => {
render(row) { render(row) {
return h(NSwitch, { return h(NSwitch, {
size: 'small', size: 'small',
defaultValue: row['isRecommend'], value: row['isRecommend'],
rubberBand: false,
loading: !!row.recommending, loading: !!row.recommending,
onUpdateValue: () => handleRecommend(row), onUpdateValue: () => handleRecommend(row),
}) })
@ -101,7 +105,8 @@ export const usePostTable = () => {
render(row) { render(row) {
return h(NSwitch, { return h(NSwitch, {
size: 'small', size: 'small',
defaultValue: row['isPublish'], rubberBand: false,
value: row['isPublish'],
loading: !!row.publishing, loading: !!row.publishing,
onUpdateValue: () => handlePublish(row), onUpdateValue: () => handlePublish(row),
}) })
@ -123,7 +128,7 @@ export const usePostTable = () => {
style: 'margin-left: 15px;', style: 'margin-left: 15px;',
onClick: () => handleDelete(row), onClick: () => handleDelete(row),
}, },
{ default: () => '删除' } { default: () => '删除', icon: renderIcon('material-symbols:delete-outline', { size: 14 }) }
), ),
] ]
}, },