mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
完成”获取用户列表“
This commit is contained in:
@@ -5,16 +5,19 @@ import {getServiceUrl} from '../api'
|
|||||||
export default {
|
export default {
|
||||||
// 用户列表
|
// 用户列表
|
||||||
getUserList(callback) {
|
getUserList(callback) {
|
||||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/admin/users`)
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/admin/users`)
|
||||||
.method('GET')
|
.method('GET')
|
||||||
.success((res) => {
|
.success((res) => {
|
||||||
RequestService.clearRequestTime()
|
RequestService.clearRequestTime()
|
||||||
callback(res)
|
callback(res)
|
||||||
})
|
})
|
||||||
.fail(() => {
|
.fail((err) => {
|
||||||
|
console.error('请求失败:', err)
|
||||||
RequestService.reAjaxFun(() => {
|
RequestService.reAjaxFun(() => {
|
||||||
this.getList()
|
this.getUserList(callback)
|
||||||
})
|
})
|
||||||
}).send()
|
})
|
||||||
},
|
.send()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@
|
|||||||
<el-button size="mini" type="text" @click="resetPassword(scope.row)" style="color: #989fdd">重置密码</el-button>
|
<el-button size="mini" type="text" @click="resetPassword(scope.row)" style="color: #989fdd">重置密码</el-button>
|
||||||
<el-button size="mini" type="text"
|
<el-button size="mini" type="text"
|
||||||
v-if="scope.row.status === '正常'"
|
v-if="scope.row.status === '正常'"
|
||||||
@click="disableUser(scope.row)">禁用</el-button>
|
@click="disableUser(scope.row)">禁用账户</el-button>
|
||||||
<el-button size="mini" type="text"
|
<el-button size="mini" type="text"
|
||||||
v-if="scope.row.status === '禁用'"
|
v-if="scope.row.status === '禁用'"
|
||||||
@click="restoreUser(scope.row)">恢复</el-button>
|
@click="restoreUser(scope.row)">恢复账号</el-button>
|
||||||
<el-button size="mini" type="text" @click="deleteUser(scope.row)" style="color: #989fdd">删除用户</el-button>
|
<el-button size="mini" type="text" @click="deleteUser(scope.row)" style="color: #989fdd">删除用户</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -76,25 +76,16 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
searchPhone: '',
|
searchPhone: '',
|
||||||
userList: [
|
userList: [],
|
||||||
{ userId: '123456', phone: '13800138000', status: '正常', deviceCount: 10 },
|
|
||||||
{ userId: '123456', phone: '13800138000', status: '正常', deviceCount: 9 },
|
|
||||||
{ userId: '123456', phone: '13800138000', status: '正常', deviceCount: 7 },
|
|
||||||
{ userId: '123456', phone: '13800138000', status: '禁用', deviceCount: 7 }
|
|
||||||
],
|
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 5,
|
pageSize: 5,
|
||||||
total: 20
|
total: 20
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
adminApi.getUserList(({data}) => {
|
this.fetchUsers();
|
||||||
//mock偶尔会返回-1导致出错,又会返回两个list,所以这里只取第一个
|
|
||||||
this.userList = data.data[0].list;
|
|
||||||
console.log('用户列表:', this.userList);
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
pageCount() {
|
pageCount() {
|
||||||
return Math.ceil(this.total / this.pageSize);
|
return Math.ceil(this.total / this.pageSize);
|
||||||
},
|
},
|
||||||
@@ -115,9 +106,37 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 获取用户列表
|
||||||
|
fetchUsers() {
|
||||||
|
adminApi.getUserList(({data}) => {
|
||||||
|
if (data.code === 0) {
|
||||||
|
const responseData = data.data[0] || data.data
|
||||||
|
|
||||||
|
this.userList = responseData.list.map(user => ({
|
||||||
|
...user,
|
||||||
|
status: user.status === '1' ? '正常' : '禁用'
|
||||||
|
}))
|
||||||
|
|
||||||
|
this.total = responseData.totalCount || 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 分页变化
|
||||||
|
handleCurrentChange(page) {
|
||||||
|
this.currentPage = page;
|
||||||
|
this.fetchUsers();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 搜索
|
||||||
handleSearch() {
|
handleSearch() {
|
||||||
// 模拟搜索逻辑
|
if (!this.searchPhone) {
|
||||||
console.log('执行查询,搜索号码:', this.searchPhone);
|
this.fetchUsers()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.userList = this.userList.filter(user =>
|
||||||
|
user.mobile.includes(this.searchPhone)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
batchDelete() {
|
batchDelete() {
|
||||||
console.log('执行批量删除操作');
|
console.log('执行批量删除操作');
|
||||||
@@ -139,10 +158,6 @@ export default {
|
|||||||
deleteUser(row) {
|
deleteUser(row) {
|
||||||
console.log('删除用户:', row);
|
console.log('删除用户:', row);
|
||||||
},
|
},
|
||||||
handleCurrentChange(page) {
|
|
||||||
this.currentPage = page;
|
|
||||||
console.log('当前页码:', page);
|
|
||||||
},
|
|
||||||
handleSizeChange(val) {
|
handleSizeChange(val) {
|
||||||
this.pageSize = val;
|
this.pageSize = val;
|
||||||
console.log('每页条数:', val);
|
console.log('每页条数:', val);
|
||||||
|
|||||||
Reference in New Issue
Block a user