perf: vxe demo

This commit is contained in:
xingyu4j 2022-11-01 17:12:26 +08:00
parent a95694ae6b
commit 8917dcf6bf
2 changed files with 24 additions and 6 deletions

View File

@ -103,6 +103,9 @@ VXETable.setup({
input: { input: {
clearable: true clearable: true
}, },
form: {
titleColon: true // 是否显示标题冒号
},
modal: { modal: {
width: 600, // 窗口的宽度 width: 600, // 窗口的宽度
height: 400, // 窗口的高度 height: 400, // 窗口的高度
@ -124,6 +127,14 @@ VXETable.setup({
: XEUtils.toFormatString(XEUtils.get(enUS, key), args) : XEUtils.toFormatString(XEUtils.get(enUS, key), args)
} }
}) })
// 格式金额默认2位数
VXETable.formats.add('formatAmount', ({ cellValue }, digits = 2) => {
return XEUtils.commafy(XEUtils.toNumber(cellValue), { digits })
})
// 格式日期,默认 yyyy-MM-dd HH:mm:ss
VXETable.formats.add('formatDate', ({ cellValue }, format = 'yyyy-MM-dd HH:mm:ss') => {
return XEUtils.toDateString(cellValue, format)
})
export const setupVxeTable = (app: App<Element>) => { export const setupVxeTable = (app: App<Element>) => {
// 表格功能 // 表格功能
app.use(Filter).use(Edit).use(Menu).use(Export).use(Keyboard).use(Validator) app.use(Filter).use(Edit).use(Menu).use(Export).use(Keyboard).use(Validator)

View File

@ -1,9 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import XEUtils from 'xe-utils'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { VxeFormEvents, VxeFormItemProps, VxeGrid, VxeGridInstance, VxeGridProps } from 'vxe-table' import {
VxeFormEvents,
VxeFormInstance,
VxeFormItemProps,
VxeGrid,
VxeGridInstance,
VxeGridProps
} 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, getIntDictOptions } from '@/utils/dict'
import { ContentWrap } from '@/components/ContentWrap' import { ContentWrap } from '@/components/ContentWrap'
@ -14,6 +20,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
const { t } = useI18n() // const { t } = useI18n() //
const xGrid = ref<VxeGridInstance>() const xGrid = ref<VxeGridInstance>()
const xForm = ref<VxeFormInstance>()
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('edit') // const dialogTitle = ref('edit') //
const actionType = ref('') // const actionType = ref('') //
@ -93,9 +100,7 @@ const gridOptions = reactive<VxeGridProps>({
title: t('common.createTime'), title: t('common.createTime'),
width: 160, width: 160,
sortable: true, sortable: true,
formatter({ cellValue }) { formatter: 'formatDate'
return XEUtils.toDateString(cellValue, 'yyyy-MM-dd HH:ss:mm')
}
}, },
{ {
field: 'action', field: 'action',
@ -203,6 +208,8 @@ const handleDetail = (row: PostVO) => {
} }
// //
const handleCreate = () => { const handleCreate = () => {
const $form = xForm.value
$form?.reset()
setDialogTile('create') setDialogTile('create')
} }
@ -308,11 +315,11 @@ const submitForm: VxeFormEvents.Submit = async () => {
<template #default> <template #default>
<!-- 对话框(添加 / 修改) --> <!-- 对话框(添加 / 修改) -->
<vxe-form <vxe-form
ref="xForm"
v-if="['create', 'update'].includes(actionType)" v-if="['create', 'update'].includes(actionType)"
:data="formData" :data="formData"
:items="formItems" :items="formItems"
:rules="rules" :rules="rules"
titleColon
@submit="submitForm" @submit="submitForm"
/> />
<Descriptions <Descriptions