index.vue 12.4 KB
<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="70px">
            <el-form-item label="名称" prop="machineName">
                <el-input v-model="queryParams.machineName" placeholder="请输入名称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="位置" prop="location">
                <el-input v-model="queryParams.location" placeholder="请输入位置" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="ip" prop="ip">
                <el-input v-model="queryParams.ip" placeholder="请输入ip" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['resource:machine:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['resource:machine:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                    @click="handleDelete" v-hasPermi="['resource:machine:remove']">删除</el-button>
            </el-col>

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="machineList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <!-- <el-table-column label="考勤机ID" align="center" prop="id" width="180" /> -->
            <el-table-column label="考勤机名称" align="center" prop="machineName" v-if="columns[1].visible"
                min-width="200" />
            <el-table-column label="考勤机位置" align="center" prop="location" :show-overflow-tooltip="true"
                min-width="200" />
            <el-table-column label="ip地址" align="center" prop="ip" :show-overflow-tooltip="true" min-width="150" />
            <el-table-column label="安装位置" align="center" prop="location" :show-overflow-tooltip="true"
                min-width="150" />
            <el-table-column label="在线状态" align="center" prop="online" :show-overflow-tooltip="true">

                <template slot-scope="scope">
                    <el-tag v-if="scope.row.online == '在线' && scope.row.online !== null" type="success">{{
                        scope.row.online
                    }}</el-tag>
                    <el-tag v-if="scope.row.online == '不在线' && scope.row.online !== null" type="warning">{{
                        scope.row.online
                    }}</el-tag>

                </template>
            </el-table-column>
            <el-table-column label="测试时间" align="center" prop="onlineTime" :show-overflow-tooltip="true"
                min-width="180" />
            <el-table-column label="考勤机描述" align="center" prop="describes" :show-overflow-tooltip="true"
                min-width="200" />

            <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="scope" v-if="scope.row.userId !== 1">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['resource:machine:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['resource:machine:remove']">删除</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="testBtn(scope.row)"
                        v-hasPermi="['resource:machine:remove']">测试</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 新增、修改 -->
        <el-dialog :title="title" :visible.sync="changeShow" width="600px" append-to-body @close="handleClose">
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-form-item label="考勤机ID" prop="machineId" v-show="machineId !== ''">{{ machineId }}</el-form-item>
                <el-form-item label="考勤机名称" prop="machineName">
                    <el-input v-model="form.machineName" placeholder="请输入考勤机名称" maxlength="30" />
                </el-form-item>
                <el-form-item label="考勤机位置" prop="location">
                    <el-input v-model="form.location" placeholder="请输入考勤机位置" maxlength="30" />
                </el-form-item>
                <el-form-item label="IP地址" prop="ip">
                    <el-input v-model="form.ip" placeholder="请输入考勤机名称" maxlength="30" />
                </el-form-item>
                <el-form-item label="考勤机描述" prop="describes">
                    <el-input v-model="form.describes" placeholder="请输入考勤机描述" maxlength="30" />
                </el-form-item>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注">
                            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { machineLists, getDetails, addMachine, updateMachine, delMachine, testData } from "@/api/resource/machine";
import { getUserProfile } from "@/api/system/user";
export default {
    name:"Machine",
    data() {
        return {
            user: {},
            loading: false,
            // 搜索条件
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                machineName: undefined,
                location: undefined,
                // describes: undefined,
                ip: '',
            },
            // 日期
            // dateRange: [],
            // 总条数
            total: 0,
            // 列信息
            columns: [
                { key: 0, label: `考勤机ID`, visible: true },
                { key: 1, label: `考勤机名称`, visible: true },
                { key: 2, label: `考勤机位置`, visible: true },
                { key: 3, label: `考勤机描述`, visible: true },
                { key: 4, label: `创建时间`, visible: true }
            ],
            // 表格
            machineList: [],
            // 显示搜索条件
            showSearch: true,
            // 表格选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 新增修改弹框
            changeShow: false,
            // 弹出层标题
            title: "",
            // 验证
            rules: {
                machineName: [
                    { required: true, message: "考勤机名称不能为空", trigger: "blur" }
                ],
                location: [
                    { required: true, message: "考勤机地址不能为空", trigger: "blur" }
                ],
                ip: [
                    { required: true, message: "ip地址不能为空", trigger: "blur" }
                ],
            },
            // 新增、修改 表单参数
            form: {},
            // 考勤机id
            machineId: '',
        }
    },
    created() {
        this.getList();
        this.getUser();
    },
    methods: {
        // 获取用户信息
        getUser() {
            getUserProfile().then(response => {
                this.user = response.data;
            });
        },
        // 列表
        getList() {
            this.loading = true;
            machineLists(this.addDateRange(this.queryParams)).then(response => {
                this.machineList = response.rows;
                this.total = response.total;
                this.loading = false;
            }
            );
        },
        //    搜索
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        // 重置
        resetQuery() {
            this.dateRange = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 表格多选框
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },
        // 新增
        handleAdd() {
            this.reset();
            this.title = '新增';
            this.changeShow = true;
        },
        // 修改
        handleUpdate(row) {
            this.machineId = row.id;
            this.reset();
            const id = row.id || this.ids
            getDetails(id).then(response => {
                this.form = response.data;
                this.changeShow = true;
                this.title = "修改";
            });
        },
        // 删除
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除考勤机编号为"' + ids + '"的数据项?').then(function () {
                return delMachine(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        // 测试
        testBtn(row) {
            testData(row.ip).then((res) => {
                this.$alert('状态:' + res.data.online, '测试', {});

                row.online = res.data.online;
                row.onlineTime = res.data.onlineTime;

                updateMachine(row).then(response => {
                    this.getList();
                });

            })
        },
        // 新增、修改 提交
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        this.form.updateBy = this.user.userName;
                        updateMachine(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.changeShow = false;
                            this.machineId = '';
                            this.getList();
                        });
                    } else {
                        this.form.createBy = this.user.userName;
                        addMachine(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.changeShow = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        // 表单重置
        reset() {
            this.form = {
                machineName: '',
                location: '',
                describes: '',
                remark: '',
            };
            this.resetForm("form");
        },
        // 新增、修改 取消
        cancel() {
            this.changeShow = false;
            this.reset();
        },
        // 关闭弹窗
        handleClose() {


            this.machineId = '';
        }
    },
}
</script>

<style scoped></style>