Skip to content

Commit

Permalink
feat: added multi-spider git
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 29, 2024
1 parent 920597a commit 42e5cb3
Show file tree
Hide file tree
Showing 36 changed files with 250 additions and 108 deletions.
3 changes: 0 additions & 3 deletions src/components/file/FileEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useStore } from 'vuex';
import * as monaco from 'monaco-editor';
import { FILE_ROOT } from '@/constants/file';
// components
import FileEditorNavTabs from '@/components/file/FileEditorNavTabs.vue';
import { useI18n } from 'vue-i18n';
import { sendEvent } from '@/admin/umeng';
Expand Down Expand Up @@ -404,7 +402,6 @@ const initEditor = async () => {
addSaveKeyMap();
// on editor change
// editor.on('change', onContentChange);
editor.onDidChangeModelContent(() => {
onContentChange(editor?.getValue() || '');
});
Expand Down
63 changes: 53 additions & 10 deletions src/components/file/FileEditorNavMenu.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import boolean from 'async-validator/dist-types/validator/boolean';
defineOptions({ name: 'ClFileEditorNavMenu' });
import {
computed,
Expand All @@ -8,6 +10,7 @@ import {
reactive,
ref,
watch,
inject,
} from 'vue';
import { useI18n } from 'vue-i18n';
import Node from 'element-plus/es/components/tree/src/model/node';
Expand All @@ -25,6 +28,7 @@ const props = defineProps<{
defaultExpandedKeys: string[];
styles?: FileEditorStyles;
}>();
const emit = defineEmits<{
(e: 'node-click', item: FileNavItem): void;
(e: 'node-db-click', item: FileNavItem): void;
Expand All @@ -46,6 +50,13 @@ const tree = ref<typeof ElTree>();
const fileEditorNavMenu = ref<HTMLDivElement>();
const highlightTagFn = inject<{ (item: FileNavItem): TagProps | undefined }>(
'highlight-tag-fn'
);
const highlightClickFn = inject<{ (item: FileNavItem): void }>(
'highlight-click-fn'
);
const clickStatus = reactive<FileEditorNavMenuClickStatus>({
clicked: false,
item: undefined,
Expand Down Expand Up @@ -77,10 +88,6 @@ const removeDefaultExpandedKey = (key: string) => {
expandedKeys.value.splice(idx, 1);
};
const resetDefaultExpandedKeys = () => {
expandedKeys.value = [];
};
const resetClickStatus = () => {
clickStatus.clicked = false;
clickStatus.item = undefined;
Expand Down Expand Up @@ -110,6 +117,7 @@ const updateSelectedMap = (item: FileNavItem) => {
const onNodeClick = (item: FileNavItem) => {
if (clickStatus.clicked && clickStatus.item?.path === item.path) {
if (item.is_dir) return;
emit('node-db-click', item);
updateSelectedMap(item);
resetClickStatus();
Expand All @@ -127,7 +135,7 @@ const onNodeClick = (item: FileNavItem) => {
}, 200);
};
const onNodeContextMenuShow = (ev: Event, item: FileNavItem) => {
const onNodeContextMenuShow = (_: Event, item: FileNavItem) => {
contextMenuClicking.value = true;
activeContextMenuItem.value = item;
setTimeout(() => {
Expand Down Expand Up @@ -216,13 +224,13 @@ const onNodeContextMenuDelete = async (item: FileNavItem) => {
emit('ctx-menu-delete', item);
};
const onNodeDragEnter = (draggingNode: Node, dropNode: Node) => {
const onNodeDragEnter = (_: Node, dropNode: Node) => {
const item = dropNode.data as FileNavItem;
if (!item.path) return;
dragCache[item.path] = true;
};
const onNodeDragLeave = (draggingNode: Node, dropNode: Node) => {
const onNodeDragLeave = (_: Node, dropNode: Node) => {
const item = dropNode.data as FileNavItem;
if (!item.path) return;
dragCache[item.path] = false;
Expand Down Expand Up @@ -422,11 +430,10 @@ const fileSearchString = ref<string>('');
@node-drag-end="onNodeDragEnd"
@node-drop="onNodeDrop"
@node-click="onNodeClick"
@node-contextmenu="onNodeContextMenuShow"
@node-expand="onNodeExpand"
@node-collapse="onNodeCollapse"
>
<template #default="{ data }">
<template #default="{ data }: { data: FileNavItem }">
<cl-file-editor-nav-menu-context-menu
:clicking="contextMenuClicking"
:visible="isShowContextMenu(data)"
Expand Down Expand Up @@ -458,11 +465,37 @@ const fileSearchString = ref<string>('');
:name="data.name"
/>
</span>
<span class="title">
<span
class="title"
:style="{
color: highlightTagFn?.(data)?.color,
}"
>
{{ data.name }}
</span>
</div>
</div>
<template v-if="highlightTagFn?.(data)">
<el-tooltip
:content="highlightTagFn(data).tooltip"
:disabled="!highlightTagFn(data).tooltip"
>
<div
class="nav-item-suffix"
@click="
(event: Event) => {
event.stopPropagation();
highlightClickFn?.(data);
}
"
>
<cl-icon
:icon="highlightTagFn(data).icon"
:color="highlightTagFn(data).color"
/>
</div>
</el-tooltip>
</template>
</cl-file-editor-nav-menu-context-menu>
</template>
</el-tree-v2>
Expand Down Expand Up @@ -556,6 +589,16 @@ const fileSearchString = ref<string>('');
}
}
}
.nav-item-suffix {
position: absolute;
height: 100%;
top: 0;
right: 10px;
display: flex;
align-items: center;
z-index: 100;
}
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/components/git/GitRepo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup lang="ts">
defineOptions({ name: 'ClGitRepo' });
import { translate } from '@/utils';
defineProps<{
name?: string;
gitRootPath?: string;
}>();
const emit = defineEmits<{
(e: 'click'): void;
}>();
const t = translate;
</script>

<template>
<cl-tag
type="primary"
:label="name"
:icon="['fab', 'git']"
clickable
@click="emit('click')"
>
<template #tooltip>
<label>{{ t('components.git.spiders.gitRootPath') }}: </label>
<span v-if="gitRootPath">{{ gitRootPath }}</span>
<span v-else>~ ({{ t('components.file.rootDirectory') }})</span>
</template>
</cl-tag>
</template>

<style scoped lang="scss"></style>
1 change: 1 addition & 0 deletions src/components/git/GitStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const onRetry = async () => {
:spinning="data.spinning"
:tooltip="data.tooltip"
:type="data.type"
clickable
@click="emit('click')"
>
<template #tooltip>
Expand Down
5 changes: 3 additions & 2 deletions src/components/icon/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const props = withDefaults(
icon: Icon;
spinning?: boolean;
size: IconSize;
color?: string;
}>(),
{
size: 'default',
Expand All @@ -34,13 +35,13 @@ const isFaIcon = computed<boolean>(() => {
v-if="isFaIcon"
:class="spinning ? 'fa-spin' : ''"
:icon="icon"
:style="{ fontSize }"
:style="{ fontSize, color }"
class="icon"
/>
<i
v-else
:class="[spinning ? 'fa-spin' : '', icon, 'icon']"
:style="{ fontSize }"
:style="{ fontSize, color }"
/>
</template>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import CreateGitSpiderDialog from './git/CreateGitSpiderDialog.vue';
import GitBranchSelect from './git/GitBranchSelect.vue';
import GitFileStatus from './git/GitFileStatus.vue';
import GitForm from './git/GitForm.vue';
import GitRepo from './git/GitRepo.vue';
import GitStatus from './git/GitStatus.vue';
import UploadGitFilesDialog from './git/UploadGitFilesDialog.vue';
import useGit from './git/useGit';
Expand Down Expand Up @@ -111,7 +112,6 @@ import useSpider from './spider/useSpider';
import Switch from './switch/Switch.vue';
import ActionTab from './tab/ActionTab.vue';
import Tab from './tab/Tab.vue';
import * as tab from './tab/tab';
import Table from './table/Table.vue';
import TableActions from './table/TableActions.vue';
import TableCell from './table/TableCell.vue';
Expand Down Expand Up @@ -210,6 +210,7 @@ export {
GitBranchSelect as ClGitBranchSelect,
GitFileStatus as ClGitFileStatus,
GitForm as ClGitForm,
GitRepo as ClGitRepo,
GitStatus as ClGitStatus,
UploadGitFilesDialog as ClUploadGitFilesDialog,
useGit as useGit,
Expand Down Expand Up @@ -262,7 +263,6 @@ export {
Switch as ClSwitch,
ActionTab as ClActionTab,
Tab as ClTab,
tab as tab,
Table as ClTable,
TableActions as ClTableActions,
TableCell as ClTableCell,
Expand Down
1 change: 0 additions & 1 deletion src/components/tab/Tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useRouter } from 'vue-router';
import { Close } from '@element-plus/icons-vue';
import { translate } from '@/utils';
import { getPrimaryPath } from '@/utils/path';
import { Tab } from '@/components/tab/tab';
const props = withDefaults(
defineProps<{
Expand Down
6 changes: 0 additions & 6 deletions src/components/tab/tab.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/components/task/TaskStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const props = defineProps<{
status: TaskStatus;
size?: BasicSize;
error?: string;
clickable?: boolean;
}>();
const emit = defineEmits<{
Expand Down Expand Up @@ -91,6 +92,7 @@ const data = computed<TagProps>(() => {
:spinning="data.spinning"
:type="data.type"
:size="size"
:clickable="clickable"
@click="emit('click')"
>
<template #tooltip>
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/lang/en/components/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const git: LComponentsGit = {
error: 'Error',
autoPull: 'Auto Pull',
urlInvalid: 'Invalid URL',
spider: 'Spider',
},
common: {
currentBranch: 'Current Branch',
Expand Down Expand Up @@ -174,6 +175,7 @@ const git: LComponentsGit = {
create: 'Create a new spider',
},
},
gitRootPath: 'Git Root Path',
},
};

Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/en/views/gits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const gits: LViewGits = {
columns: {
name: 'Name',
status: 'Status',
spiders: 'Spiders',
},
},
navActions: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/en/views/spiders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const spiders: LViewsSpiders = {
columns: {
name: 'Name',
project: 'Project',
git: 'Git Repo',
lastStatus: 'Last Status',
lastRunAt: 'Last Run At',
stats: 'Stats',
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/lang/zh/components/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const git: LComponentsGit = {
error: '错误',
autoPull: '自动拉取',
urlInvalid: '无效 URL',
spider: '爬虫',
},
common: {
currentBranch: '当前分支',
Expand Down Expand Up @@ -174,6 +175,7 @@ const git: LComponentsGit = {
create: '创建一个新的爬虫',
},
},
gitRootPath: 'Git 仓库路径',
},
};

Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/zh/views/gits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const gits: LViewGits = {
columns: {
name: '名称',
status: '状态',
spiders: '爬虫',
},
},
navActions: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/zh/views/spiders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const spiders: LViewsSpiders = {
columns: {
name: '名称',
project: '项目',
git: 'Git 仓库',
lastStatus: '最近状态',
lastRunAt: '最近运行',
stats: '统计数据',
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/components/tab/Tab.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export declare global {
interface Tab {
id?: number;
path: string;
dragging?: boolean;
isAction?: boolean;
}
}
1 change: 1 addition & 0 deletions src/interfaces/components/table/Table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export declare global {
allowFilterItems?: boolean;
required?: boolean;
className?: string;
proOnly?: boolean;
}

type TableColumns<T = any> = TableColumn<T>[];
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/i18n/components/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface LComponentsGit {
error: string;
autoPull: string;
urlInvalid: string;
spider: string;
};
common: {
currentBranch: string;
Expand Down Expand Up @@ -174,5 +175,6 @@ interface LComponentsGit {
create: string;
};
};
gitRootPath: string;
};
}
1 change: 1 addition & 0 deletions src/interfaces/i18n/views/gits.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface LViewGits {
columns: {
name: string;
status: string;
spiders: string;
};
};
navActions: LNavActions;
Expand Down
Loading

0 comments on commit 42e5cb3

Please sign in to comment.