chore(frontend): introduce prettier + eslint and prune unused code
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,141 +4,166 @@ import {
|
||||
EditOutlined,
|
||||
PauseCircleOutlined,
|
||||
PlayCircleOutlined,
|
||||
} from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
import { message, type TableColumnsType } from "ant-design-vue";
|
||||
import type { ScheduleTask, ScheduleTaskListParams } from "@geo/shared-types";
|
||||
import type { Dayjs } from "dayjs";
|
||||
import { computed, reactive, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
} from '@ant-design/icons-vue'
|
||||
import type { ScheduleTask, ScheduleTaskListParams } from '@geo/shared-types'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
import { message, type TableColumnsType } from 'ant-design-vue'
|
||||
import type { Dayjs } from 'dayjs'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import ScheduleTaskModal from "@/components/ScheduleTaskModal.vue";
|
||||
import { promptRulesApi, schedulesApi } from "@/lib/api";
|
||||
import { formatCronExecutionTime, formatDateTime } from "@/lib/display";
|
||||
import { formatError } from "@/lib/errors";
|
||||
import { formatPublishPlatformList } from "@/lib/publish-platforms";
|
||||
import ScheduleTaskModal from '@/components/ScheduleTaskModal.vue'
|
||||
import { promptRulesApi, schedulesApi } from '@/lib/api'
|
||||
import { formatCronExecutionTime, formatDateTime } from '@/lib/display'
|
||||
import { formatError } from '@/lib/errors'
|
||||
import { formatPublishPlatformList } from '@/lib/publish-platforms'
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useI18n();
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useI18n()
|
||||
|
||||
const modalOpen = ref(false);
|
||||
const editingTask = ref<ScheduleTask | null>(null);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const createdRange = ref<[Dayjs, Dayjs] | null>(null);
|
||||
const modalOpen = ref(false)
|
||||
const editingTask = ref<ScheduleTask | null>(null)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const createdRange = ref<[Dayjs, Dayjs] | null>(null)
|
||||
|
||||
const draftFilters = reactive<{
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
prompt_rule_id?: number
|
||||
status?: string
|
||||
keyword?: string
|
||||
}>({
|
||||
keyword: "",
|
||||
});
|
||||
keyword: '',
|
||||
})
|
||||
|
||||
const appliedFilters = reactive<{
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
created_from?: string;
|
||||
created_to?: string;
|
||||
prompt_rule_id?: number
|
||||
status?: string
|
||||
keyword?: string
|
||||
created_from?: string
|
||||
created_to?: string
|
||||
}>({
|
||||
keyword: "",
|
||||
});
|
||||
keyword: '',
|
||||
})
|
||||
|
||||
const rulesQuery = useQuery({
|
||||
queryKey: ["promptRules", "simple"],
|
||||
queryKey: ['promptRules', 'simple'],
|
||||
queryFn: () => promptRulesApi.listSimple(),
|
||||
});
|
||||
})
|
||||
|
||||
const promptOptions = computed(() =>
|
||||
(rulesQuery.data.value ?? []).map((rule) => ({
|
||||
label: rule.name,
|
||||
value: rule.id,
|
||||
})),
|
||||
);
|
||||
)
|
||||
|
||||
const statusOptions = computed(() => [
|
||||
{ label: t("custom.schedule.enabled"), value: "enabled" },
|
||||
{ label: t("custom.schedule.disabled"), value: "disabled" },
|
||||
]);
|
||||
{ label: t('custom.schedule.enabled'), value: 'enabled' },
|
||||
{ label: t('custom.schedule.disabled'), value: 'disabled' },
|
||||
])
|
||||
|
||||
const listParams = computed<ScheduleTaskListParams>(() => {
|
||||
const params: ScheduleTaskListParams = {
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
};
|
||||
if (appliedFilters.prompt_rule_id) params.prompt_rule_id = appliedFilters.prompt_rule_id;
|
||||
if (appliedFilters.status) params.status = appliedFilters.status;
|
||||
if (appliedFilters.keyword?.trim()) params.keyword = appliedFilters.keyword.trim();
|
||||
if (appliedFilters.created_from) params.created_from = appliedFilters.created_from;
|
||||
if (appliedFilters.created_to) params.created_to = appliedFilters.created_to;
|
||||
return params;
|
||||
});
|
||||
}
|
||||
if (appliedFilters.prompt_rule_id) params.prompt_rule_id = appliedFilters.prompt_rule_id
|
||||
if (appliedFilters.status) params.status = appliedFilters.status
|
||||
if (appliedFilters.keyword?.trim()) params.keyword = appliedFilters.keyword.trim()
|
||||
if (appliedFilters.created_from) params.created_from = appliedFilters.created_from
|
||||
if (appliedFilters.created_to) params.created_to = appliedFilters.created_to
|
||||
return params
|
||||
})
|
||||
|
||||
const listQuery = useQuery({
|
||||
queryKey: computed(() => ["schedules", "list", listParams.value]),
|
||||
queryKey: computed(() => ['schedules', 'list', listParams.value]),
|
||||
queryFn: () => schedulesApi.list(listParams.value),
|
||||
});
|
||||
})
|
||||
|
||||
const columns = computed<TableColumnsType<ScheduleTask>>(() => [
|
||||
{ title: t("custom.schedule.name"), dataIndex: "name", key: "name", width: 220 },
|
||||
{ title: t("custom.schedule.rule"), dataIndex: "prompt_rule_name", key: "prompt_rule_name", width: 180 },
|
||||
{ title: t("custom.instant.executionStatus"), dataIndex: "status", key: "status", width: 140 },
|
||||
{ title: t("custom.instant.executionTime"), dataIndex: "cron_expr", key: "cron_expr", width: 170 },
|
||||
{ title: t("custom.schedule.autoPublishPlatforms"), dataIndex: "auto_publish_platforms", key: "auto_publish_platforms", width: 200 },
|
||||
{ title: t("custom.task.generateCount"), dataIndex: "generate_count", key: "generate_count", width: 120 },
|
||||
{ title: t("custom.instant.createdTime"), dataIndex: "created_at", key: "created_at", width: 170 },
|
||||
{ title: t("common.actions"), key: "actions", width: 140, fixed: "right", align: "right" },
|
||||
]);
|
||||
{ title: t('custom.schedule.name'), dataIndex: 'name', key: 'name', width: 220 },
|
||||
{
|
||||
title: t('custom.schedule.rule'),
|
||||
dataIndex: 'prompt_rule_name',
|
||||
key: 'prompt_rule_name',
|
||||
width: 180,
|
||||
},
|
||||
{ title: t('custom.instant.executionStatus'), dataIndex: 'status', key: 'status', width: 140 },
|
||||
{
|
||||
title: t('custom.instant.executionTime'),
|
||||
dataIndex: 'cron_expr',
|
||||
key: 'cron_expr',
|
||||
width: 170,
|
||||
},
|
||||
{
|
||||
title: t('custom.schedule.autoPublishPlatforms'),
|
||||
dataIndex: 'auto_publish_platforms',
|
||||
key: 'auto_publish_platforms',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: t('custom.task.generateCount'),
|
||||
dataIndex: 'generate_count',
|
||||
key: 'generate_count',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: t('custom.instant.createdTime'),
|
||||
dataIndex: 'created_at',
|
||||
key: 'created_at',
|
||||
width: 170,
|
||||
},
|
||||
{ title: t('common.actions'), key: 'actions', width: 140, fixed: 'right', align: 'right' },
|
||||
])
|
||||
|
||||
const removeMutation = useMutation({
|
||||
mutationFn: (id: number) => schedulesApi.remove(id),
|
||||
onSuccess: async () => {
|
||||
message.success(t("custom.messages.scheduleDeleted"));
|
||||
await queryClient.invalidateQueries({ queryKey: ["schedules"] });
|
||||
message.success(t('custom.messages.scheduleDeleted'))
|
||||
await queryClient.invalidateQueries({ queryKey: ['schedules'] })
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
});
|
||||
})
|
||||
|
||||
const toggleStatusMutation = useMutation({
|
||||
mutationFn: ({ id, status }: { id: number; status: "enabled" | "disabled" }) =>
|
||||
mutationFn: ({ id, status }: { id: number; status: 'enabled' | 'disabled' }) =>
|
||||
schedulesApi.toggleStatus(id, { status }),
|
||||
onSuccess: async (_data, variables) => {
|
||||
message.success(
|
||||
variables.status === "enabled"
|
||||
? t("custom.messages.scheduleEnabled")
|
||||
: t("custom.messages.scheduleDisabled"),
|
||||
);
|
||||
await queryClient.invalidateQueries({ queryKey: ["schedules"] });
|
||||
variables.status === 'enabled'
|
||||
? t('custom.messages.scheduleEnabled')
|
||||
: t('custom.messages.scheduleDisabled'),
|
||||
)
|
||||
await queryClient.invalidateQueries({ queryKey: ['schedules'] })
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
});
|
||||
})
|
||||
|
||||
function applyFilters(): void {
|
||||
page.value = 1;
|
||||
appliedFilters.prompt_rule_id = draftFilters.prompt_rule_id;
|
||||
appliedFilters.status = draftFilters.status;
|
||||
appliedFilters.keyword = draftFilters.keyword?.trim() || "";
|
||||
appliedFilters.created_from = createdRange.value?.[0]?.startOf("day").toISOString();
|
||||
appliedFilters.created_to = createdRange.value?.[1]?.endOf("day").toISOString();
|
||||
page.value = 1
|
||||
appliedFilters.prompt_rule_id = draftFilters.prompt_rule_id
|
||||
appliedFilters.status = draftFilters.status
|
||||
appliedFilters.keyword = draftFilters.keyword?.trim() || ''
|
||||
appliedFilters.created_from = createdRange.value?.[0]?.startOf('day').toISOString()
|
||||
appliedFilters.created_to = createdRange.value?.[1]?.endOf('day').toISOString()
|
||||
}
|
||||
|
||||
function resetFilters(): void {
|
||||
draftFilters.prompt_rule_id = undefined;
|
||||
draftFilters.status = undefined;
|
||||
draftFilters.keyword = "";
|
||||
createdRange.value = null;
|
||||
applyFilters();
|
||||
draftFilters.prompt_rule_id = undefined
|
||||
draftFilters.status = undefined
|
||||
draftFilters.keyword = ''
|
||||
createdRange.value = null
|
||||
applyFilters()
|
||||
}
|
||||
|
||||
function openModal(task?: ScheduleTask): void {
|
||||
editingTask.value = task ?? null;
|
||||
modalOpen.value = true;
|
||||
editingTask.value = task ?? null
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
page.value = nextPage;
|
||||
pageSize.value = nextPageSize;
|
||||
page.value = nextPage
|
||||
pageSize.value = nextPageSize
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -146,7 +171,7 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
<div class="task-tab">
|
||||
<div class="task-tab__filters">
|
||||
<div class="task-tab__filter">
|
||||
<label>{{ t("custom.filters.promptRule") }}:</label>
|
||||
<label>{{ t('custom.filters.promptRule') }}:</label>
|
||||
<a-select
|
||||
v-model:value="draftFilters.prompt_rule_id"
|
||||
allow-clear
|
||||
@@ -159,7 +184,7 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter">
|
||||
<label>{{ t("custom.filters.status") }}:</label>
|
||||
<label>{{ t('custom.filters.status') }}:</label>
|
||||
<a-select
|
||||
v-model:value="draftFilters.status"
|
||||
allow-clear
|
||||
@@ -171,7 +196,7 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--range">
|
||||
<label>{{ t("custom.filters.createdTime") }}:</label>
|
||||
<label>{{ t('custom.filters.createdTime') }}:</label>
|
||||
<a-range-picker
|
||||
v-model:value="createdRange"
|
||||
allow-clear
|
||||
@@ -182,7 +207,7 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--keyword">
|
||||
<label>{{ t("custom.filters.name") }}:</label>
|
||||
<label>{{ t('custom.filters.name') }}:</label>
|
||||
<a-input-search
|
||||
v-model:value="draftFilters.keyword"
|
||||
size="large"
|
||||
@@ -193,7 +218,7 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--action">
|
||||
<a-button size="large" @click="resetFilters">{{ t("common.reset") }}</a-button>
|
||||
<a-button size="large" @click="resetFilters">{{ t('common.reset') }}</a-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -213,11 +238,15 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'prompt_rule_name'">
|
||||
{{ record.prompt_rule_name || "--" }}
|
||||
{{ record.prompt_rule_name || '--' }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 'enabled' ? 'green' : 'default'">
|
||||
{{ record.status === "enabled" ? t("custom.schedule.enabled") : t("custom.schedule.disabled") }}
|
||||
{{
|
||||
record.status === 'enabled'
|
||||
? t('custom.schedule.enabled')
|
||||
: t('custom.schedule.disabled')
|
||||
}}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'cron_expr'">
|
||||
@@ -228,7 +257,7 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
{{
|
||||
record.auto_publish
|
||||
? formatPublishPlatformList(record.auto_publish_platforms)
|
||||
: t("custom.schedule.manualPublish")
|
||||
: t('custom.schedule.manualPublish')
|
||||
}}
|
||||
</a-tag>
|
||||
</template>
|
||||
@@ -252,7 +281,11 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip
|
||||
:title="record.status === 'enabled' ? t('custom.schedule.disabled') : t('custom.schedule.enabled')"
|
||||
:title="
|
||||
record.status === 'enabled'
|
||||
? t('custom.schedule.disabled')
|
||||
: t('custom.schedule.enabled')
|
||||
"
|
||||
>
|
||||
<a-button
|
||||
type="text"
|
||||
@@ -262,10 +295,12 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
'action-btn',
|
||||
record.status === 'enabled' ? 'action-disable' : 'action-enable',
|
||||
]"
|
||||
@click="toggleStatusMutation.mutate({
|
||||
id: record.id,
|
||||
status: record.status === 'enabled' ? 'disabled' : 'enabled',
|
||||
})"
|
||||
@click="
|
||||
toggleStatusMutation.mutate({
|
||||
id: record.id,
|
||||
status: record.status === 'enabled' ? 'disabled' : 'enabled',
|
||||
})
|
||||
"
|
||||
>
|
||||
<PauseCircleOutlined v-if="record.status === 'enabled'" />
|
||||
<PlayCircleOutlined v-else />
|
||||
@@ -297,7 +332,9 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
<style scoped>
|
||||
.task-tab__filters {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(180px, 240px) minmax(180px, 240px) minmax(240px, 320px) minmax(240px, 1fr) auto;
|
||||
grid-template-columns:
|
||||
minmax(180px, 240px) minmax(180px, 240px) minmax(240px, 320px) minmax(240px, 1fr)
|
||||
auto;
|
||||
gap: 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user