فهرست منبع

优化SqlSugarSetup与配置文件一致数据库类型和优化异常日志管理

兰聪 3 سال پیش
والد
کامیت
6a4e5a9b5c

+ 3 - 3
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -43,14 +43,14 @@ public static class SqlSugarSetup
                         Console.ForegroundColor = ConsoleColor.White;
                     if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase))
                         Console.ForegroundColor = ConsoleColor.Blue;
-                    Console.WriteLine("【" + DateTime.Now + "——执行SQL】\r\n" + UtilMethods.GetSqlString(DbType.MySql, sql, pars) + "\r\n");
+                    Console.WriteLine("【" + DateTime.Now + "——执行SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, sql, pars) + "\r\n");
                     App.PrintToMiniProfiler("SqlSugar", "Info", sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                 };
                 dbProvider.Aop.OnError = (ex) =>
                 {
                     Console.ForegroundColor = ConsoleColor.Red;
                     var pars = db.Utilities.SerializeObject(((SugarParameter[])ex.Parametres).ToDictionary(it => it.ParameterName, it => it.Value));
-                    Console.WriteLine("【" + DateTime.Now + "——错误SQL】\r\n" + UtilMethods.GetSqlString(DbType.MySql, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
+                    Console.WriteLine("【" + DateTime.Now + "——错误SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
                     App.PrintToMiniProfiler("SqlSugar", "Error", $"{ex.Message}{Environment.NewLine}{ex.Sql}{pars}{Environment.NewLine}");
                 };
 
@@ -107,7 +107,7 @@ public static class SqlSugarSetup
                         BusinessData = JsonConvert.SerializeObject(u.BusinessData),
                         // 枚举(insert、update、delete)
                         DiffType = u.DiffType.ToString(),
-                        Sql = UtilMethods.GetSqlString(DbType.MySql, u.Sql, u.Parameters),
+                        Sql = UtilMethods.GetSqlString(config.DbType, u.Sql, u.Parameters),
                         Parameters = JsonConvert.SerializeObject(u.Parameters),
                         Duration = u.Time == null ? 0 : (long)u.Time.Value.TotalMilliseconds
                     };

+ 69 - 0
Vben2/src/views/sys/admin/log/exlog/ExlogDrawer.vue

@@ -0,0 +1,69 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    @register="registerDrawer"
+    showFooter
+    title="异常日志"
+    width="800px"
+    @ok="handleSubmit"
+  >
+    <BasicForm @register="registerForm" />
+  </BasicDrawer>
+</template>
+<script lang="ts">
+  import { defineComponent, ref, unref } from 'vue';
+  import { BasicForm, useForm } from '/@/components/Form/index';
+  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
+
+  import { formSchema } from './exlog.data';
+
+  export default defineComponent({
+    name: 'ExlogDrawer',
+    components: { BasicDrawer, BasicForm },
+    emits: ['success', 'register'],
+    setup(_, { emit }) {
+      const isUpdate = ref(true);
+      let rowId: number;
+
+      const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
+        labelWidth: 90,
+        schemas: formSchema,
+        showActionButtonGroup: false,
+      });
+
+      const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
+        resetFields();
+        setDrawerProps({ confirmLoading: false });
+        isUpdate.value = !!data?.isUpdate;
+
+        if (unref(isUpdate)) {
+          rowId = data.record.id;
+          setFieldsValue({
+            ...data.record,
+          });
+        }
+      });
+
+      async function handleSubmit() {
+        try {
+          const values = await validate();
+          setDrawerProps({ confirmLoading: true });
+
+          closeDrawer();
+          emit('success', {
+            isUpdate: unref(isUpdate),
+            values: { ...values, id: rowId },
+          });
+        } finally {
+          setDrawerProps({ confirmLoading: false });
+        }
+      }
+
+      return {
+        registerDrawer,
+        registerForm,
+        handleSubmit,
+      };
+    },
+  });
+</script>

+ 25 - 25
Vben2/src/views/sys/admin/log/exlog/exlog.data.ts

@@ -3,44 +3,29 @@ import { FormSchema } from '/@/components/Table';
 
 export const columns: BasicColumn[] = [
   {
-    title: '账号名称',
-    dataIndex: 'userName',
+    title: '日志名称',
+    dataIndex: 'logName',
     width: 100,
     align: 'left',
   },
   {
-    title: '类名',
-    dataIndex: 'className',
+    title: '日志级别',
+    dataIndex: 'logLevel',
     width: 200,
   },
   {
-    title: '方法名',
-    dataIndex: 'methodName',
+    title: '事件Id',
+    dataIndex: 'eventId',
     width: 200,
   },
   {
-    title: '异常名称',
-    dataIndex: 'exceptionName',
+    title: '日志消息',
+    dataIndex: 'message',
     width: 200,
   },
   {
-    title: '异常信息',
-    dataIndex: 'exceptionMsg',
-    width: 200,
-  },
-  {
-    title: '异常源',
-    dataIndex: 'exceptionSource',
-    width: 200,
-  },
-  {
-    title: '堆栈信息',
-    dataIndex: 'stackTrace',
-    width: 200,
-  },
-  {
-    title: '参数对象',
-    dataIndex: 'paramsObj',
+    title: '异常对象',
+    dataIndex: 'exception',
     width: 200,
   },
   {
@@ -64,3 +49,18 @@ export const searchFormSchema: FormSchema[] = [
     colProps: { span: 8 },
   },
 ];
+
+export const formSchema: FormSchema[] = [
+  {
+    label: '',
+    field: 'message',
+    component: 'InputTextArea',
+    // dynamicDisabled: true,
+    colProps: { span: 24 },
+    componentProps: {
+      placeholder: '',
+      rows: 200,
+      allowClear: false,
+    },
+  },
+];

+ 33 - 4
Vben2/src/views/sys/admin/log/exlog/index.vue

@@ -6,22 +6,36 @@
           清空日志
         </a-button>
       </template>
+      <template #action="{ record }">
+        <TableAction
+          :actions="[
+            {
+              icon: 'ant-design:eye-outlined',
+              label: '查看',
+              onClick: handleView.bind(null, record),
+            },
+          ]"
+        />
+      </template>
     </BasicTable>
+    <ExlogDrawer @register="registerDrawer" />
   </div>
 </template>
 <script lang="ts">
   import { defineComponent } from 'vue';
-  import { BasicTable, useTable } from '/@/components/Table';
+  import { BasicTable, useTable, TableAction } from '/@/components/Table';
   import { usePermission } from '/@/hooks/web/usePermission';
-
+  import { useDrawer } from '/@/components/Drawer';
+  import ExlogDrawer from './ExlogDrawer.vue';
   import { columns, searchFormSchema } from './exlog.data';
   import { getExLogPageList, clearExLog } from '/@/api/sys/admin';
 
   export default defineComponent({
     name: 'ExlogManagement',
-    components: { BasicTable },
+    components: { BasicTable, ExlogDrawer, TableAction },
     setup() {
       const { hasPermission } = usePermission();
+      const [registerDrawer, { openDrawer }] = useDrawer();
       const [registerTable, { reload }] = useTable({
         title: '日志列表',
         api: getExLogPageList,
@@ -39,17 +53,32 @@
         pagination: {
           pageSize: 10,
         },
+        actionColumn: {
+          width: 100,
+          title: '操作',
+          dataIndex: 'action',
+          slots: { customRender: 'action' },
+          fixed: undefined,
+        },
       });
 
       async function handleClear() {
         await clearExLog();
         reload();
       }
-
+      function handleView(record: Recordable) {
+        console.log("handleView")
+        openDrawer(true, {
+          record,
+          isUpdate: true,
+        });
+      }
       return {
         registerTable,
+        registerDrawer,
         handleClear,
         hasPermission,
+        handleView,
       };
     },
   });

+ 1 - 0
Vben2/src/views/sys/admin/log/oplog/oplog.data.ts

@@ -73,6 +73,7 @@ export const formSchema: FormSchema[] = [
     componentProps: {
       placeholder: '',
       rows: 200,
+      allowClear: false,
     },
   },
 ];