设备录入实现,基地址临时改为线下,未登录状态暂时开放使用录入

This commit is contained in:
WindowBird 2025-09-02 15:18:50 +08:00
parent 8cbc733c2b
commit 63c41a0720
4 changed files with 105 additions and 60 deletions

View File

@ -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,
})
}

View File

@ -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, // delta1
})
},
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({

View File

@ -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)

View File

@ -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,
},
}