gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
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
<script lang="ts" setup>
import { ref } from 'vue'
 
import { Button, message, Modal } from 'ant-design-vue'
 
import { muteMember } from '#/api/im/group'
 
defineOptions({ name: 'ImGroupMuteMemberDialog' })
 
const emit = defineEmits<{
  success: []
}>()
 
const visible = ref(false)
const loading = ref(false)
const groupId = ref(0)
const userId = ref(0)
const memberName = ref('')
const selected = ref(600) // 默认 10 分钟
 
const presets = [
  { label: '10 分钟', value: 600 },
  { label: '1 小时', value: 3600 },
  { label: '12 小时', value: 43_200 },
  { label: '1 天', value: 86_400 },
  { label: '7 天', value: 604_800 },
  { label: '30 天', value: 2_592_000 },
  { label: '永久', value: 0 }
]
 
/** 打开弹窗 */
function open(gid: number, uid: number, name: string) {
  groupId.value = gid
  userId.value = uid
  memberName.value = name
  selected.value = 600
  visible.value = true
}
 
/** 确认禁言 */
async function handleConfirm() {
  loading.value = true
  try {
    await muteMember({
      id: groupId.value,
      userId: userId.value,
      mutedSeconds: selected.value
    })
    message.success('禁言成功')
    visible.value = false
    emit('success')
  } finally {
    loading.value = false
  }
}
 
defineExpose({ open })
</script>
 
<template>
  <!-- 禁言时长选择弹窗 -->
  <Modal v-model:open="visible" title="设置禁言" width="560px" :mask-closable="false">
    <div class="flex flex-col gap-4">
      <!-- 成员信息卡:和 FriendAddDialog 的 user 卡保持一致的浅色背景 -->
      <div
        class="flex items-center gap-2 px-3 py-2.5 rounded-md bg-[var(--ant-color-fill-secondary)]"
      >
        <span class="text-13px text-[var(--ant-color-text-secondary)]">禁言成员</span>
        <span
          class="text-sm font-medium text-[var(--ant-color-text)] truncate"
        >
          {{ memberName }}
        </span>
      </div>
 
      <!-- 禁言时长选项:用 el-button 平铺,选中走 primary,靠 gap-2 留间距 -->
      <div>
        <div class="mb-2 text-13px text-[var(--ant-color-text-secondary)]">禁言时长</div>
        <div class="grid grid-cols-3 gap-2">
          <Button
            v-for="opt in presets"
            :key="opt.value"
            :type="selected === opt.value ? 'primary' : undefined"
            class="!ml-0 w-full"
            @click="selected = opt.value"
          >
            {{ opt.label }}
          </Button>
        </div>
      </div>
    </div>
    <template #footer>
      <Button @click="visible = false">取消</Button>
      <Button type="primary" :loading="loading" @click="handleConfirm">确定</Button>
    </template>
  </Modal>
</template>