diff --git a/package.json b/package.json index e9d2b17..f56d19c 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "moment": "^2.29.1", "prerender-spa-plugin": "^3.4.0", "puppeteer": "^10.4.0", + "spark-md5": "^3.0.2", "uuid": "^9.0.0", "v-contextmenu": "^2.9.0", "v-viewer": "^1.6.3", @@ -35,6 +36,7 @@ "vue-qr": "^2.5.0", "vue-router": "^3.5.1", "vue-runtime-helpers": "^1.1.2", + "vue-simple-uploader": "^0.7.6", "vuex": "^3.6.2", "webpack": "^4.23.0" }, diff --git a/src/App.vue b/src/App.vue index 7683ce8..6c423db 100644 --- a/src/App.vue +++ b/src/App.vue @@ -82,8 +82,7 @@ html, body, .app { } .app { - font-family: Noto Sans SC, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; - font-style: normal; + font-family: var(--vt-font-family-base); font-weight: 400; } diff --git a/src/assets/css/style.css b/src/assets/css/style.css index da06bbe..546d574 100644 --- a/src/assets/css/style.css +++ b/src/assets/css/style.css @@ -1,11 +1,15 @@ /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/ body { - font-family: Noto Sans SC, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; - font-style: normal; - font-weight: 400; + font-family: var(--vt-font-family-base); + /*font-family: CustomFont,Noto Sans SC,"Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;*/ overflow: hidden; + } +:root { + --vt-font-family-base: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + --vt-font-family-mono: Menlo, Monaco, Consolas, "Courier New", monospace; +} .move-style-index { max-width: 95%; diff --git a/src/assets/img/text/upimg_text.png b/src/assets/img/text/upimg_text.png new file mode 100644 index 0000000..19f81b7 Binary files /dev/null and b/src/assets/img/text/upimg_text.png differ diff --git a/src/assets/img/text/urlimg_text.png b/src/assets/img/text/urlimg_text.png new file mode 100644 index 0000000..7854475 Binary files /dev/null and b/src/assets/img/text/urlimg_text.png differ diff --git a/src/assets/js/bus.js b/src/assets/js/bus.js new file mode 100644 index 0000000..8853b4d --- /dev/null +++ b/src/assets/js/bus.js @@ -0,0 +1,3 @@ +import Vue from 'vue' + +export default new Vue() diff --git a/src/assets/js/upload.js b/src/assets/js/upload.js index 3a1ef6b..6fdadbf 100644 --- a/src/assets/js/upload.js +++ b/src/assets/js/upload.js @@ -1,9 +1,12 @@ import albumList from '../../components/comp/album-list.vue' -import {request} from "../../network/request"; +import {request} from "../../network/request" import vueQr from 'vue-qr' import Treeselect from '@riophae/vue-treeselect' import '@riophae/vue-treeselect/dist/vue-treeselect.css' -import md5 from "js-md5"; +import md5 from "js-md5" +import UploaderList from "@/components/comp/uploadList" +// import ColorThief from "colorthief"; +import SparkMD5 from "spark-md5"; export default { metaInfo() { @@ -22,6 +25,11 @@ export default { link: [{ rel: 'asstes', href: 'http://www.hellohao.cn/' + }, { + link: [{ // set link + rel: 'icon', + href: 'https://g.csdnimg.cn/static/logo/favicon32.ico' + }] }] } @@ -33,67 +41,144 @@ export default { }, data() { return { + screenWidth: 720, uploadImg: require("../img/uploadImg.png"), - linkImg: require("../img/link.png"), timeImg: require("../img/time.png"), + // tagImg: require("../assets/img/tag.png"), + // storeImg: require("../assets/img/store.png"), isToolImgStyle: 'width: 50px;', loading: false, urlUploadMsg: false, termMsg: false,//上传期限的弹窗 imgUrl: null, uploadInfo: { + // - 图片支持格式 suffix: null, + // - 图片限制大小(访客、用户) filesize: null, + // - 图片最多同时上传个数 imgcount: 1, + // - 上传开关(访客、用户) uploadSwitch: 0, }, isAlbum: false, - ViewURL: null, albumData: {}, - headers: { - 'usersOrigin': md5(window.location.protocol + '//' + window.location.host), - "Authorization": localStorage.getItem('Authorization') - }, - data: { - day: 0 - }, - imgListShow: 'show', + // data:{ + // day:0, + // classifications:null, + // source:0 + // }, + img_day: 0, selectIndex: [], selectIndexUid: [],//这个uid是系统自己生成的一个数字串,仅用于勾选上传图片使用,防止重复图片选一个 都是同一个imguid的问题 selectImg: [], - defaultList: [], - imgName: '', visible: false, IsImgLink: false, uploadList: [], - // imgLinkForShortLink:null, imgLinkForUrl: null, + imgLinkForBriefimgurl: null, imgLinkForMD: null, imgLinkForHtml: null, images: [], imgIndex: null, + //画廊多选操作所需变量 albumlist: [], dayList: [{"label": "永久", "value": 0}, {"label": "1天", "value": 1}, { "label": "3天", "value": 3 }, {"label": "7天", "value": 7}, {"label": "30天", "value": 30}], - IsShowtagMsg: false, - tagInfo: null, - tempNum: 0,//验证是否提示过单次上传个数弹窗 tempLink: 0, tempURLErr: false, upUrlNum: -1, ismsg: null, - spinShow: false - + spinShow: false, + mytheme: { + myColor1: 'rgba(255, 255, 255, .9)',//卡片背景 + myColor2: '#515860',//文字颜色/边框颜色/图标颜色 + myColor3: '#f35d58',//按钮颜色 + myColor4: '#515860', + }, } }, - methods: { - - created() { - this.imgListShow = 'show'; + watch: { + img_day: function (newval, oldval) { + localStorage.setItem("img_day", newval) + // console.log("newval",newval) + // console.log("oldval",oldval) }, + }, + beforeUpdate() { + //解决弹窗关闭后的延迟问题 + // let chArr = document.body.getElementsByClassName("ivu-modal-mask"); + // for (let i = 0; i < chArr.length; i++) { + // if (chArr[i] != null) + // chArr[i].remove(chArr[i]); + // } + }, + mounted() { + localStorage.setItem("img_day", this.img_day) + this.$refs.UploaderList.setAssign(document.getElementById('bodydom')) + this.$Spin.show(); + this.getUploadInfo(); + + }, + methods: { + returnImgData(data) { + // console.log('上传页面接到的返回值',data) + this.uploadList.push(data) + this.$store.commit("setCopyAllUrl", this.uploadList); + this.$emit('showBtn', this.uploadList); + }, + getProgress() { + this.$refs.UploaderList.showProgressModel() + }, + async sendImgData(file) { + if (this.getUploadSwitch) { + this.$Message.warning("系统暂时关闭了用户上传功能"); + return; + } else { + this.$Notice.info({ + title: '图像上传', + desc: '剪贴板图像上传准备开始...' + }); + } + var ret = await this.getFileMD5(file); + var formRrcover = new FormData() + formRrcover.append('file', file) + formRrcover.append('day', window.localStorage.getItem('img_day')) + formRrcover.append('md5', ret) + this.$http.post('/upload', formRrcover, { + 'Content-type': 'multipart/form-data', + timeout: 600000 + }).then(res => { + if (res.data.code == '200') { + this.uploadList.push(res.data.data) + this.$store.commit("setCopyAllUrl", this.uploadList); + this.$emit('showBtn', this.uploadList); + } else { + this.$Message.warning("上传剪贴板图像失败"); + } + }, err => { + // 出现错误时的处理 + }) + }, + getFileMD5(file) { + return new Promise((resolve, reject) => { + try { + var fileReader = new FileReader(); + var spark = new SparkMD5.ArrayBuffer(); + fileReader.readAsArrayBuffer(file); + fileReader.onload = function (e) { + spark.append(e.target.result); + var md5 = spark.end(); + resolve(md5) + }; + } catch (e) { + reject(null) + } + }) + }, handleRemove(file) { this.$Modal.confirm({ title: '确认删除', @@ -101,7 +186,7 @@ export default { onOk: () => { this.$Spin.show(); var param = { - imguid: file.response.data.imguid + imguid: file.imguid } request( "/deleImagesByUid", @@ -110,12 +195,15 @@ export default { if (res.status == 200) { if (res.data.code == '200') { this.$Message.success(res.data.info); - const fileList = this.$refs.upload.fileList; - this.$refs.upload.fileList.splice(fileList.indexOf(file), 1); - this.$store.commit("setCopyAllUrl", this.$refs.upload.fileList); + for (let i = 0; i < this.uploadList.length; i++) { + if (this.uploadList[i].imguid == file.imguid) { + this.uploadList.splice(i, 1); + } + } + this.$store.commit("setCopyAllUrl", this.uploadList); this.$emit('showBtn', this.uploadList); - this.selectIndex.splice(this.selectIndex.indexOf(file.response.data.imguid), 1); - this.selectIndexUid.splice(this.selectIndexUid.indexOf(file.uid), 1); + this.selectIndex.splice(this.selectIndex.indexOf(file.imguid), 1); + this.selectIndexUid.splice(this.selectIndexUid.indexOf(file.imguid), 1); } else { this.$Message.error(res.data.info); } @@ -125,9 +213,7 @@ export default { }).catch(err => { this.$Spin.hide(); console.log(err); - this.$Message.error('服务器请求错误'); }) - }, onCancel: () => { // this.$Message.info('已取消删除'); @@ -135,60 +221,9 @@ export default { }); }, - handleSuccess(res, file) { - this.tempNum = 0; - if (res.code != "200") { - const fileList = this.$refs.upload.fileList; - this.$refs.upload.fileList.splice(fileList.indexOf(file), 1); - this.$Message.error(res.info); - return false; - } - if (res.length > 0) { - this.images.push(res[0]); - } - // let urlText = this.$store.state.copyAllUrl+res.data.url+'\n'; - // this.$store.commit("setCopyAllUrl", urlText); - this.$store.commit("setCopyAllUrl", this.$refs.upload.fileList); - - this.$emit('showBtn', this.uploadList); - const box = document.getElementById('box'); - box.scrollTop = box.scrollHeight; - }, - handleFormatError(file) { - this.$Notice.warning({ - title: '文件格式不正确', - desc: file.name + ' 的文件格式不受支持.' - }); - }, - handleMaxSize(file) { - this.$Notice.warning({ - title: '超过图像大小限制', - desc: '文件: ' + file.name + ' 太大, 不能超过 ' + this.uploadInfo.filesize + ' K' - }); - }, - handleBeforeUpload() { - const check = this.uploadList.length < this.uploadInfo.imgcount; - if (!check) { - if (this.tempNum == 0) { - this.$Notice.warning({ - name: 'imgcount', - duration: 0, - onClose: this.setImgCountMSG, - title: '页面上传图像过多', - desc: '系统限制了页面的上传图像数量,上传图像不得超过' + this.uploadInfo.imgcount + '个图像' - }); - this.tempNum = 1; - } - - } - return check; - }, - setImgCountMSG() { - this.tempNum = 0; - }, - uploadError() { - console.log("图片上传出错") - }, +//滚动到最下边 + // const box = document.getElementById('box'); + // box.scrollTop = box.scrollHeight; allSett() { if (this.selectIndex.length > 0) { this.getAlbumImgList(); @@ -197,15 +232,12 @@ export default { this.$Message.info('请选择要操作的图片'); } }, - clickImg(key, uid) { - if (this.selectIndexUid.indexOf(uid) == -1) { + clickImg(key) { + if (this.selectIndex.indexOf(key) == -1) { this.selectIndex.push(key); - this.selectIndexUid.push(uid); } else { this.selectIndex.splice(this.selectIndex.indexOf(key), 1); - this.selectIndexUid.splice(this.selectIndexUid.indexOf(uid), 1); } - }, uploadForUrl() { if (this.imgUrl == null || this.imgUrl == '') { @@ -228,40 +260,25 @@ export default { }, sendUploadForUrl(urlText) { var param = { - day: 0, - imgUrl: urlText + day: this.img_day, + imgUrl: urlText, } request( "/uploadForUrl", param, 1000 * 60 * 120).then(res => { - // this.loading = false; - // this.urlUploadMsg = false; this.spinShow = false; - // setTimeout(this.ismsg, 1); if (res.status == 200) { this.upUrlNum++; if (res.data.code == '200') { - console.log("URl上传成功返回值测试"); - console.log(res.data); let jsonData = res.data.data; if (jsonData.urls.length > 0) { for (let i = 0; i < jsonData.urls.length; i++) { - var json = { - "status": "finished", - "name": "link.png", - "size": 0, - "percentage": 100, - "uid": this.getUuid(14, 14), - "showProgress": false, - "response": jsonData.urls[i], - "exceptions": null - } - this.$refs.upload.fileList.push(json); - // let urlText = this.$store.state.copyAllUrl+jsonData.urls[i].url+'\n'; - // this.$store.commit("setCopyAllUrl", urlText); + this.uploadList.push(jsonData.urls[i].data) + } + if (this.uploadList.length > 0) { + this.$store.commit("setCopyAllUrl", this.uploadList); + this.$emit('showBtn', this.uploadList); } - this.$store.commit("setCopyAllUrl", this.$refs.upload.fileList); - this.$emit('showBtn', this.uploadList); } this.imgUrl = null; var text = ""; @@ -278,30 +295,23 @@ export default { title: "批量上传执行完毕", content: text }); - // this.$Message.success({ - // content: "批量上传执行完毕,共", - // duration: 5 - // }); - + this.imgUrl = null; } else { this.$Message.warning(res.data.info); } - } else { this.$Message.error("请求时出现错误"); } }).catch(err => { this.$Spin.hide(); - // this.loading = false; - // this.urlUploadMsg = false; console.log(err); - this.$Message.error('服务器请求错误'); + this.$Message.error(err); }) }, //获取选中的画廊图片信息 getAlbumImgList() { var param = { - imguidlist: this.selectIndex + imguidlist: this.selectIndex//JSON.stringify(this.selectIndex), } request( "/getAlbumImgList", @@ -329,11 +339,12 @@ export default { var json = res.data.data; if (json) { this.uploadInfo = json; + this.$refs.UploaderList.setUploadInfo(json) } else { this.$Message.error("获取当前上传信息时出现错误"); } } else { - this.$Message.error("获取当前上传信息时出现错误"); + console.error("获取当前上传信息时出现错误"); } }).catch(err => { this.$Spin.hide(); @@ -343,9 +354,10 @@ export default { }, getImgLink(img) { var host = window.location.host; - this.imgLinkForUrl = img.response.data.url; - this.imgLinkForHtml = '' + img.name + ''; - this.imgLinkForMD = '![' + img.name + '](' + img.response.data.url + ')'; + this.imgLinkForUrl = img.url; + this.imgLinkForBriefimgurl = img.briefimgurl; + this.imgLinkForHtml = '' + img.name + ''; + this.imgLinkForMD = '![' + img.name + '](' + img.url + ')'; this.IsImgLink = true; }, copyBtn() { @@ -377,12 +389,11 @@ export default { this.isAlbum = true; }, showUrlUploadMsg() { - this.urlUploadMsg = true; - // if(this.uploadInfo.uploadSwitch==1){ - // this.urlUploadMsg = true; - // }else{ - // this.$Message.warning(this.uploadInfo.uploadInfo); - // } + if (this.uploadInfo.uploadSwitch == 1) { + this.urlUploadMsg = true; + } else { + this.$Message.warning(this.uploadInfo.uploadInfo); + } }, showtermMsg() { this.termMsg = true; @@ -399,44 +410,10 @@ export default { title: '您之后上传的数据将会在' + value + '天后过期' }); } - }, - // 移入 - mouseOver() { - this.isToolImgStyle = "width: 50px;\n" + - " -webkit-transition:all 0.5s ease 0s;\n" + - " -moz-transition:all 0.5s ease 0s;\n" + - " transition:all 0.5s ease 0s;"; - }, - // 移出 - mouseLeave() { - this.isToolImgStyle = "width: 50px;\n"; - }, - getUuid(len, radix) { - var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); - var uuid = [], - i; - radix = radix || chars.length; - if (len) { - for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; - } else { - var r; - uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; - uuid[14] = '4'; - - for (i = 0; i < 36; i++) { - if (!uuid[i]) { - r = 0 | Math.random() * 16; - uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; - } - } - } - return uuid.join(''); - }, onGetLines() { var tempText = this.imgUrl; - if (this.imgUrl == '') { this.tempLink = 0; } else { @@ -449,18 +426,67 @@ export default { this.tempURLErr = false; } } - } + }, + imgOnOk() { + // var op = 0; + // var than = this; + // var interval = null + // try { + // interval = setInterval(function(){ + // than.$refs.webbgimg.style.opacity=op+' '; + // than.$refs.webbgimg.style.display = 'block' + // op = op+0.1 + // if(op>=0.9){ + // clearInterval(interval); + // } + // },100) + // }catch (err){ + // clearInterval(interval); + // console.log(err) + // } + }, + imgOnError() { + console.log("imgOnError-none") + this.$refs.webbgimg.style.display = 'none' + }, + //颜色排序 + sortColor(colors) { + var than = this + return colors.sort(function (a, b) { + //由深到浅 + return than.grayLevel(a) - than.grayLevel(b) + }) + }, + grayLevel(color) { + //必须要是rgb格式 + var arr = this.getMid(color).split(',') + var r = arr[0], g = arr[1], b = arr[2]; + return r * 0.299 + g * 0.587 + b * 0.114 + }, + getMid(str) { + var left = str.indexOf('(') + 1; + var right = str.indexOf(')'); + return str.slice(left, right); + }, + //判断颜色深浅色 + hexToRgb(colorChange) { //HEX十六进制颜色值转换为RGB(A)颜色值 + var grayLevel = colorChange[0] * 0.299 + colorChange[1] * 0.587 + colorChange[2] * 0.114; + if (grayLevel >= 192) {//浅色模式 + //浅色背景 用深色文字 + return '#28272b'; + } else { + //深色背景 用浅色文字 + return '#dadada'; + } + }, }, - mounted() { - this.$Spin.show(); - this.getUploadInfo(); - this.uploadList = this.$refs.upload.fileList; - }, + components: { albumList, vueQr, - Treeselect + Treeselect, + UploaderList }, computed: { getUploadSwitch: function () { diff --git a/src/components/comp/uploadList.vue b/src/components/comp/uploadList.vue new file mode 100644 index 0000000..9f62e5a --- /dev/null +++ b/src/components/comp/uploadList.vue @@ -0,0 +1,491 @@ + + + + + + diff --git a/src/main.js b/src/main.js index 30e7161..3126149 100644 --- a/src/main.js +++ b/src/main.js @@ -18,6 +18,7 @@ import '@/assets/css/font.less'; import './assets/css/style.css' import md5 from "js-md5"; import "babel-polyfill"; +import uploader from 'vue-simple-uploader' import locStorage from './assets/js/utils/locStorage.js' import img404 from './assets/img/img404.jpg' import imgloading from './assets/img/imgloading.gif' @@ -99,7 +100,7 @@ var options = { timeToIdle: 4000 }; -Vue.use(Iview).use(preview, options).use(Viewer, { +Vue.use(Iview).use(preview, options).use(uploader).use(Viewer, { defaultOptions: { navbar: false } diff --git a/src/views/index.vue b/src/views/index.vue index ad073df..644344e 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -1,7 +1,8 @@