1
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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 - 账号数据
|
||||
|
||||
@@ -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 (accountList.length > 0) {
|
||||
const accountData = accountList[0]
|
||||
console.log('找到账户信息:', accountData)
|
||||
if (res.code === 0 && res.data) {
|
||||
const accountData = res.data
|
||||
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) {
|
||||
@@ -766,8 +761,10 @@ export default {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 - 查询参数
|
||||
|
||||
Reference in New Issue
Block a user