!295 fix: vue3 bugs

Merge pull request !295 from xingyu/feature/vue3
This commit is contained in:
芋道源码
2022-11-12 01:12:43 +00:00
committed by Gitee
10 changed files with 218 additions and 220 deletions

View File

@ -1,3 +1,154 @@
<template>
<div class="flex">
<el-card class="w-1/2 dict" :gutter="12" shadow="always">
<template #header>
<div class="card-header">
<span>字典分类</span>
</div>
</template>
<Search
:schema="DictTypeSchemas.allSchemas.searchSchema"
@search="setTypeSearchParams"
@reset="setTypeSearchParams"
/>
<!-- 操作工具栏 -->
<div class="mb-10px">
<XButton
type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
v-hasPermi="['system:dict:create']"
@click="handleTypeCreate()"
/>
</div>
<!-- 列表 -->
<Table
@row-click="onClickType"
:columns="DictTypeSchemas.allSchemas.tableColumns"
:selection="false"
:data="typeTableObject.tableList"
:loading="typeTableObject.loading"
:pagination="{
total: typeTableObject.total
}"
:highlight-current-row="true"
v-model:pageSize="typeTableObject.pageSize"
v-model:currentPage="typeTableObject.currentPage"
@register="typeRegister"
>
<template #status="{ row }">
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
</template>
<template #action="{ row }">
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:dict:update']"
@click="handleTypeUpdate(row)"
/>
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['system:dict:delete']"
@click="delTypeList(row.id, false)"
/>
</template>
</Table>
</el-card>
<el-card class="w-1/2 dict" style="margin-left: 10px" :gutter="12" shadow="hover">
<template #header>
<div class="card-header">
<span>字典数据</span>
</div>
</template>
<!-- 列表 -->
<div v-if="!tableTypeSelect">
<span>请从左侧选择</span>
</div>
<div v-if="tableTypeSelect">
<Search
:schema="DictDataSchemas.allSchemas.searchSchema"
@search="setDataSearchParams"
@reset="setDataSearchParams"
/>
<!-- 操作工具栏 -->
<div class="mb-10px">
<XButton
type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
v-hasPermi="['system:dict:create']"
@click="handleDataCreate()"
/>
</div>
<Table
:columns="DictDataSchemas.allSchemas.tableColumns"
:selection="false"
:data="dataTableObject.tableList"
:loading="dataTableObject.loading"
:pagination="{
total: dataTableObject.total
}"
v-model:pageSize="dataTableObject.pageSize"
v-model:currentPage="dataTableObject.currentPage"
@register="dataRegister"
>
<template #status="{ row }">
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
</template>
<template #action="{ row }">
<XTextButton
v-hasPermi="['system:dict:update']"
preIcon="ep:edit"
:title="t('action.edit')"
@click="handleDataUpdate(row)"
/>
<XTextButton
v-hasPermi="['system:dict:delete']"
preIcon="ep:delete"
:title="t('action.del')"
@click="delDataList(row.id, false)"
/>
</template>
</Table>
</div>
</el-card>
<XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle">
<template #default>
<Form
v-if="['typeCreate', 'typeUpdate'].includes(actionType)"
:schema="DictTypeSchemas.allSchemas.formSchema"
:rules="DictTypeSchemas.dictTypeRules"
ref="typeFormRef"
/>
<Form
v-if="['dataCreate', 'dataUpdate'].includes(actionType)"
:schema="DictDataSchemas.allSchemas.formSchema"
:rules="DictDataSchemas.dictDataRules"
ref="dataFormRef"
/>
</template>
<!-- 操作按钮 -->
<template #footer>
<XButton
v-if="['typeCreate', 'typeUpdate'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitTypeForm"
/>
<XButton
v-if="['dataCreate', 'dataUpdate'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitDataForm"
/>
<XButton :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</div>
</template>
<script setup lang="ts">
import { ref, unref, onMounted } from 'vue'
import { DICT_TYPE } from '@/utils/dict'
@ -148,155 +299,3 @@ onMounted(async () => {
typeTableObject.tableList[0] && onClickType(typeTableObject.tableList[0])
})
</script>
<template>
<div class="flex">
<el-card class="w-1/2 dict" :gutter="12" shadow="always">
<template #header>
<div class="card-header">
<span>字典分类</span>
</div>
</template>
<Search
:schema="DictTypeSchemas.allSchemas.searchSchema"
@search="setTypeSearchParams"
@reset="setTypeSearchParams"
/>
<!-- 操作工具栏 -->
<div class="mb-10px">
<el-button type="primary" v-hasPermi="['system:dict:create']" @click="handleTypeCreate">
<Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
</el-button>
</div>
<!-- 列表 -->
<Table
@row-click="onClickType"
:columns="DictTypeSchemas.allSchemas.tableColumns"
:selection="false"
:data="typeTableObject.tableList"
:loading="typeTableObject.loading"
:pagination="{
total: typeTableObject.total
}"
:highlight-current-row="true"
v-model:pageSize="typeTableObject.pageSize"
v-model:currentPage="typeTableObject.currentPage"
@register="typeRegister"
>
<template #status="{ row }">
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
</template>
<template #action="{ row }">
<el-button
link
type="primary"
v-hasPermi="['system:dict:update']"
@click="handleTypeUpdate(row)"
>
<Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
</el-button>
<el-button
link
type="primary"
v-hasPermi="['system:dict:delete']"
@click="delTypeList(row.id, false)"
>
<Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
</el-button>
</template>
</Table>
</el-card>
<el-card class="w-1/2 dict" style="margin-left: 10px" :gutter="12" shadow="hover">
<template #header>
<div class="card-header">
<span>字典数据</span>
</div>
</template>
<!-- 列表 -->
<div v-if="!tableTypeSelect">
<span>请从左侧选择</span>
</div>
<div v-if="tableTypeSelect">
<Search
:schema="DictDataSchemas.allSchemas.searchSchema"
@search="setDataSearchParams"
@reset="setDataSearchParams"
/>
<!-- 操作工具栏 -->
<div class="mb-10px">
<el-button type="primary" v-hasPermi="['system:dict:create']" @click="handleDataCreate">
<Icon icon="ep:zoom-in" class="mr-1px" /> {{ t('action.add') }}
</el-button>
</div>
<Table
:columns="DictDataSchemas.allSchemas.tableColumns"
:selection="false"
:data="dataTableObject.tableList"
:loading="dataTableObject.loading"
:pagination="{
total: dataTableObject.total
}"
v-model:pageSize="dataTableObject.pageSize"
v-model:currentPage="dataTableObject.currentPage"
@register="dataRegister"
>
<template #status="{ row }">
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
</template>
<template #action="{ row }">
<el-button
link
type="primary"
v-hasPermi="['system:dict:update']"
@click="handleDataUpdate(row)"
>
<Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
</el-button>
<el-button
link
type="primary"
v-hasPermi="['system:dict:delete']"
@click="delDataList(row.id, false)"
>
<Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
</el-button>
</template>
</Table>
</div>
</el-card>
<Dialog v-model="dialogVisible" :title="dialogTitle">
<Form
v-if="['typeCreate', 'typeUpdate'].includes(actionType)"
:schema="DictTypeSchemas.allSchemas.formSchema"
:rules="DictTypeSchemas.dictTypeRules"
ref="typeFormRef"
/>
<Form
v-if="['dataCreate', 'dataUpdate'].includes(actionType)"
:schema="DictDataSchemas.allSchemas.formSchema"
:rules="DictDataSchemas.dictDataRules"
ref="dataFormRef"
/>
<!-- 操作按钮 -->
<template #footer>
<el-button
v-if="['typeCreate', 'typeUpdate'].includes(actionType)"
type="primary"
:loading="actionLoading"
@click="submitTypeForm"
>
{{ t('action.save') }}
</el-button>
<el-button
v-if="['dataCreate', 'dataUpdate'].includes(actionType)"
type="primary"
:loading="actionLoading"
@click="submitDataForm"
>
{{ t('action.save') }}
</el-button>
<el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
</template>
</Dialog>
</div>
</template>

View File

@ -60,9 +60,9 @@
<template #footer>
<XButton
v-if="['create', 'update'].includes(actionType)"
:loading="actionLoading"
:title="t('action.save')"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitForm"
/>
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
@ -79,35 +79,31 @@ import { rules, allSchemas } from './post.data'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeFormEvents, VxeGridInstance } from 'vxe-table'
import { VxeGridInstance } from 'vxe-table'
import { FormExpose } from '@/components/Form'
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const xGrid = ref<VxeGridInstance>()
const formRef = ref<FormExpose>() // 表单 Ref
const dialogVisible = ref(false) // 是否显示弹出层
const dialogTitle = ref('edit') // 弹出层标题
const actionType = ref('') // 操作按钮的类型
const actionLoading = ref(false) // 按钮Loading
const xGrid = ref<VxeGridInstance>() // grid Ref
const formRef = ref<FormExpose>() // 表单 Ref
const detailRef = ref() // 详情 Ref
const { gridOptions } = useVxeGrid<PostVO>({
allSchemas: allSchemas,
getListApi: PostApi.getPostPageApi
})
// 设置标题
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
// ========== 详情相关 ==========
const detailRef = ref() // 详情 Ref
// 详情操作
const handleDetail = (row: PostVO) => {
setDialogTile('detail')
detailRef.value = row
}
// 新增操作
const handleCreate = () => {
setDialogTile('create')
@ -115,6 +111,12 @@ const handleCreate = () => {
unref(formRef)?.getElFormRef()?.resetFields()
}
// 详情操作
const handleDetail = (row: PostVO) => {
setDialogTile('detail')
detailRef.value = row
}
// 修改操作
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
@ -122,6 +124,7 @@ const handleUpdate = async (rowId: number) => {
const res = await PostApi.getPostApi(rowId)
unref(formRef)?.setValues(res)
}
// 删除操作
const handleDelete = async (rowId: number) => {
message
@ -134,8 +137,9 @@ const handleDelete = async (rowId: number) => {
xGrid.value?.commitProxy('query')
})
}
// 提交按钮
const submitForm: VxeFormEvents.Submit = async () => {
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
@ -151,7 +155,6 @@ const submitForm: VxeFormEvents.Submit = async () => {
await PostApi.updatePostApi(data)
message.success(t('common.updateSuccess'))
}
// 操作成功,重新加载列表
dialogVisible.value = false
} finally {
actionLoading.value = false

View File

@ -1,8 +1,8 @@
import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
@ -17,7 +17,7 @@ const crudSchemas = reactive<VxeCrudSchema[]>([
{
title: t('common.index'),
field: 'id',
type: 'index',
type: 'seq',
form: {
show: false
},