优化webman-buildadmin框架
This commit is contained in:
@@ -3,18 +3,18 @@
|
||||
<el-switch
|
||||
v-if="field.prop"
|
||||
@change="onChange"
|
||||
:model-value="cellValue"
|
||||
:model-value="displayValue"
|
||||
:loading="loading"
|
||||
active-value="1"
|
||||
inactive-value="0"
|
||||
v-bind="invokeTableContextDataFun(field.customRenderAttr?.switch, { row, field, cellValue, column, index })"
|
||||
v-bind="invokeTableContextDataFun(field.customRenderAttr?.switch, { row, field, cellValue: displayValue, column, index })"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TableColumnCtx } from 'element-plus'
|
||||
import { inject, ref } from 'vue'
|
||||
import { inject, ref, onMounted } from 'vue'
|
||||
import { getCellValue, invokeTableContextDataFun } from '/@/components/table/index'
|
||||
import type baTableClass from '/@/utils/baTable'
|
||||
|
||||
@@ -28,13 +28,27 @@ interface Props {
|
||||
const loading = ref(false)
|
||||
const props = defineProps<Props>()
|
||||
const baTable = inject('baTable') as baTableClass
|
||||
const cellValue = ref(getCellValue(props.row, props.field, props.column, props.index))
|
||||
|
||||
if (typeof cellValue.value === 'number') {
|
||||
cellValue.value = cellValue.value.toString()
|
||||
const rawValue = getCellValue(props.row, props.field, props.column, props.index)
|
||||
const normalized = (v: unknown) => {
|
||||
if (typeof v === 'number') return v.toString()
|
||||
if (v === null || v === undefined || v === '') return '0'
|
||||
return String(v)
|
||||
}
|
||||
const displayValue = ref(normalized(rawValue))
|
||||
|
||||
const mountedAt = ref(0)
|
||||
onMounted(() => {
|
||||
mountedAt.value = Date.now()
|
||||
})
|
||||
|
||||
const onChange = (value: string | number | boolean) => {
|
||||
const newVal = String(value)
|
||||
const prevVal = normalized(rawValue)
|
||||
if (prevVal === newVal) return
|
||||
if ([null, undefined, ''].includes(rawValue) && newVal === '0') return
|
||||
if (Date.now() - mountedAt.value < 150) return
|
||||
|
||||
loading.value = true
|
||||
baTable.api
|
||||
.postData('edit', {
|
||||
@@ -42,7 +56,7 @@ const onChange = (value: string | number | boolean) => {
|
||||
[props.field.prop!]: value,
|
||||
})
|
||||
.then(() => {
|
||||
cellValue.value = value
|
||||
displayValue.value = newVal
|
||||
baTable.onTableAction('field-change', { value: value, ...props })
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
Reference in New Issue
Block a user