3 changed files with 285 additions and 1 deletions
			
			
		@ -0,0 +1,54 @@
					 | 
				
			||||
<template> | 
				
			||||
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> | 
				
			||||
    <BasicForm @register="registerForm" /> | 
				
			||||
  </BasicModal> | 
				
			||||
</template> | 
				
			||||
<script lang="ts" setup name="ConfigModal"> | 
				
			||||
import { ref, computed, unref } from 'vue' | 
				
			||||
import { BasicModal, useModalInner } from '@/components/Modal' | 
				
			||||
import { BasicForm, useForm } from '@/components/Form' | 
				
			||||
import { formSchema } from './config.data' | 
				
			||||
import { createConfig, getConfig, updateConfig } from '@/api/infra/config' | 
				
			||||
 | 
				
			||||
const emit = defineEmits(['success', 'register']) | 
				
			||||
const isUpdate = ref(true) | 
				
			||||
const rowId = ref() | 
				
			||||
 | 
				
			||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ | 
				
			||||
  labelWidth: 100, | 
				
			||||
  baseColProps: { span: 24 }, | 
				
			||||
  schemas: formSchema, | 
				
			||||
  showActionButtonGroup: false, | 
				
			||||
  actionColOptions: { span: 23 } | 
				
			||||
}) | 
				
			||||
 | 
				
			||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { | 
				
			||||
  resetFields() | 
				
			||||
  setModalProps({ confirmLoading: false }) | 
				
			||||
  isUpdate.value = !!data?.isUpdate | 
				
			||||
 | 
				
			||||
  if (unref(isUpdate)) { | 
				
			||||
    const res = await getConfig(data.record.id) | 
				
			||||
    rowId.value = res.id | 
				
			||||
    setFieldsValue({ ...res }) | 
				
			||||
  } | 
				
			||||
}) | 
				
			||||
 | 
				
			||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增配置' : '编辑配置')) | 
				
			||||
 | 
				
			||||
async function handleSubmit() { | 
				
			||||
  try { | 
				
			||||
    const values = await validate() | 
				
			||||
    setModalProps({ confirmLoading: true }) | 
				
			||||
    if (unref(isUpdate)) { | 
				
			||||
      await updateConfig(values) | 
				
			||||
    } else { | 
				
			||||
      await createConfig(values) | 
				
			||||
    } | 
				
			||||
    closeModal() | 
				
			||||
    emit('success') | 
				
			||||
  } finally { | 
				
			||||
    setModalProps({ confirmLoading: false }) | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
</script> | 
				
			||||
@ -0,0 +1,139 @@
					 | 
				
			||||
import { BasicColumn, FormSchema, useRender } from '@/components/Table' | 
				
			||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' | 
				
			||||
 | 
				
			||||
export const columns: BasicColumn[] = [ | 
				
			||||
  { | 
				
			||||
    title: '参数主键', | 
				
			||||
    dataIndex: 'id', | 
				
			||||
    width: 100 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '参数分类', | 
				
			||||
    dataIndex: 'category', | 
				
			||||
    width: 180 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '参数名称', | 
				
			||||
    dataIndex: 'name', | 
				
			||||
    width: 100 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '参数键名', | 
				
			||||
    dataIndex: 'key', | 
				
			||||
    width: 120 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '参数键值', | 
				
			||||
    dataIndex: 'value', | 
				
			||||
    width: 120 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '系统内置', | 
				
			||||
    dataIndex: 'type', | 
				
			||||
    width: 180, | 
				
			||||
    customRender: ({ text }) => { | 
				
			||||
      return useRender.renderDict(text, DICT_TYPE.INFRA_CONFIG_TYPE) | 
				
			||||
    } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '是否可见', | 
				
			||||
    dataIndex: 'visible', | 
				
			||||
    width: 180, | 
				
			||||
    customRender: ({ text }) => { | 
				
			||||
      return useRender.renderTag(text ? '是' : '否') | 
				
			||||
    } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '备注', | 
				
			||||
    dataIndex: 'remark', | 
				
			||||
    width: 180 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '创建时间', | 
				
			||||
    dataIndex: 'createTime', | 
				
			||||
    width: 180, | 
				
			||||
    customRender: ({ text }) => { | 
				
			||||
      return useRender.renderDate(text) | 
				
			||||
    } | 
				
			||||
  } | 
				
			||||
] | 
				
			||||
 | 
				
			||||
export const searchFormSchema: FormSchema[] = [ | 
				
			||||
  { | 
				
			||||
    label: '参数名称', | 
				
			||||
    field: 'name', | 
				
			||||
    component: 'Input', | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '参数键名', | 
				
			||||
    field: 'key', | 
				
			||||
    component: 'Input', | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '系统内置', | 
				
			||||
    field: 'type', | 
				
			||||
    component: 'Select', | 
				
			||||
    componentProps: { | 
				
			||||
      options: getIntDictOptions(DICT_TYPE.INFRA_CONFIG_TYPE) | 
				
			||||
    }, | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '创建时间', | 
				
			||||
    field: 'createTime', | 
				
			||||
    component: 'RangePicker', | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  } | 
				
			||||
] | 
				
			||||
 | 
				
			||||
export const formSchema: FormSchema[] = [ | 
				
			||||
  { | 
				
			||||
    label: '编号', | 
				
			||||
    field: 'id', | 
				
			||||
    show: false, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '参数分类', | 
				
			||||
    field: 'category', | 
				
			||||
    required: true, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '参数名称', | 
				
			||||
    field: 'name', | 
				
			||||
    required: true, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '参数键名', | 
				
			||||
    field: 'key', | 
				
			||||
    required: true, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '参数键值', | 
				
			||||
    field: 'value', | 
				
			||||
    required: true, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '是否可见', | 
				
			||||
    field: 'visible', | 
				
			||||
    component: 'RadioGroup', | 
				
			||||
    defaultValue: 0, | 
				
			||||
    componentProps: { | 
				
			||||
      options: [ | 
				
			||||
        { key: true, label: '是', value: true }, | 
				
			||||
        { key: false, label: '否', value: false } | 
				
			||||
      ] | 
				
			||||
    } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '备注', | 
				
			||||
    field: 'remark', | 
				
			||||
    component: 'InputTextArea' | 
				
			||||
  } | 
				
			||||
] | 
				
			||||
@ -1,3 +1,94 @@
					 | 
				
			||||
<template> | 
				
			||||
  <div>开发中</div> | 
				
			||||
  <div> | 
				
			||||
    <BasicTable @register="registerTable"> | 
				
			||||
      <template #toolbar> | 
				
			||||
        <a-button type="primary" :preIcon="IconEnum.ADD" @click="handleCreate"> {{ t('action.create') }} </a-button> | 
				
			||||
        <a-button type="warning" :preIcon="IconEnum.EXPORT" @click="handleExport"> {{ t('action.export') }} </a-button> | 
				
			||||
      </template> | 
				
			||||
      <template #bodyCell="{ column, record }"> | 
				
			||||
        <template v-if="column.key === 'action'"> | 
				
			||||
          <TableAction | 
				
			||||
            :actions="[ | 
				
			||||
              { icon: IconEnum.EDIT, label: t('action.edit'), onClick: handleEdit.bind(null, record) }, | 
				
			||||
              { | 
				
			||||
                icon: IconEnum.DELETE, | 
				
			||||
                color: 'error', | 
				
			||||
                label: t('action.delete'), | 
				
			||||
                popConfirm: { | 
				
			||||
                  title: t('common.delMessage'), | 
				
			||||
                  placement: 'left', | 
				
			||||
                  confirm: handleDelete.bind(null, record) | 
				
			||||
                } | 
				
			||||
              } | 
				
			||||
            ]" | 
				
			||||
          /> | 
				
			||||
        </template> | 
				
			||||
      </template> | 
				
			||||
    </BasicTable> | 
				
			||||
    <ConfigModal @register="registerModal" @success="reload()" /> | 
				
			||||
  </div> | 
				
			||||
</template> | 
				
			||||
<script lang="ts" setup name="Config"> | 
				
			||||
import { useI18n } from '@/hooks/web/useI18n' | 
				
			||||
import { useMessage } from '@/hooks/web/useMessage' | 
				
			||||
import { useModal } from '@/components/Modal' | 
				
			||||
import ConfigModal from './ConfigModal.vue' | 
				
			||||
import { IconEnum } from '@/enums/appEnum' | 
				
			||||
import { BasicTable, useTable, TableAction } from '@/components/Table' | 
				
			||||
import { getConfigPage, deleteConfig, exportConfig, ConfigExportReqVO } from '@/api/infra/config' | 
				
			||||
import { columns, searchFormSchema } from './config.data' | 
				
			||||
 | 
				
			||||
const { t } = useI18n() | 
				
			||||
const { createConfirm, createMessage } = useMessage() | 
				
			||||
const [registerModal, { openModal }] = useModal() | 
				
			||||
 | 
				
			||||
const [registerTable, { getForm, reload }] = useTable({ | 
				
			||||
  title: '配置中心列表', | 
				
			||||
  api: getConfigPage, | 
				
			||||
  columns, | 
				
			||||
  formConfig: { | 
				
			||||
    labelWidth: 120, | 
				
			||||
    schemas: searchFormSchema | 
				
			||||
  }, | 
				
			||||
  useSearchForm: true, | 
				
			||||
  showTableSetting: true, | 
				
			||||
  showIndexColumn: false, | 
				
			||||
  actionColumn: { | 
				
			||||
    width: 140, | 
				
			||||
    title: t('common.action'), | 
				
			||||
    dataIndex: 'action', | 
				
			||||
    fixed: 'right' | 
				
			||||
  } | 
				
			||||
}) | 
				
			||||
 | 
				
			||||
function handleCreate() { | 
				
			||||
  openModal(true, { | 
				
			||||
    isUpdate: false | 
				
			||||
  }) | 
				
			||||
} | 
				
			||||
 | 
				
			||||
function handleEdit(record: Recordable) { | 
				
			||||
  openModal(true, { | 
				
			||||
    record, | 
				
			||||
    isUpdate: true | 
				
			||||
  }) | 
				
			||||
} | 
				
			||||
 | 
				
			||||
async function handleExport() { | 
				
			||||
  createConfirm({ | 
				
			||||
    title: t('common.exportTitle'), | 
				
			||||
    iconType: 'warning', | 
				
			||||
    content: t('common.exportMessage'), | 
				
			||||
    async onOk() { | 
				
			||||
      await exportConfig(getForm().getFieldsValue() as ConfigExportReqVO) | 
				
			||||
      createMessage.success(t('common.exportSuccessText')) | 
				
			||||
    } | 
				
			||||
  }) | 
				
			||||
} | 
				
			||||
 | 
				
			||||
async function handleDelete(record: Recordable) { | 
				
			||||
  await deleteConfig(record.id) | 
				
			||||
  createMessage.success(t('common.delSuccessText')) | 
				
			||||
  reload() | 
				
			||||
} | 
				
			||||
</script> | 
				
			||||
					 | 
				
			||||
		Reference in new issue