|
|
@@ -266,10 +266,12 @@
|
|
|
// 上传视频按钮点击事件
|
|
|
$('#upload_video_btn').on('click', function() {
|
|
|
if ($('#video_link').val()) {
|
|
|
+ // 如果输入框有值,直接设置为视频链接
|
|
|
$('#video_preview').show();
|
|
|
$('#video_preview video').attr('src', $('#video_link').val());
|
|
|
$(this).text('上传视频');
|
|
|
} else {
|
|
|
+ // 否则触发文件选择
|
|
|
$('#video_file').trigger('click');
|
|
|
}
|
|
|
});
|
|
|
@@ -282,21 +284,12 @@
|
|
|
});
|
|
|
|
|
|
// 文件选择变化事件
|
|
|
+// 修改后的上传逻辑
|
|
|
$('#video_file').on('change', function() {
|
|
|
const file = this.files[0];
|
|
|
if (!file) return;
|
|
|
|
|
|
- // 文件验证
|
|
|
- const allowedTypes = ['video/mp4', 'video/quicktime'];
|
|
|
- if (!allowedTypes.includes(file.type) && !file.name.toLowerCase().endsWith('.mp4')) {
|
|
|
- $eb.message('error', '仅支持MP4格式的视频文件');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (file.size > 100 * 1024 * 1024) {
|
|
|
- $eb.message('error', '视频文件大小不能超过100MB');
|
|
|
- return;
|
|
|
- }
|
|
|
+ // 校验文件类型和大小...
|
|
|
|
|
|
// 显示进度条
|
|
|
$('#video_progress').show().find('.progress-bar').css('width', '0%');
|
|
|
@@ -307,23 +300,23 @@
|
|
|
type: 'GET',
|
|
|
dataType: 'json',
|
|
|
success: function(res) {
|
|
|
+ // 状态码检查
|
|
|
+ console.log(res);
|
|
|
if (res.code !== 200) {
|
|
|
$eb.message('error', res.msg || '上传凭证获取失败');
|
|
|
$('#video_progress').hide();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ // 关键字段检查
|
|
|
const data = res.data;
|
|
|
- const requiredKeys = ['uploadType', 'key'];
|
|
|
+ const requiredKeys = ['uploadType'];
|
|
|
if (!data || requiredKeys.some(k => !data[k])) {
|
|
|
$eb.message('error', '服务端返回参数缺失');
|
|
|
- $('#video_progress').hide();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
// 执行上传
|
|
|
AdminUpload.upload(
|
|
|
- data.uploadType,
|
|
|
+ data.uploadType, // 关键参数必须存在
|
|
|
{
|
|
|
token: data.uploadToken || '',
|
|
|
file: file,
|
|
|
@@ -336,53 +329,20 @@
|
|
|
$('#progress_bar').css('width', progress + '%').text(progress + '%');
|
|
|
}
|
|
|
}
|
|
|
- ).then(function(uploadRes) {
|
|
|
- try {
|
|
|
- // 构造完整的视频链接
|
|
|
- const baseUrl = 'http://oss.yzcyzjkc.com/';
|
|
|
- let videoUrl = baseUrl + data.key;
|
|
|
-
|
|
|
- // 确保URL格式正确
|
|
|
- if (videoUrl.startsWith('http://') || videoUrl.startsWith('https://')) {
|
|
|
- // 如果key已经包含完整URL,则直接使用
|
|
|
- videoUrl = data.key;
|
|
|
- } else if (!videoUrl.startsWith(baseUrl)) {
|
|
|
- // 确保以baseUrl开头
|
|
|
- videoUrl = baseUrl + (data.key.startsWith('/') ? data.key.substring(1) : data.key;
|
|
|
- }
|
|
|
-
|
|
|
- // 更新表单字段和预览
|
|
|
- $('#video_link').val(videoUrl);
|
|
|
- $('#video_preview').show();
|
|
|
-
|
|
|
- if ($('#video_preview video').length === 0) {
|
|
|
- $('#video_preview').html('<video controls src="' + videoUrl + '">您的浏览器不支持 video 标签。</video>' +
|
|
|
- '<i class="layui-icon layui-icon-delete delete-video" id="delete_video"></i>');
|
|
|
- } else {
|
|
|
- $('#video_preview video').attr('src', videoUrl);
|
|
|
- }
|
|
|
-
|
|
|
- $('#upload_video_btn').text('确认添加');
|
|
|
- $eb.message('success', '视频上传成功');
|
|
|
- } catch (err) {
|
|
|
- console.error('URL处理错误:', err);
|
|
|
- $eb.message('error', '视频URL处理失败');
|
|
|
- } finally {
|
|
|
- $('#video_progress').hide();
|
|
|
- }
|
|
|
+ ).then(function(res) {
|
|
|
+ // 上传成功处理...
|
|
|
}).catch(function(err) {
|
|
|
- $eb.message('error', '上传失败: ' + (err.message || '未知错误'));
|
|
|
- $('#video_progress').hide();
|
|
|
+ $eb.message('error', '上传失败: ' + err.message);
|
|
|
});
|
|
|
},
|
|
|
error: function(xhr) {
|
|
|
- $eb.message('error', '网络请求失败: ' + (xhr.statusText || '未知错误'));
|
|
|
+ $eb.message('error', '网络请求失败');
|
|
|
$('#video_progress').hide();
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
+ });
|
|
|
|
|
|
// 选择图片
|
|
|
function changeIMG(index,pic){
|