设备录入实现,基地址临时改为线下,未登录状态暂时开放使用录入
This commit is contained in:
parent
8cbc733c2b
commit
63c41a0720
|
|
@ -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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, // delta值为1时表示返回的页面层数
|
delta: 1, // delta值为1时表示返回的页面层数
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
bind() {
|
|
||||||
let data = {
|
async bind() {
|
||||||
sn: this.sn,
|
try {
|
||||||
mac: this.mac,
|
// 1. 数据验证
|
||||||
hardwareVersionId: this.hardwareVersionId,
|
if (!this.sn || !this.mac) {
|
||||||
simProducer: this.kaid,
|
throw new Error('SN码和MAC地址不能为空')
|
||||||
}
|
}
|
||||||
console.log(data, '111')
|
|
||||||
this.$u.post(`/bst/device`, data).then(res => {
|
// 2. 准备请求数据
|
||||||
if (res.code == 200) {
|
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({
|
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 {
|
||||||
uni.showToast({
|
throw new Error(res.msg || '绑定失败')
|
||||||
title: res.msg,
|
|
||||||
icon: 'none',
|
|
||||||
duration: 2000,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
} catch (error) {
|
||||||
|
console.error('绑定出错:', error)
|
||||||
|
uni.showToast({
|
||||||
|
title: error.message,
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000,
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
uni.hideLoading()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
qrcode() {
|
qrcode() {
|
||||||
uni.scanCode({
|
uni.scanCode({
|
||||||
|
|
|
||||||
|
|
@ -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)))]
|
||||||
)
|
|
||||||
// 重新构建去重后的 devicesList
|
// 2. 重构去重后的设备列表(保留第一个匹配项)
|
||||||
this.devicesList = uniqueDevices.map(mac => {
|
this.devicesList = uniqueMacs
|
||||||
return this.devicesList.find(item => item.localName.substring(5) === mac)
|
.map(mac => this.devicesList.find(item => item.localName.substring(5) === mac))
|
||||||
})
|
.filter(Boolean) // 过滤掉undefined项
|
||||||
// 拼接成字符串
|
|
||||||
const macs = uniqueDevices
|
// 3. 批量查询设备状态
|
||||||
// 向批量接口请求录入状态
|
const { data: resultList } = await listSnByMac(uniqueMacs)
|
||||||
let data = macs
|
console.log('API响应:', resultList)
|
||||||
this.$u
|
|
||||||
.post(`/bst/device/listSnByMac`, data)
|
// 4. 更新设备状态
|
||||||
.then(res => {
|
const macToDeviceMap = new Map(
|
||||||
const resultList = res.data // 获取接口返回的数据数组
|
this.devicesList.map(device => [device.localName.substring(5), device])
|
||||||
console.log(res, '请求')
|
)
|
||||||
// 遍历 devicesList 并对比 mac 地址
|
|
||||||
this.devicesList.forEach(device => {
|
resultList.forEach(({ mac, sn }) => {
|
||||||
const mac = device.localName.substring(5)
|
const device = macToDeviceMap.get(mac)
|
||||||
// 查找返回结果中是否有与该设备 MAC 地址相同的项
|
if (device) {
|
||||||
const matchingResult = resultList.find(result => result.mac === mac)
|
device.sn = sn
|
||||||
// 如果找到了匹配的 MAC 地址项,则更新设备的 sn 和 isBand
|
device.isBand = true
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 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) {
|
choose(e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user