Test.data.ts 6.1 KB
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { listknowledge } from '@/views/super/airag/test/Test.api';
//import { Tooltip } from 'ant-design-vue';

//列表数据
export const columns: BasicColumn[] = [
  /*{
    title: 'ID',
    align: 'center',
    dataIndex: 'id',
    customRender: ({ text, record }) => {
      // 调试:检查ID值和原始记录
      console.log(`ID渲染 - 值: ${text}, 记录:`, record);

      // 如果ID为空,显示详细的调试信息
      if (!text || text === 'ID-未找到') {
        return h('div', { style: 'color: #f50; cursor: help;', title: '点击查看详情' }, [
          h('span', { style: 'font-weight: bold;' }, 'ID缺失'),
          h('div', { style: 'font-size: 10px; margin-top: 4px;' }, `字段: ${Object.keys(record._raw || {}).join(', ')}`),
        ]);
      }

      return h('span', { style: 'font-family: monospace' }, text);
    },
  },*/
  /*{
    title: '文件名称',
    align: 'center',
    dataIndex: 'text',
  },*/
  {
    title: '文档名称',
    align: 'center',
    dataIndex: 'docName',
    width: 180,
    customRender: ({ record }) => {
      return renderMetadataField(record, 'docName');
    },
  },
  {
    title: '文件内容',
    align: 'center',
    dataIndex: 'text',
  },
  {
    title: '知识库名称',
    align: 'center',
    dataIndex: 'knowledgeName',
    width: 150,
    /*customRender: ({ record }) => {
      return renderMetadataField(record, 'knowledgeId');
    },*/
  } /*
  {
    title: '文档名称',
    align: 'center',
    dataIndex: 'docName',
    width: 180,
    customRender: ({ record }) => {
      return renderMetadataField(record, 'docName');
    },
  },
  {
    title: '文档ID',
    align: 'center',
    dataIndex: 'docId',
    width: 150,
    customRender: ({ record }) => {
      return renderMetadataField(record, 'docId');
    },
  },
  {
    title: '索引位置',
    align: 'center',
    dataIndex: 'index',
    width: 100,
    customRender: ({ record }) => {
      return renderMetadataField(record, 'index');
    },
  },
  {
    title: 'metadata',
    align: 'center',
    dataIndex: 'metadata',
    customRender: ({ text }) => {
      if (!text) return '-';

      try {
        // 尝试解析JSON
        const metadata = typeof text === 'string' ? JSON.parse(text) : text;

        // 创建元数据标签
        const tags = Object.entries(metadata).map(([key, value]) => h(tags, { color: 'blue' }, `${key}: ${value}`));

        return h(
          Tooltip,
          {
            title: h('pre', JSON.stringify(metadata, null, 2)),
            overlayStyle: { maxWidth: '600px' },
          },
          () => h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' }, tags)
        );
      } catch (e) {
        // 无法解析时显示原始文本
        const displayText = typeof text === 'string' ? text : JSON.stringify(text);
        const shortText = displayText.length > 20 ? displayText.substring(0, 20) + '...' : displayText;

        return h(Tooltip, { title: displayText }, () => h('span', shortText));
      }
    },
  },*/,
];

function renderMetadataField(record: any, fieldName: string) {
  if (!record.metadata) return '-';

  try {
    // 尝试解析metadata
    const metadata = typeof record.metadata === 'string' ? JSON.parse(record.metadata) : record.metadata;

    // 获取字段值
    const value = metadata[fieldName];

    if (value === undefined || value === null) {
      return h('span', { style: 'color: #999' }, '无');
    }
    // 根据字段类型渲染
    switch (fieldName) {
      case 'knowledgeId':
      case 'docId':
        return h('span', { style: 'font-family: monospace' }, value);

      case 'index':
        return h('span', { style: 'font-weight: bold' }, value);

      default:
        return h('span', value);
    }
  } catch (e) {
    return h('span', { style: 'color: #f50' }, '解析错误');
  }
}

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '文本名称',
    field: 'docName',
    component: 'Input',
  },
  {
    label: '文本内容',
    field: 'text',
    component: 'Input',
  },
  // 新增知识库选择字段
  {
    label: '知识库',
    field: 'knowledgeId', // 注意:这里使用knowledgeId作为字段名
    component: 'ApiSelect',
    componentProps: {
      api: listknowledge, // 使用知识库接口
      labelField: 'name', // 显示知识库名称
      valueField: 'id', // 提交知识库ID
      showSearch: true,
      filterOption: (input: string, option: any) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '文件名称',
    field: 'docName', // 使用新的字段名
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入文档名称',
    },
  },
  {
    label: '文本内容',
    field: 'text',
    required: true,
    component: 'JEditor',
  },
  // 新增知识库选择字段
  {
    label: '知识库',
    field: 'knowledgeId', // 注意:这里使用knowledgeId作为字段名
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: listknowledge, // 使用知识库接口
      labelField: 'name', // 显示知识库名称
      valueField: 'id', // 提交知识库ID
      showSearch: true,
      filterOption: (input: string, option: any) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
  },
  {
    label: '',
    field: 'docId',
    component: 'Input',
    show: false,
  },
  // TODO 主键隐藏字段,目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: { title: 'name', order: 0, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchemaqrtz_fired_triggers
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据,这里需要单独处理formSchema
  return formSchema;
}