设备录入实现,基地址临时改为线下,未登录状态暂时开放使用录入
This commit is contained in:
parent
8cbc733c2b
commit
63c41a0720
|
|
@ -20,3 +20,21 @@ export function isSysAdmin() {
|
|||
method: 'GET',
|
||||
})
|
||||
}
|
||||
|
||||
export function listSnByMac(macList) {
|
||||
return request({
|
||||
url: '/bst/device/listSnByMac',
|
||||
method: 'POST',
|
||||
data: {
|
||||
macList,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function bstDevice(data) {
|
||||
return request({
|
||||
url: '/bst/device',
|
||||
method: 'POST',
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { bstDevice } from '../../api'
|
||||
|
||||
const app = getApp()
|
||||
import xBlufi from '@/components/blufi/xBlufi.js'
|
||||
|
||||
|
|
@ -286,34 +288,60 @@ export default {
|
|||
delta: 1, // delta值为1时表示返回的页面层数
|
||||
})
|
||||
},
|
||||
bind() {
|
||||
let data = {
|
||||
sn: this.sn,
|
||||
mac: this.mac,
|
||||
hardwareVersionId: this.hardwareVersionId,
|
||||
simProducer: this.kaid,
|
||||
}
|
||||
console.log(data, '111')
|
||||
this.$u.post(`/bst/device`, data).then(res => {
|
||||
if (res.code == 200) {
|
||||
|
||||
async bind() {
|
||||
try {
|
||||
// 1. 数据验证
|
||||
if (!this.sn || !this.mac) {
|
||||
throw new Error('SN码和MAC地址不能为空')
|
||||
}
|
||||
|
||||
// 2. 准备请求数据
|
||||
const requestData = {
|
||||
sn: this.sn.trim(),
|
||||
mac: this.mac.trim(),
|
||||
hardwareVersionId: this.hardwareVersionId,
|
||||
simProducer: this.kaid,
|
||||
}
|
||||
|
||||
console.log('绑定请求数据:', requestData)
|
||||
|
||||
// 3. 显示加载状态
|
||||
uni.showLoading({
|
||||
title: '绑定中...',
|
||||
mask: true,
|
||||
})
|
||||
|
||||
// 4. 发起绑定请求
|
||||
const res = await bstDevice(requestData)
|
||||
|
||||
// 5. 处理响应
|
||||
if (res.code === 200) {
|
||||
uni.showToast({
|
||||
title: '操作成功',
|
||||
title: '绑定成功',
|
||||
icon: 'success',
|
||||
duration: 2000,
|
||||
})
|
||||
|
||||
// 延迟跳转,让用户看到成功提示
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url: '/page_user/luru/controlDevice?sn=' + this.sn,
|
||||
url: `/page_user/luru/controlDevice?sn=${encodeURIComponent(this.sn)}`,
|
||||
})
|
||||
}, 2000)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
throw new Error(res.msg || '绑定失败')
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('绑定出错:', error)
|
||||
uni.showToast({
|
||||
title: error.message,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
} finally {
|
||||
uni.hideLoading()
|
||||
}
|
||||
},
|
||||
qrcode() {
|
||||
uni.scanCode({
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { listSnByMac } from '../../api'
|
||||
|
||||
const app = getApp()
|
||||
import xBlufi from '../../components/blufi/xBlufi'
|
||||
|
||||
|
|
@ -149,45 +151,42 @@ export default {
|
|||
url: '/page_user/luru/controlDevice',
|
||||
})
|
||||
},
|
||||
fetchDevicesBoundStatus() {
|
||||
// 提取所有设备的 MAC 地址,并通过 Set 去重
|
||||
let uniqueDevices = Array.from(
|
||||
new Set(this.devicesList.map(item => item.localName.substring(5)))
|
||||
)
|
||||
// 重新构建去重后的 devicesList
|
||||
this.devicesList = uniqueDevices.map(mac => {
|
||||
return this.devicesList.find(item => item.localName.substring(5) === mac)
|
||||
})
|
||||
// 拼接成字符串
|
||||
const macs = uniqueDevices
|
||||
// 向批量接口请求录入状态
|
||||
let data = macs
|
||||
this.$u
|
||||
.post(`/bst/device/listSnByMac`, data)
|
||||
.then(res => {
|
||||
const resultList = res.data // 获取接口返回的数据数组
|
||||
console.log(res, '请求')
|
||||
// 遍历 devicesList 并对比 mac 地址
|
||||
this.devicesList.forEach(device => {
|
||||
const mac = device.localName.substring(5)
|
||||
// 查找返回结果中是否有与该设备 MAC 地址相同的项
|
||||
const matchingResult = resultList.find(result => result.mac === mac)
|
||||
// 如果找到了匹配的 MAC 地址项,则更新设备的 sn 和 isBand
|
||||
if (matchingResult) {
|
||||
device.sn = matchingResult.sn
|
||||
device.isBand = true
|
||||
}
|
||||
})
|
||||
// 对 devicesList 进行排序,将 isBand 为 false 的设备排在前面
|
||||
this.devicesList.sort((a, b) => {
|
||||
return (a.isBand === false ? -1 : 1) - (b.isBand === false ? -1 : 1)
|
||||
})
|
||||
this.$forceUpdate() // 强制更新视图
|
||||
console.log(this.devicesList, 'Updated devicesList')
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('批量获取设备录入状态失败', error)
|
||||
async fetchDevicesBoundStatus() {
|
||||
try {
|
||||
// 1. 提取并去重设备MAC地址
|
||||
const uniqueMacs = [...new Set(this.devicesList.map(item => item.localName.substring(5)))]
|
||||
|
||||
// 2. 重构去重后的设备列表(保留第一个匹配项)
|
||||
this.devicesList = uniqueMacs
|
||||
.map(mac => this.devicesList.find(item => item.localName.substring(5) === mac))
|
||||
.filter(Boolean) // 过滤掉undefined项
|
||||
|
||||
// 3. 批量查询设备状态
|
||||
const { data: resultList } = await listSnByMac(uniqueMacs)
|
||||
console.log('API响应:', resultList)
|
||||
|
||||
// 4. 更新设备状态
|
||||
const macToDeviceMap = new Map(
|
||||
this.devicesList.map(device => [device.localName.substring(5), device])
|
||||
)
|
||||
|
||||
resultList.forEach(({ mac, sn }) => {
|
||||
const device = macToDeviceMap.get(mac)
|
||||
if (device) {
|
||||
device.sn = sn
|
||||
device.isBand = true
|
||||
}
|
||||
})
|
||||
|
||||
// 5. 排序设备列表(未绑定的排前面)
|
||||
this.devicesList.sort((a, b) => (a.isBand ? 1 : -1) - (b.isBand ? 1 : -1))
|
||||
|
||||
console.log('更新后的设备列表:', this.devicesList)
|
||||
this.$forceUpdate()
|
||||
} catch (error) {
|
||||
console.error('批量获取设备录入状态失败:', error)
|
||||
// 可以在这里添加错误处理逻辑,如显示错误提示
|
||||
}
|
||||
},
|
||||
choose(e) {
|
||||
console.log(e)
|
||||
|
|
|
|||
|
|
@ -18,18 +18,18 @@ import {
|
|||
const ENV_CONFIG = {
|
||||
develop: {
|
||||
// 开发环境
|
||||
// baseUrl: 'http://192.168.2.174:4501',
|
||||
baseUrl: 'https://chu.chuangtewl.com/prod-api',
|
||||
// baseUrl: 'http://192.168.2.13:4601',
|
||||
baseUrl: 'http://192.168.2.13:4601',
|
||||
appId: 1,
|
||||
},
|
||||
trial: {
|
||||
// 体验版
|
||||
baseUrl: 'https://chu.chuangtewl.com/prod-api',
|
||||
baseUrl: 'http://192.168.2.13:4601',
|
||||
appId: 1,
|
||||
},
|
||||
release: {
|
||||
// 正式版
|
||||
baseUrl: 'https://chu.chuangtewl.com/prod-api',
|
||||
baseUrl: 'http://192.168.2.13:4601',
|
||||
appId: 1,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user