dbsd_kczx/src/views/zy/zyInfoStudent/components/ZyInfoStudentPiyueForm.vue

414 lines
12 KiB
Vue
Raw Normal View History

2024-08-29 13:33:02 +08:00
<template>
<a-spin :spinning="confirmLoading">
<a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-row>
2025-01-06 08:54:25 +08:00
<a-col :span="12">
<div v-if="showType=='1'">
<iframe id="pdfPreviewIframe" :src="ylurl" frameborder="0" width="100%" height="550px" scrolling="auto"></iframe>
2024-10-08 08:29:29 +08:00
</div>
2025-01-06 08:54:25 +08:00
<div v-else-if="showType=='2'">
2024-10-08 20:49:49 +08:00
<div style="padding: 10px 20px;">
2024-10-11 17:12:06 +08:00
<a-button type="primary" @click="rotateImage">顺时针旋转</a-button>
<a-button type="primary" @click="rotateImage2" style="margin-left: 20px;">逆时针旋转</a-button>
2024-10-08 20:49:49 +08:00
</div>
2025-01-06 08:54:25 +08:00
2024-10-08 20:49:49 +08:00
<div class="image-container">
2025-01-06 08:54:25 +08:00
<img :src="ylurl" :style="{ transform: 'rotate(' + rotationAngle + 'deg)' }" class="rotated-image"/>
2024-10-08 20:49:49 +08:00
</div>
2024-10-08 08:29:29 +08:00
</div>
2025-01-06 08:54:25 +08:00
<div v-else-if="showType=='3'">
<div class="video-container">
<video
ref="videoPlayer"
:controls="controls"
:autoplay="autoplay"
:loop="loop"
:src="videoUrl"
@loadedmetadata="playVideoInFullscreen"
>
2024-10-08 08:29:29 +08:00
</video>
</div>
</div>
2025-01-06 08:54:25 +08:00
<div v-else>
2024-10-08 08:29:29 +08:00
<a-button type="primary">下载文件</a-button>
2025-01-06 08:54:25 +08:00
</div>
2024-08-29 13:33:02 +08:00
</a-col>
2025-01-06 08:54:25 +08:00
<a-col :span="12">
2024-10-08 08:29:29 +08:00
<a-row>
<a-col :span="24">
<a-form-item label="作业名称">
2025-01-06 08:54:25 +08:00
{{zyInfo.title}}
2024-10-08 08:29:29 +08:00
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="学生姓名">
2025-01-06 08:54:25 +08:00
{{formData.studentName}}
2024-10-08 08:29:29 +08:00
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="评分" v-bind="validateInfos.score">
2025-01-06 08:54:25 +08:00
<a-input-number v-model:value="formData.score" style="width: 100%" placeholder="请填写评分" ></a-input-number>
2024-10-08 08:29:29 +08:00
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="批阅内容" v-bind="validateInfos.pyContent">
<JEditor v-model:value="formData.pyContent" />
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="批阅附件" v-bind="validateInfos.pyFilePath">
2025-01-06 08:54:25 +08:00
<j-upload v-model:value="formData.pyFilePath" maxCount="1" :text="`上传批阅附件`" style="background: #ededed; " :forceAcceptVerify="true" ></j-upload>
2024-10-08 08:29:29 +08:00
</a-form-item>
</a-col>
<a-col :span="24" style="text-align: center;" v-if="disabled">
2025-01-06 08:54:25 +08:00
<div >
2024-10-08 08:29:29 +08:00
<a-button type="primary" @click="submitForm">保存</a-button>
<a-button type="primary" @click="submitNextForm" style="margin-left: 10px;">保存并下一个</a-button>
</div>
</a-col>
</a-row>
2024-08-29 13:33:02 +08:00
</a-col>
2025-01-06 08:54:25 +08:00
2024-08-29 13:33:02 +08:00
</a-row>
</a-form>
</a-spin>
</template>
<script lang="ts" setup>
2025-01-06 08:54:25 +08:00
import { ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted,onUnmounted } from 'vue';
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
import { getValueType } from '/@/utils';
import { saveOrUpdate } from '../ZyInfoStudent.api';
import { Form } from 'ant-design-vue';
import JEditor from '/@/components/Form/src/jeecg/components/JEditor.vue';
2024-10-08 08:29:29 +08:00
import { useGlobSetting } from '/@/hooks/setting';
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
2025-01-06 08:54:25 +08:00
import { getToken } from '/@/utils/auth';
2025-01-16 10:04:54 +08:00
import { encryptByBase64 } from '/@/utils/cipher';
2025-01-06 08:54:25 +08:00
const props = defineProps({
formDisabled: { type: Boolean, default: false },
formData: { type: Object, default: ()=>{} },
formBpm: { type: Boolean, default: true }
});
const formRef = ref();
const useForm = Form.useForm;
const emit = defineEmits(['register', 'ok', 'ok2']);
const formData = reactive<Record<string, any>>({
id: '',
score: '',
pyContent: '',
pyFilePath: '',
});
const { createMessage } = useMessage();
const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
const confirmLoading = ref<boolean>(false);
const showType = ref<string>('0');
const ylurl = ref<string>('');
2024-10-08 20:49:49 +08:00
const rotationAngle = ref(0);
2025-01-06 08:54:25 +08:00
const zyInfo = ref<any>({});
2024-10-08 08:29:29 +08:00
const globSetting = useGlobSetting();
const baseApiUrl = globSetting.domainUrl;
const videoPlayer = ref(null);
const videoOpen = ref<boolean>(false);
2025-01-06 08:54:25 +08:00
const controls = ref(true);
const autoplay = ref(false)
const loop = ref(false);
2024-10-08 08:29:29 +08:00
const videoUrl = ref<String>('');
2024-10-08 20:49:49 +08:00
2025-01-06 08:54:25 +08:00
//表单验证
const validatorRules = {
score: [{ required: true, message: '请输入分数!' }],
};
const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });
2024-08-29 13:33:02 +08:00
2025-01-06 08:54:25 +08:00
// 表单禁用
const disabled = computed(()=>{
if(props.formBpm === true){
if(props.formData.disabled === false){
return false;
}else{
return true;
}
2024-08-29 13:33:02 +08:00
}
2025-01-06 08:54:25 +08:00
return props.formDisabled;
});
2024-08-29 13:33:02 +08:00
2025-01-06 08:54:25 +08:00
function handleJyfz(record){
2024-08-29 13:33:02 +08:00
console.log(`🚀 ~ handleJyfz ~ record:`, record)
2025-01-06 08:54:25 +08:00
// if(zyInfo.score){
// if(parseInt(record) > parseInt(zyInfo.score)){
// createMessage.warning('评分不能超过预设作业分值!');
// formData.score = zyInfo.score;
// }
// }else{
// if(parseInt(record) > 100){
// createMessage.warning('评分不能超过100分!');
// formData.score = zyInfo.score;
// }
// }
if(parseInt(record) > 100){
createMessage.warning('评分不能超过100分!');
formData.score = '';
}
if(parseInt(record) < 0){
createMessage.warning('评分不能低于0分!');
formData.score = '';
}
}
2025-01-06 08:54:25 +08:00
2024-10-08 20:49:49 +08:00
function rotateImage() {
rotationAngle.value += 90; // 每次点击旋转90度
}
function rotateImage2() {
rotationAngle.value -= 90; // 每次点击旋转90度
}
2025-01-06 08:54:25 +08:00
/**
* 新增
*/
function add() {
edit({});
}
2024-12-13 13:21:42 +08:00
2025-01-06 08:54:25 +08:00
/**
* 编辑
*/
function edit(record) {
formData.pyContent = ''
nextTick(() => {
resetFields();
defHttp.get({url:'/zyInfo/zyInfo/queryById',params:{id:record.mainId}}).then(res=>{
console.log(`🚀 ~ defHttp.get ~ res:`, res)
zyInfo.value = res;
})
2025-01-06 08:54:25 +08:00
const parts = record.filePath.split('.');
const filetype = parts[parts.length - 1];
console.log(`🚀 ~ nextTick ~ filetype:`, filetype)
var file = getFileAccessHttpUrl(record.filePath);
ylurl.value = file;
if(filetype=='jpg' || filetype=='png' || filetype=='jpeg' || filetype=='xls' || filetype=='xlsx' || filetype=='text' ){
showType.value = '2';
}else if(filetype=='doc' || filetype=='docx' || filetype=='pdf'){
2025-03-06 10:04:04 +08:00
// showType.value = '1';
// // var file2 = getFileAccessHttpUrl(record.pdfPath);
// // let url2 = baseApiUrl + '/generic/web/viewer.html?file=' + encodeURIComponent(file2);
// var file3 = baseApiUrl + "/"+record.filePath;
2025-04-02 08:33:50 +08:00
// let url3 = 'https://zjdd.nenu.edu.cn/onlinePreview/onlinePreview?url=' + encodeURIComponent(encryptByBase64(file3));
2025-03-06 10:04:04 +08:00
// ylurl.value = url3;
2025-01-06 08:54:25 +08:00
showType.value = '1';
2025-03-06 10:04:04 +08:00
var file2 = getFileAccessHttpUrl(record.pdfPath);
let url2 = baseApiUrl + '/generic/web/viewer.html?file=' + encodeURIComponent(file2);
ylurl.value = url2;
2025-01-16 10:04:54 +08:00
2025-01-06 08:54:25 +08:00
}else if(filetype=='mp4'|| filetype=='avi'|| filetype=='mp3'|| filetype=='wav'){
showType.value = '3';
let url = getFileAccessHttpUrl(record.filePath);
console.log('视频预览-----》',url);
// videoOpen.value = true;
videoUrl.value = url;
}else{
showType.value = '0';
}
//赋值
Object.assign(formData, record);
});
}
2025-01-06 08:54:25 +08:00
// --------------------------视频------------------------------
2024-10-08 08:29:29 +08:00
const playVideo = () => {
videoPlayer.value.play();
};
const pauseVideo = () => {
videoPlayer.value.pause();
};
const handleFullScreenChange = () => {
if (!document.fullscreenElement) {
console.log('Video exited fullscreen');
// 这里可以执行取消全屏后的逻辑
videoOpen.value = false;
videoPlayer.value.pause();
}
};
2025-01-06 08:54:25 +08:00
function videoHandleCancel(){
2024-10-08 08:29:29 +08:00
pauseVideo();
videoOpen.value = false;
}
onMounted(() => {
document.addEventListener('fullscreenchange', handleFullScreenChange);
});
2025-01-06 08:54:25 +08:00
2024-10-08 08:29:29 +08:00
onUnmounted(() => {
document.removeEventListener('fullscreenchange', handleFullScreenChange);
});
//视频预览
2025-01-06 08:54:25 +08:00
function handleVideo(three){
2024-10-08 08:29:29 +08:00
let url = getFileAccessHttpUrl(three.filePath);
2025-01-06 08:54:25 +08:00
console.log('视频预览-----》',url);
2024-10-08 08:29:29 +08:00
videoOpen.value = true;
videoUrl.value = url;
playVideoInFullscreen();
// setTimeout(() => {
// playVideo();
// }, 1000);
2025-01-06 08:54:25 +08:00
2024-10-08 08:29:29 +08:00
}
// --------------------------视频------------------------------
2025-01-06 08:54:25 +08:00
const playVideoInFullscreen = async () => {
2024-10-08 08:29:29 +08:00
if (videoPlayer.value) {
try {
// 使用原生DOM方法请求全屏
// await videoPlayer.value.requestFullscreen();
} catch (err) {
console.error(err);
}
}
};
2025-01-06 08:54:25 +08:00
/**
* 提交数据
*/
async function submitForm() {
// 触发表单验证
await validate();
confirmLoading.value = true;
const isUpdate = ref<boolean>(false);
//时间格式化
let model = formData;
if (model.id) {
isUpdate.value = true;
}
//循环数据
for (let data in model) {
//如果该数据是数组并且是字符串类型
if (model[data] instanceof Array) {
let valueType = getValueType(formRef.value.getProps, data);
//如果是字符串类型的需要变成以逗号分割的字符串
if (valueType === 'string') {
model[data] = model[data].join(',');
}
2024-08-29 13:33:02 +08:00
}
}
2025-01-06 08:54:25 +08:00
2025-01-15 10:41:58 +08:00
defHttp.post({url:'/zyInfoStudent/zyInfoStudent/editFabu',params:model}).then(res =>{
2025-01-06 08:54:25 +08:00
emit('ok');
})
.finally(() => {
confirmLoading.value = false;
});
// await saveOrUpdate(model, isUpdate.value)
// .then((res) => {
// if (res.success) {
// createMessage.success(res.message);
// emit('ok');
// } else {
// createMessage.warning(res.message);
// }
// })
// .finally(() => {
// confirmLoading.value = false;
// });
2024-08-29 13:33:02 +08:00
}
2025-01-06 08:54:25 +08:00
/**
* 提交数据并下一个
*/
async function submitNextForm() {
// 触发表单验证
await validate();
confirmLoading.value = true;
const isUpdate = ref<boolean>(false);
//时间格式化
let model = formData;
if (model.id) {
isUpdate.value = true;
}
//循环数据
for (let data in model) {
//如果该数据是数组并且是字符串类型
if (model[data] instanceof Array) {
let valueType = getValueType(formRef.value.getProps, data);
//如果是字符串类型的需要变成以逗号分割的字符串
if (valueType === 'string') {
model[data] = model[data].join(',');
}
2024-10-08 08:29:29 +08:00
}
}
2025-01-06 08:54:25 +08:00
2025-01-15 10:41:58 +08:00
await defHttp.post({url:'/zyInfoStudent/zyInfoStudent/editFabu',params:model}).then(res =>{
2025-01-06 08:54:25 +08:00
emit('ok2');
})
2025-01-06 08:54:25 +08:00
await defHttp.get({url:'/zyInfoStudent/zyInfoStudent/getList2',params:{column:'createTime',order:'asc',pageNo:1,pageSize:10,ywid:zyInfo.value.id,rwbh:zyInfo.value.rwbh,queryType:5}}).then(res =>{
console.log(`🚀 ~ awaitdefHttp.post ~ res:`, res)
var list = res.records;
if(list.length>0){
edit(list[0])
}else{
createMessage.warning('已批阅完毕,暂无下一条批阅数据!');
}
})
.finally(() => {
confirmLoading.value = false;
});
}
2025-01-06 08:54:25 +08:00
defineExpose({
add,
edit,
submitForm,
});
2024-08-29 13:33:02 +08:00
</script>
<style lang="less" scoped>
2025-01-06 08:54:25 +08:00
.antd-modal-form {
min-height: 150px !important;
overflow-y: auto;
padding: 24px 24px 24px 24px;
}
.video-container {
2024-10-08 08:29:29 +08:00
text-align: center;
}
video {
display: block;
2025-01-06 08:54:25 +08:00
max-width: 100%; /* 确保视频宽度不超过其容器宽度 */
2024-10-08 08:29:29 +08:00
}
2024-10-08 20:49:49 +08:00
.image-container {
padding: 10px;
2025-01-06 08:54:25 +08:00
width:100%; /* 设置容器宽度 */
height: auto; /* 设置容器高度 */
overflow: hidden; /* 隐藏溢出的部分 */
2024-10-08 20:49:49 +08:00
display: flex;
align-items: center;
justify-content: center;
}
2025-01-06 08:54:25 +08:00
2024-10-08 20:49:49 +08:00
.rotated-image {
2025-01-06 08:54:25 +08:00
max-width: 100%; /* 最大宽度为容器宽度 */
max-height: 100%; /* 最大高度为容器高度 */
object-fit: contain; /* 保持图片内容不失真 */
transform: rotate(90deg); /* 假设图片已经旋转90度 */
2024-10-08 20:49:49 +08:00
}
2024-08-29 13:33:02 +08:00
</style>