123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765 |
- <template>
- <el-dialog title="上传文件" :visible.sync="dialogVisiblefile" :append-to-body="true" width="600px"
- :before-close="handleClose" class="dialog_diy">
- <div class="fileCss">
- <div>
- <button class="info_btn" @click="addImg($event)">
- 选择本地文件
- <input type="file" accept="*" style="display: none" multiple="multiple" @change="beforeUpload" />
- </button>
- <div class="spanName">选择本地文件</div>
- </div>
- <!-- <div>
- <el-button @click="openFile">选择素材库文件</el-button>
- <div class="spanName">选择素材库文件</div>
- </div> -->
- </div>
- <div v-if="proVisible" class="mask">
- <div class="progressBox">
- <div class="lbox">
- <img src="../../../../assets/loading.gif" />上传中,请稍后
- </div>
- <!-- <div style="margin-bottom: 10px">
- <span>{{
- isFinishSize
- }}M</span>
- /
- <span>{{
- isAllSize
- }}M</span>
- </div>
- <el-progress :text-inside="true" :stroke-width="20" :percentage="progress
- ? progress
- : 0
- " style="width: 80%"></el-progress> -->
- </div>
- </div>
- <el-dialog title="选择素材库文件" :visible.sync="dialogVisiblefile2" :append-to-body="true" width="710px"
- :before-close="handleClose2" class="dialog_diy">
- <div class="file_box">
- <div class="student_head">
- <div class="three">
- <div :class="choose == 0 ? 'choose' : ''" @click="sMtl(0)">图片</div>
- <div :class="choose == 1 ? 'choose' : ''" @click="sMtl(1)">视频</div>
- <div :class="choose == 2 ? 'choose' : ''" @click="sMtl(2)">附件</div>
- </div>
- </div>
- <div class="student_table" v-loading="isLoading">
- <div v-if="this.choose == 0" class="boxCss">
- <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
- <div class="tup">
- <img :src="item.chapdataInfo ? JSON.parse(item.chapdataInfo).url : mtp
- " alt="" @click="checkJson(JSON.parse(item.chapdataInfo))" />
- <div class="deleteWord">
- <img src="../../../../assets/icon/delete.png" alt="" />
- </div>
- </div>
- <div class="bottom_box">
- <el-tooltip :content="item.chapdataInfo
- ? JSON.parse(item.chapdataInfo).name
- : '暂无名称'" placement="top" effect="dark">
- <div>
- {{
- item.chapdataInfo
- ? JSON.parse(item.chapdataInfo).name
- : "暂无名称"
- }}
- </div>
- </el-tooltip>
- </div>
- </div>
- </div>
- <div v-if="this.choose == 1" class="boxCss">
- <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
- <div class="tup">
- <img :src="msp" alt="" @click="checkJson(JSON.parse(item.chapdataInfo))" />
- <div class="deleteWord">
- <img src="../../../../assets/icon/delete.png" alt="" />
- </div>
- </div>
- <div class="bottom_box">
- <el-tooltip :content="item.chapdataInfo
- ? JSON.parse(item.chapdataInfo).name
- : '暂无名称'" placement="top" effect="dark">
- <div>
- {{
- item.chapdataInfo
- ? JSON.parse(item.chapdataInfo).name
- : "暂无名称"
- }}
- </div>
- </el-tooltip>
- </div>
- </div>
- </div>
- <div v-if="this.choose == 2" class="boxCss">
- <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
- <div class="tup">
- <img :src="mfj" alt="" @click="checkJson(JSON.parse(item.chapdataInfo))" />
- <div class="deleteWord">
- <img src="../../../../assets/icon/delete.png" alt="" />
- </div>
- </div>
- <div class="bottom_box">
- <el-tooltip :content="item.chapdataInfo
- ? JSON.parse(item.chapdataInfo).name
- : '暂无名称'" placement="top" effect="dark">
- <div>
- {{
- item.chapdataInfo
- ? JSON.parse(item.chapdataInfo).name
- : "暂无名称"
- }}
- </div>
- </el-tooltip>
- </div>
- </div>
- </div>
- </div>
- <div class="student_page">
- <el-pagination background layout="prev, pager, next" :page-size="10" :total="total"
- v-if="page && chapInfo.length" @current-change="handleCurrentChange">
- </el-pagination>
- </div>
- </div>
- </el-dialog>
- </el-dialog>
- </template>
-
- <script>
- export default {
- props: {
- dialogVisiblefile: {
- type: Boolean,
- default: false
- },
- },
- data() {
- return {
- progress: 0,
- isFinishSize: 0,
- proVisible: false,
- isAllSize: 0,
- dialogVisiblefile2: false,
- userid: this.$route.query.userid,
- page: 1,
- isLoading: false,
- total: 0,
- chapInfo: [],
- choose: 0,
- mtp: require("../../../../assets/tup1.png"),
- msp: require("../../../../assets/icon/fileIcon/isVideo.png"),
- mfj: require("../../../../assets/icon/fileIcon/word2.png"),
- };
- },
- methods: {
- handleClose(done) {
- this.close();
- done();
- },
- handleClose2(done) {
- done();
- },
- close() {
- this.$emit("update:dialogVisiblefile", false);
- },
- openFile() {
- this.dialogVisiblefile2 = true
- this.selectMtl();
- },
- sMtl(choose) {
- this.choose = choose
- this.page = 1
- this.selectMtl()
- },
- handleCurrentChange(val) {
- this.page = val
- this.selectMtl()
- },
- selectMtl() {
- this.isLoading = true;
- let params = {
- t: this.choose,
- uid: this.userid,
- page: this.page,
- };
- this.ajax
- .get(this.$store.state.api + "selectMtl2", params)
- .then((res) => {
- this.isLoading = false;
- this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
- this.chapInfo = res.data[0];
- })
- .catch((err) => {
- this.isLoading = false;
- console.error(err);
- });
- },
- addImg(e) {
- var el = e.currentTarget;
- el.getElementsByTagName("input")[0].click();
- e.target.value = "";
- },
- beforeUpload(event, type) {
- // const loading = this.openLoading();
- let cfindex2 = 0;
- for (var cfindex = 0; cfindex < event.target.files.length; cfindex++) {
- let file = event.target.files[cfindex];
- var credentials = {
- accessKeyId: "AKIATLPEDU37QV5CHLMH",
- secretAccessKey: "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",
- }; //秘钥形式的登录上传
- window.AWS.config.update(credentials);
- window.AWS.config.region = "cn-northwest-1"; //设置区域
- var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
- var _this = this;
- // _this.progress = 0;
- _this.proVisible = true;
- // _this.isFinishSize = 0;
- // _this.isAllSize = (file.size / 1024 / 1024).toFixed(2);
- _this.$forceUpdate();
- if (file) {
- var params = {
- Key:
- file.name.split(".")[0] +
- new Date().getTime() +
- "." +
- file.name.split(".")[file.name.split(".").length - 1],
- ContentType: file.type,
- Body: file,
- "Access-Control-Allow-Credentials": "*",
- ACL: "public-read",
- }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
- var options = {
- partSize: 2048 * 1024 * 1024,
- queueSize: 2,
- leavePartsOnError: true,
- };
- bucket
- .upload(params, options)
- .on("httpUploadProgress", function (evt) {
- //这里可以写进度条
- // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
- // _this.progress = parseInt((evt.loaded / evt.total) * 100);
- // _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2);
- // _this.$forceUpdate();
- })
- .send(function (err, data) {
- cfindex2++;
- // _this.progress = 100;
- // _this.isFinishSize = _this.isAllSize;
- // _this.$forceUpdate();
- // setTimeout(() => {
- // _this.proVisible = false;
- // _this.$forceUpdate();
- // }, 1000);
- setTimeout(() => {
- if (
- cfindex2 == event.target.files.length - 1 ||
- cfindex2 > event.target.files.length - 1
- ) {
- _this.proVisible = false;
- _this.close();
- }
- }, 1000);
- // loading.close();
- if (err) {
- _this.$message.error("上传失败");
- } else {
- let _type = 2;
- var imgA = [
- "png",
- "jpg",
- "jpeg",
- "bmp",
- "gif",
- "webp",
- "psd",
- "svg",
- "tiff",
- ];
- var fileA = [
- "DOC",
- "DOCX",
- "DOCM",
- "DOTM",
- "DOTX",
- "PPTX",
- "PPSX",
- "PPT",
- "PPS",
- "PPTM",
- "POTM",
- "PPAM",
- "POTX",
- "PPSM",
- "XLSX",
- "XLS",
- ];
- var videoA = [
- "AVI",
- "NAVI",
- "MPEG",
- "ASF",
- "MOV",
- "WMV",
- "3GP",
- "RM",
- "RMVB",
- "FLV",
- "F4V",
- "H.264",
- "H.265",
- "REAL VIDEO",
- "MKV",
- "WebM",
- "HDDVD",
- "MP4",
- "MPG",
- "M4V",
- "MGV",
- "OGV",
- "QTM",
- "STR",
- "AMC",
- "DVX",
- "EVO",
- "DAT",
- "OGG",
- "OGM",
- ];
- if (
- fileA.indexOf(
- data.Location.split(".")[
- data.Location.split(".").length - 1
- ].toLocaleUpperCase()
- ) != -1
- ) {
- _type = 1; //word 文件
- } else if (
- videoA.indexOf(
- data.Location.split(".")[
- data.Location.split(".").length - 1
- ].toLocaleUpperCase()
- ) != -1
- ) {
- _type = 2; //视频
- } else if (
- imgA.indexOf(
- data.Location.split(".")[
- data.Location.split(".").length - 1
- ].toLocaleLowerCase()
- ) != -1
- ) {
- _type = 3; //图片
- } else if (
- 'pdf'.indexOf(
- data.Location.split(".")[
- data.Location.split(".").length - 1
- ].toLocaleLowerCase()
- ) != -1
- ) {
- _type = 4; //pdf
- } else {
- _type = 5; //文件
- }
- // if (_this.checkJson.file) {
- // _this.checkJson.file.push({
- // name: file.name,
- // url: data.Location,
- // type: _type,
- // });
- // } else {
- // _this.checkJson.file = []
- // _this.checkJson.file.push({
- // name: file.name,
- // url: data.Location,
- // type: _type,
- // });
- // }
- _this.$emit("setCheckJson", file.name, data.Location, _type);
- _this.$forceUpdate();
- console.log(_this.checkJson);
- console.log(data.Location);
- }
- });
- }
- }
- },
- checkJson(json) {
- let _type = 2;
- let url = "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/"+encodeURIComponent(json.url.split(
- "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/"
- )[1]);
- let name = json.name
- var imgA = [
- "png",
- "jpg",
- "jpeg",
- "bmp",
- "gif",
- "webp",
- "psd",
- "svg",
- "tiff",
- ];
- var fileA = [
- "DOC",
- "DOCX",
- "DOCM",
- "DOTM",
- "DOTX",
- "PPTX",
- "PPSX",
- "PPT",
- "PPS",
- "PPTM",
- "POTM",
- "PPAM",
- "POTX",
- "PPSM",
- "XLSX",
- "XLS",
- ];
- var videoA = [
- "AVI",
- "NAVI",
- "MPEG",
- "ASF",
- "MOV",
- "WMV",
- "3GP",
- "RM",
- "RMVB",
- "FLV",
- "F4V",
- "H.264",
- "H.265",
- "REAL VIDEO",
- "MKV",
- "WebM",
- "HDDVD",
- "MP4",
- "MPG",
- "M4V",
- "MGV",
- "OGV",
- "QTM",
- "STR",
- "AMC",
- "DVX",
- "EVO",
- "DAT",
- "OGG",
- "OGM",
- ];
- if (
- fileA.indexOf(
- url.split(".")[
- url.split(".").length - 1
- ].toLocaleUpperCase()
- ) != -1
- ) {
- _type = 1; //word 文件
- } else if (
- videoA.indexOf(
- url.split(".")[
- url.split(".").length - 1
- ].toLocaleUpperCase()
- ) != -1
- ) {
- _type = 2; //视频
- } else if (
- imgA.indexOf(
- url.split(".")[
- url.split(".").length - 1
- ].toLocaleLowerCase()
- ) != -1
- ) {
- _type = 3; //图片
- } else if (
- 'pdf'.indexOf(
- url.split(".")[
- url.split(".").length - 1
- ].toLocaleLowerCase()
- ) != -1
- ) {
- _type = 4; //pdf
- } else {
- _type = 5; //文件
- }
- this.$emit("setCheckJson", name, url, _type);
- this.dialogVisiblefile2 = false
- this.close();
- }
- }
- };
- </script>
-
- <style scoped>
- .dialog_diy>>>.el-dialog {
- /* height: 100%; */
- margin: 10vh auto !important;
- }
- .dialog_diy>>>.el-dialog__header {
- background: #454545 !important;
- padding: 15px 20px;
- }
- .dialog_diy>>>.el-dialog__body {
- height: calc(100% - 124px);
- box-sizing: border-box;
- padding: 0px;
- }
- .dialog_diy>>>.el-dialog__title {
- color: #fff;
- }
- .dialog_diy>>>.el-dialog__headerbtn {
- top: 19px;
- }
- .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close {
- color: #fff;
- }
- .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close:hover {
- color: #fff;
- }
- .dialog_diy>>>.el-dialog__body,
- .dialog_diy>>>.el-dialog__footer {
- background: #fafafa;
- }
- .fileCss {
- width: 100%;
- display: flex;
- flex-direction: row;
- flex-wrap: nowrap;
- justify-content: space-around;
- align-items: center;
- padding: 40px 0;
- box-sizing: border-box;
- }
- .fileCss>div {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .fileCss .spanName {
- margin-top: 10px
- }
- .info_btn,
- .teacherWord {
- color: #fff;
- background-color: #0f7eff;
- padding: 8px 24px;
- font-size: 0.9375rem;
- box-shadow: 0px 1px 3px 0px rgb(0 0 0 / 20%), 0px 2px 2px 0px rgb(0 0 0 / 14%),
- 0px 3px 1px -2px rgb(0 0 0 / 12%);
- min-width: 64px;
- font-weight: 500;
- border-radius: 4px;
- box-sizing: border-box;
- border: none;
- cursor: pointer;
- }
- .mask {
- background-color: rgb(0 0 0 / 30%);
- /* position: fixed; */
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- z-index: 90;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .progressBox {
- width: 300px;
- height: 150px;
- background: #fff;
- border-radius: 10px;
- box-shadow: 0 0 6px 1px #bfbfbf;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- position: relative;
- color: #6c6c6c;
- }
- .progressBox>>>.el-progress-bar__outer {
- background-color: #d1dfff !important;
- }
- .progressBox .lbox {
- height: 50px;
- font-size: 19px;
- display: flex;
- align-items: center;
- color: #747474;
- }
- .progressBox .lbox img {
- width: 40px;
- margin-right: 20px;
- }
- .closeCss {
- position: absolute;
- top: 8px;
- right: 8px;
- cursor: pointer;
- width: 20px;
- height: 20px;
- }
- .closeCss>img {
- width: 100%;
- height: 100%;
- }
- .file_box {
- width: 100%;
- padding: 15px;
- box-sizing: border-box;
- }
- .student_head>>>.el-button--primary {
- background-color: #2268bc;
- }
- .student_head {
- display: flex;
- justify-content: space-between;
- }
- .three {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- width: 200px;
- height: 30px;
- }
- .three>div {
- cursor: pointer;
- }
- .choose {
- border-bottom: 5px solid #3994fd;
- }
- .student_table {
- width: 100%;
- height: 100%;
- background: #f2f2f2;
- margin-top: 10px;
- }
- .tup {
- width: calc(100% - 20px);
- height: 120px;
- margin: 0 auto;
- position: relative;
- }
- .out_box:hover .deleteWord {
- /* display: block; */
- }
- .deleteWord {
- width: 25px;
- height: 25px;
- position: absolute;
- right: -25px;
- top: -10px;
- cursor: pointer;
- display: none;
- }
- .tup>img,
- .deleteWord>img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
- .out_box {
- display: flex;
- flex-direction: column;
- flex-wrap: nowrap;
- width: 216px;
- padding: 10px 0;
- background: #fff;
- margin: 0 10px 10px 0;
- height: fit-content;
- cursor: pointer;
- }
- .out_box:nth-child(3n){
- margin-right: 0;
- }
- .bottom_box {
- display: flex;
- text-align: center;
- margin: 0 auto;
- padding: 10px 0 5px 0;
- }
- .bottom_box>div:nth-child(1) {
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- word-break: break-all;
- width: 200px;
- }
- .uploadThing {
- background: #2268bc;
- width: 90px;
- height: 35px;
- color: #fff;
- font-size: 12px;
- text-align: center;
- line-height: 35px;
- cursor: pointer;
- border-radius: 4px;
- }
- .top {
- display: flex;
- justify-content: space-between;
- }
- .student_page {
- margin-top: 30px;
- }
- .boxCss {
- padding: 15px 5px;
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- min-height: 250px;
- }
- </style>
-
|