Commit 8917dcf6bf3ca3bd3c74b64b7b16f894c8a49bb6

Authored by xingyu4j
1 parent a95694ae

perf: vxe demo

yudao-ui-admin-vue3/src/plugins/vxeTable/index.ts
... ... @@ -103,6 +103,9 @@ VXETable.setup({
103 103 input: {
104 104 clearable: true
105 105 },
  106 + form: {
  107 + titleColon: true // 是否显示标题冒号
  108 + },
106 109 modal: {
107 110 width: 600, // 窗口的宽度
108 111 height: 400, // 窗口的高度
... ... @@ -124,6 +127,14 @@ VXETable.setup({
124 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 138 export const setupVxeTable = (app: App<Element>) => {
128 139 // 表格功能
129 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 1 <script setup lang="ts">
2 2 import { reactive, ref } from 'vue'
3 3 import dayjs from 'dayjs'
4   -import XEUtils from 'xe-utils'
5 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 13 import * as PostApi from '@/api/system/post'
8 14 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
9 15 import { ContentWrap } from '@/components/ContentWrap'
... ... @@ -14,6 +20,7 @@ import { ElMessage, ElMessageBox } from &#39;element-plus&#39;
14 20 const { t } = useI18n() // 国际化
15 21  
16 22 const xGrid = ref<VxeGridInstance>()
  23 +const xForm = ref<VxeFormInstance>()
17 24 const dialogVisible = ref(false) // 是否显示弹出层
18 25 const dialogTitle = ref('edit') // 弹出层标题
19 26 const actionType = ref('') // 操作按钮的类型
... ... @@ -93,9 +100,7 @@ const gridOptions = reactive&lt;VxeGridProps&gt;({
93 100 title: t('common.createTime'),
94 101 width: 160,
95 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 106 field: 'action',
... ... @@ -203,6 +208,8 @@ const handleDetail = (row: PostVO) =&gt; {
203 208 }
204 209 // 新增操作
205 210 const handleCreate = () => {
  211 + const $form = xForm.value
  212 + $form?.reset()
206 213 setDialogTile('create')
207 214 }
208 215  
... ... @@ -308,11 +315,11 @@ const submitForm: VxeFormEvents.Submit = async () =&gt; {
308 315 <template #default>
309 316 <!-- 对话框(添加 / 修改) -->
310 317 <vxe-form
  318 + ref="xForm"
311 319 v-if="['create', 'update'].includes(actionType)"
312 320 :data="formData"
313 321 :items="formItems"
314 322 :rules="rules"
315   - titleColon
316 323 @submit="submitForm"
317 324 />
318 325 <Descriptions
... ...