xiejun
2024-11-01 80b6cbfc9c861469146318d0b3dd5f8b8b525b8a
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<template>
    <div>
        <BasicTable @register="registerTable">
            <template \#toolbar>
                <a-button type="primary" v-auth="'${modelCode!}_add'" @click="handleCreate">
                    新增
                </a-button>
            </template>
            <template \#bodyCell="{ column, record }">
             #for(x in prototypes) {
                    #if(isNotEmpty(x.dictCode)){
                    <template v-if="column.dataIndex === '${x.propertyName!}'">
                              {{ formatDictValue(options['${x.propertyName!}Data'], record.category) }}
                     </template>
                    #}
              #}
             <template v-if="column.dataIndex === 'action'">
                 <TableAction
                     :actions="[
                          {
                            auth: '${modelCode!}_view',
                            label: '查看',
                            color: 'success',
                            icon: 'clarity:info-standard-line',
                            onClick: handleView.bind(null, record),
                          },
                          {
                            auth: '${modelCode!}_edit',
                            label: '编辑',
                            icon: 'clarity:note-edit-line',
                            onClick: handleEdit.bind(null, record),
                          },
                          {
                            auth: '${modelCode!}_delete',
                            label: '删除',
                            icon: 'ant-design:delete-outlined',
                            color: 'error',
                            popConfirm: {
                              title: '是否确认删除',
                              confirm: handleDelete.bind(null, record),
                            },
                          },
                        ]"
                      />
                 </template>
            </template>
        </BasicTable>
        <${modelClass!}Modal @register="registerModal" @success="handleSuccess" />
    </div>
</template>
<script lang="ts" setup name="${modelClass!}">
    import { ref } from 'vue';
    import ${modelClass!}Modal from './${modelCode!}Modal.vue';
    import { BasicTable, useTable, TableAction } from '/@/components/Table';
    import { getList, remove } from '/@/api/${serviceCode!}/${modelCode!}';
    import { useModal } from '/@/components/Modal';
    import { columns, searchFormSchema } from './${modelCode!}.data';
    import { useMessage } from '/@/hooks/web/useMessage';
    import { formatDictValue } from '/@/utils';
    import { getDictList } from '/@/api/system/system';
    //初始化字典
    let options = ref({});
    async function fetch() {
    #for(x in prototypes) {
        #if(isNotEmpty(x.dictCode)){
          options.value['${x.propertyName!}Data'] = await getDictList({ code: '${x.dictCode!}' });
        #}
    #}
    }
    fetch();
 
    const { createMessage } = useMessage();
    const [registerModal, { openModal }] = useModal();
    const [registerTable, { reload }] = useTable({
        api: getList,
        rowKey: 'id',
        columns,
        formConfig: {
            labelWidth: 120,
            schemas: searchFormSchema,
            baseColProps: { xl: 12, xxl: 8 },
        },
        useSearchForm: true,
        actionColumn: {
            width: 250,
            title: '操作',
            dataIndex: 'action',
        },
    });
 
    function handleCreate() {
        openModal(true, {
            isDetail: false,
            isUpdate: false,
        });
    }
 
    function handleView(record: Recordable) {
        openModal(true, {
            record,
            isUpdate: false,
            isDetail: true,
        });
    }
 
    function handleEdit(record: Recordable) {
        openModal(true, {
            record,
            isDetail: false,
            isUpdate: true,
        });
    }
    async function handleDelete(record: Recordable) {
        await remove({ ids: record.id });
        createMessage.success('操作成功');
        reload();
    }
 
    function handleSuccess() {
        //操作成功提示
        createMessage.success('操作成功');
        reload();
    }
</script>