From d71996a0a0bdc79d1b0533a7107774a82233e926 Mon Sep 17 00:00:00 2001 From: dark Date: Sun, 12 May 2024 16:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0cms=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/cms.ts | 19 +++++++++ src/store/cms/collect.ts | 86 ++++++++++++++++++++++++++++++++++++++++ src/store/cms/video.ts | 87 +++++++++++++++++++++++++++++++++++++++++ src/store/cms/video_cloud.ts | 87 +++++++++++++++++++++++++++++++++++++++++ src/store/cms/video_magnet.ts | 87 +++++++++++++++++++++++++++++++++++++++++ src/store/system/role.ts | 2 +- src/types/cms/collect.d.ts | 21 ++++++++++ src/types/cms/video.d.ts | 38 ++++++++++++++++++ src/types/cms/video_cloud.d.ts | 38 ++++++++++++++++++ src/types/cms/video_magnet.d.ts | 37 ++++++++++++++++++ src/types/index.d.ts | 7 ++++ 11 files changed, 508 insertions(+), 1 deletion(-) create mode 100644 src/service/cms.ts create mode 100644 src/store/cms/collect.ts create mode 100644 src/store/cms/video.ts create mode 100644 src/store/cms/video_cloud.ts create mode 100644 src/store/cms/video_magnet.ts create mode 100644 src/types/cms/collect.d.ts create mode 100644 src/types/cms/video.d.ts create mode 100644 src/types/cms/video_cloud.d.ts create mode 100644 src/types/cms/video_magnet.d.ts diff --git a/src/service/cms.ts b/src/service/cms.ts new file mode 100644 index 0000000..783138a --- /dev/null +++ b/src/service/cms.ts @@ -0,0 +1,19 @@ +import { createCURD } from '@/service/base.ts' +import { Cms } from '@/types' + +const cmsServ = { + collect: { + ...createCURD('/cms/collect') + }, + video: { + ...createCURD('/cms/video') + }, + videoCloud: { + ...createCURD('/cms/video_cloud') + }, + videoMagnet: { + ...createCURD('/cms/video_magnet') + }, +} + +export default cmsServ \ No newline at end of file diff --git a/src/store/cms/collect.ts b/src/store/cms/collect.ts new file mode 100644 index 0000000..17f3c16 --- /dev/null +++ b/src/store/cms/collect.ts @@ -0,0 +1,86 @@ +import { Cms } from '@/types' +import { atom } from 'jotai' +import { IApiResult, IPage } from '@/global' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import { message } from 'antd' +import { t } from 'i18next' +import cmsServ from '@/service/cms.ts' + + +type SearchParams = IPage & { + key?: string +} + +export const idAtom = atom(0) + +export const collectIdsAtom = atom([]) + +export const collectAtom = atom(undefined as unknown as Cms.ICollect) + +export const searchAtom = atom({ + key: '' +} as SearchParams) + +export const pageAtom = atom({ + pageSize: 10, + page: 1, +}) + +export const collectsAtom = atomWithQuery((get) => { + return { + queryKey: [ 'collects', get(searchAtom) ], + queryFn: async ({ queryKey: [ , params ] }) => { + return await cmsServ.collect.list(params as SearchParams) + }, + select: res => { + const data = res.data + data.rows = data.rows?.map(row => { + return { + ...row, + } + }) + return data + } + } +}) + +//saveOrUpdateAtom +export const saveOrUpdateCollectAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateCollect' ], + mutationFn: async (data) => { + // data.status = data.status ? '1' : '0' + if (data.id === 0) { + return await cmsServ.collect.add(data) + } + return await cmsServ.collect.update(data) + }, + onSuccess: (res) => { + const isAdd = !!res.data?.id + message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) + + //更新列表 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore fix + get(queryClientAtom).invalidateQueries({ queryKey: [ 'collects', get(searchAtom) ] }) + + return res + } + } +}) + +export const deleteCollectAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteCollect' ], + mutationFn: async (ids: number[]) => { + return await cmsServ.collect.batchDelete(ids ?? get(collectIdsAtom)) + }, + onSuccess: (res) => { + message.success('message.deleteSuccess') + //更新列表 + get(queryClientAtom).invalidateQueries({ queryKey: [ 'collects', get(searchAtom) ] }) + return res + } + } +}) diff --git a/src/store/cms/video.ts b/src/store/cms/video.ts new file mode 100644 index 0000000..b6ad5bd --- /dev/null +++ b/src/store/cms/video.ts @@ -0,0 +1,87 @@ +import { atom } from 'jotai' +import { IApiResult, IPage } from '@/global' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import { message } from 'antd' +import { t } from 'i18next' +import { Cms } from '@/types' +import cmsServ from '@/service/cms.ts' + + +type SearchParams = IPage & { + key?: string +} + +export const idAtom = atom(0) + +export const videoIdsAtom = atom([]) + +export const videoAtom = atom(undefined as unknown as Cms.IVideo) + +export const searchAtom = atom({ + key: '' +} as SearchParams) + +export const pageAtom = atom({ + pageSize: 10, + page: 1, +}) + +export const videosAtom = atomWithQuery((get) => { + return { + queryKey: [ 'videos', get(searchAtom) ], + queryFn: async ({ queryKey: [ , params ] }) => { + return await cmsServ.video.list(params as SearchParams) + }, + select: res => { + const data = res.data + data.rows = data.rows?.map(row => { + return { + ...row, + //status: convertToBool(row.status) + } + }) + return data + } + } +}) + +//saveOrUpdateAtom +export const saveOrUpdateVideoAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateVideo' ], + mutationFn: async (data) => { + //data.status = data.status ? '1' : '0' + if (data.id === 0) { + return await cmsServ.video.add(data) + } + return await cmsServ.video.update(data) + }, + onSuccess: (res) => { + const isAdd = !!res.data?.id + message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) + + //更新列表 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore fix + get(queryClientAtom).invalidateQueries({ queryKey: [ 'videos', get(searchAtom) ] }) + + return res + } + } +}) + +export const deleteVideoAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteVideo' ], + mutationFn: async (ids: number[]) => { + return await cmsServ.video.batchDelete(ids ?? get(videoIdsAtom)) + }, + onSuccess: (res) => { + message.success('message.deleteSuccess') + //更新列表 + get(queryClientAtom).invalidateQueries({ queryKey: [ 'videos', get(searchAtom) ] }) + return res + } + } +}) diff --git a/src/store/cms/video_cloud.ts b/src/store/cms/video_cloud.ts new file mode 100644 index 0000000..ac84354 --- /dev/null +++ b/src/store/cms/video_cloud.ts @@ -0,0 +1,87 @@ +import { atom } from 'jotai' +import { IApiResult, IPage } from '@/global' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import { message } from 'antd' +import { t } from 'i18next' +import { Cms } from '@/types' +import cmsServ from '@/service/cms.ts' + + +type SearchParams = IPage & { + key?: string +} + +export const idAtom = atom(0) + +export const videoCloudIdsAtom = atom([]) + +export const videoCloudAtom = atom(undefined as unknown as Cms.IVideoCloud) + +export const searchAtom = atom({ + key: '' +} as SearchParams) + +export const pageAtom = atom({ + pageSize: 10, + page: 1, +}) + +export const videoCloudsAtom = atomWithQuery((get) => { + return { + queryKey: [ 'videoClouds', get(searchAtom) ], + queryFn: async ({ queryKey: [ , params ] }) => { + return await cmsServ.videoCloud.list(params as SearchParams) + }, + select: res => { + const data = res.data + data.rows = data.rows?.map(row => { + return { + ...row, + //status: convertToBool(row.status) + } + }) + return data + } + } +}) + +//saveOrUpdateAtom +export const saveOrUpdateVideoCloudAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateVideoCloud' ], + mutationFn: async (data) => { + //data.status = data.status ? '1' : '0' + if (data.id === 0) { + return await cmsServ.videoCloud.add(data) + } + return await cmsServ.videoCloud.update(data) + }, + onSuccess: (res) => { + const isAdd = !!res.data?.id + message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) + + //更新列表 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore fix + get(queryClientAtom).invalidateQueries({ queryKey: [ 'videoClouds', get(searchAtom) ] }) + + return res + } + } +}) + +export const deleteVideoCloudAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteVideoCloud' ], + mutationFn: async (ids: number[]) => { + return await cmsServ.videoCloud.batchDelete(ids ?? get(videoCloudIdsAtom)) + }, + onSuccess: (res) => { + message.success('message.deleteSuccess') + //更新列表 + get(queryClientAtom).invalidateQueries({ queryKey: [ 'videoClouds', get(searchAtom) ] }) + return res + } + } +}) diff --git a/src/store/cms/video_magnet.ts b/src/store/cms/video_magnet.ts new file mode 100644 index 0000000..d9dd464 --- /dev/null +++ b/src/store/cms/video_magnet.ts @@ -0,0 +1,87 @@ +import { atom } from 'jotai' +import { IApiResult, IPage } from '@/global' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import { message } from 'antd' +import { t } from 'i18next' +import { Cms } from '@/types' +import cmsServ from '@/service/cms.ts' + + +type SearchParams = IPage & { + key?: string +} + +export const idAtom = atom(0) + +export const videoMagnetIdsAtom = atom([]) + +export const videoMagnetAtom = atom(undefined as unknown as Cms.IVideoMagnet) + +export const searchAtom = atom({ + key: '' +} as SearchParams) + +export const pageAtom = atom({ + pageSize: 10, + page: 1, +}) + +export const videoMagnetsAtom = atomWithQuery((get) => { + return { + queryKey: [ 'videoMagnets', get(searchAtom) ], + queryFn: async ({ queryKey: [ , params ] }) => { + return await cmsServ.videoMagnet.list(params as SearchParams) + }, + select: res => { + const data = res.data + data.rows = data.rows?.map(row => { + return { + ...row, + //status: convertToBool(row.status) + } + }) + return data + } + } +}) + +//saveOrUpdateAtom +export const saveOrUpdateVideoMagnetAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateVideoMagnet' ], + mutationFn: async (data) => { + //data.status = data.status ? '1' : '0' + if (data.id === 0) { + return await cmsServ.videoMagnet.add(data) + } + return await cmsServ.videoMagnet.update(data) + }, + onSuccess: (res) => { + const isAdd = !!res.data?.id + message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) + + //更新列表 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore fix + get(queryClientAtom).invalidateQueries({ queryKey: [ 'videoMagnets', get(searchAtom) ] }) + + return res + } + } +}) + +export const deleteVideoMagnetAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteVideoMagnet' ], + mutationFn: async (ids: number[]) => { + return await cmsServ.videoMagnet.batchDelete(ids ?? get(videoMagnetIdsAtom)) + }, + onSuccess: (res) => { + message.success('message.deleteSuccess') + //更新列表 + get(queryClientAtom).invalidateQueries({ queryKey: [ 'videoMagnets', get(searchAtom) ] }) + return res + } + } +}) diff --git a/src/store/system/role.ts b/src/store/system/role.ts index 4ac38eb..53e1c4a 100644 --- a/src/store/system/role.ts +++ b/src/store/system/role.ts @@ -85,4 +85,4 @@ export const deleteRoleAtom = atomWithMutation((get) => { return res } } -}) \ No newline at end of file +}) diff --git a/src/types/cms/collect.d.ts b/src/types/cms/collect.d.ts new file mode 100644 index 0000000..6a6f1a2 --- /dev/null +++ b/src/types/cms/collect.d.ts @@ -0,0 +1,21 @@ +export interface ICollect { + id: number; + name: string; + url: string; + param: string; + type_id: number; + opt: number; + filter: number; + filter_form: string; + sync_pic: number; + icon_cdn: string; + class: string; + weights: number; + status: boolean; + open_replace: boolean; + replace_str: string; + site_auth: boolean; + site_cooperation: boolean; + categories_rules: string; + +} diff --git a/src/types/cms/video.d.ts b/src/types/cms/video.d.ts new file mode 100644 index 0000000..0e22d1e --- /dev/null +++ b/src/types/cms/video.d.ts @@ -0,0 +1,38 @@ +export interface IVideo { + id: number; + source_url: string; + collect_id: number; + type_id: number; + title: string; + title_sub: string; + letter: string; + tag: string; + lock: number; + copyright: number; + is_end: number; + status: number; + category_id: number; + pic: string; + pic_local: string; + pic_status: number; + actor: string; + director: string; + writer: string; + remarks: string; + pubdate: string; + total: number; + serial: string; + duration: string; + area: string; + lang: string; + version: string; + year: number; + state: string; + douban_score: number; + douban_id: number; + imdb_score: number; + imdb_id: number; + content: string; + created_at: any; + updated_at: any; +} diff --git a/src/types/cms/video_cloud.d.ts b/src/types/cms/video_cloud.d.ts new file mode 100644 index 0000000..213ea71 --- /dev/null +++ b/src/types/cms/video_cloud.d.ts @@ -0,0 +1,38 @@ + +export interface IVideoCloud { + id: number; + type_id: number; + collect_id: number; + source_url: string; + title: string; + title_sub: string; + letter: string; + tag: string; + lock: number; + copyright: number; + is_end: number; + status: number; + category_id: number; + pic: string; + pic_local: string; + actor: string; + director: string; + writer: string; + content: string; + pubdate: string; + total: number; + serial: string; + duration: string; + class: string; + area: string; + lang: string; + version: string; + year: number; + state: string; + douban_score: number; + douban_id: number; + imdb_score: number; + imdb_id: number; + created_at: any; + updated_at: any; +} diff --git a/src/types/cms/video_magnet.d.ts b/src/types/cms/video_magnet.d.ts new file mode 100644 index 0000000..7e7ed59 --- /dev/null +++ b/src/types/cms/video_magnet.d.ts @@ -0,0 +1,37 @@ +export interface IVideoMagnet { + id: number; + type_id: number; + collect_id: number; + source_url: string; + title: string; + title_sub: string; + letter: string; + tag: string; + lock: number; + copyright: number; + is_end: number; + status: number; + category_id: number; + pic: string; + pic_local: string; + actor: string; + director: string; + writer: string; + content: string; + pubdate: string; + total: number; + serial: string; + duration: string; + class: string; + area: string; + lang: string; + version: string; + year: number; + state: string; + douban_score: number; + douban_id: number; + imdb_score: number; + imdb_id: number; + created_at: any; + updated_at: any; +} diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 6eef07e..050dcff 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -11,4 +11,11 @@ export namespace WebSite { export { ICA, ISSLObtainByCA } from './website/ca' export { IDnsAccount } from './website/dns' export { ISSL, ProviderType, SSLSearchParam, SSLUploadDto } from './website/ssl' +} + +export namespace Cms { + export { ICollect } from './cms/collect' + export { IVideo } from './cms/video' + export { IVideoMagnet } from './cms/video_magnet' + export { IVideoCloud } from './cms/video_cloud' } \ No newline at end of file