DefaultPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <div class="main">
  3. <div class="search">
  4. <input type="text" class="search_input" placeholder="请输入关键字" />
  5. <div class="searchBtn">
  6. <img src="@/assets/images/newIndex/search.png" alt="" />
  7. <span>全局搜索</span>
  8. </div>
  9. </div>
  10. <div class="btmBox">
  11. <div class="upFile">
  12. <!-- <img
  13. src="@/assets/images/newIndex/upFolderLogo.png"
  14. class="upImg"
  15. alt=""
  16. />
  17. <span class="text1">上传你的文件</span> -->
  18. <el-upload
  19. class="upload-demo"
  20. :file-list="fileArr"
  21. :limit="10"
  22. :on-change="upBefore"
  23. :show-file-list="false"
  24. drag
  25. :http-request="onSuccess"
  26. multiple
  27. element-loading-text="上传中..."
  28. element-loading-background="rgba(255, 255, 255, 0.8)"
  29. v-loading="loadingUpload"
  30. >
  31. <img
  32. src="@/assets/images/newIndex/upFolderLogo.png"
  33. class="upImg"
  34. alt=""
  35. />
  36. <span class="text1">上传你的文件</span>
  37. </el-upload>
  38. <p class="text2">将文件拖到此处或 <span>选择文件</span></p>
  39. <div class="line"></div>
  40. <img src="@/assets/images/newIndex/scan.png" class="scanImg" alt="" />
  41. <div class="text3">扫描文件</div>
  42. </div>
  43. <div class="recent">
  44. <div class="top">
  45. <span>最近文件</span>
  46. </div>
  47. <div class="list">
  48. <div
  49. v-for="item in tableFileData"
  50. :key="item"
  51. @click="toFile(item)"
  52. class="oneBox"
  53. >
  54. <div class="imgBox">
  55. <img :src="setImg(item == null ? '' : item.fileType)" alt="" />
  56. </div>
  57. <div class="rightBox">
  58. <div class="text">{{ item.fileName }}</div>
  59. <div class="time">{{ item.createTime }}</div>
  60. </div>
  61. <img
  62. class="openArrow"
  63. src="@/assets/images/newIndex/CaretRight.png"
  64. alt=""
  65. />
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <ImgPreview
  72. :previewData="previewData"
  73. :copyFileType="copyFileType"
  74. :showPreview="showPreview"
  75. @closeImgPreview="closeImgPreview"
  76. ></ImgPreview>
  77. <div
  78. v-loading.fullscreen="loadingPreview"
  79. v-if="loadingPreview"
  80. class="lodingBox"
  81. ></div>
  82. </template>
  83. <script setup>
  84. import { onMounted, ref, toRaw, inject } from "vue";
  85. import { getInfo, getInfoByDirId } from "@/api/biz/info";
  86. import { listRecent, getRecent } from "@/api/biz/recent";
  87. import { setIcon, canPreviewFile } from "@/utils/index.js";
  88. import { preview } from "@/api/common/common.js";
  89. import { ElMessage, ElLoading, ElMessageBox } from "element-plus";
  90. import ImgPreview from "@/components/ImgPreview/ImgPreview.vue";
  91. import { getConfigKey } from "@/api/system/config.js";
  92. import myfile from "@/api/myfile/myfile";
  93. import documents from '@/api/document/document'
  94. import uploadApi from '@/api/upload/upload'
  95. const tableFileData = ref([]);
  96. const copyFileType = ref();
  97. const previewData = ref();
  98. const loadingPreview = ref(false);
  99. const showPreview = ref(false);
  100. let fileArr = ref([]);
  101. const useSpace = ref();
  102. let fileBig = ref(0);
  103. const allSpace = ref();
  104. const maxFileSize = ref(); //能上传的最大size
  105. const loadingUpload = ref(false);
  106. const topDirId = ref();//我的文件顶层的目录id
  107. const topSpaceId = ref();//我的文件顶层的目录id
  108. const emit = defineEmits(["openMaxmin"]);
  109. // 获取数据
  110. const getList = async () => {
  111. const resN = await listRecent({ isFolder: "N" });
  112. if (resN.code === 200) {
  113. var arr = [];
  114. resN.rows.map(async (item) => {
  115. const detail = await getInfo(item.relaId);
  116. tableFileData.value.push(detail.data);
  117. });
  118. }
  119. };
  120. // 打开最近文件
  121. const toFile = async (row) => {
  122. copyFileType.value = row.fileType;
  123. console.log("row", row);
  124. loadingPreview.value = true;
  125. const filePreview = canPreviewFile(row.fileType);
  126. if (filePreview) {
  127. loadingPreview.value = false;
  128. emit(
  129. "openMaxmin",
  130. row.fileName,
  131. `${window.location.origin}/fileEdit?clickRowId=${row.docId}&canEdit=0&canCopy=0&history=0&fileId=0`
  132. );
  133. } else {
  134. const res = await preview(row.docId);
  135. showPreview.value = true;
  136. previewData.value = URL.createObjectURL(res);
  137. loadingPreview.value = false;
  138. }
  139. };
  140. // 设置icon
  141. const setImg = (type) => {
  142. return setIcon(type);
  143. };
  144. //关闭图片预览事件
  145. const closeImgPreview = () => {
  146. // console.log('close');
  147. showPreview.value = false;
  148. };
  149. // 限制上传文件大小
  150. const upBefore = (file, files) => {
  151. const maxSize = (maxFileSize.value - 0) * 1024 * 1024;
  152. // console.log('maxSize',maxSize);
  153. if (file.size > maxSize) {
  154. files.pop();
  155. ElMessage({
  156. message:
  157. file.name + "上传失败,上传文件大小最大为" + maxFileSize.value + "M",
  158. type: "error",
  159. });
  160. } else {
  161. fileBig.value = file.size + fileBig.value;
  162. // fileArr.value.push(file.raw)
  163. }
  164. // console.log('filesend',files);
  165. };
  166. // 我的文件的空间信息
  167. function getSpaceList() {
  168. myfile.fileType(3).then((res) => {
  169. useSpace.value = res.data.usedCap;
  170. allSpace.value = res.data.spaceCap;
  171. });
  172. }
  173. //获取我的文件顶层的目录id
  174. const getDirId = ()=>{
  175. documents.getTop(3).then(res => {
  176. topDirId.value = res.dirId
  177. topSpaceId.value = res.spaceId
  178. })
  179. }
  180. function onSuccess(files, val) {
  181. // console.log('suFiles',files);
  182. const maxSize = (maxFileSize.value - 0) * 1024 * 1024;
  183. if (files.file.size < maxSize) {
  184. fileArr.value.push(files.file);
  185. }
  186. sureUpload()
  187. }
  188. // 确认上传
  189. function sureUpload() {
  190. loadingUpload.value = true;
  191. if (
  192. useSpace.value * 1024 * 1024 + fileBig.value / 1024 >
  193. allSpace.value * 1024 * 1024
  194. ) {
  195. ElMessage({
  196. message: "超过最大容量,请联系管理员扩容",
  197. type: "error",
  198. });
  199. loadingUpload.value = false;
  200. return;
  201. } else {
  202. if (fileArr.value.length > 0) {
  203. // console.log('fileArr',fileArr.value);
  204. let form = new FormData();
  205. for (var i = 0; i < fileArr.value.length; i++) {
  206. form.append("files", fileArr.value[i]);
  207. }
  208. form.append("spaceId", topSpaceId.value);
  209. form.append("dirId", topDirId.value);
  210. // console.error(fileArr.value);
  211. uploadApi
  212. .uploadFileMany(form)
  213. .then((res) => {
  214. if (res.code === 200) {
  215. ElMessage({
  216. message: "上传文件成功",
  217. type: "success",
  218. });
  219. // getAllTop()
  220. refreshFile();
  221. uploadModal.value = false;
  222. loadingUpload.value = false;
  223. fileArr.value = [];
  224. fileBig.value = 0;
  225. }
  226. })
  227. .catch((err) => {
  228. loadingUpload.value = false;
  229. fileArr.value = [];
  230. });
  231. } else {
  232. loadingUpload.value = false;
  233. return ElMessage({ message: "请选择文件", type: "error" });
  234. }
  235. }
  236. }
  237. onMounted(() => {
  238. getList();
  239. getSpaceList();
  240. getDirId()
  241. getConfigKey("file.size.limit").then((response) => {
  242. // console.log('response',response);
  243. maxFileSize.value = response.msg;
  244. });
  245. });
  246. </script>
  247. <style lang="scss" scoped>
  248. .main {
  249. width: 100%;
  250. height: calc(100vh - 160px);
  251. display: flex;
  252. flex-direction: column;
  253. justify-content: center;
  254. align-items: center;
  255. }
  256. .search {
  257. width: 1232px;
  258. height: 64px;
  259. background-color: #2e8bf6;
  260. border-radius: 86px 86px 86px 86px;
  261. display: flex;
  262. justify-content: space-between;
  263. padding-right: 24px;
  264. .search_input {
  265. width: 1080px;
  266. height: 100%;
  267. border: none;
  268. outline: none;
  269. background-color: #fff;
  270. padding-left: 20px;
  271. border-radius: 86px 86px 86px 86px;
  272. }
  273. .searchBtn {
  274. color: #fff;
  275. font-size: 18px;
  276. cursor: pointer;
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. span {
  281. margin-left: 8px;
  282. }
  283. }
  284. }
  285. .btmBox {
  286. margin-top: 16px;
  287. width: 1232px;
  288. height: 624px;
  289. display: flex;
  290. justify-content: space-between;
  291. .upFile {
  292. width: 494px;
  293. height: 100%;
  294. background-color: #fff;
  295. border-radius: 16px 16px 16px 16px;
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. justify-content: center;
  300. .upImg {
  301. width: 194px;
  302. height: 128px;
  303. }
  304. .text1 {
  305. font-style: 18px;
  306. color: #030102;
  307. font-weight: bold;
  308. margin-top: 16px;
  309. margin-bottom: 8px;
  310. }
  311. .text2 {
  312. font-weight: 400;
  313. font-size: 16px;
  314. color: #7c808d;
  315. span {
  316. font-weight: 500;
  317. font-size: 16px;
  318. color: #2e8bf6;
  319. text-decoration-line: underline;
  320. }
  321. }
  322. .text3 {
  323. font-weight: 400;
  324. font-size: 14px;
  325. color: #7c808d;
  326. margin-top: 8px;
  327. }
  328. .line {
  329. margin-top: 16px;
  330. width: 124px;
  331. height: 1px;
  332. border-top: 1px solid #dbdbdb;
  333. }
  334. .scanImg {
  335. width: 32px;
  336. height: 32px;
  337. margin-top: 16px;
  338. }
  339. }
  340. .recent {
  341. width: 722px;
  342. height: 100%;
  343. background-color: #fff;
  344. border-radius: 16px 16px 16px 16px;
  345. padding: 24px;
  346. .top {
  347. width: 100%;
  348. height: 42px;
  349. border-bottom: 1px solid #dbdbdb;
  350. span {
  351. font-weight: bold;
  352. font-size: 18px;
  353. color: #030102;
  354. }
  355. }
  356. .list {
  357. width: 100%;
  358. height: calc(624px - 42px - 1px - 24px);
  359. overflow-y: auto;
  360. // padding-top: 12px;
  361. box-sizing: border-box;
  362. .oneBox {
  363. width: 100%;
  364. height: 60px;
  365. padding: 8px 22px;
  366. box-sizing: border-box;
  367. border-radius: 12px 12px 12px 12px;
  368. display: flex;
  369. align-items: center;
  370. .imgBox {
  371. width: 44px;
  372. height: 44px;
  373. border-radius: 8px 8px 8px 8px;
  374. border: 1px solid #d0d6e6;
  375. display: flex;
  376. justify-content: center;
  377. align-items: center;
  378. img {
  379. width: 32px;
  380. height: 32px;
  381. }
  382. }
  383. .rightBox {
  384. margin-left: 12px;
  385. width: calc(100% - 44px - 12px);
  386. display: flex;
  387. flex-direction: column;
  388. justify-content: space-between;
  389. .text {
  390. font-weight: bold;
  391. font-size: 16px;
  392. color: #030102;
  393. }
  394. .time {
  395. font-weight: 500;
  396. font-size: 12px;
  397. color: #7c808d;
  398. }
  399. }
  400. .openArrow {
  401. width: 20px;
  402. height: 20px;
  403. }
  404. &:hover {
  405. background: #f6f6f6;
  406. .imgBox {
  407. border: 1px solid #2e8bf6;
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. ::v-deep .el-upload-dragger {
  415. display: flex;
  416. flex-direction: column;
  417. justify-content: center;
  418. }
  419. </style>