feat(env): add tag support for environment variables and task injection
- Add generic DataRelation and DataStorage models for tags - Update EnvService and EnvController to support tag assignment, querying, and filtering - Integrate EnvTagsConfig in Env settings for managing environment tags - Enhance TaskDialog environment selection to support searching and displaying env tags - Fix missing TaskLangConfig import in RepoDialog
This commit is contained in:
@@ -96,14 +96,16 @@ export const api = {
|
||||
delete: (id: string) => request(`/scripts/${id}`, { method: 'DELETE' })
|
||||
},
|
||||
env: {
|
||||
list: (params?: { page?: number; page_size?: number; name?: string; type?: string }) => {
|
||||
list: (params?: { page?: number; page_size?: number; name?: string; type?: string; tags?: string }) => {
|
||||
const query = new URLSearchParams()
|
||||
if (params?.page) query.set('page', String(params.page))
|
||||
if (params?.page_size) query.set('page_size', String(params.page_size))
|
||||
if (params?.name) query.set('name', params.name)
|
||||
if (params?.type && params.type !== 'all') query.set('type', params.type)
|
||||
if (params?.tags) query.set('tags', params.tags)
|
||||
return request<EnvListResponse>(`/env?${query}`)
|
||||
},
|
||||
tags: () => request<string[]>('/env/tags'),
|
||||
secretStatus: () => request<boolean>('/env/secret-status'),
|
||||
all: () => request<EnvVar[]>('/env/all'),
|
||||
tasks: (id: string) => request<Task[]>(`/env/${id}/tasks`),
|
||||
@@ -462,6 +464,7 @@ export interface EnvVar {
|
||||
type: string
|
||||
hidden: boolean
|
||||
enabled: boolean
|
||||
tags: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@ const props = withDefaults(defineProps<{
|
||||
icon?: any
|
||||
multiple?: boolean
|
||||
clearOnSelect?: boolean
|
||||
fetchTags?: () => Promise<string[]>
|
||||
}>(), {
|
||||
multiple: false,
|
||||
clearOnSelect: false
|
||||
clearOnSelect: false,
|
||||
fetchTags: () => api.tasks.tags()
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'enter'])
|
||||
@@ -27,10 +29,10 @@ watch(() => props.modelValue, (newVal) => {
|
||||
inputValue.value = newVal
|
||||
})
|
||||
|
||||
async function fetchTags() {
|
||||
async function fetchTagsData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await api.tasks.tags()
|
||||
const res = await props.fetchTags()
|
||||
allTags.value = res || []
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch tags', e)
|
||||
@@ -101,7 +103,7 @@ function handleClickOutside(e: MouseEvent) {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchTags()
|
||||
fetchTagsData()
|
||||
window.addEventListener('mousedown', handleClickOutside)
|
||||
})
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import { ref, watch, onMounted } from 'vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import Pagination from '@/components/Pagination.vue'
|
||||
import { Plus, Pencil, Trash2, Eye, EyeOff, Search, AlertTriangle, Terminal, Zap, ZapOff, Shield } from 'lucide-vue-next'
|
||||
import { Plus, Pencil, Trash2, Eye, EyeOff, Search, AlertTriangle, Terminal, Zap, ZapOff, Shield, Tag } from 'lucide-vue-next'
|
||||
import TextOverflow from '@/components/TextOverflow.vue'
|
||||
import TagInput from '@/components/TagInput.vue'
|
||||
import { api, type EnvVar } from '@/api'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { useSiteSettings } from '@/composables/useSiteSettings'
|
||||
@@ -31,6 +32,7 @@ const envVars = ref<EnvVar[]>([])
|
||||
const showValues = ref<Record<string, boolean>>({})
|
||||
|
||||
const filterName = ref('')
|
||||
const filterTags = ref('')
|
||||
const currentPage = ref(1)
|
||||
const total = ref(0)
|
||||
const activeTab = ref<string>(ENV_TYPE.NORMAL)
|
||||
@@ -53,7 +55,13 @@ async function checkSecretStatus() {
|
||||
|
||||
async function loadEnvVars() {
|
||||
try {
|
||||
const res = await api.env.list({ page: currentPage.value, page_size: pageSize.value, name: filterName.value || undefined, type: activeTab.value })
|
||||
const res = await api.env.list({
|
||||
page: currentPage.value,
|
||||
page_size: pageSize.value,
|
||||
name: filterName.value || undefined,
|
||||
type: activeTab.value,
|
||||
tags: filterTags.value || undefined
|
||||
})
|
||||
envVars.value = res.data
|
||||
total.value = res.total
|
||||
// 初始化显示状态,根据数据库的 hidden 状态同步显示
|
||||
@@ -140,10 +148,13 @@ onMounted(() => {
|
||||
<div class="flex flex-row items-center flex-wrap gap-2 w-full md:w-auto md:ml-auto md:justify-end">
|
||||
<!-- 搜索与操作 -->
|
||||
<div class="flex flex-row items-center gap-2 w-full sm:flex-1 md:flex-none md:w-auto text-sm">
|
||||
<div class="relative flex-1 md:flex-none md:w-[200px] group">
|
||||
<div class="relative flex-1 md:flex-none md:w-[150px] lg:w-[200px] group">
|
||||
<Search class="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground group-focus-within:text-primary transition-colors" />
|
||||
<Input v-model="filterName" placeholder="搜索名称..." class="h-9 pl-9 w-full bg-muted/20 border-muted-foreground/10 focus:bg-background text-sm" @input="handleSearch" />
|
||||
</div>
|
||||
<div class="w-[120px] lg:w-[150px] shrink-0">
|
||||
<TagInput v-model="filterTags" placeholder="标签过滤..." :icon="Tag" multiple :fetchTags="api.env.tags" class="h-9 bg-muted/20 border-muted-foreground/10 focus:bg-background text-sm" @enter="handleSearch" @update:modelValue="handleSearch" />
|
||||
</div>
|
||||
|
||||
<Button variant="outline" class="h-9 px-3 shrink-0 shadow-sm" @click="openCreate" :disabled="activeTab === ENV_TYPE.SECRET && !isSecretSet">
|
||||
<Plus class="h-4 w-4 md:mr-2" /> <span class="hidden md:inline">新建{{ activeTab === ENV_TYPE.SECRET ? '机密' : '变量' }}</span>
|
||||
@@ -195,9 +206,14 @@ onMounted(() => {
|
||||
class="flex items-center gap-4 px-4 py-1.5 hover:bg-muted/30 transition-colors">
|
||||
<div class="w-12 shrink-0 pl-1 text-muted-foreground tabular-nums">#{{ total - (currentPage - 1) * pageSize - index }}</div>
|
||||
|
||||
<div class="w-48 shrink-0 flex items-center gap-1.5 overflow-hidden">
|
||||
<code class="font-bold truncate text-[11px] bg-muted/60 px-2 py-0.5 rounded text-zinc-700 dark:text-zinc-200">{{ env.name }}</code>
|
||||
<Badge v-if="isNotifyEnv(env.name)" variant="secondary" class="text-[9px] h-3.5 px-1 rounded-sm uppercase font-bold tracking-tighter shrink-0 leading-none">内置</Badge>
|
||||
<div class="w-48 shrink-0 flex flex-col gap-1 justify-center overflow-hidden">
|
||||
<div class="flex items-center gap-1.5 overflow-hidden">
|
||||
<code class="font-bold truncate text-[11px] bg-muted/60 px-2 py-0.5 rounded text-zinc-700 dark:text-zinc-200">{{ env.name }}</code>
|
||||
<Badge v-if="isNotifyEnv(env.name)" variant="secondary" class="text-[9px] h-3.5 px-1 rounded-sm uppercase font-bold tracking-tighter shrink-0 leading-none">内置</Badge>
|
||||
</div>
|
||||
<div v-if="env.tags" class="flex items-center gap-1 overflow-hidden">
|
||||
<span v-for="tag in env.tags.split(',').filter(Boolean).slice(0, 3)" :key="tag" class="truncate text-[9px] leading-none px-1 py-0.5 bg-secondary text-secondary-foreground rounded border">{{ tag }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 min-w-0 text-muted-foreground truncate text-xs px-1">
|
||||
@@ -255,9 +271,14 @@ onMounted(() => {
|
||||
class="flex items-center gap-4 px-4 py-2 hover:bg-muted/30 transition-colors">
|
||||
<div class="w-12 shrink-0 pl-1 text-muted-foreground tabular-nums text-xs">#{{ total - (currentPage - 1) * pageSize - index }}</div>
|
||||
|
||||
<div class="w-48 shrink-0 flex items-center gap-1.5 overflow-hidden">
|
||||
<code class="font-bold truncate text-[11px] bg-muted/60 px-2 py-0.5 rounded text-zinc-700 dark:text-zinc-200">{{ env.name }}</code>
|
||||
<Badge v-if="isNotifyEnv(env.name)" variant="secondary" class="text-[9px] h-3.5 px-1 rounded-sm uppercase font-bold tracking-tighter shrink-0 leading-none">内置</Badge>
|
||||
<div class="w-48 shrink-0 flex flex-col gap-1 justify-center overflow-hidden">
|
||||
<div class="flex items-center gap-1.5 overflow-hidden">
|
||||
<code class="font-bold truncate text-[11px] bg-muted/60 px-2 py-0.5 rounded text-zinc-700 dark:text-zinc-200">{{ env.name }}</code>
|
||||
<Badge v-if="isNotifyEnv(env.name)" variant="secondary" class="text-[9px] h-3.5 px-1 rounded-sm uppercase font-bold tracking-tighter shrink-0 leading-none">内置</Badge>
|
||||
</div>
|
||||
<div v-if="env.tags" class="flex items-center gap-1 overflow-hidden">
|
||||
<span v-for="tag in env.tags.split(',').filter(Boolean).slice(0, 3)" :key="tag" class="truncate text-[9px] leading-none px-1 py-0.5 bg-secondary text-secondary-foreground rounded border">{{ tag }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 min-w-0 text-muted-foreground truncate text-xs">
|
||||
@@ -298,10 +319,15 @@ onMounted(() => {
|
||||
</div>
|
||||
<div v-for="(env, index) in envVars" :key="`small-${env.id}`" class="p-3 hover:bg-muted/50 transition-colors">
|
||||
<div class="flex items-start justify-between mb-3 border-b border-border/40 pb-2">
|
||||
<div class="flex items-center gap-2 flex-1 min-w-0 pr-2">
|
||||
<span class="text-xs text-muted-foreground tabular-nums flex-shrink-0">#{{ total - (currentPage - 1) * pageSize - index }}</span>
|
||||
<code class="font-bold text-xs bg-muted/60 px-2 py-0.5 rounded truncate text-zinc-700 dark:text-zinc-200">{{ env.name }}</code>
|
||||
<Badge v-if="isNotifyEnv(env.name)" variant="secondary" class="text-[8px] h-3.5 px-1 rounded-sm uppercase font-bold tracking-tighter leading-none shrink-0">内置</Badge>
|
||||
<div class="flex flex-col gap-1 flex-1 min-w-0 pr-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs text-muted-foreground tabular-nums flex-shrink-0">#{{ total - (currentPage - 1) * pageSize - index }}</span>
|
||||
<code class="font-bold text-xs bg-muted/60 px-2 py-0.5 rounded truncate text-zinc-700 dark:text-zinc-200">{{ env.name }}</code>
|
||||
<Badge v-if="isNotifyEnv(env.name)" variant="secondary" class="text-[8px] h-3.5 px-1 rounded-sm uppercase font-bold tracking-tighter leading-none shrink-0">内置</Badge>
|
||||
</div>
|
||||
<div v-if="env.tags" class="flex items-center gap-1 pl-6 overflow-hidden">
|
||||
<span v-for="tag in env.tags.split(',').filter(Boolean).slice(0, 3)" :key="tag" class="truncate text-[9px] leading-none px-1 py-0.5 bg-secondary text-secondary-foreground rounded border">{{ tag }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span @click="toggleEnabled(env)" class="cursor-pointer">
|
||||
<div v-if="env.enabled" class="h-6 w-6 rounded-md bg-green-500/10 flex items-center justify-center">
|
||||
|
||||
@@ -11,6 +11,7 @@ import { api, type EnvVar } from '@/api'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { ENV_TYPE } from '@/constants'
|
||||
import LineNumberTextarea from '@/components/LineNumberTextarea.vue'
|
||||
import EnvTagsConfig from './EnvTagsConfig.vue'
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'saved'): void
|
||||
@@ -23,7 +24,7 @@ const editingEnv = ref<Partial<EnvVar>>({})
|
||||
const textareaRef = ref<InstanceType<typeof LineNumberTextarea> | null>(null)
|
||||
|
||||
function openCreate(type: string) {
|
||||
editingEnv.value = { name: '', value: '', remark: '', type, hidden: true, enabled: true }
|
||||
editingEnv.value = { name: '', value: '', remark: '', type, hidden: true, enabled: true, tags: '' }
|
||||
isEdit.value = false
|
||||
isOpen.value = true
|
||||
}
|
||||
@@ -95,6 +96,7 @@ defineExpose({
|
||||
/>
|
||||
|
||||
</div>
|
||||
<EnvTagsConfig v-model="editingEnv.tags" />
|
||||
<div class="space-y-2 min-w-0">
|
||||
<Label>备注</Label>
|
||||
<Textarea v-model="editingEnv.remark" class="w-full min-w-0 resize-none break-all text-sm" rows="3" :placeholder="editingEnv.type === ENV_TYPE.SECRET ? '机密用途说明...' : '变量用途说明...'" />
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import TagInput from '@/components/TagInput.vue'
|
||||
import { X } from 'lucide-vue-next'
|
||||
import { api } from '@/api'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: string]
|
||||
}>()
|
||||
|
||||
const tagInput = ref('')
|
||||
|
||||
const tagsList = computed(() => {
|
||||
return props.modelValue ? props.modelValue.split(',').filter(Boolean) : []
|
||||
})
|
||||
|
||||
function addTag(passedTag?: string) {
|
||||
const val = (passedTag || tagInput.value).trim()
|
||||
if (!val) return
|
||||
const currentTags = [...tagsList.value]
|
||||
if (!currentTags.includes(val)) {
|
||||
currentTags.push(val)
|
||||
emit('update:modelValue', currentTags.join(','))
|
||||
}
|
||||
tagInput.value = ''
|
||||
}
|
||||
|
||||
function removeTag(tagToRemove: string) {
|
||||
const currentTags = tagsList.value.filter(t => t !== tagToRemove)
|
||||
emit('update:modelValue', currentTags.join(','))
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-2 min-w-0">
|
||||
<Label class="text-sm">变量标签</Label>
|
||||
<div class="flex flex-wrap gap-1.5 p-2 min-h-[42px] bg-muted/20 border border-muted-foreground/15 rounded-md focus-within:border-primary/30 transition-colors">
|
||||
<span v-for="tag in tagsList" :key="tag"
|
||||
class="flex items-center gap-1.5 bg-primary/5 text-primary px-2.5 py-1 rounded-full text-[11px] font-medium border border-primary/10 group transition-all hover:bg-primary/10">
|
||||
{{ tag }}
|
||||
<button type="button" class="text-primary/40 hover:text-destructive transition-colors shrink-0" @click.prevent="removeTag(tag)"><X class="h-3 w-3" /></button>
|
||||
</span>
|
||||
<div class="flex-1 min-w-[100px]">
|
||||
<TagInput v-model="tagInput" placeholder="输入并回车添加标签..."
|
||||
clearOnSelect
|
||||
:fetchTags="api.env.tags"
|
||||
class="h-6 border-none bg-transparent shadow-none focus-visible:ring-0 px-0 text-xs"
|
||||
@enter="addTag" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -9,6 +9,7 @@ import { Switch } from '@/components/ui/switch'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import DirTreeSelect from '@/components/DirTreeSelect.vue'
|
||||
import TaskLangConfig from './components/TaskLangConfig.vue'
|
||||
import { Globe, GitBranch, Shield, Zap, Download, AlertCircle, Terminal } from 'lucide-vue-next'
|
||||
import { api, type Task, type RepoConfig, type Agent } from '@/api'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
@@ -71,7 +71,8 @@ const filteredEnvVars = computed(() => {
|
||||
const q = envSearchQuery.value.toLowerCase()
|
||||
const matchSearch = !q ||
|
||||
env.name.toLowerCase().includes(q) ||
|
||||
(env.remark && env.remark.toLowerCase().includes(q))
|
||||
(env.remark && env.remark.toLowerCase().includes(q)) ||
|
||||
(env.tags && env.tags.toLowerCase().includes(q))
|
||||
const notSelected = !selectedEnvIds.value.includes(env.id)
|
||||
return matchSearch && notSelected
|
||||
})
|
||||
@@ -400,7 +401,7 @@ async function save() {
|
||||
<div class="px-4 py-3.5 border-b bg-muted/20 backdrop-blur-md sticky top-0 z-10">
|
||||
<div class="relative group">
|
||||
<Search class="absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground group-focus-within:text-primary transition-colors duration-300" />
|
||||
<Input v-model="envSearchQuery" placeholder="输入关键字搜索变量名或备注..."
|
||||
<Input v-model="envSearchQuery" placeholder="输入关键字搜索变量名、备注或标签..."
|
||||
class="pl-9 h-9 bg-background/50 border-primary/10 focus:border-primary/30 transition-all rounded-lg text-[13px]" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -423,6 +424,9 @@ async function save() {
|
||||
<Badge v-if="env.type === 'secret'" variant="outline" class="h-4 px-1.5 text-[9px] border-amber-500/20 bg-amber-500/5 text-amber-600 font-bold uppercase tracking-tight scale-90">
|
||||
机密
|
||||
</Badge>
|
||||
<div v-if="env.tags" class="flex items-center gap-1 overflow-hidden ml-1">
|
||||
<span v-for="tag in env.tags.split(',').filter(Boolean).slice(0, 3)" :key="tag" class="truncate text-[9px] leading-none px-1 py-0.5 bg-secondary text-secondary-foreground rounded border">{{ tag }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 scale-75 opacity-0 group-hover:opacity-100 group-hover:translate-x-0 translate-x-2 transition-all duration-300 shrink-0">
|
||||
<Plus class="h-4 w-4 text-primary" />
|
||||
|
||||
Reference in New Issue
Block a user