| | |
| | | import SparkMD5 from 'spark-md5' |
| | | import { getPublicImage } from '@/assets/js/middleGround/tool.js' |
| | | import SparkMD5 from "spark-md5"; |
| | | import { getPublicImage } from "@/assets/js/middleGround/tool.js"; |
| | | // import moment from "moment"; |
| | | |
| | | var tool = { |
| | | secondToTime(second) { |
| | | var minute = Math.floor(second / 60) |
| | | var sec = second % 60 |
| | | var time |
| | | var minute = Math.floor(second / 60); |
| | | var sec = second % 60; |
| | | var time; |
| | | if (second < 60) { |
| | | time = second + '"' |
| | | time = second + '"'; |
| | | } else { |
| | | time = sec === 0 ? minute + "'" : minute + "'" + sec + '"' |
| | | time = sec === 0 ? minute + "'" : minute + "'" + sec + '"'; |
| | | } |
| | | return time |
| | | return time; |
| | | }, |
| | | setCookie: function (c_name, value, expiredays, path) { |
| | | var exdate = new Date() |
| | | exdate.setDate(exdate.getDate() + expiredays) |
| | | var exdate = new Date(); |
| | | exdate.setDate(exdate.getDate() + expiredays); |
| | | document.cookie = |
| | | c_name + |
| | | '=' + |
| | | "=" + |
| | | escape(value) + |
| | | (expiredays == null ? '' : ';expires=' + exdate.toGMTString()) + |
| | | (path ? ';path=' + path : '') |
| | | (expiredays == null ? "" : ";expires=" + exdate.toGMTString()) + |
| | | (path ? ";path=" + path : ""); |
| | | }, |
| | | getCookie: function (c_name) { |
| | | if (document.cookie.length > 0) { |
| | | var c_start = document.cookie.indexOf(c_name + '=') |
| | | var c_start = document.cookie.indexOf(c_name + "="); |
| | | if (c_start != -1) { |
| | | c_start = c_start + c_name.length + 1 |
| | | var c_end = document.cookie.indexOf(';', c_start) |
| | | if (c_end == -1) c_end = document.cookie.length |
| | | return unescape(document.cookie.substring(c_start, c_end)) |
| | | c_start = c_start + c_name.length + 1; |
| | | var c_end = document.cookie.indexOf(";", c_start); |
| | | if (c_end == -1) c_end = document.cookie.length; |
| | | return unescape(document.cookie.substring(c_start, c_end)); |
| | | } |
| | | } |
| | | return '' |
| | | return ""; |
| | | }, |
| | | delCookie: function (name) { |
| | | var exp = new Date() |
| | | exp.setTime(exp.getTime() - 1) |
| | | var cval = tool.getCookie(name) |
| | | if (cval != null) document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString() |
| | | var exp = new Date(); |
| | | exp.setTime(exp.getTime() - 1); |
| | | var cval = tool.getCookie(name); |
| | | if (cval != null) |
| | | document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); |
| | | }, |
| | | // 强制保留2位小数,如:2,会在2后面补上00.即2.00 |
| | | toDecimal2(x) { |
| | | var f |
| | | f = parseFloat(x) |
| | | var f; |
| | | f = parseFloat(x); |
| | | if (isNaN(f)) { |
| | | return false |
| | | return false; |
| | | } |
| | | f = Math.round(x * 100) / 100 |
| | | var s = f.toString() |
| | | var rs = s.indexOf('.') |
| | | f = Math.round(x * 100) / 100; |
| | | var s = f.toString(); |
| | | var rs = s.indexOf("."); |
| | | if (rs < 0) { |
| | | rs = s.length |
| | | s += '.' |
| | | rs = s.length; |
| | | s += "."; |
| | | } |
| | | while (s.length <= rs + 2) { |
| | | s += '0' |
| | | s += "0"; |
| | | } |
| | | return s |
| | | return s; |
| | | }, |
| | | formateTime(date) { |
| | | var newDate = new Date(+new Date(date) + 8 * 3600 * 1000) |
| | | .toISOString() |
| | | .replace(/T/g, ' ') |
| | | .replace(/\.[\d]{3}Z/, '') |
| | | var time = new Date(newDate) |
| | | return time.getTime() |
| | | .replace(/T/g, " ") |
| | | .replace(/\.[\d]{3}Z/, ""); |
| | | var time = new Date(newDate); |
| | | return time.getTime(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | // 处理订单记录 |
| | | // export function setOrderList(res) { |
| | |
| | | |
| | | //处理表单提交数据 |
| | | export function worksData(res) { |
| | | let arr = [] |
| | | let arr = []; |
| | | for (let i = 0; i < res.length; i++) { |
| | | const item = res[i] |
| | | const item = res[i]; |
| | | if (item.typeField) { |
| | | if (item.typeField.config) { |
| | | item.typeField.options = JSON.parse(item.typeField.config).option |
| | | item.typeField.options = JSON.parse(item.typeField.config).option; |
| | | } |
| | | arr.push(item.typeField) |
| | | arr.push(item.typeField); |
| | | } |
| | | } |
| | | return arr |
| | | return arr; |
| | | } |
| | | |
| | | export function worksDataBytool(res, value, linkList) { |
| | | let arr = [] |
| | | let nrr = [] |
| | | let arr = []; |
| | | let nrr = []; |
| | | if (linkList && linkList.length > 0) { |
| | | linkList.forEach((e) => |
| | | nrr.push({ |
| | |
| | | linkType: e.linkType, |
| | | md5: e.md5 |
| | | }) |
| | | ) |
| | | ); |
| | | } |
| | | res.forEach((item) => { |
| | | const obj = { |
| | | baseType: item.typeField.baseType, |
| | | order: 0, |
| | | typeFieldId: item.typeField.id, |
| | | sequenceNum: item.config ? JSON.parse(item.config).uuid : '', |
| | | sequenceNum: item.config ? JSON.parse(item.config).uuid : "", |
| | | newDataAndFileLinkListRequest: [] |
| | | } |
| | | }; |
| | | for (let k in value) { |
| | | if (item.typeField.refCode === k) { |
| | | if (item.typeField.type == 'File') { |
| | | if (item.typeField.type == "File") { |
| | | try { |
| | | obj.strValue = JSON.stringify(value[k].map((citem) => citem.md5)) |
| | | obj.strValue = JSON.stringify(value[k].map((citem) => citem.md5)); |
| | | } catch (error) { |
| | | obj.strValue = '' |
| | | obj.strValue = ""; |
| | | } |
| | | obj.newDataAndFileLinkListRequest = nrr |
| | | obj.newDataAndFileLinkListRequest = nrr; |
| | | } else { |
| | | if (typeof value[k] == 'object') { |
| | | obj.strValue = JSON.stringify(value[k]) |
| | | if (typeof value[k] == "object") { |
| | | obj.strValue = JSON.stringify(value[k]); |
| | | } else { |
| | | if (obj.baseType === 'String') { |
| | | obj.strValue = value[k] + '' |
| | | } else if (obj.baseType === 'Text') { |
| | | obj.textValue = value[k] + '' |
| | | if (obj.baseType === "String") { |
| | | obj.strValue = value[k] + ""; |
| | | } else if (obj.baseType === "Text") { |
| | | obj.textValue = value[k] + ""; |
| | | } else { |
| | | obj.strValue = value[k] + '' |
| | | obj.strValue = value[k] + ""; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // if (obj.strValue || obj.textValue) { |
| | | arr.push(obj) |
| | | arr.push(obj); |
| | | // } |
| | | }) |
| | | return arr |
| | | }); |
| | | return arr; |
| | | } |
| | | |
| | | export function UpdateworksDataBytool(initData, res, value, linkList) { |
| | |
| | | id: updateOldData.id, |
| | | typeFieldId: citem.typeField.id, |
| | | sequenceNum: citem.sequenceNum, |
| | | setDataAndFileLinkListRequest: [], |
| | | setDataAndFileLinkListRequest: [] |
| | | }; |
| | | for (let k in value) { |
| | | if (citem.typeField.refCode === k) { |
| | |
| | | order: 0, |
| | | typeFieldId: citem.typeField.id, |
| | | sequenceNum: citem.sequenceNum, |
| | | setDataAndFileLinkListRequest: [], |
| | | setDataAndFileLinkListRequest: [] |
| | | }; |
| | | for (let k in value) { |
| | | if (citem.typeField.refCode === k) { |
| | |
| | | }); |
| | | return { |
| | | updateData: arr, |
| | | newData: newArr, |
| | | newData: newArr |
| | | }; |
| | | } |
| | | |
| | | export function download(url) { |
| | | const iframe = document.createElement('iframe') |
| | | iframe.setAttribute('hidden', 'hidden') |
| | | document.body.appendChild(iframe) |
| | | const iframe = document.createElement("iframe"); |
| | | iframe.setAttribute("hidden", "hidden"); |
| | | document.body.appendChild(iframe); |
| | | iframe.onload = () => { |
| | | if (iframe) { |
| | | iframe.setAttribute('src', 'about:blank') |
| | | iframe.setAttribute("src", "about:blank"); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | iframe.setAttribute('src', url) |
| | | iframe.setAttribute("src", url); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @returns {string} |
| | | */ |
| | | export function uuid(len = 32, radix = 16) { |
| | | const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') |
| | | const chars = |
| | | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""); |
| | | let uuid = [], |
| | | i |
| | | radix = radix || chars.length |
| | | i; |
| | | radix = radix || chars.length; |
| | | |
| | | if (len) { |
| | | // Compact form |
| | | for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)] |
| | | for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]; |
| | | } else { |
| | | // rfc4122, version 4 form |
| | | let r |
| | | let r; |
| | | |
| | | // rfc4122 requires these characters |
| | | uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-' |
| | | uuid[14] = '4' |
| | | uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-"; |
| | | uuid[14] = "4"; |
| | | |
| | | // Fill in random data. At i==19 set the high bits of clock sequence as |
| | | // per rfc4122, sec. 4.1.5 |
| | | for (i = 0; i < 36; i++) { |
| | | if (!uuid[i]) { |
| | | r = 0 | (Math.random() * 16) |
| | | uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r] |
| | | r = 0 | (Math.random() * 16); |
| | | uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return uuid.join('') |
| | | return uuid.join(""); |
| | | } |
| | | |
| | | export function getFileMd5(file, chunkSize) { |
| | | return new Promise((resolve, reject) => { |
| | | let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice |
| | | let chunks = Math.ceil(file.size / chunkSize) |
| | | let currentChunk = 0 |
| | | let spark = new SparkMD5.ArrayBuffer() |
| | | let fileReader = new FileReader() |
| | | let blobSlice = |
| | | File.prototype.slice || |
| | | File.prototype.mozSlice || |
| | | File.prototype.webkitSlice; |
| | | let chunks = Math.ceil(file.size / chunkSize); |
| | | let currentChunk = 0; |
| | | let spark = new SparkMD5.ArrayBuffer(); |
| | | let fileReader = new FileReader(); |
| | | fileReader.onload = function (e) { |
| | | spark.append(e.target.result) |
| | | currentChunk++ |
| | | spark.append(e.target.result); |
| | | currentChunk++; |
| | | if (currentChunk < chunks) { |
| | | loadNext() |
| | | loadNext(); |
| | | } else { |
| | | const md5 = spark.end() |
| | | resolve(md5) |
| | | const md5 = spark.end(); |
| | | resolve(md5); |
| | | } |
| | | } |
| | | }; |
| | | fileReader.onerror = function (e) { |
| | | reject(e) |
| | | } |
| | | reject(e); |
| | | }; |
| | | |
| | | function loadNext() { |
| | | let start = currentChunk * chunkSize |
| | | let end = start + chunkSize |
| | | let start = currentChunk * chunkSize; |
| | | let end = start + chunkSize; |
| | | if (end > file.size) { |
| | | end = file.size |
| | | end = file.size; |
| | | } |
| | | fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)) |
| | | fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); |
| | | } |
| | | loadNext() |
| | | }) |
| | | loadNext(); |
| | | }); |
| | | } |
| | | |
| | | export function getParentNodeByClassName(element, className) { |
| | | if (element && element.classList.contains(className)) { |
| | | return element; |
| | | } else { |
| | | return getParentNodeByClassName(element.parentNode, className); |
| | | } |
| | | } |
| | | |
| | | // 处理时间,用于显示音视频当前时间 |
| | |
| | | worksDataBytool, |
| | | UpdateworksDataBytool, |
| | | getPublicImage, |
| | | worksData |
| | | worksData, |
| | | getParentNodeByClassName |
| | | // parseHtml, |
| | | } |
| | | }; |