From ead809cb3a94c74901217afc197a373eb27e79d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=83=B3?= <826276471@qq.com> Date: Tue, 11 Mar 2025 17:24:51 +0800 Subject: [PATCH] feat --- .../src/apis/baseInfo.js | 25 +++++ .../src/apis/inputSuppliesApi/index.js | 3 + .../src/apis/inputSuppliesApi/redAndBlank.js | 1 + .../component/soilClassification/index.vue | 14 +-- .../soilClassification/useSoilTypeHook.js | 96 ++++++++++--------- 5 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 sub-government-affairs-service/src/apis/inputSuppliesApi/index.js create mode 100644 sub-government-affairs-service/src/apis/inputSuppliesApi/redAndBlank.js diff --git a/sub-government-affairs-service/src/apis/baseInfo.js b/sub-government-affairs-service/src/apis/baseInfo.js index 9a1d1b7..265dc07 100644 --- a/sub-government-affairs-service/src/apis/baseInfo.js +++ b/sub-government-affairs-service/src/apis/baseInfo.js @@ -31,3 +31,28 @@ export function exportPlanType(params = {}) { responseType: 'blob', }); } + +/* ------ ------ */ +// #region +/* 获取土壤类型列表 */ +export function getSoilType(params) { + return request('land-resource/baseInfo/soilTypePage', { + method: 'GET', + params, + }); +} +/* 创建土壤类型 */ +export function saveSoilType(data) { + return request('land-resource/baseInfo/soilTypeSave', { + method: 'POST', + data, + }); +} +/* 编辑土壤类型 */ +export function updateSoilType(data) { + return request('land-resource/baseInfo/soilTypeSave', { + method: 'PUT', + data, + }); +} +// #endregion diff --git a/sub-government-affairs-service/src/apis/inputSuppliesApi/index.js b/sub-government-affairs-service/src/apis/inputSuppliesApi/index.js new file mode 100644 index 0000000..5346cfb --- /dev/null +++ b/sub-government-affairs-service/src/apis/inputSuppliesApi/index.js @@ -0,0 +1,3 @@ +import * as redBlack from './redAndBlank'; + +export { redBlack }; diff --git a/sub-government-affairs-service/src/apis/inputSuppliesApi/redAndBlank.js b/sub-government-affairs-service/src/apis/inputSuppliesApi/redAndBlank.js new file mode 100644 index 0000000..503f164 --- /dev/null +++ b/sub-government-affairs-service/src/apis/inputSuppliesApi/redAndBlank.js @@ -0,0 +1 @@ +import request from '@/utils/request'; diff --git a/sub-government-affairs-service/src/views/dict/component/soilClassification/index.vue b/sub-government-affairs-service/src/views/dict/component/soilClassification/index.vue index e4d6ba1..67681d2 100644 --- a/sub-government-affairs-service/src/views/dict/component/soilClassification/index.vue +++ b/sub-government-affairs-service/src/views/dict/component/soilClassification/index.vue @@ -4,7 +4,7 @@ ref="crudRef" v-model:page="pageData" v-model:search="condition" - :table-loading="loading" + :table-loading="_loading" :data="data" :option="option" @search-change="handleSearch" @@ -12,7 +12,7 @@ @current-change="handleCurrentChange" @size-change="handleSizeChange" @row-save="handleSave" - @row-update="handleUpdete" + @row-update="handleUpdate" > - + + @@ -41,7 +41,7 @@ import useSoilTypeHook from './useSoilTypeHook'; const { crudRef, condition, - loading, + _loading, data, pageData, option, @@ -51,7 +51,7 @@ const { handleSearch, handleSearchReset, handleSave, - handleUpdete, + handleUpdate, } = useSoilTypeHook(); /* --------------- data --------------- */ diff --git a/sub-government-affairs-service/src/views/dict/component/soilClassification/useSoilTypeHook.js b/sub-government-affairs-service/src/views/dict/component/soilClassification/useSoilTypeHook.js index f16e863..8cf1e59 100644 --- a/sub-government-affairs-service/src/views/dict/component/soilClassification/useSoilTypeHook.js +++ b/sub-government-affairs-service/src/views/dict/component/soilClassification/useSoilTypeHook.js @@ -1,31 +1,17 @@ -import { ref, onMounted } from 'vue'; +import { ref, onMounted, nextTick } from 'vue'; import { CRUD_OPTIONS } from '@/config'; +import { getSoilType, saveSoilType, updateSoilType } from '@/apis/baseInfo'; +import { ElMessage } from 'element-plus'; export default function useSoilTypeHook() { onMounted(getList); const crudRef = ref(); const condition = ref({ - soilType: '', + soilType: null, }); - const data = ref([ - { - code: 'a123456', - soilType: '黑土地', - status: 0, - }, - { - code: 'b258369', - soilType: '黄土地', - status: 1, - }, - { - code: 'c987654', - soilType: '盐碱土地', - status: 0, - }, - ]); - const loading = ref(false); + const data = ref([]); + const _loading = ref(false); const pageData = ref({ currentPage: 1, pageSize: 10, @@ -40,7 +26,7 @@ export default function useSoilTypeHook() { column: [ { label: '编号', - prop: 'code', + prop: 'id', display: false, addDisplay: false, }, @@ -69,7 +55,7 @@ export default function useSoilTypeHook() { display: false, addDisplay: false, render: ({ row }) => { - return row.status === 0 ? '启用' : '禁用'; + return row.status === '1' ? '启用' : '禁用'; }, }, ], @@ -92,34 +78,32 @@ export default function useSoilTypeHook() { event: handleDel, }, ]); - function getList() { + async function getList() { let params = { current: pageData.value.currentPage, - pageSize: pageData.value.pageSize, + size: pageData.value.pageSize, ...condition.value, }; - console.log('get --- ', params); - console.table(data.value); + let res = await getSoilType(params); + if (res.code == 200) { + data.value = res.data.records; + pageData.value.total = res.data.total; + } + console.log('get --- ', res); } - function handleStatusChange(row, index) { - console.log('handleStatusChange --- ', row); - data.value[index].status = data.value[index].status === 0 ? 1 : 0; - console.table(data.value); + async function handleStatusChange(row, index) { + await editSoilType(row, index); } function handleCurrentChange(val) { - console.log('handleCurrentChange --- ', val); pageData.value.currentPage = val; getList(); } function handleSizeChange(val) { - console.log('handleSizeChange --- ', val); pageData.value.currentPage = 1; pageData.value.pageSize = val; getList(); } function handleSearch(val, done) { - console.log('handleSearch --- ', val); - console.log('ccc', condition.value); resetPage(); done(); } @@ -127,22 +111,44 @@ export default function useSoilTypeHook() { resetPage(); } function handleEdit(row, index) { - console.log('handleEdit --- ', row); - console.log('index --- ', index); - crudRef.value.rowEdit(row); + crudRef.value.rowEdit(row, index); } function handleDel(row) { console.log('handleDel --- ', row); } - function handleSave(form, _loading, done) { - console.log('save --- ', form); - _loading(); + async function handleSave(form, loading, done) { + let res = await saveSoilType(form); + if (res.code == 200) { + ElMessage({ + type: 'success', + message: '添加成功', + }); + } + loading(); getList(); } - function handleUpdate(form, _loading, done) { - console.log('update --- ', form); - _loading(); - getList(); + async function handleUpdate(row, index, done, loading) { + await editSoilType(row, index); + loading(); + done(); + } + async function editSoilType(row, index) { + let res = await updateSoilType({ + id: row.id, + soilType: row.soilType, + status: row.status === '0' ? '1' : '0', + }); + console.log('res ------', res); + if (res.code == 200) { + ElMessage({ + type: 'success', + message: '修改成功', + }); + nextTick(() => { + data.value[index].soilType = row.soilType; + data.value[index].status = row.status === '0' ? '1' : '0'; + }); + } } function resetPage() { pageData.value.currentPage = 1; @@ -152,7 +158,7 @@ export default function useSoilTypeHook() { return { crudRef, condition, - loading, + _loading, data, pageData, option,