1
0

TableComponent.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. <template>
  2. <div class="mymediaLibrary">
  3. <!-- 表头搜索 -->
  4. <el-form :inline="true" :model="searchForm">
  5. <el-form-item class="formitem">
  6. <el-input
  7. v-model="searchForm.name"
  8. @input="submitClick"
  9. @keydown.enter="submitClick"
  10. :placeholder="$t('mediaLibrary.addFilePlace')"
  11. size="default"
  12. :prefix-icon="Search"
  13. ></el-input>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-select
  17. style="width: 120px"
  18. v-model="searchForm.fileType"
  19. @change="submitClick"
  20. :placeholder="$t('mediaLibrary.fileType.0')"
  21. >
  22. <el-option
  23. v-for="(item, index) in [
  24. $t('mediaLibrary.fileType.0'),
  25. $t('mediaLibrary.fileType.1'),
  26. $t('mediaLibrary.fileType.2'),
  27. $t('mediaLibrary.fileType.3'),
  28. $t('mediaLibrary.fileType.4'),
  29. $t('mediaLibrary.fileType.5'),
  30. ]"
  31. :key="index"
  32. :label="item"
  33. :value="index"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item style="margin-right: 0px">
  38. <el-select
  39. class="groupingSelcet"
  40. v-model="searchForm.dictId"
  41. style="width: 120px"
  42. @change="submitClick"
  43. :placeholder="$t('mediaLibrary.fileType.0')"
  44. >
  45. <el-option
  46. v-for="(item, index) in [...allList, ...dictIdList]"
  47. :key="index"
  48. :label="item.dictName"
  49. :value="item.id"
  50. />
  51. </el-select>
  52. <div class="grouping" @click="handleAddfz">
  53. <img :src="groupingSvg" alt="" />
  54. </div>
  55. </el-form-item>
  56. <el-form-item style="float: right; margin-right: 0">
  57. <el-button
  58. v-if="photography == 1"
  59. @click="windowOpen({ type: 'photography', library: true })"
  60. >{{ $t("mediaLibrary.photography") }}</el-button
  61. >
  62. <el-button
  63. v-if="modeling == 1"
  64. @click="windowOpen({ type: 'modeling', library: true })"
  65. >{{ $t("mediaLibrary.Modeling") }}</el-button
  66. >
  67. <!--v-if="photography == 1" <el-button type="primary" @click="handleAddfz">{{$t('mediaLibrary.grouping')}}</el-button> -->
  68. <el-button type="primary" @click="handleAdd">{{
  69. $t("mediaLibrary.upload")
  70. }}</el-button>
  71. </el-form-item>
  72. </el-form>
  73. <!-- 表格 -->
  74. <el-table
  75. tooltip-effect="dark"
  76. ref="tableRef"
  77. size="large"
  78. :data="tableData"
  79. style="width: 100%"
  80. :row-class-name="tableRowClassName"
  81. >
  82. <el-table-column
  83. prop="name"
  84. :label="$t('program.case.title')"
  85. min-width="300px"
  86. show-overflow-tooltip
  87. >
  88. <template #default="scope">
  89. <a
  90. style="color: var(--primaryColor); cursor: pointer"
  91. v-if="scope.row.fileUrl"
  92. target="_blank"
  93. :title="scope.row.name"
  94. @click="floadileUrl(scope.row)"
  95. >
  96. {{ scope.row.name }}</a
  97. >
  98. </template>
  99. </el-table-column>
  100. <el-table-column
  101. prop="fileTypeStr"
  102. :label="ui18n.t('mediaLibrary.fileTypeStr')"
  103. min-width="100px"
  104. show-overflow-tooltip
  105. >
  106. <template #default="scope">
  107. {{$t(`mediaLibrary.fileType.${scope.row.fileType+1}`)}}
  108. </template>
  109. </el-table-column>
  110. <el-table-column
  111. v-for="column in columns"
  112. :key="column.prop"
  113. :prop="column.prop"
  114. show-overflow-tooltip
  115. align="center"
  116. :min-width="column.width"
  117. :label="column.label"
  118. ></el-table-column>
  119. <el-table-column
  120. align="center"
  121. :label="$t('mediaLibrary.operate')"
  122. width="150"
  123. >
  124. <template #default="{ row }">
  125. <!-- <el-button type="primary" text style="color: var(--primaryColor)" size="small" @click="handleEdit(row)">
  126. 编辑
  127. </el-button> -->
  128. <span
  129. class="oper-span"
  130. style="color: var(--primaryColor)"
  131. @click="handleEdit(row)"
  132. >
  133. {{ $t("sys.edit") }}
  134. </span>
  135. <span
  136. class="oper-span"
  137. @click="del(row)"
  138. style="color: var(--primaryColor)"
  139. >
  140. {{ $t("sys.delete") }}
  141. </span>
  142. </template>
  143. </el-table-column>
  144. </el-table>
  145. <!-- 分页 -->
  146. <el-pagination
  147. class="mt-3"
  148. background
  149. @size-change="handleSizeChange"
  150. @current-change="handleCurrentChange"
  151. :current-page="currentPage"
  152. :page-sizes="[10, 20, 30]"
  153. :page-size="pageSize"
  154. style="justify-content: end"
  155. layout="prev, pager, next"
  156. :total="total"
  157. >
  158. </el-pagination>
  159. <!-- 弹窗 -->
  160. <el-dialog v-model="dialogData.show" :title="dialogData.title" width="400">
  161. <el-form label-position="top" :model="form" label-width="110">
  162. <el-form-item
  163. v-if="dialogData.title == $t('sys.upload')"
  164. :label="$t('mediaLibrary.file')"
  165. :label-width="formLabelWidth"
  166. >
  167. <!-- <el-input v-model="addForm.name" autocomplete="off" /> -->
  168. <el-upload
  169. class="upload-demo"
  170. style="width: 100%"
  171. ref="upload"
  172. :multiple="false"
  173. :limit="1"
  174. :before-upload="beforeUpload"
  175. :on-exceed="handleExceed"
  176. :file-list="fileList"
  177. :http-request="() => {}"
  178. :on-preview="previewFile"
  179. :accept="accept"
  180. :before-remove="removeFile"
  181. >
  182. <el-button type="primary">
  183. {{ $t("sys.upload") }}
  184. </el-button>
  185. </el-upload>
  186. </el-form-item>
  187. <el-form-item
  188. :label="
  189. dialogData.title == $t('sys.upload')
  190. ? $t('mediaLibrary.dictName')
  191. : $t('mediaLibrary.setGrouping')
  192. "
  193. :label-width="formLabelWidth"
  194. >
  195. <el-select
  196. style="width: 100%"
  197. v-model="addForm.dictId"
  198. :placeholder="$t('mediaLibrary.tips.dictId')"
  199. >
  200. <el-option
  201. v-for="(item, index) in dictIdList"
  202. :key="index"
  203. :label="item.dictName"
  204. :value="item.id"
  205. />
  206. </el-select>
  207. </el-form-item>
  208. <div v-if="dialogData.title == $t('sys.upload')">
  209. <div style="margin-bottom: 10px">
  210. {{ $t("mediaLibrary.tips.uplooadfiletype")
  211. }}{{ $t("mediaLibrary.tips.uplooadSize") }}
  212. </div>
  213. <!-- <span>注意:模型需使用zip包上传。包含贴图、模型、mtl文件,包内不得包含文件夹。</span> -->
  214. <div style="margin-bottom: 10px">
  215. <div>
  216. {{ $t("mediaLibrary.tips.objtips") }}
  217. </div>
  218. <img style="width: 150px" :src="obj" alt="" />
  219. </div>
  220. <div style="margin-bottom: 10px">
  221. <div>
  222. {{ $t("mediaLibrary.tips.osgbtips") }}
  223. </div>
  224. <img style="width: 150px" :src="osgb" alt="" />
  225. </div>
  226. </div>
  227. </el-form>
  228. <template #footer>
  229. <div class="dialog-footer">
  230. <el-button @click="dialogData.show = false">{{
  231. $t("sys.cancel")
  232. }}</el-button>
  233. <el-button type="primary" @click="handleuploadAdd">
  234. {{ $t("sys.enter") }}
  235. </el-button>
  236. </div>
  237. </template>
  238. </el-dialog>
  239. <!-- 修改分组 -->
  240. <el-dialog
  241. v-model="dialogData.fzshow"
  242. :title="$t('mediaLibrary.grouping')"
  243. width="400"
  244. >
  245. <el-form label-position="top" :model="form" label-width="50">
  246. <el-form-item
  247. :label="$t('mediaLibrary.addgrouping')"
  248. :label-width="formLabelWidth"
  249. >
  250. <el-input
  251. v-model="dialogData.fzName"
  252. maxlength="50"
  253. show-word-limit
  254. style="width: 278px"
  255. />
  256. <el-button
  257. style="margin-left: 20px; width: 60px"
  258. @click="handlefzAdd"
  259. >{{ $t("common.add") }}</el-button
  260. >
  261. </el-form-item>
  262. <div class="itemTitle">
  263. <p>{{ $t("mediaLibrary.groupingList") }}</p>
  264. <div class="itemTitleList">
  265. <div class="itemTitle-list" v-if="!dictIdList?.length">
  266. {{ $t("program.undata") }}
  267. </div>
  268. <div
  269. class="itemTitle-list"
  270. v-for="(item, index) in dictIdList"
  271. :key="index"
  272. >
  273. <span class="name">{{ item.dictName }}</span>
  274. <span class="del" @click="hanleFzDle(item)">{{
  275. $t("sys.delete")
  276. }}</span>
  277. </div>
  278. </div>
  279. </div>
  280. </el-form>
  281. <template #footer>
  282. <div class="dialog-footer">
  283. <el-button @click="dialogData.fzshow = false">{{
  284. $t("sys.cancel")
  285. }}</el-button>
  286. <el-button type="primary" @click="dialogData.fzshow = false">
  287. {{ $t("sys.enter") }}
  288. </el-button>
  289. </div>
  290. </template>
  291. </el-dialog>
  292. <!-- //查看资源下载 -->
  293. <el-dialog
  294. v-model="dialogDowm.show"
  295. :title="$t('sys.query')"
  296. :width="dialogDowm.type == 4 ? 800 : 600"
  297. @close="handleClose"
  298. >
  299. <div class="showContent">
  300. <img
  301. style="width: 100%; object-fit: cover"
  302. :src="dialogDowm.url"
  303. alt=""
  304. v-if="dialogDowm.type == 0"
  305. />
  306. <video
  307. ref="audio"
  308. controls
  309. style="width: 100%; max-height: 300px"
  310. :style="{ height: dialogDowm.type == 2 ? '50px' : 'auto' }"
  311. :src="dialogDowm.url"
  312. alt=""
  313. v-else-if="dialogDowm.type == 1 || dialogDowm.type == 2"
  314. />
  315. <iframe
  316. style="width: 100%; height: 400px"
  317. v-else
  318. :src="dialogDowm.url"
  319. frameborder="0"
  320. ></iframe>
  321. </div>
  322. <template #footer>
  323. <div class="dialog-footer">
  324. <el-button @click="dialogDowm.show = false">{{
  325. $t("sys.cancel")
  326. }}</el-button>
  327. <el-button
  328. v-if="dialogDowm.type == 0"
  329. type="primary"
  330. @click="hanleDown"
  331. >
  332. {{ $t("sys.download") }}
  333. </el-button>
  334. </div>
  335. </template>
  336. </el-dialog>
  337. </div>
  338. </template>
  339. <script setup>
  340. import { Search } from "@element-plus/icons-vue";
  341. import { ref, watch, onMounted } from "vue";
  342. import {
  343. getByKeyList,
  344. getfzdel,
  345. getdictFiledel,
  346. getaddOrUpdate,
  347. setFileaddOrUpdate,
  348. uploadFile,
  349. getUploadProcess,
  350. getUrlSrc,
  351. } from "@/store/case";
  352. import dayjs from "dayjs";
  353. import obj from "@/assets/images/obj.jpg";
  354. import osgb from "@/assets/images/osgb.jpg";
  355. import { ElMessage, ElMessageBox, genFileId } from "element-plus";
  356. import { ui18n } from "@/i18n";
  357. import { windowOpen } from "@/util";
  358. import { getUrlData } from "@/store/user";
  359. import groupingSvg from "@/assets/images/grouping.svg";
  360. import { ElLoading } from "element-plus";
  361. // 定义 props
  362. const props = defineProps({
  363. columns: {
  364. type: Array,
  365. default: () => [],
  366. },
  367. searchColumns: {
  368. type: Array,
  369. default: () => [],
  370. },
  371. getData: {
  372. type: Function,
  373. required: true,
  374. },
  375. });
  376. // 定义响应式数据
  377. const searchForm = ref({
  378. name: "",
  379. fileType: 0,
  380. dictId: "0",
  381. });
  382. const addForm = ref({
  383. fileType: "",
  384. dictId: "",
  385. name: "",
  386. });
  387. const dialogDowm = ref({
  388. show: false,
  389. url: "",
  390. type: "",
  391. data: {},
  392. });
  393. const dialogData = ref({
  394. show: false,
  395. title: ui18n.t("sys.upload"),
  396. data: {},
  397. fzshow: false,
  398. fzName: "",
  399. fzList: [],
  400. });
  401. const upload = ref(null);
  402. const file = ref(null);
  403. const audio = ref(null);
  404. const loadingText = ref("0%");
  405. const accept = ".jpg,.png,.jpeg,.mp4,.wav,.mp3,.shp,.zip";
  406. const handleClose = () => {
  407. console.log("handleClose", audio.value);
  408. if (audio.value) {
  409. audio.value.pause();
  410. }
  411. };
  412. const hanleFzDle = (item) => {
  413. ElMessageBox.confirm(
  414. ui18n.t("mediaLibrary.tips.deltext"),
  415. ui18n.t("sys.dialogTitle"),
  416. {
  417. confirmButtonText: ui18n.t("sys.enter"),
  418. cancelButtonText: ui18n.t("sys.cancel"),
  419. }
  420. ).then(async () => {
  421. await getfzdel(item);
  422. dictIdList.value = dictIdList.value.filter((item1) => item1.id !== item.id);
  423. searchForm.value.dictId = "0";
  424. initData();
  425. ElMessage({
  426. type: "success",
  427. message: ui18n.t("mediaLibrary.tips.del"),
  428. });
  429. });
  430. console.log("upload", file);
  431. };
  432. const { photography, modeling } = getUrlData();
  433. const previewFile = (file) => {
  434. console.log("previewFile", file);
  435. };
  436. const handleEdit = (data) => {
  437. addForm.value.dictId = data.dictId;
  438. console.log("data", data, addForm.value);
  439. dialogData.value = {
  440. show: true,
  441. title: ui18n.t("mediaLibrary.setGrouping"),
  442. data,
  443. };
  444. };
  445. const removeFile = () => {
  446. fileList.value = [];
  447. return true;
  448. };
  449. const handleAdd = () => {
  450. fileList.value = [];
  451. addForm.value.dictId = "";
  452. dialogData.value.title = ui18n.t("sys.upload");
  453. setTimeout(() => {
  454. dialogData.value.show = true;
  455. }, 100);
  456. };
  457. const handlefzAdd = async () => {
  458. let params = {
  459. dictName: dialogData.value.fzName?.trim(),
  460. };
  461. if (!params.dictName) {
  462. return ElMessage.error(ui18n.t("mediaLibrary.tips.placeholderName"));
  463. }
  464. await getaddOrUpdate(params);
  465. ElMessage({
  466. type: "success",
  467. message: ui18n.t("mediaLibrary.tips.add"),
  468. });
  469. getFzlist();
  470. dialogData.value.fzName = "";
  471. };
  472. const handleAddfz = () => {
  473. dialogData.value.fzshow = true;
  474. };
  475. const handleuploadAdd = async () => {
  476. console.log("formData", dialogData.value.title);
  477. if (dialogData.value.title != ui18n.t("sys.upload")) {
  478. if (!addForm.value.dictId)
  479. return ElMessage.error(ui18n.t("mediaLibrary.tips.dictId"));
  480. await setFileaddOrUpdate({
  481. id: dialogData.value.data?.id,
  482. dictId: addForm.value.dictId,
  483. });
  484. initData();
  485. dialogData.value.show = false;
  486. dialogData.value.title = "";
  487. ElMessage({
  488. type: "success",
  489. message: ui18n.t("mediaLibrary.tips.operate"),
  490. });
  491. } else {
  492. const formData = new FormData();
  493. const file = fileList.value && fileList.value[0];
  494. if (!file) return ElMessage.error(ui18n.t("common.NoFilesSelected"));
  495. formData.append("file", file);
  496. formData.append("dictId", addForm.value.dictId);
  497. console.log(file, formData, "formData");
  498. const loading = ElLoading.service({
  499. lock: true,
  500. text: loadingText.value,
  501. background: "rgba(0, 0, 0, 0.7)",
  502. });
  503. windowOpen({type: 'event', data: 'menu-disabled'})
  504. uploadFile({ file, dictId: addForm.value.dictId }, (completeProgress) => {
  505. console.log("上传进度", completeProgress);
  506. // props.progress = completeProgress; //上传过程
  507. loadingText.value = completeProgress + "%";
  508. loading.setText(ui18n.t("mediaLibrary.tips.uplooad") + loadingText.value);
  509. })
  510. .then(async (res) => {
  511. console.log("上传进度", res);
  512. if (res.data?.status != -1) {
  513. loading.close();
  514. windowOpen({type: 'event', data: 'menu-enabled'})
  515. initData();
  516. dialogData.value.show = false;
  517. ElMessage({
  518. type: "success",
  519. message: res.data?.status == 0 ? ui18n.t("record.backRun"):ui18n.t("mediaLibrary.tips.uplooadSuccess"),
  520. });
  521. getFileStatus(res.data.id);
  522. } else {
  523. ElMessage.error(ui18n.t("mediaLibrary.tips.uplooadErr"));
  524. }
  525. })
  526. .catch((err) => {
  527. loading.close();
  528. windowOpen({type: 'event', data: 'menu-enabled'})
  529. });
  530. console.log(formData);
  531. }
  532. };
  533. const getFileStatus = (id) => {
  534. getUploadProcess(id).then((res) => {
  535. if(res.percent == 100){
  536. initData();
  537. }else{
  538. setTimeout(()=>{
  539. getFileStatus(id)
  540. },1000)
  541. }
  542. });
  543. };
  544. // 定义方法
  545. const del = (row) => {
  546. console.log(file, "file");
  547. ElMessageBox.confirm(
  548. ui18n.t("mediaLibrary.tips.deltext"),
  549. ui18n.t("sys.dialogTitle"),
  550. {
  551. confirmButtonText: ui18n.t("sys.enter"),
  552. cancelButtonText: ui18n.t("sys.cancel"),
  553. }
  554. ).then(async () => {
  555. await getdictFiledel({ id: row.id });
  556. initData();
  557. ElMessage({
  558. type: "success",
  559. message: ui18n.t("mediaLibrary.tips.del"),
  560. });
  561. });
  562. };
  563. const allList = ref([
  564. { dictName: ui18n.t("mediaLibrary.fileType.0"), id: "0" },
  565. ]);
  566. const dictIdList = ref([]);
  567. const tableData = ref([]);
  568. const fileList = ref([]);
  569. const currentPage = ref(1);
  570. const pageSize = ref(10);
  571. const total = ref(0);
  572. onMounted(() => {
  573. // document.body.classList.toggle("dark-mode");
  574. });
  575. const getFzlist = () => {
  576. getByKeyList({}).then((res) => {
  577. console.log("getByKeyList", res);
  578. dictIdList.value = res;
  579. });
  580. };
  581. getFzlist();
  582. const submitClick = () => {
  583. console.log("submitClick", searchForm.value);
  584. currentPage.value = 1;
  585. initData();
  586. };
  587. const tableRowClassName = ({ row, rowIndex }) => {
  588. if (rowIndex === 1) {
  589. return "warning-row";
  590. } else if (rowIndex === 3) {
  591. return "success-row";
  592. }
  593. return "";
  594. };
  595. // 初始化数据
  596. const initData = async () => {
  597. const { list, totalCount } = await props.getData({
  598. ...searchForm.value,
  599. fileType:
  600. searchForm.value.fileType == 0 ? "" : searchForm.value.fileType - 1,
  601. dictId: searchForm.value.dictId == 0 ? "" : searchForm.value.dictId,
  602. pageNum: currentPage.value,
  603. pageSize: pageSize.value,
  604. });
  605. tableData.value = list.map((res) => {
  606. return {
  607. ...res,
  608. statusStr:
  609. res.status == -1
  610. ? ui18n.t("mediaLibrary.tips.uplooadErr")
  611. : res.status == 0
  612. ? ui18n.t("mediaLibrary.tips.uplooad")
  613. : ui18n.t("mediaLibrary.tips.uplooadSuccess"),
  614. createTime: dayjs(res.createTime).format("YYYY-MM-DD HH:mm:ss"),
  615. };
  616. });
  617. total.value = totalCount;
  618. };
  619. const floadileUrl = (record) => {
  620. dialogDowm.value.type = record.fileType;
  621. dialogDowm.value.data = record;
  622. if (record.fileType == 3) {
  623. // let url = `/code/index.html?title=${record.fileName}&type=${record.fileFormat}&fileUrl=${record.fileUrl}#/sign-model`;
  624. dialogDowm.value.url = getUrlSrc({ ...record, type: 101 });
  625. dialogDowm.value.show = true;
  626. // return windowOpen({url: dialogDowm.value.url, library: true});
  627. } else if (
  628. record.fileType == 2 ||
  629. record.fileType == 1 ||
  630. record.fileType == 0
  631. ) {
  632. dialogDowm.value.url = getUrlSrc({ type: 102 }) + "/" + record.fileUrl;
  633. dialogDowm.value.show = true;
  634. // return windowOpen({url: record.fileUrl, library: true});
  635. } else {
  636. hanleDown();
  637. }
  638. };
  639. const handleExceed = (files) => {
  640. const file = files[0];
  641. if (!beforeUpload(file)) {
  642. return false;
  643. }
  644. upload.value && upload.value.clearFiles();
  645. file.uid = genFileId();
  646. upload.value && upload.value.handleStart(file);
  647. };
  648. const beforeUpload = (file) => {
  649. console.log("beforeUpload", file);
  650. const filetype = file.name
  651. .substring(file.name.lastIndexOf(".") + 1)
  652. .toLowerCase();
  653. const isExcel = [
  654. "jpg",
  655. "jpg",
  656. "png",
  657. "jpeg",
  658. "mp4",
  659. "wav",
  660. "mp3",
  661. "shp",
  662. "zip",
  663. ].includes(filetype); // 调用上面代码
  664. if (!isExcel) {
  665. ElMessage.error(ui18n.t("mediaLibrary.tips.uplooadfiletype"));
  666. fileList.value = [];
  667. return false;
  668. }
  669. const isLt10M = file.size / 1024 / 1024 < 2000;
  670. if (!isLt10M) {
  671. fileList.value = [];
  672. ElMessage.error(ui18n.t("mediaLibrary.tips.uplooadSize"));
  673. return false;
  674. }
  675. fileList.value = [file];
  676. return true;
  677. };
  678. // 监听搜索表单变化
  679. watch(searchForm, () => {
  680. currentPage.value = 1;
  681. initData();
  682. });
  683. // 处理分页大小变化
  684. const handleSizeChange = (newSize) => {
  685. pageSize.value = newSize;
  686. initData();
  687. };
  688. // 处理当前页码变化
  689. const handleCurrentChange = (newPage) => {
  690. currentPage.value = newPage;
  691. initData();
  692. };
  693. // 下载资源
  694. const hanleDown = () => {
  695. const item = dialogDowm.value.data;
  696. const a = document.createElement("a");
  697. a.href = dialogDowm.value.url;
  698. a.download = `${item.name}.${item.fileFormat}`; // 下载后的文件名
  699. a.click();
  700. a.remove();
  701. };
  702. // 处理搜索按钮点击
  703. const handleSearch = () => {
  704. currentPage.value = 1;
  705. initData();
  706. };
  707. // 重置搜索表单
  708. const resetSearch = () => {
  709. Object.keys(searchForm.value).forEach((key) => {
  710. searchForm.value[key] = "";
  711. });
  712. currentPage.value = 1;
  713. initData();
  714. };
  715. // 初始化数据
  716. initData();
  717. </script>
  718. <style lang="scss">
  719. .upload-demo .el-upload-list__item.is-success:focus:not(:hover) {
  720. display: none !important;
  721. }
  722. .mb-3 {
  723. margin-bottom: 1rem;
  724. }
  725. .mt-3 {
  726. margin-top: 1rem;
  727. }
  728. .mymediaLibrary {
  729. background-color: #292929;
  730. text-align: left;
  731. .grouping {
  732. padding: 7px 10px;
  733. background-color: var(--el-fill-color-blank);
  734. box-shadow: 0 0 0 1px var(--el-border-color);
  735. border-radius: 0 4px 4px 0;
  736. opacity: 0.7;
  737. cursor: pointer;
  738. &:hover {
  739. box-shadow: 0 0 0 1px #6c6e72;
  740. opacity: 1;
  741. }
  742. }
  743. .groupingSelcet {
  744. .el-select__wrapper {
  745. border-radius: 4px 0 0 4px;
  746. }
  747. }
  748. .el-form--inline .el-form-item {
  749. margin-right: 20px;
  750. }
  751. .itemTitle {
  752. width: 100%;
  753. margin: 0 0 10px 0;
  754. .itemTitleList {
  755. margin-top: 10px;
  756. background: rgba(255, 255, 255, 0.1);
  757. border-radius: 4px 4px 4px 4px;
  758. border: 1px solid rgba(255, 255, 255, 0.2);
  759. max-height: 240px;
  760. overflow-y: scroll;
  761. ::-webkit-scrollbar {
  762. display: none; /* Chrome Safari */
  763. }
  764. }
  765. .itemTitle-list {
  766. padding-left: 10px;
  767. line-height: 34px;
  768. display: flex;
  769. justify-content: space-between;
  770. position: relative;
  771. cursor: pointer;
  772. .name {
  773. width: 300px;
  774. overflow: hidden; //超出的文本隐藏
  775. text-overflow: ellipsis; //溢出用省略号显示
  776. white-space: nowrap; //溢出不换行
  777. }
  778. .del {
  779. color: #fa3d47;
  780. // width: 40px;
  781. cursor: pointer;
  782. }
  783. }
  784. }
  785. }
  786. .showContent {
  787. iframe {
  788. body:-webkit-full-page-media {
  789. background-color: none;
  790. }
  791. }
  792. }
  793. .el-pager li.is-active {
  794. border: 1px solid var(--el-color-primary);
  795. background-color: none;
  796. }
  797. </style>