1
This commit is contained in:
@@ -2,17 +2,43 @@
|
|||||||
* 设备选择模块 - 用于统计页面的设备切换
|
* 设备选择模块 - 用于统计页面的设备切换
|
||||||
* 这个模块会被持久化到 localStorage
|
* 这个模块会被持久化到 localStorage
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// localStorage 的 key
|
||||||
|
const STORAGE_KEY = 'device_selected_sn'
|
||||||
|
|
||||||
|
// 从 localStorage 读取上次选中的设备
|
||||||
|
const loadSelectedDevice = () => {
|
||||||
|
try {
|
||||||
|
const saved = localStorage.getItem(STORAGE_KEY)
|
||||||
|
return saved || ''
|
||||||
|
} catch (error) {
|
||||||
|
console.error('读取选中设备失败:', error)
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存选中的设备到 localStorage
|
||||||
|
const saveSelectedDevice = (deviceSn) => {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(STORAGE_KEY, deviceSn)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存选中设备失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const deviceModule = {
|
const deviceModule = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
|
|
||||||
state: {
|
state: {
|
||||||
selectedDeviceSn: '', // 当前选中的设备 SN
|
selectedDeviceSn: loadSelectedDevice(), // 从 localStorage 恢复上次选中的设备
|
||||||
deviceList: [], // 设备列表
|
deviceList: [], // 设备列表
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_SELECTED_DEVICE(state, deviceSn) {
|
SET_SELECTED_DEVICE(state, deviceSn) {
|
||||||
state.selectedDeviceSn = deviceSn
|
state.selectedDeviceSn = deviceSn
|
||||||
|
// 持久化到 localStorage
|
||||||
|
saveSelectedDevice(deviceSn)
|
||||||
},
|
},
|
||||||
|
|
||||||
SET_DEVICE_LIST(state, list) {
|
SET_DEVICE_LIST(state, list) {
|
||||||
@@ -20,6 +46,7 @@ const deviceModule = {
|
|||||||
// 如果没有选中的设备,且列表不为空,自动选中第一个
|
// 如果没有选中的设备,且列表不为空,自动选中第一个
|
||||||
if (!state.selectedDeviceSn && list.length > 0) {
|
if (!state.selectedDeviceSn && list.length > 0) {
|
||||||
state.selectedDeviceSn = list[0].deviceSn
|
state.selectedDeviceSn = list[0].deviceSn
|
||||||
|
saveSelectedDevice(state.selectedDeviceSn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ export default {
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedDeviceSn: '',
|
selectedDeviceSn: this.$store.state.device?.selectedDeviceSn || '', // 从 store 恢复上次选中的设备
|
||||||
deviceList: [],
|
deviceList: [],
|
||||||
todayStats: {
|
todayStats: {
|
||||||
applyCount: 0,
|
applyCount: 0,
|
||||||
@@ -326,11 +326,19 @@ export default {
|
|||||||
|
|
||||||
this.$store.dispatch('device/setDeviceList', this.deviceList)
|
this.$store.dispatch('device/setDeviceList', this.deviceList)
|
||||||
|
|
||||||
// 如果没有选中设备且有设备列表,选中第一个
|
// 优先从 store 恢复上次选中的设备
|
||||||
if (!this.selectedDeviceSn && this.deviceList.length > 0) {
|
const savedDeviceSn = this.$store.state.device?.selectedDeviceSn
|
||||||
|
|
||||||
|
if (savedDeviceSn && this.deviceList.some(d => d.deviceSn === savedDeviceSn)) {
|
||||||
|
// 如果 store 中保存的设备在列表中存在,恢复选中
|
||||||
|
console.log('恢复上次选中的设备:', savedDeviceSn)
|
||||||
|
this.selectedDeviceSn = savedDeviceSn
|
||||||
|
this.loadData()
|
||||||
|
} else if (!this.selectedDeviceSn && this.deviceList.length > 0) {
|
||||||
|
// 如果没有保存的设备或保存的设备不在列表中,选中第一个
|
||||||
|
console.log('选中第一个设备:', this.deviceList[0].deviceSn)
|
||||||
this.selectedDeviceSn = this.deviceList[0].deviceSn
|
this.selectedDeviceSn = this.deviceList[0].deviceSn
|
||||||
this.$store.dispatch('device/setSelectedDevice', this.selectedDeviceSn)
|
this.$store.dispatch('device/setSelectedDevice', this.selectedDeviceSn)
|
||||||
// 立即加载数据
|
|
||||||
this.loadData()
|
this.loadData()
|
||||||
} else if (this.selectedDeviceSn) {
|
} else if (this.selectedDeviceSn) {
|
||||||
// 如果已有选中设备,直接加载数据
|
// 如果已有选中设备,直接加载数据
|
||||||
@@ -740,21 +748,23 @@ export default {
|
|||||||
const deviceRes = await DeviceStatusServer.getById(this.selectedDeviceSn)
|
const deviceRes = await DeviceStatusServer.getById(this.selectedDeviceSn)
|
||||||
console.log('设备状态接口返回:', deviceRes)
|
console.log('设备状态接口返回:', deviceRes)
|
||||||
if (deviceRes.code === 0 && deviceRes.data) {
|
if (deviceRes.code === 0 && deviceRes.data) {
|
||||||
accountData.is_online = deviceRes.data.isOnline || false
|
accountData.is_online = deviceRes.data.isOnline ? 1 : 0
|
||||||
accountData.is_logged_in = deviceRes.data.isLoggedIn || false
|
accountData.is_logged_in = deviceRes.data.isLoggedIn ? 1 : 0
|
||||||
} else {
|
} else {
|
||||||
accountData.is_online = false
|
accountData.is_online = 0
|
||||||
accountData.is_logged_in = false
|
accountData.is_logged_in = 0
|
||||||
}
|
}
|
||||||
} catch (deviceError) {
|
} catch (deviceError) {
|
||||||
console.error('获取设备状态失败:', deviceError)
|
console.error('获取设备状态失败:', deviceError)
|
||||||
accountData.is_online = false
|
accountData.is_online = 0
|
||||||
accountData.is_logged_in = false
|
accountData.is_logged_in = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保布尔值字段正确初始化,转换为数字类型(0 或 1)
|
// 确保布尔值字段正确初始化,转换为数字类型(0 或 1)
|
||||||
accountData.is_enabled = accountData.is_enabled !== undefined ? Number(accountData.is_enabled) : 1
|
accountData.is_enabled = accountData.is_enabled !== undefined ? Number(accountData.is_enabled) : 1
|
||||||
|
accountData.is_online = accountData.is_online !== undefined ? Number(accountData.is_online) : 0
|
||||||
|
accountData.is_logged_in = accountData.is_logged_in !== undefined ? Number(accountData.is_logged_in) : 0
|
||||||
accountData.auto_deliver = accountData.auto_deliver !== undefined ? Number(accountData.auto_deliver) : 0
|
accountData.auto_deliver = accountData.auto_deliver !== undefined ? Number(accountData.auto_deliver) : 0
|
||||||
accountData.auto_chat = accountData.auto_chat !== undefined ? Number(accountData.auto_chat) : 0
|
accountData.auto_chat = accountData.auto_chat !== undefined ? Number(accountData.auto_chat) : 0
|
||||||
accountData.auto_active = accountData.auto_active !== undefined ? Number(accountData.auto_active) : 0
|
accountData.auto_active = accountData.auto_active !== undefined ? Number(accountData.auto_active) : 0
|
||||||
|
|||||||
@@ -244,16 +244,26 @@ class DeviceWorkStatusNotifier {
|
|||||||
activity.status === 'completed' ? '已完成' :
|
activity.status === 'completed' ? '已完成' :
|
||||||
activity.status === 'failed' ? '失败' : '未知';
|
activity.status === 'failed' ? '失败' : '未知';
|
||||||
|
|
||||||
// 构建详细描述:包含指令/任务名称和描述
|
// 使用 description 或 name,避免重复显示
|
||||||
let activityDesc = activity.description || activity.name;
|
// 如果 description 存在且不等于 name,优先使用 description
|
||||||
|
// 否则,使用 name 并可能添加 commandType
|
||||||
|
let activityDesc = '';
|
||||||
|
|
||||||
// 对于指令,显示指令类型和名称的详细信息
|
if (activity.description && activity.description !== activity.name) {
|
||||||
|
// 有独立的 description,直接使用,不再添加 commandType
|
||||||
|
activityDesc = activity.description;
|
||||||
|
} else {
|
||||||
|
// 使用 name
|
||||||
|
activityDesc = activity.name;
|
||||||
|
|
||||||
|
// 对于指令,如果 commandType 存在且与 name 不同,添加详细信息
|
||||||
if (activity.type === 'command') {
|
if (activity.type === 'command') {
|
||||||
const cmdType = activity.commandType || '';
|
const cmdType = activity.commandType || '';
|
||||||
if (cmdType && cmdType !== activity.name) {
|
if (cmdType && cmdType !== activity.name && !activity.name.includes(cmdType)) {
|
||||||
activityDesc = `${activityDesc} [${cmdType}]`;
|
activityDesc = `${activityDesc} [${cmdType}]`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parts.push(`${typeText}: ${activityDesc} (${statusText}${activity.progress > 0 ? `, 进度: ${activity.progress}%` : ''})`);
|
parts.push(`${typeText}: ${activityDesc} (${statusText}${activity.progress > 0 ? `, 进度: ${activity.progress}%` : ''})`);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ function checkTimeRange(timeRange) {
|
|||||||
const startTime = startHour * 60 + startMinute;
|
const startTime = startHour * 60 + startMinute;
|
||||||
const endTime = endHour * 60 + endMinute;
|
const endTime = endHour * 60 + endMinute;
|
||||||
|
|
||||||
// 检查是否仅工作日
|
// 检查是否仅工作日(使用宽松比较,兼容字符串和数字)
|
||||||
if (timeRange.workdays_only === 1) {
|
if (timeRange.workdays_only == 1) { // 使用 == 而不是 ===
|
||||||
const dayOfWeek = now.getDay(); // 0=周日, 1=周一, ..., 6=周六
|
const dayOfWeek = now.getDay(); // 0=周日, 1=周一, ..., 6=周六
|
||||||
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
||||||
return { allowed: false, reason: '当前是周末,不在允许的时间范围内' };
|
return { allowed: false, reason: '当前是周末,不在允许的时间范围内' };
|
||||||
|
|||||||
@@ -523,8 +523,8 @@ class TaskHandlers {
|
|||||||
const startTime = startHour * 60 + startMinute;
|
const startTime = startHour * 60 + startMinute;
|
||||||
const endTime = endHour * 60 + endMinute;
|
const endTime = endHour * 60 + endMinute;
|
||||||
|
|
||||||
// 检查是否仅工作日
|
// 检查是否仅工作日(使用宽松比较,兼容字符串和数字)
|
||||||
if (timeRange.workdays_only === 1) {
|
if (timeRange.workdays_only == 1) { // 使用 == 而不是 ===
|
||||||
const dayOfWeek = now.getDay(); // 0=周日, 1=周一, ..., 6=周六
|
const dayOfWeek = now.getDay(); // 0=周日, 1=周一, ..., 6=周六
|
||||||
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
||||||
return { allowed: false, reason: '当前是周末,不在允许的时间范围内' };
|
return { allowed: false, reason: '当前是周末,不在允许的时间范围内' };
|
||||||
|
|||||||
Reference in New Issue
Block a user