import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import {h} from "vue";
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '文章地址',
    align: "center",
    dataIndex: 'id',
    width:250,
    customRender: (text) => {
      if(text.text  == null){
        return "暂无"
      }
      if(text.text.length == 0){
        return "暂无"
      }
      let url = 'https://m.weibo.cn/detail/'+text.text;
      if(url.length > 30){
        url = url.substring(0,30) + "...."
      }
      return h('a', {
          title: 'https://m.weibo.cn/detail/'+text.text,
          href: 'https://m.weibo.cn/detail/'+text.text,
          target: '_blank'
        },
        url
      );
    },
  },

  {
    title: '用户地址',
    align: "center",
    dataIndex: 'userId',
    width:250,
    customRender: (text) => {
      if(text.text  == null){
        return "暂无"
      }
      if(text.text.length == 0){
        return "暂无"
      }
      let url = 'https://m.weibo.cn/u/'+text.text;
      if(url.length > 30){
        url = url.substring(0,30) + "...."
      }
      return h('a', {
          title: 'https://m.weibo.cn/u/'+text.text,
          href: 'https://m.weibo.cn/u/'+text.text,
          target: '_blank'
        },
        url
      );
    },
  },
  {
    title: '发布时间',
    align: "center",
    dataIndex: 'createdAt',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text);
    },
  },
  {
    title: '微博昵称',
    align: "center",
    dataIndex: 'screenName'
  },

  {
    title: '发布工具',
    align: "center",
    dataIndex: 'source'
  },
  {
    title: '点赞数',
    align: "center",
    dataIndex: 'attitudesCount'
  },
  {
    title: '评论数',
    align: "center",
    dataIndex: 'commentsCount'
  },
  {
    title: '转发数',
    align: "center",
    dataIndex: 'repostsCount'
  },
  {
    title: '原文章地址',
    align: "center",
    dataIndex: 'retweetId',
    width:250,
    customRender: (text) => {
      if(text.text  == null){
        return "暂无"
      }
      if(text.text.length == 0){
        return "暂无"
      }
      let url = 'https://m.weibo.cn/detail/'+text.text;
      if(url.length > 30){
        url = url.substring(0,30) + "...."
      }
      return h('a', {
          title: 'https://m.weibo.cn/detail/'+text.text,
          href: 'https://m.weibo.cn/detail/'+text.text,
          target: '_blank'
        },
        url
      );
    },
  },
  {
    title: '微博话题',
    align: "center",
    dataIndex: 'topics'
  },
  {
    title: 'bid',
    align: "center",
    dataIndex: 'bid'
  },
  {
    title: '存储微博中头条文章的url',
    align: "center",
    dataIndex: 'articleUrl'
  },
  {
    title: '存储微博at的用户',
    align: "center",
    dataIndex: 'atUsers'
  },
  {
    title: '存储微博的发布位置',
    align: "center",
    dataIndex: 'location'
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "bid",
    field: 'bid',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博用户id",
    field: 'userId',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博昵称",
    field: 'screenName',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博正文",
    field: 'text',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博中头条文章的url",
    field: 'articleUrl',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博话题",
    field: 'topics',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博at的用户",
    field: 'atUsers',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储原创微博的原始图片url",
    field: 'pics',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储原创微博的视频",
    field: 'videoUrl',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博的发布位置",
    field: 'location',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博的发布时间",
    field: "createdAt",
    component: 'RangePicker',
    colProps: {span: 6},
  },
  {
    label: "存储微博的发布工具",
    field: 'source',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博获得的点赞数",
    field: 'attitudesCount',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博获得的评论数",
    field: 'commentsCount',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储微博获得的转发数",
    field: 'repostsCount',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "存储转发微博中原始微博的微博id",
    field: 'retweetId',
    component: 'Input',
    colProps: {span: 6},
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: 'bid',
    field: 'bid',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入bid!'},
             ];
    },
  },
  {
    label: '存储微博用户id',
    field: 'userId',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博用户id!'},
             ];
    },
  },
  {
    label: '存储微博昵称',
    field: 'screenName',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博昵称!'},
             ];
    },
  },
  {
    label: '存储微博正文',
    field: 'text',
    component: 'JEditor',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博正文!'},
             ];
    },
  },
  {
    label: '存储微博中头条文章的url',
    field: 'articleUrl',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博中头条文章的url!'},
             ];
    },
  },
  {
    label: '存储微博话题',
    field: 'topics',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博话题!'},
             ];
    },
  },
  {
    label: '存储微博at的用户',
    field: 'atUsers',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博at的用户!'},
             ];
    },
  },
  {
    label: '存储原创微博的原始图片url',
    field: 'pics',
    component: 'JImageUpload',
    componentProps:{
    },
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储原创微博的原始图片url!'},
             ];
    },
  },
  {
    label: '存储原创微博的视频',
    field: 'videoUrl',
    component: 'JEditor',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储原创微博的视频!'},
             ];
    },
  },
  {
    label: '存储微博的发布位置',
    field: 'location',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博的发布位置!'},
             ];
    },
  },
  {
    label: '存储微博的发布时间',
    field: 'createdAt',
    component: 'DatePicker',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博的发布时间!'},
             ];
    },
  },
  {
    label: '存储微博的发布工具',
    field: 'source',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博的发布工具!'},
             ];
    },
  },
  {
    label: '存储微博获得的点赞数',
    field: 'attitudesCount',
    component: 'InputNumber',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博获得的点赞数!'},
             ];
    },
  },
  {
    label: '存储微博获得的评论数',
    field: 'commentsCount',
    component: 'InputNumber',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博获得的评论数!'},
             ];
    },
  },
  {
    label: '存储微博获得的转发数',
    field: 'repostsCount',
    component: 'InputNumber',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储微博获得的转发数!'},
             ];
    },
  },
  {
    label: '存储转发微博中原始微博的微博id',
    field: 'retweetId',
    component: 'Input',
    dynamicRules: () => {
      return [
              { required: true, message: '请输入存储转发微博中原始微博的微博id!'},
             ];
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
