import { h } from 'vue';
import { Tag, Avatar } from 'ant-design-vue';

export const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 50,
    fixed: 'left',
  },
  {
    title: '文章标题',
    dataIndex: 'title',
    width: 200,
    customRender({ record }) {
      return h(
        'a',
        {
          href: 'http://www.baidu.com',
          target: '_blank',
        },
        record.title,
      );
    },
  },
  {
    title: '文章封面',
    dataIndex: 'cover',
    key: 'cover',
    width: 100,
    customRender({ record }) {
      return h(Avatar, {
        size: 48,
        src: record.cover,
        shape: 'square',
        fit: 'fill',
      });
    },
  },
  {
    title: '文章分类',
    dataIndex: 'categoryName',
    width: 100,
  },
  {
    title: '文章作者',
    dataIndex: 'author',
    width: 100,
  },
  {
    title: '文章状态',
    dataIndex: 'status',
    width: 100,
    customRender({ record }) {
      return h(
        Tag,
        {
          color: record.status == 1 ? 'error' : 'success',
        },
        {
          default: () => (record.status == 1 ? '下架' : '正常'),
        },
      );
    },
  },
  {
    title: '点击率',
    dataIndex: 'click',
    width: 100,
  },
  {
    title: '文章排序',
    dataIndex: 'sort',
    width: 100,
  },
  {
    title: '创建人',
    dataIndex: 'createUser',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '操作',
    fixed: 'right',
    dataIndex: 'action',
    key: 'action',
    width: 200,
  },
];
