com.kailaimei.carbon/pages/index/index.vue

64 lines
1.4 KiB
Vue

<template>
<view>
<view class="tips" v-if="allowMac!==macStr">使</view>
</view>
</template>
<script>
export default {
data() {
return {
macStr:'', //设备mac
allowMac:'B0:CC:FE:9E:D3:4A', //允许设备mac
}
},
onLoad() {
// #ifdef APP
// 导入Java类。Networklnterface类表示一个由名称和分配给此接口的IP地址列表组成的网络接口
const net = plus.android.importClass('java.net.NetworkInterface');
// 搜索具有指定名称的网络接口
const wlan0 = net.getByName('wlan0');
// 获得网卡的硬件地址
const macByte = wlan0.getHardwareAddress();
//转换MAC地址
let baseMac = '';
macByte.forEach(item => { //.toString(16)数字以十六进制值显示
let temp = '';
if (item < 0){
temp = (256 + item).toString(16);
}else{
temp = item.toString(16);if (temp.length == 1) temp = `0${temp}`;
}
baseMac += temp;
});
// 格式转换
let finalMac = baseMac.toUpperCase();
for (let i = 2; i < finalMac.length; i += 3) {
finalMac = finalMac.slice(0, i) + ':' + finalMac.slice(i);
}
// 赋值MAC
this.macStr = finalMac;
// #endif
if(this.macStr == this.allowMac){
uni.reLaunch({
url:'/pages/count/count'
})
}
},
methods: {
}
}
</script>
<style scoped>
.tips{
font-size: 40rpx;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>