config.ts 1.97 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { findDictItemByCode } from '/@/api/system/dict';

// 表格配置
export const columns: BasicColumn[] = [
  {
    title: '接口名称',
    dataIndex: 'name',
    width: 80,
  },
  {
    title: '请求方式',
    dataIndex: 'method',
    width: 120,
  },
  {
    title: '接口内容',
    dataIndex: 'content',
    width: 120,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    customRender: ({ record }) => {
      const status = record.status;
      const color = status == 0 ? 'green' : 'red';
      const text = status == 0 ? '发布' : '未发布';
      return h(Tag, { color: color }, () => text);
    },
  },
];

//模拟数据
export const list = [
  {
    name: '传感器趋势图',
    method: 'get',
    content: '/api/sensor',
    status: 0,
  },
  {
    name: '报警器趋势图',
    method: 'get',
    content: '/api/alarm',
    status: 1,
  },
];

//表单配置
// 新增编辑配置
export const schemas: FormSchema[] = [
  {
    field: 'name',
    label: '接口名称',
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 64,
      placeholder: '请输入接口名称',
    },
  },
  {
    field: 'address',
    label: '接口地址',
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 64,
      placeholder: '请输入接口地址',
    },
  },
  {
    field: 'method',
    label: '选择方式',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 24 },
    componentProps: {
      placeholder: '请选择选择方式',
      api: findDictItemByCode,
      params: {
        dictCode: 'dataview_select_methods',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
];