You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.0 KiB
111 lines
3.0 KiB
package com.gyf.csams.uikit
|
|
|
|
import androidx.annotation.StringRes
|
|
import androidx.compose.foundation.border
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.ExperimentalComposeApi
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.res.stringResource
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.gyf.lib.ScrollListW
|
|
import com.gyf.lib.uikit.BodyS
|
|
import com.gyf.lib.uikit.MainColumnFrame
|
|
|
|
/**
|
|
* 表格
|
|
*
|
|
* @param callback
|
|
*/
|
|
@ExperimentalComposeApi
|
|
@Composable
|
|
fun <A> TestTable(
|
|
clazz: Class<out ScrollListW<A>>,
|
|
@StringRes title: Int,
|
|
callback: @Composable (vo: A) -> Unit
|
|
) {
|
|
BodyS {
|
|
MainColumnFrame(background = { /*TODO*/ }) {
|
|
val listState = rememberLazyListState()
|
|
val model = viewModel(modelClass = clazz)
|
|
val data by model.data.observeAsState()
|
|
Row(
|
|
horizontalArrangement = Arrangement.Center,
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(10.dp)
|
|
) {
|
|
Text(
|
|
text = stringResource(id = title),
|
|
style = MaterialTheme.typography.h4
|
|
)
|
|
}
|
|
LazyColumn(state = listState) {
|
|
data?.forEach {
|
|
item {
|
|
callback(vo = it)
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 表格行
|
|
*
|
|
* @param modifier
|
|
* @param key
|
|
* @param value
|
|
* @param content
|
|
*/
|
|
@Composable
|
|
fun RowItem(
|
|
modifier: Modifier = Modifier,
|
|
@StringRes key: Int,
|
|
value: String? = null,
|
|
content: (@Composable () -> Unit)? = null
|
|
) {
|
|
Row(
|
|
modifier = modifier
|
|
.fillMaxWidth()
|
|
.border(width = 1.dp, color = Color.Black)
|
|
) {
|
|
Cell(
|
|
modifier = Modifier.weight(0.5F),
|
|
value = stringResource(id = key)
|
|
)
|
|
Cell(modifier = Modifier.weight(0.5F), value = value, content = content)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun Cell(
|
|
modifier: Modifier = Modifier,
|
|
value: String? = null,
|
|
content: (@Composable () -> Unit)? = null
|
|
) {
|
|
Box(
|
|
modifier = modifier
|
|
.fillMaxSize()
|
|
.border(width = 1.dp, color = MaterialTheme.colors.onBackground),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
if (content != null) content() else Text(
|
|
text = value ?: throw IllegalArgumentException(
|
|
"参数错误"
|
|
)
|
|
)
|
|
}
|
|
} |