he wei
2025-01-13 8ffb54b88e3907ea59c120d34a8cd9f486cc1151
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<script setup>
import { ref, computed, nextTick } from "vue";
import {
  controllTestModel,
  controllLLCBuckCurr,
  controllLLCBuckVol,
  controllVBusVref,
  controllPowerOpen,
  controllPowerClose,
} from "@/api/params";
import useElement from "@/hooks/useElement.js";
const { $alert, $loading, $message, $confirm } = useElement();
 
const emit = defineEmits(["setOk"]);
 
const props = defineProps({
  info: {
    type: Object,
    // default: () => {
    //   return {};
    // },
    required: true,
  },
});
const title = ref("设置测试模式");
const paramsVisible = ref(false);
const inputValue = ref();
const currentIdx = ref(0);
const input = ref();
 
const testModelab = computed(() => {
  const obj = {
    3: "逆变并网",
    6: "PFC工作",
  };
  const lab = props.info.state?.testModelab || 0;
  return obj[lab] || `未知 (${lab})`;
});
 
function edit(idx) {
  currentIdx.value = idx;
  switch (idx) {
    case 0:
      title.value = "设置测试模式";
      inputValue.value = props.info.state.testModelab;
      break;
    case 1:
      title.value = "设置VBus电压";
      inputValue.value = props.info.state.vbusVerfVolSet;
      break;
    case 2:
      title.value = "设置LLC Buck电压";
      inputValue.value = props.info.state.llcBuckVolSet;
      break;
    case 3:
      title.value = "设置LLC Buck电流";
      inputValue.value = props.info.state.llcBuckCurrSet;
      break;
    default:
      break;
  }
  paramsVisible.value = true;
 
  if (idx) {
    setTimeout(() => {
      input.value.select();
    }, 0);
  }
}
function setParams() {
  let setFn;
  if (currentIdx.value !== 0 &&inputValue.value.trim() === '') {
    $message.error("请输入参数");
    return;
  }
  switch (currentIdx.value) {
    case 0:
      setFn = controllTestModel;
      break;
    case 1:
      setFn = controllVBusVref;
      break;
    case 2:
      setFn = controllLLCBuckVol;
      break;
    case 3:
      setFn = controllLLCBuckCurr;
      break;
    default:
      break;
  }
 
  let loading = $loading();
  setFn(props.info.powerId, inputValue.value)
    .then((res) => {
      let { code, data } = res.data;
      loading.close();
      if (code && data) {
        console.log(data);
        $message.success("设置成功");
        emit("setOk");
        paramsVisible.value = false;
      } else {
        $message.error("设置失败");
      }
    })
    .catch((err) => {
      $message.error("设置失败");
      loading.close();
      console.log(err);
    });
}
</script>
 
<template>
  <div class="params">
    <div class="item">
      <div class="label">测试模式</div>
      <div class="value">{{ testModelab }}</div>
      <el-button size="small" type="primary" @click="edit(0)">修改</el-button>
    </div>
    <!-- <div class="item">
      <div class="label">并网输出电流</div>
      <div class="value">{{ info.state.gridIrefCurrSet }}</div>
      <el-button size="small" type="primary" @click="edit">修改</el-button>
    </div> -->
    <!-- <div class="item">
      <div class="label">VBus电压</div>
      <div class="value">{{ info.state.vbusVerfVolSet }}</div>
      <el-button size="small" type="primary" @click="edit(1)">修改</el-button>
    </div> -->
    <div class="item">
      <div class="label">LLC Buck电压</div>
      <div class="value">{{ info.state.llcBuckVolSet }}</div>
      <el-button size="small" type="primary" @click="edit(2)">修改</el-button>
    </div>
    <div class="item">
      <div class="label">LLC Buck电流</div>
      <div class="value">{{ info.state.llcBuckCurrSet }}</div>
      <el-button size="small" type="primary" @click="edit(3)">修改</el-button>
    </div>
  </div>
  <!-- 弹窗 -->
  <el-dialog
    :title="title"
    v-model="paramsVisible"
    :close-on-click-modal="false"
    class="dialog-center"
    width="280px"
    center
  >
    <el-select
      v-model="inputValue"
      v-if="currentIdx === 0"
      placeholder="Select"
      size="small"
    >
      <el-option :value="3" label="逆变并网"></el-option>
      <el-option :value="6" label="PFC工作"></el-option>
    </el-select>
    <el-input
      v-else
      ref="input"
      v-model="inputValue"
      placeholder="Please input"
    />
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="paramsVisible = false">取消</el-button>
        <el-button type="primary" @click="setParams">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
 
<style scoped lang="scss">
.params {
  display: flex;
  flex-direction: column;
  .item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    .label {
      flex: 1;
      margin-right: 10px;
      text-align: right;
      &::after {
        content: ":";
      }
    }
    .value {
      width: 8em;
      margin-right: 10px;
    }
  }
}
</style>