Browse Source

refactor: 重构黑名单模块

master
wangxiang 2 years ago
parent
commit
9df378bfd0
  1. 96
      src/views/common/push/pushApplication/application.data.ts
  2. 45
      src/views/common/push/pushBlacklist/BlacklistModal.vue
  3. 87
      src/views/common/push/pushBlacklist/PassListModal.vue
  4. 118
      src/views/common/push/pushBlacklist/blacklist.data.ts
  5. 43
      src/views/common/push/pushBlacklist/index.vue
  6. 71
      src/views/common/push/pushBlacklist/passList.data.ts

96
src/views/common/push/pushApplication/application.data.ts

@ -2,12 +2,7 @@ import { BasicColumn } from '/@/components/Table'; @@ -2,12 +2,7 @@ import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { listPushFile } from '/@/api/platform/common/controller/pushFile';
import { useUserStore } from '/@/store/modules/user';
import { listPushCustomType } from '/@/api/platform/common/controller/pushCustomType';
const userStore = useUserStore();
const userInfoStore = userStore.getUserInfo;
import { listPushType } from '/@/api/platform/common/controller/pushType';
/** 表格列配置 */
export const columns: BasicColumn[] = [
@ -28,8 +23,8 @@ export const columns: BasicColumn[] = [ @@ -28,8 +23,8 @@ export const columns: BasicColumn[] = [
}
},
{
title: '限制ip',
dataIndex: 'ip'
title: '忽略ip',
dataIndex: 'ignoreIp'
},
{
title: '创建人',
@ -81,8 +76,8 @@ export const formSchema: FormSchema[] = [ @@ -81,8 +76,8 @@ export const formSchema: FormSchema[] = [
}
},
{
field: 'ip',
label: '限制ip',
field: 'ignoreIp',
label: '忽略ip',
component: 'Input',
colProps: {
span: 12
@ -118,8 +113,8 @@ export const formSchema: FormSchema[] = [ @@ -118,8 +113,8 @@ export const formSchema: FormSchema[] = [
export const sendFormSchema: FormSchema[] = [
{
field: 'fromUserId',
label: '送方用户id',
field: 'userId',
label: '送方用户id',
component: 'Input',
show: false
},
@ -151,37 +146,11 @@ export const sendFormSchema: FormSchema[] = [ @@ -151,37 +146,11 @@ export const sendFormSchema: FormSchema[] = [
}
},
{
label: '自定义通知声音',
field: 'sound',
component: 'Input',
componentProps: {
placeholder: '格式为R.raw.[sound]',
},
colProps: {
span: 24
}
},
{
field: 'customPlayFileName',
label: '播放文件名称',
field: 'pushTypeId',
label: '推送类型',
component: 'ApiSelect',
componentProps: {
api: listPushFile,
params: {
size: 99,
createById: userInfoStore.id
},
labelField: 'original',
valueField: 'original',
resultField: 'data'
},
},
{
field: 'customTypeId',
label: '自定义推送类型ID',
component: 'ApiSelect',
componentProps: {
api: listPushCustomType,
api: listPushType,
params: {
size: 99
},
@ -190,49 +159,4 @@ export const sendFormSchema: FormSchema[] = [ @@ -190,49 +159,4 @@ export const sendFormSchema: FormSchema[] = [
resultField: 'data'
},
},
{
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
}
},
];

45
src/views/common/push/pushBlacklist/BlacklistModal.vue

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
<template>
<BasicModal
v-bind="$attrs"
width="720px"
:showOkBtn="false"
@register="registerModal"
>
<BasicForm @register="registerForm"/>
</BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './blacklist.data';
import { getPushBlacklist } from '/@/api/platform/common/controller/pushBlacklist';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { useRoute } from 'vue-router';
/** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>('');
/** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']);
const router = useRoute();
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({
labelWidth: 100,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => {
//
await resetFields();
await clearValidate();
//
tag.value = data._tag;
const props: Partial<ModalProps> = { confirmLoading: false };
props.title = '查看黑名单用户';
await setFieldsValue(await getPushBlacklist({
concernUserId: data.record?.concernUserId,
fanUserId: data.record?.fanUserId
}));
// :
setModalProps(props);
});
</script>

87
src/views/common/push/pushBlacklist/PassListModal.vue

@ -1,87 +0,0 @@ @@ -1,87 +0,0 @@
<template>
<BasicModal
v-bind="$attrs"
width="720px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm"/>
</BasicModal>
</template>
<script lang="ts" setup>
/**
* 提供模板规范代码参考,请尽量保证编写代码风格跟模板规范代码一致
* 采用vben-动态表格表单封装组件编写,采用 setup 写法
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved.
* author entfrm开发团队-王翔
*/
import {ref, toRaw, unref} from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './passList.data';
import { addPushPassList, editPushPassList, getPushPassList } from '/@/api/platform/common/controller/pushPassList';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { useRoute } from 'vue-router';
/** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>('');
/** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']);
const router = useRoute();
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({
labelWidth: 100,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => {
//
await resetFields();
await clearValidate();
//
tag.value = data._tag;
const refId = data.record?.id;
const props: Partial<ModalProps> = { confirmLoading: false };
await updateSchema([
{
field: 'type',
defaultValue: router.query.type
},
]);
// tag
switch (unref(tag)) {
case 'add':
props.title = '新增黑名单';
break;
case 'edit':
props.title = '编辑黑名单';
await setFieldsValue(await getPushPassList(refId));
break;
}
// :
setModalProps(props);
});
/** 处理弹出框提交 */
async function handleSubmit() {
try {
//
const formData = await validate();
//
setModalProps({ confirmLoading: true });
// tag
switch (unref(tag)) {
case 'add':
await addPushPassList(formData);
break;
case 'edit':
await editPushPassList(formData);
break;
}
//
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

118
src/views/common/push/pushBlacklist/blacklist.data.ts

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
/** 表格列配置 */
export const columns: BasicColumn[] = [
{
title: '昵称',
dataIndex: 'nickName'
},
{
title: '性别',
dataIndex: 'sex',
width: 80,
customRender: ({ record }) => {
const sex = record.sex;
const enable = ~~sex === 0;
const color = enable ? 'green' : 'red';
const text = enable ? '男' : '女';
return h(Tag, { color: color }, () => text);
}
},
{
title: '手机号',
dataIndex: 'phone'
},
{
title: '邮箱',
dataIndex: 'email'
},
{
title: '所属部门',
dataIndex: 'deptName'
},
{
title: '创建人',
dataIndex: 'createByName'
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 200
},
];
/** 搜索表单配置 */
export const searchFormSchema: FormSchema[] = [
{
field: 'nickName',
label: '昵称',
component: 'Input',
componentProps: {
placeholder: '请输入昵称',
},
colProps: { span: 6 }
}
];
/** 表单配置 */
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'nickName',
label: '昵称',
component: 'Input',
componentProps: {
disabled: true
}
},
{
field: 'deptName',
label: '所属部门',
component: 'Input',
colProps: {
span: 12
},
componentProps: {
disabled: true
}
},
{
field: 'sex',
label: '性别',
component: 'Select',
colProps: {
span: 12
},
componentProps: {
disabled: true,
options: [
{ label: '男', value: '0' },
{ label: '女', value: '1' }
]
},
},
{
field: 'phone',
label: '手机号',
component: 'Input',
componentProps: {
disabled: true
}
},
{
field: 'email',
label: '邮箱',
component: 'Input',
componentProps: {
disabled: true
}
},
];

43
src/views/common/push/pushBlacklist/index.vue

@ -5,22 +5,20 @@ @@ -5,22 +5,20 @@
@selection-change="handleSelectionChange"
>
<template #toolbar>
<!--<a-button type="primary"
@click="handleAdd()"
>新增黑名单</a-button>
<a-button type="primary"
:disabled="state.single"
@click="handleEdit()"
>修改黑名单</a-button>-->
<a-button
type="primary"
:disabled="state.multiple"
@click="handleDel()"
>移除黑名单</a-button>
</template>
<template #action="{ record }">
<TableAction
:actions="[
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction :actions="[
{
label: '查看',
icon: 'fa6-regular:pen-to-square',
onClick: handleViewEdit.bind(null, record)
},
{
label: '移除',
icon: 'ant-design:delete-outlined',
@ -29,9 +27,10 @@ @@ -29,9 +27,10 @@
}]"
/>
</template>
</template>
</BasicTable>
<!--弹出窗体区域-->
<PassListModal @register="registerModal" @success="handleRefreshTable"/>
<BlacklistModal @register="registerModal" @success="handleRefreshTable"/>
</div>
</template>
@ -44,10 +43,10 @@ @@ -44,10 +43,10 @@
*/
import { reactive, toRaw } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { listPushPassList, delPushPassList } from '/@/api/platform/common/controller/pushPassList';
import { listPushBlacklist, delPushBlacklist } from '/@/api/platform/common/controller/pushBlacklist';
import { useModal } from '/@/components/Modal';
import PassListModal from './PassListModal.vue';
import { columns, searchFormSchema } from './passList.data';
import BlacklistModal from './BlacklistModal.vue';
import { columns, searchFormSchema } from './blacklist.data';
import { useMessage } from '/@/hooks/web/useMessage';
import { useRoute } from 'vue-router';
@ -69,12 +68,12 @@ @@ -69,12 +68,12 @@
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({
title: '黑名单列表',
api: listPushPassList,
api: listPushBlacklist,
rowKey: 'id',
columns,
formConfig: {
compact: true,
labelWidth: 100,
labelWidth: 60,
schemas: searchFormSchema,
autoSubmitOnEnter: true,
showAdvancedButton: true,
@ -90,12 +89,8 @@ @@ -90,12 +89,8 @@
width: 220,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: false
},
searchInfo: {
type: '0'
},
handleSearchInfoFn: () => clearSelectedRowKeys()
});
@ -111,10 +106,10 @@ @@ -111,10 +106,10 @@
openModal(true,{ _tag: 'add' });
}
/** 编辑按钮操作,行内编辑 */
function handleEdit(record?: Recordable) {
/** 查看按钮操作,行内查看 */
function handleViewEdit(record?: Recordable) {
record = record || { id: getSelectRowKeys() };
openModal(true, { _tag: 'edit', record });
openModal(true, { _tag: 'view', record });
}
/** 删除按钮操作,行内删除 */
@ -125,7 +120,7 @@ @@ -125,7 +120,7 @@
title: '警告',
content: `是否确认移除编号为${ids}的数据?`,
onOk: async () => {
await delPushPassList(ids);
await delPushBlacklist(ids);
createMessage.success('移除成功!');
handleRefreshTable();
}

71
src/views/common/push/pushBlacklist/passList.data.ts

@ -1,71 +0,0 @@ @@ -1,71 +0,0 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
/** 表格列配置 */
export const columns: BasicColumn[] = [
{
title: '发送方用户id',
dataIndex: 'fromPushId'
},
{
title: '对方用户id',
dataIndex: 'toPushId'
},
{
title: '创建人',
dataIndex: 'createByName'
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 200
}
];
/** 搜索表单配置 */
export const searchFormSchema: FormSchema[] = [
{
field: 'fromPushId',
label: '发送方用户id',
component: 'Input',
componentProps: {
placeholder: '请输入发送方用户id',
},
colProps: { span: 6 }
}
];
/** 表单配置 */
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'type',
label: '白名单类型',
component: 'Input',
defaultValue: '0',
show: false
},
{
field: 'fromPushId',
label: '发送方用户id',
component: 'Input',
required: true,
colProps: {
span: 24
}
},
{
field: 'toPushId',
label: '对方用户id',
component: 'Input',
required: true,
colProps: {
span: 24
}
},
];
Loading…
Cancel
Save