作者 dong

日志界面

  1 +import { defHttp } from '/@/utils/http/axios';
  2 +import { useMessage } from '/@/hooks/web/useMessage';
  3 +
  4 +const { createConfirm } = useMessage();
  5 +
  6 +enum Api {
  7 + list = '/airaglog/airagLog/list',
  8 + save = '/airaglog/airagLog/add',
  9 + saveToQuestionLibrary = '/airaglog/airagLog/saveToQuestionLibrary',
  10 + edit = '/airaglog/airagLog/edit',
  11 + deleteOne = '/airaglog/airagLog/delete',
  12 + deleteBatch = '/airaglog/airagLog/deleteBatch',
  13 + importExcel = '/airaglog/airagLog/importExcel',
  14 + exportXls = '/airaglog/airagLog/exportXls',
  15 +}
  16 +/**
  17 + * 导出api
  18 + * @param params
  19 + */
  20 +export const getExportUrl = Api.exportXls;
  21 +/**
  22 + * 导入api
  23 + */
  24 +export const getImportUrl = Api.importExcel;
  25 +/**
  26 + * 列表接口
  27 + * @param params
  28 + */
  29 +export const list = (params) => defHttp.get({ url: Api.list, params });
  30 +export const saveToQuestionLibrary = (params) =>
  31 + defHttp.post({
  32 + url: Api.saveToQuestionLibrary,
  33 + params,
  34 + headers: {
  35 + 'Content-Type': 'application/json',
  36 + },
  37 + });
  38 +/**
  39 + * 删除单个
  40 + */
  41 +export const deleteOne = (params, handleSuccess) => {
  42 + return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
  43 + handleSuccess();
  44 + });
  45 +};
  46 +/**
  47 + * 批量删除
  48 + * @param params
  49 + */
  50 +export const batchDelete = (params, handleSuccess) => {
  51 + createConfirm({
  52 + iconType: 'warning',
  53 + title: '确认删除',
  54 + content: '是否删除选中数据',
  55 + okText: '确认',
  56 + cancelText: '取消',
  57 + onOk: () => {
  58 + return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
  59 + handleSuccess();
  60 + });
  61 + },
  62 + });
  63 +};
  64 +/**
  65 + * 保存或者更新
  66 + * @param params
  67 + */
  68 +export const saveOrUpdate = (params, isUpdate) => {
  69 + const url = isUpdate ? Api.saveToQuestionLibrary : Api.save;
  70 + return defHttp.post({ url: url, params });
  71 +};
  1 +import { BasicColumn } from '/@/components/Table';
  2 +import { FormSchema } from '/@/components/Table';
  3 +//列表数据
  4 +export const columns: BasicColumn[] = [
  5 + {
  6 + title: '问题',
  7 + align: 'center',
  8 + dataIndex: 'question',
  9 + },
  10 + {
  11 + title: '回答',
  12 + align: 'center',
  13 + dataIndex: 'answer',
  14 + },
  15 + {
  16 + title: '模型名称',
  17 + align: 'center',
  18 + dataIndex: 'name',
  19 + },
  20 +];
  21 +//查询数据
  22 +export const searchFormSchema: FormSchema[] = [
  23 + {
  24 + label: '问题',
  25 + field: 'question',
  26 + component: 'JInput',
  27 + },
  28 + {
  29 + label: '模型ID',
  30 + field: 'modelId',
  31 + component: 'Input',
  32 + //colProps: {span: 6},
  33 + },
  34 +];
  35 +//表单数据
  36 +export const formSchema: FormSchema[] = [
  37 + {
  38 + label: '问题',
  39 + field: 'question',
  40 + component: 'Input',
  41 + },
  42 + {
  43 + label: '回答',
  44 + field: 'answer',
  45 + component: 'Input',
  46 + },
  47 + {
  48 + label: '模型名称',
  49 + field: 'name',
  50 + component: 'Input',
  51 + },
  52 + // TODO 主键隐藏字段,目前写死为ID
  53 + {
  54 + label: '',
  55 + field: 'id',
  56 + component: 'Input',
  57 + show: false,
  58 + },
  59 +];
  60 +
  61 +// 高级查询数据
  62 +export const superQuerySchema = {
  63 + question: { title: '问题', order: 0, view: 'text', type: 'string' },
  64 + answer: { title: '回答', order: 1, view: 'text', type: 'string' },
  65 + modelId: { title: '模型ID', order: 2, view: 'text', type: 'string' },
  66 +};
  67 +
  68 +/**
  69 + * 流程表单调用这个方法获取formSchema
  70 + * @param param
  71 + */
  72 +export function getBpmFormSchema(_formData): FormSchema[] {
  73 + // 默认和原始表单保持一致 如果流程中配置了权限数据,这里需要单独处理formSchema
  74 + return formSchema;
  75 +}
  1 +<template>
  2 + <div>
  3 + <!--引用表格-->
  4 + <BasicTable @register="registerTable" :rowSelection="rowSelection">
  5 + <!--插槽:table标题-->
  6 + <template #tableTitle>
  7 + <a-button type="primary" v-auth="'airaglog:airag_log:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
  8 + <a-button type="primary" v-auth="'airaglog:airag_log:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
  9 + <j-upload-button type="primary" v-auth="'airaglog:airag_log:importExcel'" preIcon="ant-design:import-outlined" @click="onImportXls"
  10 + >导入</j-upload-button
  11 + >
  12 + <a-dropdown v-if="selectedRowKeys.length > 0">
  13 + <template #overlay>
  14 + <a-menu>
  15 + <a-menu-item key="1" @click="batchHandleDelete">
  16 + <Icon icon="ant-design:delete-outlined" />
  17 + 删除
  18 + </a-menu-item>
  19 + </a-menu>
  20 + </template>
  21 + <a-button v-auth="'airaglog:airag_log:deleteBatch'"
  22 + >批量操作
  23 + <Icon icon="mdi:chevron-down" />
  24 + </a-button>
  25 + </a-dropdown>
  26 + <!-- 高级查询 -->
  27 + <super-query :config="superQueryConfig" @search="handleSuperQuery" />
  28 + </template>
  29 + <!--操作栏-->
  30 + <template #action="{ record }">
  31 + <TableAction :actions="getTableAction(record)" />
  32 + </template>
  33 + <!--字段回显插槽-->
  34 + <template #bodyCell="{ column, record, index, text }"> </template>
  35 + </BasicTable>
  36 + <!-- 表单区域 -->
  37 + <AiragLogModal @register="registerModal" @success="handleSuccess" />
  38 + </div>
  39 +</template>
  40 +
  41 +<script lang="ts" name="airaglog-airagLog" setup>
  42 + import { ref, reactive } from 'vue';
  43 + import { BasicTable, TableAction } from '/@/components/Table';
  44 + import { useModal } from '/@/components/Modal';
  45 + import { useListPage } from '/@/hooks/system/useListPage';
  46 + import AiragLogModal from './components/AiragLogModal.vue';
  47 + import { columns, searchFormSchema, superQuerySchema } from './AiragLog.data';
  48 + import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './AiragLog.api';
  49 + import { useUserStore } from '/@/store/modules/user';
  50 + import { defHttp } from '@/utils/http/axios';
  51 + const queryParam = reactive<any>({});
  52 + const checkedKeys = ref<Array<string | number>>([]);
  53 + const userStore = useUserStore();
  54 + //注册model
  55 + const [registerModal, { openModal }] = useModal();
  56 + //注册table数据
  57 + const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  58 + tableProps: {
  59 + title: '日志管理',
  60 + api: list,
  61 + columns,
  62 + canResize: false,
  63 + formConfig: {
  64 + //labelWidth: 120,
  65 + schemas: searchFormSchema,
  66 + autoSubmitOnEnter: true,
  67 + showAdvancedButton: true,
  68 + fieldMapToNumber: [],
  69 + fieldMapToTime: [],
  70 + },
  71 + actionColumn: {
  72 + width: 120,
  73 + fixed: 'right',
  74 + },
  75 + beforeFetch: (params) => {
  76 + return Object.assign(params, queryParam);
  77 + },
  78 + },
  79 + exportConfig: {
  80 + name: '日志管理',
  81 + url: getExportUrl,
  82 + params: queryParam,
  83 + },
  84 + importConfig: {
  85 + url: getImportUrl,
  86 + success: handleSuccess,
  87 + },
  88 + });
  89 +
  90 + const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  91 +
  92 + // 高级查询配置
  93 + const superQueryConfig = reactive(superQuerySchema);
  94 +
  95 + /**
  96 + * 高级查询事件
  97 + */
  98 + function handleSuperQuery(params) {
  99 + Object.keys(params).map((k) => {
  100 + queryParam[k] = params[k];
  101 + });
  102 + reload();
  103 + }
  104 + /**
  105 + * 新增事件
  106 + */
  107 + function handleAdd() {
  108 + openModal(true, {
  109 + isUpdate: false,
  110 + showFooter: true,
  111 + });
  112 + }
  113 + /**
  114 + * 编辑事件
  115 + */
  116 + function handleEdit(record: Recordable) {
  117 + openModal(true, {
  118 + record,
  119 + isUpdate: true,
  120 + showFooter: true,
  121 + });
  122 + }
  123 + /**
  124 + * 详情
  125 + */
  126 + function handleDetail(record: Recordable) {
  127 + openModal(true, {
  128 + record,
  129 + isUpdate: true,
  130 + showFooter: false,
  131 + });
  132 + }
  133 + /**
  134 + * 删除事件
  135 + */
  136 + async function handleDelete(record) {
  137 + await deleteOne({ id: record.id }, handleSuccess);
  138 + }
  139 + /**
  140 + * 批量删除事件
  141 + */
  142 + async function batchHandleDelete() {
  143 + await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  144 + }
  145 + /**
  146 + * 成功回调
  147 + */
  148 + function handleSuccess() {
  149 + (selectedRowKeys.value = []) && reload();
  150 + }
  151 + /**
  152 + * 操作栏
  153 + */
  154 + function getTableAction(record) {
  155 + return [
  156 + {
  157 + label: '存入问题库',
  158 + onClick: () => handleSaveToQuestionLibrary(record),
  159 + auth: 'airaglog:airag_log:saveToQuestionLibrary',
  160 + },
  161 + ];
  162 + }
  163 + /**
  164 + * 存入问题库事件
  165 + */
  166 + async function handleSaveToQuestionLibrary(record) {
  167 + openModal(true, {
  168 + record,
  169 + isUpdate: true,
  170 + showFooter: true,
  171 + showSaveButton: true,
  172 + onConfirm: async (record) => {
  173 + try {
  174 + await defHttp.post({ url: '/airaglog/airagLog/saveToQuestionLibrary', params: record });
  175 + // 刷新列表
  176 + reload();
  177 + } catch (error) {
  178 + console.error('存入问题库失败', error);
  179 + }
  180 + },
  181 + });
  182 + }
  183 + /**
  184 + * 下拉操作栏
  185 + */
  186 + function getDropDownAction(record) {
  187 + return [
  188 + {
  189 + label: '详情',
  190 + onClick: handleDetail.bind(null, record),
  191 + },
  192 + {
  193 + label: '删除',
  194 + popConfirm: {
  195 + title: '是否确认删除',
  196 + confirm: handleDelete.bind(null, record),
  197 + placement: 'topLeft',
  198 + },
  199 + auth: 'airaglog:airag_log:delete',
  200 + },
  201 + ];
  202 + }
  203 +</script>
  204 +
  205 +<style lang="less" scoped>
  206 + :deep(.ant-picker),
  207 + :deep(.ant-input-number) {
  208 + width: 100%;
  209 + }
  210 +</style>
  1 +<template>
  2 + <div style="min-height: 400px">
  3 + <BasicForm @register="registerForm" />
  4 + <div style="width: 100%; text-align: center" v-if="!formDisabled">
  5 + <a-button @click="submitForm" pre-icon="ant-design:check" type="primary">提 交</a-button>
  6 + </div>
  7 + </div>
  8 +</template>
  9 +
  10 +<script lang="ts">
  11 + import { BasicForm, useForm } from '/@/components/Form/index';
  12 + import { computed, defineComponent } from 'vue';
  13 + import { defHttp } from '/@/utils/http/axios';
  14 + import { propTypes } from '/@/utils/propTypes';
  15 + import { getBpmFormSchema } from '../AiragLog.data';
  16 + import { saveOrUpdate } from '../AiragLog.api';
  17 +
  18 + export default defineComponent({
  19 + name: 'AiragLogForm',
  20 + components: {
  21 + BasicForm,
  22 + },
  23 + props: {
  24 + formData: propTypes.object.def({}),
  25 + formBpm: propTypes.bool.def(true),
  26 + },
  27 + setup(props) {
  28 + const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({
  29 + labelWidth: 150,
  30 + schemas: getBpmFormSchema(props.formData),
  31 + showActionButtonGroup: false,
  32 + baseColProps: { span: 24 },
  33 + });
  34 +
  35 + const formDisabled = computed(() => {
  36 + if (props.formData.disabled === false) {
  37 + return false;
  38 + }
  39 + return true;
  40 + });
  41 +
  42 + let formData = {};
  43 + const queryByIdUrl = '/airaglog/airagLog/queryById';
  44 + async function initFormData() {
  45 + let params = { id: props.formData.dataId };
  46 + const data = await defHttp.get({ url: queryByIdUrl, params });
  47 + formData = { ...data };
  48 + //设置表单的值
  49 + await setFieldsValue(formData);
  50 + //默认是禁用
  51 + await setProps({ disabled: formDisabled.value });
  52 + }
  53 +
  54 + async function submitForm() {
  55 + let data = getFieldsValue();
  56 + let params = Object.assign({}, formData, data);
  57 + console.log('表单数据', params);
  58 + await saveOrUpdate(params, true);
  59 + }
  60 +
  61 + initFormData();
  62 +
  63 + return {
  64 + registerForm,
  65 + formDisabled,
  66 + submitForm,
  67 + };
  68 + },
  69 + });
  70 +</script>
  1 +<template>
  2 + <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
  3 + <BasicForm @register="registerForm" name="AiragLogForm" />
  4 + <template #footer>
  5 + <!-- 根据 showSaveButton 决定显示哪个按钮 -->
  6 + <template v-if="showSaveButton">
  7 + <a-button @click="handleSubmit">存入</a-button>
  8 + </template>
  9 + <template v-else>
  10 + <a-button @click="handleSubmit">确认</a-button>
  11 + </template>
  12 + <a-button @click="closeModal">取消</a-button>
  13 + </template>
  14 + </BasicModal>
  15 +</template>
  16 +
  17 +<script lang="ts" setup>
  18 + import { ref, computed, unref } from 'vue';
  19 + import { BasicModal, useModalInner } from '/@/components/Modal';
  20 + import { BasicForm, useForm } from '/@/components/Form/index';
  21 + import { formSchema } from '../AiragLog.data';
  22 + import { saveOrUpdate } from '../AiragLog.api';
  23 + // Emits声明
  24 + const emit = defineEmits(['register', 'success']);
  25 + const isUpdate = ref(true);
  26 + const isDetail = ref(false);
  27 + const showSaveButton = ref(true);
  28 + const props = defineProps({
  29 + onConfirm: {
  30 + type: Function,
  31 + default: null,
  32 + },
  33 + });
  34 + //表单配置
  35 + const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
  36 + labelWidth: 150,
  37 + schemas: formSchema,
  38 + showActionButtonGroup: false,
  39 + baseColProps: { span: 24 },
  40 + });
  41 + //表单赋值
  42 + const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  43 + //重置表单
  44 + await resetFields();
  45 + setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
  46 + isUpdate.value = !!data?.isUpdate;
  47 + isDetail.value = !!data?.showFooter;
  48 + if (unref(isUpdate)) {
  49 + //表单赋值
  50 + await setFieldsValue({
  51 + ...data.record,
  52 + });
  53 + }
  54 + // 隐藏底部时禁用整个表单
  55 + setProps({ disabled: !data?.showFooter });
  56 + });
  57 + //设置标题
  58 + const title = computed(() => (!unref(isUpdate) ? '新增' : !unref(isDetail) ? '详情' : '编辑'));
  59 + //表单提交事件
  60 + async function handleSubmit(v) {
  61 + try {
  62 + let values = await validate();
  63 + setModalProps({ confirmLoading: true });
  64 + if (props.onConfirm) {
  65 + await props.onConfirm(values);
  66 + } else {
  67 + //提交表单
  68 + await saveOrUpdate(values, isUpdate.value);
  69 + }
  70 + //关闭弹窗
  71 + closeModal();
  72 + //刷新列表
  73 + emit('success');
  74 + } catch ({ errorFields }) {
  75 + if (errorFields) {
  76 + const firstField = errorFields[0];
  77 + if (firstField) {
  78 + scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
  79 + }
  80 + }
  81 + return Promise.reject(errorFields);
  82 + } finally {
  83 + setModalProps({ confirmLoading: false });
  84 + }
  85 + }
  86 +
  87 + async function handleSave() {
  88 + await handleSubmit();
  89 + }
  90 +</script>
  91 +
  92 +<style lang="less" scoped>
  93 + /** 时间和数字输入框样式 */
  94 + :deep(.ant-input-number) {
  95 + width: 100%;
  96 + }
  97 +
  98 + :deep(.ant-calendar-picker) {
  99 + width: 100%;
  100 + }
  101 +</style>