feat: 新增发送消息

This commit is contained in:
wanglihui 2023-08-05 20:19:08 +08:00
parent de0f894304
commit b26f27c261
12 changed files with 265 additions and 13 deletions

View File

@ -38,6 +38,7 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'vue/multi-word-component-names': 'off',
'vue/no-mutating-props': 'off',
'no-undef': 'off'
},
globals: {

View File

@ -9,6 +9,24 @@ export function messageGet(params: any) {
});
}
// 发消息
export function messageSendPost(data: any) {
return request({
url: '/manager/message/send',
method: 'post',
data
});
}
// 发全员消息
export function messageSendAllPost(data: any) {
return request({
url: '/manager/message/sendall',
method: 'post',
data
});
}
// 违禁词列表
export function messageProhibitWordsGet(params: any) {
return request({

View File

@ -0,0 +1,85 @@
<template>
<el-dialog
:model-value="value"
:width="600"
:align-center="true"
:close-on-click-modal="false"
:close-on-press-escape="false"
:draggable="true"
:z-index="99"
title="发送信息"
@close="onClose"
>
<div class="mb-20px">
<div>给所有用户发送一条信息</div>
</div>
<div>
<el-input v-model="content" :rows="6" type="textarea" placeholder="请输入内容" />
</div>
<template #footer>
<el-space>
<el-button @click="onSend">取消</el-button>
<el-button type="primary" :loading="loaging" @click="onSend">发送</el-button>
</el-space>
</template>
</el-dialog>
</template>
<script lang="ts" name="BdSandAllMsg" setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
// API
import { messageSendAllPost } from '@/api/message';
interface IProps {
value: boolean;
}
const props = withDefaults(defineProps<IProps>(), {
value: false
});
const content = ref('');
const loaging = ref<boolean>(false);
const emits = defineEmits<{
(e: 'update:value', item: boolean): void;
(e: 'ok', item: any): void;
}>();
watch(
() => props.value,
(n, _o) => {
console.log(props.value);
props.value = n;
}
);
//
const onClose = () => {
emits('update:value', false);
};
//
const onSend = () => {
if (!content.value) {
return ElMessage.info('请输入发送内容!');
}
const fromData = {
content: content.value
};
loaging.value = true;
messageSendAllPost(fromData)
.then((res: any) => {
loaging.value = false;
if (res.status == 200) {
ElMessage.success('发送成功!');
content.value = '';
onClose();
emits('ok', true);
}
})
.catch(err => {
loaging.value = false;
if (err.status == 400) {
ElMessage.error(err.msg);
}
});
};
</script>

View File

@ -0,0 +1,96 @@
<template>
<el-dialog
:model-value="value"
:width="600"
:align-center="true"
:close-on-click-modal="false"
:close-on-press-escape="false"
:draggable="true"
:z-index="99"
title="发送信息"
@close="onClose"
>
<div class="mb-20px">
<el-divider content-position="left">接受者信息</el-divider>
<div>接受者ID{{ receivederName }}</div>
<div>接受者名称{{ receiveder }}</div>
<el-divider content-position="left">发送者信息</el-divider>
<div>发送者ID{{ sender }}</div>
<div>发送者名字{{ sender }}</div>
</div>
<div>
<el-input v-model="content" :rows="6" type="textarea" placeholder="请输入内容" />
</div>
<el-button type="primary" size="large" :loading="loaging" class="m-t-20px !w-full" @click="onSend">发送</el-button>
</el-dialog>
</template>
<script lang="ts" name="BdSandMsg" setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
// API
import { messageSendPost } from '@/api/message';
interface IProps {
value: boolean;
receivederChannelType?: number;
receiveder?: string;
receivederName?: string;
sender?: string;
senderName?: string;
}
const props = withDefaults(defineProps<IProps>(), {
value: false,
receivederChannelType: 1,
receiveder: '',
receivederName: '',
sender: '',
senderName: ''
});
const content = ref('');
const loaging = ref<boolean>(false);
const emits = defineEmits<{
(e: 'update:value', item: boolean): void;
}>();
watch(
() => props.value,
(n, _o) => {
console.log(props.value);
props.value = n;
}
);
const onClose = () => {
emits('update:value', false);
};
const onSend = () => {
if (!content.value) {
return ElMessage.info('请输入发送内容!');
}
const fromData = {
sender: props.sender,
sender_name: props.senderName,
received_channel_id: props.receiveder,
received_channel_type: props.receivederChannelType,
content: content.value
};
loaging.value = true;
messageSendPost(fromData)
.then((res: any) => {
loaging.value = false;
if (res.status == 200) {
ElMessage.success('发送成功!');
content.value = '';
}
})
.catch(err => {
loaging.value = false;
if (err.status == 400) {
ElMessage.error(err.msg);
}
});
};
</script>

View File

@ -47,7 +47,7 @@ const onChangePassword = () => {
const onLogoutClick = () => {
// 1. Token
userStore.setToken('');
userStore.setUserInfo({ name: '您好,超管' });
userStore.setUserInfo({ name: '您好,超管', uid: '' });
// 2.
router.replace(LOGIN_URL);
};

View File

@ -53,6 +53,8 @@
/>
</div>
</div>
<!-- 发消息 -->
<bd-send-msg v-model:value="sendValue" v-bind="sendInfo" />
</bd-page>
</template>
@ -138,7 +140,7 @@ const column = reactive<Column.ColumnOptions[]>([
render: (scope: any) => {
return (
<ElSpace>
<ElButton type="primary" onClick={() => aa(scope.row)}>
<ElButton type="primary" onClick={() => onSand(scope.row)}>
发消息
</ElButton>
<ElDropdown
@ -210,9 +212,24 @@ const onCurrentChange = (current: number) => {
getTableList();
};
//
const aa = (a: any) => {
console.log(a);
//
const sendValue = ref<boolean>(false);
const sendInfo = ref({
receivederChannelType: 1,
receiveder: '',
receivederName: '',
sender: '',
senderName: ''
});
const onSand = (item: any) => {
sendValue.value = true;
sendInfo.value = {
receivederChannelType: 2,
receiveder: item.group_no,
receivederName: item.name,
sender: item.create_name,
senderName: item.creator
};
};
//

View File

@ -9,7 +9,7 @@
<div class="flex items-center h-50px">
<el-form inline>
<el-form-item class="mb-0 !mr-0">
<el-button type="primary">发送消息</el-button>
<el-button type="primary" @click="onSand">发送消息</el-button>
</el-form-item>
</el-form>
</div>
@ -50,6 +50,8 @@
/>
</div>
</div>
<!-- 发送消息 -->
<bd-sand-all-msg v-model:value="sandValue" @ok="okSand" />
</bd-page>
</template>
@ -114,7 +116,8 @@ const column = reactive<Column.ColumnOptions[]>([
render: (scope: any) => {
let img_url = '';
if (scope.row['receiver']) {
img_url = `${BU_DOU_CONFIG.APP_URL}users/${scope.row['receiver']}/avatar`;
const msgURL = scope.row['receiver_channel_type'] == 1 ? 'users' : 'groups';
img_url = `${BU_DOU_CONFIG.APP_URL}${msgURL}/${scope.row['receiver']}/avatar`;
}
return (
<ElAvatar src={img_url} size={54}>
@ -201,6 +204,16 @@ const onCurrentChange = (current: number) => {
getTableList();
};
//
const sandValue = ref<boolean>(false);
const onSand = () => {
sandValue.value = true;
};
//
const okSand = () => {
getTableList();
};
//
onMounted(() => {
getTableList();

View File

@ -54,6 +54,8 @@
/>
</div>
</div>
<!-- 发消息 -->
<bd-send-msg v-model:value="sendValue" v-bind="sendInfo" />
</bd-page>
</template>
@ -66,11 +68,13 @@ meta:
<script lang="tsx" setup>
import { useRouter } from 'vue-router';
import { ElButton, ElSpace, ElAvatar, ElDropdown, ElDropdownMenu, ElDropdownItem, ElMessage, ElMessageBox } from 'element-plus';
import { useUserStore } from '@/stores/modules/user';
import { BU_DOU_CONFIG } from '@/config';
// API
import { userListGet, userLiftbanPut } from '@/api/user';
const router = useRouter();
const userStore = useUserStore();
/**
* 表格
*/
@ -167,7 +171,7 @@ const column = reactive<Column.ColumnOptions[]>([
render: (scope: any) => {
return (
<ElSpace>
<ElButton type="primary" onClick={() => aa(scope.row)}>
<ElButton type="primary" onClick={() => onSand(scope.row)}>
发消息
</ElButton>
<ElDropdown
@ -231,8 +235,24 @@ const onCurrentChange = (current: number) => {
getUserList();
};
const aa = (a: any) => {
console.log(a);
//
const sendValue = ref<boolean>(false);
const sendInfo = ref({
receivederChannelType: 1,
receiveder: '',
receivederName: '',
sender: '',
senderName: ''
});
const onSand = (item: any) => {
sendValue.value = true;
sendInfo.value = {
receivederChannelType: 1,
receiveder: item.uid,
receivederName: item.name,
sender: userStore.userInfo.uid,
senderName: userStore.userInfo.name
};
};
//

View File

@ -26,7 +26,7 @@ export interface GlobalState {
/* UserState */
export interface UserState {
token: string;
userInfo: { name: string };
userInfo: { name: string; uid: string };
}
/* tabsMenuProps */

View File

@ -6,7 +6,7 @@ export const useUserStore = defineStore({
id: 'budou-user',
state: (): UserState => ({
token: '',
userInfo: { name: '您好,超管' }
userInfo: { name: '您好,超管', uid: '' }
}),
getters: {},
actions: {

View File

@ -10,6 +10,8 @@ declare module 'vue' {
AddNode: typeof import('./../components/bdWorkflow/nodes/addNode.vue')['default']
Approver: typeof import('./../components/bdWorkflow/nodes/approver.vue')['default']
BdPage: typeof import('./../components/BdPage/index.vue')['default']
BdSandAllMsg: typeof import('./../components/BdSandAllMsg/index.vue')['default']
BdSendMsg: typeof import('./../components/BdSendMsg/index.vue')['default']
BdStatistic: typeof import('./../components/BdStatistic/index.vue')['default']
BdWorkflow: typeof import('./../components/bdWorkflow/index.vue')['default']
Branch: typeof import('./../components/bdWorkflow/nodes/branch.vue')['default']

View File

@ -32,7 +32,7 @@ axiosInstance.interceptors.response.use(
const code = error.response.status;
if (code == 401) {
userStore.setToken('');
userStore.setUserInfo({ name: '您好,超管' });
userStore.setUserInfo({ name: '您好,超管', uid: '' });
router.replace('/login');
}
if (code == 400) {