From b820bead2e6a4c9bbb100885e919a32a1a7e835a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E9=B8=BF?= Date: Fri, 13 Jun 2025 09:08:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(sub-government-affairs-service):=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=96=B0=E5=A2=9E=E7=BD=91=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gridManagement/index.js | 43 ++ .../src/components/AreaCascader/index.vue | 246 +++----- .../src/components/AreaSelect/index.vue | 49 +- .../src/components/FileUploader/index.vue | 87 ++- .../component/landsManage/index.vue | 43 +- .../coOp/components/TabBasicInfo.vue | 6 +- .../src/views/resource/grid/AddGrid.vue | 573 +++++++----------- .../src/views/resource/grid/AddGridBac.vue | 392 ++++++++++++ 8 files changed, 825 insertions(+), 614 deletions(-) create mode 100644 sub-government-affairs-service/src/views/resource/grid/AddGridBac.vue diff --git a/sub-government-affairs-service/src/apis/landResourceManagement/gridManagement/index.js b/sub-government-affairs-service/src/apis/landResourceManagement/gridManagement/index.js index e69de29..825700c 100644 --- a/sub-government-affairs-service/src/apis/landResourceManagement/gridManagement/index.js +++ b/sub-government-affairs-service/src/apis/landResourceManagement/gridManagement/index.js @@ -0,0 +1,43 @@ +import request from '@/utils/axios'; + +// 新增(POST) +export function createGrid(data = {}) { + return request('/land-resource/gridManage/save', { + method: 'POST', + data, + }); +} +// 删除(DELETE) +export function deleteGrid(id) { + return request(`/land-resource/gridManage/${id}`, { + method: 'DELETE', + }); +} +// 修改(PUT) +export function updateGrid(data = {}) { + return request('//land-resource/gridManage/edit', { + method: 'PUT', + data, + }); +} +// 查询列表(GET) +export function fetchGridList(params) { + return request('/land-resource/gridManage/page', { + method: 'GET', + params, + }); +} +// 获取详情(GET) +export function getGridDetail(id) { + return request(`/land-resource/gridManage/${id}`, { + method: 'GET', + }); +} +// 导出(GET + Blob) +export function exportGrid(params = {}) { + return request('/land-resource/gridManage/export', { + method: 'GET', + params, + responseType: 'blob', + }); +} diff --git a/sub-government-affairs-service/src/components/AreaCascader/index.vue b/sub-government-affairs-service/src/components/AreaCascader/index.vue index 1920dfa..70c5e14 100644 --- a/sub-government-affairs-service/src/components/AreaCascader/index.vue +++ b/sub-government-affairs-service/src/components/AreaCascader/index.vue @@ -1,40 +1,27 @@ diff --git a/sub-government-affairs-service/src/components/AreaSelect/index.vue b/sub-government-affairs-service/src/components/AreaSelect/index.vue index f4cb29a..82669c1 100644 --- a/sub-government-affairs-service/src/components/AreaSelect/index.vue +++ b/sub-government-affairs-service/src/components/AreaSelect/index.vue @@ -24,7 +24,7 @@ const props = defineProps({ default: false, }, modelValue: { - type: Array, + type: [Array, String], default: () => [], }, label: { @@ -39,6 +39,10 @@ const props = defineProps({ type: [Number, String], default: 500, }, + emitPath: { + type: Boolean, + default: true, + }, }); const emit = defineEmits(['update:modelValue']); @@ -46,14 +50,35 @@ const emit = defineEmits(['update:modelValue']); const userStore = useUserStore(); const areaOptions = ref([]); -const selectedAreaPath = ref([...props.modelValue]); + +// 检查计算属性有没有循环依赖用 +// const selectedAreaPath = props.emitPath ? ref([].concat(props.modelValue)) : ref(props.modelValue); + +const selectedAreaPath = computed({ + get() { + // 初始回显 & 外部变更都走这里 + if (props.emitPath) { + return Array.isArray(props.modelValue) ? props.modelValue : []; + } else { + return typeof props.modelValue === 'string' ? props.modelValue : ''; + } + }, + set(val) { + // 组件内部选中时走这里 + if (props.emitPath) { + emit('update:modelValue', Array.isArray(val) ? val : []); + } else { + emit('update:modelValue', typeof val === 'string' ? val : ''); + } + }, +}); // 自定义字段映射 const cascaderProps = computed(() => ({ label: 'areaName', value: 'areaCode', children: 'areaChildVOS', - emitPath: true, + emitPath: props.emitPath, expandTrigger: 'hover', })); @@ -70,7 +95,7 @@ const fetchAreaData = async () => { console.error('加载行政区域失败', err); } }; - +// !!!禁止使用外部更新,会造成循环依赖 // // 外部更新 => 内部同步 // watch( // () => props.modelValue, @@ -80,9 +105,19 @@ const fetchAreaData = async () => { // ); // 内部更新 => 外部同步 -watch(selectedAreaPath, (val) => { - emit('update:modelValue', val); -}); +watch( + selectedAreaPath, + (val) => { + if (props.emitPath) { + // 期望数组模式,确保输出数组 + emit('update:modelValue', Array.isArray(val) ? val : []); + } else { + // 期望字符串模式,确保输出字符串 + emit('update:modelValue', typeof val === 'string' ? val : ''); + } + }, + { deep: true } +); onMounted(() => { fetchAreaData(); diff --git a/sub-government-affairs-service/src/components/FileUploader/index.vue b/sub-government-affairs-service/src/components/FileUploader/index.vue index e4990ca..808d766 100644 --- a/sub-government-affairs-service/src/components/FileUploader/index.vue +++ b/sub-government-affairs-service/src/components/FileUploader/index.vue @@ -12,6 +12,7 @@ :auto-upload="true" :disabled="readonly" :accept="accept" + @preview="handlePreview" > @@ -24,78 +25,74 @@ import { ref, computed } from 'vue'; import { Plus } from '@element-plus/icons-vue'; import { CommonUpload } from '@/apis/index'; +// 1. props & emit const props = defineProps({ - modelValue: { - type: Array, - default: () => [], - }, - ossUrl: { - type: String, - default: 'http://gov-cloud.oss-cn-chengdu.aliyuncs.com/', - }, - limit: { - type: Number, - default: 5, - }, - accept: { - type: String, - default: 'image/*', - }, - readonly: { - type: Boolean, - default: false, - }, + modelValue: { type: [Array, String], default: () => [] }, + ossUrl: { type: String, default: 'http://gov-cloud.oss-cn-chengdu.aliyuncs.com/' }, + limit: { type: Number, default: 5 }, + accept: { type: String, default: 'image/*' }, + readonly: { type: Boolean, default: false }, }); const emit = defineEmits(['update:modelValue']); -// 构造 el-upload 所需 file-list -const fileList = computed(() => { - return props.modelValue.map((path, idx) => ({ - name: `image_${idx}`, - url: props.ossUrl + path, - uid: `${idx}`, - })); +// 2. 中间层 computed:统一成数组,写时根据 limit 决定发出数组还是字符串 +const selectedFiles = computed({ + get() { + // 回显:如果父传字符串且 limit===1,就把它当成长度 1 数组 + if (props.limit === 1 && typeof props.modelValue === 'string' && props.modelValue) { + return [props.modelValue]; + } + // 其他情况,确保数组 + return Array.isArray(props.modelValue) ? props.modelValue : []; + }, + set(val) { + // 内部操作后:如果单文件场景,传字符串;多文件场景,传数组 + if (props.limit === 1) { + emit('update:modelValue', val.length ? val[0] : ''); + } else { + emit('update:modelValue', val); + } + }, }); -// 预览 +// 3. fileList & previewList 都基于 selectedFiles +const fileList = computed(() => + selectedFiles.value.map((path, idx) => ({ + name: `file_${idx}`, + url: props.ossUrl + path, + uid: `${idx}`, + })) +); const previewShow = ref(false); -const previewList = computed(() => fileList.value.map((item) => item.url)); const previewIndex = ref(0); +const previewList = computed(() => fileList.value.map((f) => f.url)); -// 上传请求内部实现 +// 4. 上传 & 移除 const customUploadRequest = async ({ file, onSuccess, onError }) => { const formData = new FormData(); formData.append('file', file); try { const res = await CommonUpload(formData); - // 假设后端返回 { code:200, data: { url: 'relative/path.jpg' } } onSuccess(res, file); } catch (err) { onError(err); } }; - -// 上传成功回调,推入 modelValue function handleUploadSuccess(res) { const relative = res.data?.url; - if (relative) { - const newArr = [...props.modelValue, relative]; - emit('update:modelValue', newArr); - } + if (!relative) return; + // 推入中间层 + selectedFiles.value = [...selectedFiles.value, relative]; } - -// 删除图片 function handleRemove(file) { - const fullUrl = file.url; - const relative = fullUrl.replace(props.ossUrl, ''); - const newArr = props.modelValue.filter((path) => path !== relative); - emit('update:modelValue', newArr); + const rel = file.url.replace(props.ossUrl, ''); + selectedFiles.value = selectedFiles.value.filter((p) => p !== rel); } -// 点击预览 +// 5. 预览 function handlePreview(file) { const idx = fileList.value.findIndex((item) => item.uid === file.uid); - if (idx !== -1) { + if (idx >= 0) { previewIndex.value = idx; previewShow.value = true; } diff --git a/sub-government-affairs-service/src/views/landManage/component/landsManage/index.vue b/sub-government-affairs-service/src/views/landManage/component/landsManage/index.vue index 9c739dc..9176bd1 100644 --- a/sub-government-affairs-service/src/views/landManage/component/landsManage/index.vue +++ b/sub-government-affairs-service/src/views/landManage/component/landsManage/index.vue @@ -95,16 +95,7 @@ - - - + @@ -147,7 +138,7 @@ - + - - - - + @@ -190,20 +168,7 @@ - - - - + diff --git a/sub-government-affairs-service/src/views/productOperateMain/coOp/components/TabBasicInfo.vue b/sub-government-affairs-service/src/views/productOperateMain/coOp/components/TabBasicInfo.vue index 3c73b1e..a7f06d0 100644 --- a/sub-government-affairs-service/src/views/productOperateMain/coOp/components/TabBasicInfo.vue +++ b/sub-government-affairs-service/src/views/productOperateMain/coOp/components/TabBasicInfo.vue @@ -25,6 +25,7 @@ > + @@ -45,7 +46,7 @@ - - + --> + diff --git a/sub-government-affairs-service/src/views/resource/grid/AddGrid.vue b/sub-government-affairs-service/src/views/resource/grid/AddGrid.vue index 6ae51e1..aef975f 100644 --- a/sub-government-affairs-service/src/views/resource/grid/AddGrid.vue +++ b/sub-government-affairs-service/src/views/resource/grid/AddGrid.vue @@ -2,391 +2,260 @@
- + + + diff --git a/sub-government-affairs-service/src/views/resource/grid/AddGridBac.vue b/sub-government-affairs-service/src/views/resource/grid/AddGridBac.vue new file mode 100644 index 0000000..6ae51e1 --- /dev/null +++ b/sub-government-affairs-service/src/views/resource/grid/AddGridBac.vue @@ -0,0 +1,392 @@ + +