uniapp+canvas实现手写签字

借鉴文章







// httpUtil.js
const host = `https://xxx/`;
let fileUrl = 'https://xxx/'; //文件服务
let imageUrl = 'https://xxx/'; //图片文件服务
let caseHost = "https://xxx/"
const fingerPkg = 'com.xxx' // 指纹采集包名

const reportBook = imageUrl + "xx" // 告知书地址

const androidPkgUrl = imageUrl + "xxxx" // 安卓安装包地址


const pageSize = 10;


var quanliyiwugaozhishu = 'https://xxx' // 权利义务告知书
var shigurendingshu = 'https://xxx' //事故认定书
var searchLetter = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
import Local from '@/utils/local.js';
import Common from '@/utils/common.js';
let httpUtil = {
    getData: (url, data, method, callBack, msg) => {
        // 检测网络是否可用
        uni.getNetworkType({
            success: function (res) {
                let networkType = res.networkType;
                if (networkType == 'none') {
                    // 无网络
                    uni.showToast({
                        title: '无网络',
                        icon: 'none',
                        duration: 500
                    })
                } else {
                    var header = {
                        'Content-Type': 'application/json'
                    }

                    var urlString = "", dataNew = '';
                    if ((method == 'get' || method == 'GET') && url.indexOf('getWxConfig') < 0) {
                        // get 请求讲请求数据拼接在url上
                        for (var key in data) {
                            if (urlString != '') {
                                urlString = urlString + '&' + key + '=' + data[key]
                            } else {
                                urlString = urlString + '?' + key + '=' + data[key]
                            }
                        }
                        if (urlString == '') {
                            urlString = url;
                        } else {
                            urlString = url + urlString
                        }
                    } else {
                        dataNew = JSON.stringify(data)
                        urlString = url;
                    }

                    if (url.indexOf('getWxConfig') < 0 && url.indexOf('oauth2wx') < 0) {
                        if (Local.local.getItem("token") != '' && Local.local.getItem("token") != undefined) {
                            header.Authorization = Local.local.getItem("token")
                        }

                    }

                    uni.request({
                        method: method,
                        url: urlString,
                        data: dataNew,
                        header: header,
                        success: res => {
                            console.log(res)
                            if (msg == '更新') {
                                callBack(res.data)
                                return
                            }
                            if (urlString.indexOf('qywx/oauth2wx') >= 0) {
                                callBack(res.data)
                            }
                            if (res.header.token != '' && res.header.token != undefined) {
                                // 更新token
                                Local.local.setItem("token", res.header.token)
                            }
                            if (res.data.success == true) {
                                callBack(res.data)
                            } else {
                                if (url.indexOf("getWxConfig") >= 0) {
                                    Local.local.removeItem('perm')
                                    callBack("error")
                                } else {

                                    if (res.data.errMessage != null && res.data.errMessage != "" && res.data.errMessage != undefined) {
                                        uni.showToast({
                                            title: res.data.errMessage,
                                            icon: 'none',
                                            duration: 2000
                                        })
                                    }

                                    if (res.data.errCode == "InvalidToken") {
                                        // token 过期到登录界面
                                        // #ifdef APP-PLUS
                                        wx.clearStorage()
                                        setTimeout(function () {
                                            uni.redirectTo({
                                                url: "/pages/app/login/login"
                                            })
                                        }, 1000)
                                        // #endif
                                    }

                                }
                                return;
                            }
                        },
                        fail: err => {
                            uni.showToast({
                                title: err.message,
                                icon: 'none',
                                duration: 2000
                            })
                        }
                    })
                }
            }
        })
    }
}

// 输出
module.exports = {
    host: host,
    httpUtil: httpUtil,
    imageUrl: imageUrl,
    caseHost: caseHost,
    pageSize: pageSize,
    fileUrl: fileUrl,
    searchLetter: searchLetter,
    fingerPkg: fingerPkg,
    reportBook: reportBook,
    androidPkgUrl: androidPkgUrl,
    quanliyiwugaozhishu: quanliyiwugaozhishu,
    shigurendingshu: shigurendingshu
}
// local.js
let local = {
    // 同步获取存储数据
    getItem:key =>{
        return wx.getStorageSync(key);
    },
    // 异步获取存储数据
    getItemAsyn:(key,callBck) =>wx.getStorage({
        key: key,
        success:function(res){
            callBck(res.data)
        }
    }),
    // 异步设置存储数据
    setItem:(key,value) =>wx.setStorage({
      key: key,
      data: value,
    }),
    setItemNow:(key,value)=>wx.setStorageSync(key, value),
    // 情况缓存
    clear:() => wx.clearStorage(),
    // 删除异步存储数据
    removeItem:key => {
        let guard;
        wx.removeStorage({
            key: key,
            success: () => guard = true,
            fail:  () => guard = false,
        })
        return guard;
    },
    // 异步获取storage信息
    getSize:() =>{
        let size;
        wx.getStorageInfo({
            success: res => size = res.currentSize
        })
    },
}

module.exports = {
    local: local
}

你可能感兴趣的:(uniapp+canvas实现手写签字)