表格模版修改

This commit is contained in:
仲么了
2024-02-26 20:36:18 +08:00
parent c5d953ba49
commit ed90f125be
3 changed files with 12 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue' import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue' import TableHeader from '@/components/table/header/index.vue'
import PopupEdit from './dialog.vue' import PopupEdit from './dialog.vue'
import { mainHeight } from '@/utils/layout'
// 注意名字不要重复若要保持页面存活名字需要和路由admin后面的字符保持一致 // 注意名字不要重复若要保持页面存活名字需要和路由admin后面的字符保持一致
defineOptions({ defineOptions({
@@ -37,6 +38,8 @@ defineOptions({
}) })
const popupEdit = ref() const popupEdit = ref()
const tableStore = new TableStore({ const tableStore = new TableStore({
// 若页面表格高度需要调整请修改publicHeight(内容区域除表格外其他内容的高度)
// publicHeight: 60,
url: '/user-boot/user/list', url: '/user-boot/user/list',
method: 'POST', method: 'POST',
column: [ column: [
@@ -153,8 +156,9 @@ const tableStore = new TableStore({
}) })
} }
}) })
// 注入到子组件
provide('tableStore', tableStore) provide('tableStore', tableStore)
// 默认参数 参数多的话可以使用Object.assign方法
tableStore.table.params.searchState = 1 tableStore.table.params.searchState = 1
tableStore.table.params.searchValue = '' tableStore.table.params.searchValue = ''
tableStore.table.params.casualUser = -1 tableStore.table.params.casualUser = -1
@@ -164,6 +168,7 @@ onMounted(() => {
tableStore.index() tableStore.index()
}) })
// 弹框
const addUser = () => { const addUser = () => {
popupEdit.value.open('新增用户') popupEdit.value.open('新增用户')
} }

View File

@@ -3,6 +3,7 @@ import createAxios from '@/utils/request'
import { requestPayload } from '@/utils/request' import { requestPayload } from '@/utils/request'
import { Method } from 'axios' import { Method } from 'axios'
import { mainHeight } from '@/utils/layout' import { mainHeight } from '@/utils/layout'
interface TableStoreParams { interface TableStoreParams {
url: string url: string
pk?: string pk?: string
@@ -39,7 +40,7 @@ export default class TableStore {
loadCallback: null, loadCallback: null,
resetCallback: null, resetCallback: null,
beforeSearchFun: null, beforeSearchFun: null,
height: mainHeight(20 + (this.showPage ? 58 : 0)).height as string, height: 0,
publicHeight: 0 publicHeight: 0
}) })
@@ -55,6 +56,7 @@ export default class TableStore {
this.table.loadCallback = options.loadCallback || null this.table.loadCallback = options.loadCallback || null
this.table.beforeSearchFun = options.beforeSearchFun || null this.table.beforeSearchFun = options.beforeSearchFun || null
Object.assign(this.table.params, options.params) Object.assign(this.table.params, options.params)
this.table.height = mainHeight(20 + (this.showPage ? 58 : 0) + this.table.publicHeight).height as string
} }
index() { index() {

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class='default-main'> <div>
<!-- 表头 --> <!-- 表头 -->
<TableHeader date-picker> <TableHeader date-picker>
<template v-slot:operation> <template v-slot:operation>
@@ -17,8 +17,10 @@ import { ElMessageBox, ElMessage } from 'element-plus'
import TableStore from '@/utils/tableStore' import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue' import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue' import TableHeader from '@/components/table/header/index.vue'
import { mainHeight } from '@/utils/layout'
const tableStore = new TableStore({ const tableStore = new TableStore({
publicHeight: 60,
url: '/user-boot/user/list', url: '/user-boot/user/list',
method: 'POST', method: 'POST',
column: [ column: [
@@ -115,7 +117,6 @@ const tableStore = new TableStore({
] ]
} }
], ],
loadCallback: () => { loadCallback: () => {
tableStore.table.data.forEach((item: any) => { tableStore.table.data.forEach((item: any) => {
item.deptName = item.deptName || '/' item.deptName = item.deptName || '/'
@@ -135,7 +136,6 @@ const tableStore = new TableStore({
}) })
} }
}) })
provide('tableStore', tableStore) provide('tableStore', tableStore)
tableStore.table.params.searchState = 1 tableStore.table.params.searchState = 1
tableStore.table.params.casualUser = -1 tableStore.table.params.casualUser = -1
@@ -146,6 +146,5 @@ onMounted(() => {
}) })
const addUser = () => { const addUser = () => {
popupEdit.value.open('新增用户')
} }
</script> </script>