2025-01-13 12:14:12 +08:00
|
|
|
<template>
|
2025-02-17 22:42:51 +08:00
|
|
|
<a-button
|
|
|
|
v-permission="['message:notice:create']"
|
|
|
|
v-if="props.isCreate"
|
|
|
|
type="primary"
|
|
|
|
@click="handleClick"
|
|
|
|
>
|
2025-01-13 12:14:12 +08:00
|
|
|
<template #icon><icon-plus /></template>
|
|
|
|
新建
|
|
|
|
</a-button>
|
|
|
|
<a-button
|
|
|
|
v-permission="['message:notice:update']"
|
|
|
|
v-if="!props.isCreate"
|
|
|
|
type="outline"
|
|
|
|
size="small"
|
|
|
|
:style="{ marginRight: '10px', padding: '7px' }"
|
|
|
|
@click="handleClick"
|
|
|
|
>
|
|
|
|
<template #icon><icon-edit /></template>
|
2025-02-25 16:37:41 +08:00
|
|
|
编辑
|
2025-01-13 12:14:12 +08:00
|
|
|
</a-button>
|
|
|
|
|
|
|
|
<a-modal
|
|
|
|
width="900px"
|
2025-01-17 16:20:12 +08:00
|
|
|
height="500px"
|
2025-01-13 12:14:12 +08:00
|
|
|
:visible="visible"
|
|
|
|
@cancel="handleCancel"
|
|
|
|
>
|
|
|
|
<template #title>{{ modalTitle }}</template>
|
2025-02-17 22:42:51 +08:00
|
|
|
<!-- <DynamicForm :prem="fieIds" />-->
|
|
|
|
<a-form
|
|
|
|
ref="CreateRef"
|
|
|
|
:model="formData"
|
|
|
|
:style="{ width: '800px', height: '420px' }"
|
|
|
|
>
|
2025-01-13 12:14:12 +08:00
|
|
|
<a-form-item
|
|
|
|
field="userId"
|
|
|
|
label="用户"
|
|
|
|
:validate-trigger="['change', 'input']"
|
2025-02-17 22:42:51 +08:00
|
|
|
:rules="[{ message: '请输入用戶' }]"
|
2025-01-13 12:14:12 +08:00
|
|
|
>
|
|
|
|
<a-input-tag
|
2025-02-10 23:58:45 +08:00
|
|
|
v-model="selectedNames"
|
2025-02-17 22:42:51 +08:00
|
|
|
placeholder="请选择用戶"
|
2025-02-10 23:58:45 +08:00
|
|
|
:max-tag-count="5"
|
|
|
|
readonly
|
2025-01-13 12:14:12 +08:00
|
|
|
@click="queryDeptTree"
|
|
|
|
/>
|
|
|
|
</a-form-item>
|
2025-01-17 16:10:39 +08:00
|
|
|
<a-form-item
|
|
|
|
field="type"
|
|
|
|
label="类型"
|
|
|
|
:validate-trigger="['change', 'input']"
|
2025-02-17 22:42:51 +08:00
|
|
|
:rules="[{ required: true, message: '请选择类型' }]"
|
2025-01-17 16:10:39 +08:00
|
|
|
>
|
|
|
|
<a-select
|
|
|
|
v-model="formData.type"
|
2025-02-17 22:42:51 +08:00
|
|
|
placeholder="请选择类型"
|
2025-01-17 16:10:39 +08:00
|
|
|
:options="messageType"
|
|
|
|
/>
|
|
|
|
</a-form-item>
|
2025-01-13 12:14:12 +08:00
|
|
|
<a-form-item
|
|
|
|
field="title"
|
|
|
|
label="标题"
|
|
|
|
:validate-trigger="['change', 'input']"
|
2025-02-17 22:42:51 +08:00
|
|
|
:rules="[{ required: true, message: '请输入标题' }]"
|
2025-01-13 12:14:12 +08:00
|
|
|
>
|
2025-02-17 22:42:51 +08:00
|
|
|
<a-input v-model="formData.title" placeholder="请输入消息标题" />
|
2025-01-13 12:14:12 +08:00
|
|
|
</a-form-item>
|
|
|
|
<a-form-item
|
|
|
|
field="remark"
|
|
|
|
label="备注"
|
|
|
|
:validate-trigger="['change', 'input']"
|
|
|
|
>
|
|
|
|
<!-- v-if="isCreate"-->
|
2025-02-17 22:42:51 +08:00
|
|
|
<a-input v-model="formData.remark" placeholder="请输入备注" />
|
2025-01-13 12:14:12 +08:00
|
|
|
</a-form-item>
|
2025-01-17 16:20:12 +08:00
|
|
|
<a-form-item
|
|
|
|
field="sms"
|
|
|
|
label="短信"
|
|
|
|
:validate-trigger="['change', 'input']"
|
|
|
|
>
|
|
|
|
<a-switch
|
|
|
|
v-model="formData.sms"
|
|
|
|
:checked-value="true"
|
|
|
|
:unchecked-value="false"
|
|
|
|
/>
|
|
|
|
</a-form-item>
|
|
|
|
<a-form-item
|
|
|
|
field="email"
|
|
|
|
label="邮件"
|
|
|
|
:validate-trigger="['change', 'input']"
|
|
|
|
>
|
|
|
|
<a-switch
|
|
|
|
v-model="formData.email"
|
|
|
|
:checked-value="true"
|
|
|
|
:unchecked-value="false"
|
|
|
|
/>
|
|
|
|
</a-form-item>
|
2025-02-17 22:42:51 +08:00
|
|
|
<!-- <a-form-item-->
|
|
|
|
<!-- field="attachmentIds"-->
|
|
|
|
<!-- label='附件'-->
|
|
|
|
<!-- >-->
|
|
|
|
<!-- <!– v-if="isCreate"–>-->
|
|
|
|
<!-- <a-input-->
|
|
|
|
<!-- type="file"-->
|
|
|
|
<!-- v-model="formData.attachmentIds"-->
|
|
|
|
<!-- />-->
|
|
|
|
<!-- </a-form-item>-->
|
|
|
|
<a-form-item field="content" label="内容" :rules="[{ required: true }]">
|
|
|
|
<div style="border: 1px solid #ccc; min-width: 600px">
|
2025-01-13 12:14:12 +08:00
|
|
|
<Toolbar
|
|
|
|
style="border-bottom: 1px solid #ccc"
|
|
|
|
:editor="editorRef"
|
|
|
|
:default-config="toolbarConfig"
|
|
|
|
:mode="mode"
|
2025-02-17 22:42:51 +08:00
|
|
|
:class="{ 'fullscreen-toolbar': isFullScreen }"
|
2025-01-13 12:14:12 +08:00
|
|
|
/>
|
|
|
|
<Editor
|
|
|
|
v-model="formData.content"
|
2025-02-17 22:42:51 +08:00
|
|
|
style="overflow-y: hidden; min-height: 200px"
|
2025-01-13 12:14:12 +08:00
|
|
|
:default-config="editorConfig"
|
|
|
|
:mode="mode"
|
2025-02-17 22:42:51 +08:00
|
|
|
:class="{ 'fullscreen-editor': isFullScreen }"
|
2025-01-13 12:14:12 +08:00
|
|
|
@on-created="handleCreated"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<!-- <a-textarea v-model="formData.content" placeholder="请输入公告内容" style="height: 100px" />-->
|
|
|
|
</a-form-item>
|
|
|
|
</a-form>
|
|
|
|
<template #footer>
|
2025-02-17 22:42:51 +08:00
|
|
|
<a-button class="editor-button" @click="handleCancel">取消</a-button>
|
|
|
|
<a-button class="editor-button" type="primary" @click="handleSubmit"
|
|
|
|
>确定</a-button
|
|
|
|
>
|
2025-01-13 12:14:12 +08:00
|
|
|
</template>
|
|
|
|
</a-modal>
|
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
<!-- 部门树模态框-->
|
|
|
|
<a-modal width="900px" :visible="deptVisible" @cancel="deptTreeCancel">
|
2025-01-13 12:14:12 +08:00
|
|
|
<template #title>发送用户</template>
|
2025-02-17 22:42:51 +08:00
|
|
|
<div style="display: flex">
|
|
|
|
<a-card style="margin-right: 10px; width: 30%">
|
2025-01-13 12:14:12 +08:00
|
|
|
<a-tree
|
|
|
|
:data="deptTreeData"
|
|
|
|
:field-names="{ title: 'name', key: 'id', children: 'children' }"
|
|
|
|
style="margin-bottom: 8px; max-width: 240px"
|
|
|
|
@select="handleClickTree"
|
|
|
|
>
|
|
|
|
</a-tree>
|
|
|
|
</a-card>
|
|
|
|
<a-card style="flex: 1">
|
2025-02-23 18:04:12 +08:00
|
|
|
<a-table
|
|
|
|
row-key="id"
|
|
|
|
:data="renderData"
|
|
|
|
:columns="columns"
|
|
|
|
:row-selection="rowSelection"
|
|
|
|
v-model:selected-keys="selectedIds"
|
2025-02-10 23:58:45 +08:00
|
|
|
>
|
|
|
|
<template #name="{ record }">
|
2025-01-13 12:14:12 +08:00
|
|
|
{{ record.username }}
|
|
|
|
</template>
|
|
|
|
</a-table>
|
|
|
|
</a-card>
|
|
|
|
</div>
|
|
|
|
<template #footer>
|
2025-02-17 22:42:51 +08:00
|
|
|
<a-button class="editor-button" @click="deptTreeCancel">取消</a-button>
|
|
|
|
<a-button class="editor-button" type="primary" @click="deptTreeSubmit"
|
|
|
|
>确定</a-button
|
|
|
|
>
|
2025-01-13 12:14:12 +08:00
|
|
|
</template>
|
|
|
|
</a-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import useVisible from '@/hooks/visible';
|
2025-02-17 22:42:51 +08:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
defineEmits,
|
|
|
|
PropType,
|
|
|
|
ref,
|
|
|
|
shallowRef,
|
|
|
|
onBeforeUnmount,
|
|
|
|
onMounted,
|
|
|
|
} from 'vue';
|
2025-01-13 12:14:12 +08:00
|
|
|
import { CreateRecord } from '@/api/user';
|
|
|
|
import { FormInstance } from '@arco-design/web-vue/es/form';
|
|
|
|
import { Message } from '@arco-design/web-vue';
|
2025-02-10 23:58:45 +08:00
|
|
|
import { useMessageStore, useUserStore } from '@/store';
|
2025-01-13 12:14:12 +08:00
|
|
|
import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
|
2025-02-17 22:42:51 +08:00
|
|
|
import { IEditorConfig } from '@wangeditor/editor';
|
|
|
|
import '@wangeditor/editor/dist/css/style.css';
|
2025-01-13 12:14:12 +08:00
|
|
|
import { getAllDeptTree } from '@/api/dept';
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
prem: {
|
|
|
|
type: Object as PropType<CreateRecord>,
|
|
|
|
},
|
|
|
|
isCreate: Boolean,
|
|
|
|
});
|
|
|
|
// 部门树模态框状态
|
2025-02-10 23:58:45 +08:00
|
|
|
const userStore = useUserStore();
|
2025-02-17 22:42:51 +08:00
|
|
|
const deptVisible = ref(false);
|
2025-01-13 12:14:12 +08:00
|
|
|
const emit = defineEmits(['refresh']);
|
|
|
|
const modalTitle = computed(() => {
|
|
|
|
return props.isCreate ? '创建消息' : '编辑消息';
|
|
|
|
});
|
|
|
|
const { visible, setVisible } = useVisible(false);
|
|
|
|
const checkKeys = ref<number[]>([]);
|
2025-02-17 22:42:51 +08:00
|
|
|
const editorRef = shallowRef();
|
2025-01-13 12:14:12 +08:00
|
|
|
const handleCreated = (editor: any) => {
|
|
|
|
editorRef.value = editor; // 记录 editor 实例,重要!
|
2025-02-17 22:42:51 +08:00
|
|
|
};
|
2025-01-13 12:14:12 +08:00
|
|
|
const CreateRef = ref<FormInstance>();
|
|
|
|
const formData = ref<any>({
|
2025-01-17 16:10:39 +08:00
|
|
|
sms: false,
|
|
|
|
email: false,
|
2025-01-13 12:14:12 +08:00
|
|
|
...props.prem,
|
|
|
|
});
|
|
|
|
const messageStore = useMessageStore();
|
|
|
|
const isFullScreen = ref(false);
|
|
|
|
const mode = 'default';
|
2025-02-17 22:42:51 +08:00
|
|
|
const selectedIds = ref<number[]>([]);
|
|
|
|
const selectedNames = ref<string[]>([]);
|
2025-02-10 23:58:45 +08:00
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
const toolbarConfig = {
|
|
|
|
excludeKeys: ['uploadVideo', 'insertImage', 'insertVideo'],
|
|
|
|
};
|
|
|
|
const columns = computed<any[]>(() => [
|
2025-02-23 18:04:12 +08:00
|
|
|
// {
|
|
|
|
// title: '操作',
|
|
|
|
// dataIndex: 'id',
|
|
|
|
// slotName: 'id',
|
|
|
|
// },
|
2025-01-13 12:14:12 +08:00
|
|
|
{
|
|
|
|
title: '用户',
|
|
|
|
dataIndex: 'username',
|
|
|
|
},
|
2025-02-17 22:42:51 +08:00
|
|
|
]);
|
2025-02-23 18:04:12 +08:00
|
|
|
const rowSelection = {
|
|
|
|
type: 'checkbox',
|
|
|
|
showCheckedAll: true, // 默认选中的行 ID
|
|
|
|
};
|
2025-01-13 12:14:12 +08:00
|
|
|
|
|
|
|
const deptTreeData = ref([
|
|
|
|
{
|
|
|
|
id: '1',
|
|
|
|
name: '总部门',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
id: '2',
|
|
|
|
name: '部门1',
|
|
|
|
members: [
|
|
|
|
{ id: '101', username: '成员1' },
|
2025-02-17 22:42:51 +08:00
|
|
|
{ id: '102', username: '成员2' },
|
|
|
|
],
|
2025-01-13 12:14:12 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '3',
|
|
|
|
name: '部门2',
|
|
|
|
members: [
|
|
|
|
{ id: '201', username: '成员3' },
|
2025-02-17 22:42:51 +08:00
|
|
|
{ id: '202', username: '成员4' },
|
|
|
|
],
|
2025-01-13 12:14:12 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '4',
|
|
|
|
name: '部门3',
|
|
|
|
members: [
|
|
|
|
{ id: '203', username: '成员5' },
|
2025-02-17 22:42:51 +08:00
|
|
|
{ id: '204', username: '成员6' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2025-01-13 12:14:12 +08:00
|
|
|
]);
|
|
|
|
const renderData = ref<any[]>([]);
|
2025-01-17 16:10:39 +08:00
|
|
|
const messageType = computed(() => [
|
|
|
|
{
|
|
|
|
label: '消息',
|
|
|
|
value: 'MESSAGE',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '通知',
|
|
|
|
value: 'NOTICE',
|
|
|
|
},
|
|
|
|
]);
|
2025-01-13 12:14:12 +08:00
|
|
|
// 获取部门树
|
2025-02-10 23:58:45 +08:00
|
|
|
const getDeptTree = async (deptId: number) => {
|
|
|
|
const res = await getAllDeptTree(deptId || 0);
|
2025-01-13 12:14:12 +08:00
|
|
|
if (res.status === 200) {
|
|
|
|
deptTreeData.value = res.data;
|
|
|
|
}
|
2025-02-17 22:42:51 +08:00
|
|
|
};
|
2025-01-13 12:14:12 +08:00
|
|
|
// 部门树查询
|
2025-02-17 22:42:51 +08:00
|
|
|
const queryDeptTree = async () => {
|
2025-01-13 12:14:12 +08:00
|
|
|
deptVisible.value = true;
|
2025-02-17 22:42:51 +08:00
|
|
|
};
|
2025-01-13 12:14:12 +08:00
|
|
|
|
2025-02-10 23:58:45 +08:00
|
|
|
// 获取用户列表
|
|
|
|
const fetchData = async (deptId: number) => {
|
|
|
|
try {
|
|
|
|
const res = await userStore.getUserList({
|
|
|
|
deptId,
|
|
|
|
});
|
|
|
|
renderData.value = res.data.records;
|
|
|
|
} catch (err) {
|
|
|
|
// you can report use errorHandler or other
|
2025-01-13 12:14:12 +08:00
|
|
|
}
|
2025-02-10 23:58:45 +08:00
|
|
|
};
|
|
|
|
|
2025-01-13 12:14:12 +08:00
|
|
|
// 部门树被点击
|
|
|
|
const handleClickTree = (id: number[]) => {
|
2025-02-10 23:58:45 +08:00
|
|
|
const [deptId] = id;
|
|
|
|
fetchData(deptId);
|
2025-02-17 22:42:51 +08:00
|
|
|
};
|
2025-01-13 12:14:12 +08:00
|
|
|
|
|
|
|
// 组件被点击
|
|
|
|
const handleClick = () => {
|
|
|
|
setVisible(true);
|
|
|
|
};
|
|
|
|
|
2025-02-17 22:42:51 +08:00
|
|
|
const editorConfig: Partial<IEditorConfig> = {
|
|
|
|
placeholder: '请输入内容...',
|
|
|
|
MENU_CONF: {
|
2025-01-13 12:14:12 +08:00
|
|
|
// 隐藏菜单
|
2025-02-17 22:42:51 +08:00
|
|
|
hide: [
|
|
|
|
'code',
|
|
|
|
'table',
|
|
|
|
'emoticon',
|
|
|
|
'uploadImage',
|
|
|
|
'video',
|
|
|
|
'todo',
|
|
|
|
'specialChar',
|
|
|
|
],
|
2025-01-13 12:14:12 +08:00
|
|
|
// 配置上传图片
|
|
|
|
uploadImage: {
|
|
|
|
base64LimitSize: 1024 * 1024,
|
|
|
|
// server: '/api/rest/bulletin/1/add',
|
2025-02-17 22:42:51 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2025-01-13 12:14:12 +08:00
|
|
|
// 提交
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
const valid = await CreateRef.value?.validate();
|
|
|
|
if (!valid) {
|
|
|
|
// 新增
|
|
|
|
if (props.isCreate) {
|
2025-01-17 16:10:39 +08:00
|
|
|
formData.value.html = true;
|
2025-01-13 12:14:12 +08:00
|
|
|
// formData.value.username = formData.value.email;
|
|
|
|
const res = await messageStore.createMessage(formData.value);
|
|
|
|
if (res.status === 200) {
|
|
|
|
Message.success({
|
|
|
|
content: '新建成功',
|
|
|
|
duration: 5 * 1000,
|
|
|
|
});
|
|
|
|
emit('refresh');
|
|
|
|
setVisible(false);
|
|
|
|
}
|
|
|
|
CreateRef.value?.resetFields();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 组件销毁时,也及时销毁编辑器
|
|
|
|
onBeforeUnmount(() => {
|
2025-02-17 22:42:51 +08:00
|
|
|
const editor = editorRef.value;
|
|
|
|
if (editor == null) return;
|
|
|
|
editor.destroy();
|
|
|
|
});
|
2025-01-13 12:14:12 +08:00
|
|
|
|
|
|
|
// 关闭
|
|
|
|
const handleCancel = async () => {
|
|
|
|
checkKeys.value = [];
|
|
|
|
setVisible(false);
|
|
|
|
};
|
|
|
|
|
2025-02-10 23:58:45 +08:00
|
|
|
const getNamesByIds = (ids: number[]) => {
|
2025-02-17 22:42:51 +08:00
|
|
|
return ids
|
|
|
|
.map((id) => renderData.value.find((dept) => dept.id === id)?.username)
|
|
|
|
.filter((username) => username !== undefined) as string[];
|
2025-02-10 23:58:45 +08:00
|
|
|
};
|
|
|
|
|
2025-01-13 12:14:12 +08:00
|
|
|
// 部门树模态框提交
|
|
|
|
const deptTreeSubmit = () => {
|
|
|
|
deptVisible.value = false;
|
|
|
|
formData.value.userIds = selectedIds.value;
|
2025-02-10 23:58:45 +08:00
|
|
|
selectedNames.value = getNamesByIds(selectedIds.value);
|
2025-01-13 12:14:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 部门树模态框
|
|
|
|
const deptTreeCancel = () => {
|
|
|
|
deptVisible.value = false;
|
|
|
|
};
|
|
|
|
onMounted(async () => {
|
2025-02-10 23:58:45 +08:00
|
|
|
await getDeptTree(0);
|
2025-01-13 12:14:12 +08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.fullscreen-toolbar {
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 50px; /* 根据需要调整高度 */
|
|
|
|
z-index: 999;
|
|
|
|
background-color: white;
|
|
|
|
}
|
|
|
|
.fullscreen-editor {
|
|
|
|
position: fixed;
|
|
|
|
top: 50px; /* 根据 toolbar 的高度调整 */
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: calc(100% - 50px); /* 减去 toolbar 的高度 */
|
|
|
|
z-index: 999;
|
|
|
|
background-color: white;
|
|
|
|
}
|
2025-02-17 22:42:51 +08:00
|
|
|
.editor-button {
|
|
|
|
position: static;
|
2025-01-13 12:14:12 +08:00
|
|
|
}
|
|
|
|
</style>
|