|
|
@@ -1,5 +1,6 @@
|
|
|
package com.iscs.bozzys.ui.pages.compose
|
|
|
|
|
|
+import android.util.Log
|
|
|
import androidx.compose.foundation.border
|
|
|
import androidx.compose.foundation.clickable
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
@@ -25,6 +26,7 @@ import androidx.compose.material3.LocalTextStyle
|
|
|
import androidx.compose.material3.RadioButton
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
@@ -48,6 +50,8 @@ import com.iscs.bozzys.R
|
|
|
import com.iscs.bozzys.api.FormField
|
|
|
import com.iscs.bozzys.api.FormOption
|
|
|
import com.iscs.bozzys.ui.theme.Main
|
|
|
+import com.iscs.bozzys.ui.theme.Text
|
|
|
+import com.iscs.bozzys.utils.DateUtil.dateToTimestamp
|
|
|
import com.iscs.bozzys.utils.DateUtil.format
|
|
|
import com.loper7.date_time_picker.DateTimeConfig
|
|
|
import com.loper7.date_time_picker.dialog.CardDatePickerDialog
|
|
|
@@ -61,7 +65,15 @@ import kotlinx.serialization.json.Json
|
|
|
* @param onValueChange 表单内容发生变化
|
|
|
*/
|
|
|
@Composable
|
|
|
-fun FormInput(label: String, value: String, onValueChange: (String) -> Unit, placeholder: String = "", required: Boolean = false) {
|
|
|
+fun FormInput(
|
|
|
+ label: String,
|
|
|
+ value: List<String>,
|
|
|
+ onValueChange: (List<String>) -> Unit,
|
|
|
+ placeholder: List<String> = listOf(),
|
|
|
+ required: Boolean = false,
|
|
|
+ enable: Boolean = true,
|
|
|
+) {
|
|
|
+ var text by remember { mutableStateOf(value.getOrNull(0) ?: "") }
|
|
|
Column(
|
|
|
Modifier
|
|
|
.fillMaxWidth()
|
|
|
@@ -72,13 +84,22 @@ fun FormInput(label: String, value: String, onValueChange: (String) -> Unit, pla
|
|
|
.fillMaxWidth()
|
|
|
.height(40.dp), verticalAlignment = Alignment.CenterVertically
|
|
|
) {
|
|
|
- Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
|
|
- if (required) Text("*", fontSize = 14.sp, color = Color(0xFFFF4D4F), modifier = Modifier.padding(start = 3.dp))
|
|
|
+ Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ if (required) Text(
|
|
|
+ "*",
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Color(0xFFFF4D4F).copy(alpha = if (enable) 1f else 0.6f),
|
|
|
+ modifier = Modifier.padding(start = 3.dp)
|
|
|
+ )
|
|
|
}
|
|
|
BasicTextField(
|
|
|
- value,
|
|
|
- onValueChange = onValueChange,
|
|
|
- Modifier
|
|
|
+ text,
|
|
|
+ onValueChange = {
|
|
|
+ text = it
|
|
|
+ onValueChange(listOf(text))
|
|
|
+ },
|
|
|
+ enabled = enable,
|
|
|
+ modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
|
.height(46.dp)
|
|
|
.border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
@@ -87,10 +108,76 @@ fun FormInput(label: String, value: String, onValueChange: (String) -> Unit, pla
|
|
|
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp, lineHeight = 18.sp),
|
|
|
decorationBox = { innerTextField ->
|
|
|
Box(contentAlignment = Alignment.CenterStart) {
|
|
|
+ innerTextField()
|
|
|
+ if (text.isEmpty()) {
|
|
|
+ val ph = placeholder.getOrNull(0) ?: "请输入$label"
|
|
|
+ Text(ph, color = Color(0xFF9CA3AF), fontSize = 14.sp, lineHeight = 18.sp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cursorBrush = SolidColor(Main),
|
|
|
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 表单多行文本输入
|
|
|
+ *
|
|
|
+ * @param label 标题
|
|
|
+ * @param value 输入的内容
|
|
|
+ * @param onValueChange 输入内容发生变化
|
|
|
+ * @param placeholder 占位内容
|
|
|
+ * @param enable 是否使能
|
|
|
+ */
|
|
|
+@Composable
|
|
|
+fun FormTextarea(
|
|
|
+ label: String,
|
|
|
+ value: List<String>,
|
|
|
+ onValueChange: (List<String>) -> Unit,
|
|
|
+ placeholder: List<String> = listOf(""),
|
|
|
+ required: Boolean = false,
|
|
|
+ enable: Boolean = true,
|
|
|
+) {
|
|
|
+ var text by remember { mutableStateOf(value.getOrNull(0) ?: "") }
|
|
|
+ Column(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .heightIn(max = 160.dp)
|
|
|
+ ) {
|
|
|
+ Row(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(40.dp), verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ if (required) Text(
|
|
|
+ "*",
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Color(0xFFFF4D4F).copy(alpha = if (enable) 1f else 0.6f),
|
|
|
+ modifier = Modifier.padding(start = 3.dp)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ BasicTextField(
|
|
|
+ text,
|
|
|
+ onValueChange = {
|
|
|
+ text = it
|
|
|
+ onValueChange(listOf(it))
|
|
|
+ },
|
|
|
+ enabled = enable,
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .heightIn(min = 120.dp)
|
|
|
+ .border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
+ .padding(10.dp)
|
|
|
+ .verticalScroll(rememberScrollState()),
|
|
|
+ textStyle = LocalTextStyle.current.copy(fontSize = 14.sp, lineHeight = 18.sp),
|
|
|
+ decorationBox = { innerTextField ->
|
|
|
+ Box(contentAlignment = Alignment.TopStart) {
|
|
|
innerTextField()
|
|
|
if (value.isEmpty()) {
|
|
|
- val text = placeholder.ifEmpty { "请输入$label" }
|
|
|
- Text(text, color = Color(0xFF9CA3AF), fontSize = 14.sp, lineHeight = 18.sp)
|
|
|
+ val ph = placeholder.getOrNull(0) ?: "请输入$label"
|
|
|
+ Text(ph, color = Color(0xFF9CA3AF), fontSize = 14.sp, lineHeight = 18.sp)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
@@ -100,6 +187,7 @@ fun FormInput(label: String, value: String, onValueChange: (String) -> Unit, pla
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 表单选择器
|
|
|
*
|
|
|
@@ -109,11 +197,20 @@ fun FormInput(label: String, value: String, onValueChange: (String) -> Unit, pla
|
|
|
* @param onSelectChange 选择变化监听
|
|
|
*/
|
|
|
@Composable
|
|
|
-fun FormSelect(label: String, value: String, options: List<FormOption>, onSelectChange: (FormOption) -> Unit, required: Boolean = false) {
|
|
|
+fun FormSelect(
|
|
|
+ label: String,
|
|
|
+ value: List<String>,
|
|
|
+ options: List<FormOption>,
|
|
|
+ onSelectChange: (List<String>) -> Unit,
|
|
|
+ placeholder: List<String> = listOf(""),
|
|
|
+ required: Boolean = false,
|
|
|
+ enable: Boolean = true,
|
|
|
+) {
|
|
|
var expanded by remember { mutableStateOf(false) }
|
|
|
var width by remember { mutableStateOf(0) }
|
|
|
val density = LocalDensity.current
|
|
|
- val find = options.find { it.value == value }
|
|
|
+ // 当前表单中的状态
|
|
|
+ var opt by remember { mutableStateOf(options.find { it.value == value.getOrNull(0) }) }
|
|
|
Column(
|
|
|
Modifier
|
|
|
.fillMaxWidth()
|
|
|
@@ -125,8 +222,13 @@ fun FormSelect(label: String, value: String, options: List<FormOption>, onSelect
|
|
|
.fillMaxWidth()
|
|
|
.height(40.dp), verticalAlignment = Alignment.CenterVertically
|
|
|
) {
|
|
|
- Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
|
|
- if (required) Text("*", fontSize = 14.sp, color = Color(0xFFFF4D4F), modifier = Modifier.padding(start = 3.dp))
|
|
|
+ Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ if (required) Text(
|
|
|
+ "*",
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Color(0xFFFF4D4F).copy(alpha = if (enable) 1f else 0.6f),
|
|
|
+ modifier = Modifier.padding(start = 3.dp)
|
|
|
+ )
|
|
|
}
|
|
|
Row(
|
|
|
Modifier
|
|
|
@@ -134,21 +236,21 @@ fun FormSelect(label: String, value: String, options: List<FormOption>, onSelect
|
|
|
.height(46.dp)
|
|
|
.border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
.clip(RoundedCornerShape(6.dp))
|
|
|
- .clickable(onClick = { expanded = true })
|
|
|
+ .clickable(onClick = { expanded = true }, enabled = enable)
|
|
|
.padding(horizontal = 10.dp),
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
) {
|
|
|
Text(
|
|
|
- find?.label ?: "请选择$label",
|
|
|
- color = Color.Black,
|
|
|
+ opt?.label ?: "请选择$label",
|
|
|
+ color = Text.copy(alpha = if (enable) 1f else 0.6f),
|
|
|
fontSize = 14.sp,
|
|
|
lineHeight = 18.sp,
|
|
|
- modifier = Modifier.weight(1f)
|
|
|
+ modifier = Modifier.weight(1f),
|
|
|
)
|
|
|
Icon(
|
|
|
painter = painterResource(R.drawable.back), contentDescription = "", modifier = Modifier
|
|
|
.rotate(if (expanded) -90f else 180f)
|
|
|
- .size(12.dp), tint = Color.Black
|
|
|
+ .size(12.dp), tint = Text.copy(alpha = if (enable) 1f else 0.6f)
|
|
|
)
|
|
|
}
|
|
|
val widthDp = with(density) { width.toDp() }
|
|
|
@@ -167,7 +269,8 @@ fun FormSelect(label: String, value: String, options: List<FormOption>, onSelect
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
text = { Text(option.label) },
|
|
|
onClick = {
|
|
|
- onSelectChange(option)
|
|
|
+ opt = option
|
|
|
+ onSelectChange(listOf(option.value))
|
|
|
expanded = false
|
|
|
}
|
|
|
)
|
|
|
@@ -177,54 +280,6 @@ fun FormSelect(label: String, value: String, options: List<FormOption>, onSelect
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * 表单多行文本输入
|
|
|
- *
|
|
|
- * @param label 标题
|
|
|
- * @param value 输入的内容
|
|
|
- * @param onValueChange 输入内容发生变化
|
|
|
- * @param placeholder 占位内容
|
|
|
- */
|
|
|
-@Composable
|
|
|
-fun FormTextarea(label: String, value: String, onValueChange: (String) -> Unit, placeholder: String = "", required: Boolean = false) {
|
|
|
- Column(
|
|
|
- Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .heightIn(max = 160.dp)
|
|
|
- ) {
|
|
|
- Row(
|
|
|
- Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .height(40.dp), verticalAlignment = Alignment.CenterVertically
|
|
|
- ) {
|
|
|
- Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
|
|
- if (required) Text("*", fontSize = 14.sp, color = Color(0xFFFF4D4F), modifier = Modifier.padding(start = 3.dp))
|
|
|
- }
|
|
|
- BasicTextField(
|
|
|
- value,
|
|
|
- onValueChange = onValueChange,
|
|
|
- Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .heightIn(min = 120.dp)
|
|
|
- .border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
- .padding(10.dp)
|
|
|
- .verticalScroll(rememberScrollState()),
|
|
|
- textStyle = LocalTextStyle.current.copy(fontSize = 14.sp, lineHeight = 18.sp),
|
|
|
- decorationBox = { innerTextField ->
|
|
|
- Box(contentAlignment = Alignment.TopStart) {
|
|
|
- innerTextField()
|
|
|
- if (value.isEmpty()) {
|
|
|
- val text = placeholder.ifEmpty { "请输入$label" }
|
|
|
- Text(text, color = Color(0xFF9CA3AF), fontSize = 14.sp, lineHeight = 18.sp)
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- cursorBrush = SolidColor(Main),
|
|
|
- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
|
|
|
- )
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* 表单单选组件
|
|
|
*
|
|
|
@@ -237,11 +292,13 @@ fun FormTextarea(label: String, value: String, onValueChange: (String) -> Unit,
|
|
|
@Composable
|
|
|
fun FormRadio(
|
|
|
label: String,
|
|
|
- value: String,
|
|
|
+ value: List<String>,
|
|
|
options: List<FormOption>,
|
|
|
- onSelectChange: (FormOption) -> Unit,
|
|
|
- required: Boolean = false
|
|
|
+ onSelectChange: (List<String>) -> Unit,
|
|
|
+ required: Boolean = false,
|
|
|
+ enable: Boolean = true,
|
|
|
) {
|
|
|
+ var text by remember { mutableStateOf(value.getOrNull(0) ?: "") }
|
|
|
Column(
|
|
|
Modifier
|
|
|
.fillMaxWidth()
|
|
|
@@ -252,8 +309,13 @@ fun FormRadio(
|
|
|
.fillMaxWidth()
|
|
|
.height(40.dp), verticalAlignment = Alignment.CenterVertically
|
|
|
) {
|
|
|
- Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
|
|
- if (required) Text("*", fontSize = 14.sp, color = Color(0xFFFF4D4F), modifier = Modifier.padding(start = 3.dp))
|
|
|
+ Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ if (required) Text(
|
|
|
+ "*",
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Color(0xFFFF4D4F).copy(alpha = if (enable) 1f else 0.6f),
|
|
|
+ modifier = Modifier.padding(start = 3.dp)
|
|
|
+ )
|
|
|
}
|
|
|
FlowRow(
|
|
|
Modifier
|
|
|
@@ -264,12 +326,20 @@ fun FormRadio(
|
|
|
Row(
|
|
|
modifier = Modifier
|
|
|
.clip(RoundedCornerShape(12.dp))
|
|
|
- .clickable { onSelectChange(item) }
|
|
|
+ .clickable(onClick = {
|
|
|
+ text = item.value
|
|
|
+ onSelectChange(listOf(item.value))
|
|
|
+ }, enabled = enable)
|
|
|
.padding(horizontal = 10.dp, vertical = 5.dp),
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
) {
|
|
|
- RadioButton(selected = value == item.value, onClick = null, modifier = Modifier.size(14.dp))
|
|
|
- Text(text = item.label, fontSize = 15.sp, modifier = Modifier.padding(start = 10.dp))
|
|
|
+ RadioButton(selected = text == item.value, onClick = null, modifier = Modifier.size(14.dp), enabled = enable)
|
|
|
+ Text(
|
|
|
+ text = item.label,
|
|
|
+ fontSize = 15.sp,
|
|
|
+ modifier = Modifier.padding(start = 10.dp),
|
|
|
+ color = Text.copy(alpha = if (enable) 1f else 0.6f)
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -277,15 +347,15 @@ fun FormRadio(
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 表单单选组件
|
|
|
+ * 表单日期时间选择组件
|
|
|
*
|
|
|
* @param label 标题
|
|
|
* @param value 当前选中
|
|
|
* @param onSelectChange 当前选中
|
|
|
*/
|
|
|
@Composable
|
|
|
-fun FormDateSelect(label: String, value: Long, onSelectChange: (Long) -> Unit, required: Boolean = false) {
|
|
|
- val date = if (value <= 0) System.currentTimeMillis() else value
|
|
|
+fun FormDateSelect(label: String, value: List<String>, onSelectChange: (List<String>) -> Unit, required: Boolean = false, enable: Boolean = true) {
|
|
|
+ var date by remember { mutableStateOf((value.getOrNull(0) ?: "").dateToTimestamp("yyyy/MM/dd HH:mm")) }
|
|
|
val picker = CardDatePickerDialog.builder(LocalContext.current)
|
|
|
.setTitle("请选择日期")
|
|
|
.setDefaultTime(date)
|
|
|
@@ -294,8 +364,9 @@ fun FormDateSelect(label: String, value: Long, onSelectChange: (Long) -> Unit, r
|
|
|
.showBackNow(false)
|
|
|
.showFocusDateInfo(false)
|
|
|
.showDateLabel(false)
|
|
|
- .setOnChoose { millisecond ->
|
|
|
- onSelectChange(millisecond)
|
|
|
+ .setOnChoose { timestamp ->
|
|
|
+ date = timestamp
|
|
|
+ onSelectChange(listOf(timestamp.toString()))
|
|
|
}.build()
|
|
|
|
|
|
Column(
|
|
|
@@ -309,8 +380,13 @@ fun FormDateSelect(label: String, value: Long, onSelectChange: (Long) -> Unit, r
|
|
|
.height(40.dp),
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
) {
|
|
|
- Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
|
|
- if (required) Text("*", fontSize = 14.sp, color = Color(0xFFFF4D4F), modifier = Modifier.padding(start = 3.dp))
|
|
|
+ Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ if (required) Text(
|
|
|
+ "*",
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Color(0xFFFF4D4F).copy(alpha = if (enable) 1f else 0.6f),
|
|
|
+ modifier = Modifier.padding(start = 3.dp)
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
Text(
|
|
|
@@ -320,20 +396,142 @@ fun FormDateSelect(label: String, value: Long, onSelectChange: (Long) -> Unit, r
|
|
|
.height(46.dp)
|
|
|
.border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
.clip(RoundedCornerShape(6.dp))
|
|
|
- .clickable(onClick = {
|
|
|
- picker.show()
|
|
|
- })
|
|
|
+ .clickable(onClick = { picker.show() }, enabled = enable)
|
|
|
.padding(10.dp),
|
|
|
fontSize = 14.sp,
|
|
|
- lineHeight = 26.sp
|
|
|
+ lineHeight = 26.sp,
|
|
|
+ color = Text.copy(alpha = if (enable) 1f else 0.6f)
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 表单日期范围选择组件
|
|
|
+ *
|
|
|
+ * @param label 标题
|
|
|
+ * @param value 当前选中
|
|
|
+ * @param onSelectChange 当前选中
|
|
|
+ */
|
|
|
+@Composable
|
|
|
+fun FormDateRangeSelect(
|
|
|
+ label: String,
|
|
|
+ value: List<String>,
|
|
|
+ onSelectChange: (List<String>) -> Unit,
|
|
|
+ placeholder: List<String> = listOf("", ""),
|
|
|
+ required: Boolean = false,
|
|
|
+ enable: Boolean = true
|
|
|
+) {
|
|
|
+ val ctx = LocalContext.current
|
|
|
+ var start by remember { mutableStateOf("".dateToTimestamp("yyyy/MM/dd")) }
|
|
|
+ var end by remember { mutableStateOf("".dateToTimestamp("yyyy/MM/dd")) }
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
+ if (value.size == 2) {
|
|
|
+ start = value[0].dateToTimestamp("yyyy/MM/dd")
|
|
|
+ end = value[1].dateToTimestamp("yyyy/MM/dd")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Column(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .heightIn(max = 90.dp)
|
|
|
+ ) {
|
|
|
+ Row(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(40.dp),
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ if (required) Text(
|
|
|
+ "*",
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Color(0xFFFF4D4F).copy(alpha = if (enable) 1f else 0.6f),
|
|
|
+ modifier = Modifier.padding(start = 3.dp)
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(46.dp),
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ start.format("yyyy/MM/dd"),
|
|
|
+ modifier = Modifier
|
|
|
+ .weight(1f)
|
|
|
+ .height(46.dp)
|
|
|
+ .border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .clickable(onClick = {
|
|
|
+ CardDatePickerDialog.builder(ctx)
|
|
|
+ .setTitle("请选择开始日期")
|
|
|
+ .setDefaultTime(start)
|
|
|
+ .setDisplayType(mutableListOf(DateTimeConfig.YEAR, DateTimeConfig.MONTH, DateTimeConfig.DAY))
|
|
|
+ .setPickerLayout(R.layout.date_range_picker)
|
|
|
+ .showBackNow(false)
|
|
|
+ .showFocusDateInfo(false)
|
|
|
+ .showDateLabel(false)
|
|
|
+ .setOnChoose { timestamp ->
|
|
|
+ start = timestamp
|
|
|
+ onSelectChange(listOf(start.toString(), end.toString()))
|
|
|
+ }.build().show()
|
|
|
+ }, enabled = enable)
|
|
|
+ .padding(10.dp),
|
|
|
+ fontSize = 14.sp,
|
|
|
+ lineHeight = 26.sp,
|
|
|
+ color = Text.copy(alpha = if (enable) 1f else 0.6f)
|
|
|
+ )
|
|
|
+ Text("-", modifier = Modifier.padding(horizontal = 5.dp), color = Text.copy(alpha = if (enable) 1f else 0.6f))
|
|
|
+ Text(
|
|
|
+ end.format("yyyy/MM/dd"),
|
|
|
+ modifier = Modifier
|
|
|
+ .weight(1f)
|
|
|
+ .height(46.dp)
|
|
|
+ .border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .clickable(onClick = {
|
|
|
+ CardDatePickerDialog.builder(ctx)
|
|
|
+ .setTitle("请选择结束日期")
|
|
|
+ .setDefaultTime(end)
|
|
|
+ .setDisplayType(mutableListOf(DateTimeConfig.YEAR, DateTimeConfig.MONTH, DateTimeConfig.DAY))
|
|
|
+ .setPickerLayout(R.layout.date_range_picker)
|
|
|
+ .showBackNow(false)
|
|
|
+ .showFocusDateInfo(false)
|
|
|
+ .showDateLabel(false)
|
|
|
+ .setOnChoose { timestamp ->
|
|
|
+ end = timestamp
|
|
|
+ onSelectChange(listOf(start.toString(), end.toString()))
|
|
|
+ }.build().show()
|
|
|
+ }, enabled = enable)
|
|
|
+ .padding(10.dp),
|
|
|
+ fontSize = 14.sp,
|
|
|
+ lineHeight = 26.sp,
|
|
|
+ color = Text.copy(alpha = if (enable) 1f else 0.6f)
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 将服务端返回的表单String JSON数组转化为可用的表单数据
|
|
|
+ */
|
|
|
+fun List<String>.getFormListByJsonList(): List<FormField> {
|
|
|
+ val list = ArrayList<FormField>()
|
|
|
+ this.forEach { form ->
|
|
|
+ Log.d("FormCompose", form)
|
|
|
+ val forms = form.getFormListByJsonObject()
|
|
|
+ list.addAll(forms)
|
|
|
+ }
|
|
|
+ return list
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 转换表单列表
|
|
|
*/
|
|
|
-fun String.getFormList(): List<FormField> {
|
|
|
+fun String.getFormListByJsonList(): List<FormField> {
|
|
|
val json = Json { ignoreUnknownKeys = true }
|
|
|
val fields = json.decodeFromString<List<FormField>>(this)
|
|
|
val list = ArrayList<FormField>()
|
|
|
@@ -349,4 +547,29 @@ fun String.getFormList(): List<FormField> {
|
|
|
fields.forEach()
|
|
|
|
|
|
return list
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 转换表单列表
|
|
|
+ */
|
|
|
+fun String.getFormListByJsonObject(): List<FormField> {
|
|
|
+ val json = Json { ignoreUnknownKeys = true }
|
|
|
+ val form = json.decodeFromString<FormField>(this)
|
|
|
+ val list = ArrayList<FormField>()
|
|
|
+
|
|
|
+ fun List<FormField>.forEach() {
|
|
|
+ this.forEach { ch ->
|
|
|
+ if (ch.children.isNotEmpty()) ch.children.forEach()
|
|
|
+ else list.add(ch)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理表单
|
|
|
+ if (form.children.isNotEmpty()) {
|
|
|
+ form.children.forEach()
|
|
|
+ } else {
|
|
|
+ list.add(form)
|
|
|
+ }
|
|
|
+
|
|
|
+ return list
|
|
|
+}
|