wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
    <cl-crud ref="Crud">
        <cl-row>
            <cl-refresh-btn />
            <cl-add-btn />
            <cl-multi-delete-btn />
            <cl-flex1 />
            <cl-search-key :placeholder="$t('搜索名称')" />
        </cl-row>
 
        <cl-row>
            <cl-table ref="Table" />
        </cl-row>
 
        <cl-row>
            <cl-flex1 />
            <cl-pagination />
        </cl-row>
 
        <cl-upsert ref="Upsert">
            <template #slot-relevance="{ scope }">
                <div>
                    <el-row>
                        <cl-switch v-model="scope.relevance" />
 
                        <span
                            :style="{
                                marginLeft: '10px',
                                fontSize: '12px'
                            }"
                        >
                            {{ t('是否关联上下级') }}
                        </span>
                    </el-row>
 
                    <cl-dept-check
                        v-model="scope.departmentIdList"
                        :check-strictly="scope.relevance == 0"
                    />
                </div>
            </template>
        </cl-upsert>
    </cl-crud>
</template>
 
<script lang="ts" setup>
defineOptions({
    name: 'sys-role'
});
 
import { useTable, useUpsert, useCrud } from '@cool-vue/crud';
import { useCool } from '/@/cool';
import { useI18n } from 'vue-i18n';
 
const { t } = useI18n();
const { service } = useCool();
 
// cl-crud
const Crud = useCrud({ service: service.base.sys.role }, app => {
    app.refresh();
});
 
// cl-upsert
const Upsert = useUpsert({
    dialog: {
        width: '800px'
    },
 
    items: [
        {
            prop: 'name',
            label: t('名称'),
            span: 12,
            required: true,
            component: {
                name: 'el-input'
            }
        },
        {
            prop: 'label',
            label: t('标识'),
            span: 12,
            required: true,
            component: {
                name: 'el-input'
            }
        },
        {
            prop: 'remark',
            label: t('备注'),
            span: 24,
            component: {
                name: 'el-input',
                props: {
                    type: 'textarea',
                    rows: 4
                }
            }
        },
        {
            label: t('功能权限'),
            prop: 'menuIdList',
            value: [],
            component: {
                name: 'cl-menu-check'
            }
        },
        {
            label: t('数据权限'),
            prop: 'relevance',
            component: {
                name: 'slot-relevance'
            }
        }
    ],
 
    onSubmit(data, { next }) {
        next({
            ...data,
            departmentIdList: data.departmentIdList || []
        });
    }
});
 
// cl-table
const Table = useTable({
    columns: [
        {
            type: 'selection',
            width: 60
        },
        {
            prop: 'name',
            label: t('名称'),
            minWidth: 150
        },
        {
            prop: 'label',
            label: t('标识'),
            minWidth: 120
        },
        {
            prop: 'remark',
            label: t('备注'),
            showOverflowTooltip: true,
            minWidth: 150
        },
        {
            prop: 'createTime',
            label: t('创建时间'),
            sortable: 'desc',
            minWidth: 170
        },
        {
            prop: 'updateTime',
            label: t('更新时间'),
            sortable: 'custom',
            minWidth: 170
        },
        {
            type: 'op'
        }
    ]
});
</script>