修改登录及设备授权处理

This commit is contained in:
xuli3099
2025-08-19 17:31:28 +08:00
parent 7fa1e5b2f9
commit 8f849cda40
5 changed files with 68 additions and 60 deletions

View File

@@ -1,16 +1,21 @@
import { createSSRApp } from "vue"; import { createSSRApp } from "vue";
import App from "./App.vue"; import App from "./App.vue";
import { CLIENT_ID,NETWORK_ENV } from '@/enums/cacheEnums';
import '@/static/font/iconfont.css' import '@/static/font/iconfont.css'
// pinia // pinia
import { createPinia } from 'pinia' import { createPinia } from 'pinia'
const pinia = createPinia() const pinia = createPinia()
export function createApp() { export function createApp() {
const app = createSSRApp(App); const app = createSSRApp(App);
app.config.globalProperties.$CLIENT_ID = CLIENT_ID;
app.config.globalProperties.$NETWORK_ENV = NETWORK_ENV;
app.use(pinia) app.use(pinia)
return { return {

View File

@@ -145,14 +145,7 @@
"navigationBarTitleText": "718友晟", "navigationBarTitleText": "718友晟",
"navigationBarBackgroundColor": "#F8F8F8", "navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8", "backgroundColor": "#F8F8F8",
"navigationStyle": "custom", "navigationStyle": "custom"
// #ifdef APP-PLUS
"style": {
"app-plus": {
"background":"#F5F5F5"
}
}
// #endif
}, },
"tabBar": { "tabBar": {
"color": "#919191", "color": "#919191",

View File

@@ -80,7 +80,6 @@ import { v4 as uuidv4 } from 'uuid'
import { getNavBarPaddingTop} from '@/utils/system.js'; import { getNavBarPaddingTop} from '@/utils/system.js';
import { getBindStatus,authDeviceApply,authInputCode } from '@/api/auth.js'; import { getBindStatus,authDeviceApply,authInputCode } from '@/api/auth.js';
import {showToast,showAlert} from '@/utils/message.js' import {showToast,showAlert} from '@/utils/message.js'
import { CLIENT_ID,NETWORK_ENV } from '@/enums/cacheEnums';
import encryptObj from '@/utils/encrypt.js' import encryptObj from '@/utils/encrypt.js'
import { requestAndroidPermissionAsync } from '@/utils/common.js' import { requestAndroidPermissionAsync } from '@/utils/common.js'
@@ -94,8 +93,10 @@ const safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule");
// #endif // #endif
let systemInfo = {}; let systemInfo = {};
let deviceId = ref(undefined); let deviceId = ref(undefined);
let clientId = `${proxy.$CLIENT_ID || 2}`;
let networkEnv = ref(proxy.$NETWORK_ENV);//1-内网 2-外网
onLoad(async(opt) => { onLoad(async(opt) => {
console.log("deviceAuth=>onLoad"); console.log("deviceAuth=>onLoad",clientId,networkEnv);
uni.setStorageSync('page_cache',true); uni.setStorageSync('page_cache',true);
// uni.preloadPage({url: "/pages/login/login"}); // uni.preloadPage({url: "/pages/login/login"});
// uni.preloadPage({url: "/pages/home/home"}); // uni.preloadPage({url: "/pages/home/home"});
@@ -210,14 +211,19 @@ const submitForm = async() => {
// 用户名和密码登录 // 用户名和密码登录
form2.value.validate().then(async param => { form2.value.validate().then(async param => {
btnLoading.value = true; btnLoading.value = true;
deviceId.value = uuidv4(); //1-内网2-外网
let clientId = `${CLIENT_ID || 2}`; if(networkEnv==1){
deviceId.value = form2.value.uniqCode;
}else{
deviceId.value = uuidv4(); //2-外网 生成的设备唯一标识
}
let password = encryptObj.Encrypt(param.username + clientId + "," + param.password); let password = encryptObj.Encrypt(param.username + clientId + "," + param.password);
let params = { let params = {
username:param.username, username:param.username,
password, password,
networkEnv:NETWORK_ENV,//1-内网2-外网 networkEnv:networkEnv.value,//1-内网2-外网
uniqCode:deviceId.value,//生成的设备唯一标识 uniqCode:deviceId.value,
...systemInfo,//设备信息 ...systemInfo,//设备信息
// #ifdef APP-PLUS // #ifdef APP-PLUS
verId:systemInfo.appWgtVersion,//当前版本号 verId:systemInfo.appWgtVersion,//当前版本号
@@ -402,6 +408,7 @@ const handleSubmit=()=>{
border-bottom: 1px solid #E7E7E7; border-bottom: 1px solid #E7E7E7;
} }
:deep(.uni-forms-item__label){ :deep(.uni-forms-item__label){
color:#239FDF; color:#239FDF;
font-weight: bold; font-weight: bold;

View File

@@ -1,71 +1,71 @@
<template> <template>
<view> <view id="test">
<!-- #ifdef h5 -->
<web-view :src="url"></web-view> <web-view :src="url"></web-view>
<!-- #endif -->
</view> </view>
</template> </template>
<script setup> <script setup>
import { ref,onMounted,getCurrentInstance } from 'vue'; import { ref,onMounted,getCurrentInstance } from 'vue';
import { onLoad,onReady } from '@dcloudio/uni-app'; import { onLoad,onReady,onBackPress } from '@dcloudio/uni-app';
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
let windowInfo = ref(null); let windowInfo = ref(null);
let url = ref(''); let url = ref('');
let title = ref(''); let title = ref('');
//将要创建的webview对象
let wv;
onLoad(async(opt) => { onLoad(async(opt) => {
// console.log(opt) console.log(opt)
url.value = opt.url; url.value = opt.url;
title.value = opt.title; title.value = opt.title;
// #ifdef APP-PLUS
titleNViewWebview(url.value,title.value);
// #endif
// uni.getSystemInfo({
// success: (res)=> {
// windowInfo.value = res;
// createWvAndLoadUrl(url.value,title.value);
// }
// });
}) })
onReady(()=>{
setTimeout(()=>{
uni.setNavigationBarTitle({
title:title.value
})
},2000)
})
onMounted(() => {
uni.getSystemInfo({ // 带标题栏控件的Webview窗口
success: (res)=> { let webview = null;
windowInfo.value = res; function titleNViewWebview(url,title) {
createWvAndLoadUrl(url.value); webview = plus.webview.create(url, 'test', {
titleNView: {
backgroundColor: '#307AF5',
titleText: title,
titleColor: '#ffffff',
autoBackButton: true,
backgroundImage:'./../../static/images/bg-Blue-header.png',
buttons:[{onclick:clickButton}]
} }
}); });
}) webview.addEventListener('close', function(){
webview=null;
/*创建web-view并加载url*/ });
const createWvAndLoadUrl=(url)=>{ webview.addEventListener('titleUpdate', function(){
// #ifdef APP-PLUS webview.show();
wv = plus.webview.create(url,"webview",{ });
// plusrequire:"none", //禁止远程网页使用plus的API有些使用mui制作的网页可能会监听plus.key造成关闭页面混乱可以通过这种方式禁止 webview.addEventListener('loading', () => {
top: 0,//this.windowInfo.statusBarHeight + 126, //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的可以继续降低TOP值
scalable: true,
height: windowInfo.value.windowHeight - windowInfo.value.statusBarHeight //- 126
})
wv.addEventListener('loading', () => {
plus.nativeUI.showWaiting("loading...",{ plus.nativeUI.showWaiting("loading...",{
width:'110px', width:'110px',
padding:'10px' padding:'10px'
}) })
}, false); }, false);
//plus.nativeUI.showWaiting() //plus.nativeUI.showWaiting()
wv.addEventListener('loaded', () => { webview.addEventListener('loaded', () => {
plus.nativeUI.closeWaiting(); plus.nativeUI.closeWaiting();
}, false); }, false);
}
//wv.loadURL(url) // 左侧按钮返回
let currentWebview = proxy.$scope.$getAppWebview(); function clickButton(){
currentWebview = wv; // plus.nativeUI.alert('clicked!');
// console.log(wv) webview=null;
// setTimeout(()=> {
// console.log(wv.getStyle())
// }, 1000);
// #endif
} }
</script> </script>

View File

@@ -73,7 +73,7 @@
</template> </template>
<script setup> <script setup>
import { ref,onMounted } from 'vue'; import { ref,onMounted,getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app'; import { onLoad } from '@dcloudio/uni-app';
import customTabs from '@/components/customTabs.vue'; import customTabs from '@/components/customTabs.vue';
import {isPhoneNumber} from '@/utils/validate'; import {isPhoneNumber} from '@/utils/validate';
@@ -83,14 +83,17 @@ import { AGREEWELCOME_KEY } from '@/enums/cacheEnums';
import { getNavBarPaddingTop} from '@/utils/system.js' import { getNavBarPaddingTop} from '@/utils/system.js'
import { useUserStore } from '@/stores/user'; import { useUserStore } from '@/stores/user';
import encryptObj from '@/utils/encrypt.js' import encryptObj from '@/utils/encrypt.js'
import { CLIENT_ID } from '@/enums/cacheEnums';
import {showAlert} from '@/utils/message.js' import {showAlert} from '@/utils/message.js'
// #ifdef APP-PLUS // #ifdef APP-PLUS
// 获取 存储手机的module // 获取 存储手机的module
const safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule"); const safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule");
// #endif // #endif
const userStore = useUserStore()
const { proxy } = getCurrentInstance();
const userStore = useUserStore();
let clientId = `${proxy.$CLIENT_ID || 2}`;
let networkEnv = ref(proxy.$NETWORK_ENV);//1-内网 2-外网
onLoad(async(opt) => { onLoad(async(opt) => {
uni.setStorageSync('page_cache',true); uni.setStorageSync('page_cache',true);
}) })
@@ -248,13 +251,13 @@ const submitForm = () => {
// 用户名和密码登录 // 用户名和密码登录
form2.value.validate().then(async param => { form2.value.validate().then(async param => {
param.loginType = activeTab.value; param.loginType = activeTab.value;
let clientId = `${CLIENT_ID || "2"}`;
param.clientId = clientId; param.clientId = clientId;
let password = encryptObj.Encrypt(param.username + clientId + "," + param.password); let password = encryptObj.Encrypt(param.username + clientId + "," + param.password);
param.password = password; param.password = password;
param.runEnv = networkEnv.value;
// #ifdef H5 // #ifdef H5
param.uniqCode = '7f47cfb4-59e2-4cb9-ac46-9da5e23c4de2';//uni.getStorageSync('app_device_id');//先从缓存取之后处理 '7f47cfb4-59e2-4cb9-ac46-9da5e23c4de2'// param.uniqCode = 'e5687e80-526f-4522-ba7d-41d5db197a15';//h5测试用
let res = await login(param); let res = await login(param);
userStore.login(res); userStore.login(res);
uni.switchTab({ url: '/pages/home/home' }) uni.switchTab({ url: '/pages/home/home' })