Commit 8917dcf6bf3ca3bd3c74b64b7b16f894c8a49bb6
1 parent
a95694ae
perf: vxe demo
Showing
2 changed files
with
24 additions
and
6 deletions
yudao-ui-admin-vue3/src/plugins/vxeTable/index.ts
| @@ -103,6 +103,9 @@ VXETable.setup({ | @@ -103,6 +103,9 @@ VXETable.setup({ | ||
| 103 | input: { | 103 | input: { |
| 104 | clearable: true | 104 | clearable: true |
| 105 | }, | 105 | }, |
| 106 | + form: { | ||
| 107 | + titleColon: true // 是否显示标题冒号 | ||
| 108 | + }, | ||
| 106 | modal: { | 109 | modal: { |
| 107 | width: 600, // 窗口的宽度 | 110 | width: 600, // 窗口的宽度 |
| 108 | height: 400, // 窗口的高度 | 111 | height: 400, // 窗口的高度 |
| @@ -124,6 +127,14 @@ VXETable.setup({ | @@ -124,6 +127,14 @@ VXETable.setup({ | ||
| 124 | : XEUtils.toFormatString(XEUtils.get(enUS, key), args) | 127 | : XEUtils.toFormatString(XEUtils.get(enUS, key), args) |
| 125 | } | 128 | } |
| 126 | }) | 129 | }) |
| 130 | +// 格式金额,默认2位数 | ||
| 131 | +VXETable.formats.add('formatAmount', ({ cellValue }, digits = 2) => { | ||
| 132 | + return XEUtils.commafy(XEUtils.toNumber(cellValue), { digits }) | ||
| 133 | +}) | ||
| 134 | +// 格式日期,默认 yyyy-MM-dd HH:mm:ss | ||
| 135 | +VXETable.formats.add('formatDate', ({ cellValue }, format = 'yyyy-MM-dd HH:mm:ss') => { | ||
| 136 | + return XEUtils.toDateString(cellValue, format) | ||
| 137 | +}) | ||
| 127 | export const setupVxeTable = (app: App<Element>) => { | 138 | export const setupVxeTable = (app: App<Element>) => { |
| 128 | // 表格功能 | 139 | // 表格功能 |
| 129 | app.use(Filter).use(Edit).use(Menu).use(Export).use(Keyboard).use(Validator) | 140 | app.use(Filter).use(Edit).use(Menu).use(Export).use(Keyboard).use(Validator) |
yudao-ui-admin-vue3/src/views/system/post/index.vue
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { reactive, ref } from 'vue' | 2 | import { reactive, ref } from 'vue' |
| 3 | import dayjs from 'dayjs' | 3 | import dayjs from 'dayjs' |
| 4 | -import XEUtils from 'xe-utils' | ||
| 5 | import { useI18n } from '@/hooks/web/useI18n' | 4 | import { useI18n } from '@/hooks/web/useI18n' |
| 6 | -import { VxeFormEvents, VxeFormItemProps, VxeGrid, VxeGridInstance, VxeGridProps } from 'vxe-table' | 5 | +import { |
| 6 | + VxeFormEvents, | ||
| 7 | + VxeFormInstance, | ||
| 8 | + VxeFormItemProps, | ||
| 9 | + VxeGrid, | ||
| 10 | + VxeGridInstance, | ||
| 11 | + VxeGridProps | ||
| 12 | +} from 'vxe-table' | ||
| 7 | import * as PostApi from '@/api/system/post' | 13 | import * as PostApi from '@/api/system/post' |
| 8 | import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' | 14 | import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
| 9 | import { ContentWrap } from '@/components/ContentWrap' | 15 | import { ContentWrap } from '@/components/ContentWrap' |
| @@ -14,6 +20,7 @@ import { ElMessage, ElMessageBox } from 'element-plus' | @@ -14,6 +20,7 @@ import { ElMessage, ElMessageBox } from 'element-plus' | ||
| 14 | const { t } = useI18n() // 国际化 | 20 | const { t } = useI18n() // 国际化 |
| 15 | 21 | ||
| 16 | const xGrid = ref<VxeGridInstance>() | 22 | const xGrid = ref<VxeGridInstance>() |
| 23 | +const xForm = ref<VxeFormInstance>() | ||
| 17 | const dialogVisible = ref(false) // 是否显示弹出层 | 24 | const dialogVisible = ref(false) // 是否显示弹出层 |
| 18 | const dialogTitle = ref('edit') // 弹出层标题 | 25 | const dialogTitle = ref('edit') // 弹出层标题 |
| 19 | const actionType = ref('') // 操作按钮的类型 | 26 | const actionType = ref('') // 操作按钮的类型 |
| @@ -93,9 +100,7 @@ const gridOptions = reactive<VxeGridProps>({ | @@ -93,9 +100,7 @@ const gridOptions = reactive<VxeGridProps>({ | ||
| 93 | title: t('common.createTime'), | 100 | title: t('common.createTime'), |
| 94 | width: 160, | 101 | width: 160, |
| 95 | sortable: true, | 102 | sortable: true, |
| 96 | - formatter({ cellValue }) { | ||
| 97 | - return XEUtils.toDateString(cellValue, 'yyyy-MM-dd HH:ss:mm') | ||
| 98 | - } | 103 | + formatter: 'formatDate' |
| 99 | }, | 104 | }, |
| 100 | { | 105 | { |
| 101 | field: 'action', | 106 | field: 'action', |
| @@ -203,6 +208,8 @@ const handleDetail = (row: PostVO) => { | @@ -203,6 +208,8 @@ const handleDetail = (row: PostVO) => { | ||
| 203 | } | 208 | } |
| 204 | // 新增操作 | 209 | // 新增操作 |
| 205 | const handleCreate = () => { | 210 | const handleCreate = () => { |
| 211 | + const $form = xForm.value | ||
| 212 | + $form?.reset() | ||
| 206 | setDialogTile('create') | 213 | setDialogTile('create') |
| 207 | } | 214 | } |
| 208 | 215 | ||
| @@ -308,11 +315,11 @@ const submitForm: VxeFormEvents.Submit = async () => { | @@ -308,11 +315,11 @@ const submitForm: VxeFormEvents.Submit = async () => { | ||
| 308 | <template #default> | 315 | <template #default> |
| 309 | <!-- 对话框(添加 / 修改) --> | 316 | <!-- 对话框(添加 / 修改) --> |
| 310 | <vxe-form | 317 | <vxe-form |
| 318 | + ref="xForm" | ||
| 311 | v-if="['create', 'update'].includes(actionType)" | 319 | v-if="['create', 'update'].includes(actionType)" |
| 312 | :data="formData" | 320 | :data="formData" |
| 313 | :items="formItems" | 321 | :items="formItems" |
| 314 | :rules="rules" | 322 | :rules="rules" |
| 315 | - titleColon | ||
| 316 | @submit="submitForm" | 323 | @submit="submitForm" |
| 317 | /> | 324 | /> |
| 318 | <Descriptions | 325 | <Descriptions |