Skip to content

Commit

Permalink
Merge pull request #5 from lzfgit-byte/dev4.0
Browse files Browse the repository at this point in the history
Dev4.0
  • Loading branch information
lzfgit-byte authored Aug 28, 2024
2 parents 48655e0 + 6b444db commit c6629a0
Show file tree
Hide file tree
Showing 18 changed files with 425 additions and 61 deletions.
4 changes: 4 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare module 'vue' {
ASpace: typeof import('ant-design-vue/es')['Space']
ASpin: typeof import('ant-design-vue/es')['Spin']
ASwitch: typeof import('ant-design-vue/es')['Switch']
ATabPane: typeof import('ant-design-vue/es')['TabPane']
ATabs: typeof import('ant-design-vue/es')['Tabs']
ATextarea: typeof import('ant-design-vue/es')['Textarea']
ATooltip: typeof import('ant-design-vue/es')['Tooltip']
ComicImage: typeof import('./src/components/comic/comic-image.vue')['default']
Expand All @@ -35,6 +37,8 @@ declare module 'vue' {
GhsMenu: typeof import('./src/components/menu/ghs-menu.vue')['default']
GhsPagination: typeof import('./src/components/pagination/ghs-pagination.vue')['default']
GhsPlayer: typeof import('./src/components/player/ghs-player.vue')['default']
GhsPlayerComments: typeof import('./src/components/player/ghs-player-comments.vue')['default']
GhsPlayerSeries: typeof import('./src/components/player/ghs-player-series.vue')['default']
GhsScroller: typeof import('./src/components/scroller/ghs-scroller.vue')['default']
GhsTag: typeof import('./src/components/tag/ghs-tag.vue')['default']
GhsText: typeof import('./src/components/text/ghs-text.vue')['default']
Expand Down
49 changes: 49 additions & 0 deletions electron/business/business.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Analysis,
CComic,
CContent,
DetailInfo,
Expand All @@ -14,6 +15,7 @@ import type { Cheerio } from 'cheerio/lib/cheerio';
import type { Element } from 'domhandler';
import { isFalsity, isFunction } from '@ilzf/utils';
import { ComicHistory, SearchHistoryEntity, ViewedHistoryEntity } from '@ghs/constant';
import type { AnalysisDetail, AnalysisVideoDetail } from '@ghs/types/src';
import { getHtml } from '../export';
import { LogMsgUtil, MessageUtil } from '../utils/message';
import { NormalFunc } from './common-func';
Expand All @@ -23,6 +25,7 @@ class BaseBusiness extends NormalFunc {
private key: string;
private comicDetailUrl = '';
private currentUrl = '';
private currentItem: Item = null;
$: CheerioAPI;
webConfig: WebConfig;
public constructor(key: string, code: WebConfig) {
Expand Down Expand Up @@ -126,6 +129,7 @@ class BaseBusiness extends NormalFunc {
public async getDetailPage(item: Item): Promise<DetailInfo> {
this.saveViewHistory(item).then();
LogMsgUtil.sendLogMsg(this.webConfig.key, 'jumpUrl', item.jumpUrl);
this.currentItem = item;
return this.webConfig.getDetailInfo(item, cheerio);
}

Expand Down Expand Up @@ -178,6 +182,9 @@ class BaseBusiness extends NormalFunc {
return await this.webConfig?.getComicImages(url, cheerio);
}

/**
* 获取历史记录里的最新漫画阅读记录
*/
public async getComicCurrentContent(): Promise<ComicHistory> {
const detailEnt = await ComicHistory.findOne({ where: { detailUrl: this.getComicUrl() } });
if (detailEnt) {
Expand All @@ -196,9 +203,51 @@ class BaseBusiness extends NormalFunc {
await ComicHistory.update(detailEnt.id, detailEnt);
}

/**
* 获取历史记录里的最新漫画阅读记录
*/
public async getSeriesCurrentContent(): Promise<ComicHistory> {
const detailEnt = await ComicHistory.findOne({
where: { detailUrl: this.currentItem.jumpUrl },
});
if (detailEnt) {
return detailEnt;
}
return null;
}

public async saveOrUpdateSeriesWatchHistory(analysisDetail: AnalysisDetail) {
if (!this.currentItem) {
LogMsgUtil.sendLogMsg('未找到当前item');
return;
}
const detailEnt = await ComicHistory.findOne({
where: { detailUrl: this.currentItem.jumpUrl },
});
if (detailEnt) {
detailEnt.contentUrl = analysisDetail.url;
await ComicHistory.update(detailEnt.id, detailEnt);
} else {
const comicHistory = new ComicHistory();
comicHistory.detailUrl = this.currentItem.jumpUrl;
comicHistory.contentUrl = analysisDetail.url;
comicHistory.currentImage = 0;
await comicHistory.save();
}
}

public async clearCurrentUrl() {
this.currentUrl = '';
}

public async getAnalysisDetail(item: Analysis): Promise<AnalysisDetail[]> {
return this.webConfig?.getAnalysisDetail(item, cheerio);
}

public async getAnalysisVideoDetail(item: AnalysisDetail): Promise<AnalysisVideoDetail[]> {
await this.saveOrUpdateSeriesWatchHistory(item);
return this.webConfig?.getAnalysisVideoDetail(item, cheerio);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion electron/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export * from './history';
//
export * from './web-config';
export * from './system-comfig';

export * from './series';
/**
*获取所有的配置项
*/
Expand Down
24 changes: 24 additions & 0 deletions electron/export/series.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { AnalysisDetail, AnalysisVideoDetail } from '@ghs/types/src';
import type { Analysis } from '@ghs/types';
import type { ComicHistory } from '@ghs/constant';
import { getCurrentBusiness } from '../business/business';
import { getCurrentKey } from '../business/use-init-web-config';

/**
* 获取页面的解析数据
*/
export const getAnalysisDetail = async (item: Analysis): Promise<AnalysisDetail[]> => {
return getCurrentBusiness(getCurrentKey())?.getAnalysisDetail(item);
};
/**
* 获取 视频播放详细 AnalysisVideoDetail
*/
export const getAnalysisVideoDetail = async (
item: AnalysisDetail
): Promise<AnalysisVideoDetail[]> => {
return getCurrentBusiness(getCurrentKey())?.getAnalysisVideoDetail(item);
};

export const getSeriesCurrentContent = async (): Promise<ComicHistory> => {
return getCurrentBusiness(getCurrentKey())?.getSeriesCurrentContent();
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghs",
"version": "4.0.29",
"version": "4.0.34",
"main": "dist-electron/main/index.js",
"license": "MIT",
"servicePort": 13356,
Expand Down
24 changes: 24 additions & 0 deletions packages/types/src/business/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum ItemDetailType {
image = 'image',
win = 'win',
comic = 'comic',
// 序列
series = 'series',
}
// 将上边枚举转换为联合类型
export type ItemDetailTypeUnion = keyof typeof ItemDetailType;
Expand Down Expand Up @@ -64,6 +66,26 @@ export interface Comment {
datetime: string;
comment: string;
}

/**
*
*/
export interface Analysis {
url: string;
title: string;
total: number;
}
export interface AnalysisDetail {
url: string;
title: string;
}
export interface AnalysisVideoDetail {
type?: string | 'mp4' | 'm3u8';
url?: string;
name?: string;
description?: string;
[x: string]: any;
}
/**
*点击Item,后获取详细信息
*/
Expand All @@ -73,6 +95,8 @@ export interface DetailInfo {
renderType: RenderTypeUnion;
details: Detail[];
relations: Item[];
// 系列明细,支持电视剧
analysis?: Analysis[];
}

/**
Expand Down
17 changes: 16 additions & 1 deletion packages/types/src/business/web-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import type { CheerioAPI } from 'cheerio';
import type { Cheerio } from 'cheerio/lib/cheerio';
import type { Element } from 'domhandler';
import type { DetailInfo, Item, Pagination, Tag, UrlAppend, UrlReplace } from '@/business/index';
import type { Analysis } from '../../dist';
import type {
AnalysisDetail,
AnalysisVideoDetail,
DetailInfo,
Item,
Pagination,
Tag,
UrlAppend,
UrlReplace,
} from '@/business/index';

export type SetTag = '标签' | '收藏' | '历史' | '过滤选项' | '系统配置' | '日志' | '配置';
export interface CContent {
Expand Down Expand Up @@ -37,6 +47,7 @@ export interface BaseConfig {

adapterImageCode?: string;
comicImgMaxWidth?: string;
[key: string]: any;
}

export interface WebConfig extends BaseConfig {
Expand All @@ -62,4 +73,8 @@ export interface WebConfig extends BaseConfig {
getContents?: (url: string, cheerio: any) => Promise<CContent[]>;
// 漫画处理,获取图片
getComicImages?: (url: string, cheerio: any) => Promise<CComic[]>;
// 电视剧处理,多解析原处理
getAnalysisDetail?: (item: Analysis, cheerio: any) => Promise<AnalysisDetail[]>;
// 获取剧集的url
getAnalysisVideoDetail?: (item: AnalysisDetail, cheerio: any) => Promise<AnalysisVideoDetail[]>;
}
2 changes: 1 addition & 1 deletion src/components/comic/comic-image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
type: 'image',
url: imgSrc.value,
title: `${imagesBase64[hashString(props.url)]}/${keys(imagesBase64).length}`,
title: `${+imagesBase64[hashString(props.url)] + 1}/${keys(imagesBase64).length}`,
},
]);
imagesRef.value.scrollIntoView({ behavior: 'smooth' });
Expand Down
6 changes: 5 additions & 1 deletion src/components/dialog/ghs-dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@
closeDialog();
}
// 启用点击遮罩层关闭
if (props.maskClosed && event?.target?.className.indexOf('dx-dialog') > -1) {
if (
props.maskClosed &&
event?.target?.className?.indexOf &&
event?.target?.className?.indexOf('dx-dialog') > -1
) {
closeDialog();
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/imgViewer/hooks/useImgShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export default (transX: Ref<number>, transY: Ref<number>, scale: Ref<number>) =>
if (event.type === 'keydown') {
if (event.key === 'ArrowRight') {
nextImg();
bus.emit(ImgEmitEnum.nextImg, hashString(imgUrl.value));
// bus.emit(ImgEmitEnum.nextImg, hashString(imgUrl.value));
}
if (event.key === 'ArrowLeft') {
preImg();
bus.emit(ImgEmitEnum.preImg, hashString(imgUrl.value));
// bus.emit(ImgEmitEnum.preImg, hashString(imgUrl.value));
}
}
};
Expand Down
60 changes: 60 additions & 0 deletions src/components/player/ghs-player-comments.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<a-float-button
v-if="commentsRef?.length > 0"
tooltip="查看评论"
type="default"
:style="{
right: '15px',
top: '250px',
width: '30px',
height: '30px',
opacity: 0.2,
}"
@click="drawerOpenModel = true"
>
<template #icon>
<CommentOutlined :style="{ fontSize: '14px', color: '#323' }" />
</template>
</a-float-button>
<a-drawer
v-model:open="drawerOpenModel"
title=""
placement="right"
:closable="false"
:mask-closable="true"
:z-index="20000"
root-class-name="ghs-video-drawer-container"
:content-wrapper-style="{ zIndex: 20000 }"
:body-style="{ zIndex: 20000, padding: '10px' }"
width="55%"
:get-container="getDrawerContainer"
:style="{ position: 'absolute' }"
>
<div h-full w-full overflow-auto>
<GhsComment
v-for="item in commentsRef"
:key="item.comment"
:datetime="item.datetime"
:comment="item.comment"
>
</GhsComment>
</div>
</a-drawer>
</template>
<script setup lang="ts">
import { CommentOutlined } from '@ant-design/icons-vue';
import type { PropType } from 'vue-demi';
import type { Comment } from '@ghs/types';
import { useVModel } from '@vueuse/core';
import { ref } from 'vue';
import GhsComment from '@/components/comment/ghs-comment.vue';
const props = defineProps({ comments: Array as PropType<Comment[]> });
const emits = defineEmits(['update:comments']);
const drawerOpenModel = ref(false);
const commentsRef = useVModel(props, 'comments', emits);
const getDrawerContainer = () => document.getElementById('body');
</script>

<style scoped lang="less"></style>
Loading

0 comments on commit c6629a0

Please sign in to comment.