241 lines
8.3 KiB
Vue
241 lines
8.3 KiB
Vue
<template>
|
|
<div>
|
|
<div class="n-layout-page-header"><n-card :bordered="false" :title="title" /></div>
|
|
<n-card :bordered="false" class="proCard">
|
|
<BasicForm
|
|
ref="searchFormRef"
|
|
@register="register"
|
|
@submit="reloadTable"
|
|
@reset="handleReset"
|
|
@keyup.enter="reloadTable"
|
|
/>
|
|
<BasicTable
|
|
ref="actionRef"
|
|
:columns="columns"
|
|
:request="loadDataTable"
|
|
:row-key="(row) => row.tenantId + '-' + row.topic + '-' + row.seqId"
|
|
:actionColumn="actionColumn"
|
|
:scroll-x="scrollX"
|
|
:resizeHeightOffset="-10000"
|
|
>
|
|
<template #tableTitle>
|
|
<n-button
|
|
v-if="hasPermission([permissionPrefix + '/export'])"
|
|
type="primary"
|
|
@click="handleExport"
|
|
><template #icon
|
|
><n-icon><ExportOutlined /></n-icon></template
|
|
>导出</n-button
|
|
>
|
|
</template>
|
|
</BasicTable>
|
|
</n-card>
|
|
<n-modal v-model:show="showDetail" preset="card" title="消息详情" class="detail-modal">
|
|
<n-descriptions label-placement="left" bordered :column="1">
|
|
<n-descriptions-item label="Topic">{{ current.topic }}</n-descriptions-item>
|
|
<n-descriptions-item label="消息序号">{{ current.seqId }}</n-descriptions-item>
|
|
<n-descriptions-item label="发送用户">{{
|
|
current.senderNickname || current.senderUsername || current.fromUserId
|
|
}}</n-descriptions-item>
|
|
<n-descriptions-item :label="group ? '群名称' : '接收用户'">{{
|
|
group
|
|
? current.groupName || current.topic
|
|
: current.receiverNickname || current.receiverUsername || current.toUserId
|
|
}}</n-descriptions-item>
|
|
<n-descriptions-item label="消息类型">{{ current.contentType }}</n-descriptions-item>
|
|
<n-descriptions-item label="消息状态">{{ current.status }}</n-descriptions-item>
|
|
<n-descriptions-item label="完整内容">
|
|
<pre class="content-view">{{ current.content || current.contentExcerpt }}</pre>
|
|
</n-descriptions-item>
|
|
<n-descriptions-item label="发送时间">{{ current.createdAt }}</n-descriptions-item>
|
|
</n-descriptions>
|
|
</n-modal>
|
|
<n-modal
|
|
v-model:show="showAction"
|
|
preset="card"
|
|
:title="actionType === 'hide' ? '隐藏消息' : '删除消息'"
|
|
class="action-modal"
|
|
>
|
|
<n-form-item label="处置原因" required
|
|
><n-input
|
|
v-model:value="reason"
|
|
type="textarea"
|
|
maxlength="500"
|
|
show-count
|
|
placeholder="请输入处置原因"
|
|
/></n-form-item>
|
|
<template #footer
|
|
><n-space justify="end"
|
|
><n-button @click="showAction = false">取消</n-button
|
|
><n-button
|
|
:type="actionType === 'hide' ? 'warning' : 'error'"
|
|
:loading="submitting"
|
|
@click="submitAction"
|
|
>确认</n-button
|
|
></n-space
|
|
></template
|
|
>
|
|
</n-modal>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { computed, h, onMounted, reactive, ref } from 'vue';
|
|
import { useMessage } from 'naive-ui';
|
|
import { ExportOutlined } from '@vicons/antd';
|
|
import { BasicForm, useForm } from '@/components/Form/index';
|
|
import { BasicTable, TableAction } from '@/components/Table';
|
|
import { usePermission } from '@/hooks/web/usePermission';
|
|
import { useUserStore } from '@/store/modules/user';
|
|
import { adaTableScrollX } from '@/utils/hotgo';
|
|
import { imQueryTenantOptions, loadImQueryTenantOptions } from '@/views/imAdminQueryShared';
|
|
import { createMessageColumns, createMessageSchemas, loadMessageOptions } from './model';
|
|
import * as PrivateApi from '@/api/imPrivateMessage';
|
|
import * as GroupApi from '@/api/imGroupMessage';
|
|
|
|
const props = defineProps<{ group: boolean }>();
|
|
const api: any = props.group ? GroupApi : PrivateApi;
|
|
const title = props.group ? '群聊消息' : '单聊消息';
|
|
const permissionPrefix = props.group ? '/imGroupMessage' : '/imPrivateMessage';
|
|
const message = useMessage();
|
|
const { hasPermission } = usePermission();
|
|
const userStore = useUserStore();
|
|
const isPlatformAdmin = computed(() => userStore.isCompanyDept);
|
|
const schemas = createMessageSchemas(props.group);
|
|
const columns = createMessageColumns(props.group);
|
|
const actionRef = ref();
|
|
const searchFormRef = ref<any>({});
|
|
const showDetail = ref(false);
|
|
const showAction = ref(false);
|
|
const submitting = ref(false);
|
|
const hasQueried = ref(!props.group);
|
|
const current = ref<Recordable>({});
|
|
const reason = ref('');
|
|
const actionType = ref<'hide' | 'delete'>('hide');
|
|
const tenantSchema = schemas.value.find((item) => item.field === 'tenantId');
|
|
if (tenantSchema) tenantSchema.ifShow = () => isPlatformAdmin.value;
|
|
const actionColumn = reactive({
|
|
width: 210,
|
|
title: '操作',
|
|
key: 'action',
|
|
fixed: 'right',
|
|
render(record) {
|
|
return h(TableAction as any, {
|
|
style: 'button',
|
|
actions: [
|
|
{ label: '详情', auth: [permissionPrefix + '/view'], onClick: () => openDetail(record) },
|
|
{
|
|
label: '隐藏',
|
|
type: 'warning',
|
|
auth: [permissionPrefix + '/hide'],
|
|
ifShow: () => record.status === 'normal',
|
|
onClick: () => openAction(record, 'hide'),
|
|
},
|
|
{
|
|
label: '删除',
|
|
type: 'error',
|
|
auth: [permissionPrefix + '/delete'],
|
|
ifShow: () => record.status !== 'deleted',
|
|
onClick: () => openAction(record, 'delete'),
|
|
},
|
|
],
|
|
});
|
|
},
|
|
});
|
|
const scrollX = computed(() => adaTableScrollX(columns, actionColumn.width));
|
|
const [register, { setFieldsValue }] = useForm({
|
|
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
|
labelWidth: 90,
|
|
schemas,
|
|
});
|
|
const loadDataTable = async (res) => {
|
|
if (props.group && !hasQueried.value) return { list: [], page: 1, pageCount: 0, totalCount: 0 };
|
|
const params = { ...searchFormRef.value?.formModel, ...res };
|
|
if (isPlatformAdmin.value && !params.tenantId)
|
|
return { list: [], page: 1, pageCount: 0, totalCount: 0 };
|
|
return api.List(params);
|
|
};
|
|
function reloadTable() {
|
|
hasQueried.value = true;
|
|
actionRef.value?.reload();
|
|
}
|
|
async function handleReset() {
|
|
const defaults: Recordable = {};
|
|
if (isPlatformAdmin.value) defaults.tenantId = imQueryTenantOptions.value[0]?.value;
|
|
await setFieldsValue(defaults);
|
|
if (props.group) hasQueried.value = false;
|
|
actionRef.value?.reload();
|
|
}
|
|
function handleExport() {
|
|
if (props.group && !hasQueried.value) {
|
|
message.warning('请先查询群聊消息');
|
|
return;
|
|
}
|
|
const params = { ...searchFormRef.value?.formModel };
|
|
if (isPlatformAdmin.value && !params.tenantId) {
|
|
message.warning('请选择商户');
|
|
return;
|
|
}
|
|
api.Export(params);
|
|
}
|
|
async function openDetail(record) {
|
|
current.value = await api.View({
|
|
tenantId: record.tenantId,
|
|
topic: record.topic,
|
|
seqId: record.seqId,
|
|
});
|
|
showDetail.value = true;
|
|
}
|
|
function openAction(record, type: 'hide' | 'delete') {
|
|
current.value = record;
|
|
actionType.value = type;
|
|
reason.value = '';
|
|
showAction.value = true;
|
|
}
|
|
async function submitAction() {
|
|
if (!reason.value.trim()) {
|
|
message.warning('请输入处置原因');
|
|
return;
|
|
}
|
|
submitting.value = true;
|
|
try {
|
|
const fn = actionType.value === 'hide' ? api.Hide : api.Delete;
|
|
const res = await fn({
|
|
tenantId: current.value.tenantId,
|
|
topic: current.value.topic,
|
|
seqId: current.value.seqId,
|
|
reason: reason.value.trim(),
|
|
});
|
|
message.success(`命令已提交:${res?.commandId || ''}`);
|
|
showAction.value = false;
|
|
reloadTable();
|
|
} finally {
|
|
submitting.value = false;
|
|
}
|
|
}
|
|
onMounted(async () => {
|
|
loadMessageOptions();
|
|
if (isPlatformAdmin.value) {
|
|
await loadImQueryTenantOptions();
|
|
if (imQueryTenantOptions.value.length)
|
|
await setFieldsValue({ tenantId: imQueryTenantOptions.value[0].value });
|
|
else message.warning('暂无可用商户');
|
|
}
|
|
if (!props.group) reloadTable();
|
|
});
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.detail-modal {
|
|
width: min(760px, 92vw);
|
|
}
|
|
.action-modal {
|
|
width: min(520px, 92vw);
|
|
}
|
|
.content-view {
|
|
margin: 0;
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|
|
</style>
|