完成“分页查找用户”、“重置密码”功能

This commit is contained in:
CGD
2025-04-02 10:57:26 +08:00
parent 143d33e285
commit 198755c3f5
3 changed files with 113 additions and 27 deletions
+17
View File
@@ -40,5 +40,22 @@ export default {
this.deleteUser(id, callback) this.deleteUser(id, callback)
}) })
}).send() }).send()
},
// 重置用户密码
resetUserPassword(id, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/api/v1/admin/users/${id}`)
.method('PUT')
.success((res) => {
RequestService.clearRequestTime()
callback(res)
})
.fail((err) => {
console.error('重置密码失败:', err)
RequestService.reAjaxFun(() => {
this.resetUserPassword(id, callback)
})
}).send()
} }
} }
@@ -0,0 +1,77 @@
<template>
<el-dialog :visible.sync="visible" width="400px" center>
<div style="margin: 22px 15px;">
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;">
<div style="color: red;display: inline-block;">*</div>
用户密码
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input v-model="password" type="text" :readonly="true" style="font-weight: bold; color: #333;"/>
</div>
</div>
<div style="display: flex;margin: 15px 15px;gap: 7px;">
<div class="dialog-btn" style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;" @click="closeDialog">
关闭
</div>
<div class="dialog-btn" style="background: #5778ff;color: white;" @click="copyPassword">
复制密码
</div>
</div>
</el-dialog>
</template>
<script>
export default {
name: 'ViewPasswordDialog',
props: {
visible: { type: Boolean, required: true },
password: { type: String, default: '' }
},
methods: {
closeDialog() {
this.$emit('update:visible', false)
},
copyPassword() {
navigator.clipboard.writeText(this.password)
this.$message.success('密码已复制')
}
}
}
</script>
<style scoped>
.input-46 {
border: 1px solid #e4e6ef;
background: #f6f8fb;
border-radius: 15px;
}
.dialog-btn {
cursor: pointer;
flex: 1;
border-radius: 23px;
height: 40px;
font-weight: 500;
font-size: 12px;
line-height: 40px;
text-align: center;
}
::v-deep .el-dialog {
border-radius: 15px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
::v-deep .el-dialog__headerbtn {
display: none;
}
::v-deep .el-dialog__body {
padding: 4px 6px;
}
::v-deep .el-input__inner {
background-color: #f6f8fb !important;
cursor: default !important;
}
</style>
+19 -27
View File
@@ -42,13 +42,7 @@
<button class="pagination-btn" :disabled="currentPage === 1" @click="goFirst">首页</button> <button class="pagination-btn" :disabled="currentPage === 1" @click="goFirst">首页</button>
<button class="pagination-btn" :disabled="currentPage === 1" @click="goPrev">上一页</button> <button class="pagination-btn" :disabled="currentPage === 1" @click="goPrev">上一页</button>
<button <button v-for="page in visiblePages" :key="page" class="pagination-btn" :class="{ active: page === currentPage }" @click="goToPage(page)">
v-for="page in visiblePages"
:key="page"
class="pagination-btn"
:class="{ active: page === currentPage }"
@click="goToPage(page)"
>
{{ page }} {{ page }}
</button> </button>
@@ -61,6 +55,7 @@
<div style="font-size: 12px; font-weight: 400; margin-top: auto; padding-top: 30px; color: #979db1;"> <div style="font-size: 12px; font-weight: 400; margin-top: auto; padding-top: 30px; color: #979db1;">
©2025 xiaozhi-esp32-server ©2025 xiaozhi-esp32-server
</div> </div>
<view-password-dialog :visible.sync="showViewPassword" :password="currentPassword"/>
</el-main> </el-main>
</div> </div>
</template> </template>
@@ -68,12 +63,14 @@
<script> <script>
import HeaderBar from "@/components/HeaderBar.vue"; import HeaderBar from "@/components/HeaderBar.vue";
import adminApi from '@/apis/module/admin'; import adminApi from '@/apis/module/admin';
import ViewPasswordDialog from '@/components/ViewPasswordDialog.vue'
export default { export default {
components: { HeaderBar }, components: { HeaderBar, ViewPasswordDialog },
data() { data() {
return { return {
showViewPassword: false,
currentPassword: '', // 存储获取到的密码
searchPhone: '', searchPhone: '',
userList: [], userList: [],
currentPage: 1, currentPage: 1,
@@ -86,9 +83,7 @@ export default {
}, },
computed: { computed: {
pageCount() { pageCount() {
const count = Math.ceil(this.total / this.pageSize); return Math.ceil(this.total / this.pageSize);
console.log('总页数计算:', this.total, '/', this.pageSize, '=', count);
return count;
}, },
visiblePages() { visiblePages() {
const pages = []; const pages = [];
@@ -109,19 +104,11 @@ export default {
methods: { methods: {
// 获取用户列表 // 获取用户列表
fetchUsers() { fetchUsers() {
console.log('请求参数:', {
page: this.currentPage,
limit: this.pageSize,
mobile: this.searchPhone
});
adminApi.getUserList({ adminApi.getUserList({
page: this.currentPage, page: this.currentPage,
limit: this.pageSize, limit: this.pageSize,
mobile: this.searchPhone mobile: this.searchPhone
}, ({ data }) => { }, ({ data }) => {
console.log('响应数据:', data);
if (data.code === 0) { if (data.code === 0) {
this.userList = data.data.list.map(user => ({ this.userList = data.data.list.map(user => ({
...user, ...user,
@@ -143,9 +130,17 @@ export default {
batchDisable() { batchDisable() {
console.log('执行批量禁用操作'); console.log('执行批量禁用操作');
}, },
// 重置密码
resetPassword(row) { resetPassword(row) {
console.log('重置用户密码,用户:', row); adminApi.resetUserPassword(row.userid, ({ data }) => {
}, if (data.code === 0) {
this.currentPassword = data.data
this.showViewPassword = true
} else {
this.$message.error(data.msg || '获取密码失败')
}
})
},
disableUser(row) { disableUser(row) {
row.status = '禁用'; row.status = '禁用';
console.log('禁用用户:', row); console.log('禁用用户:', row);
@@ -154,6 +149,7 @@ export default {
row.status = '正常'; row.status = '正常';
console.log('恢复用户:', row); console.log('恢复用户:', row);
}, },
// 用户删除
deleteUser(row) { deleteUser(row) {
this.$confirm('确定要删除该用户吗?', '警告', { this.$confirm('确定要删除该用户吗?', '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
@@ -161,10 +157,8 @@ export default {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
adminApi.deleteUser(row.userid, ({data}) => { adminApi.deleteUser(row.userid, ({data}) => {
console.log("33333333")
if (data.code === 0) { if (data.code === 0) {
this.$message.success('删除成功') this.$message.success('删除成功')
// 删除后重新获取数据(或前端直接过滤)
this.fetchUsers() this.fetchUsers()
} else { } else {
this.$message.error(data.msg || '删除失败') this.$message.error(data.msg || '删除失败')
@@ -184,7 +178,7 @@ export default {
}, },
goFirst() { goFirst() {
this.currentPage = 1; this.currentPage = 1;
this.handleCurrentChange(1); this.fetchUsers();
}, },
goPrev() { goPrev() {
if (this.currentPage > 1) { if (this.currentPage > 1) {
@@ -193,9 +187,7 @@ export default {
} }
}, },
goNext() { goNext() {
console.log("1111111111111")
if (this.currentPage < this.pageCount) { if (this.currentPage < this.pageCount) {
console.log("2222222222")
this.currentPage++; this.currentPage++;
this.fetchUsers(); this.fetchUsers();
} }