|
|
@@ -284,72 +284,64 @@
|
|
|
});
|
|
|
|
|
|
// 文件选择变化事件
|
|
|
+// 修改后的上传逻辑
|
|
|
$('#video_file').on('change', function() {
|
|
|
- var file = this.files[0];
|
|
|
+ const file = this.files[0];
|
|
|
if (!file) return;
|
|
|
|
|
|
- // 验证文件类型
|
|
|
- if (!file.type.includes('video/mp4') && !file.name.toLowerCase().endsWith('.mp4')) {
|
|
|
- $eb.message('error', '请选择MP4格式的视频文件');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 验证文件大小(100MB以内)
|
|
|
- if (file.size > 100 * 1024 * 1024) {
|
|
|
- $eb.message('error', '视频文件大小不能超过100MB');
|
|
|
- return;
|
|
|
- }
|
|
|
+ // 校验文件类型和大小...
|
|
|
|
|
|
// 显示进度条
|
|
|
- $('#video_progress').show();
|
|
|
- $('#progress_bar').css('width', '0%').text('0%');
|
|
|
+ $('#video_progress').show().find('.progress-bar').css('width', '0%');
|
|
|
|
|
|
- // 获取签名信息
|
|
|
+ // 获取上传凭证
|
|
|
$.ajax({
|
|
|
url: "https://shop.yzcyzjkc.com/admin/widget.video/get_signature",
|
|
|
type: 'GET',
|
|
|
- success: function(signatureResponse) {
|
|
|
- // console.log(上传视频);
|
|
|
- console.log(signatureResponse);
|
|
|
- // if (signatureResponse.code != 200) {
|
|
|
- // $eb.message('error', signatureResponse.msg || '获取上传凭证失败');
|
|
|
- // $('#video_progress').hide();
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
- // 使用AdminUpload进行上传
|
|
|
- AdminUpload.upload(signatureResponse.data.uploadType, {
|
|
|
- token: signatureResponse.data.uploadToken || '',
|
|
|
- file: file,
|
|
|
- accessKeyId: signatureResponse.data.accessKey || '',
|
|
|
- accessKeySecret: signatureResponse.data.secretKey || '',
|
|
|
- bucketName: signatureResponse.data.storageName || '',
|
|
|
- region: signatureResponse.data.storageRegion || '',
|
|
|
- domain: signatureResponse.data.domain || '',
|
|
|
- uploadIng: function(progress) {
|
|
|
- $('#progress_bar').css('width', progress + '%').text(progress + '%');
|
|
|
- }
|
|
|
- }).then(function(res) {
|
|
|
- // 上传成功
|
|
|
- $('#video_link').val(res.url);
|
|
|
- $('#video_preview').show();
|
|
|
- $('#video_preview video').attr('src', res.url);
|
|
|
- $('#upload_video_btn').text('确认添加');
|
|
|
- $eb.message('success', '视频上传成功');
|
|
|
+ dataType: 'json',
|
|
|
+ success: function(res) {
|
|
|
+ // 状态码检查
|
|
|
+ console.log(res.code);
|
|
|
+ if (res.code !== 200) {
|
|
|
+ $eb.message('error', res.msg || '上传凭证获取失败');
|
|
|
$('#video_progress').hide();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 关键字段检查
|
|
|
+ const data = res.data;
|
|
|
+ const requiredKeys = ['uploadType'];
|
|
|
+ if (!data || requiredKeys.some(k => !data[k])) {
|
|
|
+ $eb.message('error', '服务端返回参数缺失');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 执行上传
|
|
|
+ AdminUpload.upload(
|
|
|
+ data.uploadType, // 关键参数必须存在
|
|
|
+ {
|
|
|
+ token: data.uploadToken || '',
|
|
|
+ file: file,
|
|
|
+ accessKeyId: data.accessKey || '',
|
|
|
+ accessKeySecret: data.secretKey || '',
|
|
|
+ bucketName: data.storageName || '',
|
|
|
+ region: data.storageRegion || '',
|
|
|
+ domain: data.domain || '',
|
|
|
+ uploadIng: function(progress) {
|
|
|
+ $('#progress_bar').css('width', progress + '%').text(progress + '%');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ).then(function(res) {
|
|
|
+ // 上传成功处理...
|
|
|
}).catch(function(err) {
|
|
|
- // 上传失败
|
|
|
- console.error('视频上传失败:', err);
|
|
|
- $eb.message('error', '视频上传失败: ' + (err.message || '未知错误'));
|
|
|
- $('#video_progress').hide();
|
|
|
+ $eb.message('error', '上传失败: ' + err.message);
|
|
|
});
|
|
|
},
|
|
|
- error: function() {
|
|
|
- $eb.message('error', '获取上传凭证失败');
|
|
|
+ error: function(xhr) {
|
|
|
+ $eb.message('error', '网络请求失败');
|
|
|
$('#video_progress').hide();
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
});
|
|
|
|
|
|
// 选择图片
|