Browse Source

refactor: 重构推送类型模块

master
wangxiang 2 years ago
parent
commit
a77ca9db19
  1. 144
      src/views/common/push/pushCustomType/customType.data.ts
  2. 10
      src/views/common/push/pushType/TypeModal.vue
  3. 28
      src/views/common/push/pushType/index.vue
  4. 195
      src/views/common/push/pushType/type.data.ts

144
src/views/common/push/pushCustomType/customType.data.ts

@ -1,144 +0,0 @@ @@ -1,144 +0,0 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { listPushFile } from '/@/api/platform/common/controller/pushFile';
import {useUserStore} from '/@/store/modules/user';
const userStore = useUserStore();
const userInfoStore = userStore.getUserInfo;
/** 表格列配置 */
export const columns: BasicColumn[] = [
{
title: '类型名称',
dataIndex: 'name'
},
{
title: '是否播放声音',
dataIndex: 'playSound',
customRender: ({record}) => {
return ~~record?.playSound === 0 ? '是' : '否';
}
},
{
title: '是否震动',
dataIndex: 'playVibrate',
customRender: ({record}) => {
return ~~record?.playVibrate === 0 ? '是' : '否';
}
},
{
title: '是否闪光',
dataIndex: 'playLights',
customRender: ({record}) => {
return ~~record?.playLights === 0 ? '是' : '否';
}
},
{
title: '自定义播放文件名称',
dataIndex: 'customPlayFileName'
},
{
title: '创建人',
dataIndex: 'createByName'
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 200
}
];
/** 搜索表单配置 */
export const searchFormSchema: FormSchema[] = [
{
field: 'name',
label: '类型名称',
component: 'Input',
componentProps: {
placeholder: '请输入类型名称',
},
colProps: { span: 6 }
}
];
/** 表单配置 */
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'name',
label: '类型名称',
component: 'Input',
required: true,
colProps: {
span: 24
}
},
{
field: 'playSound',
label: '是否播放声音',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playVibrate',
label: '是否震动',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playLights',
label: '是否闪光',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'customPlayFileName',
label: '播放文件名称',
component: 'ApiSelect',
componentProps: {
api: listPushFile,
params: {
size: 99,
createById: userInfoStore.id
},
labelField: 'original',
valueField: 'original',
resultField: 'data'
},
},
];

10
src/views/common/push/pushCustomType/CustomTypeModal.vue → src/views/common/push/pushType/TypeModal.vue

@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
*/
import { ref, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './customType.data';
import { addPushCustomType, editPushCustomType, getPushCustomType } from '/@/api/platform/common/controller/pushCustomType';
import { formSchema } from './type.data';
import { addPushType, editPushType, getPushType } from '/@/api/platform/common/controller/pushType';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
/** 通用变量统一声明区域 */
@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
break;
case 'edit':
props.title = '编辑推送类型';
await setFieldsValue(await getPushCustomType(refId));
await setFieldsValue(await getPushType(refId));
break;
}
// :
@ -63,10 +63,10 @@ @@ -63,10 +63,10 @@
// tag
switch (unref(tag)) {
case 'add':
await addPushCustomType(formData);
await addPushType(formData);
break;
case 'edit':
await editPushCustomType(formData);
await editPushType(formData);
break;
}
//

28
src/views/common/push/pushCustomType/index.vue → src/views/common/push/pushType/index.vue

@ -20,9 +20,9 @@ @@ -20,9 +20,9 @@
@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',
@ -34,27 +34,22 @@ @@ -34,27 +34,22 @@
color: 'error',
onClick: handleDel.bind(null, record)
}]"
/>
/>
</template>
</template>
</BasicTable>
<!--弹出窗体区域-->
<CustomTypeModal @register="registerModal" @success="handleRefreshTable"/>
<TypeModal @register="registerModal" @success="handleRefreshTable"/>
</div>
</template>
<script lang="ts" setup>
/**
* 提供模板规范代码参考,请尽量保证编写代码风格跟模板规范代码一致
* 采用vben-动态表格表单封装组件编写,采用 setup 写法
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved.
* author entfrm开发团队-王翔
*/
import { reactive, toRaw } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { listPushCustomType, delPushCustomType } from '/@/api/platform/common/controller/pushCustomType';
import { listPushType, delPushType } from '/@/api/platform/common/controller/pushType';
import { useModal } from '/@/components/Modal';
import CustomTypeModal from './CustomTypeModal.vue';
import { columns, searchFormSchema } from './customType.data';
import TypeModal from './TypeModal.vue';
import { columns, searchFormSchema } from './type.data';
import { useMessage } from '/@/hooks/web/useMessage';
/** 类型规范统一声明定义区域 */
@ -74,7 +69,7 @@ @@ -74,7 +69,7 @@
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({
title: '推送类型列表',
api: listPushCustomType,
api: listPushType,
rowKey: 'id',
columns,
formConfig: {
@ -95,7 +90,6 @@ @@ -95,7 +90,6 @@
width: 220,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: false
},
handleSearchInfoFn: () => clearSelectedRowKeys()
@ -127,7 +121,7 @@ @@ -127,7 +121,7 @@
title: '警告',
content: `是否确认删除编号为${ids}的数据?`,
onOk: async () => {
await delPushCustomType(ids);
await delPushType(ids);
createMessage.success('删除成功!');
handleRefreshTable();
}

195
src/views/common/push/pushType/type.data.ts

@ -0,0 +1,195 @@ @@ -0,0 +1,195 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { listPushRingtone } from '/@/api/platform/common/controller/pushRingtone';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
/** 表格列配置 */
export const columns: BasicColumn[] = [
{
title: '类型名称',
dataIndex: 'name'
},
{
title: '播放声音',
dataIndex: 'playSound',
width: 80,
customRender: ({ record }) => {
const playSound = record?.playSound;
const enable = ~~playSound === 0;
const color = enable ? 'green' : 'red';
const text = enable ? '是' : '否';
return h(Tag, { color: color }, () => text);
}
},
{
title: '震动',
dataIndex: 'playVibrate',
width: 80,
customRender: ({ record }) => {
const playVibrate = record?.playVibrate;
const enable = ~~playVibrate === 0;
const color = enable ? 'green' : 'red';
const text = enable ? '是' : '否';
return h(Tag, { color: color }, () => text);
}
},
{
title: '闪光',
dataIndex: 'playLights',
width: 80,
customRender: ({ record }) => {
const playLights = record?.playLights;
const enable = ~~playLights === 0;
const color = enable ? 'green' : 'red';
const text = enable ? '是' : '否';
return h(Tag, { color: color }, () => text);
}
},
{
title: '文字转语音',
dataIndex: 'playToText',
width: 120,
customRender: ({ record }) => {
const playToText = record?.playToText;
const enable = ~~playToText === 1;
const color = enable ? 'green' : 'red';
const text = enable ? '是': '否';
return h(Tag, { color: color }, () => text);
}
},
{
title: '在线铃声',
dataIndex: 'onlineRingtone'
},
{
title: '创建人',
dataIndex: 'createByName'
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 200
}
];
/** 搜索表单配置 */
export const searchFormSchema: FormSchema[] = [
{
field: 'name',
label: '类型名称',
component: 'Input',
componentProps: {
placeholder: '请输入类型名称',
},
colProps: { span: 6 }
}
];
/** 表单配置 */
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'name',
label: '类型名称',
component: 'Input',
required: true,
colProps: {
span: 24
}
},
{
field: 'playSound',
label: '播放声音',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playVibrate',
label: '震动',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playLights',
label: '闪光',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '是', value: '0' },
{ label: '否', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'playToText',
label: '文字转语音',
component: 'RadioGroup',
required: true,
defaultValue: '0',
componentProps: {
options: [
{ label: '否', value: '0' },
{ label: '是', value: '1' }
]
},
colProps: {
span: 12
}
},
{
field: 'offlineRingtone',
label: '离线铃声',
component: 'Input',
componentProps: {
placeholder: '格式为R.raw.[sound]',
},
colProps: {
span: 12
}
},
{
field: 'onlineRingtone',
label: '在线铃声',
component: 'ApiSelect',
componentProps: {
api: listPushRingtone,
params: {
size: 99
},
labelField: 'name',
valueField: 'id',
resultField: 'data'
},
},
];
Loading…
Cancel
Save