update V3.0.0

This commit is contained in:
hupeng committed 2024-06-02 10:52:34 +08:00
1 parent 3b4e0ca614
commit b16dd30f0b
1227 files changed
+337804 -4

No files matched your search

@@ -0,0 +1,83 @@
<template>
<div class="waterfall" v-loading="props.loading">
<div class="waterfall-item" v-for="item in props.list" :key="item.id">
<a target="_blank" :href="item.url">
<img class="material-img" :src="item.url" />
<div class="item-name">{{ item.name }}</div>
</a>
<el-row justify="center">
<el-button
type="danger"
circle
@click="emit('delete', item.id)"
v-hasPermi="['mp:material:delete']"
>
<Icon icon="ep:delete" />
</el-button>
</el-row>
</div>
</div>
</template>
<script lang="ts" setup>
const props = defineProps<{
list: any[]
loading: boolean
}>()
const emit = defineEmits<{
(e: 'delete', v: number)
}>()
</script>
<style lang="scss" scoped>
@media (width >= 992px) and (width <= 1300px) {
.waterfall {
column-count: 3;
}
p {
color: red;
}
}
@media (width >= 768px) and (width <= 991px) {
.waterfall {
column-count: 2;
}
p {
color: orange;
}
}
@media (width <= 767px) {
.waterfall {
column-count: 1;
}
}
.waterfall {
width: 100%;
column-gap: 10px;
column-count: 5;
margin-top: 10px;
/* 芋道源码:增加 10px,避免顶着上面 */
}
.waterfall-item {
padding: 10px;
margin-bottom: 10px;
break-inside: avoid;
border: 1px solid #eaeaea;
}
.material-img {
width: 100%;
}
p {
line-height: 30px;
}
</style>
@@ -0,0 +1,77 @@
<template>
<el-upload
:action="UPLOAD_URL"
:headers="HEADERS"
multiple
:limit="1"
:file-list="fileList"
:data="uploadData"
:on-error="onUploadError"
:before-upload="onBeforeUpload"
:on-success="onUploadSuccess"
>
<el-button type="primary" plain> 点击上传 </el-button>
<template #tip>
<span class="el-upload__tip" style="margin-left: 5px">
<slot></slot>
</span>
</template>
</el-upload>
</template>
<script lang="ts" setup>
import type { UploadProps, UploadUserFile } from 'element-plus'
import {
HEADERS,
UPLOAD_URL,
UploadData,
UploadType,
beforeImageUpload,
beforeVoiceUpload
} from './upload'
const message = useMessage()
const props = defineProps<{ type: UploadType }>()
const accountId = inject<number>('accountId')
const fileList = ref<UploadUserFile[]>([])
const emit = defineEmits<{
(e: 'uploaded', v: void)
}>()
const uploadData: UploadData = reactive({
type: UploadType.Image,
title: '',
introduction: '',
accountId: accountId!
})
/** 上传前检查 */
const onBeforeUpload = props.type === UploadType.Image ? beforeImageUpload : beforeVoiceUpload
/** 上传成功处理 */
const onUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
if (res.code !== 0) {
message.alertError('上传出错:' + res.msg)
return false
}
// 清空上传时的各种数据
fileList.value = []
uploadData.title = ''
uploadData.introduction = ''
message.notifySuccess('上传成功')
emit('uploaded')
}
/** 上传失败处理 */
const onUploadError = (err: Error) => message.error('上传失败: ' + err.message)
</script>
<style lang="scss" scoped>
.el-upload__tip {
margin-left: 5px;
}
</style>
@@ -0,0 +1,129 @@
<template>
<el-dialog title="新建视频" v-model="showDialog" width="600px">
<el-upload
:action="UPLOAD_URL"
:headers="HEADERS"
multiple
:limit="1"
:file-list="fileList"
:data="uploadData"
:before-upload="beforeVideoUpload"
:on-error="onUploadError"
:on-success="onUploadSuccess"
ref="uploadVideoRef"
:auto-upload="false"
class="mb-5"
>
<template #trigger>
<el-button type="primary" plain>选择视频</el-button>
</template>
<template #tip>
<span class="el-upload__tip" style="margin-left: 10px"
>格式支持 MP4,文件大小不超过 10MB</span
>
</template>
</el-upload>
<el-divider />
<el-form :model="uploadData" :rules="uploadRules" ref="uploadFormRef">
<el-form-item label="标题" prop="title">
<el-input
v-model="uploadData.title"
placeholder="标题将展示在相关播放页面,建议填写清晰、准确、生动的标题"
/>
</el-form-item>
<el-form-item label="描述" prop="introduction">
<el-input
:rows="3"
type="textarea"
v-model="uploadData.introduction"
placeholder="介绍语将展示在相关播放页面,建议填写简洁明确、有信息量的内容"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="showDialog = false">取 消</el-button>
<el-button type="primary" @click="submitVideo">提 交</el-button>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import type {
FormInstance,
FormRules,
UploadInstance,
UploadProps,
UploadUserFile
} from 'element-plus'
import { HEADERS, UploadData, UPLOAD_URL, UploadType, beforeVideoUpload } from './upload'
const message = useMessage()
const accountId = inject<number>('accountId')
const uploadRules: FormRules = {
title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
introduction: [{ required: true, message: '请输入描述', trigger: 'blur' }]
}
const props = defineProps({
modelValue: {
type: Boolean,
default: false
}
})
const emit = defineEmits<{
(e: 'update:modelValue', v: boolean)
(e: 'uploaded', v: void)
}>()
const showDialog = computed<boolean>({
get() {
return props.modelValue
},
set(val) {
emit('update:modelValue', val)
}
})
const fileList = ref<UploadUserFile[]>([])
const uploadData: UploadData = reactive({
type: UploadType.Video,
title: '',
introduction: '',
accountId: accountId!
})
const uploadFormRef = ref<FormInstance | null>(null)
const uploadVideoRef = ref<UploadInstance | null>(null)
const submitVideo = () => {
uploadFormRef.value?.validate((valid) => {
if (!valid) {
return false
}
uploadVideoRef.value?.submit()
})
}
/** 上传成功处理 */
const onUploadSuccess: UploadProps['onSuccess'] = (res: any) => {
if (res.code !== 0) {
message.error('上传出错:' + res.msg)
return false
}
// 清空上传时的各种数据
fileList.value = []
uploadData.title = ''
uploadData.introduction = ''
showDialog.value = false
message.notifySuccess('上传成功')
emit('uploaded')
}
/** 上传失败处理 */
const onUploadError = (err: Error) => message.error(`上传失败: ${err.message}`)
</script>
@@ -0,0 +1,59 @@
<template>
<el-table :data="props.list" stripe border v-loading="props.loading" style="margin-top: 10px">
<el-table-column label="编号" align="center" prop="mediaId" />
<el-table-column label="文件名" align="center" prop="name" />
<el-table-column label="标题" align="center" prop="title" />
<el-table-column label="介绍" align="center" prop="introduction" />
<el-table-column label="视频" align="center">
<template #default="scope">
<WxVideoPlayer v-if="scope.row.url" :url="scope.row.url" />
</template>
</el-table-column>
<el-table-column
label="上传时间"
align="center"
:formatter="dateFormatter"
prop="createTime"
width="180"
>
<template #default="scope">
<span>{{ scope.row.createTime }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right">
<template #default="scope">
<el-button type="primary" link @click="handleDownload(scope.row.url)">
<Icon icon="ep:download" />下载
</el-button>
<el-button
type="primary"
link
@click="emit('delete', scope.row.id)"
v-hasPermi="['mp:material:delete']"
>
<Icon icon="ep:delete" />删除
</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script lang="ts" setup>
import WxVideoPlayer from '@/views/mp/components/wx-video-play'
import { dateFormatter } from '@/utils/formatTime'
const props = defineProps<{
list: any[]
loading: boolean
}>()
const emit = defineEmits<{
(e: 'delete', v: number)
(e: 'download', v: string)
}>()
// 下载文件
const handleDownload = (url: string) => {
window.open(url, '_blank')
}
</script>
@@ -0,0 +1,51 @@
<template>
<el-table :data="props.list" stripe border v-loading="props.loading" style="margin-top: 10px">
<el-table-column label="编号" align="center" prop="mediaId" />
<el-table-column label="文件名" align="center" prop="name" />
<el-table-column label="语音" align="center">
<template #default="scope">
<WxVoicePlayer v-if="scope.row.url" :url="scope.row.url" />
</template>
</el-table-column>
<el-table-column
label="上传时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180"
>
<template #default="scope">
<span>{{ scope.row.createTime }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button type="primary" link @click="emit('delete', scope.row.id)">
<Icon icon="ep:download" />下载
</el-button>
<el-button
type="primary"
link
@click="emit('delete', scope.row.id)"
v-hasPermi="['mp:material:delete']"
>
<Icon icon="ep:delete" />删除
</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script lang="ts" setup>
import WxVoicePlayer from '@/views/mp/components/wx-voice-play'
import { dateFormatter } from '@/utils/formatTime'
const props = defineProps<{
list: any[]
loading: boolean
}>()
const emit = defineEmits<{
(e: 'delete', v: number)
}>()
</script>
@@ -0,0 +1,32 @@
import type { UploadProps, UploadRawFile } from 'element-plus'
import { getAccessToken } from '@/utils/auth'
import { UploadType, useBeforeUpload } from '@/views/mp/hooks/useUpload'
const HEADERS = { Authorization: 'Bearer ' + getAccessToken() } // 请求头
const UPLOAD_URL = import.meta.env.VITE_BASE_URL + '/admin-api/mp/material/upload-permanent' // 上传地址
interface UploadData {
type: UploadType
title: string
introduction: string
accountId: number
}
const beforeImageUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) =>
useBeforeUpload(UploadType.Image, 2)(rawFile)
const beforeVoiceUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) =>
useBeforeUpload(UploadType.Voice, 2)(rawFile)
const beforeVideoUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) =>
useBeforeUpload(UploadType.Video, 10)(rawFile)
export {
HEADERS,
UPLOAD_URL,
UploadType,
UploadData,
beforeImageUpload,
beforeVoiceUpload,
beforeVideoUpload
}
@@ -0,0 +1,158 @@
<template>
<!-- 搜索工作栏 -->
<ContentWrap>
<el-form class="-mb-15px" :inline="true" label-width="68px">
<el-form-item label="公众号" prop="accountId">
<WxAccountSelect @change="onAccountChanged" />
</el-form-item>
</el-form>
</ContentWrap>
<ContentWrap>
<el-tabs v-model="type" @tab-change="onTabChange">
<!-- tab 1:图片 -->
<el-tab-pane :name="UploadType.Image">
<template #label>
<el-row align="middle"> <Icon icon="ep:picture" />图片 </el-row>
</template>
<UploadFile
v-hasPermi="['mp:material:upload-permanent']"
:type="UploadType.Image"
@uploaded="getList"
>
支持 bmp/png/jpeg/jpg/gif 格式,大小不超过 2M
</UploadFile>
<!-- 列表 -->
<ImageTable :loading="loading" :list="list" @delete="handleDelete" />
<!-- 分页组件 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</el-tab-pane>
<!-- tab 2:语音 -->
<el-tab-pane :name="UploadType.Voice">
<template #label>
<el-row align="middle"> <Icon icon="ep:microphone" />语音 </el-row>
</template>
<UploadFile
v-hasPermi="['mp:material:upload-permanent']"
:type="UploadType.Voice"
@uploaded="getList"
>
格式支持 mp3/wma/wav/amr,文件大小不超过 2M,播放长度不超过 60s
</UploadFile>
<!-- 列表 -->
<VoiceTable :list="list" :loading="loading" @delete="handleDelete" />
<!-- 分页组件 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</el-tab-pane>
<!-- tab 3:视频 -->
<el-tab-pane :name="UploadType.Video">
<template #label>
<el-row align="middle"> <Icon icon="ep:video-play" /> 视频 </el-row>
</template>
<el-button
v-hasPermi="['mp:material:upload-permanent']"
type="primary"
plain
@click="showCreateVideo = true"
>新建视频</el-button
>
<!-- 新建视频的弹窗 -->
<UploadVideo v-model="showCreateVideo" />
<!-- 列表 -->
<VideoTable :list="list" :loading="loading" @delete="handleDelete" />
<!-- 分页组件 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</el-tab-pane>
</el-tabs>
</ContentWrap>
</template>
<script lang="ts" setup name="MpMaterial">
import WxAccountSelect from '@/views/mp/components/wx-account-select'
import ImageTable from './components/ImageTable.vue'
import VoiceTable from './components/VoiceTable.vue'
import VideoTable from './components/VideoTable.vue'
import UploadFile from './components/UploadFile.vue'
import UploadVideo from './components/UploadVideo.vue'
import { UploadType } from './components/upload'
import * as MpMaterialApi from '@/api/mp/material'
const message = useMessage() // 消息
const type = ref<UploadType>(UploadType.Image) // 素材类型
const loading = ref(false) // 遮罩层
const list = ref<any[]>([]) // 总条数
const total = ref(0) // 数据列表
const accountId = ref(-1)
provide('accountId', accountId)
// 查询参数
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: accountId,
permanent: true
})
const showCreateVideo = ref(false) // 是否新建视频的弹窗
/** 侦听公众号变化 **/
const onAccountChanged = (id: number) => {
accountId.value = id
queryParams.accountId = id
queryParams.pageNo = 1
getList()
}
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await MpMaterialApi.getMaterialPage({
...queryParams,
type: type.value
})
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 处理 table 切换 */
const onTabChange = () => {
// 提前情况数据,避免 tab 切换后显示垃圾数据
list.value = []
total.value = 0
// 从第一页开始查询
handleQuery()
}
/** 处理删除操作 */
const handleDelete = async (id: number) => {
await message.confirm('此操作将永久删除该文件, 是否继续?')
await MpMaterialApi.deletePermanentMaterial(id)
message.alertSuccess('删除成功')
}
</script>