uni-app電子簽名

樣式

html部分

? uni-popup:是在uni-app官網(wǎng)下載的插件秸妥,僅做彈窗使用滚停,如果不需要此功能可刪掉,或使用別的插件粥惧。

<uni-popup ref="popup" :mask-click="false" background-color="white">

<view class="popup_footer">

<view style="display: flex; align-items: center;">

<image? src="../../../../static/img_mine/icon_qxy_qianming.png" mode="" class="popup_footer_img1"></image>

<view class="popup_footer_txt" @click="close">簽名</view>

</view>

<view @click="closed">

<image src="../../../../static/img_mine/close.png" mode="" class="popup_footer_img"></image>

</view>

</view>

<canvas

class="mycanvas"

canvas-id="mycanvas"

@touchstart="touchstart"

@touchmove="touchmove"

@touchend="touchend"

>

</canvas>

<view class="popup_footerd">

<view class="re_button" @click="reWrite">重寫</view>

<view class="button" @click="finish">確認</view>

</view>

</uni-popup>

js部分

<script>

? ? var x = 20;

? ? var y =20;?

export default {

onLoad() {

this.ctx = uni.createCanvasContext("mycanvas",this);? //創(chuàng)建繪圖對象

//設(shè)置畫筆樣式

this.ctx.lineWidth = 4;

this.ctx.lineCap = "round"

this.ctx.lineJoin = "round"

},

data() {

return {

? ? headerStyleHeight:0,

? ? headerStyleTop:0,

? ? ctx:"",

? ? points:[],? ? ? //路徑點集合

? ? showCanvas:false,

signature:'',

path: ''

}

},

methods: {

? ? ? ? ? ? open() {

this.$refs.popup.open('bottom')

},

closed() {

this.$refs.popup.close()

},

reWrite() {

this.clear();

},

//關(guān)閉并清空畫布

? ? ? close:function(){

? ? ? this.showCanvas = false;

? ? ? this.clear();

? ? ? },

? ? ? //創(chuàng)建并顯示畫布

? ? ? createCanvas:function(){

? ? ? this.showCanvas = true;?

? ? ? this.ctx = uni.createCanvasContext("mycanvas",this);? //創(chuàng)建繪圖對象? ? ?

? ? ? //設(shè)置畫筆樣式

? ? ? this.ctx.lineWidth = 4;

? ? ? this.ctx.lineCap = "round"

? ? ? this.ctx.lineJoin = "round"

? ? ? },

? ? ? //觸摸開始铐刘,獲取到起點

? ? ? touchstart:function(e){

? ? ? let startX = e.changedTouches[0].x;

? ? ? let startY = e.changedTouches[0].y;

? ? ? let startPoint = {X:startX,Y:startY};

? ? ? this.points.push(startPoint);

? ? ? //每次觸摸開始,開啟新的路徑

? ? ? this.ctx.beginPath();

? ? ? },? ?

? ? ? //觸摸移動影晓,獲取到路徑點

? ? ? touchmove:function(e){

? ? ? let moveX = e.changedTouches[0].x;

? ? ? let moveY = e.changedTouches[0].y;

? ? ? let movePoint = {X:moveX,Y:moveY};

? ? ? this.points.push(movePoint);? ? ? //存點

? ? ? let len = this.points.length;

? ? ? if(len>=2){

? ? ? this.draw();? ? ? ? ? ? ? ? ? //繪制路徑

? ? ? }? ? ?

? ? ? },

? ? ? touchend:function(){? ? ? ? ? ? ? ? ?

? ? ? this.points=[];

? ? ? },

? ? ? 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)

? ? ? },

? ? ? //清空畫布

? ? ? clear() {

? ? ? let that = this;

? ? ? uni.getSystemInfo({

? ? ? success(res) {

? ? ? let canvasw = res.windowWidth;

? ? ? let canvash = res.windowHeight;

? ? ? that.ctx.clearRect(0, 0, canvasw, canvash);

? ? ? that.ctx.draw(true);

? ? ? },

? ? ? })

? ? ? },

//完成繪畫

finish(){

uni.canvasToTempFilePath({

? canvasId: 'mycanvas',

? success: function(res) {

? ? let path = res.tempFilePath;

console.log(path)


? }

})

}

? ? }

}

</script>

css部分

.mycanvas{

width: 100%;

height: 500rpx;

}

.popup_footer{

width: auto;

height: 120rpx;

display: flex;

justify-content: space-between;

align-items: center;

border-bottom: 1rpx solid #979797;

margin: 0 30rpx 0 30rpx;

}

.popup_footerd{

width: auto;

height: 90rpx;

margin: 0 30rpx 30rpx 30rpx;

display: flex;

justify-content: flex-end;

align-items: center;

}

.popup_footer_img{

width: 32rpx;

height: 32rpx;

}

.popup_footer_img1{

width: 50rpx;

height: 50rpx;

}

.popup_footer_txt{

font-size: 28rpx;

font-weight: 400;

color: #333333;

margin-left: 27rpx;

}

.re_button{

width: 79rpx;

height: 44rpx;

text-align: center;

font-size: 24rpx;

line-height: 45rpx;

? ? border: 1px solid #979797;

border-radius: 10rpx;

color: #333333;

margin-right: 66rpx;

}

.button{

width: 79rpx;

height: 44rpx;

text-align: center;

font-size: 24rpx;

line-height: 45rpx;

background: #EF5350;

border: 1px solid #EF5350;

border-radius: 10rpx;

color: #F6F6F6;

}

.btn{

background: linear-gradient(360deg, #CCCCCC 0%, #F98156 0%, #EF5350 9%, #E53935 100%);

border-radius: 20rpx;

margin: 70rpx 88rpx 50rpx 88rpx;

color: #F6F6F6;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末镰吵,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子挂签,更是在濱河造成了極大的恐慌疤祭,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件饵婆,死亡現(xiàn)場離奇詭異勺馆,居然都是意外死亡,警方通過查閱死者的電腦和手機侨核,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進店門草穆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人搓译,你說我怎么就攤上這事悲柱。” “怎么了些己?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵豌鸡,是天一觀的道長嘿般。 經(jīng)常有香客問我,道長涯冠,這世上最難降的妖魔是什么炉奴? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮蛇更,結(jié)果婚禮上瞻赶,老公的妹妹穿的比我還像新娘。我一直安慰自己派任,他們只是感情好砸逊,可當我...
    茶點故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著吨瞎,像睡著了一般痹兜。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上颤诀,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天字旭,我揣著相機與錄音,去河邊找鬼崖叫。 笑死遗淳,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的心傀。 我是一名探鬼主播屈暗,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼脂男!你這毒婦竟也來了养叛?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤宰翅,失蹤者是張志新(化名)和其女友劉穎弃甥,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體汁讼,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡淆攻,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了嘿架。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片瓶珊。...
    茶點故事閱讀 40,001評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖耸彪,靈堂內(nèi)的尸體忽然破棺而出伞芹,到底是詐尸還是另有隱情,我是刑警寧澤搜囱,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布丑瞧,位于F島的核電站柑土,受9級特大地震影響蜀肘,放射性物質(zhì)發(fā)生泄漏绊汹。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一扮宠、第九天 我趴在偏房一處隱蔽的房頂上張望西乖。 院中可真熱鬧,春花似錦坛增、人聲如沸获雕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽届案。三九已至,卻和暖如春罢艾,著一層夾襖步出監(jiān)牢的瞬間楣颠,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工咐蚯, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留童漩,地道東北人。 一個月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓春锋,卻偏偏與公主長得像矫膨,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子期奔,可洞房花燭夜當晚...
    茶點故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容