DictionaryConfig.vue 5.42 KB
<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>