Merge remote-tracking branch 'origin/master' into dev
# Conflicts: # frontend/src/views/system/dictionary/data.vue
This commit is contained in:
@@ -23,8 +23,14 @@ interface Pageable {
|
||||
total: number;
|
||||
}
|
||||
|
||||
interface ResPageable {
|
||||
current: number;
|
||||
size: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
interface PaginationProps {
|
||||
pageable: Pageable;
|
||||
pageable: ResPageable;
|
||||
handleSizeChange: (size: number) => void;
|
||||
handleCurrentChange: (currentPage: number) => void;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
<slot name='pagination'>
|
||||
<Pagination
|
||||
v-if='pagination'
|
||||
:pageable='pageable'
|
||||
:pageable='resPageable'
|
||||
:handle-size-change='handleSizeChange'
|
||||
:handle-current-change='handleCurrentChange'
|
||||
/>
|
||||
@@ -173,6 +173,7 @@ const { selectionChange, selectedList, selectedListIds, isSelected } = useSelect
|
||||
const {
|
||||
tableData,
|
||||
pageable,
|
||||
resPageable,
|
||||
searchParam,
|
||||
searchInitParam,
|
||||
getTableList,
|
||||
@@ -190,7 +191,7 @@ const clearSelection = () => tableRef.value!.clearSelection()
|
||||
onMounted(() => {
|
||||
dragSort()
|
||||
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.pagination) return props.data
|
||||
return props.data.slice(
|
||||
(pageable.value.pageNum - 1) * pageable.value.pageSize,
|
||||
pageable.value.pageSize * pageable.value.pageNum,
|
||||
(resPageable.value.current - 1) * resPageable.value.size,
|
||||
resPageable.value.size * resPageable.value.current,
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -4,9 +4,17 @@ export namespace Table {
|
||||
pageSize: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface ResPageable {
|
||||
current: number;
|
||||
size: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface StateProps {
|
||||
tableData: any[];
|
||||
pageable: Pageable;
|
||||
resPageable: ResPageable;
|
||||
searchParam: {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
@@ -20,6 +20,15 @@ export const useTable = (
|
||||
tableData: [],
|
||||
// 分页数据
|
||||
pageable: {
|
||||
// 当前页数
|
||||
pageNum: 1,
|
||||
// 每页显示条数
|
||||
pageSize: 10,
|
||||
// 总条数
|
||||
total: 0,
|
||||
},
|
||||
// 响应分页
|
||||
resPageable: {
|
||||
// 当前页数
|
||||
current: 1,
|
||||
// 每页显示条数
|
||||
@@ -71,9 +80,9 @@ export const useTable = (
|
||||
state.tableData = isPageable ? data.records : data;
|
||||
// 解构后台返回的分页数据 (如果有分页更新分页信息)
|
||||
if (isPageable) {
|
||||
state.pageable.total = data.total;
|
||||
state.pageable.current = data.current;
|
||||
state.pageable.size = data.size;
|
||||
state.resPageable.total = data.total;
|
||||
state.resPageable.current = data.current;
|
||||
state.resPageable.size = data.size;
|
||||
}
|
||||
} catch (error) {
|
||||
requestError && requestError(error);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<template>
|
||||
<div class="table-box">
|
||||
<el-dialog class='table-box' v-model='dialogVisible1' top='114px'
|
||||
:style="{ height: height, maxHeight: height, overflow: 'hidden' }" :title='title1' :width='width'
|
||||
:modal='false'>
|
||||
<ProTable :columns="columns" :data="data">
|
||||
:style="{ height: height, maxHeight: height, overflow: 'hidden' }" :title='title1' :width='width' :modal='false'>
|
||||
<div class="table-box">
|
||||
<ProTable
|
||||
ref='proTable'
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
>
|
||||
<template #tableHeader="scope">
|
||||
<el-button type="primary" :icon="CirclePlus" @click="openDrawer('新增')">新增</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>
|
||||
</template>
|
||||
</ProTable>
|
||||
</el-dialog>
|
||||
</div>
|
||||
<el-dialog v-model="dialogVisible2" :title="dialogTitle"
|
||||
v-bind="dialogSmall">
|
||||
</el-dialog>
|
||||
<el-dialog v-model="dialogVisible2" :title="dialogType2 === '新增' ? '新增字典数据' : '编辑字典数据'" v-bind="dialogSmall">
|
||||
<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-input :value="route.params.code" disabled />
|
||||
</el-form-item>
|
||||
<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 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 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 label="显示排序" :label-width="100">
|
||||
<el-input-number v-model="formContent.sort"/>
|
||||
<el-input-number v-model="dialogForm.sort" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
@@ -66,12 +68,13 @@ import {useDownload} from '@/hooks/useDownload'
|
||||
import { dictDataList } from '@/api/system/dictionary/dictExample'
|
||||
import { FormItemRule } from 'element-plus'
|
||||
import {
|
||||
getDictDataListByTypeId,
|
||||
addDictData,
|
||||
getDictDataList,
|
||||
updateDictData,
|
||||
deleteDictData,
|
||||
getDicDataById
|
||||
} from "@/api/system/dictionary/dictData";
|
||||
addDictData,
|
||||
batchAddDictData,
|
||||
exportDictData,
|
||||
deleteDictData
|
||||
} from '@/api/system/dictionary'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
@@ -84,17 +87,6 @@ const dialogVisible1 = ref(false)
|
||||
const title1 = ref('')
|
||||
const dialogFormRef = ref()
|
||||
|
||||
const props = defineProps({
|
||||
width: {
|
||||
type: String,
|
||||
default: '800px',
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '744px',
|
||||
},
|
||||
})
|
||||
|
||||
const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
|
||||
{ type: 'selection', fixed: 'left', width: 70 },
|
||||
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
|
||||
@@ -122,7 +114,7 @@ const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
|
||||
{
|
||||
prop: 'level',
|
||||
label: '事件等级',
|
||||
width: 180,
|
||||
width: 120,
|
||||
render: scope => {
|
||||
return (
|
||||
<>
|
||||
@@ -136,46 +128,75 @@ 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',
|
||||
label: '创建时间',
|
||||
width: 180
|
||||
width: 180,
|
||||
search: {
|
||||
el: 'date-picker',
|
||||
props: { type: 'daterange', valueFormat: 'YYYY-MM-DD' }
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
fixed: 'right',
|
||||
minWidth: 300
|
||||
width: 330
|
||||
},
|
||||
])
|
||||
|
||||
const {dialogVisible2, titleType2, formContent} = useMetaInfo();
|
||||
function useMetaInfo() {
|
||||
const dialogVisible2 = ref(false)
|
||||
const titleType2 = ref('add')
|
||||
|
||||
const formContent = ref<Dict.ResDictData>({
|
||||
id: "",
|
||||
typeId:"",
|
||||
name: "",
|
||||
code: "",
|
||||
value: "",
|
||||
sort: 100,
|
||||
state:1,
|
||||
})
|
||||
|
||||
return {dialogVisible2, titleType2, formContent};
|
||||
}
|
||||
|
||||
let dialogTitle = computed(() => {
|
||||
return titleType2.value === 'add' ? '新增字典类型' : '编辑字典类型'
|
||||
})
|
||||
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, dialogType2, dialogForm } = useCount();
|
||||
function useCount() {
|
||||
const dialogVisible2 = ref(false)
|
||||
const dialogType2 = ref('新增')
|
||||
|
||||
const dialogForm = ref({
|
||||
id: "",
|
||||
name: "",
|
||||
code: "",
|
||||
value: "",
|
||||
sort: 100,
|
||||
})
|
||||
|
||||
return { dialogVisible2, dialogType2, dialogForm };
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
width: {
|
||||
type: String,
|
||||
default: '800px',
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '744px',
|
||||
},
|
||||
})
|
||||
|
||||
const open = (textTitle: string, id: string) => {
|
||||
dialogVisible1.value = true
|
||||
title1.value = textTitle
|
||||
@@ -190,20 +211,31 @@ defineExpose({open})
|
||||
// 打开 drawer(新增、查看、编辑)
|
||||
const openDrawer = (title: string, row: Partial<Dict.ResDictType> = {}) => {
|
||||
dialogVisible2.value = true
|
||||
titleType2.value = title
|
||||
dialogType2.value = title
|
||||
if (title === '编辑') {
|
||||
row && (formContent.value = row as {
|
||||
id: "",
|
||||
typeId:"",
|
||||
name: "",
|
||||
code: "",
|
||||
value: "",
|
||||
sort: 100,
|
||||
state:1,
|
||||
});
|
||||
row && (dialogForm.value = row as { id: string; name: string; code: string; value: string; sort: number; state: number; });
|
||||
}
|
||||
}
|
||||
|
||||
// 批量添加字典数据
|
||||
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[]) => {
|
||||
await useHandleData(deleteDictData, { id }, '删除所选字典数据')
|
||||
@@ -217,21 +249,16 @@ const handleDelete = async (params: Dict.ResDictType) => {
|
||||
proTable.value?.getTableList()
|
||||
}
|
||||
|
||||
const resetFormContent = () => {
|
||||
formContent.value = {
|
||||
const close = () => {
|
||||
dialogVisible2.value = false
|
||||
//清空dialogForm中的值
|
||||
dialogForm.value = {
|
||||
id: "",
|
||||
typeId:"",
|
||||
name: "",
|
||||
code: "",
|
||||
value: "",
|
||||
sort: 100,
|
||||
state:1,
|
||||
sort: 100
|
||||
}
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
dialogVisible2.value = false
|
||||
resetFormContent()
|
||||
dialogFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
@@ -239,15 +266,13 @@ const save = () => {
|
||||
try {
|
||||
dialogFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
let params = JSON.stringify(formContent.value)
|
||||
if (formContent.value.id) {
|
||||
await updateDictData(formContent.value)
|
||||
// await useHandleData(addDictData, formContent.value, '新增字典数据')
|
||||
let params = JSON.stringify(dialogForm.value)
|
||||
console.log(params)
|
||||
if (dialogType2.value === '新增') {
|
||||
await useHandleData(addDictData, dialogForm.value, '新增字典数据')
|
||||
} else {
|
||||
await addDictData(formContent.value)
|
||||
// await useHandleData(updateDictData, formContent.value, '编辑字典数据')
|
||||
await useHandleData(updateDictData, dialogForm.value, '编辑字典数据')
|
||||
}
|
||||
ElMessage.success({ message: `${dialogTitle.value}成功!` })
|
||||
close()
|
||||
proTable.value?.getTableList()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user