2023-11-20 19:24:12 +00:00
|
|
|
|
<template>
|
|
|
|
|
|
<fs-page>
|
|
|
|
|
|
<template #header>
|
|
|
|
|
|
<div class="title">可编辑</div>
|
2024-06-15 18:32:36 +00:00
|
|
|
|
<div class="more"><a target="_blank" href="http://fast-crud.docmirror.cn/api/crud-options/table.html#editable">文档</a></div>
|
2023-11-20 19:24:12 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
<fs-crud ref="crudRef" v-bind="crudBinding">
|
|
|
|
|
|
<template #actionbar-right>
|
|
|
|
|
|
<!-- <fs-button class="ml-1" @click="addRow">添加行</fs-button>-->
|
|
|
|
|
|
<a-radio-group v-model:value="crudBinding.table.editable.enabled" class="ml-5">
|
|
|
|
|
|
<a-radio-button :value="true">启用编辑</a-radio-button>
|
|
|
|
|
|
<a-radio-button :value="false">退出编辑</a-radio-button>
|
|
|
|
|
|
</a-radio-group>
|
2024-06-15 18:32:36 +00:00
|
|
|
|
<a-radio-group v-model:value="crudBinding.table.editable.showAction" class="ml-1">
|
|
|
|
|
|
<a-radio-button :value="true">显示操作按钮</a-radio-button>
|
|
|
|
|
|
<a-radio-button :value="false">不显示</a-radio-button>
|
|
|
|
|
|
</a-radio-group>
|
|
|
|
|
|
<a-radio-group v-model:value="crudBinding.table.editable.activeDefault" class="ml-1">
|
|
|
|
|
|
<a-radio-button :value="true">默认激活</a-radio-button>
|
|
|
|
|
|
<a-radio-button :value="false">默认不激活</a-radio-button>
|
|
|
|
|
|
</a-radio-group>
|
2023-11-20 19:24:12 +00:00
|
|
|
|
<template v-if="crudBinding.table.editable.enabled">
|
|
|
|
|
|
<fs-button class="ml-5" @click="save">保存</fs-button>
|
|
|
|
|
|
<fs-button class="ml-5" @click="log">log</fs-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</fs-crud>
|
|
|
|
|
|
</fs-page>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2024-06-15 18:32:36 +00:00
|
|
|
|
import { defineComponent, onMounted, ref } from "vue";
|
2023-11-20 19:24:12 +00:00
|
|
|
|
import createCrudOptions from "./crud";
|
2024-06-15 18:32:36 +00:00
|
|
|
|
import { useFs, utils } from "@fast-crud/fast-crud";
|
2023-11-20 19:24:12 +00:00
|
|
|
|
import { message } from "ant-design-vue";
|
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
name: "EditableFree",
|
|
|
|
|
|
setup() {
|
|
|
|
|
|
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions });
|
|
|
|
|
|
|
|
|
|
|
|
// 页面打开后获取列表数据
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
crudExpose.doRefresh();
|
2024-06-15 18:32:36 +00:00
|
|
|
|
crudExpose.editable.enable({ mode: "free" });
|
2023-11-20 19:24:12 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
crudBinding,
|
|
|
|
|
|
crudRef,
|
|
|
|
|
|
active() {
|
2024-06-15 18:32:36 +00:00
|
|
|
|
crudExpose.editable.active({});
|
2023-11-20 19:24:12 +00:00
|
|
|
|
},
|
|
|
|
|
|
inactive() {
|
|
|
|
|
|
crudExpose.editable.inactive();
|
|
|
|
|
|
},
|
|
|
|
|
|
async save() {
|
|
|
|
|
|
const res = await crudExpose.editable.validate();
|
|
|
|
|
|
if (res !== true) {
|
|
|
|
|
|
console.error("validate error:", res);
|
2024-06-15 18:32:36 +00:00
|
|
|
|
message.error("validate error:" + JSON.stringify(res));
|
2023-11-20 19:24:12 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
message.success("保存,修改行:" + JSON.stringify(crudBinding.value.data));
|
|
|
|
|
|
},
|
|
|
|
|
|
log() {
|
2024-06-15 18:32:36 +00:00
|
|
|
|
utils.logger.info("table data:", crudBinding.value.data, crudExpose.getTableData());
|
2023-11-20 19:24:12 +00:00
|
|
|
|
},
|
|
|
|
|
|
cancel() {
|
|
|
|
|
|
crudExpose.editable.resume();
|
|
|
|
|
|
},
|
|
|
|
|
|
addRow() {
|
|
|
|
|
|
crudExpose.editable.addRow();
|
|
|
|
|
|
},
|
|
|
|
|
|
editCol() {
|
|
|
|
|
|
crudExpose.editable.activeCols({ cols: ["radio"] });
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|