修改测试问题

This commit is contained in:
guanj
2025-11-14 09:33:35 +08:00
parent d9efb37083
commit 6303bd1e2c
6 changed files with 256 additions and 218 deletions

View File

@@ -1,24 +1,44 @@
<template>
<div :style="{ height: typeof props.height === 'string' ? props.height : tableStore.table.height }">
<vxe-table ref="tableRef" height="auto" :key="key" :data="tableStore.table.data"
v-loading="tableStore.table.loading" v-bind="Object.assign({}, defaultAttribute, $attrs)"
@checkbox-all="selectChangeEvent" @checkbox-change="selectChangeEvent" :showOverflow="showOverflow"
:sort-config="{ remote: true }" @sort-change="handleSortChange">
<vxe-table
ref="tableRef"
height="auto"
:key="key"
:data="tableStore.table.data"
v-loading="tableStore.table.loading"
v-bind="Object.assign({}, defaultAttribute, $attrs)"
@checkbox-all="selectChangeEvent"
@checkbox-change="selectChangeEvent"
:showOverflow="showOverflow"
:sort-config="{ remote: true }"
@sort-change="handleSortChange"
>
<!-- Column 组件内部是 el-table-column -->
<template v-if="isGroup">
<GroupColumn :column="tableStore.table.column" />
</template>
<template v-else>
<Column :attr="item" :key="key + '-column'" v-for="(item, key) in tableStore.table.column"
:tree-node="item.treeNode">
<Column
:attr="item"
:key="key + '-column'"
v-for="(item, key) in tableStore.table.column"
:tree-node="item.treeNode"
>
<!-- tableStore 预设的列 render 方案 -->
<template v-if="item.render" #default="scope">
<FieldRender :field="item" :row="scope.row" :column="scope.column" :index="scope.rowIndex" :key="key +
'-' +
item.render +
'-' +
(item.field ? '-' + item.field + '-' + scope.row[item.field] : '')
" />
<FieldRender
:field="item"
:row="scope.row"
:column="scope.column"
:index="scope.rowIndex"
:key="
key +
'-' +
item.render +
'-' +
(item.field ? '-' + item.field + '-' + scope.row[item.field] : '')
"
/>
</template>
</Column>
</template>
@@ -27,11 +47,16 @@
</div>
<div v-if="tableStore.showPage" class="table-pagination">
<el-pagination :currentPage="tableStore.table.params!.pageNum" :page-size="tableStore.table.params!.pageSize"
:page-sizes="pageSizes" background
<el-pagination
:currentPage="tableStore.table.params!.pageNum"
:page-size="tableStore.table.params!.pageSize"
:page-sizes="pageSizes"
background
:layout="config.layout.shrink ? 'prev, next, jumper' : 'sizes,total, ->, prev, pager, next, jumper'"
:total="tableStore.table.total" @size-change="onTableSizeChange"
@current-change="onTableCurrentChange"></el-pagination>
:total="tableStore.table.total"
@size-change="onTableSizeChange"
@current-change="onTableCurrentChange"
></el-pagination>
</div>
<slot name="footer"></slot>
</template>
@@ -125,6 +150,7 @@ watch(
() => tableStore.table.allFlag,
newVal => {
if (tableStore.table.allFlag) {
console.log('🚀 ~ tableStore.table.allData:', tableStore.table.allData)
tableRef.value?.exportData({
filename: tableStore.exportName || document.querySelectorAll('.ba-nav-tab.active')[0].textContent || '', // 文件名字

View File

@@ -18,6 +18,7 @@ interface TableStoreParams {
publicHeight?: number //计算高度
resetCallback?: () => void // 重置
loadCallback?: () => void // 接口调用后的回调
exportProcessingData?: () => void //导出处理数据
beforeSearchFun?: () => void // 接口调用前的回调
}
@@ -47,6 +48,7 @@ export default class TableStore {
column: [],
loadCallback: null,
resetCallback: null,
exportProcessingData: null,
beforeSearchFun: null,
height: '',
publicHeight: 0
@@ -64,6 +66,7 @@ export default class TableStore {
this.table.publicHeight = options.publicHeight || 0
this.table.resetCallback = options.resetCallback || null
this.table.loadCallback = options.loadCallback || null
this.table.exportProcessingData = options.exportProcessingData || null
this.table.beforeSearchFun = options.beforeSearchFun || null
Object.assign(this.table.params, options.params)
this.table.height = mainHeight(20 + (this.showPage ? 58 : 0) + this.table.publicHeight).height as string
@@ -187,26 +190,21 @@ export default class TableStore {
[
'export',
() => {
ElMessage({
message: '正在导出,请稍等...',
type: 'info',
duration: 1000
})
// this.index()
let params = { ...this.table.params, pageNum: 1, pageSize: this.table.total }
setTimeout(() => {
createAxios(
Object.assign(
{
url: this.url,
method: this.method
},
requestPayload(this.method, params, this.paramsPOST)
)
).then(res => {
this.table.allData = filtration(res.data.records || res.data)
this.table.allFlag = data.showAllFlag || true
})
}, 1500)
createAxios(
Object.assign(
{
url: this.url,
method: this.method
},
requestPayload(this.method, params, this.paramsPOST)
)
).then(res => {
this.table.allData = filtration(res.data.records || res.data)
this.table.exportProcessingData && this.table.exportProcessingData()
this.table.allFlag = data.showAllFlag || true
})
}
]
])

View File

@@ -1,162 +1,164 @@
<template>
<div class="default-main" style="display: flex" :style="{ height: height }">
<div style="flex: 1; overflow: hidden">
<div class="custom-table-header">
<div class="title">角色列表</div>
<el-button :icon="Plus" type="primary" @click="addRole" class="ml10">新增</el-button>
</div>
<Table ref="tableRef" @currentChange="currentChange" />
</div>
<Tree
v-if="menuListId"
ref="treeRef"
show-checkbox
width="350px"
:data="menuTree"
:checkStrictly="checkStrictly"
@check-change="checkChange"
></Tree>
<el-empty style="width: 350px; padding-top: 300px; box-sizing: border-box" description="请选择角色" v-else />
<PopupForm ref="popupRef"></PopupForm>
</div>
</template>
<script setup lang="ts">
import { Plus } from '@element-plus/icons-vue'
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import Tree from '@/components/tree/index.vue'
import { functionTree } from '@/api/user-boot/function'
import { getFunctionsByRoleIndex, updateRoleMenu } from '@/api/user-boot/roleFuction'
import { mainHeight } from '@/utils/layout'
import { del } from '@/api/user-boot/role'
import { ElMessage } from 'element-plus'
import PopupForm from './popupForm.vue'
import { useAdminInfo } from '@/stores/adminInfo'
const adminInfo = useAdminInfo()
defineOptions({
name: 'auth/role'
})
const height = mainHeight(20).height
const treeRef = ref()
const menuTree = ref<treeData[]>([])
const popupRef = ref()
const checkStrictly = ref(true)
const menuListId = ref('')
const tableStore = new TableStore({
showPage: false,
url: '/user-boot/role/selectRoleDetail?id=' + adminInfo.$state.userType,
method: 'POST',
column: [
{ title: '角色名称', field: 'name', align: 'center' },
{ title: '角色编码', field: 'code', align: 'center' },
{ title: '备注', field: 'remark', align: 'center' },
{
title: '状态',
field: 'state',
width: '80',
render: 'tag',
custom: {
0: 'danger',
1: 'success'
},
replaceValue: {
0: '注销',
1: '正常'
}
},
{
title: '操作',
align: 'center',
width: '180',
render: 'buttons',
buttons: [
{
name: 'edit',
title: '编辑',
type: 'primary',
icon: 'el-icon-EditPen',
render: 'basicButton',
click: row => {
popupRef.value.open('编辑角色', row)
}
},
{
name: 'del',
title: '删除',
type: 'danger',
icon: 'el-icon-Delete',
render: 'confirmButton',
popconfirm: {
confirmButtonText: '确认',
cancelButtonText: '取消',
confirmButtonType: 'danger',
title: '确定删除该角色吗?'
},
click: row => {
del([row.id]).then(() => {
ElMessage.success('删除成功')
tableStore.index()
})
}
}
]
}
]
})
tableStore.table.params.searchValue = ''
provide('tableStore', tableStore)
const filterData = (arr: any[]) => {
// return arr.filter((item: any) => {
// item.name = item.title
// if (item.children.length) {
// item.children = filterData(item.children)
// }
// return item.type === 0
// })
arr.forEach((item: any) => {
item.name = item.title
if (item.children.length) {
filterData(item.children)
}
})
}
functionTree().then((res: any) => {
filterData(res.data)
menuTree.value = res.data
})
const currentChange = (data: any) => {
checkStrictly.value = true
menuListId.value = data.row.id
getFunctionsByRoleIndex({ id: data.row.id }).then((res: any) => {
treeRef.value.treeRef.setCheckedKeys(res.data.map((item: any) => item.id))
})
}
const timeout = ref<NodeJS.Timeout>()
const checkChange = (data: any) => {
if (checkStrictly.value) {
checkStrictly.value = false
return
}
if (timeout.value) {
clearTimeout(timeout.value)
}
timeout.value = setTimeout(() => {
updateRoleMenu({
id: menuListId.value,
idList: treeRef.value.treeRef.getCheckedNodes(false, true).map((node: any) => node.id)
})
}, 1000)
}
onMounted(() => {
tableStore.index()
})
const addRole = () => {
popupRef.value.open('新增角色')
}
</script>
<template>
<div class="default-main" style="display: flex" :style="{ height: height }">
<div style="flex: 1; overflow: hidden">
<div class="custom-table-header">
<div class="title">角色列表</div>
<el-button :icon="Plus" type="primary" @click="addRole" class="ml10">新增</el-button>
</div>
<Table ref="tableRef" @currentChange="currentChange" />
</div>
<Tree
v-if="menuListId"
ref="treeRef"
show-checkbox
width="350px"
:data="menuTree"
:checkStrictly="checkStrictly"
@check-change="checkChange"
></Tree>
<el-empty style="width: 350px; padding-top: 300px; box-sizing: border-box" description="请选择角色" v-else />
<PopupForm ref="popupRef"></PopupForm>
</div>
</template>
<script setup lang="ts">
import { Plus } from '@element-plus/icons-vue'
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import Tree from '@/components/tree/index.vue'
import { functionTree } from '@/api/user-boot/function'
import { getFunctionsByRoleIndex, updateRoleMenu } from '@/api/user-boot/roleFuction'
import { mainHeight } from '@/utils/layout'
import { del } from '@/api/user-boot/role'
import { ElMessage } from 'element-plus'
import PopupForm from './popupForm.vue'
import { useAdminInfo } from '@/stores/adminInfo'
const adminInfo = useAdminInfo()
defineOptions({
name: 'auth/role'
})
const height = mainHeight(20).height
const treeRef = ref()
const menuTree = ref<treeData[]>([])
const popupRef = ref()
const checkStrictly = ref(true)
const menuListId = ref('')
const tableStore = new TableStore({
showPage: false,
url: '/user-boot/role/selectRoleDetail?id=' + adminInfo.$state.userType,
method: 'POST',
column: [
{ title: '角色名称', field: 'name', align: 'center' },
{ title: '角色编码', field: 'code', align: 'center' },
{ title: '备注', field: 'remark', align: 'center' },
{
title: '状态',
field: 'state',
width: '80',
render: 'tag',
custom: {
0: 'danger',
1: 'success'
},
replaceValue: {
0: '注销',
1: '正常'
}
},
{
title: '操作',
align: 'center',
width: '180',
render: 'buttons',
buttons: [
{
name: 'edit',
title: '编辑',
type: 'primary',
icon: 'el-icon-EditPen',
render: 'basicButton',
click: row => {
popupRef.value.open('编辑角色', row)
}
},
{
name: 'del',
title: '删除',
type: 'danger',
icon: 'el-icon-Delete',
render: 'confirmButton',
popconfirm: {
confirmButtonText: '确认',
cancelButtonText: '取消',
confirmButtonType: 'danger',
title: '确定删除该角色吗?'
},
click: row => {
del([row.id]).then(() => {
ElMessage.success('删除成功')
tableStore.index()
})
}
}
]
}
]
})
tableStore.table.params.searchValue = ''
provide('tableStore', tableStore)
const filterData = (arr: any[]) => {
// return arr.filter((item: any) => {
// item.name = item.title
// if (item.children.length) {
// item.children = filterData(item.children)
// }
// return item.type === 0
// })
arr.forEach((item: any) => {
item.name = item.title
if (item.children.length) {
filterData(item.children)
}
})
}
functionTree().then((res: any) => {
filterData(res.data)
menuTree.value = res.data
})
const currentChange = (data: any) => {
checkStrictly.value = true
menuListId.value = data.row.id
getFunctionsByRoleIndex({ id: data.row.id }).then((res: any) => {
treeRef.value.treeRef.setCheckedKeys(res.data.map((item: any) => item.id))
})
}
const timeout = ref<NodeJS.Timeout>()
const checkChange = (data: any) => {
if (checkStrictly.value) {
checkStrictly.value = false
return
}
if (timeout.value) {
clearTimeout(timeout.value)
}
timeout.value = setTimeout(() => {
updateRoleMenu({
id: menuListId.value,
idList: treeRef.value.treeRef.getCheckedNodes(false, true).map((node: any) => node.id)
}).then(() => {
ElMessage.success('操作成功!')
})
}, 1000)
}
onMounted(() => {
tableStore.index()
})
const addRole = () => {
popupRef.value.open('新增角色')
}
</script>

View File

@@ -96,14 +96,14 @@ const tableStore = new TableStore({
fixed: 'right',
render: 'tag',
custom: {
功能调试: 'warning',
出厂调试: 'warning',
正式投运: 'success'
2: 'warning',
3: 'warning',
4: 'success'
},
replaceValue: {
功能调试: '功能调试',
出厂调试: '出厂调试',
正式投运: '正式投运'
2: '功能调试',
3: '出厂调试',
4: '正式投运'
},
minWidth: 80
},
@@ -142,11 +142,14 @@ const tableStore = new TableStore({
{ title: '完整性(%)', fixed: 'right', width: 100, field: 'integrity', sortable: true }
],
beforeSearchFun: () => {},
loadCallback: () => {
tableStore.table.data.forEach(item => {
exportProcessingData: () => {
tableStore.table.allData = tableStore.table.allData.filter(item => {
item.process = item.process == 2 ? '功能调试' : item.process == 3 ? '出厂调试' : '正式投运'
return item
})
console.log('🚀 ~ tableStore.table.allData:', tableStore.table.allData)
},
loadCallback: () => {
let name = tableStore.table.params.name
let data = tableStore.table.copyData.filter(item => {
// 处理latestTime默认值
@@ -182,7 +185,10 @@ const exportTab = () => {
sheetName: 'Sheet1',
type: 'xlsx', //导出文件类型 xlsx 和 csv
useStyle: true,
data: tableStore.table.copyData, // 数据源 // 过滤那个字段导出
data: tableStore.table.copyData.filter(item => {
item.process = item.process == 2 ? '功能调试' : item.process == 3 ? '出厂调试' : '正式投运'
return item
}), // 数据源 // 过滤那个字段导出
columnFilterMethod: function (column: any) {
return !(
column.column.title === undefined ||

View File

@@ -107,8 +107,8 @@ const editd = (e: any) => {
}
// 设计
const Aclick = (e: any) => {
// window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false&&graphicDisplay=zl`)
window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false&&graphicDisplay=zl`)
// window.open('http://192.168.1.128:4001' + `/zutai/?id=${e.id}&&name=${e.name}&&preview=false&&graphicDisplay=zl`)
}
// 删除
@@ -143,8 +143,8 @@ const deleted = (e: any) => {
}
const imgData = (e: any) => {
// window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true&&graphicDisplay=zl#/preview_ZL`)
window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true&&graphicDisplay=zl#/preview_ZL`)
window.open(window.location.origin + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true&&graphicDisplay=zl#/preview_ZL`)
// window.open('http://192.168.1.128:4001' + `/zutai/?id=${e.id}&&name=${e.name}&&preview=true&&graphicDisplay=zl#/preview_ZL`)
}

22
types/table.d.ts vendored
View File

@@ -8,8 +8,8 @@ declare global {
interface CnTable {
ref: VxeTableInstance | null
data: TableRow[] | any
copyData: TableRow[] | any
allData: TableRow[] | any
filename: any
allFlag: Boolean
// 前端分页数据
webPagingData: TableRow[][]
@@ -29,6 +29,7 @@ declare global {
loadCallback: (() => void) | null
resetCallback: (() => void) | null
beforeSearchFun: (() => void) | null
exportProcessingData: (() => void) | null
height: string
publicHeight: number
}
@@ -50,6 +51,7 @@ declare global {
| 'buttons'
| 'slot'
| 'customTemplate'
| 'renderFormatter'
| 'customRender'
// 默认值
default?: any
@@ -59,14 +61,15 @@ declare global {
custom?: any
// 值替换数据,如{open: '开'}
replaceValue?: any
effect?: any
// 时间格式化
timeFormat?: string
// 开关控制
onChangeField?: (row: TableRow, value: any) => void
activeValue?: string
inactiveValue?: string
activeText?: string
inactiveText?: string
// 开关控制
onChangeField?: (row: TableRow, value: any) => void
activeValue?: string
inactiveValue?: string
activeText?: string
inactiveText?: string
// 自定义组件/函数渲染
customRender?: string | Component
// 使用了 render 属性时,渲染前对字段值的预处理方法,请返回新值
@@ -80,6 +83,8 @@ declare global {
index: number
) => string
children?: TableColumn[]
property?: string
clickable?: boolean // 是否可点击
}
/* 表格右侧操作按钮 */
@@ -90,15 +95,16 @@ declare global {
title?: string
text?: string
class?: string
loading?: string
type: ButtonType
icon: string
popconfirm?: Partial<Mutable<PopconfirmProps>>
disabledTip?: boolean
// 自定义点击事件
click?: (row: TableRow, field: TableColumn) => void
// 按钮是否禁用,请返回布尔值
disabled?: (row: TableRow, field: TableColumn) => boolean
showDisabled?: (row: TableRow, field: TableColumn) => boolean
// 自定义el-button属性
attr?: Partial<Mutable<ButtonProps>>
}