This commit is contained in:
2024-11-06 21:15:49 +08:00
parent 07ccde9f59
commit dc7e9d40e7
2 changed files with 319 additions and 307 deletions

View File

@@ -1,144 +1,149 @@
<template>
<div class='table-box' ref='popupBaseView'>
<ProTable
<div class='table-box' ref='popupBaseView'>
<ProTable
ref='proTable'
:columns='columns'
:init-param="initParam"
:request-api='getPqDevList'
>
<!-- :requestApi="getRoleList" -->
<!-- 表格 header 按钮 -->
<template #tableHeader='scope'>
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
<el-button type='primary' :icon='Download' plain @click='downloadFile()'>批量导</el-button>
<el-button type='primary' :icon='Upload' plain @click='importFile()'>批量导入</el-button>
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected' @click='batchDelete(scope.selectedListIds)'>
批量删除
</el-button>
</template>
<!-- 表格操作 -->
<template #operation='scope'>
<el-button type='primary' link :icon='EditPen' @click="openDialog('edit', scope.row)">编辑</el-button>
<el-button type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button>
:request-api='getTableList'
>
<!-- :requestApi="getRoleList" -->
<!-- 表格 header 按钮 -->
<template #tableHeader='scope'>
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
<el-button type='primary' :icon='Download' plain @click='downloadFile()'>批量导出</el-button>
<el-button type='primary' :icon='Upload' plain @click='importFile()'>批量导</el-button>
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
@click='batchDelete(scope.selectedListIds)'>
批量删除
</el-button>
</template>
<!-- 表格操作 -->
<template #operation='scope'>
<el-button type='primary' link :icon='EditPen' @click="openDialog('edit', scope.row)">编辑</el-button>
<el-button type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button>
</template>
</ProTable>
</div>
<DevicePopup :refresh-table='proTable?.getTableList' ref='devicePopup'/>
</template>
<script setup lang='tsx' name='useRole'>
import TimeControl from '@/components/TimeControl/index.vue'
import { type Device } from '@/api/device/interface'
import { useHandleData } from '@/hooks/useHandleData'
import { useDownload } from '@/hooks/useDownload'
import { useAuthButtons } from '@/hooks/useAuthButtons'
import ProTable from '@/components/ProTable/index.vue'
import ImportExcel from '@/components/ImportExcel/index.vue'
import { type ProTableInstance, type ColumnProps } from '@/components/ProTable/interface'
import DevicePopup from '@/views/machine/device/components/devicePopup.vue'
import { CirclePlus, Delete, EditPen, Share, Download, Upload, View, Refresh } from '@element-plus/icons-vue'
import deviceDataList from '@/api/device/deviceData'
import { useDictStore } from '@/stores/modules/dict'
import {getPqDevList,deletePqDev,exportPqDev,importPqDev} from '@/api/device/device.ts'
import { reactive, ref } from 'vue'
const dictStore = useDictStore()
// ProTable 实例
const proTable = ref<ProTableInstance>()
const devicePopup = ref()
// 定义包含和排除的单位
const includedUnits = ['日', '周', '月', '自定义']; // 可以根据需要包含的单位
const excludedUnits = ['季度','年']; // 要排除的单位
const defaultUnits = '日'; // 默认的单位
// 表格配置项
const columns = reactive<ColumnProps<Device.ResPqDev>[]>([
{ type: 'selection', fixed: 'left', width: 70 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
{
prop: 'name',
label: '名称',
search: { el: 'input' },
minWidth: 200,
},
{
prop: 'devType',
label: '类型',
enum: dictStore.getDictData('High_Cate'),
search: { el: 'select', props: { filterable: true } },
fieldNames: { label: 'name', value: 'code' },
minWidth: 200,
},
{
prop: 'devChns',
label: '设备通道数',
minWidth: 110,
},
{
prop: 'devVolt',
label: '额定电压V',
minWidth: 130,
},
{
prop: 'devCurr',
label: '额定电流A',
minWidth: 130,
},
{
prop: 'manufacturer',
label: '制作厂商',
minWidth: 200,
},
{
prop: 'createDate',
label: '生产日期',
minWidth: 200,
search: {
</ProTable>
</div>
<DevicePopup :refresh-table='proTable?.getTableList' ref='devicePopup' />
</template>
<script setup lang='tsx' name='useRole'>
import TimeControl from '@/components/TimeControl/index.vue'
import { type Device } from '@/api/device/interface'
import { useHandleData } from '@/hooks/useHandleData'
import { useDownload } from '@/hooks/useDownload'
import { useAuthButtons } from '@/hooks/useAuthButtons'
import ProTable from '@/components/ProTable/index.vue'
import ImportExcel from '@/components/ImportExcel/index.vue'
import { type ProTableInstance, type ColumnProps } from '@/components/ProTable/interface'
import DevicePopup from '@/views/machine/device/components/devicePopup.vue'
import { CirclePlus, Delete, EditPen, Share, Download, Upload, View, Refresh } from '@element-plus/icons-vue'
import deviceDataList from '@/api/device/deviceData'
import { useDictStore } from '@/stores/modules/dict'
import { getPqDevList, deletePqDev, exportPqDev, importPqDev } from '@/api/device/device.ts'
import { reactive, ref } from 'vue'
const dictStore = useDictStore()
// ProTable 实例
const proTable = ref<ProTableInstance>()
const devicePopup = ref()
// 定义包含和排除的单位
const getTableList = (params: any) => {
let newParams = JSON.parse(JSON.stringify(params))
newParams.createTimeEnd = endDate.value
newParams.createTimeStart = startDate.value
return getPqDevList(newParams)
}
// 表格配置项
const columns = reactive<ColumnProps<Device.ResPqDev>[]>([
{ type: 'selection', fixed: 'left', width: 70 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
{
prop: 'name',
label: '名称',
search: { el: 'input' },
minWidth: 200,
},
{
prop: 'devType',
label: '类型',
enum: dictStore.getDictData('High_Cate'),
search: { el: 'select', props: { filterable: true } },
fieldNames: { label: 'name', value: 'code' },
minWidth: 200,
},
{
prop: 'devChns',
label: '设备通道数',
minWidth: 110,
},
{
prop: 'devVolt',
label: '额定电压V',
minWidth: 130,
},
{
prop: 'devCurr',
label: '额定电流A',
minWidth: 130,
},
{
prop: 'manufacturer',
label: '制作厂商',
minWidth: 200,
},
{
prop: 'createDate',
label: '生产日期',
minWidth: 200,
search: {
span: 2,
render: () => {
return (
<div class='flx-flex-start'>
<TimeControl
include={includedUnits}
exclude={excludedUnits}
default={defaultUnits}
onUpdate-dates={handleDateChange}
/>
</div>
<div class='flx-flex-start'>
<TimeControl
include={['日', '周', '月', '自定义']}
default={'月'}
onUpdate-dates={handleDateChange}
/>
</div>
)
},
},
},
{ prop: 'operation', label: '操作', fixed: 'right', width: 200 },
])
},
{ prop: 'operation', label: '操作', fixed: 'right', width: 200 },
])
// 处理日期变化的回调函数
const handleDateChange = (startDate: Date, endDate: Date) => {
console.log('Start Date:', startDate)
console.log('End Date:', endDate)
// 这里可以添加更多的逻辑处理
// 处理日期变化的回调函数
const startDate = ref('')
const endDate = ref('')
const handleDateChange = (startDateTemp: string, endDateTemp: string) => {
startDate.value = startDateTemp
endDate.value = endDateTemp
console.log(startDateTemp)
console.log(endDateTemp)
}
// 打开 drawer(新增、编辑)
const openDialog = (titleType: string, row: Partial<Device.ResPqDev> = {}) => {
devicePopup.value?.open(titleType, row)
}
// 批量删除字典类型
const batchDelete = async (id: string[]) => {
await useHandleData(deletePqDev, id, '删除所选设备')
proTable.value?.clearSelection()
proTable.value?.getTableList()
}
// 删除字典类型
const handleDelete = async (params: Device.ResPqDev) => {
await useHandleData(deletePqDev, [params.id], `删除【${params.name}】设备`)
proTable.value?.getTableList()
}
</script>
// 打开 drawer(新增、编辑)
const openDialog = (titleType: string, row: Partial<Device.ResPqDev> = {}) => {
devicePopup.value?.open(titleType, row)
}
// 批量删除字典类型
const batchDelete = async (id: string[]) => {
await useHandleData(deletePqDev, id, '删除所选设备')
proTable.value?.clearSelection()
proTable.value?.getTableList()
}
// 删除字典类型
const handleDelete = async (params: Device.ResPqDev) => {
await useHandleData(deletePqDev, [params.id], `删除【${params.name}】设备`)
proTable.value?.getTableList()
}
</script>