UserPicker.vue 3.88 KB
<template>
    <!--查询栏-->
    <m-pagination-query-render title="" :fields="pagination.filterFields" :form="pagination.queryForm" @onSearch="pageReload" @onReset="pageReset" :simpleFieldNum="4"/>
    <!--查询栏end-->
    <a-table :columns="columns" :data-source="pagination.content" :loading="loading" :bordered="false" @change="pageRefresh" @resizeColumn="this.$filters.tableResizeColumn"
             :row-selection="{ selectedRowKeys: selectIds, onChange: onSelectChange, type: 'checkbox', preserveSelectedRowKeys:true,getCheckboxProps:getCheckboxProps}"
             size="small" :pagination="pageState" :row-key="record => record.userId" :scroll="{y: '446px'}">
        <template #bodyCell="{column,record}">
            <template v-if="column.key === 'roles'">
                <a-tag v-for="role in record?.roles" :key="role.roleId">{{ role.roleName }}</a-tag>
            </template>
        </template>
        <!--库存车辆列表end-->
    </a-table>
</template>
<script lang="ts">
import {Component, Emit, Prop} from "vue-facing-decorator";
import AccountTypeTag from "@/views/account/account/tag/AccountTypeTag.vue";
import {PaginationComponent} from "@/components/PaginationComponent";
import {Account} from "lib/src/entity/account/entity/Account";
import {User} from "lib/src/entity/security/entity/User";
import {TableColumnsType} from "ant-design-vue";
import {SecurityController} from "@/api/SecurityController";
import {Operator, Order} from "lib/src/core/page/Pagination";
import {Vehicle} from "lib/src/entity/vehicle/entity/Vehicle";

@Component({
    components: {AccountTypeTag}
})
export default class UserPicker extends PaginationComponent<User> {
    columns: TableColumnsType = [
        {title: "账号", dataIndex: 'userName', key: 'userName', width: 140, resizable: true},
        {title: "真实姓名", dataIndex: 'realName', key: 'realName', width: 140, resizable: true, ellipsis: true},
        {title: "角色", dataIndex: 'roles', key: 'roles', width: 200, resizable: true, ellipsis: true},
        {title: "性别", dataIndex: 'gender', key: 'gender', width: 50, align: 'center'},
        {title: "邮箱", dataIndex: 'email', key: 'email', width: 140, resizable: true, ellipsis: true},
        {title: "电话", dataIndex: 'mobile', key: 'mobile', width: 140, resizable: true, ellipsis: true},
        {title: "创建时间", dataIndex: 'createTime', key: 'createTime', width: 160, sorter: true, resizable: true, ellipsis: true, align: 'center'},
    ];

    @Prop({type: Array, default: []})
    ids: number[]

    selectIds: number[] = [];

    selectedItems: Account[] = [];

    created(): void {
        this.init(this.axios, SecurityController.PAGE_USER);
        this.buildQueryForm({
            userName: [null, {label: "账号", field: 'userName', operator: Operator.like}],
            realName: [null, {label: "真实姓名", field: 'realName', operator: Operator.eq}],
            mobile: [null, {label: "电话", field: 'mobile', operator: Operator.eq}],
            email: [null, {label: "邮箱", field: 'email', operator: Operator.like}],
            createTime: [null, {label: "创建时间", field: 'createTime', operator: Operator.dateBetween, type: 'date-range'}],
        });
        this.pagination.setDefaultSort('createTime', Order.desc);
        this.pagination.addDefaultFilter('enabled', true);
        this.pageReload();
    }


    getCheckboxProps(record: Vehicle): Vehicle {
        record.disabled = this.hasSelected(record.vehicleId);
        return record;
    }

    hasSelected(vehicleId: number): boolean {
        return this.ids?.some(id => id === vehicleId);
    }

    onSelectChange(selectedRowKeys: number[], selectedRows: Account[]): void {
        this.selectIds = selectedRowKeys;
        this.selectedItems = selectedRows;
    }

    @Emit('handleOk')
    selectUsers(): Account[] {
        return this.selectedItems;
    }
}
</script>

<style lang="less" scoped>

</style>