2025-10-30 16:33:33 +08:00
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
|
import type { UploadRawFile } from 'element-plus';
|
|
|
|
|
|
|
|
|
|
|
|
import type { Reply } from './types';
|
|
|
|
|
|
|
|
|
|
|
|
import { computed, reactive, ref } from 'vue';
|
|
|
|
|
|
|
2025-11-03 11:18:45 +08:00
|
|
|
|
import { IconifyIcon } from '@vben/icons';
|
2025-10-30 16:33:33 +08:00
|
|
|
|
import { useAccessStore } from '@vben/stores';
|
|
|
|
|
|
|
2025-11-03 11:18:45 +08:00
|
|
|
|
import {
|
|
|
|
|
|
ElButton,
|
|
|
|
|
|
ElCol,
|
|
|
|
|
|
ElDialog,
|
|
|
|
|
|
ElMessage,
|
|
|
|
|
|
ElRow,
|
|
|
|
|
|
ElUpload,
|
|
|
|
|
|
} from 'element-plus';
|
2025-10-30 16:33:33 +08:00
|
|
|
|
|
2025-11-03 14:04:00 +08:00
|
|
|
|
import { UploadType, useBeforeUpload } from '#/utils/useUpload';
|
2025-11-03 11:18:45 +08:00
|
|
|
|
import WxMaterialSelect from '#/views/mp/modules/wx-material-select';
|
|
|
|
|
|
import WxVoicePlayer from '#/views/mp/modules/wx-voice-play';
|
2025-10-30 16:33:33 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置上传的请求头部
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
modelValue: Reply;
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
(e: 'update:modelValue', v: Reply): void;
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const message = ElMessage;
|
|
|
|
|
|
|
|
|
|
|
|
const UPLOAD_URL = `${import.meta.env.VITE_BASE_URL}/admin-api/mp/material/upload-temporary`;
|
|
|
|
|
|
const HEADERS = { Authorization: `Bearer ${useAccessStore().accessToken}` };
|
|
|
|
|
|
const reply = computed<Reply>({
|
|
|
|
|
|
get: () => props.modelValue,
|
|
|
|
|
|
set: (val: Reply) => emit('update:modelValue', val),
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const showDialog = ref(false);
|
|
|
|
|
|
const fileList = ref([]);
|
|
|
|
|
|
const uploadData = reactive({
|
|
|
|
|
|
accountId: reply.value.accountId,
|
|
|
|
|
|
type: 'voice',
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
introduction: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-03 11:18:45 +08:00
|
|
|
|
/** 语音上传前校验 */
|
|
|
|
|
|
function beforeVoiceUpload(rawFile: UploadRawFile) {
|
|
|
|
|
|
return useBeforeUpload(UploadType.Voice, 10)(rawFile);
|
|
|
|
|
|
}
|
2025-10-30 16:33:33 +08:00
|
|
|
|
|
2025-11-03 11:18:45 +08:00
|
|
|
|
/** 上传成功 */
|
|
|
|
|
|
function onUploadSuccess(res: any) {
|
2025-10-30 16:33:33 +08:00
|
|
|
|
if (res.code !== 0) {
|
|
|
|
|
|
message.error(`上传出错:${res.msg}`);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 清空上传时的各种数据
|
|
|
|
|
|
fileList.value = [];
|
|
|
|
|
|
uploadData.title = '';
|
|
|
|
|
|
uploadData.introduction = '';
|
|
|
|
|
|
|
|
|
|
|
|
// 上传好的文件,本质是个素材,所以可以进行选中
|
|
|
|
|
|
selectMaterial(res.data);
|
2025-11-03 11:18:45 +08:00
|
|
|
|
}
|
2025-10-30 16:33:33 +08:00
|
|
|
|
|
2025-11-03 11:18:45 +08:00
|
|
|
|
/** 删除语音 */
|
|
|
|
|
|
function onDelete() {
|
2025-10-30 16:33:33 +08:00
|
|
|
|
reply.value.mediaId = null;
|
|
|
|
|
|
reply.value.url = null;
|
|
|
|
|
|
reply.value.name = null;
|
2025-11-03 11:18:45 +08:00
|
|
|
|
}
|
2025-10-30 16:33:33 +08:00
|
|
|
|
|
2025-11-03 11:18:45 +08:00
|
|
|
|
/** 选择素材 */
|
|
|
|
|
|
function selectMaterial(item: Reply) {
|
2025-10-30 16:33:33 +08:00
|
|
|
|
showDialog.value = false;
|
|
|
|
|
|
|
|
|
|
|
|
// reply.value.type = ReplyType.Voice
|
|
|
|
|
|
reply.value.mediaId = item.mediaId;
|
|
|
|
|
|
reply.value.url = item.url;
|
|
|
|
|
|
reply.value.name = item.name;
|
2025-11-03 11:18:45 +08:00
|
|
|
|
}
|
2025-10-30 16:33:33 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div class="select-item2" v-if="reply.url">
|
|
|
|
|
|
<p class="item-name">{{ reply.name }}</p>
|
2025-11-03 11:18:45 +08:00
|
|
|
|
<ElRow class="ope-row" justify="center">
|
2025-10-30 16:33:33 +08:00
|
|
|
|
<WxVoicePlayer :url="reply.url" />
|
2025-11-03 11:18:45 +08:00
|
|
|
|
</ElRow>
|
|
|
|
|
|
<ElRow class="ope-row" justify="center">
|
|
|
|
|
|
<ElButton type="danger" circle @click="onDelete">
|
|
|
|
|
|
<IconifyIcon icon="ep:delete" />
|
|
|
|
|
|
</ElButton>
|
|
|
|
|
|
</ElRow>
|
2025-10-30 16:33:33 +08:00
|
|
|
|
</div>
|
2025-11-03 11:18:45 +08:00
|
|
|
|
<ElRow v-else style="text-align: center">
|
2025-10-30 16:33:33 +08:00
|
|
|
|
<!-- 选择素材 -->
|
2025-11-03 11:18:45 +08:00
|
|
|
|
<ElCol :span="12" class="col-select">
|
|
|
|
|
|
<ElButton type="success" @click="showDialog = true">
|
|
|
|
|
|
素材库选择<IconifyIcon icon="ep:circle-check" />
|
|
|
|
|
|
</ElButton>
|
|
|
|
|
|
<ElDialog
|
2025-10-30 16:33:33 +08:00
|
|
|
|
title="选择语音"
|
|
|
|
|
|
v-model="showDialog"
|
|
|
|
|
|
width="90%"
|
|
|
|
|
|
append-to-body
|
|
|
|
|
|
destroy-on-close
|
|
|
|
|
|
>
|
|
|
|
|
|
<WxMaterialSelect
|
|
|
|
|
|
type="voice"
|
|
|
|
|
|
:account-id="reply.accountId"
|
|
|
|
|
|
@select-material="selectMaterial"
|
|
|
|
|
|
/>
|
2025-11-03 11:18:45 +08:00
|
|
|
|
</ElDialog>
|
|
|
|
|
|
</ElCol>
|
2025-10-30 16:33:33 +08:00
|
|
|
|
<!-- 文件上传 -->
|
2025-11-03 11:18:45 +08:00
|
|
|
|
<ElCol :span="12" class="col-add">
|
|
|
|
|
|
<ElUpload
|
2025-10-30 16:33:33 +08:00
|
|
|
|
:action="UPLOAD_URL"
|
|
|
|
|
|
:headers="HEADERS"
|
|
|
|
|
|
multiple
|
|
|
|
|
|
:limit="1"
|
|
|
|
|
|
:file-list="fileList"
|
|
|
|
|
|
:data="uploadData"
|
|
|
|
|
|
:before-upload="beforeVoiceUpload"
|
|
|
|
|
|
:on-success="onUploadSuccess"
|
|
|
|
|
|
>
|
2025-11-03 11:18:45 +08:00
|
|
|
|
<ElButton type="primary">点击上传</ElButton>
|
2025-10-30 16:33:33 +08:00
|
|
|
|
<template #tip>
|
|
|
|
|
|
<div class="el-upload__tip">
|
|
|
|
|
|
格式支持 mp3/wma/wav/amr,文件大小不超过 2M,播放长度不超过 60s
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
2025-11-03 11:18:45 +08:00
|
|
|
|
</ElUpload>
|
|
|
|
|
|
</ElCol>
|
|
|
|
|
|
</ElRow>
|
2025-10-30 16:33:33 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.select-item2 {
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
margin: 0 auto 10px;
|
|
|
|
|
|
border: 1px solid #eaeaea;
|
|
|
|
|
|
|
|
|
|
|
|
.item-name {
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
|
|
|
|
|
|
.ope-row {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
padding-top: 10px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.col-select {
|
|
|
|
|
|
width: 49.5%;
|
|
|
|
|
|
height: 160px;
|
|
|
|
|
|
padding: 50px 0;
|
|
|
|
|
|
border: 1px solid rgb(234 234 234);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.col-add {
|
|
|
|
|
|
float: right;
|
|
|
|
|
|
width: 49.5%;
|
|
|
|
|
|
height: 160px;
|
|
|
|
|
|
padding: 50px 0;
|
|
|
|
|
|
border: 1px solid rgb(234 234 234);
|
|
|
|
|
|
|
|
|
|
|
|
.el-upload__tip {
|
|
|
|
|
|
line-height: 18px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|