master
parent
5b08295e2c
commit
28f6a5c350
@ -0,0 +1,3 @@
|
||||
{
|
||||
"javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true
|
||||
}
|
||||
@ -0,0 +1,196 @@
|
||||
function getLocalFilePath(path) {
|
||||
if (path.indexOf('_www') === 0 || path.indexOf('_doc') === 0 || path.indexOf('_documents') === 0 || path.indexOf('_downloads') === 0) {
|
||||
return path
|
||||
}
|
||||
if (path.indexOf('file://') === 0) {
|
||||
return path
|
||||
}
|
||||
if (path.indexOf('/storage/emulated/0/') === 0) {
|
||||
return path
|
||||
}
|
||||
if (path.indexOf('/') === 0) {
|
||||
var localFilePath = plus.io.convertAbsoluteFileSystem(path)
|
||||
if (localFilePath !== path) {
|
||||
return localFilePath
|
||||
} else {
|
||||
path = path.substr(1)
|
||||
}
|
||||
}
|
||||
return '_www/' + path
|
||||
}
|
||||
|
||||
function dataUrlToBase64(str) {
|
||||
var array = str.split(',')
|
||||
return array[array.length - 1]
|
||||
}
|
||||
|
||||
var index = 0
|
||||
function getNewFileId() {
|
||||
return Date.now() + String(index++)
|
||||
}
|
||||
|
||||
function biggerThan(v1, v2) {
|
||||
var v1Array = v1.split('.')
|
||||
var v2Array = v2.split('.')
|
||||
var update = false
|
||||
for (var index = 0; index < v2Array.length; index++) {
|
||||
var diff = v1Array[index] - v2Array[index]
|
||||
if (diff !== 0) {
|
||||
update = diff > 0
|
||||
break
|
||||
}
|
||||
}
|
||||
return update
|
||||
}
|
||||
|
||||
export function pathToBase64(path) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof window === 'object' && 'document' in window) {
|
||||
if (typeof FileReader === 'function') {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', path, true)
|
||||
xhr.responseType = 'blob'
|
||||
xhr.onload = function() {
|
||||
if (this.status === 200) {
|
||||
let fileReader = new FileReader()
|
||||
fileReader.onload = function(e) {
|
||||
resolve(e.target.result)
|
||||
}
|
||||
fileReader.onerror = reject
|
||||
fileReader.readAsDataURL(this.response)
|
||||
}
|
||||
}
|
||||
xhr.onerror = reject
|
||||
xhr.send()
|
||||
return
|
||||
}
|
||||
var canvas = document.createElement('canvas')
|
||||
var c2x = canvas.getContext('2d')
|
||||
var img = new Image
|
||||
img.onload = function() {
|
||||
canvas.width = img.width
|
||||
canvas.height = img.height
|
||||
c2x.drawImage(img, 0, 0)
|
||||
resolve(canvas.toDataURL())
|
||||
canvas.height = canvas.width = 0
|
||||
}
|
||||
img.onerror = reject
|
||||
img.src = path
|
||||
return
|
||||
}
|
||||
if (typeof plus === 'object') {
|
||||
plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), function(entry) {
|
||||
entry.file(function(file) {
|
||||
var fileReader = new plus.io.FileReader()
|
||||
fileReader.onload = function(data) {
|
||||
resolve(data.target.result)
|
||||
}
|
||||
fileReader.onerror = function(error) {
|
||||
reject(error)
|
||||
}
|
||||
fileReader.readAsDataURL(file)
|
||||
}, function(error) {
|
||||
reject(error)
|
||||
})
|
||||
}, function(error) {
|
||||
reject(error)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
|
||||
wx.getFileSystemManager().readFile({
|
||||
filePath: path,
|
||||
encoding: 'base64',
|
||||
success: function(res) {
|
||||
resolve('data:image/png;base64,' + res.data)
|
||||
},
|
||||
fail: function(error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
reject(new Error('not support'))
|
||||
})
|
||||
}
|
||||
|
||||
export function base64ToPath(base64) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof window === 'object' && 'document' in window) {
|
||||
base64 = base64.split(',')
|
||||
var type = base64[0].match(/:(.*?);/)[1]
|
||||
var str = atob(base64[1])
|
||||
var n = str.length
|
||||
var array = new Uint8Array(n)
|
||||
while (n--) {
|
||||
array[n] = str.charCodeAt(n)
|
||||
}
|
||||
return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([array], { type: type })))
|
||||
}
|
||||
var extName = base64.split(',')[0].match(/data\:\S+\/(\S+);/)
|
||||
if (extName) {
|
||||
extName = extName[1]
|
||||
} else {
|
||||
reject(new Error('base64 error'))
|
||||
}
|
||||
var fileName = getNewFileId() + '.' + extName
|
||||
if (typeof plus === 'object') {
|
||||
var basePath = '_doc'
|
||||
var dirPath = 'uniapp_temp'
|
||||
var filePath = basePath + '/' + dirPath + '/' + fileName
|
||||
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
|
||||
plus.io.resolveLocalFileSystemURL(basePath, function(entry) {
|
||||
entry.getDirectory(dirPath, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function(entry) {
|
||||
entry.getFile(fileName, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function(entry) {
|
||||
entry.createWriter(function(writer) {
|
||||
writer.onwrite = function() {
|
||||
resolve(filePath)
|
||||
}
|
||||
writer.onerror = reject
|
||||
writer.seek(0)
|
||||
writer.writeAsBinary(dataUrlToBase64(base64))
|
||||
}, reject)
|
||||
}, reject)
|
||||
}, reject)
|
||||
}, reject)
|
||||
return
|
||||
}
|
||||
var bitmap = new plus.nativeObj.Bitmap(fileName)
|
||||
bitmap.loadBase64Data(base64, function() {
|
||||
bitmap.save(filePath, {}, function() {
|
||||
bitmap.clear()
|
||||
resolve(filePath)
|
||||
}, function(error) {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
}, function(error) {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
|
||||
var filePath = wx.env.USER_DATA_PATH + '/' + fileName
|
||||
wx.getFileSystemManager().writeFile({
|
||||
filePath: filePath,
|
||||
data: dataUrlToBase64(base64),
|
||||
encoding: 'base64',
|
||||
success: function() {
|
||||
resolve(filePath)
|
||||
},
|
||||
fail: function(error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
reject(new Error('not support'))
|
||||
})
|
||||
}
|
||||
@ -1,112 +1,163 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"moment@2.29.3",
|
||||
"/Users/mac/Documents/朗业/2023/b-bd智能访客系统/szbd-vistor-wx"
|
||||
]
|
||||
],
|
||||
"_from": "moment@2.29.3",
|
||||
"_id": "moment@2.29.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==",
|
||||
"_location": "/moment",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "moment@2.29.3",
|
||||
"name": "moment",
|
||||
"version": "2.29.3",
|
||||
"description": "Parse, validate, manipulate, and display dates",
|
||||
"homepage": "https://momentjs.com",
|
||||
"author": "Iskren Ivov Chernev <iskren.chernev@gmail.com> (https://github.com/ichernev)",
|
||||
"contributors": [
|
||||
"Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)",
|
||||
"Rocky Meza (http://rockymeza.com)",
|
||||
"Matt Johnson <mj1856@hotmail.com> (http://codeofmatt.com)",
|
||||
"Isaac Cambron <isaac@isaaccambron.com> (http://isaaccambron.com)",
|
||||
"Andre Polykanine <andre@oire.org> (https://github.com/oire)"
|
||||
],
|
||||
"keywords": [
|
||||
"moment",
|
||||
"date",
|
||||
"time",
|
||||
"parse",
|
||||
"format",
|
||||
"validate",
|
||||
"i18n",
|
||||
"l10n",
|
||||
"ender"
|
||||
],
|
||||
"main": "./moment.js",
|
||||
"jsnext:main": "./dist/moment.js",
|
||||
"typings": "./moment.d.ts",
|
||||
"typesVersions": {
|
||||
">=3.1": {
|
||||
"*": [
|
||||
"ts3.1-typings/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/moment/moment.git"
|
||||
"escapedName": "moment",
|
||||
"rawSpec": "2.29.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.29.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz",
|
||||
"_spec": "2.29.3",
|
||||
"_where": "/Users/mac/Documents/朗业/2023/b-bd智能访客系统/szbd-vistor-wx",
|
||||
"author": {
|
||||
"name": "Iskren Ivov Chernev",
|
||||
"email": "iskren.chernev@gmail.com",
|
||||
"url": "https://github.com/ichernev"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/moment/moment/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Tim Wood",
|
||||
"email": "washwithcare@gmail.com",
|
||||
"url": "http://timwoodcreates.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/moment/moment/issues"
|
||||
{
|
||||
"name": "Rocky Meza",
|
||||
"url": "http://rockymeza.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"benchmark": "latest",
|
||||
"coveralls": "latest",
|
||||
"cross-env": "^6.0.3",
|
||||
"es6-promise": "latest",
|
||||
"eslint": "~6",
|
||||
"grunt": "latest",
|
||||
"grunt-benchmark": "latest",
|
||||
"grunt-cli": "latest",
|
||||
"grunt-contrib-clean": "latest",
|
||||
"grunt-contrib-concat": "latest",
|
||||
"grunt-contrib-copy": "latest",
|
||||
"grunt-contrib-uglify": "latest",
|
||||
"grunt-contrib-watch": "latest",
|
||||
"grunt-env": "latest",
|
||||
"grunt-exec": "latest",
|
||||
"grunt-karma": "latest",
|
||||
"grunt-nuget": "latest",
|
||||
"grunt-string-replace": "latest",
|
||||
"karma": "latest",
|
||||
"karma-chrome-launcher": "latest",
|
||||
"karma-firefox-launcher": "latest",
|
||||
"karma-qunit": "latest",
|
||||
"karma-sauce-launcher": "4.1.4",
|
||||
"load-grunt-tasks": "latest",
|
||||
"lodash": ">=4.17.19",
|
||||
"node-qunit": "latest",
|
||||
"nyc": "latest",
|
||||
"prettier": "latest",
|
||||
"qunit": "^2.10.0",
|
||||
"rollup": "2.17.1",
|
||||
"typescript": "^1.8.10",
|
||||
"typescript3": "npm:typescript@^3.1.6",
|
||||
"uglify-js": "latest"
|
||||
{
|
||||
"name": "Matt Johnson",
|
||||
"email": "mj1856@hotmail.com",
|
||||
"url": "http://codeofmatt.com"
|
||||
},
|
||||
"ender": "./ender.js",
|
||||
"dojoBuild": "package.js",
|
||||
"jspm": {
|
||||
"files": [
|
||||
"moment.js",
|
||||
"moment.d.ts",
|
||||
"locale"
|
||||
],
|
||||
"map": {
|
||||
"moment": "./moment"
|
||||
},
|
||||
"buildConfig": {
|
||||
"uglify": true
|
||||
}
|
||||
{
|
||||
"name": "Isaac Cambron",
|
||||
"email": "isaac@isaaccambron.com",
|
||||
"url": "http://isaaccambron.com"
|
||||
},
|
||||
"scripts": {
|
||||
"ts3.1-typescript-test": "cross-env node_modules/typescript3/bin/tsc --project ts3.1-typing-tests",
|
||||
"typescript-test": "cross-env node_modules/typescript/bin/tsc --project typing-tests",
|
||||
"test": "grunt test",
|
||||
"eslint": "eslint Gruntfile.js tasks src",
|
||||
"prettier-check": "prettier --check Gruntfile.js tasks src",
|
||||
"prettier-fmt": "prettier --write Gruntfile.js tasks src",
|
||||
"coverage": "nyc npm test && nyc report",
|
||||
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
|
||||
{
|
||||
"name": "Andre Polykanine",
|
||||
"email": "andre@oire.org",
|
||||
"url": "https://github.com/oire"
|
||||
}
|
||||
],
|
||||
"description": "Parse, validate, manipulate, and display dates",
|
||||
"devDependencies": {
|
||||
"benchmark": "latest",
|
||||
"coveralls": "latest",
|
||||
"cross-env": "^6.0.3",
|
||||
"es6-promise": "latest",
|
||||
"eslint": "~6",
|
||||
"grunt": "latest",
|
||||
"grunt-benchmark": "latest",
|
||||
"grunt-cli": "latest",
|
||||
"grunt-contrib-clean": "latest",
|
||||
"grunt-contrib-concat": "latest",
|
||||
"grunt-contrib-copy": "latest",
|
||||
"grunt-contrib-uglify": "latest",
|
||||
"grunt-contrib-watch": "latest",
|
||||
"grunt-env": "latest",
|
||||
"grunt-exec": "latest",
|
||||
"grunt-karma": "latest",
|
||||
"grunt-nuget": "latest",
|
||||
"grunt-string-replace": "latest",
|
||||
"karma": "latest",
|
||||
"karma-chrome-launcher": "latest",
|
||||
"karma-firefox-launcher": "latest",
|
||||
"karma-qunit": "latest",
|
||||
"karma-sauce-launcher": "4.1.4",
|
||||
"load-grunt-tasks": "latest",
|
||||
"lodash": ">=4.17.19",
|
||||
"node-qunit": "latest",
|
||||
"nyc": "latest",
|
||||
"prettier": "latest",
|
||||
"qunit": "^2.10.0",
|
||||
"rollup": "2.17.1",
|
||||
"typescript": "^1.8.10",
|
||||
"typescript3": "npm:typescript@^3.1.6",
|
||||
"uglify-js": "latest"
|
||||
},
|
||||
"dojoBuild": "package.js",
|
||||
"ender": "./ender.js",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://momentjs.com",
|
||||
"jsnext:main": "./dist/moment.js",
|
||||
"jspm": {
|
||||
"files": [
|
||||
"moment.js",
|
||||
"moment.d.ts",
|
||||
"locale"
|
||||
],
|
||||
"map": {
|
||||
"moment": "./moment"
|
||||
},
|
||||
"spm": {
|
||||
"main": "moment.js",
|
||||
"output": [
|
||||
"locale/*.js"
|
||||
]
|
||||
"buildConfig": {
|
||||
"uglify": true
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"moment",
|
||||
"date",
|
||||
"time",
|
||||
"parse",
|
||||
"format",
|
||||
"validate",
|
||||
"i18n",
|
||||
"l10n",
|
||||
"ender"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./moment.js",
|
||||
"name": "moment",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/moment/moment.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "nyc npm test && nyc report",
|
||||
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
||||
"eslint": "eslint Gruntfile.js tasks src",
|
||||
"prettier-check": "prettier --check Gruntfile.js tasks src",
|
||||
"prettier-fmt": "prettier --write Gruntfile.js tasks src",
|
||||
"test": "grunt test",
|
||||
"ts3.1-typescript-test": "cross-env node_modules/typescript3/bin/tsc --project ts3.1-typing-tests",
|
||||
"typescript-test": "cross-env node_modules/typescript/bin/tsc --project typing-tests"
|
||||
},
|
||||
"spm": {
|
||||
"main": "moment.js",
|
||||
"output": [
|
||||
"locale/*.js"
|
||||
]
|
||||
},
|
||||
"typesVersions": {
|
||||
">=3.1": {
|
||||
"*": [
|
||||
"ts3.1-typings/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"typings": "./moment.d.ts",
|
||||
"version": "2.29.3"
|
||||
}
|
||||
|
||||
@ -0,0 +1,159 @@
|
||||
<template>
|
||||
<view class="containers">
|
||||
<view class="signwrap">
|
||||
<l-signature disableScroll backgroundColor="#ddd" ref="signatureRef" :penColor="penColor"
|
||||
:penSize="penSize"></l-signature>
|
||||
</view>
|
||||
<view class="signbtns justify-between">
|
||||
<button type="primary" @click="onClick('clear')">清空</button>
|
||||
<button type="primary" @click="onClick('undo')">撤消</button>
|
||||
<button type="primary" @click="onClick('save')">保存</button>
|
||||
<!-- <button @click="onClick('openSmooth')">压感{{openSmooth?'开':'关'}}</button> -->
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
base64ToPath
|
||||
} from 'image-tools'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
id:"",
|
||||
title: 'Hello',
|
||||
penColor: 'black',
|
||||
penSize: 5,
|
||||
urls: '',
|
||||
accept_admin_sign:"",
|
||||
picForm:{},
|
||||
host:''
|
||||
}
|
||||
},
|
||||
onLoad(options){
|
||||
this.id = options.id
|
||||
this.host = this.util.HOST
|
||||
this.loadDetail()
|
||||
},
|
||||
methods: {
|
||||
onClick(type) {
|
||||
if (type == 'save') {
|
||||
this.$refs.signatureRef.canvasToTempFilePath({
|
||||
success: (res) => {
|
||||
// 是否为空画板 无签名
|
||||
if (res.isEmpty) {
|
||||
return
|
||||
}
|
||||
// 生成图片的临时路径
|
||||
// app | H5 | 微信小程序 生成的是base64
|
||||
this.urls = res.tempFilePath
|
||||
base64ToPath(this.urls)
|
||||
.then(path => {
|
||||
this.uploadImg(path)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error)
|
||||
})
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.$refs.signatureRef)
|
||||
this.$refs.signatureRef[type]()
|
||||
},
|
||||
|
||||
uploadImg(url) {
|
||||
let that = this
|
||||
uni.uploadFile({
|
||||
url: this.host+'/api/admin/upload-file',
|
||||
filePath: url,
|
||||
name: 'file',
|
||||
header:{
|
||||
token:uni.getStorageSync('userInfo_BD_token').token
|
||||
},
|
||||
success: (res) => {
|
||||
console.log("respic",res.data)
|
||||
let data = JSON.parse(res.data)
|
||||
that.picForm.accept_admin_sign = data.response?data.response.id:data.id
|
||||
console.log("that.accept_admin_sign",that.picForm)
|
||||
that.picSubmit()
|
||||
}
|
||||
});
|
||||
},
|
||||
loadDetail() {
|
||||
let that = this
|
||||
console.log("that.id",that.id)
|
||||
this.util.request({
|
||||
api: '/api/admin/visit/show',
|
||||
method: "get",
|
||||
requestType: 'bd',
|
||||
data: {
|
||||
id: that.id
|
||||
},
|
||||
utilSuccess: function(res) {
|
||||
that.picForm = res
|
||||
},
|
||||
utilFail: function(res) {
|
||||
uni.showToast({
|
||||
title: res.errmsg,
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
picSubmit() {
|
||||
let that = this
|
||||
// return
|
||||
this.util.request({
|
||||
api: '/api/admin/visit/save',
|
||||
method: "POST",
|
||||
requestType:'bd',
|
||||
data: that.picForm,
|
||||
utilSuccess: function(res) {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
uni.navigateTo({
|
||||
url:'/pages/bd/record?type=myrecord'
|
||||
})
|
||||
},
|
||||
utilFail: function(res) {
|
||||
uni.showToast({
|
||||
title: res.errmsg,
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.signwrap {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.signbtns {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.signbtns button {
|
||||
background: #fff;
|
||||
border: none;
|
||||
width: 25%;
|
||||
margin-top: 20rpx;
|
||||
/* padding: 40rpx; */
|
||||
color: #333;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,66 @@
|
||||
export const uniContext = (ctx) => {
|
||||
const ALIAS_ATTRS_MAP = [
|
||||
'lineCap',
|
||||
'strokeStyle',
|
||||
'lineWidth',
|
||||
'fillStyle',
|
||||
]
|
||||
ALIAS_ATTRS_MAP.forEach(style => {
|
||||
Object.defineProperty(ctx, style, {
|
||||
set: value => {
|
||||
if(value)
|
||||
ctx[`set${style.charAt(0).toUpperCase()}${style.slice(1)}`](value)
|
||||
}
|
||||
})
|
||||
})
|
||||
ctx.uniDrawImage = ctx.drawImage
|
||||
ctx.drawImage = (image,...agrs) => {
|
||||
ctx.uniDrawImage(image.src, ...agrs)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
class Image {
|
||||
constructor() {
|
||||
this.currentSrc = null
|
||||
this.naturalHeight = 0
|
||||
this.naturalWidth = 0
|
||||
this.width = 0
|
||||
this.height = 0
|
||||
this.tagName = 'IMG'
|
||||
}
|
||||
set src(src) {
|
||||
this.currentSrc = src
|
||||
uni.getImageInfo({
|
||||
src,
|
||||
success: (res) => {
|
||||
this.naturalWidth = this.width = res.width
|
||||
this.naturalHeight = this.height = res.height
|
||||
this.onload()
|
||||
},
|
||||
fail: () => {
|
||||
this.onerror()
|
||||
}
|
||||
})
|
||||
}
|
||||
get src() {
|
||||
return this.currentSrc
|
||||
}
|
||||
}
|
||||
|
||||
export const createImage = () => {
|
||||
return new Image()
|
||||
}
|
||||
|
||||
export const toDataURL = (canvasId, com) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.canvasToTempFilePath({
|
||||
canvasId,
|
||||
success: (res) => {
|
||||
resolve(res.tempFilePath)
|
||||
},
|
||||
fail: reject
|
||||
}, com)
|
||||
})
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,95 @@
|
||||
export function compareVersion(v1, v2) {
|
||||
v1 = v1.split('.')
|
||||
v2 = v2.split('.')
|
||||
const len = Math.max(v1.length, v2.length)
|
||||
while (v1.length < len) {
|
||||
v1.push('0')
|
||||
}
|
||||
while (v2.length < len) {
|
||||
v2.push('0')
|
||||
}
|
||||
for (let i = 0; i < len; i++) {
|
||||
const num1 = parseInt(v1[i], 10)
|
||||
const num2 = parseInt(v2[i], 10)
|
||||
|
||||
if (num1 > num2) {
|
||||
return 1
|
||||
} else if (num1 < num2) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
export const getCanvas2d = () => {
|
||||
let {SDKVersion, uniPlatform} = uni.getSystemInfoSync()
|
||||
|
||||
if(!uniPlatform) {
|
||||
// #ifdef MP-WEIXIN
|
||||
uniPlatform = 'mp-weixin'
|
||||
// #endif
|
||||
// #ifdef MP-MP-ALIPAY
|
||||
SDKVersion = my.SDKVersion
|
||||
uniPlatform = 'mp-alipay'
|
||||
// #endif
|
||||
// #ifdef MP-MP-ALIPAY
|
||||
uniPlatform = 'mp-toutiao'
|
||||
// #endif
|
||||
}
|
||||
|
||||
const MAP = {
|
||||
'mp-weixin': '2.9.7',
|
||||
'mp-toutiao': '1.78.0',
|
||||
'mp-alipay': '2.7.0'
|
||||
}[uniPlatform]
|
||||
return MAP && SDKVersion && compareVersion(SDKVersion, MAP) >= 1
|
||||
}
|
||||
|
||||
export const wrapEvent = (e) => {
|
||||
if (!e) return;
|
||||
if (!e.preventDefault) {
|
||||
e.preventDefault = function() {};
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
export const requestAnimationFrame = (cb) => {
|
||||
setTimeout(cb, 30)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* base64转路径
|
||||
* @param {Object} base64
|
||||
*/
|
||||
export function base64ToPath(base64) {
|
||||
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64) || [];
|
||||
return new Promise((resolve, reject) => {
|
||||
const bitmap = new plus.nativeObj.Bitmap('bitmap' + Date.now())
|
||||
bitmap.loadBase64Data(base64, () => {
|
||||
if (!format) {
|
||||
reject(new Error('ERROR_BASE64SRC_PARSE'))
|
||||
}
|
||||
const time = new Date().getTime();
|
||||
const filePath = `_doc/uniapp_temp/${time}.${format}`
|
||||
bitmap.save(filePath, {},
|
||||
() => {
|
||||
bitmap.clear()
|
||||
resolve(filePath)
|
||||
},
|
||||
(error) => {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
}, (error) => {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function sleep(delay) {
|
||||
return new Promise(resolve => setTimeout(resolve, delay))
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
<template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
@ -0,0 +1,122 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<title></title>
|
||||
<style type="text/css">
|
||||
html,
|
||||
body,
|
||||
canvas {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow-y: hidden;
|
||||
background-color: transparent;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas id="lime-signature"></canvas>
|
||||
<script type="text/javascript" src="./uni.webview.1.5.3.js"></script>
|
||||
<script type="text/javascript" src="./signature.js"></script>
|
||||
<script>
|
||||
var signature = null;
|
||||
var timer = null;
|
||||
var isStart = false;
|
||||
var options = null
|
||||
console.log = function(...args) {
|
||||
postMessage(args);
|
||||
};
|
||||
// function stringify(key, value) {
|
||||
// if (typeof value === 'object' && value !== null) {
|
||||
// if (cache.indexOf(value) !== -1) {
|
||||
// return;
|
||||
// }
|
||||
// cache.push(value);
|
||||
// }
|
||||
// return value;
|
||||
// };
|
||||
function emit(event, data) {
|
||||
postMessage({
|
||||
event,
|
||||
data: typeof data !== "object" && data !== null ? data : JSON.stringify(data),
|
||||
});
|
||||
// cache = [];
|
||||
}
|
||||
|
||||
function postMessage(data) {
|
||||
uni.postMessage({
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
function update(v = {}) {
|
||||
if (signature) {
|
||||
options = v
|
||||
signature.pen.setOption(v);
|
||||
} else {
|
||||
signature = new Signature.Signature({el: "lime-signature"});
|
||||
canvasEl = signature.canvas.get("el");
|
||||
options = v
|
||||
signature.pen.setOption(v)
|
||||
const width = signature.canvas.get("width");
|
||||
const height = signature.canvas.get("height");
|
||||
|
||||
emit({changeSize: {width,height}})
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
signature.clear()
|
||||
}
|
||||
|
||||
function undo() {
|
||||
signature.undo()
|
||||
}
|
||||
function isEmpty() {
|
||||
const isEmpty = signature.isEmpty()
|
||||
emit({isEmpty});
|
||||
}
|
||||
function save(args) {
|
||||
// delete args.success;
|
||||
// delete args.fail;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
let path = canvasEl.toDataURL()
|
||||
if(options.backgroundColor) {
|
||||
const canvas = document.createElement('canvas')
|
||||
const width = signature.canvas.get('width')
|
||||
const height = signature.canvas.get('height')
|
||||
const pixelRatio = signature.canvas.get('pixelRatio')
|
||||
canvas.width = width * pixelRatio
|
||||
canvas.height = height * pixelRatio
|
||||
const context = canvas.getContext('2d')
|
||||
context.scale(pixelRatio, pixelRatio)
|
||||
context.fillStyle = backgroundColor
|
||||
context.fillRect(0,0, width, height)
|
||||
context.drawImage(signature.canvas.get('el'), 0, 0, width, height)
|
||||
path = canvas.toDataURL()
|
||||
canvas.remove()
|
||||
}
|
||||
if (typeof path == "string") {
|
||||
const index = Math.ceil(path.length / 8);
|
||||
for (var i = 0; i < 8; i++) {
|
||||
if (i == 7) {
|
||||
emit({"success": path.substr(i * index, index)});
|
||||
} else {
|
||||
emit({"file": path.substr(i * index, index)});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error("canvas no data");
|
||||
emit({"fail": "canvas no data"});
|
||||
}
|
||||
}, 30);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue