Compare commits
2 Commits
32dc012598
...
f006ca5a2b
Author | SHA1 | Date | |
---|---|---|---|
f006ca5a2b | |||
e3ff6020ac |
@ -5,10 +5,11 @@ VITE_APP_TITLE = 煤科建管平台
|
|||||||
VITE_APP_ENV = 'development'
|
VITE_APP_ENV = 'development'
|
||||||
|
|
||||||
# 开发环境
|
# 开发环境
|
||||||
VITE_APP_BASE_API = 'http://192.168.110.209:8899'
|
VITE_APP_BASE_API = 'http://192.168.110.149:8899'
|
||||||
# VITE_APP_BASE_API = 'http://58.17.134.85:8899'
|
# VITE_APP_BASE_API = 'http://58.17.134.85:8899'
|
||||||
# GO开发环境
|
# GO开发环境
|
||||||
VITE_APP_BASE_API_GO = 'http://192.168.110.188:8919'
|
VITE_APP_BASE_API_GO = 'http://xny.yj-3d.com:7464'
|
||||||
|
# VITE_APP_BASE_API_GO = 'http://192.168.110.188:8919'
|
||||||
|
|
||||||
# 无人机接口地址
|
# 无人机接口地址
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ VITE_APP_SNAILJOB_ADMIN = '/snail-job'
|
|||||||
|
|
||||||
# 生产环境
|
# 生产环境
|
||||||
# GO生产环境
|
# GO生产环境
|
||||||
VITE_APP_BASE_API_GO = 'http://58.17.134.85:7363'
|
VITE_APP_BASE_API_GO = 'http://58.17.134.85:7464'
|
||||||
VITE_APP_BASE_API = 'http://xny.yj-3d.com:8899'
|
VITE_APP_BASE_API = 'http://xny.yj-3d.com:8899'
|
||||||
|
|
||||||
# 是否在打包时开启压缩,支持 gzip 和 brotli
|
# 是否在打包时开启压缩,支持 gzip 和 brotli
|
||||||
|
@ -129,10 +129,10 @@ export function getGoToken(): AxiosPromise<any> {
|
|||||||
data: {
|
data: {
|
||||||
status: 'yjdsj',
|
status: 'yjdsj',
|
||||||
verifyCode: '1111',
|
verifyCode: '1111',
|
||||||
|
// username: 'admin',
|
||||||
|
// password: 'zmkg@2023A'
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'zmkg@2023A'
|
password: 'zmkg@2023C'
|
||||||
// username: 'admin1',
|
|
||||||
// password: 'zmkg@2023C'
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,270 @@
|
|||||||
import $cache from '@/plugins/cache';
|
import $cache from '@/plugins/cache';
|
||||||
|
import useUserStore from '@/store/modules/user';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
import axios from 'axios';
|
||||||
|
import sign from '@/utils/sign.js';
|
||||||
|
import CryptoJS from 'crypto-js';
|
||||||
/**
|
/**
|
||||||
* 包装 request 请求,统一使用 Go 服务地址作为 baseURL
|
* 包装 request 请求,统一使用 Go 服务地址作为 baseURL
|
||||||
* @param config 原始请求配置
|
* @param config 原始请求配置
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BASE_GO_URL = import.meta.env.VITE_APP_BASE_API_GO;
|
const BASE_GO_URL = import.meta.env.VITE_APP_BASE_API_GO;
|
||||||
|
const token = $cache.local.get('goToken');
|
||||||
|
|
||||||
interface RequestGo extends Function {
|
interface RequestGo extends Function {
|
||||||
(config: any): Promise<any>;
|
(config: any): Promise<any>;
|
||||||
download?: (url: string, params: any, filename: string) => void;
|
download?: (url: string, params: any, filename: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestGo: RequestGo = (config: any) => {
|
// 加密密钥
|
||||||
return request({
|
const corySecretKey = 'happyCoryOrTieHanHan202410151415';
|
||||||
baseURL: BASE_GO_URL,
|
|
||||||
...config,
|
// 配置新建一个 axios 实例
|
||||||
headers: {
|
const service = axios.create({
|
||||||
'Authorization': `Bearer ${$cache.local.get('goToken') || ''}`
|
baseURL: BASE_GO_URL as any,
|
||||||
|
timeout: 120000,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
|
||||||
|
// 不需要修改项目id的接口数组
|
||||||
|
const whiteUrl = [
|
||||||
|
'/api/wxApplet/wxApplet/sysProjectTeam/list',
|
||||||
|
'/api/wxApplet/wxApplet/sysProjectTeam/add',
|
||||||
|
'/api/wxApplet/wxApplet/sysProjectTeam/edit',
|
||||||
|
'/api/v1/test/testFollowInfo/add',
|
||||||
|
'/api/wxApplet/wxApplet/busConstructionUser/changePay',
|
||||||
|
// 获取项目资料文件夹
|
||||||
|
'/api/v1/system/documentData/treeStructureData',
|
||||||
|
'/api/v1/system/busConstructionUser/exportSalary',
|
||||||
|
'/api/v1/system/busSalaryDetails/list',
|
||||||
|
'/api/v1/system/ys7Devices/add',
|
||||||
|
'/api/v1/system/ys7Devices/edit',
|
||||||
|
'/api/v1/system/subProject/add',
|
||||||
|
'/api/v1/system/subProject/edit',
|
||||||
|
'/api/v1/system/subProject/list',
|
||||||
|
'/api/v1/system/workStatus/getTree',
|
||||||
|
'/api/v1/system/sysProjectIntroduce/list',
|
||||||
|
'/api/v1/system/sysProjectIntroduce/add',
|
||||||
|
'/api/v1/system/sysProjectIntroduce/edit',
|
||||||
|
'/video/hat/manage/api/v1/video/device/list',
|
||||||
|
'/video/hat/manage/api/v1/video/project/bind',
|
||||||
|
'/api/v1/system/notifications/publish',
|
||||||
|
'/api/v1/system/notifications/list',
|
||||||
|
'/api/v1/system/notifications/edit',
|
||||||
|
'/webodm/api/v1/taskCreate',
|
||||||
|
'/webodm/api/v1/taskProcess',
|
||||||
|
'/webodm/api/v1/download',
|
||||||
|
'/api/v1/system/manageTaskRecord/upDataResource',
|
||||||
|
'/api/v1/system/ys7Devices/list',
|
||||||
|
'/api/v1/system/busFolderFile/add',
|
||||||
|
'/api/v1/system/manageTaskRecordResource/voluntarilyReq',
|
||||||
|
'/api/v1/system/busAttendanceMachine/edit',
|
||||||
|
'/api/v1/system/qianqiFangzhen/add',
|
||||||
|
'/api/v1/system/qianqiNibianqi/add'
|
||||||
|
];
|
||||||
|
|
||||||
|
const exceptionStr = '/api/v1/test/'; // /api/v1/test/*接口拦截
|
||||||
|
|
||||||
|
// 添加请求拦截器
|
||||||
|
service.interceptors.request.use(
|
||||||
|
(config: any) => {
|
||||||
|
// 在发送请求之前做些什么 token
|
||||||
|
if (token) {
|
||||||
|
config.headers = config.headers || {};
|
||||||
|
(config.headers as any)['Authorization'] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
});
|
const stores = useUserStore();
|
||||||
};
|
if (!whiteUrl.includes(config.url) && !config.url.includes(exceptionStr)) {
|
||||||
|
if (config.params && Reflect.has(config.params, 'projectId')) {
|
||||||
|
config.params.projectId = stores.selectedProject.goId;
|
||||||
|
}
|
||||||
|
// 处理FormData中的projectId
|
||||||
|
if (config.data instanceof FormData && config.data.has('projectId')) {
|
||||||
|
config.data.set('projectId', stores.selectedProject.goId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let dataInfoReq = {};
|
||||||
|
if (config.method === 'get' || config.method === 'delete') {
|
||||||
|
config.params = config.params || {};
|
||||||
|
dataInfoReq = JSON.parse(JSON.stringify(config.params));
|
||||||
|
const encryptedParam = encryptAES256(JSON.stringify(dataInfoReq), corySecretKey);
|
||||||
|
if ($cache.local.get('i18n') != null) {
|
||||||
|
config.params = { coryKey: encryptedParam, corySimplifiedToTraditional: $cache.local.get('i18n') };
|
||||||
|
} else {
|
||||||
|
config.params = { coryKey: encryptedParam };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 处理FormData类型
|
||||||
|
if (config.data instanceof FormData) {
|
||||||
|
// 将FormData转换为普通对象
|
||||||
|
dataInfoReq = Object.fromEntries(config.data.entries());
|
||||||
|
// 重新创建一个新的FormData实例
|
||||||
|
const newFormData = new FormData();
|
||||||
|
const encryptedData = encryptAES256(JSON.stringify(dataInfoReq), corySecretKey);
|
||||||
|
|
||||||
requestGo.download = function (url: string, params: any, filename: string, method: 'post' | 'get' = 'post') {
|
newFormData.append('coryKey', encryptedData);
|
||||||
return request({
|
if ($cache.local.get('i18n') != null) {
|
||||||
url,
|
newFormData.append('corySimplifiedToTraditional', $cache.local.get('i18n'));
|
||||||
method: method,
|
}
|
||||||
baseURL: BASE_GO_URL,
|
|
||||||
data: method === 'post' ? params : undefined,
|
// 如果有文件,需要重新添加
|
||||||
params: method === 'get' ? params : undefined,
|
for (let [key, value] of config.data.entries()) {
|
||||||
headers: {
|
if (value instanceof File) {
|
||||||
'Authorization': `Bearer ${$cache.local.get('goToken') || ''}`
|
newFormData.append(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.data = newFormData;
|
||||||
|
// 设置Content-Type为undefined,让浏览器自动设置boundary
|
||||||
|
config.headers['Content-Type'] = undefined;
|
||||||
|
} else {
|
||||||
|
dataInfoReq = config.data;
|
||||||
|
const encryptedData = encryptAES256(JSON.stringify(dataInfoReq), corySecretKey);
|
||||||
|
if ($cache.local.get('i18n') != null) {
|
||||||
|
config.data = { coryKey: encryptedData, corySimplifiedToTraditional: $cache.local.get('i18n') };
|
||||||
|
} else {
|
||||||
|
config.data = { coryKey: encryptedData };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { timestamp, nonce, sign: signature } = sign(dataInfoReq);
|
||||||
|
config.headers.timestamp = timestamp;
|
||||||
|
config.headers.nonce = nonce;
|
||||||
|
config.headers.sign = signature;
|
||||||
|
|
||||||
|
return config;
|
||||||
},
|
},
|
||||||
responseType: 'blob'
|
(error) => {
|
||||||
}).then((response) => {
|
// 对请求错误做些什么
|
||||||
// ✅ 只取 response.data
|
return Promise.reject(error);
|
||||||
const blob = new Blob([response.data]);
|
}
|
||||||
const link = document.createElement('a');
|
);
|
||||||
link.style.display = 'none';
|
// 添加响应拦截器
|
||||||
link.href = URL.createObjectURL(blob);
|
service.interceptors.response.use(
|
||||||
link.setAttribute('download', filename);
|
(response) => {
|
||||||
document.body.appendChild(link);
|
// 对响应数据进行解密操作
|
||||||
link.click();
|
try {
|
||||||
document.body.removeChild(link);
|
// 处理特殊情况:data为空值或不需要解密的情况
|
||||||
URL.revokeObjectURL(link.href);
|
if (response.data.data === null || response.data.data === '' || response.data.data === undefined) {
|
||||||
});
|
return response.data;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default requestGo;
|
// 检查响应数据格式
|
||||||
|
if (typeof response.data.data !== 'string') {
|
||||||
|
// 尝试将非字符串数据转换为字符串
|
||||||
|
try {
|
||||||
|
response.data.data = JSON.stringify(response.data.data);
|
||||||
|
} catch (convertError) {
|
||||||
|
throw new Error('响应数据格式不正确,无法转换为字符串');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 执行解密
|
||||||
|
const decryptedData = decryptAES256(response.data.data, corySecretKey);
|
||||||
|
// 正确处理解密后的数据
|
||||||
|
if (decryptedData && typeof decryptedData === 'object') {
|
||||||
|
// 保持response.data的结构不变,只替换data字段的内容
|
||||||
|
response.data = {
|
||||||
|
...response.data,
|
||||||
|
data: decryptedData
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果解密后的数据不是对象,可能需要特殊处理
|
||||||
|
response.data.data = decryptedData;
|
||||||
|
}
|
||||||
|
if (response.data.code !== 0) {
|
||||||
|
ElMessage.error(response.data.message);
|
||||||
|
}
|
||||||
|
return response.data;
|
||||||
|
} catch (decryptError) {
|
||||||
|
// 提供更友好的错误信息
|
||||||
|
if (decryptError.message.includes('无效的Base64格式')) {
|
||||||
|
ElMessage.error('数据格式错误:接收到无效的加密数据');
|
||||||
|
} else {
|
||||||
|
ElMessage.error('数据解密失败,请联系管理员');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(decryptError);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
// 对响应错误做点什么
|
||||||
|
if (error.message.indexOf('timeout') !== -1) {
|
||||||
|
ElMessage.error('网络超时');
|
||||||
|
} else if (error.message === 'Network Error') {
|
||||||
|
ElMessage.error('网络连接错误');
|
||||||
|
} else {
|
||||||
|
console.log(error, '网络错误');
|
||||||
|
|
||||||
|
if (error.response.data) ElMessage.error(error.response.statusText);
|
||||||
|
else {
|
||||||
|
ElMessage.error('接口路径找不到');
|
||||||
|
console.log(error, '接口路径找不到');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 加密函数
|
||||||
|
function encryptAES256(plainText: string, key: string): string | null {
|
||||||
|
try {
|
||||||
|
const parsedKey = CryptoJS.enc.Utf8.parse(key);
|
||||||
|
const iv = CryptoJS.lib.WordArray.random(16);
|
||||||
|
const plainTextWordArray = CryptoJS.enc.Utf8.parse(plainText);
|
||||||
|
const encrypted = CryptoJS.AES.encrypt(plainTextWordArray, parsedKey, {
|
||||||
|
iv: iv,
|
||||||
|
mode: CryptoJS.mode.CBC,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
});
|
||||||
|
const encryptedData = iv.concat(encrypted.ciphertext);
|
||||||
|
return encryptedData.toString(CryptoJS.enc.Base64);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Encryption error:', err.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增强的解密函数,处理各种输入情况
|
||||||
|
function decryptAES256(encryptedData: string, key: string): any {
|
||||||
|
// eslint-disable-next-line no-useless-catch
|
||||||
|
try {
|
||||||
|
// 检查输入是否为有效的Base64字符串
|
||||||
|
if (!/^[A-Za-z0-9+/=]+$/.test(encryptedData)) {
|
||||||
|
// 尝试对非标准Base64字符串进行处理
|
||||||
|
// 移除可能的前缀
|
||||||
|
const cleanData = encryptedData.replace(/^data:.*?;base64,/, '').replace(/\s/g, ''); // 移除空格
|
||||||
|
|
||||||
|
if (!/^[A-Za-z0-9+/=]+$/.test(cleanData)) {
|
||||||
|
throw new Error('无效的Base64格式');
|
||||||
|
}
|
||||||
|
|
||||||
|
return decryptAES256(cleanData, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const decodedData = CryptoJS.enc.Base64.parse(encryptedData);
|
||||||
|
const iv = CryptoJS.lib.WordArray.create(decodedData.words.slice(0, 4));
|
||||||
|
const encryptedText = CryptoJS.lib.WordArray.create(decodedData.words.slice(4));
|
||||||
|
const parsedKey = CryptoJS.enc.Utf8.parse(key);
|
||||||
|
|
||||||
|
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedText }, parsedKey, {
|
||||||
|
iv: iv,
|
||||||
|
mode: CryptoJS.mode.CBC,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
});
|
||||||
|
|
||||||
|
const decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
|
||||||
|
|
||||||
|
// 尝试解析为JSON
|
||||||
|
try {
|
||||||
|
return JSON.parse(decryptedStr);
|
||||||
|
} catch (jsonError) {
|
||||||
|
return decryptedStr;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 导出 axios 实例
|
||||||
|
export default service;
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
<!-- <el-form-item label="所属村委会" prop="villageCommittee">
|
<!-- <el-form-item label="所属村委会" prop="villageCommittee">
|
||||||
<el-input v-model="queryParams.villageCommittee" placeholder="请输入所属村委会" clearable @keyup.enter="handleQuery" />
|
<el-input v-model="queryParams.villageCommittee" placeholder="请输入所属村委会" clearable @keyup.enter="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="设计面积" prop="designArea">
|
<el-form-item label="设计面积(亩)" prop="designArea">
|
||||||
<el-input v-model="queryParams.designArea" placeholder="请输入设计面积" clearable @keyup.enter="handleQuery" />
|
<el-input v-model="queryParams.designArea" type="number" placeholder="请输入设计面积" clearable @keyup.enter="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="地块数" prop="blockCount">
|
<el-form-item label="地块数(块)" prop="blockCount">
|
||||||
<el-input v-model="queryParams.blockCount" placeholder="请输入地块数" clearable @keyup.enter="handleQuery" />
|
<el-input v-model="queryParams.blockCount" type="number" placeholder="请输入地块数" clearable @keyup.enter="handleQuery" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="农户数(户)" prop="farmerCount">
|
<el-form-item label="农户数(户)" prop="farmerCount">
|
||||||
<el-input v-model="queryParams.farmerCount" type="number" placeholder="请输入农户数" clearable @keyup.enter="handleQuery" />
|
<el-input v-model="queryParams.farmerCount" type="number" placeholder="请输入农户数" clearable @keyup.enter="handleQuery" />
|
||||||
@ -53,14 +53,14 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
</template>
|
</template>
|
||||||
<el-table draggable v-loading="loading" :data="landBlockList" @selection-change="handleSelectionChange">
|
<el-table draggable v-loading="loading" :data="landBlockList" @selection-change="handleSelectionChange">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="index" label="序号" width="55" align="center" />
|
||||||
<el-table-column label="地块编号" align="center" prop="landCode" />
|
<el-table-column label="地块编号" align="center" prop="landCode" />
|
||||||
<el-table-column label="地块名称" align="center" prop="landName" />
|
<el-table-column label="地块名称" align="center" prop="landName" />
|
||||||
<el-table-column label="方阵" align="center" prop="unit" />
|
<el-table-column label="方阵" align="center" prop="unit" />
|
||||||
<el-table-column label="所属村委会" align="center" prop="villageCommittee" />
|
<el-table-column label="所属村委会" align="center" prop="villageCommittee" />
|
||||||
<el-table-column label="设计面积" align="center" prop="designArea" />
|
<el-table-column label="设计面积(亩)" align="center" prop="designArea" />
|
||||||
<el-table-column label="地块数" align="center" prop="blockCount" />
|
<el-table-column label="地块数(块)" align="center" prop="blockCount" />
|
||||||
<el-table-column label="农户数" align="center" prop="farmerCount" />
|
<el-table-column label="农户数(户)" align="center" prop="farmerCount" />
|
||||||
<el-table-column label="备注" align="center" prop="remark" />
|
<el-table-column label="备注" align="center" prop="remark" />
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
@ -82,23 +82,20 @@
|
|||||||
<!-- 地块表单弹窗 -->
|
<!-- 地块表单弹窗 -->
|
||||||
<el-dialog draggable :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
<el-dialog draggable :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||||
<el-form ref="landBlockFormRef" :model="form" :rules="rules" label-width="100px">
|
<el-form ref="landBlockFormRef" :model="form" :rules="rules" label-width="100px">
|
||||||
<el-form-item label="地块编号" prop="landCode">
|
|
||||||
<el-input v-model="form.landCode" placeholder="请输入地块编号" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="地块名称" prop="landName">
|
<el-form-item label="地块名称" prop="landName">
|
||||||
<el-input v-model="form.landName" placeholder="请输入地块名称" />
|
<el-input v-model="form.landName" placeholder="请输入地块名称" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="所属村委会" prop="villageCommittee">
|
<el-form-item label="所属村委会" prop="villageCommittee">
|
||||||
<el-input v-model="form.villageCommittee" placeholder="请输入所属村委会" />
|
<el-input v-model="form.villageCommittee" placeholder="请输入所属村委会" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="设计面积" prop="designArea">
|
<el-form-item label="设计面积(亩)" prop="designArea">
|
||||||
<el-input v-model="form.designArea" placeholder="请输入设计面积" />
|
<el-input type="number" v-model="form.designArea" placeholder="请输入设计面积" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="地块数" prop="blockCount">
|
<el-form-item label="地块数(块)" prop="blockCount">
|
||||||
<el-input v-model="form.blockCount" placeholder="请输入地块数" />
|
<el-input type="number" v-model="form.blockCount" placeholder="请输入地块数" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="农户数" prop="farmerCount">
|
<el-form-item label="农户数(户)" prop="farmerCount">
|
||||||
<el-input v-model="form.farmerCount" placeholder="请输入农户数" />
|
<el-input type="number" v-model="form.farmerCount" placeholder="请输入农户数" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="备注" prop="remark">
|
<el-form-item label="备注" prop="remark">
|
||||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
|
||||||
@ -106,7 +103,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="dialog-footer">
|
<div class="dialog-footer">
|
||||||
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm" v-hasPermi="['land:landBlock:add']">确 定</el-button>
|
||||||
<el-button @click="cancel">取 消</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -131,7 +128,7 @@
|
|||||||
>
|
>
|
||||||
<el-cascader
|
<el-cascader
|
||||||
:options="fangzhenList"
|
:options="fangzhenList"
|
||||||
placeholder="请选择"
|
placeholder="请选择方阵"
|
||||||
filterable
|
filterable
|
||||||
:props="{ value: 'matrixId', label: 'name' }"
|
:props="{ value: 'matrixId', label: 'name' }"
|
||||||
v-model="item.unitProjectId"
|
v-model="item.unitProjectId"
|
||||||
@ -151,7 +148,11 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
<!-- 方阵状态:保留原有规则 -->
|
<!-- 方阵状态:保留原有规则 -->
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item label="方阵状态" prop="unitProjectStatus">
|
<el-form-item
|
||||||
|
label="方阵状态"
|
||||||
|
:prop="`unitBoList[${i}].unitProjectStatus`"
|
||||||
|
:rules="{ required: true, message: '请输入方阵状态', trigger: 'blur' }"
|
||||||
|
>
|
||||||
<el-input v-model="item.unitProjectStatus" placeholder="请输入方阵状态" />
|
<el-input v-model="item.unitProjectStatus" placeholder="请输入方阵状态" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -178,7 +179,16 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="LandBlock" lang="ts">
|
<script setup name="LandBlock" lang="ts">
|
||||||
import { listLandBlock, getLandBlock, delLandBlock, LandUnit, addLandBlock, updateLandBlock, subMatrix } from '@/api/system/landTransfer/landBlock';
|
import {
|
||||||
|
listLandBlock,
|
||||||
|
getLandBlock,
|
||||||
|
delLandBlock,
|
||||||
|
LandUnit,
|
||||||
|
addLandBlock,
|
||||||
|
updateLandBlock,
|
||||||
|
subMatrix,
|
||||||
|
importLandBlock
|
||||||
|
} from '@/api/system/landTransfer/landBlock';
|
||||||
import { LandBlockVO, LandBlockQuery, LandBlockForm } from '@/api/system/landTransfer/landBlock/types';
|
import { LandBlockVO, LandBlockQuery, LandBlockForm } from '@/api/system/landTransfer/landBlock/types';
|
||||||
import { useUserStoreHook } from '@/store/modules/user';
|
import { useUserStoreHook } from '@/store/modules/user';
|
||||||
import { getCurrentInstance, ComponentInternalInstance, onMounted, onUnmounted, watch, reactive, ref, toRefs, computed } from 'vue';
|
import { getCurrentInstance, ComponentInternalInstance, onMounted, onUnmounted, watch, reactive, ref, toRefs, computed } from 'vue';
|
||||||
@ -212,10 +222,10 @@ interface MatrixForm {
|
|||||||
|
|
||||||
// 基础实例与Store
|
// 基础实例与Store
|
||||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
// 获取用户 store
|
|
||||||
const userStore = useUserStoreHook();
|
const userStore = useUserStoreHook();
|
||||||
// 从 store 中获取项目列表和当前选中的项目
|
|
||||||
const currentProject = computed(() => userStore.selectedProject);
|
const currentProject = computed(() => userStore.selectedProject);
|
||||||
|
|
||||||
|
// 响应式数据
|
||||||
const landBlockList = ref<LandBlockVO[]>([]);
|
const landBlockList = ref<LandBlockVO[]>([]);
|
||||||
const fangzhenList = ref<FangzhenOption[]>([]);
|
const fangzhenList = ref<FangzhenOption[]>([]);
|
||||||
const buttonLoading = ref(false);
|
const buttonLoading = ref(false);
|
||||||
@ -234,23 +244,20 @@ const ids = ref<Array<string | number>>([]);
|
|||||||
const single = ref(true);
|
const single = ref(true);
|
||||||
const multiple = ref(true);
|
const multiple = ref(true);
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
|
|
||||||
|
// 表单Ref
|
||||||
const queryFormRef = ref<ElFormInstance>();
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
const landBlockFormRef = ref<ElFormInstance>();
|
const landBlockFormRef = ref<ElFormInstance>();
|
||||||
const landBlockFormMatrixRef = ref<ElFormInstance>();
|
const landBlockFormMatrixRef = ref<ElFormInstance>();
|
||||||
|
|
||||||
const dialog = reactive<DialogOption>({
|
// 弹窗配置
|
||||||
visible: false,
|
const dialog = reactive<DialogOption>({ visible: false, title: '' });
|
||||||
title: ''
|
const dialogMatrix = reactive<DialogOption>({ visible: false, title: '选择方阵' });
|
||||||
});
|
|
||||||
|
|
||||||
const dialogMatrix = reactive<DialogOption>({
|
|
||||||
visible: false,
|
|
||||||
title: '选择方阵'
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// 初始表单数据
|
||||||
const initFormData: LandBlockForm = {
|
const initFormData: LandBlockForm = {
|
||||||
id: undefined,
|
id: undefined,
|
||||||
projectId: currentProject.value.id,
|
projectId: currentProject.value?.id,
|
||||||
landCode: undefined,
|
landCode: undefined,
|
||||||
landName: undefined,
|
landName: undefined,
|
||||||
villageCommittee: undefined,
|
villageCommittee: undefined,
|
||||||
@ -259,12 +266,14 @@ const initFormData: LandBlockForm = {
|
|||||||
farmerCount: undefined,
|
farmerCount: undefined,
|
||||||
remark: undefined
|
remark: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 核心数据(含表单规则)
|
||||||
const data = reactive({
|
const data = reactive({
|
||||||
form: { ...initFormData },
|
form: { ...initFormData },
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
projectId: currentProject.value.id,
|
projectId: currentProject.value?.id,
|
||||||
landCode: undefined,
|
landCode: undefined,
|
||||||
landName: undefined,
|
landName: undefined,
|
||||||
villageCommittee: undefined,
|
villageCommittee: undefined,
|
||||||
@ -284,91 +293,117 @@ const data = reactive({
|
|||||||
|
|
||||||
const { queryParams, form, rules } = toRefs(data);
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
/** 查询地块信息列表 */
|
/** 查询地块列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
try {
|
||||||
const res = await listLandBlock(queryParams.value);
|
const res = await listLandBlock(queryParams.value);
|
||||||
landBlockList.value = res.rows;
|
landBlockList.value = res.rows;
|
||||||
total.value = res.total;
|
total.value = res.total;
|
||||||
|
} catch (err) {
|
||||||
|
proxy?.$modal.msgError('获取地块列表失败');
|
||||||
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 取消按钮 */
|
/** 地块表单取消 */
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
reset();
|
reset();
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 表单重置 */
|
/** 地块表单重置 */
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
form.value = { ...initFormData };
|
form.value = { ...initFormData };
|
||||||
landBlockFormRef.value?.resetFields();
|
landBlockFormRef.value?.resetFields();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索提交 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
queryParams.value.pageNum = 1;
|
queryParams.value.pageNum = 1;
|
||||||
getList();
|
getList();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
/** 搜索重置 */
|
||||||
const resetQuery = () => {
|
const resetQuery = () => {
|
||||||
queryFormRef.value?.resetFields();
|
queryFormRef.value?.resetFields();
|
||||||
handleQuery();
|
handleQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 多选框选中数据 */
|
/** 表格选择变化 */
|
||||||
const handleSelectionChange = (selection: LandBlockVO[]) => {
|
const handleSelectionChange = (selection: LandBlockVO[]) => {
|
||||||
ids.value = selection.map((item) => item.id);
|
ids.value = selection.map((item) => item.id);
|
||||||
single.value = selection.length != 1;
|
single.value = selection.length !== 1;
|
||||||
multiple.value = !selection.length;
|
multiple.value = selection.length === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 新增按钮操作 */
|
/** 新增地块 */
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
reset();
|
reset();
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = '添加地块信息';
|
dialog.title = '添加地块信息';
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 修改按钮操作 */
|
/** 编辑地块 */
|
||||||
const handleUpdate = async (row?: LandBlockVO) => {
|
const handleUpdate = async (row?: LandBlockVO) => {
|
||||||
reset();
|
reset();
|
||||||
const _id = row?.id || ids.value[0];
|
const _id = row?.id || ids.value[0];
|
||||||
|
if (!_id) return proxy?.$modal.msgWarning('请选择要编辑的地块');
|
||||||
|
|
||||||
|
try {
|
||||||
const res = await getLandBlock(_id);
|
const res = await getLandBlock(_id);
|
||||||
Object.assign(form.value, res.data);
|
Object.assign(form.value, res.data);
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.title = '修改地块信息';
|
dialog.title = '修改地块信息';
|
||||||
|
} catch (err) {
|
||||||
|
proxy?.$modal.msgError('获取地块详情失败');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 提交按钮 */
|
/** 提交地块表单 */
|
||||||
const submitForm = () => {
|
const submitForm = () => {
|
||||||
landBlockFormRef.value?.validate(async (valid: boolean) => {
|
landBlockFormRef.value?.validate(async (valid: boolean) => {
|
||||||
if (valid) {
|
if (!valid) return;
|
||||||
|
|
||||||
buttonLoading.value = true;
|
buttonLoading.value = true;
|
||||||
|
try {
|
||||||
if (form.value.id) {
|
if (form.value.id) {
|
||||||
await updateLandBlock(form.value).finally(() => (buttonLoading.value = false));
|
await updateLandBlock(form.value);
|
||||||
} else {
|
} else {
|
||||||
await addLandBlock(form.value).finally(() => (buttonLoading.value = false));
|
await addLandBlock(form.value);
|
||||||
}
|
}
|
||||||
proxy?.$modal.msgSuccess('操作成功');
|
proxy?.$modal.msgSuccess('操作成功');
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
await getList();
|
await getList();
|
||||||
|
} catch (err) {
|
||||||
|
proxy?.$modal.msgError(form.value.id ? '修改失败' : '新增失败');
|
||||||
|
} finally {
|
||||||
|
buttonLoading.value = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
/** 删除地块 */
|
||||||
const handleDelete = async (row?: LandBlockVO) => {
|
const handleDelete = async (row?: LandBlockVO) => {
|
||||||
const _ids = row?.id || ids.value;
|
const _ids = row?.id || ids.value;
|
||||||
await proxy?.$modal.confirm('是否确认删除地块信息编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
|
if (!_ids.length) return proxy?.$modal.msgWarning('请选择要删除的地块');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await proxy?.$modal.confirm(`是否确认删除地块信息编号为"${_ids}"的数据项?`);
|
||||||
await delLandBlock(_ids);
|
await delLandBlock(_ids);
|
||||||
proxy?.$modal.msgSuccess('删除成功');
|
proxy?.$modal.msgSuccess('删除成功');
|
||||||
await getList();
|
await getList();
|
||||||
|
} catch (err) {
|
||||||
|
// 取消确认时不提示错误
|
||||||
|
if (err !== 'cancel') proxy?.$modal.msgError('删除失败');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取方阵列表
|
/** 获取方阵列表 */
|
||||||
const getfangzhenList = async () => {
|
const getfangzhenList = async () => {
|
||||||
|
if (!currentProject.value?.id) return;
|
||||||
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const res = await subMatrix(currentProject.value.id);
|
const res = await subMatrix(currentProject.value.id);
|
||||||
@ -399,7 +434,8 @@ const handleView = async (row: LandBlockVO) => {
|
|||||||
|
|
||||||
dialogMatrix.title = `关联方阵(地块:${row.landName || row.landCode})`;
|
dialogMatrix.title = `关联方阵(地块:${row.landName || row.landCode})`;
|
||||||
};
|
};
|
||||||
// 动态添加unitBoList项
|
|
||||||
|
/** 新增方阵表单项 */
|
||||||
const addUnitBoItem = () => {
|
const addUnitBoItem = () => {
|
||||||
formM.value.unitBoList.push({
|
formM.value.unitBoList.push({
|
||||||
unitProjectArea: '',
|
unitProjectArea: '',
|
||||||
@ -410,7 +446,7 @@ const addUnitBoItem = () => {
|
|||||||
landBlockFormMatrixRef.value?.clearValidate();
|
landBlockFormMatrixRef.value?.clearValidate();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 移除unitBoList项
|
/** 删除方阵表单项 */
|
||||||
const removeUnitBoItem = (index: number) => {
|
const removeUnitBoItem = (index: number) => {
|
||||||
if (formM.value.unitBoList.length <= 1) {
|
if (formM.value.unitBoList.length <= 1) {
|
||||||
return proxy?.$modal.msgWarning('至少保留一项方阵配置');
|
return proxy?.$modal.msgWarning('至少保留一项方阵配置');
|
||||||
@ -443,18 +479,27 @@ const submitFormMatrix = () => {
|
|||||||
unitProjectName: unitProjectName
|
unitProjectName: unitProjectName
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
var res = await LandUnit({ ...formM.value, unitBoList: arr });
|
|
||||||
if (res.code == 200) {
|
// 调用关联接口
|
||||||
proxy?.$modal.msgSuccess('操作成功');
|
const res = await LandUnit({
|
||||||
|
landId: formM.value.landId,
|
||||||
|
unitBoList: unitBoListParams
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
proxy?.$modal.msgSuccess('关联方阵成功');
|
||||||
dialogMatrix.visible = false;
|
dialogMatrix.visible = false;
|
||||||
await getList();
|
await getList();
|
||||||
} else {
|
} else {
|
||||||
proxy?.$modal.msgError(res.msg);
|
proxy?.$modal.msgError(res.msg || '关联失败');
|
||||||
}
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
proxy?.$modal.msgError(err.msg || '关联过程异常');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/** 取消按钮 */
|
|
||||||
|
/** 方阵表单取消 */
|
||||||
const cancelMatrix = () => {
|
const cancelMatrix = () => {
|
||||||
resetMatrix();
|
resetMatrix();
|
||||||
dialogMatrix.visible = false;
|
dialogMatrix.visible = false;
|
||||||
@ -469,7 +514,8 @@ const resetMatrix = () => {
|
|||||||
formM.value.landId = undefined;
|
formM.value.landId = undefined;
|
||||||
formM.value.unitBoList = [{ unitProjectArea: '', unitProjectStatus: '', unitProjectId: [] }];
|
formM.value.unitBoList = [{ unitProjectArea: '', unitProjectStatus: '', unitProjectId: [] }];
|
||||||
};
|
};
|
||||||
//监听项目id刷新数据
|
|
||||||
|
/** 监听项目变化,刷新数据 */
|
||||||
const listeningProject = watch(
|
const listeningProject = watch(
|
||||||
() => currentProject.value?.id,
|
() => currentProject.value?.id,
|
||||||
(newId) => {
|
(newId) => {
|
||||||
@ -543,6 +589,8 @@ const downloadTemplate = () => {
|
|||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
listeningProject();
|
listeningProject();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** 生命周期:组件挂载时初始化数据 */
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getList();
|
getList();
|
||||||
getfangzhenList();
|
getfangzhenList();
|
||||||
|
@ -1089,6 +1089,11 @@ const submitForm = () => {
|
|||||||
proxy?.$modal.msgSuccess('操作成功');
|
proxy?.$modal.msgSuccess('操作成功');
|
||||||
dialog.visible = false;
|
dialog.visible = false;
|
||||||
await getList();
|
await getList();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('操作失败:', error);
|
||||||
|
proxy?.$modal.msgError('操作失败,请重试');
|
||||||
|
} finally {
|
||||||
|
buttonLoading.value = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user