From 363c1aadabc3d62ddf36a9f8989591174116f6cd Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Thu, 1 Feb 2024 17:04:47 +0800 Subject: [PATCH] patch: getAllUserCurrent --- src/Manager/components/User.vue | 125 ++++++++++---------------------- 1 file changed, 40 insertions(+), 85 deletions(-) diff --git a/src/Manager/components/User.vue b/src/Manager/components/User.vue index 0c7a5e4..9f72534 100644 --- a/src/Manager/components/User.vue +++ b/src/Manager/components/User.vue @@ -55,7 +55,7 @@ 用户名: - 电话: + 电话:
@@ -82,34 +82,7 @@
- - - +
@@ -118,8 +91,6 @@ import {computed, onMounted, reactive, ref} from 'vue'; import {DeleteOutlined, EditOutlined, PlusOutlined, SearchOutlined} from '@ant-design/icons-vue'; import {message} from "ant-design-vue"; -import {usePagination} from 'vue-request'; -import axios from 'axios'; import requests from "@/public/request.js"; const value1 = ref(''); @@ -128,7 +99,9 @@ const AddDiaLog = ref(false); const DeleteDiaLog = ref(false); const EditDiaLog = ref(false); const DeleteId = ref(0); -let dataSource = [] +let dataSource = ref([]); +let data = ref([]); +const dataLoaded = ref(false); const token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxNiIsImV4cCI6MTcwNjc4OTgwNH0.Cx4NOfPh3QXH-pYRCSHxpUjdeUxBZABVb5Z82gK8sfI" const requestBody = { "page": null, @@ -400,19 +373,14 @@ const columns = [ }, { title: '用户状态', - dataIndex: 'user_state', + dataIndex: 'enabled', key: 'enabled', }, { title: '更新时间', key: 'updatedAt', dataIndex: 'updatedAt' - }, - { - title: '操作', - key:'user_action', - dataIndex: 'user_action', - }, + } ]; const rowSelection = { @@ -425,56 +393,43 @@ const rowSelection = { }), }; -const queryData = params => { - return axios.get('https://randomuser.me/api?noinfo', { - params, - }); -}; -const { - run, - loading, - current, - pageSize, -} = usePagination(queryData, { - formatResult: res => res.data.results, - pagination: { - currentKey: 'page', - pageSizeKey: 'results', - }, -}); -const pagination = computed(() => ({ - total: 200, - current: current.value, - pageSize: pageSize.value, -})); -const handleTableChange = (pag, filters, sorter) => { - run({ - results: pag.pageSize, - page: pag?.current, - sortField: sorter.field, - sortOrder: sorter.order, - ...filters, - }); -}; - - -requests.userAllCurrent(requestBody, token).then((res) => { - const getUserData = res.data.data.users - for (let i = 0; i < res.data.data.count; i++) { - dataSource[i] = { - id: i, - username: getUserData[i].user.username, - phone: getUserData[i].user.phone, - enabled: getUserData[i].user.enabled, - updatedAt: getUserData[i].user.updatedAt +async function fetchData() { + try { + const queryData = await requests.userAllCurrent( + { + page: null, + limit: null, + search: null, + role: null + }, + "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNzA2ODU0Nzk1fQ.A5kh3jSxbkvHmfEyp9MTp9--N0HdoiEREkKdPgcfXOk" + ); + console.log(queryData.data); // 访问数据 + dataSource.value = queryData.data.data; + dataLoaded.value = true; + for (let i = 0; i <= dataSource.value.count; i++) { + if (dataSource.value.users[i].user.updatedAt === null) { + dataSource.value.users[i].user.updatedAt = "null" + } + data.value.push({ + username: dataSource.value.users[i].user.username, + nickname: dataSource.value.users[i].user.nickname, + phone: dataSource.value.users[i].user.phone, + enabled: dataSource.value.users[i].user.enabled, + updatedAt: dataSource.value.users[i].user.updatedAt, + }); } + console.log(data.value); + } catch (error) { + console.error(error); } -}) +} console.log(dataSource) - - - +// 组件挂载时调用 fetchData +onMounted(() => { + fetchData(); +});