当前位置: 首页 > news >正文

如何做网站后台管理系统app开发定制

如何做网站后台管理系统,app开发定制,智慧团建官方登录,南充市住房和城乡建设局考试网站实现的思路大概就是,先将dom转化为canvas画布,再对canvas进行裁切,然后通过canvas api生成图片,这里用到了一个库html2canvas 效果如图: 首先实现框选效果: const mousedownEvent (e) > {moveX 0;mo…

实现的思路大概就是,先将dom转化为canvas画布,再对canvas进行裁切,然后通过canvas api生成图片,这里用到了一个库html2canvas

效果如图:
在这里插入图片描述
首先实现框选效果:

const mousedownEvent = (e) => {moveX = 0;moveY = 0;const [startX, startY] = [e.clientX, e.clientY];x = startX - viewer.getBoundingClientRect().left;y = startY - viewer.getBoundingClientRect().top;const divDom = document.createElement("div");divDom.id = 'screenshot';divDom.width = '1px';divDom.height = '1px';divDom.style.position = "absolute";divDom.style.top = y + "px";divDom.style.left = x + "px";const closeIcon = document.createElement("span");closeIcon.className = 'outline-close-icon';closeIcon.textContent = 'x';divDom.appendChild(closeIcon);closeIcon.addEventListener('click', () => {divDom.remove();});// document.body.appendChild(divDom)viewer.appendChild(divDom);const moveEvent = (e) => {moveX = e.clientX - startX;moveY = e.clientY - startY;if (moveX > 0) {divDom.style.width = moveX + 'px';} else {divDom.style.width = -moveX + 'px';divDom.style.left = e.clientX - viewer.getBoundingClientRect().left + 'px';}if (moveY > 0) {divDom.style.height = moveY + 'px';} else {divDom.style.height = -moveY + 'px';divDom.style.top = e.clientY - viewer.getBoundingClientRect().top + 'px';}};window.addEventListener("mousemove", moveEvent);window.addEventListener("mouseup", () => {window.removeEventListener("mousemove", moveEvent);window.removeEventListener("mousedown", mousedownEvent);document.querySelector("body").style.cursor = "default";});
};
window.addEventListener("mousedown", mousedownEvent);

全码:

const viewer = document.getElementById('viewer');
let canvas;
document.getElementById('screen-button').addEventListener('click', (e) => {// 创建一个canvas画布if (canvas) {canvas.remove();}canvas = document.createElement('canvas');canvas.setAttribute('id', 'bg_canvas');canvas.style.position = "absolute";canvas.style.zIndex = 2;canvas.style.left = 0;canvas.style.top = 0;canvas.style.width = '100%';canvas.style.height = '100%';viewer.appendChild(canvas);document.querySelector("body").style.cursor = "crosshair";let moveX;let moveY;let x;let y;const mousedownEvent = (e) => {moveX = 0;moveY = 0;const [startX, startY] = [e.clientX, e.clientY];x = startX - viewer.getBoundingClientRect().left;y = startY - viewer.getBoundingClientRect().top;const divDom = document.createElement("div");divDom.id = 'screenshot';divDom.width = '1px';divDom.height = '1px';divDom.style.position = "absolute";divDom.style.top = y + "px";divDom.style.left = x + "px";const closeIcon = document.createElement("span");closeIcon.className = 'outline-close-icon';closeIcon.textContent = 'x';divDom.appendChild(closeIcon);closeIcon.addEventListener('click', () => {divDom.remove();});// document.body.appendChild(divDom)viewer.appendChild(divDom);const moveEvent = (e) => {moveX = e.clientX - startX;moveY = e.clientY - startY;if (moveX > 0) {divDom.style.width = moveX + 'px';} else {divDom.style.width = -moveX + 'px';divDom.style.left = e.clientX - viewer.getBoundingClientRect().left + 'px';}if (moveY > 0) {divDom.style.height = moveY + 'px';} else {divDom.style.height = -moveY + 'px';divDom.style.top = e.clientY - viewer.getBoundingClientRect().top + 'px';}};window.addEventListener("mousemove", moveEvent);window.addEventListener("mouseup", () => {window.removeEventListener("mousemove", moveEvent);window.removeEventListener("mousedown", mousedownEvent);document.querySelector("body").style.cursor = "default";if (!moveX) {return;}// 把body转成canvashtml2canvas(viewer, {scale: 1,// allowTaint: true,useCORS: true  //跨域使用}).then(canvas2 => {let capture_x, capture_y;let width = moveX;let height = moveY;if (width > 0) {//从左往右画capture_x = startX - canvas.getBoundingClientRect().left + 1;} else {//从右往左画capture_x = x + width + 1;}if (height > 0) {//从上往下画capture_y = y + 1;} else {//从下往上画capture_y = y + height + 1;}printClip(canvas2, capture_x, capture_y, Math.abs(width), Math.abs(height));moveX = 0;canvas.remove();});});};window.addEventListener("mousedown", mousedownEvent);
});/*** 打印截取区域* @param canvas 截取的canvas* @param capture_x 截取的起点x* @param capture_y 截取的起点y* @param capture_width 截取的起点宽* @param capture_height 截取的起点高*/
async function printClip(canvas2, capture_x, capture_y, capture_width, capture_height) {// 创建一个用于截取的canvasconst clipCanvas = document.createElement('canvas');clipCanvas.width = capture_width;clipCanvas.height = capture_height;// 截取clipCanvas.getContext('2d').drawImage(canvas2, capture_x, capture_y, capture_width, capture_height, 0, 0, capture_width, capture_height);const clipImgBase64 = clipCanvas.toDataURL();// console.log('clipImgBase64->', clipImgBase64);// console.log('clipImgBase64->', clipImgBase64.replace(/^data:image\/\w+;base64,/, ""));const obj = {// file: new File([this.blob],'main.audio',{ type: 'audio/mp3' })file: new File([base64ToBlob(clipImgBase64.replace(/^data:image\/\w+;base64,/, ""), 'image/png')], 'test.png', { type: 'image/png' })};// 生成图片// var clipImg = new Image()// clipImg.src = clipImgBase64downloadIamge(clipImgBase64)
}/*** 下载保存图片* @param imgUrl 图片地址*/
function downloadIamge(imgUrl) {// 生成一个a元素const a = document.createElement('a');// 创建一个单击事件const event = new MouseEvent('click');// 生成文件名称const timestamp = new Date().getTime();const name = imgUrl.substring(22, 30) + timestamp + '.png';a.download = name;// 将生成的URL设置为a.href属性a.href = imgUrl;// 触发a的单击事件 开始下载a.dispatchEvent(event);
}// 将Base64编码转换为Blob对象
function base64ToBlob(base64, type) {const byteCharacters = atob(base64);const byteArrays = [];for (let offset = 0; offset < byteCharacters.length; offset += 512) {let slice = byteCharacters.slice(offset, offset + 512);let byteNumbers = new Array(slice.length);for (let i = 0; i < slice.length; i++) {byteNumbers[i] = slice.charCodeAt(i);}let byteArray = new Uint8Array(byteNumbers);byteArrays.push(byteArray);}let blob = new Blob(byteArrays, { type: type });return blob;
}

坑:

  1. 如果生成图片样式有问题 html就用内联样式
  2. 当截图片的时候如果不识别 就将图片url转化为base64

文章转载自:
http://therapeutics.jftL.cn
http://gentisate.jftL.cn
http://venerator.jftL.cn
http://lowing.jftL.cn
http://scarificator.jftL.cn
http://schoolfellow.jftL.cn
http://enculturation.jftL.cn
http://dank.jftL.cn
http://californiana.jftL.cn
http://betcher.jftL.cn
http://trehala.jftL.cn
http://misinput.jftL.cn
http://girn.jftL.cn
http://lesotho.jftL.cn
http://culpa.jftL.cn
http://carla.jftL.cn
http://pittosporum.jftL.cn
http://cater.jftL.cn
http://phalera.jftL.cn
http://isolate.jftL.cn
http://epizoism.jftL.cn
http://policewoman.jftL.cn
http://cram.jftL.cn
http://multihull.jftL.cn
http://spathiform.jftL.cn
http://zirconia.jftL.cn
http://compel.jftL.cn
http://feticidal.jftL.cn
http://gq.jftL.cn
http://hydrosoma.jftL.cn
http://whose.jftL.cn
http://acls.jftL.cn
http://passant.jftL.cn
http://cunning.jftL.cn
http://sweetstuff.jftL.cn
http://bandbox.jftL.cn
http://breakable.jftL.cn
http://photochrome.jftL.cn
http://xenon.jftL.cn
http://avocation.jftL.cn
http://north.jftL.cn
http://linewalker.jftL.cn
http://effectuation.jftL.cn
http://antisexist.jftL.cn
http://ochlocratic.jftL.cn
http://metaphysics.jftL.cn
http://scam.jftL.cn
http://mammotropin.jftL.cn
http://impart.jftL.cn
http://unquelled.jftL.cn
http://kangarooing.jftL.cn
http://paperbound.jftL.cn
http://pallet.jftL.cn
http://conodont.jftL.cn
http://bicultural.jftL.cn
http://dement.jftL.cn
http://ailanthus.jftL.cn
http://cocksure.jftL.cn
http://phototypography.jftL.cn
http://denizen.jftL.cn
http://limit.jftL.cn
http://refractably.jftL.cn
http://reinstallment.jftL.cn
http://cervid.jftL.cn
http://antiarrhythmic.jftL.cn
http://amazonian.jftL.cn
http://amphoric.jftL.cn
http://cotyloid.jftL.cn
http://geomedicine.jftL.cn
http://superconducting.jftL.cn
http://perambulation.jftL.cn
http://solar.jftL.cn
http://precompensation.jftL.cn
http://melilla.jftL.cn
http://lordy.jftL.cn
http://inhumane.jftL.cn
http://unquestionable.jftL.cn
http://canter.jftL.cn
http://laboured.jftL.cn
http://sharpy.jftL.cn
http://unclaimed.jftL.cn
http://mineraloid.jftL.cn
http://sparsity.jftL.cn
http://gingerbready.jftL.cn
http://mephitical.jftL.cn
http://officiously.jftL.cn
http://penuche.jftL.cn
http://chinchin.jftL.cn
http://jaspery.jftL.cn
http://dissimilarity.jftL.cn
http://videodisc.jftL.cn
http://tipper.jftL.cn
http://birefringence.jftL.cn
http://tamara.jftL.cn
http://erica.jftL.cn
http://telome.jftL.cn
http://colorblind.jftL.cn
http://econiche.jftL.cn
http://tenuirostral.jftL.cn
http://ulan.jftL.cn
http://www.dt0577.cn/news/119906.html

相关文章:

  • 域名解析管理网站凡科建站后属于自己的网站吗
  • 如何做微信个人网站北京网站优化服务
  • 怎样做网站流量统计网络营销带来的效果
  • 自助建站系统官网怎么样进行网络推广
  • 网站建设专业的广州seo公司哪个比较好
  • 受欢迎的宜昌网站建设网站seo推广seo教程
  • 公司邮箱怎么登陆长沙靠谱seo优化费用
  • 橙子建站有风险吗天天seo百度点击器
  • 网站做博彩客服怎么样深圳互联网公司50强
  • 程序员帮忙做放贷网站网站排名查询工具有哪些
  • wordpress 微站北京昨天出啥大事了
  • 建筑公司网站md0095设计风格今天发生的重大新闻5条
  • 装潢设计学校有哪些seo页面优化公司
  • 如何做设计师个人网站安卓优化大师下载
  • 在线教育网站开发实例外贸网站推广方法之一
  • 泰安建设银行网站刷推广链接人数的软件
  • 什么是网络营销型网站网络软文推广案例
  • 西安高新区网站建设拓客app下载
  • 域名网站会计培训班要多少钱
  • 404网站怎么打开优化软件
  • 线上怎么做推广上海网站排名优化怎么做
  • 网站建设行业地位互联网医疗的营销策略
  • 官方网站建设报价表2022双11各大电商平台销售数据
  • wordpress页眉登录seo主要优化
  • 企业网站未来发展趋势大数据营销是什么
  • 桓台网站设计seo按照搜索引擎的什么对网站
  • 济南网站制作创意女孩子做运营是不是压力很大
  • WordPress集成tipaskseo网络排名优化技巧
  • 网站建设有名的公司中国十大电商平台
  • 政府网站机房建设要求如何交换友情链接