浏览代码

feat: add vxe crud schemas

xingyu4j 2 年之前
父节点
当前提交
49237ad966

+ 245 - 0
yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts

@@ -0,0 +1,245 @@
+import { DescriptionsSchema } from '@/types/descriptions'
+import { getIntDictOptions } from '@/utils/dict'
+import { reactive } from 'vue'
+import {
+  FormItemRenderOptions,
+  VxeFormItemProps,
+  VxeGridPropTypes,
+  VxeTableDefines
+} from 'vxe-table'
+import { eachTree } from 'xe-utils'
+import { useI18n } from '@/hooks/web/useI18n'
+import { VxeTableColumn } from '@/types/table'
+
+export type VxeCrudSchema = Omit<VxeTableColumn, 'children'> & {
+  field: string
+  title?: string
+  search?: CrudSearchParams
+  table?: CrudTableParams
+  form?: CrudFormParams
+  detail?: CrudDescriptionsParams
+  print?: boolean
+  children?: VxeCrudSchema[]
+  dictType?: string
+}
+type CrudSearchParams = {
+  // 是否显示在查询项
+  show?: boolean
+} & Omit<VxeFormItemProps, 'field'>
+
+type CrudTableParams = {
+  // 是否显示表头
+  show?: boolean
+} & Omit<VxeTableDefines.ColumnOptions, 'field'>
+
+type CrudFormParams = {
+  // 是否显示表单项
+  show?: boolean
+} & Omit<VxeFormItemProps, 'field'>
+
+type CrudDescriptionsParams = {
+  // 是否显示表单项
+  show?: boolean
+} & Omit<DescriptionsSchema, 'field'>
+
+interface VxeAllSchemas {
+  searchSchema: VxeFormItemProps[]
+  tableSchema: VxeGridPropTypes.Columns
+  formSchema: VxeFormItemProps[]
+  detailSchema: DescriptionsSchema[]
+  printSchema: VxeTableDefines.ColumnInfo[]
+}
+
+// 过滤所有结构
+export const useVxeCrudSchemas = (
+  crudSchema: VxeCrudSchema[]
+): {
+  allSchemas: VxeAllSchemas
+} => {
+  // 所有结构数据
+  const allSchemas = reactive<VxeAllSchemas>({
+    searchSchema: [],
+    tableSchema: [],
+    formSchema: [],
+    detailSchema: [],
+    printSchema: []
+  })
+
+  const searchSchema = filterSearchSchema(crudSchema)
+  allSchemas.searchSchema = searchSchema || []
+
+  const tableSchema = filterTableSchema(crudSchema)
+  allSchemas.tableSchema = tableSchema || []
+
+  const formSchema = filterFormSchema(crudSchema)
+  allSchemas.formSchema = formSchema
+
+  const detailSchema = filterDescriptionsSchema(crudSchema)
+  allSchemas.detailSchema = detailSchema
+
+  const printSchema = filterPrintSchema(crudSchema)
+  allSchemas.printSchema = printSchema
+
+  return {
+    allSchemas
+  }
+}
+
+// 过滤 Search 结构
+const filterSearchSchema = (crudSchema: VxeCrudSchema[]): VxeFormItemProps[] => {
+  const searchSchema: VxeFormItemProps[] = []
+  const { t } = useI18n()
+  eachTree(crudSchema, (schemaItem: VxeCrudSchema) => {
+    // 判断是否显示
+    if (schemaItem?.search?.show) {
+      let itemRenderName = schemaItem?.search?.itemRender?.name || '$input'
+      const options: any[] = []
+      let itemRender: FormItemRenderOptions = {
+        name: itemRenderName,
+        props: { placeholder: t('common.inputText') }
+      }
+      if (schemaItem.dictType) {
+        const allOptions = { label: '全部', value: '' }
+        options.push(allOptions)
+        getIntDictOptions(schemaItem.dictType).forEach((dict) => {
+          options.push(dict)
+        })
+        itemRender.options = options
+        if (!schemaItem.search.itemRender?.name) itemRenderName = '$select'
+        itemRender = {
+          name: itemRenderName,
+          options: options,
+          props: { placeholder: t('common.selectText') }
+        }
+      }
+
+      const searchSchemaItem = {
+        // 默认为 input
+        span: 6,
+        itemRender: itemRender,
+        ...schemaItem.search,
+        field: schemaItem.field,
+        title: schemaItem.search?.title || schemaItem.title
+      }
+      // 删除不必要的字段
+      delete searchSchemaItem.show
+
+      searchSchema.push(searchSchemaItem)
+    }
+  })
+  // 添加搜索按钮
+  const buttons: VxeFormItemProps = {
+    span: 24,
+    align: 'center',
+    collapseNode: true,
+    itemRender: {
+      name: '$buttons',
+      children: [
+        { props: { type: 'submit', content: t('common.query'), status: 'primary' } },
+        { props: { type: 'reset', content: t('common.reset') } }
+      ]
+    }
+  }
+  searchSchema.push(buttons)
+  return searchSchema
+}
+
+// 过滤 table 结构
+const filterTableSchema = (crudSchema: VxeCrudSchema[]): VxeGridPropTypes.Columns => {
+  const tableSchema: VxeGridPropTypes.Columns = []
+  eachTree(crudSchema, (schemaItem: VxeCrudSchema) => {
+    // 判断是否显示
+    if (schemaItem?.table?.show !== false) {
+      const tableSchemaItem = {
+        ...schemaItem.table,
+        field: schemaItem.field,
+        title: schemaItem.table?.title || schemaItem.title
+      }
+
+      // 删除不必要的字段
+      delete tableSchemaItem.show
+
+      tableSchema.push(tableSchemaItem)
+    }
+  })
+  return tableSchema
+}
+
+// 过滤 form 结构
+const filterFormSchema = (crudSchema: VxeCrudSchema[]): VxeFormItemProps[] => {
+  const formSchema: VxeFormItemProps[] = []
+  const { t } = useI18n()
+  eachTree(crudSchema, (schemaItem: VxeCrudSchema) => {
+    // 判断是否显示
+    if (schemaItem?.form?.show !== false) {
+      let itemRenderName = schemaItem?.form?.itemRender?.name || '$input'
+      let itemRender: FormItemRenderOptions = {
+        name: itemRenderName,
+        props: { placeholder: t('common.inputText') }
+      }
+      if (schemaItem.dictType) {
+        if (!(schemaItem.form && schemaItem.form.itemRender?.name)) itemRenderName = '$select'
+        itemRender = {
+          name: itemRenderName,
+          options: getIntDictOptions(schemaItem.dictType),
+          props: { placeholder: t('common.selectText') }
+        }
+      }
+      const formSchemaItem = {
+        // 默认为 input
+        itemRender: itemRender,
+        ...schemaItem.form,
+        field: schemaItem.field,
+        title: schemaItem.form?.title || schemaItem.title
+      }
+
+      // 删除不必要的字段
+      delete formSchemaItem.show
+
+      formSchema.push(formSchemaItem)
+    }
+  })
+
+  return formSchema
+}
+
+// 过滤 descriptions 结构
+const filterDescriptionsSchema = (crudSchema: VxeCrudSchema[]): DescriptionsSchema[] => {
+  const descriptionsSchema: DescriptionsSchema[] = []
+
+  eachTree(crudSchema, (schemaItem: VxeCrudSchema) => {
+    // 判断是否显示
+    if (schemaItem?.detail?.show !== false) {
+      const descriptionsSchemaItem = {
+        ...schemaItem.detail,
+        field: schemaItem.field,
+        label: schemaItem.detail?.label || schemaItem.title
+      }
+
+      // 删除不必要的字段
+      delete descriptionsSchemaItem.show
+
+      descriptionsSchema.push(descriptionsSchemaItem)
+    }
+  })
+
+  return descriptionsSchema
+}
+
+// 过滤 打印 结构
+const filterPrintSchema = (crudSchema: VxeCrudSchema[]): any[] => {
+  const printSchema: any[] = []
+
+  eachTree(crudSchema, (schemaItem: VxeCrudSchema) => {
+    // 判断是否显示
+    if (schemaItem?.detail?.show !== false) {
+      const printSchemaItem = {
+        field: schemaItem.field
+      }
+
+      printSchema.push(printSchemaItem)
+    }
+  })
+
+  return printSchema
+}

+ 59 - 0
yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts

@@ -0,0 +1,59 @@
+import { reactive } from 'vue'
+import { VxeGridProps } from 'vxe-table'
+
+export const useVxeGrid = (allSchemas, getPageApi) => {
+  const gridOptions = reactive<VxeGridProps>({
+    loading: false,
+    rowConfig: {
+      keyField: 'id',
+      isHover: true
+    },
+    toolbarConfig: {
+      custom: true,
+      slots: { buttons: 'toolbar_buttons' }
+    },
+    printConfig: {
+      columns: allSchemas.printSchema
+    },
+    formConfig: {
+      titleWidth: 100,
+      titleAlign: 'right',
+      items: allSchemas.searchSchema
+    },
+    columns: allSchemas.tableSchema,
+    pagerConfig: {
+      border: false,
+      background: false,
+      perfect: true,
+      pageSize: 10,
+      pagerCount: 7,
+      pageSizes: [5, 10, 15, 20, 50, 100, 200, 500],
+      layouts: [
+        'PrevJump',
+        'PrevPage',
+        'Jump',
+        'PageCount',
+        'NextPage',
+        'NextJump',
+        'Sizes',
+        'Total'
+      ]
+    },
+    proxyConfig: {
+      seq: true, // 启用动态序号代理(分页之后索引自动计算为当前页的起始序号)
+      form: true, // 启用表单代理,当点击表单提交按钮时会自动触发 reload 行为
+      props: { result: 'list', total: 'total' },
+      ajax: {
+        query: ({ page, form }) => {
+          const queryParams = Object.assign({}, form)
+          queryParams.pageSize = page.pageSize
+          queryParams.pageNo = page.currentPage
+          return new Promise(async (resolve) => {
+            resolve(await getPageApi(queryParams))
+          })
+        }
+      }
+    }
+  })
+  return gridOptions
+}

+ 6 - 0
yudao-ui-admin-vue3/src/types/table.d.ts

@@ -4,6 +4,12 @@ export type TableColumn = {
   children?: TableColumn[]
   children?: TableColumn[]
 } & Recordable
 } & Recordable
 
 
+export type VxeTableColumn = {
+  field: string
+  title?: string
+  children?: TableColumn[]
+} & Recordable
+
 export type TableSlotDefault = {
 export type TableSlotDefault = {
   row: Recordable
   row: Recordable
   column: TableColumn
   column: TableColumn

+ 14 - 172
yudao-ui-admin-vue3/src/views/system/post/index.vue

@@ -1,24 +1,18 @@
 <script setup lang="ts">
 <script setup lang="ts">
-import { reactive, ref } from 'vue'
+import { ref } from 'vue'
 import dayjs from 'dayjs'
 import dayjs from 'dayjs'
 import { useI18n } from '@/hooks/web/useI18n'
 import { useI18n } from '@/hooks/web/useI18n'
-import {
-  VxeFormEvents,
-  VxeFormInstance,
-  VxeFormItemProps,
-  VxeGrid,
-  VxeGridInstance,
-  VxeGridProps
-} from 'vxe-table'
+import { VxeFormEvents, VxeFormInstance, VxeFormItemProps, VxeGridInstance } from 'vxe-table'
 import * as PostApi from '@/api/system/post'
 import * as PostApi from '@/api/system/post'
-import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
+import { DICT_TYPE } from '@/utils/dict'
 import { ContentWrap } from '@/components/ContentWrap'
 import { ContentWrap } from '@/components/ContentWrap'
-import { PostPageReqVO, PostVO } from '@/api/system/post/types'
+import { PostVO } from '@/api/system/post/types'
 import { rules, allSchemas } from './post.data'
 import { rules, allSchemas } from './post.data'
-import { ElMessage, ElMessageBox } from 'element-plus'
+import { useMessage } from '@/hooks/web/useMessage'
+import { useVxeGrid } from '@/hooks/web/useVxeGrid'
 
 
 const { t } = useI18n() // 国际化
 const { t } = useI18n() // 国际化
-
+const message = useMessage()
 const xGrid = ref<VxeGridInstance>()
 const xGrid = ref<VxeGridInstance>()
 const xForm = ref<VxeFormInstance>()
 const xForm = ref<VxeFormInstance>()
 const dialogVisible = ref(false) // 是否显示弹出层
 const dialogVisible = ref(false) // 是否显示弹出层
@@ -26,158 +20,9 @@ const dialogTitle = ref('edit') // 弹出层标题
 const actionType = ref('') // 操作按钮的类型
 const actionType = ref('') // 操作按钮的类型
 const actionLoading = ref(false) // 遮罩层
 const actionLoading = ref(false) // 遮罩层
 
 
-const gridOptions = reactive<VxeGridProps>({
-  loading: false,
-  rowConfig: {
-    keyField: 'id',
-    isHover: true
-  },
-  toolbarConfig: {
-    custom: true,
-    slots: { buttons: 'toolbar_buttons' }
-  },
-  printConfig: {
-    columns: [
-      { field: 'name' },
-      { field: 'code' },
-      { field: 'sort' },
-      { field: 'status' },
-      { field: 'createTime' }
-    ]
-  },
-  formConfig: {
-    titleWidth: 100,
-    titleAlign: 'right',
-    items: [
-      {
-        field: 'name',
-        title: '岗位名称',
-        span: 6,
-        itemRender: { name: '$input', props: { placeholder: '请输入岗位名称' } }
-      },
-      {
-        field: 'code',
-        title: '岗位编码',
-        span: 6,
-        itemRender: { name: '$input', props: { placeholder: '请输入岗位编码' } }
-      },
-      {
-        field: 'status',
-        title: t('common.status'),
-        span: 6,
-        itemRender: { name: '$select', options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) }
-      },
-      {
-        span: 24,
-        align: 'center',
-        collapseNode: true,
-        itemRender: {
-          name: '$buttons',
-          children: [
-            { props: { type: 'submit', content: t('common.query'), status: 'primary' } },
-            { props: { type: 'reset', content: t('common.reset') } }
-          ]
-        }
-      }
-    ]
-  },
-  columns: [
-    { type: 'seq', title: t('common.index'), width: 100 },
-    { field: 'name', title: '岗位名称' },
-    { field: 'code', title: '岗位编码' },
-    { field: 'sort', title: '岗位顺序' },
-    {
-      field: 'status',
-      title: t('common.status'),
-      slots: {
-        default: 'status_default'
-      }
-    },
-    {
-      field: 'createTime',
-      title: t('common.createTime'),
-      width: 160,
-      sortable: true,
-      formatter: 'formatDate'
-    },
-    {
-      field: 'action',
-      title: t('table.action'),
-      width: '240px',
-      showOverflow: true,
-      slots: {
-        default: 'action_default'
-      }
-    }
-  ],
-  pagerConfig: {
-    border: false,
-    background: false,
-    perfect: true,
-    pageSize: 10,
-    pagerCount: 7,
-    pageSizes: [5, 10, 15, 20, 50, 100, 200, 500],
-    layouts: ['PrevJump', 'PrevPage', 'Jump', 'PageCount', 'NextPage', 'NextJump', 'Sizes', 'Total']
-  },
-  proxyConfig: {
-    seq: true, // 启用动态序号代理(分页之后索引自动计算为当前页的起始序号)
-    form: true, // 启用表单代理,当点击表单提交按钮时会自动触发 reload 行为
-    props: { result: 'list', total: 'total' },
-    ajax: {
-      query: ({ page, form }) => {
-        const queryParams: PostPageReqVO = Object.assign({}, form)
-        queryParams.pageSize = page.pageSize
-        queryParams.pageNo = page.currentPage
-        return new Promise(async (resolve) => {
-          resolve(await PostApi.getPostPageApi(queryParams))
-        })
-      }
-    }
-  }
-})
+const gridOptions = useVxeGrid(allSchemas, PostApi.getPostPageApi)
 const formData = ref<PostVO>()
 const formData = ref<PostVO>()
-const formItems = ref<VxeFormItemProps[]>([
-  { field: 'id', title: 'id', visible: false },
-  {
-    field: 'name',
-    title: '岗位名称',
-    span: 12,
-    itemRender: { name: '$input', props: { placeholder: '请输入岗位名称' } }
-  },
-  {
-    field: 'code',
-    title: '岗位编码',
-    span: 12,
-    itemRender: { name: '$input', props: { placeholder: '请输入岗位编码' } }
-  },
-  {
-    field: 'sort',
-    title: '岗位顺序',
-    span: 12,
-    itemRender: { name: '$input', props: { type: 'number', placeholder: '请输入岗位顺序' } }
-  },
-  {
-    field: 'status',
-    title: t('common.status'),
-    span: 12,
-    itemRender: {
-      name: '$select',
-      options: getIntDictOptions(DICT_TYPE.COMMON_STATUS),
-      props: { placeholder: '请选择' }
-    }
-  },
-  {
-    align: 'center',
-    span: 24,
-    itemRender: {
-      name: '$buttons',
-      children: [
-        { props: { type: 'submit', content: t('action.save'), status: 'primary' } },
-        { props: { type: 'reset', content: t('common.reset') } }
-      ]
-    }
-  }
-])
+const formItems = ref<VxeFormItemProps[]>(allSchemas.formSchema)
 // 设置标题
 // 设置标题
 const setDialogTile = (type: string) => {
 const setDialogTile = (type: string) => {
   dialogTitle.value = t('action.' + type)
   dialogTitle.value = t('action.' + type)
@@ -206,16 +51,13 @@ const handleUpdate = async (rowId: number) => {
 }
 }
 // 删除操作
 // 删除操作
 const handleDelete = (rowId: number) => {
 const handleDelete = (rowId: number) => {
-  ElMessageBox.confirm(t('common.delMessage'), t('common.confirmTitle'), {
-    confirmButtonText: t('common.ok'),
-    cancelButtonText: t('common.cancel'),
-    type: 'warning'
-  })
+  message
+    .confirm(t('common.delMessage'), t('common.confirmTitle'))
     .then(async () => {
     .then(async () => {
       await PostApi.deletePostApi(rowId)
       await PostApi.deletePostApi(rowId)
+      message.success(t('common.delSuccess'))
     })
     })
     .finally(() => {
     .finally(() => {
-      ElMessage.success(t('common.delSuccess'))
       xGrid.value?.commitProxy('query')
       xGrid.value?.commitProxy('query')
     })
     })
 }
 }
@@ -227,10 +69,10 @@ const submitForm: VxeFormEvents.Submit = async () => {
     const data = formData.value as PostVO
     const data = formData.value as PostVO
     if (actionType.value === 'create') {
     if (actionType.value === 'create') {
       await PostApi.createPostApi(data)
       await PostApi.createPostApi(data)
-      ElMessage.success(t('common.createSuccess'))
+      message.success(t('common.createSuccess'))
     } else {
     } else {
       await PostApi.updatePostApi(data)
       await PostApi.updatePostApi(data)
-      ElMessage.success(t('common.updateSuccess'))
+      message.success(t('common.updateSuccess'))
     }
     }
     // 操作成功,重新加载列表
     // 操作成功,重新加载列表
     dialogVisible.value = false
     dialogVisible.value = false

+ 0 - 194
yudao-ui-admin-vue3/src/views/system/post/indexd.vue

@@ -1,194 +0,0 @@
-<script setup lang="ts">
-import { ref, unref } from 'vue'
-import dayjs from 'dayjs'
-import { ElMessage } from 'element-plus'
-import { DICT_TYPE } from '@/utils/dict'
-import { useTable } from '@/hooks/web/useTable'
-import { useI18n } from '@/hooks/web/useI18n'
-import { FormExpose } from '@/components/Form'
-import type { PostVO } from '@/api/system/post/types'
-import { rules, allSchemas } from './post.data'
-import * as PostApi from '@/api/system/post'
-const { t } = useI18n() // 国际化
-
-// ========== 列表相关 ==========
-const { register, tableObject, methods } = useTable<PostVO>({
-  getListApi: PostApi.getPostPageApi,
-  delListApi: PostApi.deletePostApi,
-  exportListApi: PostApi.exportPostApi
-})
-const { getList, setSearchParams, delList, exportList } = methods
-
-// ========== CRUD 相关 ==========
-const actionLoading = ref(false) // 遮罩层
-const actionType = ref('') // 操作按钮的类型
-const dialogVisible = ref(false) // 是否显示弹出层
-const dialogTitle = ref('edit') // 弹出层标题
-const formRef = ref<FormExpose>() // 表单 Ref
-
-// 设置标题
-const setDialogTile = (type: string) => {
-  dialogTitle.value = t('action.' + type)
-  actionType.value = type
-  dialogVisible.value = true
-}
-
-// 新增操作
-const handleCreate = () => {
-  setDialogTile('create')
-  // 重置表单
-  unref(formRef)?.getElFormRef()?.resetFields()
-}
-
-// 修改操作
-const handleUpdate = async (rowId: number) => {
-  setDialogTile('update')
-  // 设置数据
-  const res = await PostApi.getPostApi(rowId)
-  unref(formRef)?.setValues(res)
-}
-
-// 提交按钮
-const submitForm = async () => {
-  const elForm = unref(formRef)?.getElFormRef()
-  if (!elForm) return
-  elForm.validate(async (valid) => {
-    if (valid) {
-      actionLoading.value = true
-      // 提交请求
-      try {
-        const data = unref(formRef)?.formModel as PostVO
-        if (actionType.value === 'create') {
-          await PostApi.createPostApi(data)
-          ElMessage.success(t('common.createSuccess'))
-        } else {
-          await PostApi.updatePostApi(data)
-          ElMessage.success(t('common.updateSuccess'))
-        }
-        // 操作成功,重新加载列表
-        dialogVisible.value = false
-        await getList()
-      } finally {
-        actionLoading.value = false
-      }
-    }
-  })
-}
-
-// ========== 详情相关 ==========
-const detailRef = ref() // 详情 Ref
-
-// 详情操作
-const handleDetail = async (row: PostVO) => {
-  // 设置数据
-  detailRef.value = row
-  setDialogTile('detail')
-}
-
-// ========== 初始化 ==========
-getList()
-</script>
-
-<template>
-  <!-- 搜索工作区 -->
-  <ContentWrap>
-    <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
-  </ContentWrap>
-  <ContentWrap>
-    <!-- 操作工具栏 -->
-    <div class="mb-10px">
-      <el-button type="primary" v-hasPermi="['system:post:create']" @click="handleCreate">
-        <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
-      </el-button>
-      <el-button
-        type="warning"
-        v-hasPermi="['system:post:export']"
-        :loading="tableObject.exportLoading"
-        @click="exportList('岗位数据.xls')"
-      >
-        <Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }}
-      </el-button>
-    </div>
-    <!-- 列表 -->
-    <Table
-      :columns="allSchemas.tableColumns"
-      :selection="false"
-      :data="tableObject.tableList"
-      :loading="tableObject.loading"
-      :pagination="{
-        total: tableObject.total
-      }"
-      v-model:pageSize="tableObject.pageSize"
-      v-model:currentPage="tableObject.currentPage"
-      @register="register"
-    >
-      <template #status="{ row }">
-        <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
-      </template>
-      <template #createTime="{ row }">
-        <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
-      </template>
-      <template #action="{ row }">
-        <el-button
-          link
-          type="primary"
-          v-hasPermi="['system:post:update']"
-          @click="handleUpdate(row.id)"
-        >
-          <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
-        </el-button>
-        <el-button
-          link
-          type="primary"
-          v-hasPermi="['system:post:update']"
-          @click="handleDetail(row)"
-        >
-          <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
-        </el-button>
-        <el-button
-          link
-          type="primary"
-          v-hasPermi="['system:post:delete']"
-          @click="delList(row.id, false)"
-        >
-          <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
-        </el-button>
-      </template>
-    </Table>
-  </ContentWrap>
-
-  <Dialog v-model="dialogVisible" :title="dialogTitle">
-    <!-- 对话框(添加 / 修改) -->
-    <Form
-      v-if="['create', 'update'].includes(actionType)"
-      :schema="allSchemas.formSchema"
-      :rules="rules"
-      ref="formRef"
-    />
-    <!-- 对话框(详情) -->
-    <Descriptions
-      v-if="actionType === 'detail'"
-      :schema="allSchemas.detailSchema"
-      :data="detailRef"
-    >
-      <template #status="{ row }">
-        <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
-      </template>
-      <template #createTime="{ row }">
-        <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
-      </template>
-    </Descriptions>
-    <!-- 操作按钮 -->
-    <template #footer>
-      <el-button
-        v-if="['create', 'update'].includes(actionType)"
-        type="primary"
-        :loading="actionLoading"
-        @click="submitForm"
-      >
-        {{ t('action.save') }}
-      </el-button>
-      <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
-    </template>
-  </Dialog>
-</template>

+ 22 - 10
yudao-ui-admin-vue3/src/views/system/post/post.data.ts

@@ -1,7 +1,7 @@
 import { reactive } from 'vue'
 import { reactive } from 'vue'
 import { useI18n } from '@/hooks/web/useI18n'
 import { useI18n } from '@/hooks/web/useI18n'
 import { required } from '@/utils/formRules'
 import { required } from '@/utils/formRules'
-import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
+import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
 import { DICT_TYPE } from '@/utils/dict'
 import { DICT_TYPE } from '@/utils/dict'
 const { t } = useI18n() // 国际化
 const { t } = useI18n() // 国际化
 
 
@@ -13,9 +13,9 @@ export const rules = reactive({
 })
 })
 
 
 // CrudSchema
 // CrudSchema
-const crudSchemas = reactive<CrudSchema[]>([
+const crudSchemas = reactive<VxeCrudSchema[]>([
   {
   {
-    label: t('common.index'),
+    title: t('common.index'),
     field: 'id',
     field: 'id',
     type: 'index',
     type: 'index',
     form: {
     form: {
@@ -26,42 +26,54 @@ const crudSchemas = reactive<CrudSchema[]>([
     }
     }
   },
   },
   {
   {
-    label: '岗位名称',
+    title: '岗位名称',
     field: 'name',
     field: 'name',
     search: {
     search: {
       show: true
       show: true
     }
     }
   },
   },
   {
   {
-    label: '岗位编码',
+    title: '岗位编码',
     field: 'code',
     field: 'code',
     search: {
     search: {
       show: true
       show: true
     }
     }
   },
   },
   {
   {
-    label: '岗位顺序',
+    title: '岗位顺序',
     field: 'sort'
     field: 'sort'
   },
   },
   {
   {
-    label: t('common.status'),
+    title: t('common.status'),
     field: 'status',
     field: 'status',
     dictType: DICT_TYPE.COMMON_STATUS,
     dictType: DICT_TYPE.COMMON_STATUS,
+    table: {
+      slots: {
+        default: 'status_default'
+      }
+    },
     search: {
     search: {
       show: true
       show: true
     }
     }
   },
   },
   {
   {
-    label: t('common.createTime'),
+    title: t('common.createTime'),
     field: 'createTime',
     field: 'createTime',
     form: {
     form: {
       show: false
       show: false
     }
     }
   },
   },
   {
   {
-    label: t('table.action'),
+    title: t('table.action'),
     field: 'action',
     field: 'action',
     width: '240px',
     width: '240px',
+    table: {
+      width: '240px',
+      showOverflow: true,
+      slots: {
+        default: 'action_default'
+      }
+    },
     form: {
     form: {
       show: false
       show: false
     },
     },
@@ -70,4 +82,4 @@ const crudSchemas = reactive<CrudSchema[]>([
     }
     }
   }
   }
 ])
 ])
-export const { allSchemas } = useCrudSchemas(crudSchemas)
+export const { allSchemas } = useVxeCrudSchemas(crudSchemas)