This commit is contained in:
张成
2025-11-28 09:50:40 +08:00
8 changed files with 127 additions and 69 deletions

View File

@@ -26,11 +26,11 @@ const baseConfig = {
// 开发环境配置
const developmentConfig = {
...baseConfig,
apiUrl: 'http://localhost:9097/admin_api/',
uploadUrl: 'http://localhost:9097/admin_api/upload',
// apiUrl: 'http://localhost:9097/admin_api/',
// uploadUrl: 'http://localhost:9097/admin_api/upload',
// apiUrl: 'http://work.light120.com/admin_api/',
// uploadUrl: 'http://work.light120.com/admin_api/upload',
apiUrl: 'http://work.light120.com/admin_api/',
uploadUrl: 'http://work.light120.com/admin_api/upload',
// 开发环境显示更多调试信息
debug: true
}

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Framework Demo</title>
<title>Admin Framework</title>
</head>
<body>
<div id="app"></div>

View File

@@ -25,6 +25,15 @@ class PlaAccountServer {
return window.framework.http.post('/account/detail', { id })
}
/**
* 通过设备SN码获取账号信息
* @param {String} sn_code - 设备SN码
* @returns {Promise}
*/
getBySnCode(sn_code) {
return window.framework.http.post('/account/getBySnCode', { sn_code })
}
/**
* 新增账号
* @param {Object} row - 账号数据

View File

@@ -19,8 +19,8 @@
<FormItem label="平台">
<Select v-model="gridOption.param.seachOption.platform_type" style="width: 120px" clearable
@on-change="query(1)">
<Option value="1">Boss直聘</Option>
<Option value="2">猎聘</Option>
<Option value="boss">Boss直聘</Option>
<Option value="liepin">猎聘</Option>
</Select>
</FormItem>
<FormItem label="在线状态">
@@ -276,8 +276,8 @@ export default {
{ title: '设备SN码', key: 'sn_code', type: 'text', required: true },
{
title: '平台', key: 'platform_type', com: 'Select', required: true, source: [
{ key: '1', value: 'Boss直聘' },
{ key: '2', value: '猎聘' }
{ key: 'boss', value: 'Boss直聘' },
{ key: 'liepin', value: '猎聘' }
]
},
{ title: '登录名', key: 'login_name', com: 'Input', required: true },
@@ -293,8 +293,8 @@ export default {
minWidth: 100,
render: (h, params) => {
const platformMap = {
'1': { text: 'Boss直聘', color: 'blue' },
'2': { text: '猎聘', color: 'green' }
'boss': { text: 'Boss直聘', color: 'blue' },
'liepin': { text: '猎聘', color: 'green' }
}
const platform = platformMap[params.row.platform_type] || { text: params.row.platform_type, color: 'default' }
return h('Tag', { props: { color: platform.color } }, platform.text)

View File

@@ -20,7 +20,7 @@
</Card>
<!-- 账户信息卡片 -->
<Card v-if="accountInfo.id" style="margin-bottom: 16px;" class="account-info-card">
<Card v-if="accountInfo && (accountInfo.id || accountInfo.sn_code)" style="margin-bottom: 16px;" class="account-info-card">
<div slot="title" style="display: flex; align-items: center; justify-content: space-between;">
<span>账户信息</span>
<Button type="primary" size="small" @click="viewAccountDetail">查看详情</Button>
@@ -718,26 +718,21 @@ export default {
try {
console.log('加载账户信息设备SN:', this.selectedDeviceSn)
// 根据 sn_code 查询账户信息
const res = await PlaAccountServer.page({
seachOption: {
key: 'sn_code',
value: this.selectedDeviceSn
},
pageOption: {
page: 1,
pageSize: 1
}
})
// 通过 sn_code 直接获取账户信息
const res = await PlaAccountServer.getBySnCode(this.selectedDeviceSn)
console.log('账户信息接口返回:', res)
// 支持多种数据格式
const accountList = res.data?.rows || res.data?.list || res.data?.data || []
if (res.code === 0 && res.data) {
const accountData = res.data
console.log('找到账户信息原始数据:', accountData)
if (accountList.length > 0) {
const accountData = accountList[0]
console.log('找到账户信息:', accountData)
// 确保 id 字段存在,支持多种字段名
if (!accountData.id) {
accountData.id = accountData.account_id || accountData.accountId || accountData.ID || null
}
console.log('账户ID:', accountData.id)
// 如果接口没有返回设备状态,则单独查询
if (accountData.is_online === undefined || accountData.is_logged_in === undefined) {
@@ -758,16 +753,18 @@ export default {
}
}
// 确保布尔值字段正确初始化
accountData.is_enabled = accountData.is_enabled !== undefined ? accountData.is_enabled : 1
accountData.auto_deliver = accountData.auto_deliver !== undefined ? accountData.auto_deliver : 0
accountData.auto_chat = accountData.auto_chat !== undefined ? accountData.auto_chat : 0
accountData.auto_active = accountData.auto_active !== undefined ? accountData.auto_active : 0
// 确保布尔值字段正确初始化转换为数字类型0 或 1
accountData.is_enabled = accountData.is_enabled !== undefined ? Number(accountData.is_enabled) : 1
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_active = accountData.auto_active !== undefined ? Number(accountData.auto_active) : 0
this.accountInfo = accountData
console.log('设置账户信息:', this.accountInfo)
console.log('accountInfo.id 值:', this.accountInfo.id)
console.log('v-if 判断结果:', !!this.accountInfo.id)
} else {
console.warn('未找到账户信息设备SN:', this.selectedDeviceSn)
console.warn('未找到账户信息设备SN:', this.selectedDeviceSn, '响应:', res)
this.accountInfo = {}
}
} catch (error) {
@@ -778,7 +775,7 @@ export default {
// 处理开关变化
async handleSwitchChange(field, value) {
if (!this.accountInfo.id) {
if (!this.accountInfo || !this.accountInfo.id) {
this.$Message.warning('账户信息不存在')
return
}
@@ -801,8 +798,8 @@ export default {
this.switchLoading[field] = true
try {
// 确保 value 是数字类型0 或 1
const numericValue = value ? 1 : 0
// i-switch 的 on-change 事件已经返回了正确的值1 或 0直接使用
const numericValue = Number(value)
// 构建更新数据,确保是纯对象,只包含基本类型
const updateData = {
@@ -822,19 +819,8 @@ export default {
const errorMsg = error.response?.data?.message || error.message || '请稍后重试'
this.$Message.error('更新失败:' + errorMsg)
// 恢复原值
this.$nextTick(() => {
const oldValue = this.accountInfo[field]
if (field === 'is_enabled') {
this.accountInfo.is_enabled = oldValue === 1 ? 0 : 1
} else if (field === 'auto_deliver') {
this.accountInfo.auto_deliver = oldValue === 1 ? 0 : 1
} else if (field === 'auto_chat') {
this.accountInfo.auto_chat = oldValue === 1 ? 0 : 1
} else if (field === 'auto_active') {
this.accountInfo.auto_active = oldValue === 1 ? 0 : 1
}
})
// 恢复原值(从数据库重新加载)
await this.loadAccountInfo()
} finally {
this.switchLoading[field] = false
}
@@ -853,8 +839,8 @@ export default {
// 获取平台颜色
getPlatformColor(platformType) {
const colorMap = {
'1': 'blue',
'2': 'green'
'boss': 'blue',
'liepin': 'green'
}
return colorMap[platformType] || 'default'
},
@@ -862,8 +848,8 @@ export default {
// 获取平台文本
getPlatformText(platformType) {
const textMap = {
'1': 'Boss直聘',
'2': '猎聘'
'boss': 'Boss直聘',
'liepin': '猎聘'
}
return textMap[platformType] || platformType || '-'
}

View File

@@ -18,6 +18,35 @@ module.exports = {
const accountData = await plaAccountService.getAccountById(id);
return ctx.success(accountData);
},
/**
* @swagger
* /admin_api/account/getBySnCode:
* post:
* summary: 通过设备SN码获取账号信息
* description: 根据设备SN码直接获取对应的账号信息
* tags: [后台-账号管理]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - sn_code
* properties:
* sn_code:
* type: string
* description: 设备SN码
* responses:
* 200:
* description: 获取成功
*/
'POST /account/getBySnCode': async (ctx) => {
const { sn_code } = ctx.getBody();
const accountData = await plaAccountService.getAccountBySnCode(sn_code);
return ctx.success(accountData);
},
/**
* @swagger
* /admin_api/account/list:

View File

@@ -1,4 +1,5 @@
const db = require('../dbProxy.js');
const logProxy = require('../logProxy.js');
const deviceManager = require('../schedule/deviceManager.js');
/**
@@ -192,7 +193,7 @@ class MqttDispatcher {
heartbeatData = JSON.parse(message);
}
const { sn_code, timestamp, status, memory, platform_status, platform_login_status } = heartbeatData;
const { sn_code, timestamp, status, memory, platform_status, platform_login_status,clientId } = heartbeatData;
if (!sn_code) {
console.warn('[MQTT心跳] 心跳消息中未找到设备SN码');
@@ -232,6 +233,7 @@ class MqttDispatcher {
loggedInUsername = platform_login_status.username || '';
loggedInUserId = platform_login_status.user_id || null;
if (platform_login_status.timestamp) {
loginTime = new Date(platform_login_status.timestamp);
}
@@ -266,19 +268,11 @@ class MqttDispatcher {
if (device) {
await device_status.update(updateData, { where: { sn_code } });
console.log(`[MQTT心跳] 设备 ${sn_code} 状态已更新 - 在线: true, 登录: ${updateData.isLoggedIn}`);
} else {
// 创建新设备记录
await device_status.create({
sn_code,
deviceName: `设备_${sn_code}`,
deviceType: 'node_mqtt_client',
...updateData,
isRunning: false,
taskStatus: 'idle',
healthStatus: 'unknown',
healthScore: 0
});
console.log(`[MQTT心跳] 设备 ${sn_code} 记录已创建 - 在线: true, 登录: ${updateData.isLoggedIn}`);
}
else
{
logProxy.error('[MQTT心跳] 设备 ${sn_code} 不存在', { sn_code });
return;
}
// 记录心跳到设备管理器

View File

@@ -37,6 +37,46 @@ class PlaAccountService {
return accountData;
}
/**
* 根据设备SN码获取账号信息
* @param {string} sn_code - 设备SN码
* @returns {Promise<Object>} 账号信息
*/
async getAccountBySnCode(sn_code) {
const pla_account = db.getModel('pla_account');
const device_status = db.getModel('device_status');
if (!sn_code) {
throw new Error('设备SN码不能为空');
}
// 根据 sn_code 查询账号,排除已删除的账号
const account = await pla_account.findOne({
where: {
sn_code: sn_code,
is_delete: 0
}
});
if (!account) {
throw new Error('账号不存在');
}
const accountData = account.get({ plain: true });
// 从 device_status 查询在线状态和登录状态
const deviceStatus = await device_status.findByPk(sn_code);
if (deviceStatus) {
accountData.is_online = deviceStatus.isOnline || false;
accountData.is_logged_in = deviceStatus.isLoggedIn || false;
} else {
accountData.is_online = false;
accountData.is_logged_in = false;
}
return accountData;
}
/**
* 获取账号列表
* @param {Object} params - 查询参数