VideoUploadDialog2.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="video-source-modal" v-if="show">
  3. <div class="modal-overlay"></div>
  4. <div class="modal-content video-source-content">
  5. <div class="modal-header">
  6. <h3 class="modal-title">{{ lang.ssSelectVideoSource }}</h3>
  7. <div class="modal-close" @click="close()">×</div>
  8. </div>
  9. <div class="modal-body video-source-body">
  10. <div class="source-options">
  11. <div class="source-option" @click="handleLocalUpload">
  12. <div class="option-icon">
  13. <svg width="48" height="48" viewBox="0 0 48 48" fill="none"
  14. xmlns="http://www.w3.org/2000/svg">
  15. <g id="Component 1">
  16. <path id="Vector" d="M24 10V38" stroke="currentColor" stroke-width="4" />
  17. <path id="Vector_2" d="M10 24L24 10L38 24" stroke="currentColor" stroke-width="4" />
  18. </g>
  19. </svg>
  20. </div>
  21. <div class="option-text">{{ lang.ssLocalUpload }}</div>
  22. </div>
  23. <div class="source-option" @click="handleBilibiliSearch" v-show="lang.lang == 'cn'">
  24. <div class="option-icon">
  25. <svg width="48" height="48" viewBox="0 0 48 48" fill="none"
  26. xmlns="http://www.w3.org/2000/svg">
  27. <g id="Component 1">
  28. <path id="Vector"
  29. d="M38 8H10C7.79086 8 6 9.79086 6 12V32C6 34.2091 7.79086 36 10 36H38C40.2091 36 42 34.2091 42 32V12C42 9.79086 40.2091 8 38 8Z"
  30. stroke="currentColor" stroke-width="4" />
  31. <path id="Vector_2" d="M20 18L32 24L20 30V18Z" stroke="currentColor" stroke-width="4" />
  32. </g>
  33. </svg>
  34. </div>
  35. <div class="option-text">{{ lang.ssBiliSearch }}</div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <!-- 隐藏的文件输入 -->
  41. <input ref="fileInput" type="file" accept="video/*" style="display: none" @change="handleFileChange" />
  42. </div>
  43. </template>
  44. <script>
  45. import "../../../../common/aws-sdk-2.235.1.min.js";
  46. export default {
  47. data() {
  48. return {
  49. show: false,
  50. data: null,
  51. };
  52. },
  53. computed: {},
  54. methods: {
  55. open(data) {
  56. this.data = data;
  57. this.show = true;
  58. },
  59. close() {
  60. this.show = false;
  61. this.init();
  62. },
  63. init() {
  64. this.data = null;
  65. },
  66. // 处理本地文件上传
  67. handleLocalUpload() {
  68. this.$refs.fileInput.click();
  69. },
  70. // 处理文件选择
  71. handleFileChange(event) {
  72. const file = event.target.files[0];
  73. if (file) {
  74. // 验证文件类型
  75. if (!file.type.startsWith('video/')) {
  76. this.$message.error('请选择视频文件');
  77. event.target.value = "";
  78. return;
  79. }
  80. // 上传文件
  81. this.uploadVideo(file);
  82. }
  83. // 重置input,以便可以再次选择同一个文件
  84. event.target.value = "";
  85. },
  86. // 上传视频文件
  87. uploadVideo(file) {
  88. const uploadId = new Date().getTime();
  89. const fileName = file.name;
  90. // 初始化进度信息
  91. this.$emit("uploadProgress", {
  92. id: uploadId,
  93. fileName: fileName,
  94. progress: 0,
  95. loaded: 0,
  96. total: file.size,
  97. status: 'uploading'
  98. });
  99. var credentials = {
  100. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  101. secretAccessKey: "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"
  102. };
  103. window.AWS.config.update(credentials);
  104. window.AWS.config.region = "cn-northwest-1";
  105. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } });
  106. var _this = this;
  107. var params = {
  108. Key:
  109. file.name.split(".")[0] +
  110. new Date().getTime() +
  111. "." +
  112. file.name.split(".")[file.name.split(".").length - 1],
  113. ContentType: file.type,
  114. Body: file,
  115. "Access-Control-Allow-Credentials": "*",
  116. ACL: "public-read"
  117. };
  118. var options = {
  119. partSize: 2048 * 1024 * 1024,
  120. queueSize: 2,
  121. leavePartsOnError: true
  122. };
  123. bucket
  124. .upload(params, options)
  125. .on("httpUploadProgress", function (evt) {
  126. // 更新上传进度
  127. const progress = Math.round((evt.loaded * 100) / evt.total);
  128. _this.$emit("uploadProgress", {
  129. id: uploadId,
  130. fileName: fileName,
  131. progress: progress,
  132. loaded: evt.loaded,
  133. total: evt.total,
  134. status: 'uploading'
  135. });
  136. })
  137. .send(function (err, data) {
  138. if (err) {
  139. // 上传失败,更新进度状态
  140. _this.$emit("uploadProgress", {
  141. id: uploadId,
  142. fileName: fileName,
  143. progress: 0,
  144. loaded: 0,
  145. total: file.size,
  146. status: 'error'
  147. });
  148. _this.$message.error("上传失败");
  149. } else {
  150. // 上传成功,触发事件传递文件信息
  151. _this.$emit("uploadLocalVideo", {
  152. id: uploadId,
  153. file: file,
  154. url: data.Location,
  155. name: file.name
  156. });
  157. _this.close();
  158. }
  159. });
  160. },
  161. // 处理Bilibili搜索
  162. handleBilibiliSearch() {
  163. // 触发Bilibili搜索事件
  164. this.$emit("searchBilibili");
  165. this.close();
  166. },
  167. },
  168. };
  169. </script>
  170. <style scoped>
  171. /* 视频来源选择弹窗 */
  172. .video-source-modal {
  173. position: fixed;
  174. top: 0;
  175. left: 0;
  176. right: 0;
  177. bottom: 0;
  178. z-index: 1000;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. }
  183. .modal-overlay {
  184. position: absolute;
  185. top: 0;
  186. left: 0;
  187. right: 0;
  188. bottom: 0;
  189. background-color: rgba(0, 0, 0, 0.5);
  190. }
  191. .modal-content {
  192. position: relative;
  193. z-index: 1001;
  194. background-color: white;
  195. border-radius: 8px;
  196. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  197. overflow: hidden;
  198. width: 600px;
  199. }
  200. .modal-header {
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. padding: 20px 24px;
  205. /* border-bottom: 1px solid #f0f0f0; */
  206. }
  207. .modal-title {
  208. font-size: 18px;
  209. font-weight: 600;
  210. color: #333;
  211. margin: 0;
  212. }
  213. .modal-close {
  214. font-size: 24px;
  215. color: #999;
  216. cursor: pointer;
  217. transition: all 0.3s;
  218. }
  219. .modal-close:hover {
  220. /* color: #409eff; */
  221. background-color: #f3f4f6;
  222. }
  223. .video-source-body {
  224. padding: 0px 24px 30px;
  225. }
  226. .source-options {
  227. display: flex;
  228. justify-content: center;
  229. gap: 40px;
  230. }
  231. .source-option {
  232. flex: 1;
  233. max-width: 200px;
  234. padding: 15px 20px;
  235. border: 2px solid #e5e7eb;
  236. border-radius: 8px;
  237. display: flex;
  238. flex-direction: column;
  239. align-items: center;
  240. justify-content: center;
  241. cursor: pointer;
  242. transition: all 0.3s;
  243. background-color: #fafbfc;
  244. }
  245. .source-option:hover {
  246. background-color: #fff8f0;
  247. border-color: #f8963c;
  248. color: #FF9300;
  249. box-shadow: 0 2px 8px rgba(40, 92, 245, 0.1);
  250. }
  251. .source-option:hover .option-icon{
  252. color: #FF9300;
  253. }
  254. .option-icon {
  255. width: 95%;
  256. height: 80px;
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. margin-bottom: 20px;
  261. border: 1px solid #e5e7eb;
  262. color: #6b7280;
  263. background: #fff;
  264. border-radius: 4px;
  265. padding: 10px;
  266. }
  267. .option-text {
  268. font-size: 16px;
  269. font-weight: 600;
  270. color: #333;
  271. text-align: center;
  272. }
  273. </style>