Skip to content

Commit

Permalink
feat: added priority in spider and schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jul 2, 2023
1 parent 9d426f8 commit 2f20356
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 38 deletions.
51 changes: 33 additions & 18 deletions src/components/schedule/ScheduleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@
</cl-form-item>
<!-- ./Row -->

<!-- Row -->
<cl-form-item
:span="2"
:offset="2"
:label="t('components.spider.form.priority')"
prop="priority"
>
<el-select
v-model="form.priority"
:placeholder="t('components.spider.form.priority')"
:disabled="isFormItemDisabled('priority')"
id="priority"
class-name="priority"
>
<el-option
v-for="op in priorityOptions"
:key="op.value"
:label="op.label"
:value="op.value"
/>
</el-select>
</cl-form-item>
<!-- ./Row -->

<!-- Row -->
<cl-form-item
:span="2"
Expand Down Expand Up @@ -128,30 +152,15 @@
<!-- ./Row -->

<cl-form-item
v-if="form.mode === TASK_MODE_SELECTED_NODE_TAGS"
:span="4"
:label="t('components.schedule.form.selectedTags')"
prop="node_tags"
required
>
<cl-check-tag-group
v-locate="'node_tags'"
v-model="form.node_tags"
:disabled="isFormItemDisabled('node_tags')"
:options="allNodeTags"
/>
</cl-form-item>

<cl-form-item
v-if="[TASK_MODE_SELECTED_NODES, TASK_MODE_SELECTED_NODE_TAGS].includes(form.mode)"
v-if="[TASK_MODE_SELECTED_NODES].includes(form.mode)"
:span="4"
:label="t('components.schedule.form.selectedNodes')"
required
>
<cl-check-tag-group
v-locate="'node_ids'"
v-model="form.node_ids"
:disabled="form.mode === TASK_MODE_SELECTED_NODE_TAGS && isFormItemDisabled('node_ids')"
:disabled="isFormItemDisabled('node_ids')"
:options="allNodeSelectOptions"
/>
</cl-form-item>
Expand Down Expand Up @@ -184,6 +193,7 @@ import useNode from '@/components/node/node';
import {ElMessage} from 'element-plus';
import {useI18n} from 'vue-i18n';
import {sendEvent} from '@/admin/umeng';
import useTask from "@/components/task/task";
export default defineComponent({
name: 'ScheduleForm',
Expand All @@ -206,6 +216,11 @@ export default defineComponent({
allListSelectOptions: allSpiderSelectOptions,
} = useSpider(store);
// use task
const {
priorityOptions,
} = useTask(store);
// use schedule
const {
form,
Expand All @@ -231,7 +246,7 @@ export default defineComponent({
allSpiderSelectOptions,
allNodeSelectOptions,
allNodeTags,
priorityOptions,
TASK_MODE_SELECTED_NODES,
TASK_MODE_SELECTED_NODE_TAGS,
onEnabledChange,
Expand Down
4 changes: 2 additions & 2 deletions src/components/spider/RunSpiderDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ export default defineComponent({
// get run options
const getOptions = (): SpiderRunOptions => {
return {
mode: TASK_MODE_RANDOM,
mode: spider.value.mode || TASK_MODE_RANDOM,
cmd: spider.value.cmd,
param: spider.value.param,
priority: 5,
priority: spider.value.priority || 5,
};
};
Expand Down
55 changes: 37 additions & 18 deletions src/components/spider/SpiderForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@
</cl-form-item>
<!-- ./Row -->

<!-- Row -->
<cl-form-item
:span="2"
:offset="2"
:label="t('components.spider.form.priority')"
prop="priority"
>
<el-select
v-model="form.priority"
:placeholder="t('components.spider.form.priority')"
:disabled="isFormItemDisabled('priority')"
id="priority"
class-name="priority"
>
<el-option
v-for="op in priorityOptions"
:key="op.value"
:label="op.label"
:value="op.value"
/>
</el-select>
</cl-form-item>
<!-- ./Row -->

<!-- Row -->
<cl-form-item
:span="2"
Expand Down Expand Up @@ -107,24 +131,9 @@
</cl-form-item>
<!-- ./Row -->

<!--Row-->
<cl-form-item
v-if="form.mode === TASK_MODE_SELECTED_NODE_TAGS"
:span="4"
:label="t('components.spider.form.selectedTags')"
prop="node_tags"
required
>
<cl-check-tag-group
v-model="form.node_tags"
:options="allNodeTags"
:disabled="isFormItemDisabled('node_tags')"
id="node-tags"
class-name="node-tags"
/>
</cl-form-item>

<cl-form-item
v-if="[TASK_MODE_SELECTED_NODES, TASK_MODE_SELECTED_NODE_TAGS].includes(form.mode)"
v-if="[TASK_MODE_SELECTED_NODES].includes(form.mode)"
:span="4"
:label="t('components.spider.form.selectedNodes')"
prop="node_ids"
Expand All @@ -133,12 +142,14 @@
<cl-check-tag-group
v-model="form.node_ids"
:options="allNodeSelectOptions"
:disabled="form.mode === TASK_MODE_SELECTED_NODE_TAGS && isFormItemDisabled('node_ids')"
:disabled="isFormItemDisabled('node_ids')"
id="node"
class-name="nodes"
/>
</cl-form-item>
<!--./Row-->

<!--Row-->
<cl-form-item
:span="4"
:label="t('components.spider.form.description')"
Expand All @@ -153,6 +164,7 @@
class="description"
/>
</cl-form-item>
<!--./Row-->
</cl-form>
</template>

Expand All @@ -167,6 +179,7 @@ import pinyin, {STYLE_NORMAL} from 'pinyin';
import {isZeroObjectId} from '@/utils/mongo';
import {useI18n} from 'vue-i18n';
import useSpiderDetail from "@/views/spider/detail/useSpiderDetail";
import useTask from "@/components/task/task";
export default defineComponent({
name: 'SpiderForm',
Expand All @@ -188,6 +201,11 @@ export default defineComponent({
allListSelectOptionsWithEmpty: allProjectSelectOptions,
} = useProject(store);
// use task
const {
priorityOptions,
} = useTask(store);
// use spider
const {
form,
Expand Down Expand Up @@ -237,6 +255,7 @@ export default defineComponent({
allNodeSelectOptions,
allNodeTags,
allProjectSelectOptions,
priorityOptions,
onColInput,
onDataCollectionSuggestionSelect,
onDataCollectionInput,
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/en/components/spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const spider: LComponentsSpider = {
selectedTags: 'Selected Tags',
selectedNodes: 'Selected Nodes',
description: 'Description',
priority: 'Priority',
},
actions: {
files: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/zh/components/spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const spider: LComponentsSpider = {
selectedTags: '指定标签',
selectedNodes: '指定节点',
description: '描述',
priority: '优先级',
},
actions: {
files: {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/i18n/components/spider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface LComponentsSpider {
selectedTags: string;
selectedNodes: string;
description: string;
priority: string;
};
actions: {
files: {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/models/spider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export declare global {
spider_type?: string;
cmd?: string;
param?: string;
priority?: number;
col_id?: string;
col_name?: string;
data_source_id?: string;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/views/schedule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Schedule {
cron?: string;
cmd?: string;
param?: string;
priority?: number;
mode?: TaskMode;
node_ids?: string[];
node_tags?: string[];
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const state = {
return {
enabled: true,
mode: TASK_MODE_RANDOM,
priority: 5,
};
},
tabs: [
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const state = {
newFormFn: () => {
return {
mode: TASK_MODE_RANDOM,
priority: 5,
};
},
tabs: [
Expand Down

0 comments on commit 2f20356

Please sign in to comment.