Skip to content

Commit

Permalink
feat: sort
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Sep 6, 2024
1 parent 3549930 commit 23d2bdf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default {
'pages.account.nijiMode': 'niji模式',
'pages.account.remark': '备注',
'pages.account.disabledReason': '禁用原因',

'pages.account.sync': '同步',
'pages.account.add': '新增账号',
'pages.account.updateAndReconnect': '更新账号并重连',
Expand Down Expand Up @@ -165,7 +166,7 @@ export default {
'pages.account.allowModes': '允许生成速度模式',
'pages.account.timeoutMinutes': '任务超时时间',
'pages.account.weight': '权重',
'pages.account.dateCreated': '创建时间',
'pages.account.dateCreated': '添加时间',
'pages.account.mjSettings': 'MJ设置',
'pages.account.nijiSettings': 'Niji设置',
'pages.account.updateNotice': '注意:更新账号并重连后,该账号执行中的任务将会丢失!',
Expand Down
33 changes: 30 additions & 3 deletions src/pages/AccountList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PageContainer, ProTable } from '@ant-design/pro-components';
import { useIntl } from '@umijs/max';
import { Button, Card, Form, Modal, notification, Space, Tag, Tooltip } from 'antd';
import { ColumnType } from 'antd/lib/table';
import moment from 'moment';
import React, { useEffect, useRef, useState } from 'react';

const AccountList: React.FC = () => {
Expand Down Expand Up @@ -185,6 +186,7 @@ const AccountList: React.FC = () => {
dataIndex: 'guildId',
width: 200,
align: 'center',
sorter: true,
render: (text: string, record: Record<string, any>) => (
<a
onClick={() => {
Expand All @@ -205,6 +207,7 @@ const AccountList: React.FC = () => {
dataIndex: 'channelId',
align: 'center',
width: 200,
sorter: true,
} as ColumnType<Record<string, any>>,
// {
// title: intl.formatMessage({ id: 'pages.account.username' }),
Expand All @@ -217,6 +220,7 @@ const AccountList: React.FC = () => {
dataIndex: 'enable',
width: 200,
align: 'center',
sorter: true,
request: async () => [
{
label: intl.formatMessage({ id: 'pages.enable' }),
Expand Down Expand Up @@ -341,6 +345,7 @@ const AccountList: React.FC = () => {
dataIndex: 'sponsor',
ellipsis: true,
width: 100,
sorter: true,
// 赞助商 - 富文本
render: (text: string, record: Record<string, any>) => (
<div dangerouslySetInnerHTML={{ __html: record.sponsor || '-' }} />
Expand All @@ -350,6 +355,7 @@ const AccountList: React.FC = () => {
title: intl.formatMessage({ id: 'pages.account.remark' }),
dataIndex: 'remark',
ellipsis: true,
sorter: true,
width: 150,
} as ColumnType<Record<string, any>>,
{
Expand All @@ -361,6 +367,16 @@ const AccountList: React.FC = () => {
// renderText: (text: string, record: Record<string, any>) =>
// record['properties']['disabledReason'],
} as ColumnType<Record<string, any>>,
{
title: intl.formatMessage({ id: 'pages.account.dateCreated' }),
dataIndex: 'dateCreated',
ellipsis: true,
width: 140,
sorter: true,
hideInSearch: true,
renderText: (text: string, record: Record<string, any>) =>
moment(text).format('YYYY-MM-DD HH:mm'),
} as ColumnType<Record<string, any>>,
{
title: intl.formatMessage({ id: 'pages.operation' }),
dataIndex: 'operation',
Expand Down Expand Up @@ -415,7 +431,12 @@ const AccountList: React.FC = () => {
onClick={() =>
openModal(
intl.formatMessage({ id: 'pages.account.update' }),
<UpdateContent r={Math.random()} form={form} record={record} onSubmit={handleUpdate} />,
<UpdateContent
r={Math.random()}
form={form}
record={record}
onSubmit={handleUpdate}
/>,
1000,
)
}
Expand Down Expand Up @@ -503,8 +524,14 @@ const AccountList: React.FC = () => {
{intl.formatMessage({ id: 'pages.add' })}
</Button>,
]}
request={async (params) => {
const res = await queryAccounts({ ...params, pageNumber: params.current! - 1 });
request={async (params, sort) => {
const kys = Object.keys(sort);
// console.log('params', params, sort, kys.length > 0 ? sort[kys[0]] : '');
const res = await queryAccounts(
{ ...params, pageNumber: params.current! - 1 },
kys.length > 0 ? kys[0] : '',
(kys.length > 0 ? sort[kys[0]] : '') == 'descend',
);
return {
data: res.list,
total: res.pagination.total,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const Welcome: React.FC = () => {
<PageContainer>
{data && data.notify && (
<Alert
message={data.notify}
description={data.notify}
banner
closable
style={{
Expand Down
6 changes: 3 additions & 3 deletions src/services/mj/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function queryAccount(options?: { [key: string]: any }) {
});
}

export async function queryAccounts(data: any, options?: { [key: string]: any }) {
export async function queryAccounts(data: any, predicate?: string, descend?: boolean, options?: { [key: string]: any }) {
return request<Record<string, any>>('/mj/admin/accounts', {
method: 'POST',
data: {
Expand All @@ -92,8 +92,8 @@ export async function queryAccounts(data: any, options?: { [key: string]: any })
pageSize: data?.pageSize || 10,
},
sort: {
predicate: '',
reverse: true,
predicate: predicate || '',
reverse: descend || true,
},
search: {
...data,
Expand Down

0 comments on commit 23d2bdf

Please sign in to comment.