定义defaultDialog .vue
<script lang="ts" setup>
import { ref,toRefs,onUpdated } from 'vue'
import { ElMessageBox } from 'element-plus'
const props =defineProps({
msg:String,
show:{
type:Boolean,
default:false
},
title: {
type:String,
require: '',
default: '中型弹窗'
},
noFooter: {
type:Boolean,
require: false,
default: false
}
})
const emit = defineEmits<{
close: []
cancel: []
save: []
}>()
const close = () => {
emit('close')
}
const save = () =>{
emit('save')
}
const cancel = (val:any) => {
emit('cancel')
}
const createForm1 = ref(null)
const createForm2 = ref(null)
onUpdated(()=>{
document.getElementById("div");
let height1 = createForm1.value
})
</script>
<template>
<div class="myDialog">
<el-dialog
width="104rem"
style="height: 67%;min-height: 620px;min-width: 900px;"
:title="props.title"
v-model="props.show"
v-dialogDrag
v-if="props.show"
:before-close="close"
>
<!-- 自定义插槽 noFooter为true的时候,不显示footer的插槽-->
<slot name="dia_Content"></slot>
<div
class="dialog-footer"
v-if="noFooter ? false : true"
>
<el-button type="primary" size="large" @click="save" color="#4088FE"> 确 定 </el-button>
<div style="width: 4rem;"></div>
<el-button size="large" @click="cancel" color="rgba(132, 158, 199, 1)"> 取 消 </el-button>
</div>
</el-dialog>
</div>
</template>
<style lang="scss" scoped>
.el-form-item__content{
width: 100%;
}
:deep(.el-cascader.el-tooltip__trigger.el-tooltip__trigger){
width: 100% !important;
}
:deep(.el-input.el-input--prefix.el-input--suffix.el-date-editor.el-date-editor--date.el-tooltip__trigger.el-tooltip__trigger){
width: 100% !important;
}
.myDialog{
color: #26315E;
}
.dialog-footer{
display: flex;
justify-content: center;
align-items: center;
}
:deep(.el-button--large){
padding: 1.6rem 4rem;
font-size: 2rem;
color: white;
}
:deep(.el-dialog__title){
font-size: 24px;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #26315E;
}
:deep(.el-dialog) {
border-radius: 8px !important;
}
:deep(.el-dialog__body){
padding-top: 2.4rem;
height: 100%;
}
:deep(.el-dialog__headerbtn) {
top: 8px !important;
background: url('@/assets/img/componentImg/off.png') left no-repeat;
}
:deep(.el-dialog__headerbtn i) {
font-size: 25px;
visibility: hidden;
}
:deep(.el-form-item){
}
:deep(.el-overlay){
background: rgba(0,0,0,0.8);
}
:deep(.el-input__inner){
height: 40px;
}
</style>
页面使用
import defaultDialog from "@/components/Dialog/defaultDialog.vue"
<defaultDialog
:title="EquipmentEditData.title"
@save="saveUserEdit(createFormRef)"
:show="EquipmentEditData.visible" :
noFooter=false @cancel="closeUserEdit"
@close="closeUserEdit">
<template #dia_Content>
</template>
</defaultDialog>
分页
首先创建个usePagination.ts
import { reactive } from "vue"
interface DefaultPaginationData {
total: number
currentPage: number
pageSizes: number[]
pageSize: number
layout: string
}
interface PaginationData {
total?: number
currentPage?: number
pageSizes?: number[]
pageSize?: number
layout?: string
}
export function usePagination(initialPaginationData: PaginationData = {}) {
const defaultPaginationData: DefaultPaginationData = {
total: 0,
currentPage: 1,
pageSizes: [10, 20, 50],
pageSize: 18,
layout: "prev, pager, next, jumper, total, sizes"
}
const paginationData = reactive({ ...defaultPaginationData, ...initialPaginationData })
const handleCurrentChange = (value: number) => {
paginationData.currentPage = value
}
const handleSizeChange = (value: number) => {
paginationData.pageSize = value
}
return { paginationData, handleCurrentChange, handleSizeChange }
}
使用页面
import { usePagination } from "@/hooks/usePagination"
const { paginationData, handleCurrentChange, handleSizeChange } = usePagination({ pageSize: 15, pageSizes: [15, 30, 50], layout: "prev, pager, next, jumper, total, sizes" })```
watch([() => paginationData.currentPage, () => paginationData.pageSize], getTableData, { immediate: true })
<el-pagination background :layout="paginationData.layout" :page-sizes="paginationData.pageSizes"
:total="paginationData.total" :page-size="paginationData.pageSize"
:currentPage="paginationData.currentPage" @size-change="handleSizeChange"
@current-change="handleCurrentChange" />