whyczyk
2020-11-21 a3ff79d37a4be09d69e3d40d8406c41ff342009e
启动养护/除锍 功能
2个文件已修改
605 ■■■■■ 已修改文件
src/assets/js/const/const_curing.js 41 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/params/CuringParams.vue 564 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/js/const/const_curing.js
@@ -1,11 +1,10 @@
export default {
    cmd: {
        read: 0xA0,     // 读取
        set: 0xA1,      // 设置
        stop: 0xA4,     // 停止
        read: 0xA0, // 读取
        set: 0xA1, // 设置
        stop: 0xA4, // 停止
    },
    testType: [
        {
    testType: [{
            label: '除硫',
            value: 0xA2
        },
@@ -13,5 +12,35 @@
            label: '养护',
            value: 0xA3
        }
    ]
    ],
    dischargeRules: {
        FloatVol: { // 浮充电压
            pattern: /^[0-9]{1,2}(\.[0-9]{0,1})?$/,
            regVal: true,
            min: 0,
            max: 90,
            msg: '取值范围0.0~90.0(保留一位小数)'
        },
        Strength: { // 除硫强度
            pattern: /^[0-9]{1,3}$/,
            regVal: true,
            min: 0,
            max: 30,
            msg: '取值范围1~30(整数)'
        },
        YHStrength: { // 养护强度
            pattern: /^[0-9]{1,3}$/,
            regVal: true,
            min: 0,
            max: 30,
            msg: '取值范围1~30(整数)'
        },
        TimeLong: { // 除硫天数
            pattern: /^[0-9]{1,3}$/,
            regVal: true,
            min: 0,
            max: 999,
            msg: '取值范围1~999(整数)'
        },
    }
}
src/components/params/CuringParams.vue
@@ -1,12 +1,6 @@
<template>
    <div class="params-container">
        <el-form
            ref="ruleForm"
            size="mini"
            label-position="top"
            :model="params"
            :rules="rules"
            class="params-dialog">
        <el-form ref="ruleForm" size="mini" label-position="top" :model="params" :rules="rules" class="params-dialog">
            <el-form-item label="电池组名称">
                <el-input v-model="otherParams.groupName" readonly></el-input>
            </el-form-item>
@@ -20,9 +14,7 @@
                    <div class="table-cell">
                        <el-form-item label="除硫/养护">
                            <el-select v-model="op_cmd" placeholder="请选择">
                                <el-option
                                    v-for="item in testType" :key="item.value"
                                    :label="item.label"
                                <el-option v-for="item in testType" :key="item.value" :label="item.label"
                                    :value="item.value"></el-option>
                            </el-select>
                        </el-form-item>
@@ -35,36 +27,37 @@
                        </el-form-item>
                    </div>
                    <div class="table-cell">
                        <el-form-item label="电池组号">
                            <el-select v-model="params.GroupNum" placeholder="请选择">
                        <el-form-item label="模块编号">
                            <el-select v-model="params.GroupNum" placeholder="请选择" @change="changeGroupNum">
                                <el-option :value="1">1</el-option>
                                <el-option :value="2">2</el-option>
                                <el-option :value="3">3</el-option>
                                <el-option :value="4">4</el-option>
                                <el-option :value="5">5</el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                </div>
                <div class="table-row">
                    <div class="table-cell pr16">
                        <el-form-item label="浮充电压(0~90V)">
                        <el-form-item label="浮充电压(0~90V)" prop="FloatVol">
                            <el-input v-model="params.FloatVol"></el-input>
                        </el-form-item>
                    </div>
                    <div class="table-cell">
                        <el-form-item label="除硫强度(0~30)">
                        <el-form-item label="除硫强度(0~30)" prop="Strength">
                            <el-input v-model="params.Strength"></el-input>
                        </el-form-item>
                    </div>
                </div>
                <div class="table-row">
                    <div class="table-cell pr16">
                        <el-form-item label="养护强度(0~30)">
                        <el-form-item label="养护强度(0~30)" prop="YHStrength">
                            <el-input v-model="params.YHStrength"></el-input>
                        </el-form-item>
                    </div>
                    <div class="table-cell">
                        <el-form-item label="除硫天数(0~999天)">
                        <el-form-item label="除硫天数(0~999天)" prop="TimeLong">
                            <el-input v-model="params.TimeLong"></el-input>
                        </el-form-item>
                    </div>
@@ -80,252 +73,331 @@
</template>
<script>
import {
    const_curing
} from '@/assets/js/const'
export default {
    name: "CuringParams",
    props: {
        batt: {
            type: Object,
            default() {
                return {}
    import {
        const_curing
    } from '@/assets/js/const'
    import {
        testVal
    } from '../../assets/js/tools'
    export default {
        name: "CuringParams",
        props: {
            batt: {
                type: Object,
                default () {
                    return {}
                }
            }
        }
    },
    data() {
        let cmd = const_curing.cmd;
        let testType = const_curing.testType;
        return {
            loading: 0,
            cmd: cmd,
            op_cmd: testType[0].value,
            testType: testType,
            startTestFlag: false,       // 启动测试的状态
            setTestFlag: false,         // 设置参数的状态
            params: {
                dev_id: 0,
                GroupNum: 1,        // 电池组号
                STDCap: 0,        // 标称容量
                FloatVol: 0,    // 浮充电压
                Strength: 0,    // 除硫强度
                YHStrength: 0,    // 养护强度
                TimeLong: 0    // 除硫天数
            },
            allData: {
                FloatVol_four: 0,
                FloatVol_one: 0,
                FloatVol_three: 0,
                FloatVol_two: 0,
                GroupNum: 0,
                STDCap_four: 0,
                STDCap_one: 0,
                STDCap_three: 0,
                STDCap_two: 0,
                Strength_four: 0,
                Strength_one: 0,
                Strength_three: 0,
                Strength_two: 0,
                TimeLong_four: 0,
                TimeLong_one: 0,
                TimeLong_three: 0,
                TimeLong_two: 0,
                YHStrength_four: 0,
                YHStrength_one: 0,
                YHStrength_three: 0,
                YHStrength_two: 0,
                dev_id: 0,
                num: 0,
                op_cmd: 0,
                test_cmd: 0,
            },
            rules: {},
        }
    },
    methods: {
        init() {
            // 界面参数
            this.params = {
                dev_id: 0,
                GroupNum: 1,        // 电池组号
                STDCap: 0,        // 标称容量
                FloatVol: 0,    // 浮充电压
                Strength: 0,    // 除硫强度
                YHStrength: 0,    // 养护强度
                TimeLong: 0    // 除硫天数
            };
            // 提交数据库的参数
            this.allData = {
                FloatVol_four: 0,
                FloatVol_one: 0,
                FloatVol_three: 0,
                FloatVol_two: 0,
                GroupNum: 0,
                STDCap_four: 0,
                STDCap_one: 0,
                STDCap_three: 0,
                STDCap_two: 0,
                Strength_four: 0,
                Strength_one: 0,
                Strength_three: 0,
                Strength_two: 0,
                TimeLong_four: 0,
                TimeLong_one: 0,
                TimeLong_three: 0,
                TimeLong_two: 0,
                YHStrength_four: 0,
                YHStrength_one: 0,
                YHStrength_three: 0,
                YHStrength_two: 0,
                dev_id: 0,
                num: 0,
                op_cmd: 0,
                test_cmd: 0,
            };
        },
        readFromDB(loading) {    // 从数据库中读取养护除硫参数
            let batt = this.batt;
            this.init();  // 初始化信息
            if(loading) {
                // 开启等待框
                this.loading = this.$layer.loading(1);
        data() {
            let cmd = const_curing.cmd;
            let testType = const_curing.testType;
            let rules = const_curing.dischargeRules;
            return {
                loading: 0,
                cmd: cmd,
                op_cmd: testType[0].value,
                testType: testType,
                startTestFlag: false, // 启动测试的状态
                setTestFlag: false, // 设置参数的状态
                params: {
                    dev_id: 0,
                    GroupNum: 1, // 电池组号
                    STDCap: 0, // 标称容量
                    FloatVol: 0, // 浮充电压
                    Strength: 0, // 除硫强度
                    YHStrength: 0, // 养护强度
                    TimeLong: 0 // 除硫天数
                },
                allData: {
                    FloatVol_five: 0,
                    FloatVol_four: 0,
                    FloatVol_one: 0,
                    FloatVol_three: 0,
                    FloatVol_two: 0,
                    GroupNum: 1,
                    STDCap_five: 0,
                    STDCap_four: 0,
                    STDCap_one: 0,
                    STDCap_three: 0,
                    STDCap_two: 0,
                    Strength_five: 0,
                    Strength_four: 0,
                    Strength_one: 0,
                    Strength_three: 0,
                    Strength_two: 0,
                    TimeLong_five: 0,
                    TimeLong_four: 0,
                    TimeLong_one: 0,
                    TimeLong_three: 0,
                    TimeLong_two: 0,
                    YHStrength_five: 0,
                    YHStrength_four: 0,
                    YHStrength_one: 0,
                    YHStrength_three: 0,
                    YHStrength_two: 0,
                    dev_id: 0,
                    num: 0,
                    op_cmd: 0,
                    test_cmd: 0,
                },
                rules: {
                    FloatVol: [{
                        validator(rule, value, callback) {
                            testVal(rule, value, callback, rules.FloatVol)
                        },
                        trigger: 'change'
                    }],
                    Strength: [{
                        validator(rule, value, callback) {
                            testVal(rule, value, callback, rules.Strength)
                        },
                        trigger: 'change'
                    }],
                    YHStrength: [{
                        validator(rule, value, callback) {
                            testVal(rule, value, callback, rules.YHStrength)
                        },
                        trigger: 'change'
                    }],
                    TimeLong: [{
                        validator(rule, value, callback) {
                            testVal(rule, value, callback, rules.TimeLong)
                        },
                        trigger: 'change'
                    }],
                },
            }
            // 查询后台
            this.$apis.curing.readFromDB(batt.FBSDeviceId).then(res=>{
                let rs = JSON.parse(res.data.result);
                // 查询成功执行
                if(rs.code === 1) {
                    // 从读取设备执行后执行
                    if(!loading) {
                        // this.startTestFlag = true;   // 启动测试的状态
                        this.setTestFlag = true;    // 设置参数的状态
                        // 提示读取参数状态
        },
        methods: {
            init() {
                // 界面参数
                this.params = {
                    dev_id: 0,
                    GroupNum: 1, // 电池组号
                    STDCap: 0, // 标称容量
                    FloatVol: 0, // 浮充电压
                    Strength: 0, // 除硫强度
                    YHStrength: 0, // 养护强度
                    TimeLong: 0 // 除硫天数
                };
                // 提交数据库的参数
                this.allData = {
                    FloatVol_five: 0,
                    FloatVol_four: 0,
                    FloatVol_one: 0,
                    FloatVol_three: 0,
                    FloatVol_two: 0,
                    GroupNum: 1,
                    STDCap_five: 0,
                    STDCap_four: 0,
                    STDCap_one: 0,
                    STDCap_three: 0,
                    STDCap_two: 0,
                    Strength_five: 0,
                    Strength_four: 0,
                    Strength_one: 0,
                    Strength_three: 0,
                    Strength_two: 0,
                    TimeLong_five: 0,
                    TimeLong_four: 0,
                    TimeLong_one: 0,
                    TimeLong_three: 0,
                    TimeLong_two: 0,
                    YHStrength_five: 0,
                    YHStrength_four: 0,
                    YHStrength_one: 0,
                    YHStrength_three: 0,
                    YHStrength_two: 0,
                    dev_id: 0,
                    num: 0,
                    op_cmd: 0,
                    test_cmd: 0,
                };
            },
            changeGroupNum() { // 改变某块编号
                let groupNum = this.getCuringGroupNum(this.params.GroupNum);
                Object.keys(this.allData).forEach(key => {
                    if (key.indexOf(groupNum) != -1) {
                        Object.keys(this.params).forEach(jkey => {
                            if ((jkey + groupNum) == key) {
                                this.params[jkey] = this.allData[key];
                            }
                        });
                    }
                });
            },
            readFromDB(loading) { // 从数据库中读取养护除硫参数
                let batt = this.batt;
                this.init(); // 初始化信息
                if (loading) {
                    // 开启等待框
                    this.loading = this.$layer.loading(1);
                }
                // 查询后台
                this.$apis.curing.readFromDB(batt.FBSDeviceId).then(res => {
                    let rs = JSON.parse(res.data.result);
                    // 查询成功执行
                    if (rs.code === 1) {
                        // 从读取设备执行后执行
                        if (!loading) {
                            // this.startTestFlag = true;   // 启动测试的状态
                            this.setTestFlag = true; // 设置参数的状态
                            // 提示读取参数状态
                            this.$layer.msg(rs.msg);
                        }
                        let data = rs.data[0];
                        this.allData = data;
                        let groupNum = this.getCuringGroupNum(data.GroupNum);
                        Object.keys(this.params).forEach(key => {
                            if (key == 'dev_id') {
                                this.params[key] = data[key];
                            } else if (key == 'GroupNum') {
                                if (loading) {
                                    if (data[key] == 0) {
                                        this.params[key] = data[key] + 1;
                                    } else {
                                        this.params[key] = data[key];
                                    }
                                }
                            } else {
                                this.params[key] = data[key + groupNum];
                            }
                        });
                    } else {
                        this.$layer.msg(rs.msg);
                    }
                    let data = rs.data[0];
                    this.allData = data;
                    let groupNum = this.getCuringGroupNum(data.GroupNum);
                    Object.keys(this.params).forEach(key=>{
                        if(key == 'dev_id') {
                            this.params[key] = data[key];
                        }else if(key == 'GroupNum') {
                            this.params[key] = data[key]+1;
                        }else {
                            this.params[key] = data[key+groupNum];
                        }
                    });
                    console.log(this.params);
                }else {
                    this.$layer.msg(rs.msg);
                }
                // 关闭等待框
                this.$layer.close(this.loading);
            }).catch(error=>{
                // 关闭等待框
                this.$layer.close(this.loading);
            });
        },
        readFromDev() {     // 从设备上获取数据,写入数据库
            let batt = this.batt;
            // 开启等待框
            this.loading = this.$layer.loading(1);
            // 查询后台
            this.$apis.curing.readFromDev(batt.FBSDeviceId).then(res=>{
                let rs = JSON.parse(res.data.result);
                if(rs.code == 1) {
                    this.readFromDB();
                }else {
                    // 关闭等待框
                    this.$layer.close(this.loading);
                    this.$layer.msg(rs.msg);
                }).catch(error => {
                    // 关闭等待框
                    this.$layer.close(this.loading);
                });
            },
            readFromDev() { // 从设备上获取数据,写入数据库
                let batt = this.batt;
                // 开启等待框
                this.loading = this.$layer.loading(1);
                // 查询后台
                this.$apis.curing.readFromDev(batt.FBSDeviceId).then(res => {
                    let rs = JSON.parse(res.data.result);
                    if (rs.code == 1) {
                        this.readFromDB();
                    } else {
                        // 关闭等待框
                        this.$layer.close(this.loading);
                        this.$layer.msg(rs.msg);
                    }
                }).catch(error => {
                    // 关闭等待框
                    this.$layer.close(this.loading);
                });
            },
            getCuringGroupNum(group) {
                let groupNum = null;
                group = Number(group);
                switch (group) {
                    case 0:
                    case 1:
                        groupNum = '_one';
                        break;
                    case 2:
                        groupNum = '_two';
                        break;
                    case 3:
                        groupNum = '_three';
                        break;
                    case 4:
                        groupNum = '_four';
                        break;
                    case 5:
                        groupNum = '_five';
                        break;
                }
            }).catch(error=>{
                // 关闭等待框
                this.$layer.close(this.loading);
            });
        },
        getCuringGroupNum(group) {
            let groupNum = null;
            group = Number(group);
            switch(group) {
                case 0:
                case 1:
                    groupNum = '_one';
                    break;
                case 2:
                    groupNum = '_two';
                    break;
                case 3:
                    groupNum = '_three';
                    break;
                case 4:
                    groupNum = '_four';
                    break;
                return groupNum;
            },
            submitFrom() {
                this.$refs.ruleForm.validate((valid) => {
                    // 校验通过
                    if (valid) {
                        // 设置参数
                        this.setParams();
                    } else {
                        this.$layer.msg('存在校验未通过的数据!');
                        return false;
                    }
                });
            },
            setParams() {
                let params = this.getSetParams();
                // 开启等待框
                this.loading = this.$layer.loading(1);
                this.$apis.curing.setParams(params).then((res) => {
                    let rs = JSON.parse(res.data.result);
                    if (rs.code == 1) {
                        // 关闭等待框
                        this.$layer.close(this.loading);
                        this.$layer.msg(rs.msg);
                    } else {
                        // 关闭等待框
                        this.$layer.close(this.loading);
                        this.$layer.msg(rs.msg);
                    }
                }).catch((err) => {
                    // 关闭等待框
                    this.$layer.close(this.loading);
                    this.$layer.msg('设置失败!');
                })
            },
            getSetParams() {
                let params = this.params;
                let groupNum = this.getCuringGroupNum(params.GroupNum);
                for (let key in params) {
                    if (key !== "dev_id" && key !== "GroupNum") {
                        let realKey = key + groupNum;
                        this.allData[realKey] = Number(params[key]);
                    }
                }
                this.allData.BattGroupNum = this.batt.GroupIndexInFBSDevice;
                this.allData.GroupNum = this.params.GroupNum;
                return this.allData;
            }
            return groupNum;
        },
        submitFrom() {
            this.$refs.ruleForm.validate((valid) => {
                // 校验通过
                if (valid) {
                    // 设置参数
                    this.setParams();
                } else {
                    this.$layer.msg('存在校验未通过的数据!');
                    return false;
                }
            });
        },
        setParams() {
            let params = this.getSetParams();
            console.log(params);
        },
        getSetParams() {
            let params = this.params;
            let groupNum = this.getCuringGroupNum(params.GroupNum);
            for(let key in params) {
                //console.log(key);
                if(key !=="dev_id" && key !== "GroupNum") {
                    let realKey = key + groupNum;
                    this.allData[realKey] = params[key];
        computed: {
            otherParams() {
                let batt = this.batt;
                let groupInfo = '单体数量:' + this.batt.MonCount + ";电压(V):" +
                    this.batt.MonVolStd + ";容量(AH):" + this.batt.MonCapStd;
                return {
                    groupName: batt.StationName + "-" + batt.BattGroupName,
                    FBSDeviceId: batt.FBSDeviceId,
                    groupInfo: groupInfo,
                    GroupIndexInFBSDevice: this.batt.GroupIndexInFBSDevice + 1,
                }
            }
            return this.allData;
        },
        mounted() {
            // 从数据库中读取数据
            this.readFromDB(true);
        }
    },
    computed: {
        otherParams() {
            let batt = this.batt;
            let groupInfo = '单体数量:'+this.batt.MonCount+";电压(V):"
                +this.batt.MonVolStd+";容量(AH):"+this.batt.MonCapStd;
            return {
                groupName: batt.StationName+"-"+batt.BattGroupName,
                FBSDeviceId: batt.FBSDeviceId,
                groupInfo: groupInfo,
                GroupIndexInFBSDevice: this.batt.GroupIndexInFBSDevice+1,
            }
        }
    },
    mounted() {
        // 从数据库中读取数据
        this.readFromDB(true);
    }
}
</script>
<style scoped>
.params-container {
    padding: 8px;
    background-color: #ececec;
}
.form-footer {
    margin-top: 16px;
    margin-bottom: 16px;
    text-align: right;
}
.form-footer .three-btn {
    margin-left: 12px;
}
    .params-container {
        padding: 8px;
        background-color: #ececec;
    }
    .form-footer {
        margin-top: 16px;
        margin-bottom: 16px;
        text-align: right;
    }
    .form-footer .three-btn {
        margin-left: 12px;
    }
</style>