zhaowc
2025-06-07 9dfb7d191bdf19595d766647222171f992d8af3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
    <div class="h-full">
        <fs-crud ref="crudRef" v-bind="crudBinding">
            <template #pagination-left>
                <fs-button icon="ion:trash-outline" @click="handleBatchDelete" />
            </template>
            <template #cell_url="scope">
                <n-tooltip trigger="hover">
                    <template #trigger>
                        <n-button> 预览 </n-button>
                    </template>
                    <n-image width="120px" height="120px" :src="baseURL + '/' + scope.row.url"></n-image>
                </n-tooltip>
            </template>
        </fs-crud>
    </div>
</template>
 
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { useExpose, useCrud } from '@fast-crud/fast-crud';
import createCrudOptions from './crud';
 
const baseURL = import.meta.env.VITE_API_URL;
 
export default defineComponent({
    name: 'FastCrud',
    setup() {
        const crudRef = ref();
        const crudBinding = ref();
        const { expose } = useExpose({ crudRef, crudBinding });
        const { crudOptions, selectedIds } = createCrudOptions({ expose });
        const { resetCrudOptions } = useCrud({ expose, crudOptions });
 
        // 页面初始化
        onMounted(() => {
            expose.doRefresh();
        });
        // 批量删除
        const handleBatchDelete = async () => {
            if (selectedIds.value?.length > 0) {
                // ElMessageBox.confirm(`确定要批量删除这${selectedIds.value.length}条记录吗`, '确认', {
                //     confirmButtonText: '确定',
                //     cancelButtonText: '取消',
                //     type: 'info',
                // }).then(async () => {
                //        await delBatchSysFile(selectedIds.value);
                //       message.success('删除成功');
                //       selectedIds.value = [];
                //       await expose.doRefresh();
                //         ElMessage.success('删除成功');
                //     })
                //     .catch(() => { });
            } else {
                // ElMessage.success('请勾选要删除的记录');
            }
        };
        return {
            crudBinding,
            crudRef,
            handleBatchDelete,
            baseURL,
        };
    },
});
</script>