联调接口

This commit is contained in:
xuli3099
2025-08-12 13:43:21 +08:00
parent 74596473ab
commit f5717959ae
15 changed files with 293 additions and 114 deletions

View File

@@ -70,7 +70,6 @@
</block>
</view>
</view>
<view class="bottom-pic">
<image src="@/static/images/PicLogo@2x.png" class="pic-logo" />
@@ -85,8 +84,10 @@ import { ref,nextTick,onMounted,onUnmounted,getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { v4 as uuidv4 } from 'uuid'
import { getNavBarPaddingTop} from '@/utils/system.js';
import { getBindStatus } from '@/api/auth.js';
import { getBindStatus,authDeviceApply,authInputCode } from '@/api/auth.js';
import {showToast} from '@/utils/message.js'
import { CLIENT_ID,NETWORK_ENV } from '@/enums/cacheEnums';
import encryptObj from '@/utils/encrypt.js'
const { proxy } = getCurrentInstance();
import { useUserStore } from '@/stores/user';
@@ -112,7 +113,9 @@ onMounted(async () => {
console.log("333bindStatus=>",bindStatus.value)
if(bindStatus.value==2){
// bindStatus=2-----到等待页面(定时任务查询 10秒查询一次
timer = setInterval(()=>{ refreshBindStatus() },1000*10)//10秒刷新一次
timer = setInterval(()=>{
refreshBindStatus()
},1000*10)//10秒刷新一次
}
})
@@ -124,7 +127,7 @@ onUnmounted(() => {
// 根据设备ID查询设备状态
let selectBindStatus = async ()=>{
if(deviceId.value){
let res = await getBindStatus({deviceId:deviceId.value})
let res = await getBindStatus({uniqCode:deviceId.value})
bindStatus.value = res.bindStatus;
console.log("111bindStatus=>",bindStatus.value)
@@ -145,10 +148,12 @@ let selectBindStatus = async ()=>{
// 刷新定时任务
let refreshBindStatus = async ()=>{
let res = await getBindStatus({deviceId:deviceId.value})
let res = await getBindStatus({uniqCode:deviceId.value})
bindStatus.value = res.bindStatus;
console.log("222bindStatus=>",bindStatus.value)
if(bindStatus.value==2){}else{
if(bindStatus.value==2){
}else{
if(bindStatus.value==4){
if (userStore.isLogin) {
uni.reLaunch({
@@ -167,50 +172,84 @@ let refreshBindStatus = async ()=>{
// 账号登录
const form2 = ref(null);
const formData2 = ref({
username: 'admin',
password: '123456'
username: '',
password: ''
});
const rules2 = {
username: {
rules: [
{ required: true, errorMessage: '请输入用户名' },
{ minLength: 3, maxLength: 10, errorMessage: '用户名长度在3到10个字符之间' }
// { minLength: 3, maxLength: 10, errorMessage: '用户名长度在3到10个字符之间' }
]
},
password: {
rules: [
{ required: true, errorMessage: '请输入密码' },
{ pattern: /^[a-zA-Z0-9]{6,12}$/, errorMessage: '密码必须是6-12位字母或数字' }
// { pattern: /^[a-zA-Z0-9]{6,12}$/, errorMessage: '密码必须是6-12位字母或数字' }
]
}
};
const btnLoading=ref(false)
// 登录提交
const submitForm = () => {
// 用户名和密码登录
form2.value.validate().then(async param => {
const submitForm = async() => {
// 用户名和密码登录
form2.value.validate().then(async param => {
btnLoading.value = true;
setTimeout(()=>{
console.log('表单数据11:', formData2.value);
// let res = await login(param);
deviceId.value = uuidv4();
let cilentId = `${CLIENT_ID || 2}`;
let password = encryptObj.Encrypt(param.username + cilentId + "," + param.password);
console.log("password=>",password)
btnLoading.value = false;
deviceId.value = uuidv4();console.log("新生成=>",deviceId.value);
uni.setStorageSync('app_device_id', deviceId.value)
bindStatus.value = 2;//默认为 等待审核
timer = setInterval(()=>{ refreshBindStatus() },1000*10)//10秒刷新一次
},500)
let systemInfo = uni.getSystemInfoSync()
let params = {
username:param.username,
password,
networkEnv:NETWORK_ENV,//1-内网2-外网
uniqCode:deviceId.value,//生成的设备唯一标识
...systemInfo,//设备信息
// #ifdef APP-PLUS
verId:systemInfo.appWgtVersion,//当前版本号
// #endif
// #ifdef H5
verId : systemInfo.appVersion,
// #endif
osAndroidApiLevel:systemInfo.osAndroidAPILevel
}
console.log("params=>",params)
let res = await authDeviceApply(params);
console.log("authDeviceApply=>",res)
btnLoading.value = false;
uni.setStorageSync('app_device_id', deviceId.value)
bindStatus.value = res.bindStatus;//默认为 2-等待审核
// 刷新状态
refreshBindStatus();
timer = setInterval(()=>{
refreshBindStatus()
},1000*10)//10秒刷新一次
}).catch(err => {
console.log('表单错误11:', err);
btnLoading.value = false;
});
};
// 在UniApp的APP端使用plus.netinfo
let getLocalIPInUniApp=()=>{
return new Promise((resolve) => {
plus.netinfo.getCurrentInfo((info) => {
const ips = [];
if (info.wifi && info.wifi.ipAddress) {
ips.push(info.wifi.ipAddress);
}
if (info.cellular && info.cellular.ipAddress) {
ips.push(info.cellular.ipAddress);
}
console.log(1111,ips)
resolve(ips.length ? ips : ['无法获取本地IP']);
});
});
}
// 刷新
const handleRefresh = ()=>{
selectBindStatus();
@@ -276,7 +315,6 @@ const handleInput=(e,type)=>{
num6.value = obj6.num;
break;
}
}
let authCode = ref('')
@@ -290,6 +328,7 @@ const handleBlur = ()=>{
authCode.value = pass1+pass2+pass3+pass4+pass5+pass6;
}
// 执行设备绑定
let subLoading = ref(false)
const handleSubmit=()=>{
console.log("authCode=>",authCode.value)
@@ -297,10 +336,22 @@ const handleSubmit=()=>{
showToast("请输入验证码")
return;
}
if(authCode.value.length!=6){
showToast("请正确输入验证码")
return;
}
let uniqCode = uni.getStorageSync('app_device_id');
let param={
uniqCode,
authCode:authCode.value
}
subLoading.value=true;
uni.reLaunch({ url: '/pages/login/login' })
subLoading.value = false;
authInputCode(param).then(res=>{
uni.reLaunch({ url: '/pages/login/login' })
}).finally(()=>{
subLoading.value = false;
})
}
</script>