Browse Source

🚀 消息推送模块

master
wangxiang 2 years ago
parent
commit
268d8bccae
  1. 4
      src/api/platform/common/controller/pushApplication.ts
  2. 56
      src/views/common/push/application/SendMessageModal.vue
  3. 117
      src/views/common/push/application/application.data.ts
  4. 12
      src/views/common/push/application/index.vue

4
src/api/platform/common/controller/pushApplication.ts

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
*/
import type { PushApplication, PushApplicationParams, PushApplicationResult } from '/@/api/platform/common/entity/pushApplication';
import { defHttp } from '/@/utils/http/axios';
import type { PushMessage } from '/@/api/platform/common/entity/pushMessage';
enum Api {
list = '/common_proxy/common/pushApplication/list',
@ -12,12 +13,15 @@ enum Api { @@ -12,12 +13,15 @@ enum Api {
get = '/common_proxy/common/pushApplication',
edit = '/common_proxy/common/pushApplication/update',
del = '/common_proxy/common/pushApplication/remove',
send = '/common_proxy/common/pushApplication/send'
}
export const listPushApplication = (params?: Partial<PushApplicationParams>) => defHttp.get<PushApplicationResult>({ url: Api.list, params }, { isReturnResultResponse: true });
export const addPushApplication = (params: Partial<PushApplication>) => defHttp.post({ url: Api.add, data: params });
export const sendMessage = (params: Partial<PushMessage>) => defHttp.post({ url: Api.send, data: params });
export const editPushApplication = (params: Partial<PushApplication>) => defHttp.put({ url: Api.edit, data: params });
export const getPushApplication = (id: string) => defHttp.get<PushApplication>({ url: `${Api.get}/${id}` });

56
src/views/common/push/application/SendMessageModal.vue

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
<template>
<BasicModal v-bind="$attrs"
width="720px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm"/>
</BasicModal>
</template>
<script lang="ts" setup>
import { BasicForm, useForm } from '/@/components/Form/index';
import { sendFormSchema } from './application.data';
import { sendMessage } from '/@/api/platform/common/controller/pushApplication';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { ref } from 'vue';
import { useUserStore } from '/@/store/modules/user';
const messageSecret = ref<Nullable<string>>('');
const userStore = useUserStore();
const userInfoStore = userStore.getUserInfo;
const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({
labelWidth: 150,
schemas: sendFormSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
const [registerModal, { setModalProps, closeModal, redoModalHeight }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => {
//
await resetFields();
await clearValidate();
messageSecret.value = data.record?.messageSecret;
const props: Partial<ModalProps> = { confirmLoading: false };
props.title = '发送消息';
// :
setModalProps(props);
redoModalHeight();
});
async function handleSubmit() {
try {
//
const formData = await validate();
formData.fromUserId = userInfoStore.id;
formData.messageSecret = messageSecret.value;
//
setModalProps({ confirmLoading: true });
await sendMessage(formData);
//
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

117
src/views/common/push/application/application.data.ts

@ -22,8 +22,8 @@ export const columns: BasicColumn[] = [ @@ -22,8 +22,8 @@ export const columns: BasicColumn[] = [
}
},
{
title: '匹配域',
dataIndex: 'url'
title: '限制ip',
dataIndex: 'ip'
},
{
title: '创建人',
@ -75,10 +75,9 @@ export const formSchema: FormSchema[] = [ @@ -75,10 +75,9 @@ export const formSchema: FormSchema[] = [
}
},
{
field: 'url',
label: '匹配域',
field: 'ip',
label: '限制ip',
component: 'Input',
required: true,
colProps: {
span: 12
}
@ -110,3 +109,111 @@ export const formSchema: FormSchema[] = [ @@ -110,3 +109,111 @@ export const formSchema: FormSchema[] = [
}
}
];
export const sendFormSchema: FormSchema[] = [
{
field: 'fromUserId',
label: '发送方用户id',
component: 'Input',
show: false
},
{
field: 'messageSecret',
label: 'app发送密钥',
component: 'Input',
show: false
},
{
field: 'title',
label: '标题',
component: 'Input',
required: true,
colProps: {
span: 24
}
},
{
label: '通知文字描述',
field: 'text',
component: 'InputTextArea',
required: true,
componentProps: {
rows: 6
},
colProps: {
span: 24
}
},
{
label: '自定义通知声音',
field: 'sound',
component: 'Input',
componentProps: {
placeholder: '格式为R.raw.[sound]',
},
colProps: {
span: 24
}
},
{
label: '自定义播放文件名称',
field: 'customPlayFileName',
component: 'Input',
colProps: {
span: 24
}
},
{
field: 'customTypeId',
label: '自定义推送类型ID',
component: 'Input',
colProps: {
span: 12
}
},
{
field: 'playVibrate',
label: '收到通知是否震动',
component: 'RadioGroup',
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playLights',
label: '收到通知是否闪灯',
component: 'RadioGroup',
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playSound',
label: '收到通知是否发出声音',
component: 'RadioGroup',
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
];

12
src/views/common/push/application/index.vue

@ -18,6 +18,11 @@ @@ -18,6 +18,11 @@
</template>
<template #action="{ record }">
<TableAction :actions="[
{
label: '发送消息',
icon: 'fa6-regular:message',
onClick: handleSend.bind(null, record)
},
{
label: '编辑',
icon: 'fa6-regular:pen-to-square',
@ -34,6 +39,7 @@ @@ -34,6 +39,7 @@
</BasicTable>
<!--弹出窗体区域-->
<ApplicationModal @register="registerModal" @success="handleRefreshTable"/>
<SendMessageModal @register="registerSendModal"/>
</div>
</template>
@ -49,6 +55,7 @@ @@ -49,6 +55,7 @@
import { listPushApplication, delPushApplication } from '/@/api/platform/common/controller/pushApplication';
import { useModal } from '/@/components/Modal';
import ApplicationModal from './ApplicationModal.vue';
import SendMessageModal from './SendMessageModal.vue';
import { columns, searchFormSchema } from './application.data';
import { useMessage } from '/@/hooks/web/useMessage';
@ -67,6 +74,7 @@ @@ -67,6 +74,7 @@
});
const { createConfirm, createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerSendModal, { openModal: openSendModal }] = useModal();
const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({
title: '推送应用列表',
api: listPushApplication,
@ -111,6 +119,10 @@ @@ -111,6 +119,10 @@
openModal(true, { _tag: 'edit', record });
}
function handleSend(record?: Recordable) {
openSendModal(true, { record });
}
/** 删除按钮操作,行内删除 */
async function handleDel(record?: Recordable) {
const ids = record?.id || getSelectRowKeys();

Loading…
Cancel
Save