联调接口

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>

View File

@@ -23,6 +23,7 @@
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { versionCheck,getBindStatus } from '@/api/auth.js';
import { formatIOS } from '@/utils/status.js'
import { useUserStore } from '@/stores/user';
const userStore = useUserStore();
@@ -43,51 +44,82 @@ onLoad(async(opt) => {
// #ifdef APP-PLUS
// 查询版本接口
await getOSVesion();
// #endif
// 不更新版本 执行设备ID查询和绑定操作
if(!versionVisible.value){
selectDeviceId()
}
// #endif
// #ifdef H5
setTimeout(()=>{
if(userStore.isLogin){
uni.reLaunch({
url: '/pages/home/home',
});
}else{
uni.reLaunch({
url: '/pages/login/login',
});
}
},2000)
// #endif
});
// 检查版本是否是最新的
let getOSVesion = async()=>{
let systemInfo = uni.getSystemInfoSync();
let systemInfo = uni.getSystemInfoSync(); console.log(systemInfo.osName)
let param = {
// #ifdef APP-PLUS
appVersion:systemInfo.appWgtVersion,//当前版本号
verNumber:systemInfo.appWgtVersion,//当前版本号
// #endif
// #ifdef H5
appVersion : systemInfo.appVersion,
verNumber : systemInfo.appVersion,
// #endif
deviceType:systemInfo.model,//型号
os: systemInfo.osName,//操作系统 Android IOS
osVersion:systemInfo.osVersion,//操作系统版本
resolution:systemInfo.windowWidth+"*"+systemInfo.windowHeight,//分辨率
trademark:systemInfo.deviceBrand,//设备品牌
uniqueCode:systemInfo.deviceId//设备ID
// deviceType:systemInfo.model,//型号
os: formatIOS(systemInfo.osName),//操作系统 Android IOS
// osVersion:systemInfo.osVersion,//操作系统版本
// resolution:systemInfo.windowWidth+"*"+systemInfo.windowHeight,//分辨率
// trademark:systemInfo.deviceBrand,//设备品牌
// uniqueCode:systemInfo.deviceId//设备ID
}
// 当前手机版本
appVersion.value = param.appVersion;
appVersion.value = param.verNumber;
// console.log("appVersion=>",appVersion)
versionData.value = param;
let data = await versionCheck(param);
newVersion.value = data.latestVersion;
newVersion.value = data.verNumber;
// isForceUpdate 是否强制更新 1-是 2-否
let isForceUpdate = data.isForceUpdate;
if(isForceUpdate==1){
btnVisible.value = false;
}else{
btnVisible.value = true;
}
// 是否为当前最新版本(是=1否=2)
let isCurrent = data.isCurrent;
if(isCurrent == 1){
versionVisible.value=false;
}else{
versionVisible.value=true;
}
// 版本状态 0-最新版本 1-有新版本,但现有版本可用 2-现有版本不可用,需要下载新版本
if(data.status == 1 || data.status == 2){
versionVisible.value = true;
downloadURL.value = data.downloadURL;
// 可用版本列表
let availableVersionsList = data.availableVersionsList;
// let versionList = availableVersionsList.split(",");
if(availableVersionsList.indexOf(appVersion.value)>-1){
btnVisible.value = true;
}else{
btnVisible.value = false;
}
// }else{
// if(data.status == 1 || data.status == 2){
// versionVisible.value = true;
// downloadURL.value = data.downloadURL;
// // 可用版本列表
// let availableVersionsList = data.availableVersionsList;
// // let versionList = availableVersionsList.split(",");
// if(availableVersionsList.indexOf(appVersion.value)>-1){
// }else{
// btnVisible.value = false;
// }
// // }else{
// if(userStore.isLogin){
// // _this.getUserInfo();
// }else{
@@ -95,18 +127,53 @@ let getOSVesion = async()=>{
// url: '/pages/home/home',
// });
// }
}
// }
}
// 查询设备ID
const selectDeviceId = async()=>{
// 查询本地缓存的设备状态是否绑定过
let deviceId = uni.getStorageSync('app_device_id');// 本地设备ID
console.log("uniqCode=>",deviceId)
if(!deviceId){
setTimeout(()=>{
uni.reLaunch({
url: '/pages/deviceAuth/deviceAuth',
});
},2000)
}else{
let res = await getBindStatus({uniqCode:deviceId});
console.log("getBindStatus=>",res)
setTimeout(()=>{
// 检查是否已登录 并 获取用户信息
// if (userStore.isLogin) {
// 绑定状态1=已提交、2=等待审核、3=审核通过、4=绑定成功、5=审核拒绝)
if(res.bindStatus == 4){
uni.reLaunch({
url: '/pages/home/home',
});
}else{
uni.reLaunch({
url: '/pages/deviceAuth/deviceAuth',
});
}
// }else{
// uni.reLaunch({
// url: '/pages/login/login',
// });
// }
},2000)
}
}
// 下载最新版本
const handleDown = ()=>{
// 跳转到应用商店或下载最新版本的页面
plus.runtime.openURL(downloadURL.value);
// if (versionData.value.os == 'ios'){
// plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
// } else if (versionData.value.os == 'android'){
if (versionData.value.os == 'ios'){
plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
} else if (versionData.value.os == 'android'){
plus.runtime.quit();
// }
}
}
//版本更新关闭
@@ -117,34 +184,6 @@ const handleClose=()=>{
selectDeviceId()
}
}
// 查询设备ID
const selectDeviceId = async()=>{
// 查询本地缓存的设备状态是否绑定过
let deviceId = ref(undefined);
deviceId.value = uni.getStorageSync('app_device_id');// 本地设备ID
let res = await getBindStatus({deviceId:deviceId.value});
setTimeout(()=>{
// 检查是否已登录 并 获取用户信息
if (userStore.isLogin) {
// 绑定状态1=已提交、2=等待审核、3=审核通过、4=绑定成功、5=审核拒绝)
if(res.bindStatus == 4){
uni.reLaunch({
url: '/pages/home/home',
});
}else{
uni.reLaunch({
url: '/pages/deviceAuth/deviceAuth',
});
}
}else{
uni.reLaunch({
url: '/pages/login/login',
});
}
},2000)
}
</script>
<style>

View File

@@ -81,10 +81,11 @@ import {showAlert} from '@/utils/message';
import { getVerifyCode,login } from '@/api/auth';
import cache from '@/utils/cache';
import { AGREEWELCOME_KEY } from '@/enums/cacheEnums';
import { getNavBarPaddingTop} from '@/utils/system.js'
import { useUserStore } from '@/stores/user';
import encryptObj from '@/utils/encrypt.js'
import { CLIENT_ID } from '@/enums/cacheEnums';
const userStore = useUserStore()
onLoad(async(opt) => {
uni.setStorageSync('page_cache',true);
@@ -187,7 +188,7 @@ let resetCountdown =()=>{
// 账号登录
const form2 = ref(null);
const formData2 = ref({
username: 'admin',
username: '445',
password: '123456',
loginType:1
});
@@ -196,13 +197,13 @@ 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位字母或数字' }
]
}
};
@@ -242,7 +243,13 @@ const submitForm = () => {
}else if(activeTab.value===1){
// 用户名和密码登录
form2.value.validate().then(async param => {
param.loginType = activeTab.value; console.log('表单数据11:', formData2.value);
param.loginType = activeTab.value;
let cilentId = `${CLIENT_ID || 2}`;
let password = encryptObj.Encrypt(param.username + cilentId + "," + param.password);
param.password = password;
param.uniqCode = uni.getStorageSync('app_device_id');//先从缓存取之后处理
console.log("login->param->",param)
let res = await login(param);
userStore.login(res);
uni.switchTab({ url: '/pages/home/home' })