欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp實(shí)現(xiàn)橫屏簽字版

 更新時(shí)間:2022年07月08日 11:02:25   作者:勉灬之  
這篇文章主要為大家詳細(xì)介紹了uniapp實(shí)現(xiàn)橫屏簽字版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了uniapp實(shí)現(xiàn)橫屏簽字版的具體代碼,供大家參考,具體內(nèi)容如下

兼容H5、APP、微信小程序
可作為組件直接引入
通過(guò)this.$emit(‘tempFilePath’, val.tempFilePath)給予回調(diào)

<template>
?? ?<view class="main-content" v-if="isShow" @touchmove.stop.prevent="">
?? ??? ?<!-- 簽字canvas -->
?? ??? ?<canvas?
?? ??? ??? ?class="mycanvas"?
?? ??? ??? ?id="mycanvas"?
?? ??? ??? ?canvas-id="mycanvas"?
?? ??? ??? ?@touchstart="touchstart"?
?? ??? ??? ?@touchmove="touchmove"?
?? ??? ??? ?@touchend="touchend"
?? ??? ?></canvas>
?? ??? ?<!-- 旋轉(zhuǎn)canvas -->
?? ??? ?<canvas
?? ??? ??? ?class="mycanvas"
?? ??? ??? ?:style="{ 'z-index': -1, width: `${screenWidth}px`, height: `${(screenWidth * screenWidth) / screenHeight}px` }"
?? ??? ??? ?id="rotatCanvas"
?? ??? ??? ?canvas-id="rotatCanvas"
?? ??? ?></canvas>
?? ??? ?<cover-view class="button-line">
?? ??? ??? ?<cover-view class="save-button" @tap="finish">保存</cover-view>
?? ??? ??? ?<cover-view class="clear-button" @tap="clear">清除</cover-view>
?? ??? ??? ?<cover-view class="cancel-button" @tap="hide">關(guān)閉</cover-view>
?? ??? ?</cover-view>
?? ?</view>
</template>

<script>
export default {
?? ?data() {
?? ??? ?return {
?? ??? ??? ?ctx: '', //繪圖圖像
?? ??? ??? ?points: [], //路徑點(diǎn)集合
?? ??? ??? ?isShow: false,
?? ??? ??? ?screenWidth: '',
?? ??? ??? ?screenHeight: ''
?? ??? ?};
?? ?},
?? ?mounted() {
?? ??? ?this.createCanvas();
?? ??? ?uni.getSystemInfo({
?? ??? ??? ?success: e => {
?? ??? ??? ??? ?this.screenWidth = e.screenWidth;
?? ??? ??? ??? ?this.screenHeight = e.screenHeight;
?? ??? ??? ?}
?? ??? ?});
?? ?},
?? ?methods: {
?? ??? ?show() {
?? ??? ??? ?this.clear();
?? ??? ??? ?this.isShow = true;
?? ??? ?},
?? ??? ?hide() {
?? ??? ??? ?this.isShow = false;
?? ??? ?},
?? ??? ?//創(chuàng)建并顯示畫(huà)布
?? ??? ?createCanvas() {
?? ??? ??? ?this.showCanvas = true;
?? ??? ??? ?this.ctx = uni.createCanvasContext('mycanvas', this); //創(chuàng)建繪圖對(duì)象
?? ??? ??? ?//設(shè)置畫(huà)筆樣式
?? ??? ??? ?this.ctx.lineWidth = 2;
?? ??? ??? ?this.ctx.lineCap = 'round';
?? ??? ??? ?this.ctx.lineJoin = 'round';
?? ??? ?},
?? ??? ?//觸摸開(kāi)始,獲取到起點(diǎn)
?? ??? ?touchstart(e) {
?? ??? ??? ?let startX = e.changedTouches[0].x;
?? ??? ??? ?let startY = e.changedTouches[0].y;
?? ??? ??? ?let startPoint = {
?? ??? ??? ??? ?X: startX,
?? ??? ??? ??? ?Y: startY
?? ??? ??? ?};
?? ??? ??? ?this.points.push(startPoint);
?? ??? ??? ?//每次觸摸開(kāi)始,開(kāi)啟新的路徑
?? ??? ??? ?this.ctx.beginPath();
?? ??? ?},
?? ??? ?//觸摸移動(dòng),獲取到路徑點(diǎn)
?? ??? ?touchmove(e) {
?? ??? ??? ?let moveX = e.changedTouches[0].x;
?? ??? ??? ?let moveY = e.changedTouches[0].y;
?? ??? ??? ?let movePoint = {
?? ??? ??? ??? ?X: moveX,
?? ??? ??? ??? ?Y: moveY
?? ??? ??? ?};
?? ??? ??? ?this.points.push(movePoint); //存點(diǎn)
?? ??? ??? ?let len = this.points.length;
?? ??? ??? ?if (len >= 2) {
?? ??? ??? ??? ?this.draw(); //繪制路徑
?? ??? ??? ?}
?? ??? ?},
?? ??? ?// 觸摸結(jié)束,將未繪制的點(diǎn)清空防止對(duì)后續(xù)路徑產(chǎn)生干擾
?? ??? ?touchend() {
?? ??? ??? ?this.points = [];
?? ??? ?},
?? ??? ?/* ***********************************************
?? ??? ??? ?# ? 繪制筆跡
?? ??? ??? ?#?? ?1.為保證筆跡實(shí)時(shí)顯示,必須在移動(dòng)的同時(shí)繪制筆跡
?? ??? ??? ?#?? ?2.為保證筆跡連續(xù),每次從路徑集合中區(qū)兩個(gè)點(diǎn)作為起點(diǎn)(moveTo)和終點(diǎn)(lineTo)
?? ??? ??? ?#?? ?3.將上一次的終點(diǎn)作為下一次繪制的起點(diǎn)(即清除第一個(gè)點(diǎn))
?? ??? ??? ?************************************************ */
?? ??? ?draw() {
?? ??? ??? ?let point1 = this.points[0];
?? ??? ??? ?let point2 = this.points[1];
?? ??? ??? ?this.points.shift();
?? ??? ??? ?this.ctx.moveTo(point1.X, point1.Y);
?? ??? ??? ?this.ctx.lineTo(point2.X, point2.Y);
?? ??? ??? ?this.ctx.stroke();
?? ??? ??? ?this.ctx.draw(true);
?? ??? ?},
?? ??? ?//清空畫(huà)布
?? ??? ?clear() {
?? ??? ??? ?this.ctx.clearRect(0, 0, this.screenWidth, this.screenHeight);
?? ??? ??? ?this.ctx.draw(true);
?? ??? ?},
?? ??? ?//完成繪畫(huà)并保存到本地
?? ??? ?finish() {
?? ??? ??? ?uni.canvasToTempFilePath(
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?canvasId: 'mycanvas',
?? ??? ??? ??? ??? ?success: res => {
?? ??? ??? ??? ??? ??? ?this.rotat(res.tempFilePath);
?? ??? ??? ??? ??? ?},
?? ??? ??? ??? ??? ?complete: com => {}
?? ??? ??? ??? ?},
?? ??? ??? ??? ?this
?? ??? ??? ?);
?? ??? ?},
?? ??? ?// 將圖片選裝
?? ??? ?rotat(e) {
?? ??? ??? ?let rotatCtx = uni.createCanvasContext('rotatCanvas', this); //創(chuàng)建繪圖對(duì)象
?? ??? ??? ?// 重新定位中心點(diǎn)
?? ??? ??? ?rotatCtx.translate(0, (this.screenWidth * this.screenWidth) / this.screenHeight);
?? ??? ??? ?// 將畫(huà)布逆時(shí)針旋轉(zhuǎn)90度
?? ??? ??? ?rotatCtx.rotate((270 * Math.PI) / 180);
?? ??? ??? ?// 將簽字圖片繪制進(jìn)入Canvas
?? ??? ??? ?rotatCtx.drawImage(e, 0, 0, (this.screenWidth * this.screenWidth) / this.screenHeight, this.screenWidth);
?? ??? ??? ?// 保存后旋轉(zhuǎn)后的結(jié)果
?? ??? ??? ?rotatCtx.draw(true);
?? ??? ??? ?setTimeout(() => {
?? ??? ??? ??? ?// 生成圖片并回調(diào)
?? ??? ??? ??? ?uni.canvasToTempFilePath(
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?canvasId: 'rotatCanvas',
?? ??? ??? ??? ??? ??? ?success: val => {
?? ??? ??? ??? ??? ??? ??? ?this.$emit('tempFilePath', val.tempFilePath);
?? ??? ??? ??? ??? ??? ??? ?setTimeout(() => {
?? ??? ??? ??? ??? ??? ??? ??? ?this.hide();
?? ??? ??? ??? ??? ??? ??? ?}, 500);
?? ??? ??? ??? ??? ??? ?},
?? ??? ??? ??? ??? ??? ?complete: com => {
?? ??? ??? ??? ??? ??? ??? ?// console.log(com);
?? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?},
?? ??? ??? ??? ??? ?this
?? ??? ??? ??? ?);
?? ??? ??? ?}, 500);
?? ??? ?}
?? ?}
};
</script>

<style lang="scss" scoped>
.main-content {
?? ?width: 100vw;
?? ?height: 100vh;
?? ?background-color: red;
?? ?position: fixed;
?? ?top: 0rpx;
?? ?left: 0rpx;
?? ?z-index: 9999;
}
.mycanvas {
?? ?width: 100vw;
?? ?height: 100vh;
?? ?background-color: #efefef;
?? ?position: fixed;
?? ?left: 0rpx;
?? ?top: 0rpx;
?? ?z-index: 2;
}
.button-line {
?? ?transform: rotate(90deg);
?? ?position: fixed;
?? ?bottom: 170rpx;
?? ?left: -100rpx;
?? ?width: 340rpx;
?? ?height: 50rpx;
?? ?display: flex;
?? ?align-items: center;
?? ?justify-content: space-between;
?? ?z-index: 999;
}
.button-style {
?? ?color: #ffffff;
?? ?width: 100rpx;
?? ?height: 60rpx;
?? ?text-align: center;
?? ?line-height: 60rpx;
?? ?border-radius: 10rpx;
}
.save-button {
?? ?@extend .button-style;
?? ?background-color: #02b340;
}
.clear-button {
?? ?@extend .button-style;
?? ?background-color: #ffa500;
}
.cancel-button {
?? ?@extend .button-style;
?? ?background-color: #e10b2b;
}
</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript數(shù)組reduce()方法的語(yǔ)法與實(shí)例解析

    JavaScript數(shù)組reduce()方法的語(yǔ)法與實(shí)例解析

    js函數(shù)中有三個(gè)在特定場(chǎng)合很好用的函數(shù):reduce(),map(),filter(),這篇文章主要給大家介紹了關(guān)于JavaScript數(shù)組reduce()方法的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • javascript:void(0)是什么意思及href=#與href=javascriptvoid(0)的區(qū)別

    javascript:void(0)是什么意思及href=#與href=javascriptvoid(0)的區(qū)別

    Javascript中void是一個(gè)操作符,該操作符指定要計(jì)算一個(gè)表達(dá)式但是不返回值,本文給大家介紹javascript:void(0)是什么意思及href=#與href=javascriptvoid(0)的區(qū)別,需要的朋友參考下
    2015-11-11
  • javascript 判斷整數(shù)方法分享

    javascript 判斷整數(shù)方法分享

    本文介紹了使用javascript判斷整數(shù)的2種方法中的一種正則判斷,因?yàn)橹鹱峙袛嘈侍拖铝?,有相同需求的小伙伴們參考?/div> 2014-12-12
  • js實(shí)現(xiàn)收縮菜單效果實(shí)例代碼

    js實(shí)現(xiàn)收縮菜單效果實(shí)例代碼

    這篇文章介紹了js實(shí)現(xiàn)收縮菜單效果實(shí)例代碼,有需要的朋友可以參考一下
    2013-10-10
  • Javascript連接數(shù)據(jù)庫(kù)查詢(xún)并插入數(shù)據(jù)

    Javascript連接數(shù)據(jù)庫(kù)查詢(xún)并插入數(shù)據(jù)

    這篇文章主要介紹了Javascript連接數(shù)據(jù)庫(kù)查詢(xún)并插入數(shù)據(jù),下面文章圍繞主題展開(kāi)詳細(xì)內(nèi)容,具有一的參考價(jià)值,需要的小伙伴可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助
    2022-03-03
  • webpack自動(dòng)打包和熱更新的實(shí)現(xiàn)方法

    webpack自動(dòng)打包和熱更新的實(shí)現(xiàn)方法

    這篇文章主要介紹了webpack自動(dòng)打包和熱更新的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • es6中??與||區(qū)別小結(jié)

    es6中??與||區(qū)別小結(jié)

    本文主要介紹了es6中??與||區(qū)別小結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-01-01
  • document.execCommand()的用法小結(jié)

    document.execCommand()的用法小結(jié)

    本篇文章主要是對(duì)document.execCommand()的用法進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
    2014-01-01
  • js中eval()函數(shù)和trim()去掉字符串左右空格應(yīng)用

    js中eval()函數(shù)和trim()去掉字符串左右空格應(yīng)用

    對(duì)于js中eval()函數(shù)的理解和寫(xiě)一個(gè)函數(shù)trim()去掉字符串左右空格;對(duì)于js中eval()函數(shù)的理解是本人心得不一定正確,感興趣的朋友參考下,或許對(duì)你學(xué)習(xí)eval()函數(shù)有所幫助
    2013-02-02
  • 深入理解JS DOM事件機(jī)制

    深入理解JS DOM事件機(jī)制

    下面小編就為大家?guī)?lái)一篇深入理解JS DOM事件機(jī)制。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-08-08

最新評(píng)論