qiniuTransfer.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  1. <template>
  2. <div>
  3. <div>
  4. <div class="gva-search-box">
  5. <div>
  6. <el-form ref="searchForm" :inline="true" :model="searchInfo">
  7. <el-form-item label="归属任务">
  8. <el-select v-model="searchInfo.name" size="small" filterable>
  9. <el-option
  10. v-for="item in taskOptions"
  11. :key="item.value"
  12. :label="item.label"
  13. :value="item.value"
  14. />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="负责人">
  18. <el-select v-model="searchInfo.director_name" size="small">
  19. <el-option
  20. v-for="item in directorOptions"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value"
  24. />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button
  29. size="small"
  30. type="primary"
  31. icon="search"
  32. @click="onSubmit"
  33. >查询</el-button
  34. >
  35. <el-button size="small" icon="refresh" @click="onReset"
  36. >重置</el-button
  37. >
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </div>
  42. <div class="gva-search-box" style="padding-bottom: 25px">
  43. <div>
  44. <el-button
  45. size="small"
  46. type="primary"
  47. icon="upload"
  48. @click="navToScript()"
  49. >上传文件</el-button
  50. >
  51. <el-button
  52. v-if="createButtonVisible"
  53. class="excel-btn"
  54. size="small"
  55. type="success"
  56. icon="plus"
  57. @click="switchCreateFolder()"
  58. >新建文件夹</el-button
  59. >
  60. </div>
  61. </div>
  62. <div class="gva-btn-list">
  63. <div class="row center">
  64. <el-breadcrumb :separator-icon="ArrowRight">
  65. <el-breadcrumb-item
  66. v-for="(breadcrumb, index) in breadcrumbList"
  67. :key="index"
  68. >
  69. <a @click="clickBreadcrumb(breadcrumb, index)">{{
  70. breadcrumb.name
  71. }}</a>
  72. </el-breadcrumb-item>
  73. </el-breadcrumb>
  74. </div>
  75. </div>
  76. <div class="gva-table-box">
  77. <div class="video-container">
  78. <el-card shadow="hover">
  79. <div class="video-main">
  80. <ul class="list">
  81. <li v-if="files.length == 0" class="list-none">
  82. <el-empty :image-size="100" description="暂无文件" />
  83. </li>
  84. <li
  85. v-else
  86. v-for="(file, index) in files"
  87. :key="index"
  88. :class="{ active: file.active }"
  89. class="list-item"
  90. @dblclick="dbClickOpenFile(file)"
  91. >
  92. <el-dropdown
  93. trigger="contextmenu"
  94. :id="String(file.id)"
  95. placement="bottom"
  96. @command="handleCommand"
  97. @visible-change="handleChange($event, String(file.id))"
  98. ref="dropdownRef"
  99. >
  100. <div class="inner">
  101. <img
  102. :src="file.thumUrl ? file.thumUrl : defultThumUrl"
  103. class="icon-thumb"
  104. />
  105. <div class="inner-info" v-if="file.isFile">
  106. <p>
  107. 版本:<span style="font-size: 14px">{{
  108. file.file_version
  109. }}</span>
  110. </p>
  111. </div>
  112. <!-- <i v-else class="icon-folder"></i> -->
  113. <!-- <div v-show="file.resType > 0" class="hover-cover">
  114. <span style="color: #fff">{{
  115. file.size | sizeFilter
  116. }}</span>
  117. </div> -->
  118. </div>
  119. <template #dropdown>
  120. <el-dropdown-menu>
  121. <el-dropdown-item
  122. v-if="file.isFile == false"
  123. :command="beforeHandleCommand('open', file)"
  124. ><el-icon><Position /></el-icon>打开</el-dropdown-item
  125. >
  126. <el-dropdown-item
  127. v-if="file.isFile"
  128. :command="beforeHandleCommand('rename', file)"
  129. ><el-icon><InfoFilled /></el-icon
  130. >重命名</el-dropdown-item
  131. >
  132. <el-dropdown-item
  133. v-if="file.isFile"
  134. :command="beforeHandleCommand('getUrl', file)"
  135. ><el-icon><Share /></el-icon
  136. >获取链接</el-dropdown-item
  137. >
  138. <el-dropdown-item
  139. v-if="file.isFile"
  140. :command="beforeHandleCommand('download', file)"
  141. ><el-icon><Download /></el-icon>下载</el-dropdown-item
  142. >
  143. <el-dropdown-item
  144. v-if="file.isFile"
  145. :command="beforeHandleCommand('delete', file)"
  146. ><el-icon><DeleteFilled /></el-icon
  147. >删除</el-dropdown-item
  148. >
  149. </el-dropdown-menu>
  150. </template>
  151. </el-dropdown>
  152. <!-- <i
  153. class="icon-file-selected"
  154. @click="toggleSelect(file, file.id)"
  155. ></i> -->
  156. <div class="file-name">
  157. <span :title="file.name">{{ file.name }}</span>
  158. </div>
  159. </li>
  160. </ul>
  161. </div>
  162. </el-card>
  163. </div>
  164. </div>
  165. </div>
  166. <el-dialog
  167. title="文件上传界面"
  168. v-model="uploadVisible"
  169. :center="true"
  170. :close-on-click-modal="false"
  171. :close-on-press-escape="false"
  172. >
  173. <el-form
  174. ref="elForm2"
  175. :model="uploadForm"
  176. size="default"
  177. label-width="100px"
  178. >
  179. <el-form-item label="上传目录" prop="way">
  180. <el-col :span="20">
  181. <el-input
  182. v-model="uploadForm.way"
  183. placeholder="根目录"
  184. disabled
  185. ></el-input>
  186. </el-col>
  187. </el-form-item>
  188. <el-form-item label="关联任务" prop="id">
  189. <el-col :span="20">
  190. <el-input
  191. v-model="uploadForm.task_id"
  192. placeholder="关联任务"
  193. disabled
  194. ></el-input>
  195. </el-col>
  196. </el-form-item>
  197. <el-form-item label="任务名称" prop="name">
  198. <el-col :span="20">
  199. <el-input
  200. v-model="uploadForm.task_name"
  201. placeholder="任务名称"
  202. disabled
  203. ></el-input>
  204. </el-col>
  205. </el-form-item>
  206. <el-form-item label="文件类型" prop="type">
  207. <el-col :span="20">
  208. <el-select
  209. v-model="uploadForm.type"
  210. placeholder="文件类型"
  211. :style="{ width: '100%' }"
  212. @change="selectChanged(uploadForm)"
  213. >
  214. <el-option
  215. v-for="item in fileTypeOptions"
  216. :key="item.value"
  217. :label="item.label"
  218. :value="item.value"
  219. />
  220. </el-select>
  221. </el-col>
  222. </el-form-item>
  223. <el-form-item label="文件名称" prop="qiniuVersion">
  224. <el-col :span="20">
  225. <el-input
  226. v-model="uploadForm.fileName"
  227. placeholder="文件名称,选择文件后自动生成"
  228. disabled
  229. :style="{ width: '100%' }"
  230. ></el-input>
  231. </el-col>
  232. </el-form-item>
  233. <el-form-item v-if="showVersion" label="更新版本" prop="qiniuVersion">
  234. <el-col :span="20">
  235. <el-input
  236. v-model="uploadForm.qiniuVersion"
  237. placeholder="版本号"
  238. disabled
  239. :style="{ width: '100%' }"
  240. ></el-input>
  241. </el-col>
  242. </el-form-item>
  243. <el-form-item v-if="showUpload" label="选择文件" prop="qiniuAddress">
  244. <el-col :span="20">
  245. <el-upload
  246. :limit="1"
  247. action="http://upload-z2.qiniup.com"
  248. :data="qiniuData"
  249. drag
  250. :disabled="disabledUpload"
  251. :show-file-list="false"
  252. :http-request="uploadHttpRequest"
  253. :on-success="handleAvatarSuccess"
  254. :before-upload="beforeAvatarUpload"
  255. :on-progress="onProgress"
  256. >
  257. <div class="el-default" v-if="!progressFlag">
  258. <i class="el-icon-upload"></i>
  259. <div class="el-upload__text">
  260. 将文件拖到此处,或<em> 点击上传 </em>
  261. </div>
  262. </div>
  263. <el-progress
  264. type="circle"
  265. :percentage="progress"
  266. :stroke-width="15"
  267. style="margin-top: 20px"
  268. v-if="progressFlag"
  269. >
  270. </el-progress>
  271. </el-upload>
  272. <!-- 进度条 -->
  273. <!-- <el-progress
  274. v-if="progressFlag"
  275. :text-inside="true"
  276. :percentage="progress"
  277. :stroke-width="15"
  278. :status="status"
  279. ></el-progress> -->
  280. </el-col>
  281. </el-form-item>
  282. <el-form-item>
  283. <el-button size="small" @click="cancelUp(uploadForm)"
  284. >取消上传</el-button
  285. >
  286. <!-- <el-button type="primary" size="small" @click="recordFile(uploadForm)"
  287. >确定上传</el-button
  288. > -->
  289. </el-form-item>
  290. </el-form>
  291. </el-dialog>
  292. <el-dialog
  293. v-model="fileFolderVisible"
  294. title="新建文件夹"
  295. width="50%"
  296. :close-on-press-escape="false"
  297. :show-close="false"
  298. :close-on-click-modal="false"
  299. >
  300. <el-form
  301. v-if="fileFolderVisible"
  302. :inline="true"
  303. :model="formFolder"
  304. :rules="rules"
  305. label-position="left"
  306. label-width="100px"
  307. >
  308. <el-row :gutter="2">
  309. <el-col :span="24">
  310. <el-form-item label="文件夹类型" prop="folder_type">
  311. <!-- <el-select
  312. v-model="formFolder.folder_type"
  313. size="small"
  314. @change="changeFolderType"
  315. >
  316. <el-option label="游戏任务" value="0" />
  317. <el-option label="其他文件" value="1" />
  318. </el-select> -->
  319. <el-select
  320. v-model="formFolder.folder_type"
  321. placeholder="文件夹类型"
  322. :style="{ width: '100%' }"
  323. size="small"
  324. @change="changeFolderType"
  325. >
  326. <el-option
  327. v-for="item in folderTypeOptions"
  328. :key="item.value"
  329. :label="item.label"
  330. :value="item.value"
  331. />
  332. </el-select>
  333. </el-form-item>
  334. </el-col>
  335. </el-row>
  336. <el-row :gutter="2" v-if="taskFolderVisible">
  337. <el-col :span="24">
  338. <el-form-item label="任务名称" prop="task">
  339. <el-select
  340. v-model="formFolder.task"
  341. size="small"
  342. filterable
  343. @change="changeTask"
  344. >
  345. <el-option
  346. v-for="item in taskOptions"
  347. :key="item.value"
  348. :label="item.label"
  349. :value="item.value"
  350. />
  351. </el-select>
  352. </el-form-item>
  353. </el-col>
  354. </el-row>
  355. <el-row :gutter="2">
  356. <el-col :span="24">
  357. <el-form-item label="文件夹名" prop="folder_name">
  358. <el-input
  359. v-model="formFolder.folder_name"
  360. :disabled="disabledFolderName"
  361. />
  362. </el-form-item>
  363. </el-col>
  364. </el-row>
  365. </el-form>
  366. <template #footer>
  367. <div class="dialog-footer">
  368. <el-button size="small" @click="fileFolderVisible = false"
  369. >取 消</el-button
  370. >
  371. <el-button size="small" type="primary" @click="createFolder()"
  372. >确 定</el-button
  373. >
  374. </div>
  375. </template>
  376. </el-dialog>
  377. </div>
  378. </template>
  379. <script>
  380. export default {
  381. name: "qiniuTransfer",
  382. };
  383. </script>
  384. <script setup>
  385. import {
  386. getAllTaskSimple,
  387. addFileFolder,
  388. getFolderFileList,
  389. getQiniuToken,
  390. getAllFileType,
  391. selectFolderMsg,
  392. queryVersionByType,
  393. addQiniuFile,
  394. deleteQiniuFile,
  395. deleteQiniuFileAndRecord,
  396. renameQiniuFileAndRecord,
  397. queryFolder,
  398. } from "@/api/fileManager";
  399. import { getDirectorList } from "@/api/responsiblePerson";
  400. import { ref } from "vue";
  401. import { ElMessage, ElMessageBox } from "element-plus";
  402. import { ArrowRight } from "@element-plus/icons-vue";
  403. // import { number } from "echarts";
  404. import * as qiniu from "qiniu-js";
  405. import defultThumUrlimage from '@/assets/defultThumUrl.svg'
  406. // import { switchCase } from "@babel/types";
  407. //===================
  408. const fileFolderVisible = ref(false);
  409. const taskFolderVisible = ref(false);
  410. const createButtonVisible = ref(true);
  411. const disabledFolderName = ref(false);
  412. const formFolder = ref({
  413. folder_type: "0",
  414. folder_name: "",
  415. task: "",
  416. parentId: 0,
  417. });
  418. const taskOptions = ref();
  419. const fileTypeOptions = ref([]);
  420. const directorOptions = ref();
  421. const currentParentId = ref(0);
  422. const uploadVisible = ref(false);
  423. const progressFlag = ref(false);
  424. const progress = ref(0);
  425. const cance = ref(false);
  426. const disabledUpload = ref(false);
  427. const uploadForm = ref({
  428. way: "",
  429. parentId: 0,
  430. parentName: "",
  431. task_id: 0,
  432. task_name: "",
  433. fileName: "",
  434. type: null,
  435. type_name: "",
  436. qiniuVersion: "",
  437. key: "",
  438. qiniuAddress: "",
  439. qiniuHash: "",
  440. });
  441. const folderTypeOptions = ref([]);
  442. const dropdownRef = ref();
  443. const activeItems = ref([]); // 选中激活的文件列表
  444. const qiniuData = ref({
  445. key: "",
  446. token: "",
  447. cName: "",
  448. }); //七牛上传时获取的服务器信息
  449. const showVersion = ref(false);
  450. const showUpload = ref(false);
  451. const status = ref("exception");
  452. //
  453. async function switchCreateFolder() {
  454. if (breadcrumbList.value.length == 1) {
  455. folderTypeOptions.value = [
  456. { value: "0", label: "游戏任务" },
  457. // { value: "1", label: "其他文件" },
  458. ];
  459. formFolder.value.folder_type = "0";
  460. taskFolderVisible.value = true;
  461. disabledFolderName.value = true;
  462. formFolder.value.folder_name = "";
  463. formFolder.value.task = "";
  464. } else {
  465. folderTypeOptions.value = [
  466. // { value: "0", label: "游戏任务" },
  467. { value: "1", label: "其他文件" },
  468. ];
  469. formFolder.value.folder_type = "1";
  470. taskFolderVisible.value = false;
  471. disabledFolderName.value = false;
  472. formFolder.value.folder_name = "";
  473. formFolder.value.task = "";
  474. }
  475. formFolder.value.parentId =
  476. breadcrumbList.value[breadcrumbList.value.length - 1].id;
  477. if (fileFolderVisible.value == false) {
  478. fileFolderVisible.value = true;
  479. }
  480. if (formFolder.value.folder_type === "0") {
  481. taskFolderVisible.value = true;
  482. disabledFolderName.value = true;
  483. }
  484. const taskListRes = await getAllTaskSimple({
  485. page: 1,
  486. pageSize: 999,
  487. });
  488. let taskList = [];
  489. const data = taskListRes.data.list;
  490. data.forEach((e) => {
  491. taskList.push({
  492. value: e.task_id + "|" + e.task_name,
  493. label: e.task_id + "_" + e.task_name,
  494. });
  495. });
  496. taskOptions.value = taskList;
  497. }
  498. function changeFolderType(e) {
  499. if (e === "0") {
  500. taskFolderVisible.value = true;
  501. disabledFolderName.value = true;
  502. formFolder.value.folder_name = "";
  503. formFolder.value.task = "";
  504. } else {
  505. taskFolderVisible.value = false;
  506. disabledFolderName.value = false;
  507. formFolder.value.folder_name = "";
  508. formFolder.value.task = "";
  509. }
  510. }
  511. function changeTask(e) {
  512. formFolder.value.folder_name = e;
  513. }
  514. const createFolder = async () => {
  515. var task = formFolder.value.task;
  516. var taskArr = task.split("|");
  517. const addFormFolder = {
  518. name: formFolder.value.folder_name,
  519. task_id: Number(taskArr[0]),
  520. parent_id: Number(formFolder.value.parentId),
  521. };
  522. let res = await addFileFolder(addFormFolder);
  523. // console.log(res);
  524. if (res.code === 0) {
  525. ElMessage({
  526. type: "success",
  527. message: "文件夹创建成功!",
  528. });
  529. fileFolderVisible.value = false;
  530. currentParentId.value = res.data.id;
  531. breadcrumbList.value.push({ id: res.data.id, name: res.data.name });
  532. initMaterialPage(currentParentId.value);
  533. } else {
  534. ElMessage({
  535. type: "error",
  536. message: res.message,
  537. });
  538. }
  539. };
  540. //
  541. // 跳转上传界面
  542. async function navToScript() {
  543. if (breadcrumbList.value.length == 1) {
  544. ElMessage.warning("根目录不允许直接上传文件,请先选择进入文件夹!!");
  545. return;
  546. }
  547. uploadForm.value.parentId =
  548. breadcrumbList.value[breadcrumbList.value.length - 1].id;
  549. uploadForm.value.parentName =
  550. breadcrumbList.value[breadcrumbList.value.length - 1].name;
  551. uploadForm.value.way = "";
  552. breadcrumbList.value.forEach((e) => {
  553. uploadForm.value.way += e.name + ">";
  554. });
  555. // console.log(uploadForm.value.parentId);
  556. const folderInfo = await getParentTaskMsg(uploadForm.value.parentId);
  557. // console.log(folderInfo);
  558. if (folderInfo == "") {
  559. uploadForm.value.task_id = "";
  560. uploadForm.value.task_name = "";
  561. } else {
  562. uploadForm.value.task_id = folderInfo.task_id;
  563. uploadForm.value.task_name = folderInfo.task_name;
  564. }
  565. uploadVisible.value = true;
  566. cance.value = false;
  567. showVersion.value = false;
  568. showUpload.value = false;
  569. uploadForm.value.fileName = "";
  570. uploadForm.value.type = null;
  571. uploadForm.value.qiniuVersion = "";
  572. uploadForm.value.qiniuAddress = "";
  573. progressFlag.value = false;
  574. await getFileTypeOptions();
  575. disabledUpload.value = false;
  576. await getToken();
  577. }
  578. // 查询所有文件类型
  579. async function getFileTypeOptions() {
  580. fileTypeOptions.value = [];
  581. const res = await getAllFileType();
  582. if (res.code === 0) {
  583. for (let i = 0; i < res.data.list.length; i++) {
  584. var temp = {
  585. typeId: res.data.list[i].id,
  586. value: i,
  587. label: res.data.list[i].name + res.data.list[i].describe,
  588. name: res.data.list[i].name,
  589. type: res.data.list[i].describe,
  590. };
  591. fileTypeOptions.value.push(temp);
  592. }
  593. }
  594. }
  595. //查询上传目录是否关联任务id并返回
  596. async function getParentTaskMsg(id) {
  597. const res = await selectFolderMsg({ id: Number(id) });
  598. // console.log(res);
  599. if (res.msg == "获取成功") {
  600. return res.data.data;
  601. }
  602. return "";
  603. }
  604. const handleChange = (visible, id) => {
  605. if (!visible) return;
  606. dropdownRef.value.forEach((item) => {
  607. if (item.id == id) return;
  608. item.handleClose();
  609. });
  610. };
  611. /**
  612. * 动态设置Dropdown的command
  613. */
  614. function beforeHandleCommand(flag, command) {
  615. // flag为传递的参数
  616. return {
  617. flag: flag,
  618. command: command,
  619. };
  620. }
  621. const handleCommand = (val) => {
  622. switch (val.flag) {
  623. case "open":
  624. dbClickOpenFile(val.command);
  625. break;
  626. case "download":
  627. downloadFile(val.command);
  628. break;
  629. case "delete":
  630. deleteFile(val.command);
  631. break;
  632. case "getUrl":
  633. getUrl(val.command);
  634. break;
  635. case "rename":
  636. rename(val.command);
  637. break;
  638. default:
  639. break;
  640. }
  641. };
  642. //文件重命名
  643. async function rename(file) {
  644. ElMessageBox.prompt("请输入新的文件名", "重命名", {
  645. confirmButtonText: "确认",
  646. cancelButtonText: "取消",
  647. inputPattern:
  648. /(?!((^(con)$)|^(con)\..*|(^(prn)$)|^(prn)\..*|(^(aux)$)|^(aux)\..*|(^(nul)$)|^(nul)\..*|(^(com)[1-9]$)|^(com)[1-9]\..*|(^(lpt)[1-9]$)|^(lpt)[1-9]\..*)|^\s+|.*\s$)(^[^\\\/\:\*\?\"\<\>\|]{1,255}$)/,
  649. inputErrorMessage: "不允许这样命名",
  650. inputValue: file.name,
  651. })
  652. .then(async ({ value }) => {
  653. const res = await renameQiniuFileAndRecord({
  654. id: file.id,
  655. file_name: file.name,
  656. file_name_new: value,
  657. qiniu_key: file.qiniu_key,
  658. });
  659. // console.log(res);
  660. if (res.code == 0) {
  661. ElMessage.success(res.msg);
  662. initMaterialPage(currentParentId.value);
  663. }
  664. })
  665. .catch(() => {
  666. // ElMessage({
  667. // type: "info",
  668. // message: "Input canceled",
  669. // });
  670. });
  671. }
  672. //获取下载链接
  673. async function getUrl(file) {
  674. ElMessageBox.alert(
  675. "<strong>" + file.qiniu_address + "</strong>",
  676. "下载链接",
  677. {
  678. dangerouslyUseHTMLString: true,
  679. showClose: false,
  680. }
  681. );
  682. }
  683. //从七牛云删除文件并且清除数据库记录
  684. async function deleteFile(file) {
  685. // console.log(file);
  686. ElMessageBox.confirm("确定删除此文件?", "警告", {
  687. type: "warning",
  688. })
  689. .then(async () => {
  690. const res = await deleteQiniuFileAndRecord({
  691. id: file.id,
  692. qiniu_key: file.qiniu_key,
  693. });
  694. if (res.code == 0) {
  695. ElMessage.success(res.msg);
  696. initMaterialPage(currentParentId.value);
  697. }
  698. })
  699. .catch(() => null);
  700. }
  701. //下载文件
  702. async function downloadFile(file) {
  703. // console.log(file);
  704. // console.log(file.qiniu_address);
  705. // let url = window.URL.createObjectURL(new Blob([file.qiniu_address]));
  706. // let link = document.createElement("a");
  707. // link.style.display = "none";
  708. // link.href = url;
  709. // link.setAttribute("download", file.name); //指定下载后的文件名,防跳转
  710. // document.body.appendChild(link);
  711. // link.click();
  712. // // 释放内存
  713. // window.URL.revokeObjectURL(link.href);
  714. // 创建 a 标签
  715. const a = document.createElement("a");
  716. // 创建一个点击事件
  717. const event = new MouseEvent("click");
  718. // 将 a 的 download 属性设置为想要下载的名称
  719. a.download = file.name || "文件名称";
  720. // 将生成的 url 设置为 a.href 属性
  721. a.href = file.qiniu_address;
  722. // 打开新的窗口(如果是一个图片类型的文件,在浏览器打开新的标签页打开)
  723. // a.target = "_blank";
  724. // 实现触发生成的 a 标签
  725. a.dispatchEvent(event);
  726. }
  727. //获取七牛token
  728. async function getToken() {
  729. const res = await getQiniuToken();
  730. if (res.code === 0) {
  731. qiniuData.value.token = res.data.token;
  732. qiniuData.value.cName = res.data.cName;
  733. // console.log(qiniuData);
  734. } else {
  735. ElMessageBox.alert(err, "提示", {
  736. confirmButtonText: "关闭",
  737. });
  738. }
  739. }
  740. async function selectChanged(aaa) {
  741. // 查询该类型对应最新版本号并+1
  742. const res = await queryVersionByType({
  743. task_id: aaa.task_id,
  744. file_type: fileTypeOptions.value[uploadForm.value.type].typeId,
  745. });
  746. // console.log(res);
  747. if (res.code == 0) {
  748. uploadForm.value.qiniuVersion = parseInt(res.data.fileVersion) + 1;
  749. } else {
  750. }
  751. showVersion.value = true;
  752. showUpload.value = true;
  753. }
  754. // 取消上传文件
  755. async function cancelUp(aaa) {
  756. //中断文件传输
  757. cance.value = true;
  758. uploadVisible.value = false;
  759. // console.log(qiniuData.value.key);
  760. var qiniu_key = qiniuData.value.key;
  761. if (qiniu_key == "") {
  762. return;
  763. }
  764. //取消上传时从七牛云删除已上传的文件
  765. const res = await deleteQiniuFile({
  766. qiniu_key: qiniu_key,
  767. });
  768. // console.log(res);
  769. if (res.code == 0) {
  770. ElMessage.success(res.msg);
  771. }
  772. }
  773. //上传前处理
  774. function beforeAvatarUpload(file) {
  775. progressFlag.value = false;
  776. const fileFirst = file.name.substring(0, file.name.lastIndexOf("."));
  777. const fileLast = file.name.substring(file.name.lastIndexOf(".") + 1);
  778. //
  779. const limitType = fileTypeOptions.value[uploadForm.value.type].type;
  780. let isALL = limitType.substring(limitType.lastIndexOf(".") + 1);
  781. if (isALL == "*") {
  782. } else if (fileLast == "" || isALL != fileLast) {
  783. ElMessageBox.alert("只能上传" + isALL + "格式的文件", "提示", {
  784. confirmButtonText: "关闭",
  785. });
  786. return false;
  787. }
  788. let folder =
  789. "shuyou/" +
  790. uploadForm.value.task_id +
  791. "|" +
  792. uploadForm.value.task_name +
  793. "/" +
  794. fileTypeOptions.value[uploadForm.value.type].name +
  795. "/" +
  796. fileFirst +
  797. "_" +
  798. new Date().getTime() +
  799. "." +
  800. fileLast;
  801. uploadForm.value.fileName =
  802. fileFirst + "_" + new Date().getTime() + "." + fileLast;
  803. qiniuData.value.key = folder;
  804. // console.log(folder);
  805. disabledUpload.value = true;
  806. }
  807. //确定上传,记录文件信息在数据库中
  808. async function recordFile(aaa) {
  809. console.log(aaa);
  810. const params = {
  811. parent_id: aaa.parentId,
  812. task_id: aaa.task_id,
  813. file_version: aaa.qiniuVersion,
  814. qiniu_address: aaa.qiniuAddress,
  815. file_name: aaa.fileName,
  816. file_type: aaa.type,
  817. file_type_name: aaa.type_name,
  818. qiniu_hash: aaa.qiniuHash,
  819. qiniu_key: aaa.key,
  820. };
  821. let res = await addQiniuFile(params);
  822. if (res.code === 0) {
  823. uploadVisible.value = false;
  824. ElMessage.success("文件记录成功!!!");
  825. }
  826. cance.value = false;
  827. initMaterialPage(currentParentId.value);
  828. }
  829. //上传成功
  830. function handleAvatarSuccess(res) {
  831. // console.log(res);
  832. // 七牛云对外域名qiniuData.value.cName
  833. const fileUrl = qiniuData.value.cName + res.key;
  834. const fileHash = res.hash;
  835. // console.log(fileUrl);
  836. uploadForm.value.key = res.key;
  837. uploadForm.value.qiniuAddress = fileUrl;
  838. uploadForm.value.qiniuHash = fileHash;
  839. uploadForm.value.type_name =
  840. fileTypeOptions.value[uploadForm.value.type].name;
  841. uploadForm.value.type = fileTypeOptions.value[uploadForm.value.type].typeId;
  842. setTimeout(() => {
  843. recordFile(uploadForm.value);
  844. }, 1000); // 一秒后执行保存
  845. }
  846. //进度条显示
  847. function onProgress(event, file, fileList) {
  848. progressFlag.value = true; // 显示进度条
  849. progress.value = parseInt(event.percent); // 动态获取文件上传进度
  850. status.value = "exception";
  851. if (progress.value >= 100) {
  852. status.value = "success";
  853. // setTimeout(() => {
  854. // progressFlag.value = false;
  855. // }, 1000); // 一秒后关闭进度条
  856. } else if (progress.value >= 50) {
  857. status.value = "warning";
  858. }
  859. }
  860. //自定义上传操作
  861. function uploadHttpRequest(option) {
  862. // 开始上传,token从后端获取, key自定义也可从后端获取(key可以说是文件名)
  863. const putExtra = {};
  864. const config = {
  865. checkByServer: false,
  866. checkByMD5: false,
  867. forceDirect: false,
  868. useCdnDomain: true,
  869. disableStatisticsReport: false,
  870. concurrentRequestLimit: 10,
  871. retryCount: 4,
  872. chunkSize: 100, //分片时每片大小
  873. // region: qiniu.region.z2,
  874. debugLogLevel: "OFF",
  875. };
  876. const observable = qiniu.upload(
  877. option.file,
  878. qiniuData.value.key,
  879. qiniuData.value.token,
  880. putExtra,
  881. config
  882. );
  883. let subscription = observable.subscribe({
  884. // 以下相关代码就是将七牛云的回调函数给el-upload
  885. //让el-upload能够展示进度条
  886. next(res) {
  887. option.onProgress({ percent: res.total.percent });
  888. if (cance.value == true) {
  889. console.log("上传取消");
  890. ElMessage.error("上传取消");
  891. subscription.unsubscribe(); // 上传取消
  892. }
  893. },
  894. error(err) {
  895. option.onError(err);
  896. },
  897. complete(res) {
  898. option.onSuccess(res);
  899. },
  900. });
  901. return subscription;
  902. }
  903. function toggleSelect(item, id) {
  904. // 切换选择文件或文件夹的激活样式
  905. // this.id = id;
  906. // if (item.active) {
  907. // Vue.set(item, "active", false); // 为item添加不存在的属性,需要使用vue提供的Vue.set( object, key, value )方法
  908. // const index = this.activeItems.indexOf(id);
  909. // if (index > -1) {
  910. // this.activeItems.splice(index, 1);
  911. // }
  912. // } else {
  913. // Vue.set(item, "active", true);
  914. // this.activeItems.push(id);
  915. // }
  916. // if (this.activeItems.length > 0) {
  917. // // 当有文件被激活时,显示重命名,删除,移动操作按钮
  918. // this.activeFlag = true;
  919. // } else {
  920. // this.activeFlag = false;
  921. // }
  922. // if (this.activeItems.length > 1) {
  923. // // 当有两个以上的文件被选中的时候,重命名,移动操作按钮不可用
  924. // this.activeFlagNotReame = true;
  925. // } else {
  926. // this.activeFlagNotReame = false;
  927. // }
  928. // this.activeFlagMoveble = true;
  929. // this.files.forEach((item) => {
  930. // if (item.active) {
  931. // if (item.resType !== 0) {
  932. // // 只要有一个不是文件夹的被选中,就可以移动
  933. // this.activeFlagMoveble = false;
  934. // }
  935. // }
  936. // });
  937. }
  938. //===================
  939. const rules = ref({
  940. folder_type: [
  941. { required: true, message: "请选择文件夹类型", trigger: "blur" },
  942. ],
  943. folder_name: [{ required: true, message: "请输入文件夹名", trigger: "blur" }],
  944. });
  945. const page = ref(1);
  946. const pageSize = ref(20);
  947. const searchInfo = ref({});
  948. let breadcrumbList = ref([
  949. {
  950. id: 0,
  951. name: "根目录",
  952. },
  953. ]); // 面包屑
  954. let files = ref([]); // 文件数据列表
  955. const defultThumUrl = ref(defultThumUrlimage); // 默认文件夹的样式图片
  956. function clickBreadcrumb(breadcrumb, index) {
  957. breadcrumbList.value = breadcrumbList.value.slice(0, index + 1);
  958. currentParentId.value = breadcrumb.id;
  959. initMaterialPage(currentParentId.value);
  960. if (breadcrumbList.value.length == 1) {
  961. createButtonVisible.value = true;
  962. } else {
  963. createButtonVisible.value = false;
  964. }
  965. }
  966. function dbClickOpenFile(file) {
  967. // 双击文件操作
  968. if (file.isFile) {
  969. return;
  970. }
  971. // 打开的是文件夹
  972. breadcrumbList.value.push({ id: file.id, name: file.name });
  973. currentParentId.value = file.id;
  974. // console.log(file);
  975. // console.log(currentParentId.value);
  976. initMaterialPage(currentParentId.value);
  977. if (breadcrumbList.value.length == 1) {
  978. createButtonVisible.value = true;
  979. } else {
  980. createButtonVisible.value = false;
  981. }
  982. }
  983. import fileTypeDll from '@/assets/file_type_dll.svg'
  984. import fileTypeId from '@/assets/file_type_ld.png'
  985. import fileTypeApk from '@/assets/file_type_apk.svg'
  986. import fileTypeYeshen from '@/assets/file_type_yeshen.webp'
  987. import fileTypeOther from '@/assets/file_type_other.svg'
  988. async function initMaterialPage(id = 0) {
  989. searchInfo.value.parent_id = id;
  990. files.value = [];
  991. // 初始化获取
  992. const table = await getFolderFileList({
  993. // page: page.value,
  994. // pageSize: pageSize.value,
  995. ...searchInfo.value,
  996. });
  997. if (table.code === 0) {
  998. // console.log(table);
  999. const folderList = table.data.folderList;
  1000. const fileList = table.data.fileList;
  1001. if (folderList != null) {
  1002. for (let i = 0; i < table.data.folderList.length; i++) {
  1003. var temp = {
  1004. id: table.data.folderList[i].id,
  1005. name: table.data.folderList[i].name,
  1006. isFile: false,
  1007. };
  1008. files.value.push(temp);
  1009. }
  1010. }
  1011. if (fileList != null) {
  1012. for (let i = 0; i < table.data.fileList.length; i++) {
  1013. var temp = {
  1014. id: table.data.fileList[i].id,
  1015. name: table.data.fileList[i].file_name,
  1016. isFile: true,
  1017. update_time: table.data.fileList[i].update_time,
  1018. file_version: table.data.fileList[i].file_version,
  1019. qiniu_address: table.data.fileList[i].qiniu_address,
  1020. qiniu_key: table.data.fileList[i].qiniu_key,
  1021. qiniu_hash: table.data.fileList[i].qiniu_hash,
  1022. thumUrl: "",
  1023. };
  1024. switch (table.data.fileList[i].file_type) {
  1025. case 1:
  1026. temp.thumUrl = fileTypeDll;
  1027. break;
  1028. case 2:
  1029. temp.thumUrl = fileTypeId;
  1030. break;
  1031. case 3:
  1032. temp.thumUrl = fileTypeApk;
  1033. break;
  1034. case 4:
  1035. temp.thumUrl = fileTypeYeshen;
  1036. break;
  1037. default:
  1038. temp.thumUrl = fileTypeOther;
  1039. break;
  1040. }
  1041. files.value.push(temp);
  1042. }
  1043. }
  1044. }
  1045. }
  1046. //获取下拉框list
  1047. const getSelectList = async () => {
  1048. const taskListRes = await getAllTaskSimple({
  1049. page: 1,
  1050. pageSize: 999,
  1051. });
  1052. let taskList = [];
  1053. const data = taskListRes.data.list;
  1054. data.forEach((e) => {
  1055. taskList.push({
  1056. value: e.task_id + "|" + e.task_name,
  1057. label: e.task_id + "_" + e.task_name,
  1058. });
  1059. });
  1060. taskOptions.value = taskList;
  1061. //游戏负责人列表===============================
  1062. const directorRes = await getDirectorList();
  1063. let directorList = [];
  1064. const data3 = directorRes.data.list;
  1065. data3.forEach((e) => {
  1066. if (e.name != "备用") {
  1067. directorList.push({ value: e.name, label: e.name });
  1068. }
  1069. });
  1070. directorOptions.value = directorList;
  1071. };
  1072. const onReset = () => {
  1073. searchInfo.value = {};
  1074. };
  1075. const onSubmit = async () => {
  1076. // console.log(searchInfo.value)
  1077. files.value = [];
  1078. const table = await queryFolder({
  1079. ...searchInfo.value,
  1080. });
  1081. if (table.code === 0) {
  1082. // // console.log(table);
  1083. const folderList = table.data.folderList;
  1084. if (folderList != null) {
  1085. for (let i = 0; i < table.data.folderList.length; i++) {
  1086. var temp = {
  1087. id: table.data.folderList[i].id,
  1088. name: table.data.folderList[i].name,
  1089. isFile: false,
  1090. };
  1091. files.value.push(temp);
  1092. }
  1093. }
  1094. }
  1095. };
  1096. getSelectList();
  1097. initMaterialPage();
  1098. </script>
  1099. <style scoped lang="scss">
  1100. .button-box {
  1101. padding: 10px 20px;
  1102. .el-button {
  1103. float: right;
  1104. }
  1105. }
  1106. .warning {
  1107. color: #dc143c;
  1108. }
  1109. .clearfix:after {
  1110. content: "";
  1111. display: block;
  1112. clear: both;
  1113. }
  1114. .video-container {
  1115. min-width: 630px;
  1116. margin: 10px;
  1117. .video-header {
  1118. padding: 0 0 5px 0;
  1119. border-bottom: 1px solid #dbdbdb;
  1120. .breadcrumb {
  1121. // float: left;
  1122. height: 20px;
  1123. margin-top: 10px;
  1124. .breadcrumb-link {
  1125. cursor: pointer;
  1126. //font-size: 16px;
  1127. }
  1128. .breadcrumb-link:hover {
  1129. color: #409eff;
  1130. text-decoration: underline;
  1131. }
  1132. .breadcrumb-link-active {
  1133. // 面包屑当前激活文件夹的样式
  1134. font-weight: 700;
  1135. }
  1136. }
  1137. .header-top {
  1138. // float: right;
  1139. height: 40px;
  1140. line-height: 40px;
  1141. position: relative;
  1142. }
  1143. }
  1144. .video-main {
  1145. .list-none {
  1146. box-sizing: border-box;
  1147. position: relative;
  1148. height: 300px;
  1149. width: 100%;
  1150. margin: 5px;
  1151. display: inline-block;
  1152. }
  1153. .list-item {
  1154. border: 1px solid rgb(241, 241, 241);
  1155. border-radius: 5%;
  1156. box-sizing: border-box;
  1157. position: relative;
  1158. height: 125px;
  1159. width: 160px;
  1160. background-color: rgb(241, 241, 241);
  1161. margin: 5px;
  1162. display: inline-block;
  1163. cursor: pointer;
  1164. .inner {
  1165. height: 85px;
  1166. width: 140px;
  1167. // background-color: red;
  1168. margin: 5px 10px;
  1169. // padding: 10px 15px 10px 15px;
  1170. .icon-folder {
  1171. // 文件夹的样式
  1172. display: inline-block;
  1173. width: 80px;
  1174. height: 80px;
  1175. background-image: url("@/assets/defultThumUrl.svg");
  1176. background-size: 100% 100%;
  1177. }
  1178. .icon-thumb {
  1179. // 文件的样式
  1180. width: 80px;
  1181. height: 80px;
  1182. }
  1183. .inner-info {
  1184. float: right;
  1185. // border: 1px solid #409eff;
  1186. width: 45px;
  1187. height: 20px;
  1188. margin-top: 30px;
  1189. }
  1190. }
  1191. .file-name {
  1192. // 文件夹name样式
  1193. padding-left: 10px;
  1194. overflow: hidden;
  1195. text-overflow: ellipsis;
  1196. white-space: nowrap;
  1197. color: #424e67;
  1198. font-size: 12px;
  1199. }
  1200. .file-name:hover {
  1201. color: rgb(0, 123, 255);
  1202. }
  1203. }
  1204. .hover-cover {
  1205. width: 100px;
  1206. height: 100px;
  1207. position: absolute;
  1208. left: 10px;
  1209. top: 5px;
  1210. background-color: rgb(0, 0, 0);
  1211. opacity: 0;
  1212. text-align: center;
  1213. line-height: 100px;
  1214. font-size: 12px;
  1215. }
  1216. .list-item:hover {
  1217. background-color: rgb(212, 212, 212);
  1218. .icon-file-selected {
  1219. opacity: 0.5;
  1220. }
  1221. .hover-cover {
  1222. opacity: 0.6;
  1223. }
  1224. }
  1225. .icon-file-selected {
  1226. // 小圆点默认样式
  1227. position: absolute;
  1228. right: 5px;
  1229. top: 5px;
  1230. display: inline-block;
  1231. width: 20px;
  1232. height: 20px;
  1233. background-size: 100% 100%;
  1234. background-image: url(@/assets/selected.svg);
  1235. opacity: 0;
  1236. }
  1237. .icon-file-selected:hover {
  1238. // 小圆点hover
  1239. opacity: 1 !important;
  1240. }
  1241. .active {
  1242. // 选择文件触发激活样式
  1243. border: 1px solid #409eff;
  1244. border-radius: 8px;
  1245. .icon-file-selected {
  1246. position: absolute;
  1247. right: 5px;
  1248. top: 5px;
  1249. display: inline-block;
  1250. width: 20px;
  1251. height: 20px;
  1252. background-size: 100% 100%;
  1253. background-image: url(@/assets/selected.svg);
  1254. opacity: 1;
  1255. }
  1256. }
  1257. .active:hover {
  1258. // 激活状态小圆点透明度1
  1259. .icon-file-selected {
  1260. opacity: 1 !important;
  1261. }
  1262. }
  1263. // .loadding-message {
  1264. // // 加载loading的文字样式
  1265. // color: #424e67;
  1266. // font-size: 12px;
  1267. // text-align: center;
  1268. // }
  1269. }
  1270. }
  1271. </style>