diff --git a/src/views/ChangePassword.vue b/src/views/ChangePassword.vue
index 054856c..3401540 100644
--- a/src/views/ChangePassword.vue
+++ b/src/views/ChangePassword.vue
@@ -18,7 +18,7 @@
确认修改
- 返回登录
+ 返回登录
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 5a44813..ed2241a 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -129,77 +129,42 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 车道1
- 车道2
- 车道3
- 车道4
-
-
-
-
-
-
- 周一
- 周二
- 周三
- 周四
- 周五
- 周六
- 周日
-
-
-
-
-
- 保存方案
- 重置
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
{{ lane }},
-
+
+
+
+ {{ ['周一', '周二', '周三', '周四', '周五', '周六', '周日'][day] }}
+ ,
+
+
+
+
+
+ handleStatusChange(val, scope.row)"
+ >
+
+
+
编辑
删除
@@ -207,21 +172,33 @@
-
-
-
+
+
+
-
+
+
+
+
+
+
+
+
+
-
-
- 至
-
-
+
+
-
+
车道1
车道2
车道3
@@ -229,13 +206,25 @@
+
+
+ 周一
+ 周二
+ 周三
+ 周四
+ 周五
+ 周六
+ 周日
+
+
-
+
+
+
-
@@ -288,7 +277,33 @@ export default {
repeatDays: [], // 添加重复日期数组
},
plans: [
-
+ // {
+ // id: 1,
+ // name: '早高峰方案',
+ // timeRange: '07:30 - 09:30',
+ // selectedMode: '0', // 左转直行
+ // lanes: ['车道1', '车道2'],
+ // repeatDays: [0, 1, 2, 3, 4], // 周一到周五
+ // enabled: true
+ // },
+ // {
+ // id: 2,
+ // name: '晚高峰方案',
+ // timeRange: '17:00 - 19:00',
+ // selectedMode: '1', // 右转直行
+ // lanes: ['车道2', '车道3', '车道4'],
+ // repeatDays: [0, 1, 2, 3, 4],
+ // enabled: false
+ // },
+ // {
+ // id: 3,
+ // name: '周末方案',
+ // timeRange: '09:00 - 18:00',
+ // selectedMode: '0',
+ // lanes: ['车道1', '车道2', '车道3'],
+ // repeatDays: [5, 6], // 周六周日
+ // enabled: true
+ // }
],
editDialogVisible: false,
editPlanData: {},
@@ -315,6 +330,10 @@ export default {
lane3: [],
lane4: []
},
+ planDialogVisible: false,
+ dialogTitle: '新增方案',
+ isEdit: false,
+ currentEditId: null,
};
},
methods: {
@@ -322,13 +341,13 @@ export default {
resetNewPlan() {
this.newPlan = {
name: '',
- startTime: '',
- endTime: '',
- lanes: [],
- timeRange: [],
selectedMode: '',
- repeatDays: [], // 重置重复日期
+ timeRange: [],
+ lanes: [],
+ repeatDays: []
};
+ this.isEdit = false;
+ this.currentEditId = null;
},
// 模式设置
async applySettings() {
@@ -407,37 +426,22 @@ export default {
return;
}
- const [startTime, endTime] = this.newPlan.timeRange || [null, null];
- if (!startTime || !endTime) {
- ElMessage({
- message: '请选择时间范围',
- type: 'error'
- });
- return;
- }
-
- if (!this.newPlan.lanes || this.newPlan.lanes.length === 0) {
- ElMessage({
- message: '请选择至少一个车道',
- type: 'error'
- });
- return;
- }
-
- if (!this.newPlan.repeatDays || this.newPlan.repeatDays.length === 0) {
- ElMessage({
- message: '请选择重复日期',
- type: 'error'
- });
- return;
- }
-
const formatTime = (date) => {
+ if (typeof date === 'string') return date;
return date.toTimeString().slice(0, 5);
};
- const lanes = this.newPlan.lanes.map(lane => {
- return lane.replace('车道', '') - 1;
+ // 处理时间范围
+ let startTime, endTime;
+ if (Array.isArray(this.newPlan.timeRange)) {
+ [startTime, endTime] = this.newPlan.timeRange;
+ } else if (typeof this.newPlan.timeRange === 'string') {
+ [startTime, endTime] = this.newPlan.timeRange.split(' - ');
+ }
+
+ // 处理车道
+ const lanes = (this.newPlan.lanes || []).map(lane => {
+ return String(lane.replace('车道', '') - 1);
});
const planData = {
@@ -445,15 +449,15 @@ export default {
command: "set_scheme",
parameters: {
scheme: [{
- id: this.plans.length + 1,
+ id: this.isEdit ? this.currentEditId : (this.plans.length + 1),
name: this.newPlan.name,
- selectedMode: String(this.modeMap[this.newPlan.selectedMode]),
+ selectedMode: this.newPlan.selectedMode,
timeRange: {
start: formatTime(startTime),
end: formatTime(endTime)
},
- lanes: lanes.map(String),
- repeatDays: this.newPlan.repeatDays // 添加重复日期
+ lanes: lanes,
+ repeatDays: this.newPlan.repeatDays.map(day => Number(day))
}]
}
};
@@ -469,7 +473,26 @@ export default {
console.log('收到方案添加响应:', JSON.stringify(response.data, null, 2));
if (response.data?.parameters?.status === 0) {
- this.plans.push({ ...this.newPlan });
+ const newPlanData = {
+ id: planData.parameters.scheme[0].id,
+ name: this.newPlan.name,
+ timeRange: `${formatTime(startTime)} - ${formatTime(endTime)}`,
+ selectedMode: this.newPlan.selectedMode,
+ lanes: this.newPlan.lanes,
+ repeatDays: this.newPlan.repeatDays.map(day => Number(day)),
+ enabled: true
+ };
+
+ if (this.isEdit) {
+ const index = this.plans.findIndex(p => p.id === this.currentEditId);
+ if (index !== -1) {
+ this.plans.splice(index, 1, newPlanData);
+ }
+ } else {
+ this.plans.push(newPlanData);
+ }
+
+ this.planDialogVisible = false;
this.resetNewPlan();
ElMessage({
message: response.data?.parameters?.message || '方案添加成功',
@@ -545,7 +568,8 @@ export default {
name: scheme.name,
timeRange: `${scheme.timeRange.start} - ${scheme.timeRange.end}`,
selectedMode: scheme.selectedMode,
- lanes: scheme.lanes.map(lane => `车道${parseInt(lane) + 1}`)
+ lanes: scheme.lanes.map(lane => `车道${parseInt(lane) + 1}`),
+ repeatDays: scheme.repeatDays || [] // 添加重复日期
}));
}
@@ -659,29 +683,24 @@ export default {
try {
const deleteData = {
JSON_id: getNextJsonId(),
- command: "set_scheme",
+ command: "delete_scheme",
parameters: {
- scheme: [{
- id: plan.id,
- name: plan.name,
- selectedMode: "0", // 特殊值表示删除
- timeRange: {
- start: "00:00",
- end: "00:00"
- },
- lanes: []
- }]
+ id: plan.id
}
};
+ console.log('发送删除方案请求:', JSON.stringify(deleteData, null, 2));
+
const response = await axios.post('/communication', deleteData, {
headers: {
"content-type": "application/json"
}
});
+ console.log('收到删除方案响应:', JSON.stringify(response.data, null, 2));
+
if (response.data?.parameters?.status === 0) {
- this.plans = this.plans.filter(p => p !== plan);
+ this.plans = this.plans.filter(p => p.id !== plan.id);
ElMessage({
message: response.data?.parameters?.message || '方案删除成功',
type: 'success'
@@ -699,46 +718,106 @@ export default {
type: 'error'
});
}
+ this.getAllInfo();
},
// 编辑方案
editPlan(plan) {
- this.editPlanData = { ...plan };
- this.editDialogVisible = true;
+ this.isEdit = true;
+ this.dialogTitle = '编辑方案';
+ this.currentEditId = plan.id;
+
+ // 处理时间范围
+ let [startTime, endTime] = plan.timeRange.split(' - ');
+
+ // 创建今天的日期对象,并设置时间
+ const today = new Date();
+ const [startHour, startMinute] = startTime.split(':');
+ const [endHour, endMinute] = endTime.split(':');
+
+ const startDate = new Date(today);
+ startDate.setHours(parseInt(startHour), parseInt(startMinute), 0);
+
+ const endDate = new Date(today);
+ endDate.setHours(parseInt(endHour), parseInt(endMinute), 0);
+
+ this.newPlan = {
+ name: plan.name,
+ selectedMode: plan.selectedMode,
+ timeRange: [startDate, endDate], // 使用 Date 对象
+ lanes: [...(plan.lanes || [])],
+ repeatDays: [...(plan.repeatDays || [])].map(String)
+ };
+
+ this.planDialogVisible = true;
},
// 保存编辑的方案
async saveEditPlan() {
try {
+ const formatTime = (date) => {
+ if (typeof date === 'string') return date;
+ return date.toTimeString().slice(0, 5);
+ };
+
+ // 处理时间范围
+ let startTime, endTime;
+ if (Array.isArray(this.newPlan.timeRange)) {
+ [startTime, endTime] = this.newPlan.timeRange;
+ }
+
+ // 处理车道
+ const lanes = (this.newPlan.lanes || []).map(lane => {
+ return String(lane.replace('车道', '') - 1);
+ });
+
const editedPlan = {
JSON_id: getNextJsonId(),
command: "set_scheme",
parameters: {
scheme: [{
- id: this.editPlanData.id,
- name: this.editPlanData.name,
- selectedMode: String(this.editPlanData.selectedMode),
+ id: this.currentEditId,
+ name: this.newPlan.name,
+ selectedMode: this.newPlan.selectedMode,
timeRange: {
- start: this.editPlanData.startTime,
- end: this.editPlanData.endTime
+ start: formatTime(startTime),
+ end: formatTime(endTime)
},
- lanes: this.editPlanData.lanes.map(lane => lane.replace('车道', '') - 1).map(String)
+ lanes: lanes,
+ repeatDays: this.newPlan.repeatDays.map(day => Number(day))
}]
}
};
+ console.log('发送方案编辑请求:', JSON.stringify(editedPlan, null, 2));
+
const response = await axios.post('/communication', editedPlan, {
headers: {
"content-type": "application/json"
}
});
+ console.log('收到方案编辑响应:', JSON.stringify(response.data, null, 2));
+
if (response.data?.parameters?.status === 0) {
- const index = this.plans.findIndex(p => p.id === this.editPlanData.id);
+ const newPlanData = {
+ id: this.currentEditId,
+ name: this.newPlan.name,
+ timeRange: `${formatTime(startTime)} - ${formatTime(endTime)}`,
+ selectedMode: this.newPlan.selectedMode,
+ lanes: this.newPlan.lanes,
+ repeatDays: this.newPlan.repeatDays.map(day => Number(day)),
+ enabled: true
+ };
+
+ const index = this.plans.findIndex(p => p.id === this.currentEditId);
if (index !== -1) {
- this.plans.splice(index, 1, { ...this.editPlanData });
+ this.plans.splice(index, 1, newPlanData);
}
- this.editDialogVisible = false;
+
+ this.planDialogVisible = false;
+ this.resetNewPlan();
+
ElMessage({
message: response.data?.parameters?.message || '方案编辑成功',
type: 'success'
@@ -798,7 +877,48 @@ export default {
type: 'error'
});
}
- }
+ },
+ // 显示新增方案弹窗
+ showAddPlanDialog() {
+ this.isEdit = false;
+ this.dialogTitle = '新增方案';
+ this.resetNewPlan();
+ this.planDialogVisible = true;
+ },
+
+ // 处理方案提交
+ handlePlanSubmit() {
+ if (this.isEdit) {
+ this.saveEditPlan();
+ } else {
+ this.addPlan();
+ }
+ },
+
+ // 处理状态改变
+ async handleStatusChange(val, row) {
+ try {
+ const statusData = {
+ JSON_id: getNextJsonId(),
+ command: "set_scheme_status",
+ parameters: {
+ id: row.id,
+ enabled: val
+ }
+ };
+ console.log('发送状态更新请求:', JSON.stringify(statusData, null, 2));
+ const response = await axios.post('/communication', statusData);
+ if (response.data?.parameters?.status === 0) {
+ ElMessage.success('状态更新成功');
+ } else {
+ row.enabled = !val; // 恢复原状态
+ ElMessage.error('状态更新失败');
+ }
+ } catch (error) {
+ row.enabled = !val; // 恢复原状态
+ ElMessage.error('状态更新失败');
+ }
+ },
},
mounted() {
// 组件挂载时获取设备信息和所有信息
@@ -913,4 +1033,36 @@ export default {
margin-bottom: 10px;
color: #303133;
}
+
+.plan-list-header {
+ margin-bottom: 20px;
+}
+
+.dialog-footer {
+ text-align: right;
+ margin-top: 20px;
+}
+
+/* 添加表格相关样式 */
+.el-table {
+ margin: 0 auto;
+ background-color: #ffffff;
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
+}
+
+.el-table th {
+ background-color: #f5f7fa !important;
+ color: #606266;
+ font-weight: bold;
+ font-size: 14px;
+}
+
+.el-table td {
+ padding: 8px 0;
+}
+
+/* 调整按钮间距 */
+.el-button + .el-button {
+ margin-left: 8px;
+}
diff --git a/可变车道JSON协议.json b/可变车道JSON协议.json
index 9a0ed8f..4e4825f 100644
--- a/可变车道JSON协议.json
+++ b/可变车道JSON协议.json
@@ -131,6 +131,8 @@
"compileTime": "2025-01-14T10:30:00Z"
}
}
+
+
获取所有信息
(Web → 单片机)
@@ -156,14 +158,15 @@
"lanes": [
"0",
"1"
- ]
+ ],
+ "repeatDays": [0, 1, 2, 3, 4, 5, 6] // 表示周一到周日每天都重复执行该方案
}
],
"laneSetting": {
- "lane1": ["0"], //0左转直行 1右转直行
- "lane2": ["1"],
- "lane3": ["0"],
- "lane4": ["1"]
+ "lane1": "0", //0左转直行 1右转直行
+ "lane2": "1",
+ "lane3": "0",
+ "lane4": "1"
},
"deviceInfo": {
@@ -175,13 +178,14 @@
}
默认车道设置
(Web → 单片机)
+
{
"command": "default_lane_setting",
"parameters": {
- "lane1": ["0"], //0左转直行 1右转直行
- "lane2": ["1"],
- "lane3": ["2"],
- "lane4": ["3"]
+ "lane1": "0", //0左转直行 1右转直行
+ "lane2": "1",
+ "lane3": "2",
+ "lane4": "3"
}
}
@@ -193,4 +197,42 @@
"message": "Set successfully"
}
}
-
\ No newline at end of file
+
+使能部分
+(Web → 单片机)
+{
+ "JSON_id": 30,
+ "command": "set_scheme_status",
+ "parameters": {
+ "id": 1,
+ "enabled": false
+ }
+ }
+
+(单片机 → Web)
+{
+ "command": "set_scheme_status_response",
+ "parameters": {
+ "status": 0, // 0: 成功, 1: 失败
+ "message": "Set successfully"
+ }
+}
+
+删除方案
+(Web → 单片机)
+{
+ "command": "delete_scheme",
+ "parameters": {
+ "id": 1
+ }
+}
+
+(单片机 → Web)
+{
+ "command": "delete_scheme_response",
+ "parameters": {
+ "status": 0, // 0: 成功, 1: 失败
+ "message": "Delete successfully"
+ }
+}
+