Browse Source

refactor: 铃声模块

master
wangxiang 2 years ago
parent
commit
dbb946267a
  1. 2
      src/api/platform/common/entity/pushRingtone.ts
  2. 76
      src/views/common/push/pushRingtone/RingtoneModal.vue
  3. 56
      src/views/common/push/pushRingtone/file.data.ts
  4. 80
      src/views/common/push/pushRingtone/index.vue
  5. 94
      src/views/common/push/pushRingtone/ringtone.data.ts

2
src/api/platform/common/entity/pushRingtone.ts

@ -6,7 +6,7 @@ export type PushRingtoneParams = Page & PushRingtone; @@ -6,7 +6,7 @@ export type PushRingtoneParams = Page & PushRingtone;
export interface PushRingtone extends CommonEntity {
id: string;
name: string;
ringtone: string;
ringtone: string | string[];
[key:string]: any;
}

76
src/views/common/push/pushRingtone/RingtoneModal.vue

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
<template>
<BasicModal
v-bind="$attrs"
width="720px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm"/>
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './ringtone.data';
import { addPushRingtone, editPushRingtone, getPushRingtone } from '/@/api/platform/common/controller/pushRingtone';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
/** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>('');
/** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']);
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 };
// tag
switch (unref(tag)) {
case 'add':
props.title = '新增铃声';
break;
case 'edit':
props.title = '编辑铃声';
let ringtone = await getPushRingtone(refId);
ringtone.ringtone = String(ringtone.ringtone).split(',');
await setFieldsValue(await getPushRingtone(refId));
break;
}
// :
setModalProps(props);
});
/** 处理弹出框提交 */
async function handleSubmit() {
try {
//
const formData = await validate();
formData.ringtone = Array(formData.ringtone).join(',');
//
setModalProps({ confirmLoading: true });
// tag
switch (unref(tag)) {
case 'add':
await addPushRingtone(formData);
break;
case 'edit':
await editPushRingtone(formData);
break;
}
//
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

56
src/views/common/push/pushRingtone/file.data.ts

@ -1,56 +0,0 @@ @@ -1,56 +0,0 @@
/**
* @program: kicc-ui
* @description:
* @author: entfrm开发团队-
* @create: 2022/4/21
*/
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getFileSize } from '/@/utils/file/download';
/** 表格列配置 */
export const columns: BasicColumn[] = [
{
title: '源文件名称',
dataIndex: 'original'
},
{
title: '空间名称',
dataIndex: 'bucketName'
},
{
title: '文件名称',
dataIndex: 'fileName'
},
{
title: '文件类型',
dataIndex: 'type'
},
{
title: '文件大小',
dataIndex: 'fileSize',
customRender: ({ record }) => getFileSize(record.fileSize)
},
{
title: '上传人',
dataIndex: 'createByName'
},
{
title: '创建时间',
dataIndex: 'createTime'
}
];
/** 搜索表单配置 */
export const searchFormSchema: FormSchema[] = [
{
field: 'fileName',
label: '文件名称',
component: 'Input',
componentProps: {
placeholder: '请输入文件名称',
},
colProps: { span: 6 }
}
];

80
src/views/common/push/pushRingtone/index.vue

@ -5,44 +5,41 @@ @@ -5,44 +5,41 @@
@selection-change="handleSelectionChange"
>
<template #toolbar>
<BasicUpload
v-model:value="state.fileList"
v-auth="['file_upload']"
:maxSize="20"
:maxNumber="10"
:showPreviewNumber="false"
:emptyHidePreview="true"
:api="commonUpload"
:accept="['audio/*']"
multiple
@change="handleUploadSave"
/>
<a-button
v-auth="['file_del']"
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>
>删除铃声</a-button>
</template>
<template #action="{ record }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction
:actions="[
{
label: '文件下载',
icon: 'fa6-regular:circle-down',
auth: ['file_download'],
onClick: handleFileDownLoad.bind(null, record)
label: '编辑',
icon: 'fa6-regular:pen-to-square',
onClick: handleEdit.bind(null, record)
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
auth: ['file_del'],
onClick: handleDel.bind(null, record)
}]"
/>
</template>
</template>
</BasicTable>
<RingtoneModal @register="registerModal" @success="handleRefreshTable"/>
</div>
</template>
@ -55,20 +52,16 @@ @@ -55,20 +52,16 @@
*/
import { reactive, toRaw } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { getFile } from '/@/api/platform/system/controller/file';
import { columns, searchFormSchema } from './file.data';
import { listPushRingtone, delPushRingtone } from '/@/api/platform/common/controller/pushRingtone';
import { useModal } from '/@/components/Modal';
import RingtoneModal from './RingtoneModal.vue';
import { columns, searchFormSchema } from './ringtone.data';
import { useMessage } from '/@/hooks/web/useMessage';
import { commonUpload, delPushFile, listPushFile } from '/@/api/platform/common/controller/pushFile';
import { BasicUpload } from '/@/components/Upload';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();
const userInfoStore = userStore.getUserInfo;
/** 类型规范统一声明定义区域 */
interface TableState {
single: boolean;
multiple: boolean;
fileList: Recordable[];
}
/** 通用变量统一声明区域 */
@ -76,14 +69,13 @@ @@ -76,14 +69,13 @@
//
single: true,
//
multiple: true,
//
fileList: []
multiple: true
});
const { createConfirm, createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({
title: '推送文件列表',
api: listPushFile,
title: '在线铃声列表',
api: listPushRingtone,
rowKey: 'id',
columns,
formConfig: {
@ -104,12 +96,8 @@ @@ -104,12 +96,8 @@
width: 220,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: false
},
searchInfo: {
createById: userInfoStore.id
},
handleSearchInfoFn: () => clearSelectedRowKeys()
});
@ -120,15 +108,15 @@ @@ -120,15 +108,15 @@
state.multiple = !rowSelection.length;
}
/** 处理上传成功保存回调 */
function handleUploadSave(fileList: string[]) {
state.fileList = [];
handleRefreshTable();
/** 新增按钮操作,行内新增与工具栏局域新增通用 */
function handleAdd() {
openModal(true,{ _tag: 'add' });
}
/** 处理行内文件下载 */
function handleFileDownLoad(record?: Recordable) {
getFile(record?.bucketName, record?.fileName).then(() => createMessage.success(`${record?.fileName}文件下载成功!`));
/** 编辑按钮操作,行内编辑 */
function handleEdit(record?: Recordable) {
record = record || { id: getSelectRowKeys() };
openModal(true, { _tag: 'edit', record });
}
/** 删除按钮操作,行内删除 */
@ -137,9 +125,9 @@ @@ -137,9 +125,9 @@
createConfirm({
iconType: 'warning',
title: '警告',
content: `是否确认删除文件编号为${ids}文件吗?`,
content: `是否确认删除编号为${ids}的数据?`,
onOk: async () => {
await delPushFile(ids);
await delPushRingtone(ids);
createMessage.success('删除成功!');
handleRefreshTable();
}

94
src/views/common/push/pushRingtone/ringtone.data.ts

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { commonUpload } from '/@/api/platform/core/controller/upload';
/** 表格列配置 */
export const columns: BasicColumn[] = [
{
title: '铃声名称',
dataIndex: 'name'
},
{
title: '铃声地址',
dataIndex: 'ringtone'
},
{
title: '创建人',
dataIndex: 'createByName'
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 200
},
{
title: '备注',
dataIndex: 'remarks',
width: 200,
customRender: ({record}) => {
return record.remarks || h(Tag, { color: 'red' }, () => '暂无数据');
}
}
];
/** 搜索表单配置 */
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: 12
}
},
{
field: 'ringtone',
label: '上传铃声',
component: 'Upload',
required: true,
componentProps: {
multiple: false,
maxSize: 20,
maxNumber: 1,
showUploadSaveBtn: true,
showPreviewNumber: true,
emptyHidePreview: true,
api: commonUpload,
accept: ['audio/*']
}
},
{
label: '备注',
field: 'remarks',
component: 'InputTextArea',
componentProps: {
rows: 6
},
colProps: {
span: 24
}
}
];
Loading…
Cancel
Save