wangzhibo
2026-08-30 c8515170fd399b4d2dfaebb59128d4674e58915e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
<!-- 使用 type="home" 属性设置首页,其他页面不需要设置,默认为page -->
<route lang="jsonc" type="home">
{
  "layout": "tabbar",
  "style": {
    // 'custom' 表示开启自定义导航栏,默认 'default'
    "navigationStyle": "custom",
    "navigationBarTitleText": "首页"
  }
}
</route>
 
<script lang="ts" setup>
import type { Agent } from '@/api/agent/types'
import { computed, onMounted, ref } from 'vue'
// 在组件挂载后设置导航栏标题
import { useMessage } from 'wot-design-uni/components/wd-message-box'
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
import { createAgent, deleteAgent, getAgentList } from '@/api/agent/agent'
import { t } from '@/i18n'
import { toast } from '@/utils/toast'
 
defineOptions({
  name: 'Home',
})
 
// 获取屏幕边界到安全区域距离
let safeAreaInsets: any
let systemInfo: any
 
// #ifdef MP-WEIXIN
// 微信小程序使用新的API
systemInfo = uni.getWindowInfo()
safeAreaInsets = systemInfo.safeArea
  ? {
      top: systemInfo.safeArea.top,
      right: systemInfo.windowWidth - systemInfo.safeArea.right,
      bottom: systemInfo.windowHeight - systemInfo.safeArea.bottom,
      left: systemInfo.safeArea.left,
    }
  : null
// #endif
 
// #ifndef MP-WEIXIN
// 其他平台继续使用uni API
systemInfo = uni.getSystemInfoSync()
safeAreaInsets = systemInfo.safeAreaInsets
// #endif
 
// 智能体数据
const agentList = ref<Agent[]>([])
const pagingRef = ref()
useZPaging(pagingRef)
// 消息组件
const message = useMessage()
const deleteDialogVisible = ref(false)
const deleteTargetAgent = ref<Agent | null>(null)
const deleteConfirmText = ref('')
const deleteAgentLoading = ref(false)
 
const isDeleteAgentNameMatched = computed(() => {
  return !!deleteTargetAgent.value?.agentName && deleteConfirmText.value === deleteTargetAgent.value.agentName
})
 
// z-paging查询列表数据
async function queryList(pageNo: number, pageSize: number) {
  try {
    console.log('z-paging获取智能体列表')
 
    const response = await getAgentList()
 
    // 更新本地列表
    agentList.value = response
 
    // 直接返回全部数据,不需要分页处理
    pagingRef.value.complete(response)
  }
  catch (error) {
    console.error('获取智能体列表失败:', error)
    // 告知z-paging数据加载失败
    pagingRef.value.complete(false)
  }
}
 
// 创建智能体
async function handleCreateAgent(agentName: string) {
  try {
    await createAgent({ agentName: agentName.trim() })
    // 创建成功后刷新列表
    pagingRef.value.reload()
    toast.success(`${t('home.agentName')}"${agentName}"${t('message.saveSuccess')}`)
  }
  catch (error: any) {
    console.error('创建智能体失败:', error)
    const errorMessage = error?.message || t('message.saveFail')
    toast.error(errorMessage)
  }
}
 
function openDeleteAgentDialog(agent: Agent) {
  if (!agent.id || !agent.agentName) {
    toast.error(t('home.deleteAgentMissingInfo'))
    return
  }
 
  deleteTargetAgent.value = agent
  deleteConfirmText.value = ''
  deleteDialogVisible.value = true
}
 
function closeDeleteAgentDialog() {
  if (deleteAgentLoading.value)
    return
 
  deleteDialogVisible.value = false
  deleteTargetAgent.value = null
  deleteConfirmText.value = ''
}
 
function handleDeleteAgentPaste() {
  toast.warning(t('home.deleteAgentPasteForbidden'))
}
 
// 删除智能体
async function handleDeleteAgent() {
  if (!deleteTargetAgent.value || !isDeleteAgentNameMatched.value || deleteAgentLoading.value)
    return
 
  try {
    deleteAgentLoading.value = true
    await deleteAgent(deleteTargetAgent.value.id)
    // 删除成功后刷新列表
    pagingRef.value.reload()
    toast.success(t('home.deleteAgentSuccess'))
    deleteDialogVisible.value = false
    deleteTargetAgent.value = null
    deleteConfirmText.value = ''
  }
  catch (error: any) {
    console.error('删除智能体失败:', error)
    const errorMessage = error?.message || t('message.deleteFail')
    toast.error(errorMessage)
  }
  finally {
    deleteAgentLoading.value = false
  }
}
 
// 进入编辑页面
function goToEditAgent(agent: Agent) {
  // 传递智能体ID到编辑页面
  uni.navigateTo({
    url: `/pages/agent/index?agentId=${agent.id}`,
  })
}
 
// 点击卡片进入编辑
function handleCardClick(agent: Agent) {
  goToEditAgent(agent)
}
 
// 打开创建对话框
function openCreateDialog() {
  message
    .prompt({
      title: t('home.dialogTitle'),
      msg: '',
      inputPlaceholder: t('home.inputPlaceholder'),
      inputValue: '',
      inputPattern: /^.{1,64}$/,
      inputError: t('home.createError'),
      confirmButtonText: t('home.createNow'),
      cancelButtonText: t('common.cancel'),
    })
    .then(async (result: any) => {
      if (result.value && String(result.value).trim()) {
        await handleCreateAgent(String(result.value).trim())
      }
    })
    .catch(() => {
      // 用户取消操作
    })
}
 
// 格式化时间
function formatTime(timeStr: string) {
  const date = new Date(timeStr)
  const now = new Date()
  const diff = now.getTime() - date.getTime()
 
  if (diff < 60000)
    return t('home.justNow')
  if (diff < 3600000)
    return `${Math.floor(diff / 60000)}${t('home.minutesAgo')}`
  if (diff < 86400000)
    return `${Math.floor(diff / 3600000)}${t('home.hoursAgo')}`
  return `${Math.floor(diff / 86400000)}${t('home.daysAgo')}`
}
 
// 页面显示时刷新列表
onShow(() => {
  console.log('首页 onShow,刷新智能体列表')
  if (pagingRef.value) {
    pagingRef.value.refresh()
  }
})
 
onMounted(() => {
  uni.setNavigationBarTitle({
    title: t('home.pageTitle'),
  })
})
</script>
 
<template>
  <z-paging
    ref="pagingRef" v-model="agentList" :refresher-enabled="true" :auto-show-back-to-top="true"
    :loading-more-enabled="false" :show-loading-more="false" :hide-empty-view="false" :empty-view-text="t('home.emptyState')"
    empty-view-img="" :refresher-threshold="80" :back-to-top-style="{
      backgroundColor: '#fff',
      borderRadius: '50%',
      width: '56px',
      height: '56px',
    }" @query="queryList"
  >
    <!-- 固定在顶部的横幅区域 -->
    <template #top>
      <view class="banner-section" :style="{ paddingTop: `${safeAreaInsets?.top + 100}rpx` }">
        <view class="banner-content">
          <view class="welcome-info">
            <text class="greeting">
              {{ t('home.greeting') }}
            </text>
            <text class="subtitle">
              {{ t('home.subtitle') }} <text class="highlight">
                {{ t('home.wonderfulDay') }}
              </text>
            </text>
          </view>
          <view class="wave-decoration">
            <!-- 添加波浪装饰 -->
            <view class="wave" />
            <view class="wave wave-2" />
          </view>
        </view>
      </view>
 
      <!-- 内容区域开始标识 -->
      <view class="content-section-header" />
    </template>
 
    <!-- 智能体卡片列表 -->
    <view class="agent-list">
      <view v-for="agent in agentList" :key="agent.id" class="agent-item">
        <wd-swipe-action>
          <view class="simple-card" @click="handleCardClick(agent)">
            <view class="card-content">
              <view class="card-main">
                <view class="agent-title">
                  <text class="agent-name">
                    {{ agent.agentName }}
                  </text>
                </view>
 
                <view class="model-info">
                  <text class="model-text">
                    {{ t('home.languageModel') }}: {{ agent.llmModelName }}
                  </text>
                  <text class="model-text">
                    {{ t('home.voiceModel') }}: {{ agent.ttsModelName }} ({{ agent.ttsVoiceName }})
                  </text>
                </view>
 
                <view class="stats-row">
                  <view class="stat-chip">
                    <wd-icon name="phone" custom-class="chip-icon" />
                    <text class="chip-text">
                      {{ t('home.deviceManagement') }}({{ agent.deviceCount }})
                    </text>
                  </view>
                  <view v-if="agent.lastConnectedAt" class="stat-chip">
                    <wd-icon name="time" custom-class="chip-icon" />
                    <text class="chip-text">
                      {{ t('home.lastConversation') }}{{ formatTime(agent.lastConnectedAt) }}
                    </text>
                  </view>
                  <text v-if="agent.tags" class="flex-1 truncate text-right text-[22rpx] text-[#666]">
                    {{ agent.tags.map(tag => tag.tagName).join(',') }}
                  </text>
                </view>
              </view>
 
              <wd-icon name="arrow-right" custom-class="arrow-icon" />
            </view>
          </view>
 
          <template #right>
            <view class="swipe-actions">
              <view class="action-btn delete-btn" @click.stop="openDeleteAgentDialog(agent)">
                <wd-icon name="delete" />
                <text>{{ t('home.delete') }}</text>
              </view>
            </view>
          </template>
        </wd-swipe-action>
      </view>
    </view>
 
    <!-- 自定义空状态 -->
    <template #empty>
      <view class="empty-state">
        <wd-icon name="robot" custom-class="empty-icon" />
        <text class="empty-text">
          {{ t('home.emptyState') }}
        </text>
        <text class="empty-desc">
          {{ t('home.createFirstAgent') }}
        </text>
      </view>
    </template>
 
    <!-- FAB 新增按钮 -->
    <wd-fab type="primary" icon="add" :draggable="true" :expandable="false" @click="openCreateDialog" />
 
    <!-- MessageBox 组件 -->
    <wd-message-box />
  </z-paging>
 
  <wd-popup
    v-model="deleteDialogVisible"
    position="center"
    custom-style="width: 88%; max-width: 420px; border-radius: 16px;"
    :close-on-click-modal="!deleteAgentLoading"
    safe-area-inset-bottom
    @close="closeDeleteAgentDialog"
  >
    <view class="delete-agent-dialog">
      <view class="delete-agent-header">
        <text class="delete-agent-title">
          {{ t('home.deleteConfirmTitle') }}
        </text>
      </view>
 
      <view class="delete-agent-body">
        <view class="delete-agent-content">
          <wd-icon name="warning" custom-class="delete-agent-warning" />
          <view class="delete-agent-message">
            <text
              class="delete-agent-copy-guard delete-agent-tip"
              @copy.stop.prevent
              @cut.stop.prevent
              @contextmenu.stop.prevent
              @longpress.stop.prevent
            >
              {{ t('home.confirmDeleteAgent', { agentName: deleteTargetAgent?.agentName || '' }) }}
            </text>
            <view
              class="delete-agent-copy-guard delete-agent-target"
              @copy.stop.prevent
              @cut.stop.prevent
              @contextmenu.stop.prevent
              @longpress.stop.prevent
            >
              <text>{{ deleteTargetAgent?.agentName || '' }}</text>
            </view>
 
            <input
              v-model="deleteConfirmText"
              class="delete-agent-input"
              type="text"
              :maxlength="deleteTargetAgent?.agentName?.length || 64"
              :placeholder="t('home.deleteAgentNamePlaceholder')"
              :disabled="deleteAgentLoading"
              @paste.stop.prevent="handleDeleteAgentPaste"
              @drop.stop.prevent="handleDeleteAgentPaste"
              @contextmenu.stop.prevent
            >
            <text v-if="deleteConfirmText && !isDeleteAgentNameMatched" class="delete-agent-helper">
              {{ t('home.deleteAgentNameMismatch') }}
            </text>
          </view>
        </view>
      </view>
 
      <view class="delete-agent-footer">
        <wd-button type="info" custom-class="delete-agent-button" :disabled="deleteAgentLoading" @click="closeDeleteAgentDialog">
          {{ t('common.cancel') }}
        </wd-button>
        <wd-button
          type="primary"
          custom-class="delete-agent-button"
          :loading="deleteAgentLoading"
          :disabled="!isDeleteAgentNameMatched"
          @click="handleDeleteAgent"
        >
          {{ t('common.confirm') }}
        </wd-button>
      </view>
    </view>
  </wd-popup>
</template>
 
<style lang="scss" scoped>
.banner-section {
  background: linear-gradient(145deg, #9ebbfc, #6baaff, #9ebbfc, #f5f8fd);
  position: relative;
  padding: 40rpx 40rpx 80rpx 40rpx;
  overflow: hidden;
 
  .banner-content {
    position: relative;
    z-index: 2;
  }
 
  .header-actions {
    position: absolute;
    top: -50rpx;
    right: 0;
    display: flex;
    gap: 32rpx;
 
    .filter-icon,
    .setting-icon {
      color: white;
      cursor: pointer;
      transition: opacity 0.2s ease;
 
      &:active {
        opacity: 0.7;
      }
    }
  }
 
  .welcome-info {
    .greeting {
      display: block;
      font-size: 48rpx;
      font-weight: 700;
      color: #ffffff;
      margin-bottom: 16rpx;
      text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
    }
 
    .subtitle {
      display: block;
      font-size: 32rpx;
      color: rgba(255, 255, 255, 0.9);
      margin-bottom: 12rpx;
      font-weight: 500;
 
      .highlight {
        color: #ffd700;
        font-weight: 600;
      }
    }
 
    .english-subtitle {
      display: block;
      font-size: 24rpx;
      color: rgba(255, 255, 255, 0.7);
      font-style: italic;
    }
  }
 
  .wave-decoration {
    position: absolute;
    top: 0;
    right: -100rpx;
    width: 400rpx;
    height: 100%;
    opacity: 0.1;
    pointer-events: none;
 
    .wave {
      position: absolute;
      width: 200%;
      height: 200%;
      background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
      border-radius: 50%;
      animation: float 6s ease-in-out infinite;
 
      &.wave-2 {
        top: 20%;
        right: 20%;
        animation-delay: -3s;
        opacity: 0.5;
      }
    }
  }
}
 
@keyframes float {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
  }
 
  50% {
    transform: translateY(-30rpx) rotate(180deg);
  }
}
 
// 内容区域开始标识,创建白色背景过渡
.content-section-header {
  background: #ffffff;
  border-radius: 32rpx 32rpx 0 0;
  margin-top: -32rpx;
  height: 32rpx;
  position: relative;
  z-index: 1;
}
 
// z-paging内容区域样式
:deep(.z-paging-content) {
  background: #ffffff;
  padding: 0 0 40rpx 0;
}
 
.agent-list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
  padding: 0 20rpx;
}
 
.agent-item {
  :deep(.wd-swipe-action) {
    border-radius: 16rpx;
    overflow: hidden;
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
    border: 1rpx solid #f0f0f0;
  }
}
 
.simple-card {
  background: #ffffff;
  padding: 24rpx;
  cursor: pointer;
  transition: all 0.2s ease;
 
  &:active {
    background: #f8f9fa;
  }
 
  .card-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
 
  .card-main {
    flex: 1;
    width: 100%;
  }
 
  .agent-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12rpx;
 
    .agent-name {
      font-size: 32rpx;
      font-weight: 600;
      color: #1a1a1a;
    }
  }
 
  .model-info {
    margin-bottom: 16rpx;
 
    .model-text {
      display: block;
      font-size: 24rpx;
      color: #666666;
      line-height: 1.5;
      margin-bottom: 4rpx;
 
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
 
  .stats-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12rpx;
    flex-wrap: wrap;
 
    .stat-chip {
      display: flex;
      align-items: center;
      padding: 6rpx 12rpx;
      background: #f8f9fa;
      border-radius: 20rpx;
      border: 1rpx solid #eaeaea;
 
      :deep(.chip-icon) {
        font-size: 20rpx;
        color: #666666;
        margin-right: 6rpx;
      }
 
      .chip-text {
        font-size: 22rpx;
        color: #666666;
      }
    }
  }
 
  :deep(.arrow-icon) {
    font-size: 24rpx;
    color: #c7c7cc;
    margin-left: 16rpx;
  }
}
 
.swipe-actions {
  display: flex;
  height: 100%;
 
  .action-btn {
    width: 120rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8rpx;
    color: #ffffff;
    font-size: 24rpx;
    font-weight: 500;
    transition: all 0.3s ease;
 
    &.edit-btn {
      background: #1890ff;
 
      &:active {
        background: #096dd9;
      }
    }
 
    &.delete-btn {
      background: #ff4d4f;
 
      &:active {
        background: #d9363e;
      }
    }
 
    :deep(.wd-icon) {
      font-size: 32rpx;
    }
  }
}
 
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 40rpx;
  text-align: center;
 
  :deep(.empty-icon) {
    font-size: 120rpx;
    color: #d9d9d9;
    margin-bottom: 32rpx;
  }
 
  .empty-text {
    font-size: 32rpx;
    color: #666666;
    margin-bottom: 16rpx;
    font-weight: 500;
  }
 
  .empty-desc {
    font-size: 26rpx;
    color: #999999;
    line-height: 1.5;
  }
}
 
@keyframes pulse {
  0% {
    opacity: 1;
  }
 
  50% {
    opacity: 0.5;
  }
 
  100% {
    opacity: 1;
  }
}
 
.filter-actions {
  padding: 32rpx;
  text-align: center;
  border-top: 1rpx solid #eeeeee;
}
 
.delete-agent-dialog {
  overflow: hidden;
  background: #ffffff;
}
 
.delete-agent-header {
  padding: 32rpx 32rpx 20rpx;
  border-bottom: 1rpx solid #f0f0f0;
  text-align: center;
}
 
.delete-agent-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #232338;
}
 
.delete-agent-body {
  padding: 32rpx;
}
 
.delete-agent-content {
  display: flex;
  align-items: flex-start;
  gap: 16rpx;
}
 
:deep(.delete-agent-warning) {
  margin-top: 4rpx;
  color: #e6a23c;
  font-size: 40rpx;
}
 
.delete-agent-message {
  flex: 1;
  min-width: 0;
}
 
.delete-agent-tip {
  display: block;
  color: #606266;
  font-size: 28rpx;
  line-height: 1.6;
}
 
.delete-agent-target {
  box-sizing: border-box;
  width: 100%;
  margin-top: 20rpx;
  padding: 18rpx 20rpx;
  border: 1rpx solid #ebeef5;
  border-radius: 12rpx;
  background: #f5f7fa;
  color: #303133;
  font-size: 30rpx;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-all;
}
 
.delete-agent-copy-guard {
  user-select: none;
  -webkit-user-select: none;
}
 
.delete-agent-input {
  box-sizing: border-box;
  width: 100%;
  height: 80rpx;
  margin-top: 28rpx;
  padding: 0 20rpx;
  border: 1rpx solid #eeeeee;
  border-radius: 12rpx;
  background: #f5f7fb;
  color: #232338;
  font-size: 28rpx;
  outline: none;
}
 
.delete-agent-helper {
  display: block;
  min-height: 32rpx;
  margin-top: 10rpx;
  color: #f56c6c;
  font-size: 24rpx;
  line-height: 1.4;
}
 
.delete-agent-footer {
  display: flex;
  gap: 16rpx;
  padding: 24rpx 32rpx 32rpx;
  border-top: 1rpx solid #eeeeee;
}
 
:deep(.delete-agent-button) {
  flex: 1;
}
</style>