<template>
|
<div class="user viewWrap">
|
<h2>用户管理</h2>
|
<!-- 搜索功能区 -->
|
<div class="wrap">
|
<div class="searchWrap">
|
<div class="searchItem">
|
<span class="searchTitle">姓名</span>
|
<el-input v-model="name" placeholder="请输入内容" clearable style="width:220px;"></el-input>
|
</div>
|
<div class="searchItem">
|
<span class="searchTitle">手机号</span>
|
<el-input v-model="phone" placeholder="请输入内容" clearable style="width:220px;"></el-input>
|
</div>
|
<div class="searchItem">
|
<span class="searchTitle">状态</span>
|
<el-select v-model="disabled" placeholder="请选择" style="width:220px;" clearable>
|
<el-option label="全部" :value="null"> </el-option>
|
<el-option label="禁用" :value="true"> </el-option>
|
<el-option label="启用" :value="false"> </el-option>
|
</el-select>
|
</div>
|
<div class="searchButton">
|
<el-button type="primary" @click="onGetSearchData">查询</el-button>
|
<el-button @click="onClearSearchData">清空</el-button>
|
</div>
|
</div>
|
</div>
|
|
<!-- 数据功能按钮区 -->
|
<el-button type="primary" style="margin-top: 20px; width: 100px;" icon="el-icon-plus"
|
@click="handleFormDataAdd">添加</el-button>
|
|
<!-- 数据表格区 -->
|
<el-table stripe :data="tableData" height="0" style="margin-top: 20px;">
|
<el-table-column type="index" label="序号"> </el-table-column>
|
<el-table-column prop="name" label="姓名"> </el-table-column>
|
<el-table-column label="二维码" width="150">
|
<template slot-scope="scope">
|
<el-button @click.native.prevent="handleShowCode(scope.row)" type="text" size="small">
|
<i class="iconfont icon-erweima" style="font-size: 12px;"></i>
|
查看二维码
|
</el-button>
|
</template>
|
</el-table-column>
|
<el-table-column prop="phone" label="手机号" width="140">
|
</el-table-column>
|
<el-table-column prop="disabled" label="状态" width="180">
|
<template slot-scope="scope">
|
<el-switch v-model="scope.row.disabled" active-color="#ff0000" active-text="禁用" inactive-color="#409EFF"
|
inactive-text="启用" @change="handleDisabled(scope.row)">
|
</el-switch>
|
</template>
|
</el-table-column>
|
<el-table-column prop="dt" label="创建时间" width="180">
|
</el-table-column>
|
<el-table-column label="操作" width="220">
|
<template slot-scope="scope">
|
<el-button icon="el-icon-edit" @click.native.prevent="handleFormDataEdit(scope.row)" type="text" size="small">
|
编辑
|
</el-button>
|
<el-button @click.native.prevent="handleDelete(scope.row)" type="text" size="small" icon="el-icon-delete">
|
删除
|
</el-button>
|
<el-button @click.native.prevent="handleSetDefaultPassword(scope.row)" type="text" size="small"
|
icon="el-icon-refresh">
|
重置密码
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<!-- 分页组件 -->
|
<el-pagination style="margin-top: 20px;" @size-change="onGetTableData" @current-change="onGetTableData"
|
:current-page.sync="pageCurr" :page-size.sync="pageSize" :page-sizes="[10, 20, 50, 100]"
|
layout="total, sizes, prev, pager, next, jumper" :total="total">
|
</el-pagination>
|
|
<!-- 表单 -->
|
<el-dialog title="用户信息" :visible.sync="showFromData" width="600px" :before-close="handleFormDataClose">
|
<el-form :model="formData" :rules="formRules" ref="formData" label-width="80px">
|
<el-form-item label="用户ID" prop="id" style="display: none;">
|
<el-input style="width:220px" v-model="formData.id" disabled></el-input>
|
</el-form-item>
|
<el-form-item label="姓名" prop="name">
|
<el-input style="width:220px" v-model="formData.name" clearable></el-input>
|
</el-form-item>
|
<el-form-item label="手机号" prop="phone">
|
<el-input style="width:220px" v-model="formData.phone" clearable></el-input>
|
</el-form-item>
|
<el-form-item label="状态" prop="disabled">
|
<el-switch v-model="formData.disabled" active-color="#ff0000" active-text="禁用" inactive-color="#409EFF"
|
inactive-text="启用" />
|
</el-form-item>
|
<el-form-item label="角色">
|
<div>
|
<div class="typeName">请选择角色</div>
|
<el-row style="margin:10px 0;">
|
<el-col v-for="(item, index) in roleData" :key="index" :span="6">
|
<el-checkbox :value="returnCheck(item.id)" :label="item.name"
|
@change="handleCheck(item.id)"></el-checkbox>
|
</el-col>
|
</el-row>
|
</div>
|
</el-form-item>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="handleFormDataClose">取 消</el-button>
|
<el-button type="primary" @click="handleFormDataSubmit">确 定</el-button>
|
</span>
|
</el-dialog>
|
|
<!-- 二维码 -->
|
<div class="codeWrap" v-show="showCode" @click="handleCloseCode">
|
<transition name="el-zoom-in-center">
|
<img v-show="showCode" :src="imgBase64">
|
</transition>
|
<div class="codeMessage">点击屏幕关闭二维码</div>
|
</div>
|
</div>
|
</template>
|
|
<style lang="less" scoped></style>
|
|
<script>
|
|
export default {
|
name: "user",
|
components: {},
|
data() {
|
return {
|
name: null,
|
phone: null,
|
disabled: null,
|
pageSize: 10,
|
pageCurr: 1,
|
total: 0,
|
tableData: [],
|
roleData: [],
|
showFromData: false,
|
formData: {
|
id: null,
|
name: null,
|
phone: null,
|
disabled: false,
|
roleIds: [],
|
},
|
formRules: {
|
name: [{ required: true, message: "必填项", trigger: "blur" }],
|
disabled: [{ required: true, message: "必填项", trigger: "blur" }],
|
phone: [{ required: true, message: "必填项", trigger: "blur" }],
|
},
|
defaultPassword: null,
|
showCode: false,
|
codeObj: null,
|
imgBase64: null,
|
};
|
},
|
computed: {},
|
mounted() {
|
this.onGetTableData();
|
this.onGetRoleData();
|
this.onGetDefaultPassword();
|
},
|
methods: {
|
// 路由跳转
|
goto: function (path) {
|
if (path != this.$route.name) {
|
this.$router.push({
|
name: path,
|
});
|
}
|
},
|
// 执行条件查询
|
onGetSearchData: function () {
|
this.pageCurr = 1;
|
this.onGetTableData();
|
},
|
// 清空查询条件
|
onClearSearchData: function () {
|
this.name = null;
|
this.disabled = null;
|
this.phone = null;
|
this.pageCurr = 1;
|
this.onGetTableData();
|
},
|
// 获取表格数据
|
onGetTableData: function () {
|
var that = this;
|
var data = {
|
name: this.name,
|
disabled: this.disabled,
|
phone: this.phone,
|
pageSize: this.pageSize,
|
pageCurr: this.pageCurr,
|
};
|
that
|
.$axiosAdmin({
|
method: "post",
|
url: "base/user/some",
|
data: JSON.stringify(data),
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.tableData = res.content.obj;
|
that.total = res.content.itemTotal;
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
// 状态变更确认
|
handleDisabled(row) {
|
this.$confirm(`此操作将变更 ${row.name} 的状态, 是否继续?`, "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
this.onDisabled(row);
|
})
|
.catch(() => {
|
this.onGetTableData();
|
this.$message({
|
type: "info",
|
message: "已取消",
|
});
|
});
|
},
|
// 执行状态变更
|
onDisabled: function (row) {
|
var that = this;
|
var data = {
|
id: row.id,
|
disabled: row.disabled,
|
};
|
that
|
.$axiosAdmin({
|
method: "post",
|
url: "base/user/disabled",
|
data: JSON.stringify(data),
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.$message({
|
type: "success",
|
message: "已成功",
|
});
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
that.onGetTableData();
|
})
|
.catch((err) => {
|
console.log(err);
|
that.onGetTableData();
|
});
|
},
|
// 删除确认
|
handleDelete(row) {
|
this.$confirm(`此操作将删除 ${row.name} , 是否继续?`, "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
this.onDelete(row);
|
})
|
.catch(() => {
|
this.$message({
|
type: "info",
|
message: "已取消",
|
});
|
});
|
},
|
// 执行删除
|
onDelete: function (row) {
|
var that = this;
|
var params = {
|
id: row.id,
|
};
|
that
|
.$axiosAdmin({
|
method: "get",
|
url: "base/user/delete",
|
params: params,
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.$message({
|
type: "success",
|
message: "已成功",
|
});
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
that.onGetTableData();
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
// 添加
|
handleFormDataAdd: function () {
|
this.formData.id = null;
|
this.formData.name = null;
|
this.formData.phone = null;
|
this.formData.disabled = false;
|
this.formData.roleIds = [];
|
this.showFromData = true;
|
this.onGetRoleData();
|
this.onGetDefaultPassword();
|
},
|
// 关闭
|
handleFormDataClose: function () {
|
this.formData.id = null;
|
this.formData.name = null;
|
this.formData.phone = null;
|
this.formData.disabled = false;
|
this.formData.roleIds = [];
|
this.showFromData = false;
|
this.$refs['formData'].resetFields();
|
},
|
// 编辑
|
handleFormDataEdit: function (row) {
|
this.formData.id = row.id;
|
this.formData.name = row.name;
|
this.formData.phone = row.phone;
|
this.formData.disabled = row.disabled;
|
this.formData.roleIds = [];
|
row.roles.forEach((item) => {
|
this.formData.roleIds.push(item.id);
|
});
|
this.showFromData = true;
|
this.onGetRoleData();
|
},
|
// 查询角色
|
onGetRoleData: function () {
|
var that = this;
|
that
|
.$axiosAdmin({
|
method: "get",
|
url: "base/role/all",
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.roleData = res.content;
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
// 检查选中状态
|
returnCheck: function (id) {
|
if (this.formData.roleIds.indexOf(id) == -1) {
|
return false;
|
} else {
|
return true;
|
}
|
},
|
// 管理选中状态
|
handleCheck: function (id) {
|
if (this.formData.roleIds.indexOf(id) == -1) {
|
this.formData.roleIds.push(id);
|
} else {
|
this.formData.roleIds.splice(this.formData.roleIds.indexOf(id), 1);
|
}
|
},
|
// 提交数据确认
|
handleFormDataSubmit: function () {
|
this.$confirm(`此操作将保存并更新数据, 是否继续?`, "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
this.onFormDataSubmit();
|
})
|
.catch(() => {
|
this.$message({
|
type: "info",
|
message: "已取消",
|
});
|
});
|
},
|
// 提交数据
|
onFormDataSubmit: function () {
|
var that = this;
|
var url, data;
|
if (this.formData.id) {
|
url = "base/user/update";
|
data = {
|
id: this.formData.id,
|
name: this.formData.name,
|
phone: this.formData.phone,
|
disabled: this.formData.disabled,
|
roleIds: this.formData.roleIds,
|
password: "000000",
|
};
|
} else {
|
url = "base/user/save";
|
data = {
|
password: this.defaultPassword,
|
name: this.formData.name,
|
phone: this.formData.phone,
|
disabled: this.formData.disabled,
|
roleIds: this.formData.roleIds,
|
};
|
}
|
that
|
.$axiosAdmin({
|
method: "post",
|
url: url,
|
data: JSON.stringify(data),
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.$message({
|
type: "success",
|
message: "已成功",
|
});
|
that.handleFormDataClose();
|
that.onGetTableData();
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
// 获取系统默认密码
|
onGetDefaultPassword: function () {
|
var that = this;
|
var params = {};
|
that
|
.$axiosAdmin({
|
method: "get",
|
url: "base/user/defaultPassword",
|
params: params,
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.defaultPassword = res.content;
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
// 确认重置密码
|
handleSetDefaultPassword: function (row) {
|
this.onGetDefaultPassword();
|
this.$confirm(`此操作将重置 ${row.name} 的登录密码为 ${this.defaultPassword} , 是否继续?`, "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
this.onSetDefaultPassword(row);
|
})
|
.catch((err) => {
|
this.$message({
|
type: "info",
|
message: "已取消",
|
});
|
});
|
},
|
// 重置密码
|
onSetDefaultPassword: function (row) {
|
var that = this;
|
var data = {
|
id: row.id,
|
password: this.defaultPassword,
|
};
|
that
|
.$axiosAdmin({
|
method: "post",
|
url: "base/user/resetPassword",
|
data: JSON.stringify(data),
|
})
|
.then((res) => {
|
if (res.success == true) {
|
that.$message({
|
type: "success",
|
message: "已成功",
|
});
|
} else {
|
that.$alert(res.content, "提示", {
|
confirmButtonText: "确定",
|
});
|
}
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
// 生成二维码
|
handleShowCode: function (row) {
|
this.imgBase64 = row.qrCode
|
this.showCode = true;
|
},
|
// 关闭二维码
|
handleCloseCode: function () {
|
this.imgBase64 = null
|
this.showCode = false;
|
},
|
},
|
};
|
</script>
|