登录页面显示设备二维码

This commit is contained in:
2025-10-21 09:34:30 +08:00
parent 5a5385ea31
commit f4e7cab2d0
5 changed files with 75 additions and 43 deletions
+14 -8
View File
@@ -41,14 +41,6 @@
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:exported="true" android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape"/>
<!-- android:theme="@style/Theme.Inbound"-->
<activity
android:name=".InitActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/Theme.Inbound"> android:theme="@style/Theme.Inbound">
<intent-filter> <intent-filter>
@@ -57,6 +49,20 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- <activity-->
<!-- android:name=".InitActivity"-->
<!-- android:configChanges="orientation|screenSize"-->
<!-- android:exported="true"-->
<!-- android:label="@string/app_name"-->
<!-- android:screenOrientation="landscape"-->
<!-- android:theme="@style/Theme.Inbound">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
</application> </application>
</manifest> </manifest>
@@ -18,13 +18,13 @@ import javax.inject.Singleton
@Module @Module
@InstallIn(SingletonComponent::class) @InstallIn(SingletonComponent::class)
object NetworkModule { object NetworkModule {
private const val DEVICE_BASE_URL = "http://device.shuziweidao.com:8889/" // private const val DEVICE_BASE_URL = "http://device.shuziweidao.com:8889/"
// private const val BASE_URL = "https://127.0.0.1" // private const val BASE_URL = "https://127.0.0.1"
private const val BASE_URL = "https://yyjk.shuziweidao.com/gateway/" private const val BASE_URL = "https://yyjk.shuziweidao.com/gateway/"
// private const val BASE_URL = "http://192.168.1.237:9002/" // private const val BASE_URL = "http://192.168.1.237:9002/"
// private const val BASE_URL = "https://vip.shuziweidao.com/gateway/" // private const val BASE_URL = "https://vip.shuziweidao.com/gateway/"
private const val TIME_OUT = 30L // 超时时间(秒) private const val TIME_OUT = 30L // 超时时间(秒)
@Provides @Provides
@@ -52,7 +52,8 @@ object NetworkModule {
@Singleton @Singleton
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit { fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
return Retrofit.Builder() return Retrofit.Builder()
.baseUrl(DEVICE_BASE_URL) // .baseUrl(DEVICE_BASE_URL)
.baseUrl(BASE_URL)
.client(okHttpClient) .client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build() .build()
@@ -1,5 +1,6 @@
package com.sw.inbound.network.interceptor package com.sw.inbound.network.interceptor
import com.sw.inbound.GlobalData
import com.sw.inbound.GlobalKey import com.sw.inbound.GlobalKey
import com.sw.inbound.utils.ContextUtils import com.sw.inbound.utils.ContextUtils
import com.sw.inbound.utils.SPUtil import com.sw.inbound.utils.SPUtil
@@ -15,6 +16,7 @@ class RequestInterceptor : Interceptor {
val requestBuilder = originalRequest.newBuilder() val requestBuilder = originalRequest.newBuilder()
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("Accept", "application/json") .header("Accept", "application/json")
.header("deviceId", GlobalData.deviceId)
// .header("Authorization", "Bearer ${getToken()}") // .header("Authorization", "Bearer ${getToken()}")
// .header("x-access-token", getToken()) // .header("x-access-token", getToken())
@@ -1,12 +1,16 @@
package com.sw.inbound.ui.page package com.sw.inbound.ui.page
import androidx.compose.foundation.Image
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
@@ -22,6 +26,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
@@ -42,6 +47,7 @@ import com.sw.inbound.ext.withSize
import com.sw.inbound.ui.Screen import com.sw.inbound.ui.Screen
import com.sw.inbound.ui.theme.AppTypography import com.sw.inbound.ui.theme.AppTypography
import com.sw.inbound.ui.weight.CustomButton import com.sw.inbound.ui.weight.CustomButton
import com.sw.inbound.utils.QRCodeUtil
import com.sw.inbound.utils.SPUtil import com.sw.inbound.utils.SPUtil
import com.sw.inbound.utils.ToastUtils import com.sw.inbound.utils.ToastUtils
import com.sw.inbound.viewmodel.UserViewModel import com.sw.inbound.viewmodel.UserViewModel
@@ -81,6 +87,14 @@ fun LoginScreen(
// } // }
} }
val qrCodeBmp by lazy {
QRCodeUtil.generateQRCode(
content = GlobalData.deviceId,
size = 150
)
}
Box(contentAlignment = Alignment.BottomStart) {
Column( Column(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
@@ -111,13 +125,21 @@ fun LoginScreen(
return@CustomButton return@CustomButton
} }
viewModel.login(username, password) viewModel.login(username, password)
// viewModel.test() // viewModel.test()
}, },
borderColor = colorResource(R.color.blue), borderColor = colorResource(R.color.blue),
textColor = colorResource(R.color.white), textColor = colorResource(R.color.white),
fontSize = 36.sp fontSize = 36.sp
) )
} }
Image(
bitmap = qrCodeBmp!!.asImageBitmap(),
contentDescription = "",
modifier = Modifier
.padding(start = 10.dp, bottom = 10.dp)
.size(80.dp, 80.dp)
)
}
} }
@@ -172,4 +194,5 @@ private fun UserInputView(
}, },
singleLine = true // 确保单行输入(避免换行导致高度变化) singleLine = true // 确保单行输入(避免换行导致高度变化)
) )
} }
+1 -1
View File
@@ -2,6 +2,6 @@
<resources> <resources>
<style name="Theme.Inbound" parent="android:Theme.Material.Light.NoActionBar" > <style name="Theme.Inbound" parent="android:Theme.Material.Light.NoActionBar" >
<item name="android:windowBackground">@drawable/bg_splash</item> <!-- <item name="android:windowBackground">@drawable/bg_splash</item>-->
</style> </style>
</resources> </resources>