feat: auto login in dev
This commit is contained in:
@@ -51,6 +51,14 @@ class HomeFragment : Fragment() {
|
||||
|
||||
private val TAG: String = HomeFragment::class.java.simpleName
|
||||
|
||||
/**
|
||||
* ========== 开发调试开关 ==========
|
||||
* TODO: 正式发布前务必设置为 false
|
||||
*/
|
||||
companion object {
|
||||
private const val DEV_AUTO_SELECT_INT_EXP = true // 自动选择国际出港开关
|
||||
}
|
||||
|
||||
private var rvLeft: RecyclerView by Delegates.notNull()
|
||||
private var rvRight: RecyclerView by Delegates.notNull()
|
||||
|
||||
@@ -70,6 +78,10 @@ class HomeFragment : Fragment() {
|
||||
val leftMenuList = initLeftMenuData()
|
||||
rvLeft.adapter = HomeLeftAdapt(leftMenuList)
|
||||
rvRight.adapter = HomeRightAdapt(getRightMenu4Id(leftMenuList.first().id))
|
||||
|
||||
// ========== 开发调试:自动选择"国际出港"菜单 ==========
|
||||
// TODO: 正式发布前删除此行
|
||||
autoSelectIntExpForDev()
|
||||
}
|
||||
|
||||
/////////// 左边的list循环
|
||||
@@ -155,6 +167,31 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
override fun getItemCount() = leftMenuList.size
|
||||
|
||||
/**
|
||||
* 开发调试:模拟点击菜单项
|
||||
* TODO: 正式发布前删除此方法
|
||||
*/
|
||||
fun simulateClick(position: Int) {
|
||||
if (position < 0 || position >= leftMenuList.size) return
|
||||
|
||||
val leftMenuTemp = leftMenuList[position]
|
||||
|
||||
// 跳过特殊菜单(航班查询、货物查询)
|
||||
if (Constant.AuthName.Flight == leftMenuTemp.id ||
|
||||
Constant.AuthName.CargoStatus == leftMenuTemp.id) {
|
||||
return
|
||||
}
|
||||
|
||||
// 更新选中位置
|
||||
mPosition = position
|
||||
|
||||
// 刷新右侧菜单
|
||||
refreshRight(leftMenuList[mPosition].id)
|
||||
|
||||
// 更新菜单状态
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
inner class LeftMenu(val id: String, val img: Int, val text: String)
|
||||
@@ -906,4 +943,26 @@ class HomeFragment : Fragment() {
|
||||
private fun refreshRight(id: String) {
|
||||
(rvRight.adapter as? HomeRightAdapt)?.refresh(getRightMenu4Id(id))
|
||||
}
|
||||
|
||||
/**
|
||||
* 开发调试:自动选择"国际出港"菜单
|
||||
* TODO: 正式发布前删除此方法或将 DEV_AUTO_SELECT_INT_EXP 设置为 false
|
||||
*/
|
||||
private fun autoSelectIntExpForDev() {
|
||||
if (!DEV_AUTO_SELECT_INT_EXP) return
|
||||
|
||||
// 延迟执行,确保适配器已初始化
|
||||
rvLeft.postDelayed({
|
||||
val leftAdapter = rvLeft.adapter as? HomeLeftAdapt ?: return@postDelayed
|
||||
|
||||
// 查找"国际出港"在左侧菜单的位置
|
||||
val leftMenuList = initLeftMenuData()
|
||||
val intExpIndex = leftMenuList.indexOfFirst { it.id == Constant.AuthName.IntExp }
|
||||
|
||||
if (intExpIndex >= 0) {
|
||||
// 模拟点击左侧"国际出港"菜单项
|
||||
leftAdapter.simulateClick(intExpIndex)
|
||||
}
|
||||
}, 300) // 延迟300ms确保适配器已绑定数据
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,11 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import me.jessyan.autosize.internal.CustomAdapt
|
||||
|
||||
/**
|
||||
* ========== 开发调试开关 ==========
|
||||
* TODO: 正式发布前务必设置为 false
|
||||
*/
|
||||
private const val DEV_AUTO_LOGIN = true // 自动登录开关
|
||||
|
||||
@Route(path = ARouterConstants.ACTIVITY_URL_LOGIN)
|
||||
class LoginActivity : BaseActivity(),
|
||||
@@ -100,6 +105,15 @@ class LoginActivity : BaseActivity(),
|
||||
spinner.setSelection(index)
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 开发调试:角色信息获取成功后自动登录 ==========
|
||||
// TODO: 正式发布前删除此代码块
|
||||
if (DEV_AUTO_LOGIN && user.text.toString() == "ADMIN") {
|
||||
loginButton.postDelayed({
|
||||
val encodedPassword = "$2a$10$02ZpVb/bymrybmPE2Mu2C.O.JcMXTB..gkssaNn8q2EC.kUAfJP0S"
|
||||
viewModel.login(user.text.toString(), encodedPassword)
|
||||
}, 200) // 短暂延迟确保spinner更新完成
|
||||
}
|
||||
}
|
||||
bindOnSelected(spinner, object : IOnSpinnerSelected {
|
||||
override fun onSelected(position: Int) {
|
||||
@@ -183,6 +197,28 @@ class LoginActivity : BaseActivity(),
|
||||
|
||||
bindAdapter(spinner, viewModel.roleList, "请选择角色", R.layout.item_spinner_list_18sp)
|
||||
setEnable(spinner, false)
|
||||
|
||||
// ========== 开发调试:自动登录 ==========
|
||||
// TODO: 正式发布前删除此行
|
||||
autoLoginForDev()
|
||||
}
|
||||
|
||||
/**
|
||||
* 开发调试:自动登录
|
||||
* TODO: 正式发布前删除此方法或将 DEV_AUTO_LOGIN 设置为 false
|
||||
*/
|
||||
private fun autoLoginForDev() {
|
||||
if (!DEV_AUTO_LOGIN) return
|
||||
|
||||
// 延迟执行,确保UI初始化完成
|
||||
loginButton.postDelayed({
|
||||
// 设置用户名
|
||||
user.setText("ADMIN")
|
||||
|
||||
// 手动触发获取角色信息
|
||||
// 角色信息获取成功后会在userRoleBean.observe中自动执行登录
|
||||
viewModel.getUserRole("ADMIN")
|
||||
}, 500) // 延迟500ms确保ViewModel已初始化
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class GjcExportLoad {
|
||||
* 获取格式化的运单号(prefix + no)
|
||||
*/
|
||||
fun getFullWaybillNo(): String {
|
||||
return if (prefix.isNotEmpty()) "$prefix-$no" else no
|
||||
return if (prefix.isNotEmpty()) "$prefix$no" else no
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="0.8"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- 第一行:运单号、状态、代理、件数、重量 -->
|
||||
@@ -153,7 +153,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="0.8"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- 第一行:运单号、特码、状态、件数 -->
|
||||
<!-- 第一行:运单号、状态、件数、重量 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -52,7 +52,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -74,36 +74,11 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 特码 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.5"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="特码:"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp"
|
||||
completeSpace="@{3}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{bean.spCode}"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 状态 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.5"
|
||||
android:layout_weight="0.8"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -113,7 +88,7 @@
|
||||
android:text="状态:"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp"
|
||||
completeSpace="@{3}" />
|
||||
completeSpace="@{5}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -128,7 +103,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="0.8"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -138,7 +113,7 @@
|
||||
android:text="件数:"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp"
|
||||
completeSpace="@{3}" />
|
||||
completeSpace="@{4}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -149,21 +124,11 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第二行:重量、品名(中)、航班日期、航班号 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 重量 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:layout_weight="1.2"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -178,24 +143,34 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{String.valueOf((int)bean.weight)}"
|
||||
android:text="@{String.valueOf(bean.weight)}"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 品名(中) -->
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第二行:特码、航班日期、航班号、品名(中) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 特码 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.5"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="品名(中):"
|
||||
android:text="特码:"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp"
|
||||
completeSpace="@{5}" />
|
||||
@@ -203,9 +178,7 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@{bean.goods}"
|
||||
android:text="@{bean.spCode}"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp" />
|
||||
|
||||
@@ -215,7 +188,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.5"
|
||||
android:layout_weight="0.8"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -240,7 +213,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="0.8"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -261,6 +234,33 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 品名(中) -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.2"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="品名(中):"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp"
|
||||
completeSpace="@{5}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@{bean.goods}"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user