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

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', 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> </template>
<script> <script>
import { bstDevice } from '../../api'
const app = getApp() const app = getApp()
import xBlufi from '@/components/blufi/xBlufi.js' import xBlufi from '@/components/blufi/xBlufi.js'
@ -286,34 +288,60 @@ export default {
delta: 1, // delta1 delta: 1, // delta1
}) })
}, },
bind() {
let data = { async bind() {
sn: this.sn, try {
mac: this.mac, // 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, hardwareVersionId: this.hardwareVersionId,
simProducer: this.kaid, simProducer: this.kaid,
} }
console.log(data, '111')
this.$u.post(`/bst/device`, data).then(res => { console.log('绑定请求数据:', requestData)
if (res.code == 200) {
// 3.
uni.showLoading({
title: '绑定中...',
mask: true,
})
// 4.
const res = await bstDevice(requestData)
// 5.
if (res.code === 200) {
uni.showToast({ uni.showToast({
title: '操作成功', title: '绑定成功',
icon: 'success', icon: 'success',
duration: 2000, duration: 2000,
}) })
//
setTimeout(() => { setTimeout(() => {
uni.navigateTo({ uni.navigateTo({
url: '/page_user/luru/controlDevice?sn=' + this.sn, url: `/page_user/luru/controlDevice?sn=${encodeURIComponent(this.sn)}`,
}) })
}, 2000) }, 2000)
} else { } else {
throw new Error(res.msg || '绑定失败')
}
} catch (error) {
console.error('绑定出错:', error)
uni.showToast({ uni.showToast({
title: res.msg, title: error.message,
icon: 'none', icon: 'none',
duration: 2000, duration: 2000,
}) })
} finally {
uni.hideLoading()
} }
})
}, },
qrcode() { qrcode() {
uni.scanCode({ uni.scanCode({

View File

@ -62,6 +62,8 @@
</template> </template>
<script> <script>
import { listSnByMac } from '../../api'
const app = getApp() const app = getApp()
import xBlufi from '../../components/blufi/xBlufi' import xBlufi from '../../components/blufi/xBlufi'
@ -149,45 +151,42 @@ export default {
url: '/page_user/luru/controlDevice', url: '/page_user/luru/controlDevice',
}) })
}, },
fetchDevicesBoundStatus() { async fetchDevicesBoundStatus() {
// MAC Set try {
let uniqueDevices = Array.from( // 1. MAC
new Set(this.devicesList.map(item => item.localName.substring(5))) 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])
) )
// devicesList
this.devicesList = uniqueDevices.map(mac => { resultList.forEach(({ mac, sn }) => {
return this.devicesList.find(item => item.localName.substring(5) === mac) const device = macToDeviceMap.get(mac)
}) if (device) {
// device.sn = sn
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 device.isBand = true
} }
}) })
// devicesList isBand false
this.devicesList.sort((a, b) => { // 5.
return (a.isBand === false ? -1 : 1) - (b.isBand === false ? -1 : 1) this.devicesList.sort((a, b) => (a.isBand ? 1 : -1) - (b.isBand ? 1 : -1))
})
this.$forceUpdate() // console.log('更新后的设备列表:', this.devicesList)
console.log(this.devicesList, 'Updated devicesList') this.$forceUpdate()
}) } catch (error) {
.catch(error => { console.error('批量获取设备录入状态失败:', error)
console.error('批量获取设备录入状态失败', error) //
}) }
}, },
choose(e) { choose(e) {
console.log(e) console.log(e)

View File

@ -18,18 +18,18 @@ import {
const ENV_CONFIG = { const ENV_CONFIG = {
develop: { develop: {
// 开发环境 // 开发环境
// baseUrl: 'http://192.168.2.174:4501', // baseUrl: 'http://192.168.2.13:4601',
baseUrl: 'https://chu.chuangtewl.com/prod-api', baseUrl: 'http://192.168.2.13:4601',
appId: 1, appId: 1,
}, },
trial: { trial: {
// 体验版 // 体验版
baseUrl: 'https://chu.chuangtewl.com/prod-api', baseUrl: 'http://192.168.2.13:4601',
appId: 1, appId: 1,
}, },
release: { release: {
// 正式版 // 正式版
baseUrl: 'https://chu.chuangtewl.com/prod-api', baseUrl: 'http://192.168.2.13:4601',
appId: 1, appId: 1,
}, },
} }