Merge remote-tracking branch 'origin/master' into dev

# Conflicts:
#	frontend/src/views/system/dictionary/data.vue
This commit is contained in:
caozehui
2024-11-01 09:12:11 +08:00
5 changed files with 159 additions and 110 deletions

View File

@@ -23,8 +23,14 @@ interface Pageable {
total: number; total: number;
} }
interface ResPageable {
current: number;
size: number;
total: number;
}
interface PaginationProps { interface PaginationProps {
pageable: Pageable; pageable: ResPageable;
handleSizeChange: (size: number) => void; handleSizeChange: (size: number) => void;
handleCurrentChange: (currentPage: number) => void; handleCurrentChange: (currentPage: number) => void;
} }

View File

@@ -94,7 +94,7 @@
<slot name='pagination'> <slot name='pagination'>
<Pagination <Pagination
v-if='pagination' v-if='pagination'
:pageable='pageable' :pageable='resPageable'
:handle-size-change='handleSizeChange' :handle-size-change='handleSizeChange'
:handle-current-change='handleCurrentChange' :handle-current-change='handleCurrentChange'
/> />
@@ -173,6 +173,7 @@ const { selectionChange, selectedList, selectedListIds, isSelected } = useSelect
const { const {
tableData, tableData,
pageable, pageable,
resPageable,
searchParam, searchParam,
searchInitParam, searchInitParam,
getTableList, getTableList,
@@ -190,7 +191,7 @@ const clearSelection = () => tableRef.value!.clearSelection()
onMounted(() => { onMounted(() => {
dragSort() dragSort()
props.requestAuto && getTableList() props.requestAuto && getTableList()
props.data && (pageable.value.total = props.data.length) props.data && (resPageable.value.total = props.data.length)
}) })
// 处理表格数据 // 处理表格数据
@@ -198,8 +199,8 @@ const processTableData = computed(() => {
if (!props.data) return tableData.value if (!props.data) return tableData.value
if (!props.pagination) return props.data if (!props.pagination) return props.data
return props.data.slice( return props.data.slice(
(pageable.value.pageNum - 1) * pageable.value.pageSize, (resPageable.value.current - 1) * resPageable.value.size,
pageable.value.pageSize * pageable.value.pageNum, resPageable.value.size * resPageable.value.current,
) )
}) })

View File

@@ -4,9 +4,17 @@ export namespace Table {
pageSize: number; pageSize: number;
total: number; total: number;
} }
export interface ResPageable {
current: number;
size: number;
total: number;
}
export interface StateProps { export interface StateProps {
tableData: any[]; tableData: any[];
pageable: Pageable; pageable: Pageable;
resPageable: ResPageable;
searchParam: { searchParam: {
[key: string]: any; [key: string]: any;
}; };

View File

@@ -20,6 +20,15 @@ export const useTable = (
tableData: [], tableData: [],
// 分页数据 // 分页数据
pageable: { pageable: {
// 当前页数
pageNum: 1,
// 每页显示条数
pageSize: 10,
// 总条数
total: 0,
},
// 响应分页
resPageable: {
// 当前页数 // 当前页数
current: 1, current: 1,
// 每页显示条数 // 每页显示条数
@@ -71,9 +80,9 @@ export const useTable = (
state.tableData = isPageable ? data.records : data; state.tableData = isPageable ? data.records : data;
// 解构后台返回的分页数据 (如果有分页更新分页信息) // 解构后台返回的分页数据 (如果有分页更新分页信息)
if (isPageable) { if (isPageable) {
state.pageable.total = data.total; state.resPageable.total = data.total;
state.pageable.current = data.current; state.resPageable.current = data.current;
state.pageable.size = data.size; state.resPageable.size = data.size;
} }
} catch (error) { } catch (error) {
requestError && requestError(error); requestError && requestError(error);

View File

@@ -1,9 +1,12 @@
<template> <template>
<div class="table-box">
<el-dialog class='table-box' v-model='dialogVisible1' top='114px' <el-dialog class='table-box' v-model='dialogVisible1' top='114px'
:style="{ height: height, maxHeight: height, overflow: 'hidden' }" :title='title1' :width='width' :style="{ height: height, maxHeight: height, overflow: 'hidden' }" :title='title1' :width='width' :modal='false'>
:modal='false'> <div class="table-box">
<ProTable :columns="columns" :data="data"> <ProTable
ref='proTable'
:columns="columns"
:data="data"
>
<template #tableHeader="scope"> <template #tableHeader="scope">
<el-button type="primary" :icon="CirclePlus" @click="openDrawer('新增')">新增</el-button> <el-button type="primary" :icon="CirclePlus" @click="openDrawer('新增')">新增</el-button>
<el-button type="primary" :icon="Upload" plain @click="batchAdd">批量添加</el-button> <el-button type="primary" :icon="Upload" plain @click="batchAdd">批量添加</el-button>
@@ -19,26 +22,25 @@
<el-button type="primary" link :icon="Delete" @click="handleDelete(scope.row)">删除</el-button> <el-button type="primary" link :icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
</template> </template>
</ProTable> </ProTable>
</el-dialog>
</div> </div>
<el-dialog v-model="dialogVisible2" :title="dialogTitle" </el-dialog>
v-bind="dialogSmall"> <el-dialog v-model="dialogVisible2" :title="dialogType2 === '新增' ? '新增字典数据' : '编辑字典数据'" v-bind="dialogSmall">
<div> <div>
<el-form :model="formContent" ref="dialogFormRef" :rules="rules"> <el-form :model="dialogForm" ref="dialogFormRef" :rules="rules">
<el-form-item label="字典类型编码" :label-width="100"> <el-form-item label="字典类型编码" :label-width="100">
<el-input :value="route.params.code" disabled/> <el-input :value="route.params.code" disabled />
</el-form-item> </el-form-item>
<el-form-item label="名称" :label-width="100" prop="name"> <el-form-item label="名称" :label-width="100" prop="name">
<el-input v-model="formContent.name" placeholder="请输入" autocomplete="off"/> <el-input v-model="dialogForm.name" placeholder="请输入" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="编码" :label-width="100" prop="code"> <el-form-item label="编码" :label-width="100" prop="code">
<el-input v-model="formContent.code" placeholder="请输入" autocomplete="off"/> <el-input v-model="dialogForm.code" placeholder="请输入" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="值" :label-width="100" prop="value"> <el-form-item label="值" :label-width="100" prop="value">
<el-input v-model="formContent.value" placeholder="请输入" autocomplete="off"/> <el-input v-model="dialogForm.value" placeholder="请输入" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="显示排序" :label-width="100"> <el-form-item label="显示排序" :label-width="100">
<el-input-number v-model="formContent.sort"/> <el-input-number v-model="dialogForm.sort" />
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
@@ -54,24 +56,25 @@
</template> </template>
<script setup lang="tsx" name="dictData"> <script setup lang="tsx" name="dictData">
import {useRoute} from 'vue-router' import { useRoute } from 'vue-router'
import {CirclePlus, Delete, EditPen, Download, Upload} from '@element-plus/icons-vue' import { CirclePlus, Delete, EditPen, Download, Upload } from '@element-plus/icons-vue'
import {Dict} from '@/api/system/dictionary/interface' import { Dict } from '@/api/system/dictionary/interface'
import {ProTableInstance, ColumnProps} from '@/components/ProTable/interface' import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
import ImportExcel from '@/components/ImportExcel/index.vue' import ImportExcel from '@/components/ImportExcel/index.vue'
import {dialogSmall} from '@/utils/elementBind' import { dialogSmall } from '@/utils/elementBind'
import {useDictStore} from '@/stores/modules/dict' import { useDictStore } from '@/stores/modules/dict'
import {useHandleData} from '@/hooks/useHandleData' import { useHandleData } from '@/hooks/useHandleData'
import {useDownload} from '@/hooks/useDownload' import { useDownload } from '@/hooks/useDownload'
import {dictDataList} from '@/api/system/dictionary/dictExample' import { dictDataList } from '@/api/system/dictionary/dictExample'
import {FormItemRule} from 'element-plus' import { FormItemRule } from 'element-plus'
import { import {
getDictDataListByTypeId, getDictDataList,
addDictData,
updateDictData, updateDictData,
deleteDictData, addDictData,
getDicDataById batchAddDictData,
} from "@/api/system/dictionary/dictData"; exportDictData,
deleteDictData
} from '@/api/system/dictionary'
const route = useRoute() const route = useRoute()
@@ -84,20 +87,9 @@ const dialogVisible1 = ref(false)
const title1 = ref('') const title1 = ref('')
const dialogFormRef = ref() const dialogFormRef = ref()
const props = defineProps({
width: {
type: String,
default: '800px',
},
height: {
type: String,
default: '744px',
},
})
const columns = reactive<ColumnProps<Dict.ResDictData>[]>([ const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
{type: 'selection', fixed: 'left', width: 70}, { type: 'selection', fixed: 'left', width: 70 },
{type: 'index', fixed: 'left', width: 70, label: '序号'}, { type: 'index', fixed: 'left', width: 70, label: '序号' },
{ {
prop: 'name', prop: 'name',
label: '名称', label: '名称',
@@ -122,7 +114,7 @@ const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
{ {
prop: 'level', prop: 'level',
label: '事件等级', label: '事件等级',
width: 180, width: 120,
render: scope => { render: scope => {
return ( return (
<> <>
@@ -136,44 +128,73 @@ const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
) )
} }
}, },
{
prop: 'state',
label: '状态',
minWidth: 100,
enum: dictStore.getDictData('status'),
search: {
el: 'tree-select',
props: { filterable: true }
},
fieldNames: { label: 'label', value: 'code' },
render: scope => {
return (
<>
{
<el-tag type={scope.row.state ? 'success' : 'danger'} > {scope.row.state ? '正常' : '禁用'} </el-tag>
}
</>
)
},
},
{ {
prop: 'createTime', prop: 'createTime',
label: '创建时间', label: '创建时间',
width: 180 width: 180,
search: {
el: 'date-picker',
props: { type: 'daterange', valueFormat: 'YYYY-MM-DD' }
}
}, },
{ {
prop: 'operation', prop: 'operation',
label: '操作', label: '操作',
fixed: 'right', fixed: 'right',
minWidth: 300 width: 330
}, },
]) ])
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
name: [{ required: true, message: '类型名称必填!', trigger: 'blur' }],
code: [{ required: true, message: '类型编码必填!', trigger: 'blur' }],
value: [{ required: true, message: '类型值必填!', trigger: 'blur' }],
})
const {dialogVisible2, titleType2, formContent} = useMetaInfo(); const { dialogVisible2, dialogType2, dialogForm } = useCount();
function useMetaInfo() { function useCount() {
const dialogVisible2 = ref(false) const dialogVisible2 = ref(false)
const titleType2 = ref('add') const dialogType2 = ref('新增')
const formContent = ref<Dict.ResDictData>({ const dialogForm = ref({
id: "", id: "",
typeId:"",
name: "", name: "",
code: "", code: "",
value: "", value: "",
sort: 100, sort: 100,
state:1,
}) })
return {dialogVisible2, titleType2, formContent}; return { dialogVisible2, dialogType2, dialogForm };
} }
let dialogTitle = computed(() => { const props = defineProps({
return titleType2.value === 'add' ? '新增字典类型' : '编辑字典类型' width: {
}) type: String,
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({ default: '800px',
name: [{required: true, message: '类型名称必填!', trigger: 'blur'}], },
code: [{required: true, message: '类型编码必填!', trigger: 'blur'}], height: {
value: [{required: true, message: '类型值必填!', trigger: 'blur'}], type: String,
default: '744px',
},
}) })
const open = (textTitle: string, id: string) => { const open = (textTitle: string, id: string) => {
@@ -185,53 +206,59 @@ const open = (textTitle: string, id: string) => {
// } // }
} }
defineExpose({open}) defineExpose({ open })
// 打开 drawer(新增、查看、编辑) // 打开 drawer(新增、查看、编辑)
const openDrawer = (title: string, row: Partial<Dict.ResDictType> = {}) => { const openDrawer = (title: string, row: Partial<Dict.ResDictType> = {}) => {
dialogVisible2.value = true dialogVisible2.value = true
titleType2.value = title dialogType2.value = title
if (title === '编辑') { if (title === '编辑') {
row && (formContent.value = row as { row && (dialogForm.value = row as { id: string; name: string; code: string; value: string; sort: number; state: number; });
id: "",
typeId:"",
name: "",
code: "",
value: "",
sort: 100,
state:1,
});
} }
} }
// 批量添加字典数据
const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
const batchAdd = () => {
const params = {
title: '字典数据',
tempApi: exportDictData,
importApi: batchAddDictData,
getTableList: proTable.value?.getTableList,
}
dialogRef.value?.acceptParams(params)
}
// 导出字典数据
const downloadFile = async () => {
ElMessageBox.confirm('确认导出字典数据?', '温馨提示', { type: 'warning' }).then(() =>
useDownload(exportDictData, '字典数据列表', proTable.value?.searchParam),
)
}
// 批量删除字典数据 // 批量删除字典数据
const batchDelete = async (id: string[]) => { const batchDelete = async (id: string[]) => {
await useHandleData(deleteDictData, {id}, '删除所选字典数据') await useHandleData(deleteDictData, { id }, '删除所选字典数据')
proTable.value?.clearSelection() proTable.value?.clearSelection()
proTable.value?.getTableList() proTable.value?.getTableList()
} }
// 删除字典数据 // 删除字典数据
const handleDelete = async (params: Dict.ResDictType) => { const handleDelete = async (params: Dict.ResDictType) => {
await useHandleData(deleteDictData, {id: [params.id]}, `删除【${params.name}】字典数据`) await useHandleData(deleteDictData, { id: [params.id] }, `删除【${params.name}】字典数据`)
proTable.value?.getTableList() proTable.value?.getTableList()
} }
const resetFormContent = () => {
formContent.value = {
id: "",
typeId:"",
name: "",
code: "",
value: "",
sort: 100,
state:1,
}
}
const close = () => { const close = () => {
dialogVisible2.value = false dialogVisible2.value = false
resetFormContent() //清空dialogForm中的值
dialogForm.value = {
id: "",
name: "",
code: "",
value: "",
sort: 100
}
dialogFormRef.value?.resetFields() dialogFormRef.value?.resetFields()
} }
@@ -239,15 +266,13 @@ const save = () => {
try { try {
dialogFormRef.value?.validate(async (valid: boolean) => { dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) { if (valid) {
let params = JSON.stringify(formContent.value) let params = JSON.stringify(dialogForm.value)
if (formContent.value.id) { console.log(params)
await updateDictData(formContent.value) if (dialogType2.value === '新增') {
// await useHandleData(addDictData, formContent.value, '新增字典数据') await useHandleData(addDictData, dialogForm.value, '新增字典数据')
} else { } else {
await addDictData(formContent.value) await useHandleData(updateDictData, dialogForm.value, '编辑字典数据')
// await useHandleData(updateDictData, formContent.value, '编辑字典数据')
} }
ElMessage.success({ message: `${dialogTitle.value}成功!` })
close() close()
proTable.value?.getTableList() proTable.value?.getTableList()
} else { } else {