Skip to content

Let's use AI to Earn!

feat: 全局通知配置,现在视频发布完成切换到别的页面也会通知用户,另,项目中所有的通知都可以调用全局通知

gaoSir690fb2c21d29
diff --git a/electron/db/models/pubRecord.ts b/electron/db/models/pubRecord.ts
index 9121559c..5a562405 100644
--- a/electron/db/models/pubRecord.ts
+++ b/electron/db/models/pubRecord.ts
@@ -18,7 +18,7 @@ export enum PubStatus {
@Entity({ name: 'pubRecord' })
export class PubRecordModel extends TempModel {
@PrimaryGeneratedColumn({ type: 'int', comment: 'id' })
- id?: number;
+ id!: number;
@Column({ type: 'varchar', nullable: false, comment: '用户id' })
userId!: string;
@@ -43,6 +43,10 @@ export class PubRecordModel extends TempModel {
@Column({ type: 'varchar', nullable: false, comment: '视频路径' })
videoPath!: string;
+ // 定时发布日期
+ @Column({ type: 'datetime', nullable: true, comment: '定时发布日期' })
+ timingTime?: Date;
+
// 封面路径
@Column({ type: 'varchar', nullable: false, comment: '封面路径' })
coverPath!: string;
diff --git a/electron/main/plat/index.ts b/electron/main/plat/index.ts
index d7f0acad..7471b3fd 100644
--- a/electron/main/plat/index.ts
+++ b/electron/main/plat/index.ts
@@ -176,8 +176,6 @@ class PlatController {
return await platform.getUsers(params);
}
-
-
/**
* 获取作品列表
* @param account
diff --git a/src/App.tsx b/src/App.tsx
index 28fc399d..31cc2c4c 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -8,10 +8,20 @@
import { RouterProvider } from 'react-router-dom';
import router from '@/router/index';
-import { ConfigProvider } from 'antd';
+import { ConfigProvider, notification } from 'antd';
import Inform from './components/Inform';
+import { useEffect } from 'react';
+import { useAccountStore } from './store/commont';
const App = () => {
+ const [api, contextHolder] = notification.useNotification({
+ top: 70,
+ });
+
+ useEffect(() => {
+ useAccountStore.getState().setNotification(api);
+ }, []);
+
return (
<ConfigProvider
theme={{
@@ -20,6 +30,7 @@ const App = () => {
},
}}
>
+ {contextHolder}
<Inform onChooseItem={() => {}} />
<RouterProvider router={router} />
</ConfigProvider>
diff --git a/src/store/commont.ts b/src/store/commont.ts
new file mode 100644
index 00000000..69d59020
--- /dev/null
+++ b/src/store/commont.ts
@@ -0,0 +1,31 @@
+import { create } from 'zustand';
+import { combine } from 'zustand/middleware';
+import { NotificationInstance } from 'antd/es/notification/interface';
+
+export interface ICommontStore {
+ // 全局通知api
+ notification?: NotificationInstance;
+}
+
+const store: ICommontStore = {
+ notification: undefined,
+};
+
+// 项目中的通用的、全局的状态和方法
+export const useAccountStore = create(
+ combine(
+ {
+ ...store,
+ },
+ (set, get, storeApi) => {
+ const methods = {
+ setNotification(notification: NotificationInstance) {
+ set({
+ notification,
+ });
+ },
+ };
+ return methods;
+ },
+ ),
+);
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
index 24d2903c..5051c0fc 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
@@ -13,7 +13,6 @@ import {
Button,
message,
Modal,
- notification,
Space,
Switch,
Tabs,
@@ -51,7 +50,7 @@ import { IVideoChooseItem } from '../../videoPage';
import usePubParamsVerify, {
PubParamsErrStatusEnum,
} from '../../../../hooks/usePubParamsVerify';
-import { ExclamationCircleOutlined } from '@ant-design/icons';
+import { useAccountStore } from '../../../../../../store/commont';
export interface IVideoPubSetModalRef {}
@@ -94,6 +93,7 @@ const VideoPubSetModal = memo(
setVideoPubSetModalOpen,
updateAccounts,
accountRestart,
+ commonPubParams,
clear,
} = useVideoPageStore(
useShallow((state) => ({
@@ -106,6 +106,7 @@ const VideoPubSetModal = memo(
updateAccounts: state.updateAccounts,
accountRestart: state.accountRestart,
clear: state.clear,
+ commonPubParams: state.commonPubParams,
})),
);
const { moreParamsOpen, setMoreParamsOpen } = usePubStroe(
@@ -115,7 +116,6 @@ const VideoPubSetModal = memo(
})),
);
const [loading, setLoading] = useState(false);
- const [api, contextHolder] = notification.useNotification();
const pubAccountDetModuleRef = useRef<IPubAccountDetModuleRef>(null);
// 主进程传过来的发布进度数据,key为用户id value为发布进度数据
const [pubProgressMap, setPubProgressMap] = useState<
@@ -176,9 +176,10 @@ const VideoPubSetModal = memo(
};
// 创建一级记录
const recordRes = await icpCreatePubRecord({
- title: '/',
- desc: '/',
+ title: commonPubParams.title,
+ desc: commonPubParams.describe,
type: PubType.VIDEO,
+ timingTime: commonPubParams.timingTime,
videoPath: videoListChoose[0].video?.videoPath,
coverPath: videoListChoose[0].pubParams.cover?.imgPath,
});
@@ -214,7 +215,7 @@ const VideoPubSetModal = memo(
// 成功数据
const successList = okRes.filter((v) => v.code === 1);
setTimeout(() => {
- api.open({
+ useAccountStore.getState().notification!.open({
message: '发布结果',
description: (
<>
@@ -252,9 +253,6 @@ const VideoPubSetModal = memo(
return;
}
}
- if (videoListChoose.some((v) => !v.pubParams.cover)) {
- return message.warning('有的数据未上传封面,请检查后重试!');
- }
setLoading(true);
pubAccountDetModuleRef.current!.startDet();
};
@@ -266,7 +264,6 @@ const VideoPubSetModal = memo(
return (
<>
- {contextHolder}
<PubProgressModule
pubProgressData={pubProgressData}
open={pubProgressModuleOpen}
diff --git a/src/views/publish/comment.ts b/src/views/publish/comment.ts
index ffffc1e4..2e8de9d8 100644
--- a/src/views/publish/comment.ts
+++ b/src/views/publish/comment.ts
@@ -6,19 +6,6 @@
* @Description:
*/
-import { PubType } from '../../../commont/publish/PublishEnum';
+import { PubRecordModel as PubRecordModelLast } from '../../../electron/db/models/pubRecord';
-export interface PubRecordModel {
- id: number;
- userId: string;
- type: PubType;
- title: string;
- topics: string[];
- desc: string;
- videoPath: string;
- coverPath: string;
- publishTime: Date;
- status: any;
- createTime?: Date;
- updateTime?: Date;
-}
+export type PubRecordModel = PubRecordModelLast;