DictionaryConfig.vue
5.42 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
<template>
<div>
<a-button type="primary" class="table-first-btn" @click="createVisible = true">
<template #icon>
<PlusCircleOutlined class="mr-5"/>
</template>
{{ $t('common.add') }}
</a-button>
<a-table :columns="columns" :data-source="dictionaries" :loading="loading" bordered
size="small" :pagination="false" :row-key="record => record.dictionaryId">
<template #bodyCell="{column,record}">
<template v-if="column.key === 'action'">
<a @click="showEdit(record)">
<a-tooltip :title="$t('common.edit')">
{{ $t('common.edit') }}
</a-tooltip>
</a>
<a-divider type="vertical"/>
<a-popconfirm placement="topRight" :title="$t('common.delete_confirm')" :ok-text="$t('common.ok')"
:cancel-text="$t('common.cancel')" @confirm="removeRecord(record.dictionaryId)">
<a href="#" class="text-danger">
<a-tooltip :title="$t('common.delete')">
{{ $t('common.delete') }}
</a-tooltip>
</a>
</a-popconfirm>
</template>
<template v-if="column.key === 'enabled'">
<a-popconfirm placement="topRight" :title="$t('common.enabled_confirm')" :ok-text="$t('common.ok')" :cancel-text="$t('common.cancel')"
@confirm="enabledRecord(record)" @cancel="record.enabled = !record.enabled">
<a-switch v-model:checked="record.enabled" :checked-children="$t('common.enabled_true')" :un-checked-children="$t('common.enabled_false')"/>
</a-popconfirm>
</template>
</template>
<!--字典表列表end-->
</a-table>
<CreateDictionary v-if="createVisible" @after-modal-close="createVisible=$event" :dictionaryName="dictionaryName" @handleOk="reloadDictionaries()"></CreateDictionary>
<EditDictionary v-if="editVisible" :dictionary="selectedDictionary" @after-modal-close="editVisible=$event" @handleOk="reloadDictionaries()"></EditDictionary>
</div>
</template>
<script lang="ts">
import {message, TableColumnsType} from 'ant-design-vue';
import CreateDictionary from './CreateDictionary.vue';
import EditDictionary from './EditDictionary.vue';
import {Component, Prop, Vue} from "vue-facing-decorator";
import {Dictionary} from "lib/src/core/dictionary/Dictionary";
import {PlusCircleOutlined, UndoOutlined} from "@ant-design/icons-vue";
@Component({
name: "MDictionaryConfig",
components: {PlusCircleOutlined, CreateDictionary, EditDictionary}
})
export default class DictionaryConfig extends Vue {
loading = false;
/**
* 表格列配置
*/
columns: TableColumnsType = [];
@Prop()
dictionaryName: string;
dictionaries: Dictionary[] = [];
selectedDictionary: Dictionary | null = null;
/**
* 新建弹窗
*/
createVisible = false;
/**
* 修改弹窗
*/
editVisible = false;
/**
* 详情弹窗
*/
viewVisible = false;
showCreate(): void {
this.createVisible = true;
}
/**
* 初始化配置
*/
created(): void {
this.columns = [
{title: this.$t('common.code'), dataIndex: 'optionCode', sorter: false, width: 180},
{title: this.$t('common.name'), dataIndex: 'optionName', sorter: false},
{title: this.$t('common.remark'), dataIndex: 'remark', sorter: false},
{title: this.$t('common.create_time'), dataIndex: 'createTime', sorter: false, width: 180, align: 'center'},
{title: this.$t('common.enabled'), dataIndex: 'enabled', sorter: false, key: 'enabled', width: 100, align: 'center'},
{title: this.$t('common.operate'), key: 'action', width: 100, align: 'center'},
];
this.reloadDictionaries();
}
reloadDictionaries(): void {
// @ts-ignore
this.axios.get('dictionary/getDictionariesByName', {params: {dictionaryName: this.dictionaryName}}).then(response => {
this.dictionaries = response.data;
this.createVisible = false;
});
}
showEdit(dictionary: Dictionary): void {
this.selectedDictionary = dictionary;
this.editVisible = true;
}
/**
* 删除字典表
*/
removeRecord(dictionaryId: number): void {
// @ts-ignore
this.axios.delete('dictionary/removeDictionaryById', {params: {dictionaryId}}).then(() => {
message.success(this.$t('common.delete_success'));
this.reloadDictionaries();
});
}
/**
* 启/禁用
* @param record
*/
enabledRecord(record: Dictionary): void {
// @ts-ignore
this.axios.post('dictionary/enableDictionary', null, {
params: {
dictionaryId: record.dictionaryId,
enabled: record.enabled
}
}).then(() => {
message.success(record.enabled ? this.$t('common.enabled_true_success') : this.$t('common.enabled_false_success'));
this.reloadDictionaries();
}).catch((reason: any) => record.enabled = !record.enabled);
}
}
</script>
<style lang="less" scoped>
</style>