-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
264 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Submodule fs-admin-antdv4
updated
12 files
149 changes: 149 additions & 0 deletions
149
packages/fast-crud/src/components/extends/fs-table-select.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<template> | ||
<div> | ||
<fs-dict-select | ||
ref="dictSelectRef" | ||
:dict="dict" | ||
:[ui.select.modelValue]="modelValue" | ||
v-bind="select" | ||
:open="false" | ||
mode="multiple" | ||
@click="openTableSelect" | ||
/> | ||
<component :is="ui.formItem.skipValidationWrapper"> | ||
<component | ||
:is="ui.dialog.name" | ||
v-model:[ui.dialog.visible]="dialogOpen" | ||
v-bind=" | ||
ui.dialog.buildProps({ | ||
props: { | ||
title: '选择', | ||
width: '80%', | ||
onOk: onOk | ||
} | ||
}) | ||
" | ||
> | ||
<div style="width: 100%; height: 60vh"> | ||
<fs-crud ref="crudRef" v-bind="crudBinding"> | ||
<template #header-top> | ||
<div class="fs-table-select-current"> | ||
当前选中: | ||
<fs-values-format ref="valuesFormatRef" :model-value="selectedRowKeys" :dict="dict"></fs-values-format> | ||
</div> | ||
</template> | ||
</fs-crud> | ||
</div> | ||
</component> | ||
</component> | ||
</div> | ||
</template> | ||
<script lang="ts" setup> | ||
import { CreateCrudOptions, Dict, useFs, useMerge, useUi } from "../../use"; | ||
import { computed, nextTick, ref, watch, Ref } from "vue"; | ||
import { DynamicallyCrudOptions } from "../../d"; | ||
// defineOptions({ | ||
// name: "FsTableSelect" | ||
// }); | ||
type FsTableSelectProps = { | ||
/** | ||
* modelValue | ||
*/ | ||
modelValue: any; | ||
/** | ||
* crudOptionsCreator | ||
*/ | ||
createCrudOptions: CreateCrudOptions; | ||
crudOptionsOverride: DynamicallyCrudOptions; | ||
dict: Dict; | ||
select?: any; | ||
multiple?: boolean; //单选还是多选 | ||
crossPage?: boolean; //跨页选中 | ||
}; | ||
const props = defineProps<FsTableSelectProps>(); | ||
const emits = defineEmits(["change", "update:modelValue"]); | ||
const { ui } = useUi(); | ||
const dictSelectRef = ref(); | ||
const valuesFormatRef = ref(); | ||
const dialogOpen = ref(false); | ||
const openTableSelect = () => { | ||
dialogOpen.value = true; | ||
crudExpose.doRefresh(); | ||
if (props.modelValue) { | ||
if (props.multiple) { | ||
selectedRowKeys.value = props.modelValue || []; | ||
} else { | ||
selectedRowKeys.value = [props.modelValue]; | ||
} | ||
} else { | ||
selectedRowKeys.value = []; | ||
} | ||
}; | ||
watch( | ||
() => { | ||
return props.modelValue; | ||
}, | ||
async (value) => { | ||
if (value === selectedRowKeys.value) { | ||
return; | ||
} | ||
await nextTick(); | ||
dictSelectRef.value.reloadDict(); | ||
} | ||
); | ||
const selectedRowKeys: Ref<any[]> = ref([]); | ||
const override: DynamicallyCrudOptions = computed(() => { | ||
let selection = ui.table.buildSelectionBinding({ | ||
multiple: props.multiple, | ||
selectedRowKeys, | ||
crossPage: props.crossPage, | ||
onChanged: async (keys) => { | ||
selectedRowKeys.value = [...keys]; | ||
await nextTick(); | ||
if (valuesFormatRef.value) { | ||
valuesFormatRef.value.reloadDict(); | ||
} | ||
} | ||
}); | ||
const crudOptions = { ...selection }; | ||
return merge(crudOptions, props.crudOptionsOverride); | ||
}); | ||
const { merge } = useMerge(); | ||
// eslint-disable-next-line vue/no-setup-props-destructure | ||
const { crudBinding, crudRef, crudExpose, context, appendCrudOptions, crudOptions } = useFs({ | ||
createCrudOptions: props.createCrudOptions, | ||
crudOptionsOverride: override.value | ||
}); | ||
watch( | ||
() => { | ||
return override.value; | ||
}, | ||
(value) => { | ||
appendCrudOptions(value); | ||
} | ||
); | ||
function onOk() { | ||
if (selectedRowKeys.value?.length > 0) { | ||
let value = [...selectedRowKeys.value]; | ||
if (!props.multiple) { | ||
value = value[0]; | ||
} | ||
emits("update:modelValue", value); | ||
emits("change", value); | ||
} | ||
dialogOpen.value = false; | ||
} | ||
</script> | ||
|
||
<style lang="less"> | ||
.fs-table-select-current { | ||
//border: 1px solid #eee; | ||
//border-radius: 3px; | ||
padding: 10px 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { uiContext } from "../../ui"; | ||
export default function () { | ||
const ui = uiContext.get(); | ||
return { | ||
"table-select": { | ||
column: { component: { name: "fs-values-format", vModel: "modelValue" } }, | ||
form: { | ||
component: { | ||
name: "fs-table-select" | ||
} | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.