<template>
|
<div class="app-container">
|
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form-item label="用户名" prop="adminName">
|
<el-input
|
v-model="queryParams.adminName"
|
placeholder="请输入用户名"
|
clearable
|
size="small"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item>
|
<!-- <el-form-item label="密码" prop="adminPwd">
|
<el-input
|
v-model="queryParams.adminPwd"
|
placeholder="请输入密码"
|
clearable
|
size="small"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item> -->
|
<el-form-item label="手机号码" prop="adminPhone">
|
<el-input
|
v-model="queryParams.adminPhone"
|
placeholder="请输入手机号码"
|
clearable
|
size="small"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item>
|
<!-- <el-form-item label="代理角色" prop="isLock">
|
<el-input
|
v-model="queryParams.isLock"
|
placeholder="请输入代理角色"
|
clearable
|
size="small"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item> -->
|
<!-- <el-form-item label="添加时间" prop="addTime">
|
<el-date-picker
|
clearable
|
size="small"
|
style="width: 200px"
|
v-model="queryParams.addTime"
|
type="date"
|
value-format="yyyy-MM-dd"
|
placeholder="选择添加时间"
|
>
|
</el-date-picker>
|
</el-form-item> -->
|
<el-form-item>
|
<el-button type="cyan" 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" v-if="butAuthority(2128)">
|
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
</el-col>
|
<el-col :span="1.5" v-if="butAuthority(2129)">
|
<el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
|
>修改</el-button
|
>
|
</el-col>
|
<el-col :span="1.5" v-if="butAuthority(2130)">
|
<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
|
>删除</el-button
|
>
|
</el-col>
|
<!-- <el-col :span="1.5">
|
<el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
|
</el-col> -->
|
<!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
|
</el-row>
|
|
<el-table v-loading="loading" :data="adminList" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column label="ID" align="center" prop="id" />
|
<el-table-column label="用户名" align="center" prop="adminName" />
|
<!-- <el-table-column label="密码" align="center" prop="adminPwd" /> -->
|
<el-table-column label="手机号码" align="center" prop="adminPhone" />
|
<el-table-column label="代理角色" align="center" prop="roleName" />
|
<el-table-column label="添加时间" align="center" prop="addTime" width="180">
|
<template slot-scope="scope">
|
<span>{{ parseTime(scope.row.addTime, '{y}-{m}-{d}') }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<template slot-scope="scope">
|
<el-button
|
v-if="butAuthority(2129)"
|
size="mini"
|
type="text"
|
icon="el-icon-edit"
|
@click="handleUpdate(scope.row)"
|
>修改</el-button
|
>
|
<el-button
|
v-if="butAuthority(2130)"
|
size="mini"
|
type="text"
|
icon="el-icon-delete"
|
@click="handleDelete(scope.row)"
|
>删除</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="open" width="500px" append-to-body>
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-form-item label="用户名" prop="adminName" v-if="!form.id">
|
<el-input v-model="form.adminName" placeholder="请输入用户名" />
|
</el-form-item>
|
<el-form-item label="密码" prop="adminPwd">
|
<el-input v-model="form.adminPwd" placeholder="请输入密码" />
|
</el-form-item>
|
<el-form-item label="角色" prop="roleId">
|
<!-- <a-select v-model="form.roleId" placeholder="请选择角色">
|
<a-select-option v-for="(item, index) in roleList" :key="index" :value="item.roleId">
|
{{ item.roleName }}
|
</a-select-option>
|
</a-select> -->
|
<el-select style="width: 100%" v-model="form.roleId" placeholder="请选择">
|
<el-option v-for="item in roleList" :key="item.roleId" :label="item.roleName" :value="item.roleId">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="手机号码" prop="adminPhone" v-if="!form.id">
|
<el-input v-model="form.adminPhone" placeholder="请输入手机号码" />
|
</el-form-item>
|
|
<!-- roleList -->
|
<!-- <el-form-item label="代理角色" prop="isLock">
|
<el-input v-model="form.isLock" placeholder="请输入${comment}" />
|
</el-form-item> -->
|
<!-- <el-form-item label="添加时间" prop="addTime">
|
<el-date-picker
|
clearable
|
size="small"
|
style="width: 200px"
|
v-model="form.addTime"
|
type="date"
|
value-format="yyyy-MM-dd"
|
placeholder="选择添加时间"
|
>
|
</el-date-picker>
|
</el-form-item> -->
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="cancel">取 消</el-button>
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { listAdmin, getAdmin, delAdmin, addAdmin, updateAdmin, exportAdmin } from '@/api/system/admin'
|
import { listRole } from '@/api/system/role'
|
import Pagination from '@/components/Pagination/index.vue'
|
|
export default {
|
name: 'Admin',
|
components: { Pagination },
|
data() {
|
return {
|
// 遮罩层
|
loading: true,
|
// 选中数组
|
ids: [],
|
// 非单个禁用
|
single: true,
|
// 非多个禁用
|
multiple: true,
|
// 显示搜索条件
|
showSearch: true,
|
// 总条数
|
total: 0,
|
// 管理员表格数据
|
adminList: [],
|
// 弹出层标题
|
title: '',
|
// 是否显示弹出层
|
open: false,
|
// 查询参数
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
adminName: null,
|
adminPwd: null,
|
adminPhone: null,
|
addTime: null,
|
},
|
// 表单参数
|
form: {},
|
// 表单校验
|
rules: {
|
adminPwd: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
|
adminName: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
|
adminPhone: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
|
roleId: [{ required: true, message: '角色不能为空', trigger: 'blur' }],
|
},
|
roleList: [],
|
}
|
},
|
created() {
|
this.getList()
|
this.getrole()
|
},
|
methods: {
|
// 查询角色里表
|
getrole() {
|
listRole().then((response) => {
|
this.roleList = response.rows
|
console.log(this.roleList, 'aa 啊')
|
})
|
},
|
|
setData(data) {
|
let arr = []
|
for (let index = 0; index < data.length; index++) {
|
const element = data[index]
|
|
arr.push({
|
roleId: element.roleId,
|
roleName: element.roleName,
|
...element.siteAdmin,
|
})
|
}
|
return arr
|
},
|
/** 查询管理员列表 */
|
getList() {
|
this.loading = true
|
listAdmin(this.queryParams).then((response) => {
|
this.adminList = this.setData(response.rows)
|
this.total = response.total
|
console.log(this.adminList)
|
this.loading = false
|
})
|
},
|
// 取消按钮
|
cancel() {
|
this.open = false
|
this.reset()
|
},
|
// 表单重置
|
reset() {
|
this.form = {
|
id: null,
|
adminName: null,
|
adminPwd: null,
|
adminPhone: null,
|
isLock: null,
|
addTime: null,
|
}
|
this.resetForm('form')
|
},
|
/** 搜索按钮操作 */
|
handleQuery() {
|
this.queryParams.pageNum = 1
|
this.getList()
|
},
|
/** 重置按钮操作 */
|
resetQuery() {
|
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.open = true
|
this.title = '添加管理员'
|
},
|
/** 修改按钮操作 */
|
handleUpdate(row) {
|
this.reset()
|
const id = row.id || this.ids
|
getAdmin(id).then((response) => {
|
this.form = row
|
this.form.addTime = this.parseTime(this.form.addTime, '{y}-{m}-{d}')
|
this.form.adminPwd = ''
|
this.open = true
|
this.title = '修改管理员'
|
})
|
},
|
/** 提交按钮 */
|
submitForm() {
|
console.log(this.parseTime(new Date(), '{y}-{m}-{d}'))
|
this.$refs['form'].validate((valid) => {
|
if (valid) {
|
if (this.form.id != null) {
|
updateAdmin(this.form).then((response) => {
|
this.msgSuccess('修改成功')
|
this.open = false
|
this.getList()
|
})
|
} else {
|
this.form.addTime = this.parseTime(new Date(), '{y}-{m}-{d}')
|
addAdmin(this.form).then((response) => {
|
if (response.code === 200) {
|
this.msgSuccess('新增成功')
|
this.open = false
|
this.getList()
|
} else {
|
this.$message.error('新增失败')
|
}
|
})
|
}
|
}
|
})
|
},
|
/** 删除按钮操作 */
|
handleDelete(row) {
|
const ids = row.id || this.ids
|
this.$confirm('是否确认删除管理员编号为"' + ids + '"的数据项?', '警告', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then(function () {
|
return delAdmin(ids)
|
})
|
.then(() => {
|
this.getList()
|
this.msgSuccess('删除成功')
|
})
|
},
|
/** 导出按钮操作 */
|
handleExport() {
|
const queryParams = this.queryParams
|
this.$confirm('是否确认导出所有管理员数据项?', '警告', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then(function () {
|
return exportAdmin(queryParams)
|
})
|
.then((response) => {
|
this.download(response.msg)
|
})
|
},
|
},
|
}
|
</script>
|