123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <template>
- <view class="wrapper">
- <view class="handRight"></view>
- <view class="handBtn">
- <view class="slide-wrapper">
- <text>选择粗细</text>
- <slider @change="updateValue" value="25" show-value class="slider" step="25" />
- </view>
- </view>
- <view class="handCenter">
- <canvas class="handWriting" disable-scroll="true" @touchstart="uploadScaleStart"
- @touchmove="uploadScaleMove" @touchend="uploadScaleEnd" @tap="mouseDown" canvas-id="handWriting">
- </canvas>
- </view>
- <view class="showimg">
- <image v-if="showimg" :src="showimg" mode=""></image>
- <text v-else>图片展示</text>
- </view>
- <view class="buttons">
- <button @click="retDraw" class="delBtn">重写</button>
- <button @click="subCanvas" class="subBtn">保存</button>
- </view>
- </view>
- </template>
- <script>
- import Handwriting from "./js/signature.js"
- export default {
- data() {
- return {
- lineColor: 'black',
- slideValue: 25,
- handwriting: '',
- selectColor: 'black',
- color: '',
- showimg: '',
- share_popup: false,
-
- }
- },
- onLoad() {
- this.handwriting = new Handwriting({
- lineColor: this.lineColor,
- slideValue: this.slideValue, // 0, 25, 50, 75, 100
- canvasName: 'handWriting',
- })
-
- },
- methods: {
- // 选择画笔颜色
- selectColorEvent(event) {
- this.selectColor = event;
- if (event == 'black') {
- this.color = '#1A1A1A'
- } else if (event == 'red') {
- this.color = '#ca262a'
- }
- this.handwriting.selectColorEvent(this.color)
- },
- retDraw() {
- this.handwriting.retDraw()
- },
- // 笔迹粗细滑块
- updateValue(e) {
- console.log(e.detail);
- this.slideValue = e.detail.value;
- this.handwriting.selectSlideValue(this.slideValue);
- },
- uploadScaleStart(event) {
- this.handwriting.uploadScaleStart(event)
- },
- uploadScaleMove(event) {
- this.handwriting.uploadScaleMove(event)
- },
- uploadScaleEnd(event) {
- this.handwriting.uploadScaleEnd(event)
- },
- subCanvas() {
- this.handwriting.saveCanvas().then(res => {
- this.showimg = res;
- console.log(res);
-
- this.$api.worksheet_baseimg({
- staff_num: uni.getStorageSync('user').staff_num,
- base_img:res
- }).then((res)=>{
- uni.showToast({
- icon:"none",
- title:"保存成功"
- })
-
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
-
- console.log(res)
- })
-
-
- }).catch(err => {
- console.log(err);
- });
- },
- }
- }
- </script>
- <style scoped="true">
- view{
- display: flex;
- }
- .wrapper {
- width: 100%;
- height: 100%;
- margin: 30upx 0;
- overflow: hidden;
- display: flex;
- align-content: center;
- flex-direction: column;
- justify-content: center;
- font-size: 28upx;
- }
- .handWriting {
- background: #fff;
- width: 100%;
- height: 350upx;
- }
- .handRight {
- align-items: center;
- }
- .handCenter {
- border: 4upx dashed #e9e9e9;
- flex: 5;
- overflow: hidden;
- box-sizing: border-box;
- width: 90%;
- margin: 0 auto;
- }
- .handTitle {
- flex: 1;
- color: #666;
- justify-content: center;
- font-size: 30upx;
- }
- .handBtn {
- flex-direction: column;
- padding: 40upx 0;
- width: 90%;
- margin: 0 auto;
- }
- .buttons {
- width: 100%;
- margin-top: 100upx;
- justify-content: space-between;
- }
- .buttons>button {
- font-size: 30upx;
- height: 80upx;
- width: 120upx;
- }
- .delBtn {
- color: #666;
- }
- .color {
- align-items: center;
- }
- .color>text {
- margin-right: 20upx;
- }
- .subBtn {
- background: #008ef6;
- color: #fff;
- text-align: center;
- justify-content: center;
- }
- .black-select {
- width: 60upx;
- height: 60upx;
- }
- .black-select.color_select {
- width: 90upx;
- height: 90upx;
- }
- .red-select {
- width: 60upx;
- height: 60upx;
- }
- .red-select.color_select {
- width: 90upx;
- height: 90upx;
- }
- .slide-wrapper {
- align-items: center;
- margin-bottom: 20upx;
- }
- .slider {
- width: 400upx;
- padding-left: 20upx;
- }
- .drop {
- width: 50upx;
- height: 50upx;
- border-radius: 50%;
- background: #FFF;
- position: absolute;
- left: 0upx;
- top: -10upx;
- box-shadow: 0px 1px 5px #888888;
- }
- .slide {
- width: 250upx;
- height: 30upx;
- }
- .showimg {
- border: 4upx solid #e9e9e9;
- overflow: hidden;
- width: 90%;
- margin: 0 auto;
- background: #eee;
- height: 350upx;
- margin-top: 40upx;
- align-items: center;
- justify-content: center;
- }
- .showimg>image {
- width: 100%;
- height: 100%;
- }
- .showimg>text {
- font-size: 40upx;
- color: #888;
- }
- </style>
|