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:
@@ -1,63 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
import { message } from "ant-design-vue";
|
||||
import { LeftOutlined } from "@ant-design/icons-vue";
|
||||
import { kolGenerateApi } from "@/lib/api";
|
||||
import KolDynamicForm from "@/components/kol/KolDynamicForm.vue";
|
||||
import KnowledgeGroupSelect from "@/components/KnowledgeGroupSelect.vue";
|
||||
import { parseKolCardConfig } from "@/lib/kol-card-config";
|
||||
import KnowledgeGroupSelect from '@/components/KnowledgeGroupSelect.vue'
|
||||
import KolDynamicForm from '@/components/kol/KolDynamicForm.vue'
|
||||
import { kolGenerateApi } from '@/lib/api'
|
||||
import { formatError } from '@/lib/errors'
|
||||
import { parseKolCardConfig } from '@/lib/kol-card-config'
|
||||
import {
|
||||
getKolVariableInitialValue,
|
||||
isKolVariableValueEmpty,
|
||||
normalizeKolVariableDefinition,
|
||||
} from "@/lib/kol-placeholders";
|
||||
import { formatError } from "@/lib/errors";
|
||||
} from '@/lib/kol-placeholders'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useI18n();
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useI18n()
|
||||
|
||||
const subscriptionPromptId = computed(() => String(route.params.subscriptionPromptId));
|
||||
const sourcePage = computed<"workspace" | "templates" | null>(() => {
|
||||
if (route.query.source === "workspace") {
|
||||
return "workspace";
|
||||
const subscriptionPromptId = computed(() => String(route.params.subscriptionPromptId))
|
||||
const sourcePage = computed<'workspace' | 'templates' | null>(() => {
|
||||
if (route.query.source === 'workspace') {
|
||||
return 'workspace'
|
||||
}
|
||||
if (route.query.source === "templates") {
|
||||
return "templates";
|
||||
if (route.query.source === 'templates') {
|
||||
return 'templates'
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return null
|
||||
})
|
||||
|
||||
function resolveReturnRoute():
|
||||
| { name: "workspace" }
|
||||
| { name: "articles-templates" } {
|
||||
if (sourcePage.value === "workspace") {
|
||||
return { name: "workspace" };
|
||||
function resolveReturnRoute(): { name: 'workspace' } | { name: 'articles-templates' } {
|
||||
if (sourcePage.value === 'workspace') {
|
||||
return { name: 'workspace' }
|
||||
}
|
||||
return { name: "articles-templates" };
|
||||
return { name: 'articles-templates' }
|
||||
}
|
||||
|
||||
const schemaQuery = useQuery({
|
||||
queryKey: ["kol", "subscription-prompt", "schema", subscriptionPromptId],
|
||||
queryKey: ['kol', 'subscription-prompt', 'schema', subscriptionPromptId],
|
||||
queryFn: () => kolGenerateApi.schema(subscriptionPromptId.value),
|
||||
enabled: computed(() => !!subscriptionPromptId.value),
|
||||
});
|
||||
})
|
||||
|
||||
const values = ref<Record<string, any>>({});
|
||||
const enableWebSearch = ref(false);
|
||||
const selectedKnowledgeGroupIds = ref<number[]>([]);
|
||||
const values = ref<Record<string, any>>({})
|
||||
const enableWebSearch = ref(false)
|
||||
const selectedKnowledgeGroupIds = ref<number[]>([])
|
||||
|
||||
const schema = computed(() => schemaQuery.data.value);
|
||||
const cardConfig = computed(() => parseKolCardConfig(schema.value?.card_config_json));
|
||||
const allowWebSearch = computed(() => cardConfig.value.allow_web_search);
|
||||
const allowUserKnowledge = computed(() => cardConfig.value.allow_user_knowledge);
|
||||
const schema = computed(() => schemaQuery.data.value)
|
||||
const cardConfig = computed(() => parseKolCardConfig(schema.value?.card_config_json))
|
||||
const allowWebSearch = computed(() => cardConfig.value.allow_web_search)
|
||||
const allowUserKnowledge = computed(() => cardConfig.value.allow_user_knowledge)
|
||||
|
||||
function fieldKey(key?: string | null, id?: string): string {
|
||||
return key?.trim() || id || "";
|
||||
return key?.trim() || id || ''
|
||||
}
|
||||
|
||||
// Initialize values from schema
|
||||
@@ -65,17 +63,19 @@ watch(
|
||||
() => schemaQuery.data.value,
|
||||
(schema) => {
|
||||
if (schema?.schema_json?.variables) {
|
||||
const newValues: Record<string, any> = {};
|
||||
const newValues: Record<string, any> = {}
|
||||
schema.schema_json.variables.forEach((v) => {
|
||||
newValues[fieldKey(v.key, v.id)] = getKolVariableInitialValue(normalizeKolVariableDefinition(v));
|
||||
});
|
||||
values.value = newValues;
|
||||
enableWebSearch.value = false;
|
||||
selectedKnowledgeGroupIds.value = [];
|
||||
newValues[fieldKey(v.key, v.id)] = getKolVariableInitialValue(
|
||||
normalizeKolVariableDefinition(v),
|
||||
)
|
||||
})
|
||||
values.value = newValues
|
||||
enableWebSearch.value = false
|
||||
selectedKnowledgeGroupIds.value = []
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
const generateMutation = useMutation({
|
||||
mutationFn: (variables: Record<string, any>) =>
|
||||
@@ -86,41 +86,44 @@ const generateMutation = useMutation({
|
||||
}),
|
||||
onSuccess: async () => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ["articles"] }),
|
||||
queryClient.invalidateQueries({ queryKey: ["workspace"] }),
|
||||
]);
|
||||
queryClient.invalidateQueries({ queryKey: ['articles'] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace'] }),
|
||||
])
|
||||
|
||||
message.info(t("templates.wizard.messages.queued"));
|
||||
message.info(t('templates.wizard.messages.queued'))
|
||||
|
||||
await router.replace(resolveReturnRoute());
|
||||
await router.replace(resolveReturnRoute())
|
||||
},
|
||||
onError: (error: any) => {
|
||||
message.error(formatError(error) || t("common.noData"));
|
||||
message.error(formatError(error) || t('common.noData'))
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
function handleBack() {
|
||||
void router.push(resolveReturnRoute());
|
||||
void router.push(resolveReturnRoute())
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
const schemaValue = schemaQuery.data.value;
|
||||
if (!schemaValue?.schema_json?.variables) return;
|
||||
const schemaValue = schemaQuery.data.value
|
||||
if (!schemaValue?.schema_json?.variables) return
|
||||
|
||||
const missingLabels: string[] = [];
|
||||
const missingLabels: string[] = []
|
||||
schemaValue.schema_json.variables.forEach((v) => {
|
||||
const normalizedVariable = normalizeKolVariableDefinition(v);
|
||||
if (normalizedVariable.required && isKolVariableValueEmpty(normalizedVariable, values.value[fieldKey(v.key, v.id)])) {
|
||||
missingLabels.push(v.label);
|
||||
const normalizedVariable = normalizeKolVariableDefinition(v)
|
||||
if (
|
||||
normalizedVariable.required &&
|
||||
isKolVariableValueEmpty(normalizedVariable, values.value[fieldKey(v.key, v.id)])
|
||||
) {
|
||||
missingLabels.push(v.label)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
if (missingLabels.length > 0) {
|
||||
message.warning(`${t("kol.generate.fillVariables")}: ${missingLabels.join(", ")}`);
|
||||
return;
|
||||
message.warning(`${t('kol.generate.fillVariables')}: ${missingLabels.join(', ')}`)
|
||||
return
|
||||
}
|
||||
|
||||
generateMutation.mutate(values.value);
|
||||
generateMutation.mutate(values.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -145,7 +148,7 @@ function handleSubmit() {
|
||||
{{ schema.platform_hint }}
|
||||
</a-tag>
|
||||
</h2>
|
||||
<p class="header-eyebrow">{{ t("kol.generate.fillVariables") }}</p>
|
||||
<p class="header-eyebrow">{{ t('kol.generate.fillVariables') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
@@ -153,9 +156,9 @@ function handleSubmit() {
|
||||
<main class="wizard-page__main">
|
||||
<section class="wizard-section">
|
||||
<div class="wizard-card">
|
||||
<div class="wizard-card__header" style="margin-bottom: 24px;">
|
||||
<div class="wizard-card__header" style="margin-bottom: 24px">
|
||||
<div>
|
||||
<h3>{{ t("kol.generate.fillVariables") }}</h3>
|
||||
<h3>{{ t('kol.generate.fillVariables') }}</h3>
|
||||
<p>根据设定提供相关信息</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -199,7 +202,7 @@ function handleSubmit() {
|
||||
:loading="generateMutation.isPending.value"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
{{ t("kol.generate.submit") }}
|
||||
{{ t('kol.generate.submit') }}
|
||||
</a-button>
|
||||
</div>
|
||||
</footer>
|
||||
@@ -303,7 +306,7 @@ function handleSubmit() {
|
||||
}
|
||||
|
||||
.wizard-card__header h3::before {
|
||||
content: "";
|
||||
content: '';
|
||||
display: inline-block;
|
||||
width: 4px;
|
||||
height: 16px;
|
||||
@@ -379,17 +382,17 @@ function handleSubmit() {
|
||||
.wizard-page__main {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
|
||||
.wizard-card {
|
||||
padding: 18px 0;
|
||||
}
|
||||
|
||||
|
||||
.wizard-page__footer {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
|
||||
.footer-actions {
|
||||
width: 100%;
|
||||
justify-content: flex-end;
|
||||
|
||||
Reference in New Issue
Block a user