优化查询时间

master
fanluyan 1 year ago
parent 73f448a7d5
commit 6df8ca53ce

@ -16,7 +16,7 @@
ref="tree" ref="tree"
:data="treeData" :data="treeData"
:props="defaultProps" :props="defaultProps"
node-key="id" node-key="compositeKey"
:filter-node-method="filterNode" :filter-node-method="filterNode"
:default-expand-all="true" :default-expand-all="true"
highlight-current highlight-current
@ -216,6 +216,7 @@ export default {
defaultProps: { defaultProps: {
children: "children", children: "children",
label: "name", label: "name",
key: "compositeKey", // 使 uniqueKey
}, },
formdata: {}, //form formdata: {}, //form
activeName: "dataTab", activeName: "dataTab",
@ -262,18 +263,20 @@ export default {
}, },
}, },
created() { created() {
const thirtyDaysAgo = new Date(); // const thirtyDaysAgo = new Date();
this.$set( // this.$set(
this.formdata, // this.formdata,
"starttime", // "starttime",
new Date(thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)) // new Date(thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30))
); // );
console.log(this.formdata.starttime); // console.log(this.formdata.starttime);
const currentDate = new Date(); // // const currentDate = new Date(); //
currentDate.setHours(23); // 23 // currentDate.setHours(23); // 23
currentDate.setMinutes(59); // 59 // currentDate.setMinutes(59); // 59
currentDate.setSeconds(59); // 59 // currentDate.setSeconds(59); // 59
this.$set(this.formdata, "endtime", currentDate); // this.$set(this.formdata, "endtime", currentDate);
// console.log("", this.formdata.starttime);
// console.log("", currentDate);
this.treeData = []; this.treeData = [];
this.getSubNodes(); this.getSubNodes();
}, },
@ -302,13 +305,14 @@ export default {
if (response.data && response.data.length > 0) { if (response.data && response.data.length > 0) {
console.log(response.data); console.log(response.data);
//node.children = response.data.content; // children //node.children = response.data.content; // children
this.treeData = response.data; // children //this.treeData = response.data; // children
this.treeData = this.processData(response.data);
console.log(this.treeData[0]); console.log(this.treeData[0]);
this.defaultExpandedKeys = [ this.defaultExpandedKeys = [
this.treeData[0].children[0].children[0].id, this.treeData[0].children[0].children[0].id,
]; ];
this.currentNodekey = this.currentNodekey =
this.treeData[0].children[0].children[0].children[0].id; this.treeData[0].children[0].children[0].children[0].compositeKey;
console.log("我是选中的id", this.currentNodekey); console.log("我是选中的id", this.currentNodekey);
this.currentNodeData = this.currentNodeData =
this.treeData[0].children[0].children[0].children[0]; this.treeData[0].children[0].children[0].children[0];
@ -323,8 +327,19 @@ export default {
console.error("Failed to fetch sub-nodes:", error); // console.error("Failed to fetch sub-nodes:", error); //
} }
}, },
processData(data, level = 0) {
return data.map((node) => {
const compositeKey = `${level}-${node.id}`; //
node.compositeKey = compositeKey; //
if (node.children) {
node.children = this.processData(node.children, level + 1); //
}
return node;
});
},
handleNodeClick(data, node) { handleNodeClick(data, node) {
console.log(data, node); console.log(data, node);
console.log(this.currentNodeKey); console.log(this.currentNodeKey);
if (data.hasOwnProperty("children")) { if (data.hasOwnProperty("children")) {
this.$nextTick(() => { this.$nextTick(() => {
@ -339,7 +354,7 @@ export default {
// }); // });
// return; // return;
// } // }
this.currentNodeKey = data.id; this.currentNodeKey = data.compositeKey;
this.crrrentName = data.name; this.crrrentName = data.name;
this.currentId = data.id; this.currentId = data.id;
this.page = 1; this.page = 1;
@ -384,14 +399,49 @@ export default {
.then((res) => { .then((res) => {
console.log(res); console.log(res);
if (res.success) { if (res.success) {
console.log(res.data.content[0].acquisitionTime); if (res.data.content.length == 0) {
this.formdata.endtime = res.data.content[0].acquisitionTime; // this.formdata.endtime = new Date();
const thirtyDaysAgo = new Date(this.formdata.endtime); // const thirtyDaysAgo = new Date(this.formdata.endtime);
this.$set( // this.$set(
this.formdata, // this.formdata,
"starttime", // "starttime",
new Date(thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)) // new Date(thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30))
); // );
const thirtyDaysAgo = new Date();
this.$set(
this.formdata,
"starttime",
new Date(thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30))
);
console.log(this.formdata.starttime);
const currentDate = new Date(); //
console.log("asddddadadadadadasd", currentDate);
currentDate.setHours(23); // 23
currentDate.setMinutes(59); // 59
currentDate.setSeconds(59); // 59
this.$set(this.formdata, "endtime", currentDate);
console.log("我是开始时间", this.formdata.starttime);
console.log("我是结束时间", currentDate);
} else {
console.log(res.data.content[0].acquisitionTime);
this.formdata.endtime = res.data.content[0].acquisitionTime;
const qet = new Date(this.formdata.endtime);
qet.setHours(23); // 23
qet.setMinutes(59); // 59
qet.setSeconds(59); // 59
this.$set(this.formdata, "endtime", qet);
const thirtyDaysAgo = new Date(this.formdata.endtime);
thirtyDaysAgo.setHours(0); // 23
thirtyDaysAgo.setMinutes(0); // 59
thirtyDaysAgo.setSeconds(0); // 59
this.$set(
this.formdata,
"starttime",
new Date(thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30))
);
}
this.handleSearch(); this.handleSearch();
} else { } else {
this.tableData = []; this.tableData = [];

@ -15,7 +15,7 @@
:model="formInfo" :model="formInfo"
> >
<el-form-item label="主设备名称:" prop="zsbName"> <el-form-item label="主设备名称:" prop="zsbName">
<el-input v-model="formInfo.zsbName"></el-input> <el-input v-model="formInfo.zsbName" :disabled="true"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="名称:" prop="name"> <el-form-item label="名称:" prop="name">
<el-input v-model="formInfo.name"></el-input> <el-input v-model="formInfo.name"></el-input>
@ -95,7 +95,7 @@ export default {
if (valid) { if (valid) {
if (this.title == "添加监测设备") { if (this.title == "添加监测设备") {
console.log(this.formInfo); console.log(this.formInfo);
this.$set(this.formInfo, "zsbId", this.zsbInfo.id); this.$set(this.formInfo, "zsbId", this.formInfo.zsbId);
modevAddApi(this.formInfo) modevAddApi(this.formInfo)
.then((res) => { .then((res) => {
if (res.success) { if (res.success) {
@ -111,7 +111,7 @@ export default {
}) })
.catch((err) => {}); .catch((err) => {});
} else { } else {
this.$set(this.formInfo, "zsbId", this.zsbInfo.id); this.$set(this.formInfo, "zsbId", this.formInfo.zsbId);
console.log(this.formInfo); console.log(this.formInfo);
modevUpdateApi(this.formInfo) modevUpdateApi(this.formInfo)
.then((res) => { .then((res) => {

@ -15,7 +15,7 @@
:model="formInfo" :model="formInfo"
> >
<el-form-item label="主设备名称:" prop="zsbName"> <el-form-item label="主设备名称:" prop="zsbName">
<el-input v-model="formInfo.zsbName"></el-input> <el-input v-model="formInfo.zsbName" :disabled="true"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="名称:" prop="name"> <el-form-item label="名称:" prop="name">
<el-input v-model="formInfo.name"></el-input> <el-input v-model="formInfo.name"></el-input>
@ -95,7 +95,7 @@ export default {
if (valid) { if (valid) {
if (this.title == "添加监测设备") { if (this.title == "添加监测设备") {
console.log(this.formInfo); console.log(this.formInfo);
this.$set(this.formInfo, "zsbId", this.zsbInfo.id); this.$set(this.formInfo, "zsbId", this.formInfo.zsbId);
modevAddApi(this.formInfo) modevAddApi(this.formInfo)
.then((res) => { .then((res) => {
if (res.success) { if (res.success) {
@ -111,7 +111,7 @@ export default {
}) })
.catch((err) => {}); .catch((err) => {});
} else { } else {
this.$set(this.formInfo, "zsbId", this.zsbInfo.id); this.$set(this.formInfo, "zsbId", this.formInfo.zsbId);
console.log(this.formInfo); console.log(this.formInfo);
modevUpdateApi(this.formInfo) modevUpdateApi(this.formInfo)
.then((res) => { .then((res) => {

Loading…
Cancel
Save