Forráskód Böngészése

fix: 三大模块bug修复

Tong 2 éve
szülő
commit
a30ae535df

+ 21 - 0
src/utils/validate.ts

@@ -0,0 +1,21 @@
+// 邮箱验证
+export async function validateEmail(val: string) {
+  const reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
+  return !reg.test(val) ? true : false;
+}
+
+/**
+ 验证 4至16位的字母+数字 
+ */
+export function validateUserName(value) {
+  const reg = /^[a-zA-Z0-9]{4,16}$/;
+  return !reg.test(value) ? true : false;
+}
+
+/**
+ 验证字母+数字 
+ */
+export function validateStr(value) {
+  const reg = /^[A-Za-z0-9]+$/;
+  return !reg.test(value) ? true : false;
+}

+ 111 - 0
src/views/sys/sysConstant/ConstantConfig/data.ts

@@ -0,0 +1,111 @@
+import { DescItem } from '/@/components/Description';
+import { BasicColumn, FormSchema } from '/@/components/Table';
+
+export const columns: BasicColumn[] = [
+  {
+    title: '常量名称',
+    dataIndex: 'name',
+  },
+  {
+    title: '常量类型',
+    dataIndex: 'type',
+  },
+  {
+    title: '常量编码',
+    dataIndex: 'code',
+  },
+  {
+    title: '目录',
+    dataIndex: 'cateid',
+  },
+];
+
+// 表单列定义
+export const searchFormSchema: FormSchema[] = [
+  {
+    label: '常量名称',
+    field: 'name',
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入常量名称',
+    },
+  },
+  {
+    label: '常量编码',
+    field: 'code',
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入常量编码',
+    },
+  },
+];
+// 表单新增编辑
+export const dataFormSchema: FormSchema[] = [
+  {
+    label: '常量名称',
+    field: 'name',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入常量名称',
+    },
+  },
+  {
+    label: '常量类型',
+    field: 'type',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入常量类型',
+    },
+  },
+  {
+    label: '常量编码',
+    field: 'code',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入常量编码',
+    },
+  },
+  {
+    label: '目录',
+    field: 'cateid',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入目录id',
+    },
+  },
+  {
+    label: '备注',
+    field: 'remark',
+    component: 'InputTextArea',
+    componentProps: {
+      placeholder: '请输入备注',
+    },
+  },
+];
+// 表单详情查看
+export const viewSchema: DescItem[] = [
+  {
+    label: '常量名称',
+    field: 'name',
+  },
+  {
+    label: '常量类型',
+    field: 'type',
+  },
+  {
+    label: '备注',
+    field: 'remark',
+  },
+  {
+    label: '常量编码',
+    field: 'code',
+  },
+  {
+    label: '目录id',
+    field: 'cateid',
+  },
+];

+ 71 - 0
src/views/sys/sysConstant/ConstantConfig/formDrawer.vue

@@ -0,0 +1,71 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    destroyOnClose
+    @register="registerDrawer"
+    :title="getTitle"
+    :width="width"
+    @ok="handleSubmit"
+    :showFooter="true"
+  >
+    <BasicForm @register="registerForm" layout="vertical" />
+  </BasicDrawer>
+</template>
+<script lang="ts" setup>
+  import { ref, computed, unref } from 'vue';
+  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
+  import { BasicForm, useForm } from '/@/components/Form';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { dataFormSchema } from './data';
+
+  import { sysConfigAdd, sysConfigEdit, sysConfigDetail } from '/@/api/sys/sysConstantConfig';
+
+  const emit = defineEmits(['success', 'register']);
+
+  const getTitle = computed(() => (!unref(isUpdate) ? '新增常量配置' : '编辑常量配置'));
+  const width = '45%';
+  const isUpdate = ref(false);
+  const rowId = ref();
+
+  const { createMessage } = useMessage();
+  const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
+    labelWidth: 100,
+    schemas: dataFormSchema,
+    showActionButtonGroup: false,
+    actionColOptions: {
+      span: 23,
+    },
+  });
+  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async data => {
+    await resetFields();
+    setDrawerProps({ confirmLoading: false });
+    isUpdate.value = !!data?.isUpdate;
+
+    if (unref(isUpdate)) {
+      const resData = await sysConfigDetail(data.record.id);
+      rowId.value = resData.id;
+      await setFieldsValue({
+        ...resData,
+      });
+    }
+  });
+
+  // 提交按钮事件
+  async function handleSubmit() {
+    try {
+      const values = await validate();
+      setDrawerProps({ confirmLoading: true });
+      !unref(isUpdate)
+        ? await sysConfigAdd({ ...values })
+        : await sysConfigEdit({ ...values, id: rowId.value });
+      !unref(isUpdate) ? createMessage.success('新增成功!') : createMessage.success('编辑成功!');
+      closeDrawer();
+      emit('success', {
+        isUpdate: unref(isUpdate),
+        values: { ...values, id: rowId.value },
+      });
+    } finally {
+      setDrawerProps({ confirmLoading: false });
+    }
+  }
+</script>

+ 186 - 0
src/views/sys/sysConstant/ConstantConfig/index.vue

@@ -0,0 +1,186 @@
+<template>
+  <div>
+    <BasicTable @register="registerTable">
+      <template #bodyCell="{ column, record }">
+        <template v-if="column.key === 'action'">
+          <TableAction
+            :actions="[
+              {
+                auth: 'constant:config:query',
+                icon: 'icon-eye|iconfont',
+                tooltip: '查看',
+                label: '查看',
+                onClick: handleView.bind(null, record),
+              },
+              {
+                auth: 'constant:config:edit',
+                icon: 'icon-edit|iconfont',
+                tooltip: '编辑',
+                label: '编辑',
+                onClick: handleEdit.bind(null, record),
+              },
+              {
+                auth: 'constant:config:remove',
+                icon: 'icon-delete|iconfont',
+                tooltip: '删除',
+                label: '删除',
+                color: 'error',
+                popConfirm: {
+                  title: '是否确认删除',
+                  placement: 'left',
+                  confirm: handleDelete.bind(null, record),
+                },
+              },
+            ]"
+          />
+        </template>
+      </template>
+      <template #toolbar>
+        <Button
+          v-auth="['constant:config:add']"
+          type="primary"
+          @click="handleCreate"
+          preIcon="icon-plus|iconfont"
+        >
+          新增
+        </Button>
+        <Button
+          v-auth="['constant:config:remove']"
+          type="primary"
+          danger
+          @click="handleDelete(null)"
+          preIcon="icon-delete|iconfont"
+        >
+          批量删除
+        </Button>
+      </template>
+    </BasicTable>
+    <FormDrawer @register="registerDrawer" @success="handleSuccess" />
+    <ViewDrawer @register="registerDrawerView" @success="handleSuccess" />
+  </div>
+</template>
+<script lang="ts" setup>
+  import { onBeforeMount, ref } from 'vue';
+  import { Button } from '/@/components/Button';
+
+  import { BasicTable, useTable, TableAction } from '/@/components/Table';
+
+  // import { useModal } from '/@/components/Modal';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import FormDrawer from './formDrawer.vue';
+  import ViewDrawer from './viewDrawer.vue';
+  import { columns, searchFormSchema } from './data';
+
+  import { sysConfigQueryPage, sysConfigRemove } from '/@/api/sys/sysConstantConfig';
+  import { useDrawer } from '/@/components/Drawer';
+
+  onBeforeMount(async () => {});
+
+  const { createConfirm, createMessage } = useMessage();
+  // const [registerModal, { openModal }] = useModal();
+  const [registerDrawer, { openDrawer }] = useDrawer();
+  const [registerDrawerView, { openDrawer: openDrawerView }] = useDrawer();
+
+  const tableSort = ref([
+    {
+      field: 'create_time',
+      direction: 'DESC',
+    },
+  ]) as any;
+
+  const [registerTable, { reload, getSelectRowKeys }] = useTable({
+    title: ' ',
+    api: sysConfigQueryPage,
+    rowKey: 'id',
+    columns,
+    showIndexColumn: true,
+    rowSelection: { type: 'checkbox' },
+    formConfig: {
+      labelWidth: 120,
+      schemas: searchFormSchema,
+      autoSubmitOnEnter: true,
+      baseColProps: { xs: 24, sm: 12, md: 12, lg: 8 },
+      resetButtonOptions: {
+        preIcon: 'icon-delete|iconfont',
+      },
+      submitButtonOptions: {
+        preIcon: 'icon-search|iconfont',
+      },
+    },
+    useSearchForm: true,
+    bordered: true,
+    actionColumn: {
+      width: 200,
+      title: '操作',
+      dataIndex: 'action',
+    },
+    beforeFetch: handleBeforeFetch,
+    sortFn: handleSortFn,
+  });
+  // 详情按钮事件
+  function handleView(record: Recordable) {
+    console.log(record);
+    openDrawerView(true, {
+      record,
+    });
+  }
+
+  // 新增按钮事件
+  function handleCreate() {
+    openDrawer(true, {
+      isUpdate: false,
+    });
+  }
+
+  // 编辑按钮事件
+  function handleEdit(record: Recordable) {
+    openDrawer(true, {
+      record,
+      isUpdate: true,
+    });
+  }
+
+  // 删除按钮事件
+  async function handleDelete(record: Recordable) {
+    if (record) {
+      await sysConfigRemove([record.id]);
+      createMessage.success('删除成功!');
+      await reload();
+    } else {
+      createConfirm({
+        content: '你确定要删除?',
+        iconType: 'warning',
+        onOk: async () => {
+          const keys = getSelectRowKeys();
+          await sysConfigRemove(keys);
+          createMessage.success('删除成功!');
+          await reload();
+        },
+      });
+    }
+  }
+  // 表格点击字段排序
+  function handleSortFn(sortInfo) {
+    if (sortInfo?.order && sortInfo?.columnKey) {
+      // 默认单列排序
+      tableSort.value = [
+        {
+          field: sortInfo.columnKey,
+          direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
+        },
+      ];
+    }
+  }
+
+  // 表格请求之前,对参数进行处理, 添加默认 排序
+  function handleBeforeFetch(params) {
+    return { ...params, orders: tableSort.value };
+  }
+
+  // 弹窗回调事件
+  async function handleSuccess({ isUpdate, values }) {
+    console.log(isUpdate);
+    console.log(values);
+    await reload();
+  }
+</script>

+ 40 - 0
src/views/sys/sysConstant/ConstantConfig/viewDrawer.vue

@@ -0,0 +1,40 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    destroyOnClose
+    @register="registerDrawer"
+    :title="getTitle"
+    :width="width"
+  >
+    <Description @register="registerDesc" :data="descData" />
+  </BasicDrawer>
+</template>
+<script lang="ts" setup>
+  import { onBeforeMount, ref } from 'vue'; // onBeforeMount,
+  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
+  import { Description, useDescription } from '/@/components/Description';
+  import { viewSchema } from './data';
+
+  import { sysConfigDetail } from '/@/api/sys/sysConstantConfig';
+
+  const descData = ref({});
+  const getTitle = '查看常量配置';
+  const width = '45%';
+
+  onBeforeMount(async () => {});
+  const [registerDrawer] = useDrawerInner(async data => {
+    console.log('::::::::::', data.record);
+    const resData = await sysConfigDetail(data.record.id);
+    descData.value = {
+      ...resData,
+    };
+  });
+  const [registerDesc] = useDescription({
+    schema: viewSchema,
+    column: 2,
+    size: 'middle',
+    labelStyle: {
+      width: '120px',
+    },
+  });
+</script>

+ 17 - 0
src/views/sys/sysDict/sysDictItemTable/data.ts

@@ -1,4 +1,5 @@
 import { BasicColumn, FormSchema } from '/@/components/Table';
+import { validateStr } from '/@/utils/validate';
 
 export const columns: BasicColumn[] = [
   {
@@ -63,6 +64,22 @@ export const dataFormSchema: FormSchema[] = [
     componentProps: {
       placeholder: '请输入字典项编码',
     },
+    dynamicRules: () => {
+      return [
+        {
+          required: true,
+          validator: async (_, value) => {
+            if (!value) {
+              return Promise.reject('字典项编码不能为空');
+            }
+            if (validateStr(value)) {
+              return Promise.reject('字典项编码为字母或数字组成');
+            }
+            return Promise.resolve();
+          },
+        },
+      ];
+    },
   },
   {
     field: 'color',

+ 4 - 4
src/views/sys/sysDict/sysDictItemTable/index.vue

@@ -11,13 +11,13 @@
           <TableAction
             :actions="[
               {
-                auth: ['sys:dict:edit'],
+                auth: ['sys:dictItem:edit'],
                 icon: 'icon-edit|iconfont',
                 tooltip: '编辑',
                 onClick: handleEdit.bind(null, record),
               },
               {
-                auth: ['sys:dict:remove'],
+                auth: ['sys:dictItem:remove'],
                 icon: 'icon-delete|iconfont',
                 tooltip: '删除',
                 color: 'error',
@@ -33,7 +33,7 @@
       </template>
       <template #toolbar>
         <a-button
-          v-auth="['sys:dict:add']"
+          v-auth="['sys:dictItem:add']"
           v-show="!!dictId"
           type="primary"
           @click="handleCreate"
@@ -92,7 +92,7 @@
     showTableSetting: true,
     bordered: true,
     actionColumn: {
-      auth: ['sys:dict:edit', 'sys:dict:remove'],
+      auth: ['sys:dictItem:edit', 'sys:dictItem:remove'],
       width: 80,
       title: '操作',
       dataIndex: 'action',

+ 17 - 0
src/views/sys/sysDict/sysDictTable/data.ts

@@ -1,5 +1,6 @@
 import { BasicColumn, FormSchema } from '/@/components/Table';
 import { listDictModel } from '/@/api/common';
+import { validateStr } from '/@/utils/validate';
 
 export const columns: BasicColumn[] = [
   {
@@ -74,6 +75,22 @@ export const dataFormSchema: FormSchema[] = [
     componentProps: {
       placeholder: '请输入字典编码',
     },
+    dynamicRules: () => {
+      return [
+        {
+          required: true,
+          validator: async (_, value) => {
+            if (!value) {
+              return Promise.reject('字典项编码不能为空');
+            }
+            if (validateStr(value)) {
+              return Promise.reject('字典项编码为字母或数字组成');
+            }
+            return Promise.resolve();
+          },
+        },
+      ];
+    },
   },
   {
     field: 'dictType',

+ 1 - 1
src/views/sys/sysRole/FormModal.vue

@@ -73,7 +73,7 @@
         .map(item => item.id);
       await setFieldsValue({
         ...data.record,
-        disable: data.record.disable ? 1 : 0,
+        disable: String(data.record.disable),
       });
     }
   });

+ 23 - 5
src/views/sys/sysRole/data.ts

@@ -1,6 +1,6 @@
+import { validateStr } from '/@/utils/validate';
 import { listDictModel } from '/@/api/common';
 import { BasicColumn, FormSchema } from '/@/components/Table';
-import { radioSwitch } from '/@/utils/filters';
 export const columns: BasicColumn[] = [
   {
     title: '角色名称',
@@ -77,10 +77,25 @@ export const dataFormSchema: FormSchema[] = [
     field: 'code',
     label: '角色编码',
     component: 'Input',
-    required: true,
     componentProps: {
       placeholder: '请输入角色编码',
     },
+    dynamicRules: () => {
+      return [
+        {
+          required: true,
+          validator: async (_, value) => {
+            if (!value) {
+              return Promise.reject('角色编码不能为空');
+            }
+            if (validateStr(value)) {
+              return Promise.reject('角色编码为字母或数字组成');
+            }
+            return Promise.resolve();
+          },
+        },
+      ];
+    },
   },
   {
     field: 'dataScope',
@@ -120,12 +135,15 @@ export const dataFormSchema: FormSchema[] = [
   {
     field: 'disable',
     label: '状态',
-    component: 'RadioGroup',
+    component: 'ApiRadioGroup',
     required: true,
     componentProps: {
-      options: radioSwitch,
+      api: listDictModel,
+      params: {
+        dictCode: 'sys_disable_type',
+      },
     },
-    defaultValue: 0,
+    defaultValue: '0',
   },
   {
     label: '备注',

+ 5 - 3
src/views/sys/sysRole/index.vue

@@ -13,8 +13,8 @@
           </Tag>
         </template>
         <template v-if="column.key === 'disable'">
-          <Tag :color="record.disable ? 'error' : 'success'">
-            {{ commonDict(record.disable, 1) }}
+          <Tag :color="formatDictColor(disableOptions, record.disable)">
+            {{ formatDictValue(disableOptions, record.disable) }}
           </Tag>
         </template>
         <template v-if="column.key === 'action'">
@@ -86,13 +86,15 @@
   import { sysRoleQueryPage, sysRoleRemove } from '/@/api/sys/sysRoleApi';
   // import { listDictModel, downloadFile } from '/@/api/common';
   import { listDictModel } from '/@/api/common';
-  import { formatDictValue, formatDictColor, commonDict } from '/@/utils';
+  import { formatDictValue, formatDictColor } from '/@/utils';
 
   const sysCreateTypeOptions = ref([]);
   const sysDataScopeOptions = ref([]);
+  const disableOptions = ref([]);
   onBeforeMount(async () => {
     sysCreateTypeOptions.value = await listDictModel({ dictCode: 'sys_create_type' });
     sysDataScopeOptions.value = await listDictModel({ dictCode: 'sys_data_scope' });
+    disableOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
   });
 
   const { createMessage } = useMessage();

+ 2 - 4
src/views/sys/sysTenant/page/data.ts

@@ -3,6 +3,7 @@ import { sysTenantPackageQueryPage } from '/@/api/sys/sysTenantPackageApi';
 import { validatorUsername } from '/@/api/sys/sysUserApi';
 import { DescItem } from '/@/components/Description';
 import { BasicColumn, FormSchema } from '/@/components/Table';
+import { validateUserName } from '/@/utils/validate';
 
 export const columns: BasicColumn[] = [
   {
@@ -125,10 +126,7 @@ export const dataFormSchema: FormSchema[] = [
             if (!value) {
               return Promise.reject('管理账号不能为空');
             }
-            if (value.length > 16 || value.length < 4) {
-              return Promise.reject('管理账号为4-16为字母或数字组成');
-            }
-            if (!/^[A-Za-z0-9_-]$/.test(value)) {
+            if (validateUserName(value)) {
               return Promise.reject('管理账号为4-16为字母或数字组成');
             }
             await validatorUsername({ username: value }).then(res => {

+ 3 - 4
src/views/sys/sysUser/sysUserTable/data.ts

@@ -5,6 +5,7 @@ import { sysOrgQueryTree } from '/@/api/sys/sysOrgApi';
 import { sysPosQueryPage } from '/@/api/sys/sysPosApi';
 import { validatorUsername } from '/@/api/sys/sysUserApi';
 import { listDictModel } from '/@/api/common';
+import { validateUserName } from '/@/utils/validate';
 export const columns: BasicColumn[] = [
   {
     title: '账号',
@@ -83,10 +84,7 @@ export const dataFormSchema: FormSchema[] = [
             if (!value) {
               return Promise.reject('管理账号不能为空');
             }
-            if (value.length > 16 || value.length < 4) {
-              return Promise.reject('管理账号为4-16为字母或数字组成');
-            }
-            if (!/^[A-Za-z0-9_-]$/.test(value)) {
+            if (validateUserName(value)) {
               return Promise.reject('管理账号为4-16为字母或数字组成');
             }
             await validatorUsername({ username: value }).then(res => {
@@ -171,6 +169,7 @@ export const dataFormSchema: FormSchema[] = [
         params: {
           pageNum: 1,
           pageSize: 999,
+          disable: 0,
         },
         mode: 'multiple',
         labelField: 'name',