ItemIndex.vue
4.34 KB
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
<template>
<div>
<BasicDrawer
v-bind="$attrs"
@register="register"
width="60%"
:title="t('system.dict.dictConfig')"
>
<div style="background-color: #f0f2f5">
<BasicTable @register="registerTable">
<template #toolbar>
<Authority value="api:yt:dictItem:post">
<a-button type="primary" @click="handleCreate">
{{ t('system.dict.createButton') }}
</a-button>
</Authority>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: t('common.editText'),
icon: 'clarity:note-edit-line',
auth: 'api:yt:dictItem:update',
onClick: handleEdit.bind(null, record),
},
{
label: t('common.delText'),
icon: 'ant-design:delete-outlined',
color: 'error',
auth: 'api:yt:dictItem:delete',
popConfirm: {
title: t('common.isDelete'),
confirm: handleDelete.bind(null, record),
},
ifShow: record.status == 0,
},
]"
/>
</template>
</BasicTable>
<ItemDrawer @register="registerDrawer" @success="handleSuccess" />
</div>
</BasicDrawer>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { sysDictItemPage, deleteDictItem } from '/@/api/system/dict';
import { BasicDrawer, useDrawer, useDrawerInner } from '/@/components/Drawer';
import ItemDrawer from '/@/views/system/dict/item/ItemDrawer.vue';
import { columns, searchFormSchema } from './dict.item.data';
import { useMessage } from '/@/hooks/web/useMessage';
import Authority from '/@/components/Authority/src/Authority.vue';
import { useI18n } from '/@/hooks/web/useI18n';
export default defineComponent({
name: 'ItemIndex',
components: { BasicDrawer, BasicTable, ItemDrawer, TableAction, Authority },
setup() {
const { t } = useI18n();
let dictId;
const disabled = ref(false);
const { createMessage } = useMessage();
const [registerDrawer, { openDrawer }] = useDrawer();
const [register] = useDrawerInner((data) => {
dictId = data.data.id;
if (
data.data.dictCode === 'enabled_platform_admin_auth' ||
data.data.dictCode === 'disabled_tenant_auth' ||
data.data.dictCode === 'enabled_sysadmin_auth'
) {
disabled.value = true;
} else {
disabled.value = false;
}
reload();
});
const [registerTable, { reload }] = useTable({
title: t('system.dict.item.title'),
api: sysDictItemPage,
columns,
formConfig: {
labelWidth: 120,
schemas: searchFormSchema,
},
useSearchForm: true,
showTableSetting: true,
bordered: true,
showIndexColumn: false,
actionColumn: {
width: 140,
title: t('common.actionText'),
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: 'right',
},
beforeFetch: getDictId,
immediate: true,
});
function handleCreate() {
openDrawer(true, {
isUpdate: false,
dictId: dictId,
});
}
/**
* 获取父页面传递的dictId值
* @param data 请求之前的参数
*/
function getDictId(data) {
Reflect.set(data, 'dictId', dictId);
}
function handleEdit(record: Recordable) {
openDrawer(true, {
record,
isUpdate: true,
});
}
function handleDelete(record: Recordable) {
let ids = [record.id];
deleteDictItem(ids).then((result) => {
createMessage.success(result.message);
handleSuccess();
});
}
function handleSuccess() {
reload();
}
return {
register,
registerTable,
registerDrawer,
handleCreate,
handleEdit,
handleDelete,
handleSuccess,
disabled,
t,
};
},
});
</script>