From f5717959aefbd5c93e134b4c7eb56dbc6bbb5a4f Mon Sep 17 00:00:00 2001 From: xuli3099 Date: Tue, 12 Aug 2025 13:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- .env.production | 5 +- package-lock.json | 6 ++ package.json | 1 + src/api/auth.js | 31 ++++-- src/enums/cacheEnums.js | 8 +- src/enums/requestEnums.js | 4 +- src/pages/deviceAuth/deviceAuth.vue | 111 ++++++++++++++------ src/pages/loading/loading.vue | 153 +++++++++++++++++----------- src/pages/login/login.vue | 19 ++-- src/utils/encrypt.js | 30 ++++++ src/utils/message.js | 2 +- src/utils/request/index.js | 8 +- src/utils/status.js | 11 ++ vite.config.js | 14 +-- 15 files changed, 293 insertions(+), 114 deletions(-) create mode 100644 src/utils/encrypt.js create mode 100644 src/utils/status.js diff --git a/.env.development b/.env.development index a5b4b61..fc7bca5 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,4 @@ -VITE_APP_BASE_URL = "http://192.168.20.191:3000" + +#调用后台地址 +VITE_APP_BASE_URL = "http://192.168.236.71:31302" # VITE_APP_BASE_URL = "http://123.57.20.168:3000" \ No newline at end of file diff --git a/.env.production b/.env.production index 8f1c1dc..fc7bca5 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,4 @@ -VITE_APP_BASE_URL = "http://192.168.20.191:5173" \ No newline at end of file + +#调用后台地址 +VITE_APP_BASE_URL = "http://192.168.236.71:31302" +# VITE_APP_BASE_URL = "http://123.57.20.168:3000" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0ff08c1..ae1b612 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "@dcloudio/uni-mp-xhs": "3.0.0-4070520250711001", "@dcloudio/uni-quickapp-webview": "3.0.0-4070520250711001", "@dcloudio/uni-ui": "^1.5.7", + "crypto-js": "^4.2.0", "mescroll-uni": "^1.3.7", "pinia": "2.0.20", "uuid": "^11.1.0", @@ -8971,6 +8972,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/css-font-size-keywords": { "version": "1.0.0", "license": "MIT" diff --git a/package.json b/package.json index d1012ca..28f4e57 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@dcloudio/uni-mp-xhs": "3.0.0-4070520250711001", "@dcloudio/uni-quickapp-webview": "3.0.0-4070520250711001", "@dcloudio/uni-ui": "^1.5.7", + "crypto-js": "^4.2.0", "mescroll-uni": "^1.3.7", "pinia": "2.0.20", "uuid": "^11.1.0", diff --git a/src/api/auth.js b/src/api/auth.js index ecb4728..bea530e 100644 --- a/src/api/auth.js +++ b/src/api/auth.js @@ -3,7 +3,7 @@ import request from "@/utils/request" // 获取客户端版本 export function versionCheck(data) { return request.post({ - url: '/api/versionCheck', + url: '/acc/auth/version', data }) } @@ -11,18 +11,28 @@ export function versionCheck(data) { // 获取设备绑定状态 export function getBindStatus(data) { return request.post({ - url: '/api/getBindStatus', + url: '/acc/auth/status', data }) } -// 获取图片 -export function getCaptchaImage() { - return request.get({ - url: '/api/captchaImage', +// 申请设备授权 +export function authDeviceApply(data) { + return request.post({ + url: '/acc/auth/apply', + data }) } +// App绑定设备授权码 +export function authInputCode(data) { + return request.post({ + url: '/acc/auth/inputCode', + data + }) +} + + // 获取验证码 export function getVerifyCode(data) { return request.post({ @@ -34,11 +44,18 @@ export function getVerifyCode(data) { // 登录 export function login(data) { return request.post({ - url: '/api/user/login', + url: '/acc/auth/login', data }) } +// 登出 +export function logout(data) { + return request.post({ + url: '/acc/auth/logout', + data + }) +} // 获取用户信息 export function getUserInfo(data) { diff --git a/src/enums/cacheEnums.js b/src/enums/cacheEnums.js index a4a4a8d..2258607 100644 --- a/src/enums/cacheEnums.js +++ b/src/enums/cacheEnums.js @@ -1,2 +1,8 @@ export const TOKEN_KEY = 'token'; -export const AGREEWELCOME_KEY="agreewelcome" \ No newline at end of file +export const AGREEWELCOME_KEY="agreewelcome"; + +// clientId 默认写2 +export const CLIENT_ID=2; +// #区分内外网 //1-内网,2-外网 +export const NETWORK_ENV=1; + diff --git a/src/enums/requestEnums.js b/src/enums/requestEnums.js index 01955c9..dbf4e9e 100644 --- a/src/enums/requestEnums.js +++ b/src/enums/requestEnums.js @@ -10,9 +10,9 @@ export const RequestMethodsEnum = { }; export const RequestCodeEnum = { - SUCCESS: 0, //成功 + SUCCESS: 0 || 200, //成功 FAILED: -1, // 失败 - TOKEN_INVALID: 10003 // TOKEN失效未登录 + TOKEN_INVALID: 401 // TOKEN失效未登录 }; export const RequestErrMsgEnum = { diff --git a/src/pages/deviceAuth/deviceAuth.vue b/src/pages/deviceAuth/deviceAuth.vue index b0e9f34..a3e78e3 100644 --- a/src/pages/deviceAuth/deviceAuth.vue +++ b/src/pages/deviceAuth/deviceAuth.vue @@ -70,7 +70,6 @@ - @@ -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; + }) } diff --git a/src/pages/loading/loading.vue b/src/pages/loading/loading.vue index 44bf34c..0e85ade 100644 --- a/src/pages/loading/loading.vue +++ b/src/pages/loading/loading.vue @@ -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) -} -