Skip to content

Let's use AI to Earn!

feat: 【用户组】开发完成

gaoSir06c759065711
diff --git a/electron/db/index.ts b/electron/db/index.ts
index 7a2f6312..c0571541 100644
--- a/electron/db/index.ts
+++ b/electron/db/index.ts
@@ -59,6 +59,7 @@ async function sqliteDefaultDataInit() {
await accountGroupRepository.save({
id: defaultAccountGroupId,
name: '默认列表',
+ rank: 0,
});
}
}
diff --git a/electron/db/models/accountGroup.ts b/electron/db/models/accountGroup.ts
index a406483f..6cbf746f 100644
--- a/electron/db/models/accountGroup.ts
+++ b/electron/db/models/accountGroup.ts
@@ -28,7 +28,7 @@ export class AccountGroupModel extends TempModel {
type: 'int',
nullable: false,
comment: '组排序',
- default: 0,
+ default: 1,
})
rank!: number;
}
diff --git a/electron/main/account/controller.ts b/electron/main/account/controller.ts
index 69753ea4..fa9167ad 100644
--- a/electron/main/account/controller.ts
+++ b/electron/main/account/controller.ts
@@ -16,7 +16,6 @@ import { AccountModel } from '../../db/models/account';
import windowOperate from '../../util/windowOperate';
import { SendChannelEnum } from '../../../commont/UtilsEnum';
import { AccountGroupModel } from '../../db/models/accountGroup';
-import { Menu } from 'electron';
@Controller()
export class AccountController {
@@ -205,6 +204,18 @@ export class AccountController {
return this.accountService.deleteAccounts(ids, userInfo.id);
}
+ // 修改账户的账户组
+ @Icp('ICP_ACCOUNTS_EDIT_GROUP')
+ async accountEditGroup(
+ event: Electron.IpcMainInvokeEvent,
+ id: number,
+ groupId: number,
+ ): Promise<any> {
+ return this.accountService.updateAccountInfo(id, {
+ groupId,
+ });
+ }
+
// 添加用户组数据
@Icp('ICP_ACCOUNTS_GROUP_ADD')
async addAccountGroup(
diff --git a/electron/main/account/service.ts b/electron/main/account/service.ts
index d220bd16..ea5f738d 100644
--- a/electron/main/account/service.ts
+++ b/electron/main/account/service.ts
@@ -8,7 +8,10 @@ import { AppDataSource } from '../../db';
import { AccountModel } from '../../db/models/account';
import { Injectable } from '../core/decorators';
import { FindOptionsWhere, In, Repository } from 'typeorm';
-import { AccountType } from '../../../commont/AccountEnum';
+import {
+ AccountType,
+ defaultAccountGroupId,
+} from '../../../commont/AccountEnum';
import platController from '../plat/index';
import { EtEvent } from '../../global/event';
import { AccountGroupModel } from '../../db/models/accountGroup';
@@ -36,13 +39,25 @@ export class AccountService {
}
// 删除用户组数据
async deleteAccountGroup(id: number) {
- return await this.accountRepository.delete({
+ // 将删除的用户组下的账户账户的组id设置为默认组id
+ const accounts = await this.accountRepository.find({
+ where: { groupId: id },
+ });
+ await this.accountRepository.update(
+ { id: In(accounts.map((v) => v.id)) },
+ {
+ groupId: defaultAccountGroupId,
+ },
+ );
+
+ // 删除
+ return await this.accountGroupRepository.delete({
id: id,
});
}
// 修改用户组数据
async editAccountGroup(data: Partial<AccountGroupModel>) {
- return await this.accountRepository.update({ id: data.id }, data);
+ return await this.accountGroupRepository.update({ id: data.id }, data);
}
// 没有就添加有就更新cookie
@@ -195,6 +210,11 @@ export class AccountService {
return await this.accountRepository.findOne({ where: { id } });
}
+ // 更新用户信息
+ async updateAccountInfo(id: number, data: Partial<AccountModel>) {
+ await this.accountRepository.update(id, data);
+ }
+
// 更新账户的统计信息
async updateAccountStatistics(
id: number,
diff --git a/electron/main/index.ts b/electron/main/index.ts
index f38eddfc..efb1c9b8 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -11,8 +11,9 @@ import windowOperate from '../util/windowOperate';
import { logger } from '../global/log';
import { SplashWindow } from './splash';
import dotenv from 'dotenv';
-
import KwaiPubListener from './plat/platforms/Kwai/KwaiPubListener';
+import { registerContextMenuListener } from '@electron-uikit/contextmenu';
+
const platform = process.platform;
dotenv.config();
@@ -139,6 +140,8 @@ async function createWindow() {
app.whenReady().then(async () => {
try {
+ registerContextMenuListener();
+
// 创建应用实例,挂载功能
new App();
diff --git a/electron/preload/index.ts b/electron/preload/index.ts
index 2d6aab5f..17455bd8 100644
--- a/electron/preload/index.ts
+++ b/electron/preload/index.ts
@@ -1,4 +1,11 @@
import { contextBridge, ipcRenderer } from 'electron';
+import { exposeUIKit } from '@electron-uikit/core/preload';
+
+try {
+ exposeUIKit();
+} catch (e) {
+ console.error(e);
+}
// --------- Expose some API to the Renderer process ---------
contextBridge.exposeInMainWorld('ipcRenderer', {
diff --git a/package-lock.json b/package-lock.json
index 0df55af5..ae6ff190 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,7 +11,9 @@
"dependencies": {
"@ant-design/colors": "^7.2.0",
"@ant-design/icons": "^5.6.1",
+ "@electron-toolkit/preload": "^3.0.2",
"@electron-uikit/contextmenu": "^1.0.0",
+ "@electron-uikit/core": "^1.1.0",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@ffprobe-installer/ffprobe": "^2.1.2",
"@types/form-data": "^2.5.2",
@@ -574,6 +576,15 @@
"url": "https://opencollective.com/webpack"
}
},
+ "node_modules/@electron-toolkit/preload": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmmirror.com/@electron-toolkit/preload/-/preload-3.0.2.tgz",
+ "integrity": "sha512-TWWPToXd8qPRfSXwzf5KVhpXMfONaUuRAZJHsKthKgZR/+LqX1dZVSSClQ8OTAEduvLGdecljCsoT2jSshfoUg==",
+ "license": "MIT",
+ "peerDependencies": {
+ "electron": ">=13.0.0"
+ }
+ },
"node_modules/@electron-uikit/contextmenu": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/@electron-uikit/contextmenu/-/contextmenu-1.0.0.tgz",
@@ -589,6 +600,15 @@
}
}
},
+ "node_modules/@electron-uikit/core": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmmirror.com/@electron-uikit/core/-/core-1.1.0.tgz",
+ "integrity": "sha512-PH0QL5RVn7NWyA9lxihOuNZa1oDFjnX8MZOyef6x4Q/fu7yr2qVxNsu4imxBPP5p/oZjJ/HD2vswKWIiTqk4hg==",
+ "license": "MIT",
+ "peerDependencies": {
+ "electron": ">=15.0.0"
+ }
+ },
"node_modules/@electron/asar": {
"version": "3.2.18",
"resolved": "https://registry.npmmirror.com/@electron/asar/-/asar-3.2.18.tgz",
diff --git a/package.json b/package.json
index 972e3be4..c819ce59 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,9 @@
"dependencies": {
"@ant-design/colors": "^7.2.0",
"@ant-design/icons": "^5.6.1",
+ "@electron-toolkit/preload": "^3.0.2",
"@electron-uikit/contextmenu": "^1.0.0",
+ "@electron-uikit/core": "^1.1.0",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@ffprobe-installer/ffprobe": "^2.1.2",
"@types/form-data": "^2.5.2",
diff --git a/src/icp/account.ts b/src/icp/account.ts
index 6165e648..40e5f098 100644
--- a/src/icp/account.ts
+++ b/src/icp/account.ts
@@ -127,6 +127,14 @@ export async function icpDeleteAccountGroup(id: number) {
return await window.ipcRenderer.invoke('ICP_ACCOUNTS_GROUP_DELETE', id);
}
// 编辑用户组数据
-export async function editDeleteAccountGroup(data: any) {
+export async function icpEditDeleteAccountGroup(data: Partial<AccountGroup>) {
return await window.ipcRenderer.invoke('ICP_ACCOUNTS_GROUP_EDIT', data);
}
+// 修改账户的账户组
+export async function icpAccountEditGroup(id: number, groupId: number) {
+ return await window.ipcRenderer.invoke(
+ 'ICP_ACCOUNTS_EDIT_GROUP',
+ id,
+ groupId,
+ );
+}
diff --git a/src/main.tsx b/src/main.tsx
index db13a0a6..5169e249 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -20,6 +20,7 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
* 主题色:
* --colorPrimary1 ~~ --colorPrimary10
* 由浅到深
+ * 注意:“--colorPrimary6” 为中间主题色,不是 “5”
*/
root.style.setProperty(`--colorPrimary${i + 1}`, colors[i]);
}
diff --git a/src/store/account.ts b/src/store/account.ts
index 7aaa2afc..05050dfa 100644
--- a/src/store/account.ts
+++ b/src/store/account.ts
@@ -48,9 +48,14 @@ export const useAccountStore = create(
if (get().unBindFn) get().unBindFn!();
},
+ setAccountGroupList(accountGroupList: AccountGroupItem[]) {
+ set({ accountGroupList });
+ },
+
async getAccountList() {
const accountMap = new Map<number, AccountInfo>([]);
const result = await icpGetAccountList();
+ console.log(result);
if (!result) return;
for (const item of result) {
@@ -82,6 +87,10 @@ export const useAccountStore = create(
get().accountList.map((v) => {
accountGroupMap.get(v.groupId!)!.children.push(v);
});
+
+ accountGroupList.sort((a, b) => {
+ return a.rank - b.rank;
+ });
set({
accountGroupList,
});
diff --git a/src/views/account/components/AccountSidebar/AccountSidebar.module.scss b/src/views/account/components/AccountSidebar/AccountSidebar.module.scss
index bf4fb3d3..60534f75 100644
--- a/src/views/account/components/AccountSidebar/AccountSidebar.module.scss
+++ b/src/views/account/components/AccountSidebar/AccountSidebar.module.scss
@@ -3,6 +3,8 @@
.accountSidebar {
border-right: 1px solid var(--grayColor3);
width: 200px;
+ height: 100%;
+ min-height: 0;
flex-shrink: 0;
display: flex;
flex-direction: column;
@@ -12,6 +14,12 @@
}
:global {
+ .accountSidebar-userCount {
+ display: inline-block;
+ margin-left: 10px;
+ color: var(--grayColor6);
+ }
+
.accountSidebar-top {
flex-shrink: 0;
padding: 0 10px;
@@ -102,6 +110,20 @@
}
}
}
+
+ .ant-collapse {
+ overflow: auto;
+ height: 100%;
+ border: none;
+ background: transparent;
+ .ant-collapse-content-box {
+ padding: 0;
+ }
+ .ant-collapse-header {
+ background: transparent;
+ padding: 10px;
+ }
+ }
}
}
@@ -204,6 +226,9 @@
box-sizing: border-box;
padding-top: 10px;
&-top {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
}
&-bottom {
padding: 0 12px;
@@ -218,7 +243,6 @@
padding-right: 10px;
padding-left: 10px;
background: transparent;
- transition: 0.3s;
&:hover {
background: var(--colorPrimary3);
cursor: pointer;
@@ -228,21 +252,40 @@
padding-top: 5px;
padding-bottom: 5px;
}
+ &-sortHandle {
+ cursor: move;
+ margin-right: 10px;
+ }
+ &-left {
+ display: flex;
+ }
&-name {
}
&-count {
color: var(--grayColor8);
}
&-list {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ height: 100%;
+
&-title {
margin: 10px 0 10px 10px;
font-size: var(--fs-xs);
color: var(--grayColor8);
}
+
&-item {
padding-top: 10px;
padding-bottom: 10px;
}
+
+ &-sortable {
+ height: 100%;
+ overflow: auto;
+ padding-bottom: 15px;
+ }
}
&--active {
background: var(--colorPrimary3) !important;
diff --git a/src/views/account/components/AccountSidebar/AccountSidebar.tsx b/src/views/account/components/AccountSidebar/AccountSidebar.tsx
index e790ef3c..9bc00c17 100644
--- a/src/views/account/components/AccountSidebar/AccountSidebar.tsx
+++ b/src/views/account/components/AccountSidebar/AccountSidebar.tsx
@@ -8,10 +8,13 @@ import {
} from 'react';
import styles from './AccountSidebar.module.scss';
import { AccountInfo, AccountPlatInfoMap } from '../../comment';
-import { Avatar, Button, message, Popover, Tooltip } from 'antd';
+import { Avatar, Button, Collapse, message, Popover, Tooltip } from 'antd';
import { accountLogin, acpAccountLoginCheck } from '../../../../icp/account';
import AddAccountModal from '../AddAccountModal';
-import { AccountStatus } from '../../../../../commont/AccountEnum';
+import {
+ AccountStatus,
+ defaultAccountGroupId,
+} from '../../../../../commont/AccountEnum';
import {
CheckCircleOutlined,
PlusOutlined,
@@ -123,10 +126,15 @@ const AccountSidebar = memo(
) => {
const [isAccountModalOpen, setIsAccountModalOpen] = useState(false);
const pubAccountDetModuleRef = useRef<IPubAccountDetModuleRef>(null);
- const { accountList: fullAccountList, getAccountList } = useAccountStore(
+ const {
+ accountList: fullAccountList,
+ getAccountList,
+ accountGroupList,
+ } = useAccountStore(
useShallow((state) => ({
accountList: state.accountList,
getAccountList: state.getAccountList,
+ accountGroupList: state.accountGroupList,
})),
);
const [userManageModalOpen, setUserManageModalOpen] = useState(false);
@@ -179,54 +187,80 @@ const AccountSidebar = memo(
</Tooltip>
</div>
</div>
- <ul className="accountList">
- {accountList.map((account) => {
- const platInfo = AccountPlatInfoMap.get(account.type)!;
- return (
- <li
- className={[
- 'accountList-item',
- `${activeAccountId === account.id ? 'accountList-item--active' : ''}`,
- account.status === AccountStatus.DISABLE &&
- 'accountList-item--disable',
- ].join(' ')}
- key={account.id}
- onClick={async () => {
- if (account.status === AccountStatus.DISABLE) {
- const res = await accountLogin(account.type);
- if (!res) return;
- message.success('账号登录成功!');
- return;
- }
- onAccountChange(account);
- }}
- >
- <Avatar src={account.avatar} size="large" />
- <div className="accountList-item-right">
- <div
- className="accountList-item-right-name"
- title={account.nickname}
- >
- {account.nickname}
- </div>
- <div className="accountList-item-right-footer">
- <p className="accountList-item-right-plat">
- <img src={platInfo.icon} />
- <span>{platInfo.name}</span>
- </p>
- <Popover
- content={<AccountPopoverInfo accountInfo={account} />}
- // trigger="click"
- placement="right"
- >
- ...
- </Popover>
- </div>
- </div>
- </li>
- );
+
+ <Collapse
+ defaultActiveKey={[defaultAccountGroupId]}
+ items={accountGroupList.map((v) => {
+ return {
+ key: v.id,
+ label: (
+ <>
+ {v.name}
+ <span className="accountSidebar-userCount">
+ {v.children.length}/
+ {
+ v.children.map(
+ (v) => v.status === AccountStatus.USABLE,
+ ).length
+ }
+ </span>
+ </>
+ ),
+ children: (
+ <ul key={v.id} className="accountList">
+ {v.children.map((account) => {
+ const platInfo = AccountPlatInfoMap.get(account.type)!;
+ return (
+ <li
+ className={[
+ 'accountList-item',
+ `${activeAccountId === account.id ? 'accountList-item--active' : ''}`,
+ account.status === AccountStatus.DISABLE &&
+ 'accountList-item--disable',
+ ].join(' ')}
+ key={account.id}
+ onClick={async () => {
+ if (account.status === AccountStatus.DISABLE) {
+ const res = await accountLogin(account.type);
+ if (!res) return;
+ message.success('账号登录成功!');
+ return;
+ }
+ onAccountChange(account);
+ }}
+ >
+ <Avatar src={account.avatar} size="large" />
+ <div className="accountList-item-right">
+ <div
+ className="accountList-item-right-name"
+ title={account.nickname}
+ >
+ {account.nickname}
+ </div>
+ <div className="accountList-item-right-footer">
+ <p className="accountList-item-right-plat">
+ <img src={platInfo.icon} />
+ <span>{platInfo.name}</span>
+ </p>
+ <Popover
+ content={
+ <AccountPopoverInfo accountInfo={account} />
+ }
+ // trigger="click"
+ placement="right"
+ >
+ ...
+ </Popover>
+ </div>
+ </div>
+ </li>
+ );
+ })}
+ </ul>
+ ),
+ };
})}
- </ul>
+ />
<div className="accountSidebar-footer">
<Button
diff --git a/src/views/account/components/AccountSidebar/UserManageModal.tsx b/src/views/account/components/AccountSidebar/UserManageModal.tsx
index 7f1fcd9f..20123bc6 100644
--- a/src/views/account/components/AccountSidebar/UserManageModal.tsx
+++ b/src/views/account/components/AccountSidebar/UserManageModal.tsx
@@ -11,6 +11,7 @@ import {
Drawer,
message,
Modal,
+ Select,
Table,
TableProps,
Tooltip,
@@ -27,7 +28,11 @@ import {
WarningOutlined,
} from '@ant-design/icons';
import { AvatarPlat } from '../../../publish/components/PubProgressModule/PubProgressModule';
-import { icpDeleteAccounts } from '../../../../icp/account';
+import {
+ icpAccountEditGroup,
+ icpDeleteAccounts,
+ icpEditDeleteAccountGroup,
+} from '../../../../icp/account';
import UserManageSidebar from './UserManageSidebar';
export interface IUserManageModalRef {}
@@ -37,6 +42,31 @@ export interface IUserManageModalProps {
onCancel: () => void;
}
+const UserGroupSelect = ({ account }: { account: AccountModel }) => {
+ const { accountGroupList, getAccountList } = useAccountStore(
+ useShallow((state) => ({
+ accountGroupList: state.accountGroupList,
+ getAccountList: state.getAccountList,
+ })),
+ );
+
+ return (
+ <Select
+ value={account.groupId}
+ style={{ width: '160px' }}
+ fieldNames={{
+ value: 'id',
+ label: 'name',
+ }}
+ options={accountGroupList}
+ onChange={async (groupId) => {
+ await icpAccountEditGroup(account.id, groupId);
+ await getAccountList();
+ }}
+ />
+ );
+};
+
const UserManageModal = memo(
forwardRef(
(
@@ -58,6 +88,8 @@ const UserManageModal = memo(
const allUser = useRef(-1);
// -1=全部账号,不然为对应分组 ID
const [activeGroup, setActiveGroup] = useState(allUser.current);
+ // 是否改变了顺序
+ const isUpdateRank = useRef(false);
const columns = useMemo(() => {
const columns: TableProps<AccountModel>['columns'] = [
@@ -81,6 +113,21 @@ const UserManageModal = memo(
width: 200,
key: 'nickname',
},
+ {
+ title: '平台',
+ render: (text, am) => {
+ const platInfo = AccountPlatInfoMap.get(am.type)!;
+ return (
+ <div className="userManage-content-plat">
+ <Tooltip title={platInfo.name}>
+ <img src={platInfo.icon} />
+ </Tooltip>
+ </div>
+ );
+ },
+ width: 80,
+ key: 'nickname',
+ },
{
title: '账号状态',
render: (text, am) => {
@@ -110,23 +157,16 @@ const UserManageModal = memo(
</>
);
},
- width: 200,
+ width: 100,
key: 'nickname',
},
{
- title: '平台',
+ title: '所属列表',
render: (text, am) => {
- const platInfo = AccountPlatInfoMap.get(am.type)!;
- return (
- <div className="userManage-content-plat">
- <Tooltip title={platInfo.name}>
- <img src={platInfo.icon} />
- </Tooltip>
- </div>
- );
+ return <UserGroupSelect account={am} />;
},
width: 200,
- key: 'nickname',
+ key: 'groupId',
},
];
return columns;
@@ -145,9 +185,21 @@ const UserManageModal = memo(
selectedRowKeys: selectedRows.map((v) => v.id),
};
- const close = () => {
+ const close = async () => {
onCancel();
setSelectedRows([]);
+
+ if (isUpdateRank.current) {
+ isUpdateRank.current = false;
+ for (let i = 0; i < accountGroupList.length; i++) {
+ const v = accountGroupList[i];
+ // 这里不需要更新数据,因为在排序完成后已经更新了全局的sotre,引用sotre的所有位置都会发生更改
+ await icpEditDeleteAccountGroup({
+ id: v.id,
+ rank: i,
+ });
+ }
+ }
};
const accountListLast = useMemo(() => {
@@ -197,7 +249,7 @@ const UserManageModal = memo(
open={open}
title="账号管理器"
footer={null}
- width={900}
+ width={1000}
onCancel={close}
rootClassName={styles.userManageModal}
>
@@ -206,6 +258,9 @@ const UserManageModal = memo(
allUser={allUser.current}
activeGroup={activeGroup}
onChange={setActiveGroup}
+ onSortEnd={() => {
+ isUpdateRank.current = true;
+ }}
/>
<div className="userManage-content">
diff --git a/src/views/account/components/AccountSidebar/UserManageSidebar.tsx b/src/views/account/components/AccountSidebar/UserManageSidebar.tsx
index a80984ec..04140d87 100644
--- a/src/views/account/components/AccountSidebar/UserManageSidebar.tsx
+++ b/src/views/account/components/AccountSidebar/UserManageSidebar.tsx
@@ -1,12 +1,21 @@
-import { ForwardedRef, forwardRef, memo, useState } from 'react';
+import { ForwardedRef, forwardRef, memo, useRef, useState } from 'react';
import { Button, Input, message, Modal } from 'antd';
-import { PlusOutlined } from '@ant-design/icons';
+import {
+ ExclamationCircleFilled,
+ PlusOutlined,
+ UnorderedListOutlined,
+} from '@ant-design/icons';
import { useAccountStore } from '../../../../store/account';
import { useShallow } from 'zustand/react/shallow';
import styles from './AccountSidebar.module.scss';
-import { icpAddAccountGroup } from '../../../../icp/account';
+import {
+ icpEditDeleteAccountGroup,
+ icpAddAccountGroup,
+ icpDeleteAccountGroup,
+} from '../../../../icp/account';
import { defaultAccountGroupId } from '../../../../../commont/AccountEnum';
-import Contextmenu from "@electron-uikit/contextmenu";
+import { Menu, MenuItem } from '@electron-uikit/contextmenu/renderer';
+import { ReactSortable } from 'react-sortablejs';
export interface IUserManageSidebarRef {}
@@ -14,25 +23,38 @@ export interface IUserManageSidebarProps {
activeGroup: number;
allUser: number;
onChange: (id: number) => void;
+ onSortEnd: () => void;
}
+const { confirm } = Modal;
+
const UserManageSidebar = memo(
forwardRef(
(
- { activeGroup, allUser, onChange }: IUserManageSidebarProps,
+ { activeGroup, allUser, onChange, onSortEnd }: IUserManageSidebarProps,
ref: ForwardedRef<IUserManageSidebarRef>,
) => {
- const { accountGroupList, accountList, getAccountGroup } =
- useAccountStore(
- useShallow((state) => ({
- accountGroupList: state.accountGroupList,
- accountList: state.accountList,
- getAccountGroup: state.getAccountGroup,
- })),
- );
+ const {
+ accountGroupList,
+ accountList,
+ setAccountGroupList,
+ getAccountGroup,
+ getAccountList,
+ } = useAccountStore(
+ useShallow((state) => ({
+ accountGroupList: state.accountGroupList,
+ accountList: state.accountList,
+ getAccountGroup: state.getAccountGroup,
+ getAccountList: state.getAccountList,
+ setAccountGroupList: state.setAccountGroupList,
+ })),
+ );
const [openCreateGroup, setOpenCreateGroup] = useState(false);
const [groupName, setGroupName] = useState('');
const [createGroupLoading, setCreateGroupLoading] = useState(false);
+ // -1=新建 不然为重命名,值为要重命名的id
+ const [createGroupId, setCreateGroupId] = useState(0);
+ const srcollEl = useRef<HTMLElement>(undefined);
const createGroupCancel = () => {
setOpenCreateGroup(false);
@@ -42,7 +64,7 @@ const UserManageSidebar = memo(
return (
<>
<Modal
- title="新建列表"
+ title={createGroupId === -1 ? '新建列表' : '重命名列表'}
open={openCreateGroup}
onCancel={createGroupCancel}
footer={
@@ -53,9 +75,17 @@ const UserManageSidebar = memo(
disabled={groupName.length === 0}
onClick={async () => {
setCreateGroupLoading(true);
- await icpAddAccountGroup({
- name: groupName,
- });
+ if (createGroupId === -1) {
+ await icpAddAccountGroup({
+ name: groupName,
+ });
+ } else {
+ await icpEditDeleteAccountGroup({
+ name: groupName,
+ id: createGroupId,
+ });
+ }
+
await getAccountGroup();
setCreateGroupLoading(false);
createGroupCancel();
@@ -95,31 +125,103 @@ const UserManageSidebar = memo(
</div>
<div className="userManage-sidebar-list">
<p className="userManage-sidebar-list-title">列表</p>
- {accountGroupList.map((v) => {
- return (
- <div
- className={[
- 'userManage-sidebar-list-item',
- activeGroup === v.id && 'userManage-sidebar--active',
- ].join(' ')}
- key={v.id}
- onClick={() => {
- onChange(v.id);
- }}
- onContextMenu={(e) => {
- if (v.id === defaultAccountGroupId) {
- return message.error('不能操作默认列表');
- }
- console.log('打开');
- }}
- >
- <span className="userManage-sidebar-name">{v.name}</span>
- <span className="userManage-sidebar-count">
- {v.children.length}
- </span>
- </div>
- );
- })}
+
+ <ReactSortable
+ className="userManage-sidebar-list-sortable"
+ list={accountGroupList}
+ animation={250}
+ onEnd={() => {
+ onSortEnd();
+ }}
+ setList={setAccountGroupList}
+ scrollSensitivity={100}
+ scroll={srcollEl.current}
+ scrollSpeed={15}
+ handle=".userManage-sidebar-sortHandle"
+ id="id"
+ >
+ {accountGroupList.map((v) => {
+ return (
+ <div
+ className={[
+ 'userManage-sidebar-list-item',
+ activeGroup === v.id && 'userManage-sidebar--active',
+ ].join(' ')}
+ key={v.id}
+ onClick={() => {
+ onChange(v.id);
+ }}
+ onContextMenu={(e) => {
+ if (v.id === defaultAccountGroupId) {
+ return message.error('不能操作默认列表');
+ }
+ e.preventDefault();
+
+ const menu = new Menu();
+ menu.append(
+ new MenuItem({
+ label: '重命名',
+ click: () => {
+ setCreateGroupId(v.id);
+ setOpenCreateGroup(true);
+ setGroupName(v.name);
+ },
+ }),
+ );
+ menu.append(
+ new MenuItem({
+ label: '删除',
+ click: () => {
+ confirm({
+ title: '提示',
+ icon: <ExclamationCircleFilled />,
+ content: (
+ <>
+ 请确认是否删除列表:
+ <span
+ style={{
+ color: 'var(--colorPrimary6)',
+ }}
+ >
+ {v.name}
+ </span>
+ ,删除后该列表下的账号将被移动到
+ <span
+ style={{
+ color: 'var(--colorPrimary6)',
+ }}
+ >
+ 默认列表
+ </span>
+ 中
+ </>
+ ),
+ async onOk() {
+ await icpDeleteAccountGroup(v.id);
+ await getAccountList();
+ },
+ });
+ },
+ }),
+ );
+ menu.popup();
+ }}
+ >
+ <div className="userManage-sidebar-left">
+ <div className="userManage-sidebar-sortHandle">
+ <UnorderedListOutlined />
+ </div>
+ <span className="userManage-sidebar-name">
+ {v.name}
+ </span>
+ </div>
+ <span className="userManage-sidebar-count">
+ {v.children.length}
+ </span>
+ </div>
+ );
+ })}
+ </ReactSortable>
</div>
</div>
<div className="userManage-sidebar-bottom">
@@ -127,6 +229,7 @@ const UserManageSidebar = memo(
type="primary"
icon={<PlusOutlined />}
onClick={() => {
+ setCreateGroupId(-1);
setOpenCreateGroup(true);
}}
>