main
wangqiujuan0808 2024-10-23 17:21:26 +08:00
parent 95f95f2417
commit c5ee7b915c
6 changed files with 245 additions and 101 deletions

View File

@ -175,6 +175,10 @@ const infoApi = {
startHis(params) {
return postPBRequest("/data", params, 56002);
},
//
endHis(params) {
return postPBRequest("/data", params, 56003);
},
//
exportHis(params) {
return postPBRequest("/data", params, 56006);

View File

@ -2,36 +2,45 @@
<el-drawer v-model="visible" direction="rtl" :before-close="closeDialog">
<div class="count-status">
<el-tag>最大计数: {{ formData.history && formData.history.max }}</el-tag>
<el-tag>状态: {{ formData.history && !formData.history.enable?"启用":"禁用" }}</el-tag>
<el-tag>状态: {{ formData.history && formData.history.enable ? "启用" : "禁用" }}</el-tag>
</div>
<div>
<el-table :data="tableData" height="400" border
:header-cell-style="{ background: '#F6F7FC' }" size="large">
<el-table :data="tableData" height="400" border :header-cell-style="{ background: '#F6F7FC' }" size="large">
<el-table-column type="index" label="序号" width="80" align="center" />
<el-table-column prop="timestamp" label="时间戳" align="center" />
<el-table-column prop="value" label="点位值" align="center" />
</el-table>
</div>
<div class="btns">
<el-button type="primary" size="large" @click="setHis"></el-button>
<el-button type="primary" size="large" @click="startHis"></el-button>
<el-button type="primary" size="large" @click="startHis" v-if="formData.history &&
!formData.history.enable">启用</el-button>
<el-button type="danger" size="large" v-else @click="startHis"></el-button>
<el-button type="primary" size="large" @click="exportHis"></el-button>
<el-button type="primary" size="large" @click="clearHis"></el-button>
</div>
<SetHis :dialogVisible="dialogVisible1" :formData="formData" v-if="dialogVisible1"
@dialogClose="dialogVisible1 = false" @dialogSuccess="dialogSuccess1">
</SetHis>
</el-drawer>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
import SetHis from '@/components/SetHis.vue'
import axios from "axios";
export default {
components: {
SetHis
},
props: ["dialogVisible", "formData"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const state = reactive({
tableData: [],
dialogVisible1: false,
})
const ruleFormRef = ref(null);
@ -44,21 +53,13 @@ export default {
state.tableData = props.formData.history.history_value
});
const setHis = async () => {
const parm = {
driver_name: props.formData.driver_name,
device_name: props.formData.device_name,
point_name: props.formData.point_name,
history: {
max: props.formData.history.max
}
}
const res = await infoApi.setHis(parm);
if (res.code == 0) {
state.name = res.data.name
ElMessage.success(res.message || "请求成功");
const dialogSuccess1 = () => {
state.dialogVisible1 = false;
ctx.emit("dialogClose");
}
};
const setHis = async () => {
state.dialogVisible1 = true;
}
const startHis = async () => {
const parm = {
@ -66,23 +67,45 @@ export default {
device_name: props.formData.device_name,
point_name: props.formData.point_name,
}
const res = await infoApi.startHis(parm);
const res = props.formData.history && !props.formData.history.enable ? await infoApi.startHis(parm) : await infoApi.endHis(parm);
if (res.code == 0) {
ElMessage.success(res.data || "请求成功");
ctx.emit("dialogClose");
}
}
const exportHis = async () => {
const parm = {
// const parm = {
// driver_name: props.formData.driver_name,
// device_name: props.formData.device_name,
// point_name: props.formData.point_name,
// }
// const res = await infoApi.exportHis(parm);
// const url = window.URL.createObjectURL(new Blob([res]));
// window.open(url);
const params = {
driver_name: props.formData.driver_name,
device_name: props.formData.device_name,
point_name: props.formData.point_name,
}
const res = await infoApi.exportHis(parm);
const url = window.URL.createObjectURL(new Blob([res]));
window.open(url);
};
axios({
method: "post",
url: '/data',
headers: {
"action": 56006,
},
data: params,
responseType: 'blob',
}).then((response) => {
let fileName = response.headers['content-disposition'].split('filename=')[1];
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `${decodeURI(fileName.split('"')[1])}`);
document.body.appendChild(link);
link.click();
}).catch();
}
const clearHis = async () => {
const parm = {
@ -108,7 +131,8 @@ export default {
setHis,
startHis,
exportHis,
clearHis
clearHis,
dialogSuccess1
};
},
};
@ -122,6 +146,7 @@ export default {
margin-left: 10px;
}
}
.count-status {
display: flex;
justify-content: space-around;

View File

@ -54,7 +54,8 @@
<legend class="box-ht">专属配置</legend>
<el-form-item label="COM" prop="com_name">
<el-select v-model="form2.com_name" clearable>
<el-option v-for="item in comArr" :label="item.name" :value="item.name" :key="item.name"></el-option>
<el-option v-for="item in comArr" :label="item.name" :value="item.name" :key="item.name" :disabled="item.occupied">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="数据位" prop="dataBits" clearable>

114
src/components/SetHis.vue Normal file
View File

@ -0,0 +1,114 @@
<template>
<el-dialog v-model="visible" title="设定" width="25%" :before-close="closeDialog">
<el-form :model="addForm" label-width="100px" :rules="rules" ref="ruleFormRef" size="large" label-position="top">
<el-form-item label="历史记录最大数量:" prop="max">
<el-input v-model="addForm.max" placeholder="请输入历史记录最大数量" clearable type="number" />
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button size="large" @click="closeDialog"></el-button>
<el-button size="large" type="primary" @click="saveP"> </el-button>
</span>
</template>
</el-dialog>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
export default {
props: ["formData", "dialogVisible"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const checkMax = (rule, value, callback) => {
let num = Number(value);
if (value && (num >= 50 && num <= 250)) {
callback();
} else {
callback(new Error("最大值50-250"));
}
};
const ruleFormRef = ref(null);
const state = reactive({
addForm: {
},
rules: {
max: [
{ required: true, message: "请输入历史记录最大数量", trigger: "blur" },
{ required: true, validator: checkMax, trigger: "blur" }
],
},
});
const visible = computed(() => {
return props.dialogVisible;
});
onMounted(() => {
});
const closeDialog = () => {
ctx.emit("dialogClose");
};
const saveP = async () => {
await ruleFormRef.value.validate(async (valid) => {
if (valid) {
const parm = {
driver_name: props.formData.driver_name,
device_name: props.formData.device_name,
point_name: props.formData.point_name,
history: {
max: Number(state.addForm.max)
}
}
const res = await infoApi.setHis(parm);
if (res.code == 0) {
ElMessage.success(res.data || "请求成功");
ctx.emit("dialogSuccess");
}
} else {
}
});
};
return {
...toRefs(state),
visible,
closeDialog,
saveP,
ruleFormRef,
};
},
};
</script>
<style lang="scss" scoped>
.top-title {
width: 100%;
::v-deep .el-card__body {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: 800;
font-size: 16px;
}
}
.btns {
padding: 15px 0;
width: 100%;
display: flex;
justify-content: space-between;
}
.flex-center {
display: flex;
justify-content: center;
padding: 10px 0;
cursor: pointer;
}
</style>

View File

@ -160,9 +160,9 @@ export default {
onMounted(() => {
getTxStatus();
getPointType();
state.intervalId = setInterval(() =>
getDriverData(), 1000);
getDriverData()
// state.intervalId = setInterval(() =>
// getDriverData(), 1000);
});
onUnmounted(() => {

View File

@ -38,8 +38,8 @@ export default ({ mode }) => defineConfig({
// target: 'http://cdcm_test_api.shikicc.com:58909',
// target: 'http://frp.shikicc.com:58951',
// target: 'https://cdcm_api2.shikicc.com',
// target: 'https://cdcm_api.shikicc.com',
target: 'http://localhost:8088',
target: 'https://cdcm_api.shikicc.com',
// target: 'http://localhost:8088',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '/api')
}