feat(im): enhance IMChannelPanel and SettingDrawer components

Refactor settings drawer for consistency, add role-based empty states,
and improve save loading UX for IM channel configuration.
This commit is contained in:
wizardchen
2026-06-16 00:49:07 +08:00
committed by lyingbug
parent 53e0333a53
commit 8dbc20b9b3
2 changed files with 131 additions and 72 deletions
+19 -9
View File
@@ -7,7 +7,7 @@
</div> </div>
<t-loading :loading="loading" size="small" class="channels-loading-wrap"> <t-loading :loading="loading" size="small" class="channels-loading-wrap">
<div v-if="!loading && channels.length === 0" class="channels-empty"> <div v-if="!loading && channels.length === 0 && !authStore.hasRole('admin')" class="channels-empty">
<t-empty :description="$t('agentEditor.im.empty')" /> <t-empty :description="$t('agentEditor.im.empty')" />
</div> </div>
@@ -71,15 +71,16 @@
</t-loading> </t-loading>
</div> </div>
<!-- Create/Edit drawer --> <SettingDrawer
<t-drawer
v-model:visible="showCreateDialog" v-model:visible="showCreateDialog"
:header="editingChannel ? $t('agentEditor.im.editChannel') : $t('agentEditor.im.addChannel')" :title="drawerTitle"
:confirm-btn="$t('common.save')" icon="chat-message"
:cancel-btn="$t('common.cancel')" storage-key="setting-drawer:im-channel"
width="560px"
:confirm-loading="saving"
:hide-footer="!authStore.hasRole('admin')"
@confirm="handleSave" @confirm="handleSave"
@close="resetForm" @cancel="resetForm"
size="560px"
> >
<div class="drawer-form"> <div class="drawer-form">
<!-- Platform --> <!-- Platform -->
@@ -419,7 +420,7 @@
</div> </div>
</template> </template>
</div> </div>
</t-drawer> </SettingDrawer>
</div> </div>
</template> </template>
@@ -434,6 +435,7 @@ import {
import { useChatResourcesStore } from '@/stores/chatResources'; import { useChatResourcesStore } from '@/stores/chatResources';
import type { IMChannel } from '@/api/agent'; import type { IMChannel } from '@/api/agent';
import { useAuthStore } from '@/stores/auth'; import { useAuthStore } from '@/stores/auth';
import SettingDrawer from '@/components/settings/SettingDrawer.vue';
const { t } = useI18n(); const { t } = useI18n();
const authStore = useAuthStore(); const authStore = useAuthStore();
@@ -444,9 +446,14 @@ const props = defineProps<{
const channels = ref<IMChannel[]>([]); const channels = ref<IMChannel[]>([]);
const loading = ref(false); const loading = ref(false);
const saving = ref(false);
const showCreateDialog = ref(false); const showCreateDialog = ref(false);
const editingChannel = ref<IMChannel | null>(null); const editingChannel = ref<IMChannel | null>(null);
const drawerTitle = computed(() =>
editingChannel.value ? t('agentEditor.im.editChannel') : t('agentEditor.im.addChannel'),
);
// Knowledge base options for file-to-KB feature // Knowledge base options for file-to-KB feature
const knowledgeBases = ref<{ id: string; name: string }[]>([]); const knowledgeBases = ref<{ id: string; name: string }[]>([]);
@@ -706,6 +713,7 @@ function resetForm() {
} }
async function handleSave() { async function handleSave() {
saving.value = true;
try { try {
// For WeChat, validate that credentials are bound // For WeChat, validate that credentials are bound
if (formData.value.platform === 'wechat' && !formData.value.credentials.bot_token) { if (formData.value.platform === 'wechat' && !formData.value.credentials.bot_token) {
@@ -741,6 +749,8 @@ async function handleSave() {
} catch (e: any) { } catch (e: any) {
const msg = e?.message || (typeof e?.error === 'string' ? e.error : null) || t('common.operationFailed'); const msg = e?.message || (typeof e?.error === 'string' ? e.error : null) || t('common.operationFailed');
MessagePlugin.error(msg); MessagePlugin.error(msg);
} finally {
saving.value = false;
} }
} }
@@ -1,13 +1,13 @@
<template> <template>
<t-drawer <teleport to="body">
v-model:visible="drawerVisible" <div v-if="drawerVisible && resizable" class="setting-drawer-resize-handle"
:size="effectiveWidth" :class="{ 'setting-drawer-resize-handle--active': drawerResizing }" :style="{ right: `${drawerWidthPx}px` }"
:size-draggable="resizable ? sizeDragLimit : false" role="separator" aria-orientation="vertical" @mousedown.prevent="onResizeStart">
placement="right" <div class="setting-drawer-resize-line" />
destroy-on-close </div>
class="setting-drawer" </teleport>
@size-drag-end="onSizeDragEnd" <t-drawer v-model:visible="drawerVisible" :size="effectiveWidth" :z-index="2500" placement="right" destroy-on-close
> :class="['setting-drawer', { 'setting-drawer--resizing': drawerResizing }]">
<!-- <!--
Custom header. We replace TDesign's default header so we can put a leading Custom header. We replace TDesign's default header so we can put a leading
icon badge and an optional subtitle (description) right next to the title, icon badge and an optional subtitle (description) right next to the title,
@@ -43,12 +43,7 @@
<t-button theme="default" variant="outline" @click="handleCancel"> <t-button theme="default" variant="outline" @click="handleCancel">
{{ cancelText || t('common.cancel') }} {{ cancelText || t('common.cancel') }}
</t-button> </t-button>
<t-button <t-button theme="primary" :loading="confirmLoading" :disabled="confirmDisabled" @click="handleConfirm">
theme="primary"
:loading="confirmLoading"
:disabled="confirmDisabled"
@click="handleConfirm"
>
{{ confirmText || t('common.save') }} {{ confirmText || t('common.save') }}
</t-button> </t-button>
</div> </div>
@@ -58,7 +53,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue' import { computed, ref, onMounted, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
interface Props { interface Props {
@@ -73,11 +68,8 @@ interface Props {
*/ */
width?: string width?: string
/** /**
* Whether the drawer can be horizontally resized by dragging its left * Whether the drawer can be horizontally resized by dragging the visible
* edge. We delegate to TDesign's built-in `sizeDraggable` — it already * handle on its left edge (same affordance as doc-content drawer).
* renders the resize cursor on the panel edge and takes care of the
* mousemove handlers, so all we do here is bound it and persist the
* final size on drag-end.
*/ */
resizable?: boolean resizable?: boolean
/** Min/max bounds for the drag-resize, in px. */ /** Min/max bounds for the drag-resize, in px. */
@@ -136,6 +128,11 @@ const resolvedStorageKey = computed(
const clampWidth = (n: number) => const clampWidth = (n: number) =>
Math.max(props.minWidth, Math.min(props.maxWidth, Math.round(n))) Math.max(props.minWidth, Math.min(props.maxWidth, Math.round(n)))
const parseWidthToPx = (width: string) => {
const n = parseInt(width, 10)
return Number.isFinite(n) ? n : 560
}
const loadStoredWidth = (): number | null => { const loadStoredWidth = (): number | null => {
if (typeof window === 'undefined') return null if (typeof window === 'undefined') return null
try { try {
@@ -156,29 +153,73 @@ const effectiveWidth = computed(() =>
userWidthPx.value != null ? `${userWidthPx.value}px` : props.width userWidthPx.value != null ? `${userWidthPx.value}px` : props.width
) )
// ---------- TDesign-native drag-resize ---------- const drawerWidthPx = computed(() =>
// `sizeDraggable` accepts true (no clamp) or { min, max }. We always pass userWidthPx.value ?? parseWidthToPx(props.width)
// the bounds so the user can't accidentally collapse the drawer to nothing )
// or push it past the viewport.
const sizeDragLimit = computed(() => ({
min: props.minWidth,
max: props.maxWidth,
}))
const onSizeDragEnd = (ctx: { e: MouseEvent; size: number }) => { const persistWidth = (width: number) => {
const next = clampWidth(ctx.size) const next = clampWidth(width)
userWidthPx.value = next userWidthPx.value = next
if (typeof window !== 'undefined' && props.storageKey !== '') { if (typeof window === 'undefined') return
try { try {
window.localStorage.setItem(resolvedStorageKey.value, String(next)) window.localStorage.setItem(resolvedStorageKey.value, String(next))
} catch { } catch {
// localStorage can throw in private mode / quota errors. The width // localStorage can throw in private mode / quota errors.
// still applies for this session; we just lose the persistence on
// next open.
}
} }
} }
// ---------- Custom drag-resize (visible handle, same as doc-content) ----------
const drawerResizing = ref(false)
let resizeStartX = 0
let resizeStartWidth = 0
function onResizeStart(e: MouseEvent) {
drawerResizing.value = true
resizeStartX = e.clientX
resizeStartWidth = drawerWidthPx.value
document.addEventListener('mousemove', onResizeMove)
document.addEventListener('mouseup', onResizeEnd)
document.body.style.cursor = 'col-resize'
document.body.style.userSelect = 'none'
}
function onResizeMove(e: MouseEvent) {
const delta = resizeStartX - e.clientX
userWidthPx.value = clampWidth(resizeStartWidth + delta)
}
function onResizeEnd() {
document.removeEventListener('mousemove', onResizeMove)
document.removeEventListener('mouseup', onResizeEnd)
document.body.style.cursor = ''
document.body.style.userSelect = ''
drawerResizing.value = false
persistWidth(drawerWidthPx.value)
}
function cleanupResize() {
document.removeEventListener('mousemove', onResizeMove)
document.removeEventListener('mouseup', onResizeEnd)
document.body.style.cursor = ''
document.body.style.userSelect = ''
drawerResizing.value = false
}
function onWindowResize() {
if (userWidthPx.value != null) {
userWidthPx.value = clampWidth(userWidthPx.value)
}
}
onMounted(() => {
window.addEventListener('resize', onWindowResize, { passive: true })
})
onUnmounted(() => {
window.removeEventListener('resize', onWindowResize)
cleanupResize()
})
const handleConfirm = () => emit('confirm') const handleConfirm = () => emit('confirm')
const handleCancel = () => { const handleCancel = () => {
emit('cancel') emit('cancel')
@@ -249,6 +290,7 @@ const handleCancel = () => {
opacity: 0; opacity: 0;
transform: translateY(4px); transform: translateY(4px);
} }
to { to {
opacity: 1; opacity: 1;
transform: translateY(0); transform: translateY(0);
@@ -288,6 +330,7 @@ const handleCancel = () => {
opacity: 0; opacity: 0;
transform: translateY(6px); transform: translateY(6px);
} }
to { to {
opacity: 1; opacity: 1;
transform: translateY(0); transform: translateY(0);
@@ -363,32 +406,38 @@ const handleCancel = () => {
border-top: 1px solid var(--td-component-stroke); border-top: 1px solid var(--td-component-stroke);
box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04); box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
} }
}
/* /* Visible resize handle — teleported to body, aligned with drawer left edge. */
TDesign renders the drag handle as a class-less <div> on the panel edge .setting-drawer-resize-handle {
when sizeDraggable is on, with inline style `cursor: col-resize` and a position: fixed;
16px-wide TRANSPARENT background — so users can drag, but they have no top: 0;
visual cue that they can. We use an attribute selector on the inline bottom: 0;
cursor style to give it a visible 3px line that lights up on hover/drag, width: 12px;
matching the brand color so it reads as a deliberate affordance. margin-left: -6px;
*/ cursor: col-resize;
.t-drawer__content-wrapper > div[style*="col-resize"] { z-index: 2501;
/* Override TDesign's hardcoded inline width so the visible line is a display: flex;
reasonable thickness; the handle still extends past it because the align-items: center;
hit area is generous on hover. */ justify-content: center;
background: var(--td-component-stroke) !important; }
width: 3px !important;
transition: background 0.15s ease, width 0.15s ease;
&:hover { .setting-drawer-resize-line {
background: var(--td-brand-color) !important; width: 2px;
width: 4px !important; height: 48px;
} border-radius: 1px;
background: var(--td-component-border);
opacity: 0.55;
transition: opacity 0.15s ease, background 0.15s ease;
}
&:active { .setting-drawer-resize-handle:hover .setting-drawer-resize-line,
background: var(--td-brand-color-active, var(--td-brand-color)) !important; .setting-drawer-resize-handle--active .setting-drawer-resize-line {
width: 4px !important; opacity: 1;
} background: var(--td-brand-color);
} }
.t-drawer.setting-drawer--resizing .t-drawer__content {
transition: none !important;
} }
</style> </style>