NewTeamView.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script setup lang="ts">
  2. // 新建工作组:标题、组长(可不要)、组员
  3. import { computed, onMounted, ref } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import type { BotCard } from '@agent-server/client'
  6. import BotCardItem from '../components/BotCardItem.vue'
  7. import TopBar from '../components/TopBar.vue'
  8. import { botClient, human } from '../lib/config'
  9. import { attempt } from '../lib/ui'
  10. const router = useRouter()
  11. const client = botClient.value!
  12. const cards = ref<BotCard[] | null>(null)
  13. const title = ref('')
  14. const lead = ref('')
  15. const workers = ref<string[]>([])
  16. const creating = ref(false)
  17. const leads = computed(() => cards.value?.filter(b => b.kind === 'lead') ?? [])
  18. const workerCards = computed(() => cards.value?.filter(b => b.kind === 'worker') ?? [])
  19. onMounted(async () => {
  20. cards.value = (await attempt(() => client.bots())) ?? []
  21. lead.value = leads.value[0]?.id ?? ''
  22. })
  23. async function create() {
  24. creating.value = true
  25. const t = await attempt(() => client.teams.create({
  26. title: title.value.trim() || undefined, human: human.value,
  27. leadBotId: lead.value || undefined, workerBotIds: workers.value,
  28. }))
  29. creating.value = false
  30. if (t) await router.replace(`/teams/${t.id}`)
  31. }
  32. </script>
  33. <template>
  34. <TopBar back title="新建工作组" />
  35. <div class="m-page flex-1 min-h-0 overflow-y-auto pb-[calc(24px+var(--safe-bottom))]">
  36. <div class="m-group-title">标题</div>
  37. <div class="m-group p-3"><input v-model="title" class="m-field" placeholder="可选,不填自动生成"></div>
  38. <div class="m-group-title">组长:理解需求、拆分任务、分派给组员并汇总</div>
  39. <div class="m-group m-list">
  40. <label class="m-row">
  41. <input v-model="lead" type="radio" value="" class="w-5 h-5 flex-none">
  42. <span class="flex-1">不要组长(直接 @ 组员)</span>
  43. </label>
  44. <label v-for="b in leads" :key="b.id" class="m-row">
  45. <input v-model="lead" type="radio" :value="b.id" class="w-5 h-5 flex-none">
  46. <BotCardItem :bot="b" />
  47. </label>
  48. </div>
  49. <div class="m-group-title">组员{{ lead ? '(可以不选,由组长按需申请加入)' : '' }}</div>
  50. <div class="m-group m-list">
  51. <div v-if="!cards" class="px-4 py-3 text-fg-muted">加载中…</div>
  52. <div v-else-if="!workerCards.length" class="px-4 py-3 text-fg-muted">这个 Bot Key 没有可用的组员</div>
  53. <label v-for="b in workerCards" :key="b.id" class="m-row">
  54. <input v-model="workers" type="checkbox" :value="b.id" class="w-5 h-5 flex-none">
  55. <BotCardItem :bot="b" />
  56. </label>
  57. </div>
  58. <div class="px-3 pt-5">
  59. <button type="button" class="m-btn-primary w-full" :disabled="creating || (!lead && !workers.length)" @click="create">{{ creating ? '创建中…' : '创建' }}</button>
  60. </div>
  61. </div>
  62. </template>