265 lines
6.0 KiB
Vue
Raw Normal View History

2025-03-03 16:50:51 +08:00
<template>
<CustomCard>
2025-03-04 16:24:17 +08:00
<div>
<el-row :gutter="20">
<el-col :span="6">
<el-tree style="max-width: 600px" :data="typeTree" :props="{ children: 'children', label: 'label' }" @node-click="handleNodeClick" />
</el-col>
<el-col :span="18">
<avue-crud
ref="crudRef"
v-model="state.form"
v-model:search="state.query"
v-model:page="state.pageData"
:table-loading="state.loading"
:data="state.data"
:option="state.options"
@refresh-change="refreshChange"
@search-reset="searchChange"
@search-change="searchChange"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@row-del="rowDel"
2025-03-06 16:20:26 +08:00
@row-save="rowSave"
@row-update="rowUpdate"
2025-03-04 16:24:17 +08:00
>
<template #menu-left>
<el-button type="primary" icon="Plus" @click="onAdd">新增</el-button>
<el-button type="success" icon="download" @click="onExport">导出</el-button>
</template>
<template #menu="scope">
<custom-table-operate :actions="state.options.actions" :data="scope" />
</template>
</avue-crud>
</el-col>
</el-row>
</div>
2025-03-03 16:50:51 +08:00
</CustomCard>
</template>
2025-03-04 16:24:17 +08:00
<script setup>
import { ref, reactive, onMounted } from 'vue';
2025-03-03 16:50:51 +08:00
import { useApp } from '@/hooks';
import { CRUD_OPTIONS } from '@/config';
2025-03-04 16:24:17 +08:00
import CustomCard from '@/components/CustomCard.vue';
2025-03-03 16:50:51 +08:00
const { VITE_APP_BASE_API } = import.meta.env;
const app = useApp();
/* --------------- data --------------- */
// #region
2025-03-06 16:20:26 +08:00
const crudRef = ref(null);
const landUsedOptions = reactive([
{ label: '农用地', value: '0' },
{ label: '建设用地', value: '1' },
{ label: '住宅用地', value: '2' },
]);
2025-03-03 16:50:51 +08:00
const state = reactive({
loading: false,
query: {
current: 1,
size: 10,
},
form: {},
selection: [],
options: {
...CRUD_OPTIONS,
addBtnText: '',
addBtn: false,
column: [
2025-03-06 16:20:26 +08:00
{ label: '编号', prop: 'gridManager', addDisplay: false, editDisplay: false },
{
label: '土地分类',
prop: 'gridManager',
dicData: landUsedOptions,
multiple: true,
rules: {
required: true,
message: '请选择',
trigger: 'blur',
},
},
2025-03-03 16:50:51 +08:00
{ label: '土地类别', prop: 'gridManager' },
2025-03-06 16:20:26 +08:00
{ label: '状态', prop: 'gridManager', addDisplay: false, editDisplay: false },
2025-03-03 16:50:51 +08:00
],
actions: [
{
name: (row) => getStatusButtonText(row.status),
icon: 'edit',
event: ({ row }) => rowStatus(row),
},
{
name: '编辑',
icon: 'edit',
event: ({ row }) => rowEdit(row),
},
{
type: 'danger',
name: '删除',
icon: 'delete',
event: ({ row }) => rowDel(row),
},
],
},
pageData: {
total: 0,
currentPage: 1,
pageSize: 10,
},
data: [],
currentRow: {},
});
let typeTree = reactive([
{
2025-03-04 16:24:17 +08:00
label: '农用地',
id: '0',
2025-03-03 16:50:51 +08:00
children: [
2025-03-04 16:24:17 +08:00
{ label: '耕地', id: '01', children: [], pId: '0' },
{ label: '园地', children: [], id: '02', pId: '0' },
2025-03-03 16:50:51 +08:00
],
},
{
2025-03-04 16:24:17 +08:00
label: '建设用地',
id: '1',
children: [{ label: '城乡建设用地', children: [], id: '11', pId: '10' }],
},
{
label: '住宅用地',
id: '2',
children: [],
2025-03-03 16:50:51 +08:00
},
]);
// #endregion
/* --------------- methods --------------- */
2025-03-04 16:24:17 +08:00
const loadData = () => {
//state.loading = true;
// getAnnualList(state.query)
// .then((res) => {
// if (res.code === 200) {
// const { current, size, total, records } = res.data;
// state.data = records;
// state.pageData = {
// currentPage: current || 1,
// pageSize: size || 10,
// total: total,
// };
// }
// })
// .catch((err) => {
// app.$message.error(err.msg);
// state.data = [];
// })
// .finally(() => {
// state.loading = false;
// });
};
onMounted(() => {
loadData();
});
// 页数
const currentChange = (current) => {
state.query.current = current;
loadData();
};
// 条数
const sizeChange = (size) => {
state.query.size = size;
loadData();
};
// 搜索
const searchChange = (params, done) => {
if (done) done();
state.query = params;
state.query.current = 1;
loadData();
};
// 刷新
const refreshChange = () => {
loadData();
app.$message.success('刷新成功');
};
// 选择
const selectionChange = (rows) => {
state.selection = rows;
};
2025-03-03 16:50:51 +08:00
const handleNodeClick = (data) => {
2025-03-06 16:20:26 +08:00
console.log('handleNodeClick', data);
2025-03-03 16:50:51 +08:00
};
// 编辑
const rowStatus = (row) => {
console.info('操作状态');
};
const rowDel = (row) => {};
const getStatusButtonText = (status) => {
switch (status) {
case 'active':
return '启用';
case 'inactive':
return '禁用';
}
};
2025-03-06 16:20:26 +08:00
const rowEdit = (row) => {
crudRef.value && crudRef.value.rowEdit(row);
};
2025-03-03 16:50:51 +08:00
2025-03-04 16:24:17 +08:00
const onAdd = () => {
2025-03-06 16:20:26 +08:00
crudRef.value && crudRef.value.rowAdd();
2025-03-04 16:24:17 +08:00
};
2025-03-03 16:50:51 +08:00
const onExport = () => {};
2025-03-06 16:20:26 +08:00
const rowSave = (row, done, loading) => {
// console.info('新增', row);
// saveOperationRecord(row)
// .then((res) => {
// if (res.code === 200) {
// app.$message.success('添加成功!');
// done();
// loadData();
// }
// })
// .catch((err) => {
// app.$message.error(err.msg);
// })
// .finally(() => {
// loading();
// });
2025-03-04 16:24:17 +08:00
};
2025-03-06 16:20:26 +08:00
const rowUpdate = (row, index, done, loading) => {
console.info('更新');
// editOperationRecord(row)
// .then((res) => {
// if (res.code === 200) {
// app.$message.success('更新成功!');
// done();
// loadData();
// }
// })
// .catch((err) => {
// app.$message.error(err.msg);
// })
// .finally(() => {
// loading();
// });
2025-03-04 16:24:17 +08:00
};
2025-03-03 16:50:51 +08:00
// #region
// #endregion
</script>
<style lang="scss" scoped></style>