======================知识点总结===========================css
vue-validator中文文档html
给最外层盒子加上绝对定位,而且设置固定高度前端
.reg-layer { width: 100%; height: 360px; background: #ffffff; position: absolute; left: 0; top: 0; bottom: 0; right: 0; }
再给登陆框设置固定vue
.login-main { width: 100%; height: 4rem; background-color: #ffffff; padding-top: 0.4rem; }
VUe-Scrollerhtml5
_this.$router.go(0);
{ test: /vue-scroller.src.*?js$/, loader: 'babel-loader' }
this.$refs.my_scroller.finishInfinite(true);python
it must be contain a canvas tagreact
import PDFJS from 'pdfjs-dist'; showPDF(){ let pdfPath = '/static/compressed.tracemonkey-pldi-09.pdf'; let loadingTask = PDFJS.getDocument(pdfPath); loadingTask.promise.then(function (pdfDocument) { // Request a first page return pdfDocument.getPage(1).then(function (pdfPage) { console.log("pdfPage is :",pdfPage); // Display page on the existing canvas with 100% scale. let scale = 1.5; let viewport = pdfPage.getViewport(scale); let canvas = document.getElementsByClassName('theCanvas'); canvas.width = viewport.width; canvas.height = viewport.height; let ctx = canvas.getContext('2d'); let renderTask = pdfPage.render({ canvasContext: ctx, viewport: viewport }); return renderTask.promise; }); }).catch(function (reason) { console.error('Error: ' + reason); }); },
PDFViewer.vueandroid
<template> <div class="pdf-view-layout"> <header> <h1 id="title"></h1> </header> <div id="viewerContainer"> <div id="viewer" class="pdfViewer"></div> </div> <div id="loadingBar"> <div class="progress"></div> <div class="glimmer"></div> </div> <div id="errorWrapper" hidden="true"> <div id="errorMessageLeft"> <span id="errorMessage"></span> <button id="errorShowMore"> More Information </button> <button id="errorShowLess"> Less Information </button> </div> <div id="errorMessageRight"> <button id="errorClose"> Close </button> </div> <div class="clearBoth"></div> <textarea id="errorMoreInfo" hidden="true" readonly="readonly"></textarea> </div> <footer> <button class="toolbarButton pageUp" title="Previous Page" id="previous" @click="goNextPage()"></button> <button class="toolbarButton pageDown" title="Next Page" id="next"></button> <input type="number" id="pageNumber" class="toolbarField pageNumber" size="4" min="1" > <button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut"></button> <button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button> </footer> </div> </template> <script> //加载PDFJS import pdf from '../../../node_modules/pdfjs-dist/build/pdf.js'; import pdfViewer from '../../../node_modules/pdfjs-dist/web/pdf_viewer.js'; import Viewer from '../../assets/js/viewer'; export default{ data(){ return{ myPage:1, } }, mounted(){ const url = 'http://192.168.0.200:8080/media/avatar/fluent-python.pdf'; Viewer.animationStartedPromise.then(function () { Viewer.open({ url: url }); }); }, methods:{ goNextPage(){ console.log('下一页的数据'); } }, watch:{ myPage(newV,oldV){ console.log("==================:",$('#pageNumber').val()); } }, } </script> <style scoped> @import "../../assets/css/viewer.css"; </style>
viewer.jswebpack
/* Copyright 2016 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* globals PDFJS */ 'use strict'; if (!PDFJS.PDFViewer || !PDFJS.getDocument) { alert('Please build the pdfjs-dist library using\n' + ' `gulp dist-install`'); } PDFJS.useOnlyCssZoom = true; PDFJS.disableTextLayer = true; PDFJS.maxImageSize = 1024 * 1024; PDFJS.workerSrc = '../../../node_modules/pdfjs-dist/build/pdf.worker.js'; PDFJS.cMapUrl = '../../../node_modules/pdfjs-dist/cmaps/'; PDFJS.cMapPacked = true; //须要加载的pdf的文件 // var DEFAULT_URL = 'https://cdn.rawgit.com/mozilla/pdf.js/c6e8ca86/test/pdfs/calrgb.pdf'; // var DEFAULT_URL = 'http://192.168.0.200:8080/media/avatar/fluent-python.pdf'; var DEFAULT_SCALE_DELTA = 1.0; var MIN_SCALE = 0.25; var MAX_SCALE = 100.0; var DEFAULT_SCALE_VALUE = 'auto'; var PDFViewerApplication = { pdfLoadingTask: null, pdfDocument: null, pdfViewer: null, pdfHistory: null, pdfLinkService: null, /** * Opens PDF document specified by URL. * @returns {Promise} - Returns the promise, which is resolved when document * is opened. */ open: function (params) { if (this.pdfLoadingTask) { // We need to destroy already opened document return this.close().then(function () { // ... and repeat the open() call. return this.open(params); }.bind(this)); } var url = params.url; var self = this; this.setTitleUsingUrl(url); // Loading document. var loadingTask = PDFJS.getDocument(url); this.pdfLoadingTask = loadingTask; loadingTask.onProgress = function (progressData) { self.progress(progressData.loaded / progressData.total); }; return loadingTask.promise.then(function (pdfDocument) { // Document loaded, specifying document for the viewer. self.pdfDocument = pdfDocument; self.pdfViewer.setDocument(pdfDocument); self.pdfLinkService.setDocument(pdfDocument); self.pdfHistory.initialize(pdfDocument.fingerprint); self.loadingBar.hide(); self.setTitleUsingMetadata(pdfDocument); }, function (exception) { var message = exception && exception.message; var l10n = self.l10n; var loadingErrorMessage; if (exception instanceof PDFJS.InvalidPDFException) { // change error message also for other builds loadingErrorMessage = l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.'); } else if (exception instanceof PDFJS.MissingPDFException) { // special message for missing PDFs loadingErrorMessage = l10n.get('missing_file_error', null, 'Missing PDF file.'); } else if (exception instanceof PDFJS.UnexpectedResponseException) { loadingErrorMessage = l10n.get('unexpected_response_error', null, 'Unexpected server response.'); } else { loadingErrorMessage = l10n.get('loading_error', null, 'An error occurred while loading the PDF.'); } loadingErrorMessage.then(function (msg) { self.error(msg, {message: message}); }); self.loadingBar.hide(); }); }, /** * Closes opened PDF document. * @returns {Promise} - Returns the promise, which is resolved when all * destruction is completed. */ close: function () { var errorWrapper = document.getElementById('errorWrapper'); errorWrapper.setAttribute('hidden', 'true'); if (!this.pdfLoadingTask) { return Promise.resolve(); } var promise = this.pdfLoadingTask.destroy(); this.pdfLoadingTask = null; if (this.pdfDocument) { this.pdfDocument = null; this.pdfViewer.setDocument(null); this.pdfLinkService.setDocument(null, null); } return promise; }, get loadingBar() { var bar = new PDFJS.ProgressBar('#loadingBar', {}); return PDFJS.shadow(this, 'loadingBar', bar); }, setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) { this.url = url; var title = PDFJS.getFilenameFromUrl(url) || url; try { title = decodeURIComponent(title); } catch (e) { // decodeURIComponent may throw URIError, // fall back to using the unprocessed url in that case } this.setTitle(title); }, setTitleUsingMetadata: function (pdfDocument) { var self = this; pdfDocument.getMetadata().then(function(data) { var info = data.info, metadata = data.metadata; self.documentInfo = info; self.metadata = metadata; // Provides some basic debug information console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (PDFJS.version || '-') + (!PDFJS.disableWebGL ? ' [WebGL]' : '') + ')'); var pdfTitle; if (metadata && metadata.has('dc:title')) { var title = metadata.get('dc:title'); // Ghostscript sometimes returns 'Untitled', so prevent setting the // title to 'Untitled. if (title !== 'Untitled') { pdfTitle = title; } } if (!pdfTitle && info && info['Title']) { pdfTitle = info['Title']; } if (pdfTitle) { self.setTitle(pdfTitle + ' - ' + document.title); } }); }, /** * 设置title标题 * @param title */ setTitle: function pdfViewSetTitle(title) { document.title = title; console.log("document.title:",document.title,document,document.getElementById('title').textContent); if(document.getElementById('title').textContent!==''){ document.getElementById('title').textContent = title; } }, error: function pdfViewError(message, moreInfo) { var l10n = this.l10n; var moreInfoText = [l10n.get('error_version_info', {version: PDFJS.version || '?', build: PDFJS.build || '?'}, 'PDF.js v{{version}} (build: {{build}})')]; if (moreInfo) { moreInfoText.push( l10n.get('error_message', {message: moreInfo.message}, 'Message: {{message}}')); if (moreInfo.stack) { moreInfoText.push( l10n.get('error_stack', {stack: moreInfo.stack}, 'Stack: {{stack}}')); } else { if (moreInfo.filename) { moreInfoText.push( l10n.get('error_file', {file: moreInfo.filename}, 'File: {{file}}')); } if (moreInfo.lineNumber) { moreInfoText.push( l10n.get('error_line', {line: moreInfo.lineNumber}, 'Line: {{line}}')); } } } var errorWrapper = document.getElementById('errorWrapper'); errorWrapper.removeAttribute('hidden'); var errorMessage = document.getElementById('errorMessage'); errorMessage.textContent = message; var closeButton = document.getElementById('errorClose'); closeButton.onclick = function() { errorWrapper.setAttribute('hidden', 'true'); }; var errorMoreInfo = document.getElementById('errorMoreInfo'); var moreInfoButton = document.getElementById('errorShowMore'); var lessInfoButton = document.getElementById('errorShowLess'); moreInfoButton.onclick = function() { errorMoreInfo.removeAttribute('hidden'); moreInfoButton.setAttribute('hidden', 'true'); lessInfoButton.removeAttribute('hidden'); errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px'; }; lessInfoButton.onclick = function() { errorMoreInfo.setAttribute('hidden', 'true'); moreInfoButton.removeAttribute('hidden'); lessInfoButton.setAttribute('hidden', 'true'); }; moreInfoButton.removeAttribute('hidden'); lessInfoButton.setAttribute('hidden', 'true'); Promise.all(moreInfoText).then(function (parts) { errorMoreInfo.value = parts.join('\n'); }); }, progress: function pdfViewProgress(level) { var percent = Math.round(level * 100); // Updating the bar if value increases. if (percent > this.loadingBar.percent || isNaN(percent)) { this.loadingBar.percent = percent; } }, get pagesCount() { return this.pdfDocument.numPages; }, set page(val) { this.pdfViewer.currentPageNumber = val; }, get page() { return this.pdfViewer.currentPageNumber; }, zoomIn: function pdfViewZoomIn(ticks) { var newScale = this.pdfViewer.currentScale; do { newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2); newScale = Math.ceil(newScale * 10) / 10; newScale = Math.min(MAX_SCALE, newScale); } while (--ticks && newScale < MAX_SCALE); this.pdfViewer.currentScaleValue = newScale; }, zoomOut: function pdfViewZoomOut(ticks) { var newScale = this.pdfViewer.currentScale; do { newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2); newScale = Math.floor(newScale * 10) / 10; newScale = Math.max(MIN_SCALE, newScale); } while (--ticks && newScale > MIN_SCALE); this.pdfViewer.currentScaleValue = newScale; }, initUI: function pdfViewInitUI() { var linkService = new PDFJS.PDFLinkService(); this.pdfLinkService = linkService; this.l10n = PDFJS.NullL10n; var container = document.getElementById('viewerContainer'); var pdfViewer = new PDFJS.PDFViewer({ container: container, linkService: linkService, l10n: this.l10n, }); this.pdfViewer = pdfViewer; linkService.setViewer(pdfViewer); this.pdfHistory = new PDFJS.PDFHistory({ linkService: linkService }); linkService.setHistory(this.pdfHistory); document.getElementById('previous').addEventListener('click', function() { PDFViewerApplication.page--; }); document.getElementById('next').addEventListener('click', function() { PDFViewerApplication.page++; }); document.getElementById('zoomIn').addEventListener('click', function() { PDFViewerApplication.zoomIn(); }); document.getElementById('zoomOut').addEventListener('click', function() { PDFViewerApplication.zoomOut(); }); document.getElementById('pageNumber').addEventListener('click', function() { this.select(); }); document.getElementById('pageNumber').addEventListener('change', function() { PDFViewerApplication.page = (this.value | 0); // Ensure that the page number input displays the correct value, even if the // value entered by the user was invalid (e.g. a floating point number). if (this.value !== PDFViewerApplication.page.toString()) { this.value = PDFViewerApplication.page; } }); container.addEventListener('pagesinit', function () { // We can use pdfViewer now, e.g. let's change default scale. pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; }); container.addEventListener('pagechange', function (evt) { var page = evt.pageNumber; var numPages = PDFViewerApplication.pagesCount; document.getElementById('pageNumber').value = page; document.getElementById('previous').disabled = (page <= 1); document.getElementById('next').disabled = (page >= numPages); }, true); } }; document.addEventListener('DOMContentLoaded', function () { PDFViewerApplication.initUI(); }, true); (function animationStartedClosure() { // The offsetParent is not set until the PDF.js iframe or object is visible. // Waiting for first animation. PDFViewerApplication.animationStartedPromise = new Promise( function (resolve) { window.requestAnimationFrame(resolve); }); })(); /*// We need to delay opening until all HTML is loaded. PDFViewerApplication.animationStartedPromise.then(function () { PDFViewerApplication.open({ url: DEFAULT_URL }); });*/ export default PDFViewerApplication;
v-cloak指令
加入style="-webkit-user-select: auto"就能出现光标和编辑了
`
s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); }, JsGuid() { return this.s4() + this.s4() + '-' + this.s4() + '-' + this.s4() + '-' + this.s4() + '-' + this.s4() + this.s4() + this.s4(); }, newWin(url, id,target) { let a = document.createElement('a'); a.setAttribute('href', url); a.setAttribute('target', target); a.setAttribute('id', id); // 防止反复添加 if(!document.getElementById(id)) { document.body.appendChild(a); } a.click(); },
`
this.newWin(localStorage.getItem('url'),"dow","csa"+this.JsGuid());
code
/**
*/ let logUtil = { flag:true, printLog(...items){ if(this.flag){ console.log(items); } } } export default logUtil
虚拟化技术的能够在BIOS中开启,开启方法以下:
一、进入BIOS。开机时按F2或F12或DEL或ESC等键(各电脑有所不一样)。 二、进入BIOS后,找到Configuration选项,选择Intel Virtual Technology并回车,将光标移至Enabled,而后再回车,最后按F10保存并退出。 若是找不到Configuration选项,能够试试下面的方法: (1)某些HP(惠普)电脑进入BIOS后,须要选择SystemConfiguration(系统配置)菜单,而后选择Device Configuration(设备配置),找到Virtualization Technology,设置为Enabled。 (2)某些联想Thinkpad电脑进入BIOS后,须要选择Security菜单,而后选择Virtualization,设置为Enabled。 (3)某些DELL(戴尔)电脑进入BIOS后,须要选择Processor Settings菜单,而后选择VirtualizationTechnology,设置为Enabled。 虚拟化在1960年为了描述虚拟机(实验性的IBM M44/44X系统)这个概念被第一次提出。对虚拟机的架设和管理被称为平台虚拟化,如今也被称为服务器虚拟化。
使用vue-cli打包后默认生产三个js文件
vender:3.34m app:1.26m,怎么去减小它们的体积
source map文件是js文件压缩后,文件的变量名替换对应、变量所在位置等元信息数据文件,通常这种文件和min.js主文件放在同一个目录下。 好比压缩后原变量是map,压缩后经过变量替换规则可能会被替换成a,这时source map文件会记录下这个mapping的信息,这样的好处就是说,在调试的时候,若是有一些JS报错,那么浏览器会经过解析这个map文件来从新merge压缩后的js,使开发者能够用未压缩前的代码来调试,这样会给咱们带来很大的方便!
根据vue的路由去按需加载组件
微信网页受权
苹果手机上设置分享的title的问题
微信分享
isWeiXin(){ //判断是不是微信浏览器 let ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) === 'micromessenger') { return true; } else { return false; } },
分享实现流程
④经过config接口注入权限验证配置
wx.config({ debug: true, appId: '', // 必填,公众号的惟一标识 timestamp: , // 必填,生成签名的时间戳 nonceStr: '', // 必填,生成签名的随机串 signature: '',// 必填,签名,见附录1 jsApiList: [] // 必填,须要使用的JS接口列表,全部JS接口列表见附录2 });
⑤经过ready接口处理成功验证
wx.ready(function(){ // config信息验证后会执行ready方法,全部接口调用都必须在config接口得到结果以后,config是一个客户端的异步操做,因此若是须要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则能够直接调用,不须要放在ready函数中。 //进行分享的操做 //分享到朋友圈 wx.onMenuShareTimeline({ title: '测试信息', // 分享标题 link: '', // 分享连接,该连接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: '', // 分享图标 success: function (res) { // 用户确认分享后执行的回调函数 logUtil.printLog("分享到朋友圈成功返回的信息为:",res); }, cancel: function (res) { // 用户取消分享后执行的回调函数 logUtil.printLog("取消分享到朋友圈返回的信息为:",res); } }); //分享给朋友 wx.onMenuShareAppMessage({ title: '', // 分享标题 desc: '', // 分享描述 link: '', // 分享连接,该连接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: '', // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 若是type是music或video,则要提供数据连接,默认为空 success: function (res) { // 用户确认分享后执行的回调函数 logUtil.printLog("分享给朋友成功返回的信息为:",res); }, cancel: function (res) { // 用户取消分享后执行的回调函数 logUtil.printLog("取消分享给朋友返回的信息为:",res); } }); //分享到QQ wx.onMenuShareQQ({ title: '', // 分享标题 desc: '', // 分享描述 link: '', // 分享连接 imgUrl: '', // 分享图标 success: function (res) { // 用户确认分享后执行的回调函数 logUtil.printLog("分享到QQ好友成功返回的信息为:",res); }, cancel: function (res) { // 用户取消分享后执行的回调函数 logUtil.printLog("取消分享给QQ好友返回的信息为:",res); } }); //分享到QQ空间 wx.onMenuShareQZone({ title: '', // 分享标题 desc: '', // 分享描述 link: '', // 分享连接 imgUrl: '', // 分享图标 success: function (res) { // 用户确认分享后执行的回调函数 logUtil.printLog("分享到QQ空间成功返回的信息为:",res); }, cancel: function (res) { // 用户取消分享后执行的回调函数 logUtil.printLog("取消分享到QQ空间返回的信息为:",res); } }); });
⑥经过error接口处理失败验证
// config信息验证失败会执行error函数,如签名过时致使验证失败,具体错误信息能够打开config的debug模式查看,也能够在返回的res参数中查看,对于SPA能够在这里更新签名。 });
获取access_token
请求接口:https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的appid&secret=你的secret 请求方法: get 返回结果: access_token (有效期7200秒,必须在服务端缓存)
获取票据jsapi_ticket
请求接口:https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=上一步中获取的access_token&type=jsapi 请求方法: get, type: JSON, 返回结果: jsapi_ticket (有效期7200秒,必须在服务端缓存)
生成时间戳(timestamp)
// 时间戳产生函数 var timeStamp = function () { return parseInt(new Date().getTime() / 1000) + ''; };
好比:
var calcSignature =function(ticket,nonceStr,timeStamp,url) { var result = { jsapi_ticket: ticket, nonceStr: nonceStr, timestamp: timeStamp, url: url, } var str = 'jsapi_ticket=' + ticket + '&noncestr=' + nonceStr + '×tamp=' + timeStamp + '&url=' + url; // 对str使用sha1签名,获得signature,这里使用jsSHA模块,需install shaObj = new jsSHA(str, 'TEXT'); result.signature = shaObj.getHash('SHA-1', 'HEX'); return result; // 返回到前端,提供接口由前端请求 }
微信分享问题总结:
ngork
问题描述
python sha1签名
js获取当前时间、时间戳
Vue路由按需加载
注意事项
须要在配置文件webpack.base.conf.js中加入
output:{ pathinfo: true }
Vue服务端渲染
后台管理
import axios from 'axios'; /** * 获取积分信息 * @param url * @returns {*} */ export function getJiFenDetailInfo(url) { return axios.get(url).then((res)=>{ return Promise.resolve(res); },(err)=>{ return Promise.reject(err); }); }
import axios from 'axios'; /** * 处理登陆 * @param url * @param mobile * @param password * @returns {*} */ export function dealLogin(url,mobile,password) { return axios.post(url,{ mobile:mobile, password:password }).then((res)=>{ return Promise.resolve(res); },(err)=>{ return Promise.reject(err); }); }
涉及点:Base64转换为file对象
/** * 将Base64转换为file对象 * @param dataurl:文件的base64表示 * @param filename:文件名 * @return {File}:返回的file对象 */ dataURLtoFile(dataurl, filename) { var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while(n--){ u8arr[n] = bstr.charCodeAt(n); } return new File([u8arr], filename, {type:mime}); },
发现ios低版本出现了兼容问题,最终发现问题出在new File()这里。那么就得想其余解决办法了,能够先将Base64进行二进制转换操做,最终将二进制转换为File对象就能够解决。
/** * 将base64先转换为二进制对象 * */ dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], { type: mime }); }, /** * 最后再将二进制转换为file对象 * */ blobToFile(theBlob, fileName){ theBlob.lastModifiedDate = new Date(); theBlob.name = fileName; return theBlob; },
it is done!