资源管理页面微调
This commit is contained in:
@@ -9,6 +9,10 @@ export const addResourceManage = (params: FormData) => {
|
|||||||
return http.upload('/resourceManage/add', params)
|
return http.upload('/resourceManage/add', params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updateResourceManage = (params: ResourceManage.ReqUpdateResourceManage) => {
|
||||||
|
return http.post('/resourceManage/update', params)
|
||||||
|
}
|
||||||
|
|
||||||
export const getResourceManagePlayUrl = (id: string) => {
|
export const getResourceManagePlayUrl = (id: string) => {
|
||||||
return http.get<ResourceManage.PlayVO>(`/resourceManage/play?id=${id}`)
|
return http.get<ResourceManage.PlayVO>(`/resourceManage/play?id=${id}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ export namespace ResourceManage {
|
|||||||
|
|
||||||
export interface ResResourceManagePage extends ResPage<ResResourceManage> {}
|
export interface ResResourceManagePage extends ResPage<ResResourceManage> {}
|
||||||
|
|
||||||
|
export interface ReqUpdateResourceManage {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
remark: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface PlayVO {
|
export interface PlayVO {
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="dialogVisible"
|
v-model="dialogVisible"
|
||||||
title="新增资源"
|
:title="dialogTitle"
|
||||||
width="520px"
|
width="520px"
|
||||||
:destroy-on-close="true"
|
:destroy-on-close="true"
|
||||||
:close-on-click-modal="!submitting"
|
:close-on-click-modal="!submitting"
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<el-form-item label="备注" prop="remark">
|
<el-form-item label="备注" prop="remark">
|
||||||
<el-input v-model="form.remark" maxlength="250" placeholder="请输入备注" type="textarea" :rows="3" />
|
<el-input v-model="form.remark" maxlength="250" placeholder="请输入备注" type="textarea" :rows="3" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="文件" prop="file">
|
<el-form-item v-if="mode === 'add'" label="文件" prop="file">
|
||||||
<el-upload
|
<el-upload
|
||||||
ref="uploadRef"
|
ref="uploadRef"
|
||||||
action="#"
|
action="#"
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref } from 'vue'
|
import { computed, reactive, ref } from 'vue'
|
||||||
import {
|
import {
|
||||||
ElMessage,
|
ElMessage,
|
||||||
genFileId,
|
genFileId,
|
||||||
@@ -53,7 +53,8 @@ import {
|
|||||||
type UploadRawFile
|
type UploadRawFile
|
||||||
} from 'element-plus'
|
} from 'element-plus'
|
||||||
import { Upload } from '@element-plus/icons-vue'
|
import { Upload } from '@element-plus/icons-vue'
|
||||||
import { addResourceManage } from '@/api/resourceManage'
|
import { addResourceManage, updateResourceManage } from '@/api/resourceManage'
|
||||||
|
import type { ResourceManage } from '@/api/resourceManage/interface'
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 250 * 1024 * 1024
|
const MAX_FILE_SIZE = 250 * 1024 * 1024
|
||||||
|
|
||||||
@@ -63,20 +64,25 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
|
const mode = ref<'add' | 'edit'>('add')
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const uploadRef = ref<UploadInstance>()
|
const uploadRef = ref<UploadInstance>()
|
||||||
const fileList = ref<UploadFile[]>([])
|
const fileList = ref<UploadFile[]>([])
|
||||||
|
|
||||||
const form = reactive<{
|
const form = reactive<{
|
||||||
|
id: string
|
||||||
name: string
|
name: string
|
||||||
remark: string
|
remark: string
|
||||||
file: File | null
|
file: File | null
|
||||||
}>({
|
}>({
|
||||||
|
id: '',
|
||||||
name: '',
|
name: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
file: null
|
file: null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const dialogTitle = computed(() => (mode.value === 'edit' ? '编辑资源' : '新增资源'))
|
||||||
|
|
||||||
const validateFile = (_rule: unknown, value: File | null, callback: (error?: Error) => void) => {
|
const validateFile = (_rule: unknown, value: File | null, callback: (error?: Error) => void) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
callback(new Error('请选择 MP4 文件'))
|
callback(new Error('请选择 MP4 文件'))
|
||||||
@@ -91,12 +97,15 @@ const rules = reactive<FormRules>({
|
|||||||
file: [{ validator: validateFile, trigger: 'change' }]
|
file: [{ validator: validateFile, trigger: 'change' }]
|
||||||
})
|
})
|
||||||
|
|
||||||
const open = () => {
|
const open = (type: 'add' | 'edit' = 'add', row?: ResourceManage.ResResourceManage) => {
|
||||||
form.name = ''
|
mode.value = type
|
||||||
form.remark = ''
|
form.id = row?.id ?? ''
|
||||||
|
form.name = row?.name ?? ''
|
||||||
|
form.remark = row?.remark ?? ''
|
||||||
form.file = null
|
form.file = null
|
||||||
fileList.value = []
|
fileList.value = []
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
|
formRef.value?.clearValidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
const isValidMp4 = (file: File) => {
|
const isValidMp4 = (file: File) => {
|
||||||
@@ -139,17 +148,27 @@ const handleExceed: UploadProps['onExceed'] = files => {
|
|||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!formRef.value) return
|
if (!formRef.value) return
|
||||||
await formRef.value.validate()
|
await formRef.value.validate()
|
||||||
if (!form.file) return
|
|
||||||
|
|
||||||
const formData = new FormData()
|
const name = form.name.trim()
|
||||||
formData.append('name', form.name.trim())
|
const remark = form.remark.trim()
|
||||||
formData.append('remark', form.remark.trim())
|
|
||||||
formData.append('file', form.file)
|
|
||||||
|
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
try {
|
try {
|
||||||
await addResourceManage(formData)
|
if (mode.value === 'edit') {
|
||||||
ElMessage.success('新增成功')
|
await updateResourceManage({
|
||||||
|
id: form.id,
|
||||||
|
name,
|
||||||
|
remark
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (!form.file) return
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('name', name)
|
||||||
|
formData.append('remark', remark)
|
||||||
|
formData.append('file', form.file)
|
||||||
|
await addResourceManage(formData)
|
||||||
|
}
|
||||||
|
ElMessage.success(mode.value === 'edit' ? '编辑成功' : '新增成功')
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
props.refreshTable?.()
|
props.refreshTable?.()
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -16,6 +16,15 @@
|
|||||||
>
|
>
|
||||||
播放
|
播放
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-auth.resourceManage="'edit'"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
:icon="EditPen"
|
||||||
|
@click="openEditDialog(scope.row)"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</ProTable>
|
</ProTable>
|
||||||
</div>
|
</div>
|
||||||
@@ -25,7 +34,7 @@
|
|||||||
|
|
||||||
<script setup lang="tsx" name="resourceManage">
|
<script setup lang="tsx" name="resourceManage">
|
||||||
import { reactive, ref } from 'vue'
|
import { reactive, ref } from 'vue'
|
||||||
import { CirclePlus, VideoPlay } from '@element-plus/icons-vue'
|
import { CirclePlus, EditPen, VideoPlay } from '@element-plus/icons-vue'
|
||||||
import ProTable from '@/components/ProTable/index.vue'
|
import ProTable from '@/components/ProTable/index.vue'
|
||||||
import type { ColumnProps, ProTableInstance } from '@/components/ProTable/interface'
|
import type { ColumnProps, ProTableInstance } from '@/components/ProTable/interface'
|
||||||
import type { ResourceManage } from '@/api/resourceManage/interface'
|
import type { ResourceManage } from '@/api/resourceManage/interface'
|
||||||
@@ -97,7 +106,7 @@ const columns = reactive<ColumnProps<ResourceManage.ResResourceManage>[]>([
|
|||||||
{
|
{
|
||||||
prop: 'relativePath',
|
prop: 'relativePath',
|
||||||
label: '路径',
|
label: '路径',
|
||||||
minWidth: 260,
|
width: 200,
|
||||||
showOverflowTooltip: true
|
showOverflowTooltip: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -112,11 +121,15 @@ const columns = reactive<ColumnProps<ResourceManage.ResResourceManage>[]>([
|
|||||||
width: 180,
|
width: 180,
|
||||||
render: scope => formatDateTime(scope.row.createTime)
|
render: scope => formatDateTime(scope.row.createTime)
|
||||||
},
|
},
|
||||||
{ prop: 'operation', label: '操作', fixed: 'right', width: 100 }
|
{ prop: 'operation', label: '操作', fixed: 'right', width: 180 }
|
||||||
])
|
])
|
||||||
|
|
||||||
const openAddDialog = () => {
|
const openAddDialog = () => {
|
||||||
resourceManagePopup.value?.open()
|
resourceManagePopup.value?.open('add')
|
||||||
|
}
|
||||||
|
|
||||||
|
const openEditDialog = (row: ResourceManage.ResResourceManage) => {
|
||||||
|
resourceManagePopup.value?.open('edit', row)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePlay = async (row: ResourceManage.ResResourceManage) => {
|
const handlePlay = async (row: ResourceManage.ResResourceManage) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user