123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 |
- <template>
- <div class="mymediaLibrary">
- <!-- 表头搜索 -->
- <el-form :inline="true" :model="searchForm">
- <el-form-item class="formitem">
- <el-input
- v-model="searchForm.name"
- @change="submitClick"
- @keydown.enter="submitClick"
- :placeholder="$t('mediaLibrary.addFilePlace')"
- size="default"
- :prefix-icon="Search"
- ></el-input>
- </el-form-item>
- <el-form-item>
- <el-select
- style="width: 120px"
- v-model="searchForm.fileType"
- @change="submitClick"
- :placeholder="$t('mediaLibrary.fileType.0')"
- >
- <el-option
- v-for="(item, index) in [
- $t('mediaLibrary.fileType.0'),
- $t('mediaLibrary.fileType.1'),
- $t('mediaLibrary.fileType.2'),
- $t('mediaLibrary.fileType.3'),
- $t('mediaLibrary.fileType.4'),
- $t('mediaLibrary.fileType.5'),
- ]"
- :key="index"
- :label="item"
- :value="index"
- />
- </el-select>
- </el-form-item>
- <el-form-item style="margin-right: 0px">
- <el-select class="groupingSelcet"
- v-model="searchForm.dictId"
- style="width: 120px"
- @change="submitClick"
- :placeholder="$t('mediaLibrary.fileType.0')"
- >
- <el-option
- v-for="(item, index) in [...allList,...dictIdList]"
- :key="index"
- :label="item.dictName"
- :value="item.id"
- />
- </el-select>
- <div class="grouping" @click="handleAddfz">
- <img :src="groupingSvg" alt="">
- </div>
- </el-form-item>
- <el-form-item style="float: right; margin-right: 0">
- <el-button @click="windowOpen({type: 'photography', library: true})">{{$t('mediaLibrary.photography')}}</el-button>
- <el-button @click="windowOpen({type: 'modeling', library: true})">{{$t('mediaLibrary.Modeling')}}</el-button>
- <!-- <el-button type="primary" @click="handleAddfz">{{$t('mediaLibrary.grouping')}}</el-button> -->
- <el-button type="primary" @click="handleAdd">{{$t('mediaLibrary.upload')}}</el-button>
- </el-form-item>
- </el-form>
- <!-- 表格 -->
- <el-table
- tooltip-effect="dark"
- ref="tableRef"
- size="large"
- :data="tableData"
- style="width: 100%"
- :row-class-name="tableRowClassName"
- >
- <el-table-column prop="name" :label="$t('program.case.title')" min-width="300px">
- <template #default="scope">
- <a
- style="color: var(--primaryColor);cursor: pointer;"
- v-if="scope.row.fileUrl"
- target="_blank"
- :title="scope.row.name"
- @click="floadileUrl(scope.row)"
- >
- {{ scope.row.name }}</a
- >
- </template>
- </el-table-column>
- <el-table-column
- v-for="column in columns"
- :key="column.prop"
- :prop="column.prop"
- show-overflow-tooltip
- align="center"
- :min-width="column.width"
- :label="column.label"
- ></el-table-column>
- <el-table-column align="center" :label="$t('mediaLibrary.operate')" width="150">
- <template #default="{ row }">
- <!-- <el-button type="primary" text style="color: var(--primaryColor)" size="small" @click="handleEdit(row)">
- 编辑
- </el-button> -->
- <span class="oper-span" style="color: var(--primaryColor)" @click="handleEdit(row)">
- {{$t('sys.edit')}}
- </span>
- <span
- class="oper-span"
- @click="del(row)"
- style="color: var(--primaryColor)"
- >
- {{$t('sys.delete')}}
- </span>
- </template>
- </el-table-column>
- </el-table>
- <!-- 分页 -->
- <el-pagination
- class="mt-3"
- background
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- :current-page="currentPage"
- :page-sizes="[10, 20, 30]"
- :page-size="pageSize"
- style="justify-content: end"
- layout="prev, pager, next"
- :total="total"
- >
- </el-pagination>
- <!-- 弹窗 -->
- <el-dialog v-model="dialogData.show" :title="dialogData.title" width="400">
- <el-form label-position="top" :model="form" label-width="110">
- <el-form-item
- v-if="dialogData.title == $t('sys.upload')"
- label="文件"
- :label-width="formLabelWidth"
- >
- <!-- <el-input v-model="addForm.name" autocomplete="off" /> -->
- <el-upload
- class="upload-demo"
- style="width: 100%"
- :multiple="false"
- :limit="1"
- :before-upload="beforeUpload"
- :file-list="fileList"
- :http-request="() => {}"
- :on-preview="previewFile"
- :accept="accept"
- :before-remove="removeFile"
- >
- <el-button type="primary">
- {{$t('sys.upload')}}
- </el-button>
- </el-upload>
- </el-form-item>
- <el-form-item
- :label="dialogData.title == $t('sys.upload') ? $t('mediaLibrary.dictName') : $t('mediaLibrary.setGrouping')"
- :label-width="formLabelWidth"
- >
- <el-select style="width: 100%" v-model="addForm.dictId" :placeholder="$t('mediaLibrary.tips.dictId')">
- <el-option
- v-for="(item, index) in dictIdList"
- :key="index"
- :label="item.dictName"
- :value="item.id"
- />
- </el-select>
- </el-form-item>
- <div v-if="dialogData.title == $t('sys.upload')">
- <div style="margin-bottom: 10px">
- {{$t('mediaLibrary.tips.uplooadfiletype')}}{{$t('mediaLibrary.tips.uplooadSize')}}
- </div>
- <!-- <span>注意:模型需使用zip包上传。包含贴图、模型、mtl文件,包内不得包含文件夹。</span> -->
- <div style="margin-bottom: 10px">
- <div>
- {{$t('mediaLibrary.tips.objtips')}}
- </div>
- <img style="width: 150px" :src="obj" alt="" />
- </div>
- <div style="margin-bottom: 10px">
- <div>
- {{$t('mediaLibrary.tips.osgbtips')}}
- </div>
- <img style="width: 150px" :src="osgb" alt="" />
- </div>
- </div>
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button @click="dialogData.show = false">{{$t('sys.cancel')}}</el-button>
- <el-button type="primary" @click="handleuploadAdd">
- {{$t('sys.enter')}}
- </el-button>
- </div>
- </template>
- </el-dialog>
- <!-- 修改分组 -->
- <el-dialog v-model="dialogData.fzshow" :title="$t('mediaLibrary.grouping')" width="400">
- <el-form label-position="top" :model="form" label-width="50">
- <el-form-item :label="$t('mediaLibrary.addgrouping')" :label-width="formLabelWidth">
- <el-input v-model="dialogData.fzName" maxLength="100" style="width: 278px;" />
- <el-button style="margin-left: 20px;width: 60px" @click="handlefzAdd">{{$t('common.add')}}</el-button>
- </el-form-item>
- <div class="itemTitle">
- <p>{{$t('mediaLibrary.groupingList')}}</p>
- <div class="itemTitleList">
- <div class="itemTitle-list" v-for="(item, index) in dictIdList" :key="index">
- <span class="name">{{ item.dictName }}</span>
- <span class="del" @click="hanleFzDle(item)">{{$t('sys.delete')}}</span>
- </div>
- </div>
- </div>
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button @click="dialogData.fzshow = false">{{$t('sys.cancel')}}</el-button>
- <el-button type="primary" @click="dialogData.fzshow = false">
- {{$t('sys.enter')}}
- </el-button>
- </div>
- </template>
- </el-dialog>
- <!-- //查看资源下载 -->
- <el-dialog v-model="dialogDowm.show" title="资源查看" :width="dialogDowm.type == 4?800:600">
- <div class="showContent">
- <img style="width: 100%;object-fit: cover;" :src="dialogDowm.url" alt="" v-if="dialogDowm.type == 0"/>
- <video controls style="width: 100%;object-fit: cover;" :style="{height:dialogDowm.type == 2?'50px':'auto'}":src="dialogDowm.url" alt="" v-else-if="dialogDowm.type == 1 || dialogDowm.type == 2"/>
- <iframe style="width: 100%; height: 400px" v-else :src="dialogDowm.url" frameborder="0"></iframe>
- </div>
- <template #footer>
- <div class="dialog-footer">
- <el-button @click="dialogDowm.show = false">{{$t('sys.cancel')}}</el-button>
- <el-button v-if="dialogDowm.type == 0" type="primary" @click="hanleDown">
- 下载
- </el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup>
- import { Search } from "@element-plus/icons-vue";
- import { ref, watch, onMounted } from "vue";
- import { getByKeyList, getfzdel, getdictFiledel, getaddOrUpdate, setFileaddOrUpdate, uploadFile, getUrlSrc } from "@/store/case";
- import dayjs from "dayjs";
- import obj from "@/assets/images/obj.jpg";
- import osgb from "@/assets/images/osgb.jpg";
- import { ElMessage, ElMessageBox } from "element-plus";
- import { ui18n } from '@/i18n'
- import { windowOpen } from "@/util";
- import { getUrlData } from "@/store/user";
- import groupingSvg from "@/assets/images/grouping.svg";
- // 定义 props
- const props = defineProps({
- columns: {
- type: Array,
- default: () => [],
- },
- searchColumns: {
- type: Array,
- default: () => [],
- },
- getData: {
- type: Function,
- required: true,
- },
- });
- // 定义响应式数据
- const searchForm = ref({
- name: "",
- fileType: 0,
- dictId: "0",
- });
- const addForm = ref({
- fileType: "",
- dictId: "",
- name: "",
- });
- const dialogDowm = ref({
- show: false,
- url: '',
- type: '',
- data: {},
- });
- const dialogData = ref({
- show: false,
- title: ui18n.t('sys.upload'),
- data: {},
- fzshow: false,
- fzName: '',
- fzList: [],
- });
- const file = ref(null);
- const accept = ".jpg,.png,.jpeg,.mp4,.wav,.mp3,.shp";
- const hanleFzDle = (item) => {
- ElMessageBox.confirm(ui18n.t('mediaLibrary.tips.deltext'), ui18n.t('sys.dialogTitle'), {
- confirmButtonText: ui18n.t('sys.enter'),
- cancelButtonText: ui18n.t('sys.cancel'),
- }).then(async () => {
- await getfzdel(item);
- dictIdList.value = dictIdList.value.filter(item1 => item1.id !== item.id)
- ElMessage({
- type: "success",
- message: ui18n.t('mediaLibrary.tips.del'),
- });
- });
-
- console.log("upload", file);
- };
- const { photography, modeling } = getUrlData()
- const previewFile = (file) => {
- console.log("previewFile", file);
- };
- const handleEdit = (data) => {
- addForm.value.dictId = data.dictId;
- console.log("data", data, addForm.value);
- dialogData.value = {
- show: true,
- title: ui18n.t('mediaLibrary.setGrouping'),
- data,
- };
- };
- const removeFile = () => {
- return true;
- };
- const handleAdd = () => {
- addForm.value.dictId = '';
- addForm.value.dictId = '';
- fileList.value = [];
- dialogData.value = {
- show: true,
- title: ui18n.t('sys.upload')
- };
- };
- const handlefzAdd = async () => {
- let params = {
- dictName: dialogData.value.fzName,
- };
- if (!params.dictName) {
- return ElMessage.error(ui18n.t('mediaLibrary.tips.placeholderName'));
- }
- await getaddOrUpdate(params);
- ElMessage({
- type: "success",
- message: ui18n.t('mediaLibrary.tips.placeholderName'),
- });
- getFzlist();
- dialogData.value.fzName = '';
- };
- const handleAddfz = () => {
- dialogData.value.fzshow = true;
- };
- const handleuploadAdd = async () => {
- console.log('formData', dialogData.value.title);
- if (dialogData.value.title != ui18n.t('sys.upload')){
- await setFileaddOrUpdate({
- id: dialogData.value.data?.id,
- dictId: addForm.value.dictId,
- })
- initData();
- dialogData.value.show = false
- dialogData.value.title = ''
- ElMessage({
- type: "success",
- message: ui18n.t('mediaLibrary.tips.operate'),
- });
- } else {
- const formData = new FormData();
- formData.append("file", fileList.value && fileList.value[0]);
- formData.append("dictId", addForm.value.dictId);
- uploadFile(formData).then((res) => {
- console.log(res);
- if (res) {
- initData();
- dialogData.value.show = false;
- ElMessage({
- type: "success",
- message: ui18n.t('mediaLibrary.tips.uplooadSuccess'),
- });
- }
- });
- console.log(formData);
- }
- };
- // 定义方法
- const del = (row) => {
- console.log(file, "file");
- ElMessageBox.confirm(ui18n.t('mediaLibrary.tips.deltext'), ui18n.t('sys.dialogTitle'), {
- confirmButtonText: ui18n.t('sys.enter'),
- cancelButtonText: ui18n.t('sys.cancel'),
- }).then(async () => {
- await getdictFiledel({id: row.id});
- initData();
- ElMessage({
- type: "success",
- message: ui18n.t('mediaLibrary.tips.del'),
- });
- });
- };
- const allList = ref([{ dictName: ui18n.t('mediaLibrary.fileType.0'), id: "0" }])
- const dictIdList = ref([]);
- const tableData = ref([]);
- const fileList = ref([]);
- const currentPage = ref(1);
- const pageSize = ref(10);
- const total = ref(0);
- onMounted(() => {
- // document.body.classList.toggle("dark-mode");
- });
- const getFzlist = () => {
- getByKeyList({}).then((res) => {
- console.log("getByKeyList", res);
- dictIdList.value = res;
- });
- };
- getFzlist();
- const submitClick = () => {
- console.log("submitClick", searchForm.value);
- currentPage.value = 1;
- initData();
- };
- const tableRowClassName = ({ row, rowIndex }) => {
- if (rowIndex === 1) {
- return "warning-row";
- } else if (rowIndex === 3) {
- return "success-row";
- }
- return "";
- };
- // 初始化数据
- const initData = async () => {
- const { list, totalCount } = await props.getData({
- ...searchForm.value,
- fileType:
- searchForm.value.fileType == 0 ? "" : searchForm.value.fileType - 1,
- dictId: searchForm.value.dictId == 0 ? "" : searchForm.value.dictId,
- pageNum: currentPage.value,
- pageSize: pageSize.value,
- });
- tableData.value = list.map((res) => {
- return {
- ...res,
- statusStr:
- res.status == -1 ? ui18n.t('mediaLibrary.tips.uplooadErr') : res.status == 0 ? ui18n.t('mediaLibrary.tips.uplooad') : ui18n.t('mediaLibrary.tips.uplooadSuccess'),
- createTime: dayjs(res.createTime).format("YYYY-MM-DD HH:mm:ss"),
- };
- });
- total.value = totalCount;
- };
- const floadileUrl = (record) => {
- dialogDowm.value.show = true;
- dialogDowm.value.type = record.fileType;
- dialogDowm.value.data = record;
- if (record.fileType == 3) {
- // let url = `/code/index.html?title=${record.fileName}&type=${record.fileFormat}&fileUrl=${record.fileUrl}#/sign-model`;
- dialogDowm.value.url = getUrlSrc({...record, type: 101});
- return windowOpen({url, library: true});
- } else {
- dialogDowm.value.url = getUrlSrc({type: 102}) +'/'+ record.fileUrl;
- // return windowOpen({url: record.fileUrl, library: true});
- }
- };
- const beforeUpload = (file) => {
- console.log('beforeUpload', file);
- const filetype = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();
- const isExcel = ['jpg', 'jpg', 'png', 'jpeg', 'mp4', 'wav', 'mp3', 'shp', 'zip'].includes(
- filetype,
- ); // 调用上面代码
- if (!isExcel) {
- createMessage.error(ui18n.t('mediaLibrary.tips.uplooadfiletype'));
- fileList.value = [];
- return false;
- }
- const isLt10M = file.size / 1024 / 1024 < 2000;
- if (!isLt10M) {
- fileList.value = [];
- createMessage.error(ui18n.t('mediaLibrary.tips.uplooadSize'));
- return false;
- }
- fileList.value = [file];
- return true;
- };
- // 监听搜索表单变化
- watch(searchForm, () => {
- currentPage.value = 1;
- initData();
- });
- // 处理分页大小变化
- const handleSizeChange = (newSize) => {
- pageSize.value = newSize;
- initData();
- };
- // 处理当前页码变化
- const handleCurrentChange = (newPage) => {
- currentPage.value = newPage;
- initData();
- };
- // 下载资源
- const hanleDown = () => {
- const item = dialogDowm.value.data;
- const a = document.createElement('a');
- a.href = dialogDowm.value.url;
- a.download = `${item.name}.${item.fileFormat}`; // 下载后的文件名
- a.click();
- a.remove();
- }
- // 处理搜索按钮点击
- const handleSearch = () => {
- currentPage.value = 1;
- initData();
- };
- // 重置搜索表单
- const resetSearch = () => {
- Object.keys(searchForm.value).forEach((key) => {
- searchForm.value[key] = "";
- });
- currentPage.value = 1;
- initData();
- };
- // 初始化数据
- initData();
- </script>
- <style lang="scss">
- :root {
- // --el-bg-color: #151515;
- // --colorColor: #fff;
- }
- // /* 覆盖 Element Plus 的 CSS 变量 */
- // --el-color-primary: #1890ff;
- // --el-bg-color: #141414;
- // --el-text-color-primary: #ffffff;
- // /* 可以根据需要覆盖更多变量 */
- .mb-3 {
- margin-bottom: 1rem;
- }
- .mt-3 {
- margin-top: 1rem;
- }
- .mymediaLibrary {
- background-color: #292929;
- text-align: left;
- // .el-form-item{
- // margin-bottom: 30px;
- // }
- // .el-table th.el-table__cell{
- // background-color: #1d1d1d;
- // color: #fff;
- // }
- // width: 100%;
- // --el-input-bg-color: #535353;
- // .el-table{
- // background-color: #535353;
- // }
- .grouping{
- padding: 7px 10px;
- background-color: var(--el-fill-color-blank);
- box-shadow: 0 0 0 1px var(--el-border-color);
- border-radius: 0 4px 4px 0 ;
- opacity: 0.7;
- cursor: pointer;
- &:hover{
- box-shadow: 0 0 0 1px #6C6E72;
- opacity: 1;
- }
- }
- .groupingSelcet{
- .el-select__wrapper{
- border-radius:4px 0 0 4px;
- }
- }
- .el-form--inline .el-form-item{
- margin-right: 20px;
- }
- // .el-form-item, .el-select__wrapper{
- // background-color: #535353;
- // }
- // .el-input__wrapper, .el-select__wrapper{
- // background-color: #535353;
- // box-shadow: none;
- // }
- // .el-input__inner, .el-select__selected-item{
- // color: #fff;
- // }
- // /* 局部修改具有 custom-table 类名的 el-table 的背景颜色 */
- // .custom-table.el-table {
- // background-color: #535353;
- // }
- // /* 修改表头背景颜色 */
- // .custom-table.el-table__header-wrapper th {
- // background-color: #535353;
- // }
- // /* 修改表格行的背景颜色 */
- // .el-table tr {
- // background-color: #535353;
- // }
- // /* 修改表格行悬停时的背景颜色 */
- // .custom-table.el-table__body tr:hover>td {
- // background-color: #535353;
- // }
- // .el-table th.el-table__cell{
- // background-color: #1d1d1d
- // }
- // .el-table .el-table__cell{
- // border-color: #303030 !important;
- // }
- // .el-table--fit .el-table__inner-wrapper:before{
- // background-color: none;
- // }
- // .el-table .warning-row {
- // --el-table-tr-bg-color: var(--el-color-warning-light-9);
- // }
- // .el-table .success-row {
- // --el-table-tr-bg-color: var(--el-color-success-light-9);
- // }
- .itemTitle{
- width: 100%;
- margin: 0 0 10px 0;
- .itemTitleList{
- margin-top: 10px;
- background: rgba(255,255,255,0.1);
- border-radius: 4px 4px 4px 4px;
- border: 1px solid rgba(255,255,255,0.2);
- max-height: 240px;
- overflow-y: scroll;
- ::-webkit-scrollbar {
- display: none; /* Chrome Safari */
- }
- }
- .itemTitle-list{
- padding-left: 10px;
- line-height: 34px;
- display: flex;
- justify-content: space-between;
- position: relative;
- cursor: pointer;
- .name{
- width: 350px;
- overflow: hidden; //超出的文本隐藏
- text-overflow: ellipsis; //溢出用省略号显示
- white-space: nowrap; //溢出不换行
- }
- .del{
- color: red;
- width: 40px;
- cursor: pointer;
- }
- }
- }
- }
- .showContent{
- iframe{
- body:-webkit-full-page-media {
- background-color: none;
- }
- }
- }
- .el-pager li.is-active{
- border: 1px solid var(--el-color-primary);
- background-color: none;
- }
- </style>
|