mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
feat: refactor to remove unused 'getAllList' methods and related state properties
This commit is contained in:
@@ -218,12 +218,11 @@ func (r *Runner) Cancel(force bool) (err error) {
|
||||
r.cancel()
|
||||
|
||||
// Kill process
|
||||
r.Debugf("attempt to kill process[%d]", r.pid)
|
||||
err = utils.KillProcess(r.cmd, force)
|
||||
if err != nil {
|
||||
r.Errorf("kill process error: %v", err)
|
||||
return err
|
||||
r.Warnf("kill process error: %v", err)
|
||||
}
|
||||
r.Debugf("attempt to kill process[%d]", r.pid)
|
||||
|
||||
// Create a context with timeout
|
||||
ctx, cancel := context.WithTimeout(context.Background(), r.svc.GetCancelTimeout())
|
||||
@@ -1155,7 +1154,7 @@ func (r *Runner) logInternally(level string, message string) {
|
||||
|
||||
// Send to the same log system as task logs
|
||||
if r.conn != nil {
|
||||
r.writeLogLines([]string{internalLog})
|
||||
go r.writeLogLines([]string{internalLog})
|
||||
}
|
||||
|
||||
// Also log through the standard logger
|
||||
|
||||
@@ -10,7 +10,6 @@ const formComponentData = getDefaultFormComponentData<AutoProbe>();
|
||||
const useAutoProbe = (store: Store<RootStoreState>) => {
|
||||
// store
|
||||
const ns = 'autoprobe';
|
||||
const state = store.state[ns];
|
||||
|
||||
// form rules
|
||||
const formRules: FormRules = {
|
||||
@@ -20,16 +19,6 @@ const useAutoProbe = (store: Store<RootStoreState>) => {
|
||||
},
|
||||
};
|
||||
|
||||
// all autoprobe select options
|
||||
const allAutoProbeSelectOptions = computed<SelectOption[]>(() =>
|
||||
state.allList.map(d => {
|
||||
return {
|
||||
label: d.name,
|
||||
value: d._id,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
...useForm<AutoProbe>(
|
||||
'autoprobe',
|
||||
@@ -38,7 +27,6 @@ const useAutoProbe = (store: Store<RootStoreState>) => {
|
||||
formComponentData
|
||||
),
|
||||
formRules,
|
||||
allAutoProbeSelectOptions,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -10,14 +10,6 @@ const ns: ListStoreNamespace = 'dependency';
|
||||
const store = useStore();
|
||||
const { dependency: state, node: nodeState } = store.state as RootStoreState;
|
||||
|
||||
const activeNodes = computed(() => nodeState.allList.filter(n => n.active));
|
||||
|
||||
const toInstallNodes = computed(() => {
|
||||
const { mode, node_ids } = state.installForm;
|
||||
if (mode === 'all') return activeNodes.value;
|
||||
return activeNodes.value.filter(n => node_ids?.includes(n._id!));
|
||||
});
|
||||
|
||||
const visible = computed(() => state.activeDialogKey === 'config');
|
||||
|
||||
const form = computed(() => state.config);
|
||||
|
||||
@@ -9,7 +9,7 @@ const ns: ListStoreNamespace = 'dependency';
|
||||
const store = useStore();
|
||||
const { dependency: state, node: nodeState } = store.state as RootStoreState;
|
||||
|
||||
const activeNodes = computed(() => nodeState.allList.filter(n => n.active));
|
||||
const activeNodes = computed(() => nodeState.activeNodes.filter(n => n.active));
|
||||
|
||||
const toInstallNodes = computed(() => {
|
||||
const { mode, node_ids } = state.installForm;
|
||||
|
||||
@@ -9,7 +9,7 @@ const ns: ListStoreNamespace = 'dependency';
|
||||
const store = useStore();
|
||||
const { dependency: state, node: nodeState } = store.state as RootStoreState;
|
||||
|
||||
const activeNodes = computed(() => nodeState.allList.filter(n => n.active));
|
||||
const activeNodes = computed(() => nodeState.activeNodes.filter(n => n.active));
|
||||
|
||||
const toUninstallNodes = computed(() => {
|
||||
const { mode, node_ids } = state.uninstallForm;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="tsx">
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import { ref, computed, watch, Fragment } from 'vue';
|
||||
import { useStore } from 'vuex';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { FILE_ROOT } from '@/constants';
|
||||
@@ -37,7 +37,7 @@ const onConfirm = async () => {
|
||||
});
|
||||
const spiderId = res.data._id;
|
||||
ElMessage.success(
|
||||
<>
|
||||
<Fragment>
|
||||
<span class="el-message__content">
|
||||
{t('components.git.common.message.success.createSpider.title')}
|
||||
</span>
|
||||
@@ -49,9 +49,8 @@ const onConfirm = async () => {
|
||||
)}
|
||||
/>
|
||||
</span>
|
||||
</>
|
||||
</Fragment>
|
||||
);
|
||||
await store.dispatch(`${nsSpider}/getAllList`, { id: activeId.value });
|
||||
} catch (e) {
|
||||
ElMessage.error((e as Error).message);
|
||||
} finally {
|
||||
|
||||
@@ -18,7 +18,7 @@ const useNode = (store: Store<RootStoreState>) => {
|
||||
const formRules: FormRules = {};
|
||||
|
||||
const activeNodesSorted = computed(() => {
|
||||
return state.allList
|
||||
return state.activeNodes
|
||||
.filter(n => n.active)
|
||||
.sort((a, b) => {
|
||||
if (a.is_master) return -1;
|
||||
|
||||
@@ -31,7 +31,7 @@ const useNotificationAlert = (store: Store<RootStoreState>) => {
|
||||
() =>
|
||||
[
|
||||
{ label: t('common.mode.all'), value: EMPTY_OBJECT_ID },
|
||||
...nodeState.allList
|
||||
...nodeState.activeNodes
|
||||
.filter(node => node.active)
|
||||
.map(node => ({
|
||||
label: node.name,
|
||||
|
||||
@@ -44,56 +44,60 @@ const onTemplateChange = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const alertSelectOptions = computed<SelectOption<string>[]>(() =>
|
||||
notificationAlertState.allList.map((item: NotificationAlert) => ({
|
||||
label: item.name,
|
||||
value: item._id,
|
||||
}))
|
||||
);
|
||||
const alertSelectOptions = computed<SelectOption<string>[]>(() => {
|
||||
// TODO: implement
|
||||
return [];
|
||||
// notificationAlertState.allList.map((item: NotificationAlert) => ({
|
||||
// label: item.name,
|
||||
// value: item._id,
|
||||
// }))
|
||||
});
|
||||
|
||||
const createAlertVisible = ref(false);
|
||||
const alertFormRef = ref<typeof ClNotificationAlertForm>();
|
||||
const onCreateAlertClick = () => {
|
||||
// TODO: implement
|
||||
return [];
|
||||
// find existing alert
|
||||
let alertForm = notificationAlertState.allList.find(
|
||||
a => a.name === form.value.name
|
||||
) as NotificationAlert;
|
||||
|
||||
// create new alert if not found
|
||||
if (!alertForm) {
|
||||
if (form.value.template_key) {
|
||||
// find alert template
|
||||
alertForm = alertTemplates.find(
|
||||
t => t.key === form.value.template_key
|
||||
) as NotificationAlert;
|
||||
|
||||
// handle alert template
|
||||
if (alertForm) {
|
||||
alertForm = {
|
||||
...alertForm,
|
||||
name: t(alertForm.name as string),
|
||||
description: t(alertForm.description as string),
|
||||
enabled: true,
|
||||
template_key: form.value.template_key,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// create new alert form if template not found
|
||||
if (!alertForm) alertForm = notificationAlertState.newFormFn();
|
||||
|
||||
// set alert form
|
||||
store.commit('notificationAlert/setForm', { ...alertForm });
|
||||
|
||||
// open alert form create dialog
|
||||
createAlertVisible.value = true;
|
||||
} else {
|
||||
// set alert id if alert form exists
|
||||
store.commit(`${ns}/setForm`, {
|
||||
...form.value,
|
||||
alert_id: alertForm._id,
|
||||
});
|
||||
}
|
||||
// let alertForm = notificationAlertState.allList.find(
|
||||
// a => a.name === form.value.name
|
||||
// ) as NotificationAlert;
|
||||
//
|
||||
// // create new alert if not found
|
||||
// if (!alertForm) {
|
||||
// if (form.value.template_key) {
|
||||
// // find alert template
|
||||
// alertForm = alertTemplates.find(
|
||||
// t => t.key === form.value.template_key
|
||||
// ) as NotificationAlert;
|
||||
//
|
||||
// // handle alert template
|
||||
// if (alertForm) {
|
||||
// alertForm = {
|
||||
// ...alertForm,
|
||||
// name: t(alertForm.name as string),
|
||||
// description: t(alertForm.description as string),
|
||||
// enabled: true,
|
||||
// template_key: form.value.template_key,
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // create new alert form if template not found
|
||||
// if (!alertForm) alertForm = notificationAlertState.newFormFn();
|
||||
//
|
||||
// // set alert form
|
||||
// store.commit('notificationAlert/setForm', { ...alertForm });
|
||||
//
|
||||
// // open alert form create dialog
|
||||
// createAlertVisible.value = true;
|
||||
// } else {
|
||||
// // set alert id if alert form exists
|
||||
// store.commit(`${ns}/setForm`, {
|
||||
// ...form.value,
|
||||
// alert_id: alertForm._id,
|
||||
// });
|
||||
// }
|
||||
};
|
||||
const onCreateAlertConfirm = async () => {
|
||||
// validate alert form
|
||||
@@ -106,12 +110,6 @@ const onCreateAlertConfirm = async () => {
|
||||
);
|
||||
ElMessage.success(t('views.notification.message.success.create.alert'));
|
||||
|
||||
// set alert all list
|
||||
store.commit('notificationAlert/setAllList', [
|
||||
...notificationAlertState.allList,
|
||||
newAlert,
|
||||
]);
|
||||
|
||||
// set alert id
|
||||
store.commit(`${ns}/setForm`, {
|
||||
...form.value,
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Store } from 'vuex';
|
||||
import useForm from '@/components/ui/form/useForm';
|
||||
import useNotificationSettingService from '@/services/notification/useNotificationSettingService';
|
||||
import { getDefaultFormComponentData } from '@/utils/form';
|
||||
import { setupGetAllList } from '@/utils';
|
||||
|
||||
// form component data
|
||||
const formComponentData = getDefaultFormComponentData<NotificationSetting>();
|
||||
@@ -20,8 +19,6 @@ const useNotificationSetting = (store: Store<RootStoreState>) => {
|
||||
|
||||
const form = computed(() => state.form);
|
||||
|
||||
setupGetAllList(store, ['notificationAlert']);
|
||||
|
||||
return {
|
||||
...useForm<NotificationSetting>(
|
||||
'notificationSetting',
|
||||
|
||||
@@ -1,36 +1,15 @@
|
||||
import { computed, readonly } from 'vue';
|
||||
import { Store } from 'vuex';
|
||||
import { isDuplicated } from '@/utils/array';
|
||||
import useForm from '@/components/ui/form/useForm';
|
||||
import useProjectService from '@/services/project/projectService';
|
||||
import { getDefaultFormComponentData } from '@/utils/form';
|
||||
import {
|
||||
FORM_FIELD_TYPE_INPUT,
|
||||
FORM_FIELD_TYPE_INPUT_TEXTAREA,
|
||||
} from '@/constants/form';
|
||||
import { translate } from '@/utils/i18n';
|
||||
|
||||
// form component data
|
||||
const formComponentData = getDefaultFormComponentData<Project>();
|
||||
|
||||
const useProject = (store: Store<RootStoreState>) => {
|
||||
// store
|
||||
const ns = 'project';
|
||||
const state = store.state[ns];
|
||||
|
||||
// form rules
|
||||
const formRules: FormRules = {};
|
||||
|
||||
// all project select options
|
||||
const allProjectSelectOptions = computed<SelectOption[]>(() =>
|
||||
state.allList.map(d => {
|
||||
return {
|
||||
label: d.name,
|
||||
value: d._id,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
...useForm<Project>(
|
||||
'project',
|
||||
@@ -39,7 +18,6 @@ const useProject = (store: Store<RootStoreState>) => {
|
||||
formComponentData
|
||||
),
|
||||
formRules,
|
||||
allProjectSelectOptions,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -49,16 +49,6 @@ const useSchedule = (store: Store<RootStoreState>) => {
|
||||
},
|
||||
};
|
||||
|
||||
// all schedule select options
|
||||
const allScheduleSelectOptions = computed<SelectOption[]>(() =>
|
||||
state.allList.map(d => {
|
||||
return {
|
||||
label: d.name,
|
||||
value: d._id,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
const { activeId } = useScheduleDetail();
|
||||
|
||||
watch(
|
||||
@@ -87,7 +77,6 @@ const useSchedule = (store: Store<RootStoreState>) => {
|
||||
),
|
||||
modeOptions,
|
||||
formRules,
|
||||
allScheduleSelectOptions,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -23,10 +23,6 @@ const toRunNodes = computed(() => {
|
||||
return getToRunNodes(mode, node_ids, activeNodes.value);
|
||||
});
|
||||
|
||||
// use project
|
||||
const { allListSelectOptionsWithEmpty: allProjectSelectOptions } =
|
||||
useProject(store);
|
||||
|
||||
// use spider
|
||||
const { form, formRef, isFormItemDisabled, modeOptions } = useSpider(store);
|
||||
|
||||
|
||||
@@ -31,17 +31,6 @@ const useTask = (store: Store<RootStoreState>) => {
|
||||
// task id
|
||||
const id = computed(() => route.params.id);
|
||||
|
||||
const allListSelectOptions = computed<SelectOption[]>(() =>
|
||||
state.allList.map(task => {
|
||||
const spider = allSpiderDict.value.get(task.spider_id!);
|
||||
const timeAgo = formatTimeAgo(task.created_at!);
|
||||
return {
|
||||
label: `${spider?.name} (${timeAgo})`,
|
||||
value: task._id,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
...useForm<Task>('task', store, useTaskService(store), formComponentData),
|
||||
allSpiderDict,
|
||||
@@ -49,7 +38,6 @@ const useTask = (store: Store<RootStoreState>) => {
|
||||
modeOptions,
|
||||
modeOptionsDict,
|
||||
getPriorityLabel,
|
||||
allListSelectOptions,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -47,10 +47,6 @@ const form = computed<User>(() => {
|
||||
|
||||
const { allListSelectOptions: allRolesSelectOptions } = useRole(store);
|
||||
|
||||
onBeforeMount(() => {
|
||||
store.dispatch('role/getAllList');
|
||||
});
|
||||
|
||||
defineOptions({ name: 'ClUserForm' });
|
||||
</script>
|
||||
|
||||
|
||||
@@ -36,16 +36,6 @@ const useUser = (store: Store<RootStoreState>) => {
|
||||
},
|
||||
};
|
||||
|
||||
// all user select options
|
||||
const allUserSelectOptions = computed<SelectOption[]>(() =>
|
||||
state.allList.map(d => {
|
||||
return {
|
||||
label: d.username,
|
||||
value: d._id,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
// on change password
|
||||
const onChangePasswordFunc = async (id?: string) => {
|
||||
if (!id) return;
|
||||
@@ -78,7 +68,6 @@ const useUser = (store: Store<RootStoreState>) => {
|
||||
...useForm<User>('user', store, useUserService(store), formComponentData),
|
||||
modeOptions,
|
||||
formRules,
|
||||
allUserSelectOptions,
|
||||
onChangePasswordFunc,
|
||||
rolesOptions,
|
||||
};
|
||||
|
||||
@@ -58,7 +58,6 @@ export declare global {
|
||||
interface ListLayoutActionFunctions {
|
||||
setPagination: (pagination: TablePagination) => void;
|
||||
getList: () => Promise<void>;
|
||||
getAll: () => Promise<void>;
|
||||
deleteList: (ids: string[]) => Promise<Response | void>;
|
||||
deleteByIdConfirm: (row: BaseModel) => Promise<void>;
|
||||
onHeaderChange?: (
|
||||
|
||||
@@ -5,7 +5,6 @@ export declare global {
|
||||
updateById: (id: string, form: T) => Promise<ResponseWithData<T>>;
|
||||
deleteById: (id: string) => Promise<Response>;
|
||||
getList: (params?: ListRequestParams) => Promise<ResponseWithListData<T>>;
|
||||
getAll: () => Promise<ResponseWithListData<T>>;
|
||||
createList: (data: T[]) => Promise<ResponseWithListData<T>>;
|
||||
updateList: (ids: string[], data: T, fields: string[]) => Promise<Response>;
|
||||
deleteList: (ids: string[]) => Promise<Response>;
|
||||
|
||||
@@ -81,7 +81,6 @@ export declare global {
|
||||
tablePagination: TablePagination;
|
||||
tableListFilter: FilterConditionData[];
|
||||
tableListSort: SortData[];
|
||||
allList: T[];
|
||||
sidebarCollapsed: boolean;
|
||||
actionsCollapsed: boolean;
|
||||
tabs: NavItem[];
|
||||
@@ -93,8 +92,6 @@ export declare global {
|
||||
extends GetterTree<S, R> {
|
||||
dialogVisible: StoreGetter<BaseStoreState, boolean>;
|
||||
formListIds: StoreGetter<BaseStoreState, string[]>;
|
||||
allListSelectOptions: StoreGetter<BaseStoreState, SelectOption[]>;
|
||||
allDict: StoreGetter<BaseStoreState, Map<string, T>>;
|
||||
}
|
||||
|
||||
interface BaseStoreMutations<T = any>
|
||||
@@ -130,8 +127,6 @@ export declare global {
|
||||
{ key: string; sort: SortData }
|
||||
>;
|
||||
resetTableListSortByKey: StoreMutation<BaseStoreState<T>, string>;
|
||||
setAllList: StoreMutation<BaseStoreState<T>, T[]>;
|
||||
resetAllList: StoreMutation<BaseStoreState<T>>;
|
||||
setTabs: StoreMutation<BaseStoreState, NavItem[]>;
|
||||
setDisabledTabKeys: StoreMutation<BaseStoreState, string[]>;
|
||||
resetDisabledTabKeys: StoreMutation<BaseStoreState, string[]>;
|
||||
@@ -146,7 +141,6 @@ export declare global {
|
||||
deleteById: StoreAction<BaseStoreState<T>, string>;
|
||||
getList: StoreAction<BaseStoreState<T>>;
|
||||
getListWithParams: StoreAction<BaseStoreState<T>, ListRequestParams>;
|
||||
getAllList: StoreAction<BaseStoreState<T>>;
|
||||
createList: StoreAction<BaseStoreState<T>, T[]>;
|
||||
updateList: StoreAction<BaseStoreState<T>, BatchRequestPayloadWithData<T>>;
|
||||
deleteList: StoreAction<BaseStoreState<T>, BatchRequestPayload>;
|
||||
|
||||
@@ -7,6 +7,7 @@ type NodeStoreModule = BaseModule<
|
||||
|
||||
interface NodeStoreState extends BaseStoreState<CNode> {
|
||||
nodeMetricsMap: Record<string, Metric>;
|
||||
activeNodes: CNode[];
|
||||
}
|
||||
|
||||
type NodeStoreGetters = BaseStoreGetters<CNode>;
|
||||
@@ -19,4 +20,5 @@ interface NodeStoreMutations extends BaseStoreMutations<CNode> {
|
||||
|
||||
interface NodeStoreActions extends BaseStoreActions<CNode> {
|
||||
getNodeMetrics: StoreAction<NodeStoreState>;
|
||||
getActiveNodes: StoreAction<NodeStoreState>;
|
||||
}
|
||||
|
||||
@@ -37,24 +37,9 @@ const computedTabs = computed<NavItem[]>(() =>
|
||||
tabs.value.map((tab: NavItem) => ({ ...tab }))
|
||||
);
|
||||
|
||||
const computedAllListSelectOptions = computed(() => {
|
||||
if (props.allListSelectOptions) {
|
||||
return props.allListSelectOptions;
|
||||
}
|
||||
return store.state[ns.value].allList.map((item: BaseModel) => ({
|
||||
label: item[props.navItemNameKey],
|
||||
value: item._id,
|
||||
}));
|
||||
});
|
||||
|
||||
// get form before mount
|
||||
onBeforeMount(getForm);
|
||||
|
||||
// get all list before mount
|
||||
onBeforeMount(async () => {
|
||||
await store.dispatch(`${ns.value}/getAllList`);
|
||||
});
|
||||
|
||||
// reset form before unmount
|
||||
onBeforeUnmount(() => {
|
||||
if (!activeTabName.value) {
|
||||
|
||||
@@ -23,14 +23,10 @@ const useDetail = <T extends BaseModel>(ns: ListStoreNamespace) => {
|
||||
|
||||
const showActionsToggleTooltip = ref<boolean>(false);
|
||||
|
||||
const navItems = computed<NavItem<T>[]>(() =>
|
||||
state.allList.map((d: T) => {
|
||||
return {
|
||||
id: d._id,
|
||||
title: d.name,
|
||||
} as NavItem;
|
||||
})
|
||||
);
|
||||
const navItems = computed<NavItem<T>[]>(() => {
|
||||
// TODO: implement
|
||||
return [];
|
||||
});
|
||||
|
||||
const activeId = computed<string>(() => {
|
||||
const { id } = route.params;
|
||||
@@ -100,7 +96,6 @@ const useDetail = <T extends BaseModel>(ns: ListStoreNamespace) => {
|
||||
form: state.form,
|
||||
});
|
||||
ElMessage.success(t('common.message.success.save'));
|
||||
await Promise.all([store.dispatch(`${ns}/getAllList`), getForm()]);
|
||||
|
||||
// after save
|
||||
afterSave.value.map(fn => fn());
|
||||
|
||||
@@ -78,7 +78,6 @@ const useList = <T extends BaseModel>(
|
||||
setPagination: (pagination: TablePagination) =>
|
||||
store.commit(`${ns}/setTablePagination`, pagination),
|
||||
getList: () => store.dispatch(`${ns}/getList`),
|
||||
getAll: () => store.dispatch(`${ns}/getAllList`),
|
||||
deleteList: async (ids: string[]) => {
|
||||
await store.dispatch(`${ns}/deleteList`, ids);
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as llmService from './llm';
|
||||
// Export the LLM service
|
||||
export { llmService };
|
||||
|
||||
const { get, put, post, del, getList, getAll, putList, postList, delList } =
|
||||
const { get, put, post, del, getList, putList, postList, delList } =
|
||||
useRequest();
|
||||
|
||||
export const useService = <T = any>(endpoint: string): Services<T> => {
|
||||
@@ -29,9 +29,6 @@ export const useService = <T = any>(endpoint: string): Services<T> => {
|
||||
getList: async (params?: ListRequestParams) => {
|
||||
return await getList<T>(`${endpoint}`, params);
|
||||
},
|
||||
getAll: async () => {
|
||||
return await getAll<T>(`${endpoint}`);
|
||||
},
|
||||
createList: async (data: T[]) => {
|
||||
return await postList<T>(`${endpoint}/batch`, data);
|
||||
},
|
||||
|
||||
@@ -175,10 +175,6 @@ const useRequest = () => {
|
||||
return res;
|
||||
};
|
||||
|
||||
const getAll = async <T = any>(url: string, opts?: AxiosRequestConfig) => {
|
||||
return await getList(url, { all: true }, opts);
|
||||
};
|
||||
|
||||
const postList = async <T = any, R = ResponseWithListData, PM = any>(
|
||||
url: string,
|
||||
data?: T[],
|
||||
@@ -250,7 +246,6 @@ const useRequest = () => {
|
||||
put,
|
||||
del,
|
||||
getList,
|
||||
getAll,
|
||||
postList,
|
||||
putList,
|
||||
delList,
|
||||
|
||||
@@ -17,28 +17,11 @@ export const getDefaultUseListOptions = <T extends BaseModel>(
|
||||
};
|
||||
};
|
||||
|
||||
export const setupGetAllList = (
|
||||
store: Store<RootStoreState>,
|
||||
allListNamespaces: ListStoreNamespace[]
|
||||
) => {
|
||||
onBeforeMount(async () => {
|
||||
await Promise.all(
|
||||
allListNamespaces?.map(ns => store.dispatch(`${ns}/getAllList`)) || []
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const setupListComponent = (
|
||||
ns: ListStoreNamespace,
|
||||
store: Store<RootStoreState>,
|
||||
allListNamespaces?: ListStoreNamespace[],
|
||||
autoUpdate: boolean = true
|
||||
) => {
|
||||
if (!allListNamespaces) allListNamespaces = [];
|
||||
|
||||
// get all list
|
||||
setupGetAllList(store, allListNamespaces);
|
||||
|
||||
// auto update
|
||||
if (autoUpdate) {
|
||||
setupAutoUpdate(async () => {
|
||||
|
||||
@@ -19,7 +19,6 @@ export const getDefaultService = <T>(
|
||||
return dispatch(`${ns}/getList`);
|
||||
}
|
||||
},
|
||||
getAll: () => dispatch(`${ns}/getAllList`),
|
||||
createList: (data: T[]) => dispatch(`${ns}/createList`, data),
|
||||
updateList: (ids: string[], data: T, fields: string[]) =>
|
||||
dispatch(`${ns}/updateList`, { ids, data, fields }),
|
||||
|
||||
@@ -46,7 +46,6 @@ export const getDefaultStoreState = <T = any>(
|
||||
tablePagination,
|
||||
tableListFilter: [],
|
||||
tableListSort: [],
|
||||
allList: [],
|
||||
sidebarCollapsed: false,
|
||||
actionsCollapsed: false,
|
||||
tabs: [{ id: 'overview', title: t('common.tabs.overview') }],
|
||||
@@ -67,21 +66,6 @@ export const getDefaultStoreGetters = <T = any>(
|
||||
state.activeDialogKey !== undefined,
|
||||
formListIds: (state: BaseStoreState<T>) =>
|
||||
state.formList.map(d => (d as BaseModel)._id as string),
|
||||
allListSelectOptions: (state: BaseStoreState<T>) =>
|
||||
state.allList.map(d => {
|
||||
const _d = d as BaseModel;
|
||||
return {
|
||||
value: _d[opts?.selectOptionValueKey as string],
|
||||
label: _d[opts?.selectOptionLabelKey as string],
|
||||
};
|
||||
}),
|
||||
allDict: (state: BaseStoreState<T>) => {
|
||||
const dict = new Map<string, T>();
|
||||
state.allList.forEach(d =>
|
||||
dict.set((d as BaseModel)._id as string, d as any)
|
||||
);
|
||||
return dict;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -206,12 +190,6 @@ export const getDefaultStoreMutations = <T = any>(): BaseStoreMutations<T> => {
|
||||
resetTableListSortByKey: (state: BaseStoreState<T>, key) => {
|
||||
state.tableListSort = state.tableListSort.filter(d => d.key !== key);
|
||||
},
|
||||
setAllList: (state: BaseStoreState<T>, value: T[]) => {
|
||||
state.allList = value;
|
||||
},
|
||||
resetAllList: (state: BaseStoreState<T>) => {
|
||||
state.allList = [];
|
||||
},
|
||||
setTabs: (state: BaseStoreState<T>, tabs) => {
|
||||
state.tabs = tabs;
|
||||
},
|
||||
@@ -234,9 +212,6 @@ export const getDefaultStoreActions = <T = any>(
|
||||
{ commit }: StoreActionContext<BaseStoreState<T>>,
|
||||
ids: string[]
|
||||
) => Promise<Response>;
|
||||
getAllList: ({
|
||||
commit,
|
||||
}: StoreActionContext<BaseStoreState<T>>) => Promise<ResponseWithListData<T>>;
|
||||
createList: (
|
||||
{ state, commit }: StoreActionContext<BaseStoreState<T>>,
|
||||
data: T[]
|
||||
@@ -282,7 +257,6 @@ export const getDefaultStoreActions = <T = any>(
|
||||
updateById,
|
||||
deleteById,
|
||||
getList,
|
||||
getAll,
|
||||
createList,
|
||||
updateList,
|
||||
deleteList,
|
||||
@@ -346,11 +320,6 @@ export const getDefaultStoreActions = <T = any>(
|
||||
) => {
|
||||
return await getList(params);
|
||||
},
|
||||
getAllList: async ({ commit }: StoreActionContext<BaseStoreState<T>>) => {
|
||||
const res = await getAll();
|
||||
commit('setAllList', res.data || []);
|
||||
return res;
|
||||
},
|
||||
createList: async (_: StoreActionContext<BaseStoreState<T>>, data: T[]) => {
|
||||
return await createList(data);
|
||||
},
|
||||
|
||||
@@ -109,9 +109,6 @@ const actionFunctions = {
|
||||
},
|
||||
});
|
||||
},
|
||||
getAll: async () => {
|
||||
console.warn('getAll is not implemented');
|
||||
},
|
||||
deleteList: (ids: string[]) => {
|
||||
console.warn('deleteList is not implemented');
|
||||
},
|
||||
|
||||
@@ -53,7 +53,6 @@ const onDeleteSpider = async (item: FileNavItem) => {
|
||||
);
|
||||
await store.dispatch(`${nsSpider}/deleteById`, spider._id);
|
||||
ElMessage.success(t('common.message.success.delete'));
|
||||
await store.dispatch(`${nsSpider}/getAllList`, { id: activeId.value });
|
||||
};
|
||||
|
||||
defineOptions({ name: 'ClGitDetailTabFiles' });
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { useStore } from 'vuex';
|
||||
import { useDetail } from '@/layouts';
|
||||
import { setupGetAllList } from '@/utils';
|
||||
|
||||
const useNotificationAlertDetail = () => {
|
||||
const ns: ListStoreNamespace = 'notificationAlert';
|
||||
const store = useStore();
|
||||
|
||||
setupGetAllList(store, ['node']);
|
||||
|
||||
return {
|
||||
...useDetail<NotificationAlert>(ns),
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { useStore } from 'vuex';
|
||||
import { setupGetAllList } from '@/utils';
|
||||
import { useDetail } from '@/layouts';
|
||||
|
||||
const useNotificationChannelDetail = () => {
|
||||
const ns: ListStoreNamespace = 'notificationChannel';
|
||||
const store = useStore();
|
||||
|
||||
setupGetAllList(store, ['node', 'notificationChannel']);
|
||||
|
||||
return {
|
||||
...useDetail<NotificationChannel>(ns),
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { useStore } from 'vuex';
|
||||
import { useDetail } from '@/layouts';
|
||||
import { setupGetAllList } from '@/utils';
|
||||
|
||||
const useNotificationSettingDetail = () => {
|
||||
const ns: ListStoreNamespace = 'notificationSetting';
|
||||
const store = useStore();
|
||||
|
||||
setupGetAllList(store, ['notificationAlert', 'notificationChannel']);
|
||||
|
||||
return {
|
||||
...useDetail<NotificationSetting>(ns),
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import { useStore } from 'vuex';
|
||||
import { useDetail } from '@/layouts';
|
||||
import { setupGetAllList } from '@/utils/list';
|
||||
|
||||
const useScheduleDetail = () => {
|
||||
// store
|
||||
const store = useStore();
|
||||
|
||||
setupGetAllList(store, ['node', 'spider']);
|
||||
const ns: ListStoreNamespace = 'schedule';
|
||||
|
||||
return {
|
||||
...useDetail<Schedule>('schedule'),
|
||||
...useDetail<Schedule>(ns),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -28,26 +28,25 @@ const form = computed(() => state.form);
|
||||
const { activeId } = useSpiderDetail();
|
||||
|
||||
const { allDict: allDatabaseDict } = useDatabase(store);
|
||||
onBeforeMount(() => {
|
||||
store.dispatch(`database/getAllList`);
|
||||
});
|
||||
|
||||
const allDatabaseSelectOptions = computed<SelectOption[]>(() => {
|
||||
return databaseState.allList.map(db => {
|
||||
const value = db._id;
|
||||
let dbName = db.name;
|
||||
if (db._id === EMPTY_OBJECT_ID) {
|
||||
dbName = t('components.database.default.name');
|
||||
}
|
||||
let label = dbName;
|
||||
if (db.status === DATABASE_STATUS_OFFLINE) {
|
||||
label = `${dbName} (${t('components.database.status.label.offline')})`;
|
||||
}
|
||||
return {
|
||||
value,
|
||||
label,
|
||||
};
|
||||
});
|
||||
// TODO: implement
|
||||
return [];
|
||||
// return databaseState.allList.map(db => {
|
||||
// const value = db._id;
|
||||
// let dbName = db.name;
|
||||
// if (db._id === EMPTY_OBJECT_ID) {
|
||||
// dbName = t('components.database.default.name');
|
||||
// }
|
||||
// let label = dbName;
|
||||
// if (db.status === DATABASE_STATUS_OFFLINE) {
|
||||
// label = `${dbName} (${t('components.database.status.label.offline')})`;
|
||||
// }
|
||||
// return {
|
||||
// value,
|
||||
// label,
|
||||
// };
|
||||
// });
|
||||
});
|
||||
|
||||
const currentDatabase = computed(() => {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import { useStore } from 'vuex';
|
||||
import { useDetail } from '@/layouts';
|
||||
import { setupGetAllList } from '@/utils';
|
||||
import useFileService from '@/services/utils/file';
|
||||
|
||||
const useSpiderDetail = () => {
|
||||
const ns: ListStoreNamespace = 'spider';
|
||||
const store = useStore();
|
||||
|
||||
setupGetAllList(store, ['node', 'project']);
|
||||
|
||||
return {
|
||||
...useDetail<Spider>('spider'),
|
||||
...useFileService(ns, store),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { onBeforeUnmount } from 'vue';
|
||||
import { useStore } from 'vuex';
|
||||
import { useDetail } from '@/layouts';
|
||||
import { setupGetAllList } from '@/utils/list';
|
||||
|
||||
const useTaskDetail = () => {
|
||||
// store
|
||||
@@ -16,8 +15,6 @@ const useTaskDetail = () => {
|
||||
store.commit(`${ns}/disableLogAutoUpdate`);
|
||||
});
|
||||
|
||||
setupGetAllList(store, ['node', 'spider']);
|
||||
|
||||
return {
|
||||
...useDetail<Task>('task'),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user