From 7595cbbc3729f2cdd1543b602c95173411bb19c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E=E4=B8=9C=E6=97=AD?= <850374051@qq.com> Date: Fri, 16 Jun 2023 17:55:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E6=9D=83=E4=BA=A4=E6=98=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/api/items.js | 7 + static/js/common/main.js | 8 +- static/js/common/tools.js | 41 +++ static/js/lib/jq-signature/WritingPad.js | 210 +++++++++++++ static/js/lib/jq-signature/jq-signature.js | 235 ++++++++++++++ static/js/project/listingItems/bond.js | 45 ++- view/listingItems/bond.html | 337 ++++++++++++++++++++- 7 files changed, 879 insertions(+), 4 deletions(-) create mode 100644 static/js/lib/jq-signature/WritingPad.js create mode 100644 static/js/lib/jq-signature/jq-signature.js diff --git a/static/js/api/items.js b/static/js/api/items.js index 6475e72..544b1d6 100644 --- a/static/js/api/items.js +++ b/static/js/api/items.js @@ -84,6 +84,13 @@ var biddingSubmit = '/transaction/bidding/add'//出价 */ var base64Upload = '/common/base64Attach'//上传凭证 +/* +@purl /common/base64Attach +@param + id: 主键ID +*/ +var sign = '/open/attachment/sign'//上传凭证 + /* @purl /transaction/website/needProject/ @param diff --git a/static/js/common/main.js b/static/js/common/main.js index 10fd75f..e19b1d2 100644 --- a/static/js/common/main.js +++ b/static/js/common/main.js @@ -20,6 +20,8 @@ requirejs.config({ paging:'lib/paging/page_common',//分页插件 cupload:'lib/cupload/cupload',//上传图片插件 dateTime:'lib/dateTime/dateTime.min',//时间选择器 + signature:'lib/jq-signature/jq-signature', + WritingPad:'lib/jq-signature/WritingPad', //自己写的路径配置 Tools: 'common/tools', @@ -76,7 +78,11 @@ requirejs.config({ jsencrypt: { deps: ['jquery'], exports: 'jsencrypt' - } + }, + // WritingPad: { + // deps: ['jquery','signature'], + // exports: 'WritingPad' + // }, } }); diff --git a/static/js/common/tools.js b/static/js/common/tools.js index 0d4a484..f34d289 100644 --- a/static/js/common/tools.js +++ b/static/js/common/tools.js @@ -59,6 +59,47 @@ define(['jquery', 'dialog','jsencrypt'], function ($, dialog,JSEncrypt) { } }); }, + doPostSign: function (url, data, cb, Bearer) { + var _this = this; + // data.deptId = 100 ; + // console.log(data) + var headAttribute = ''; + if (Bearer && Bearer == true || _this.getCookie('Admin-Token') == '') { + headAttribute = function (xhr) { + xhr.setRequestHeader("Content-Type", 'application/json;charset=utf-8'); + } + } else { + headAttribute = function (xhr) { + xhr.setRequestHeader("Content-Type", 'application/json;charset=utf-8'); + xhr.setRequestHeader('Authorization', 'Bearer ' + _this.getCookie('Admin-Token')) + } + } + $.ajax({ + url: ajaxJsUrl + url + '?=' + Math.random(), + type: 'POST', + data: data, + dataType: 'json', + contentType: false, + processData: false, // jQuery不要去处理发送的数据 + success: function (data) { + var code = data.code; + var msg = data.msg; + if (code === 401) { + _this.removeAllCookie(); + _this.initDialog('系统提示', '登录状态已过期,您可以继续留在该页面,或者重新登录', function () { + _this.skip('/view/login/login.html') + }, '重新登录', function () { }, "取消") + } else if (code === 500) { + _this.initError(msg) + cb(data); + } else if (code != 200) { + _this.initError(msg) + } else { + cb(data); + } + } + }); + }, /** * ajax post * @param url (String) diff --git a/static/js/lib/jq-signature/WritingPad.js b/static/js/lib/jq-signature/WritingPad.js new file mode 100644 index 0000000..d56e21d --- /dev/null +++ b/static/js/lib/jq-signature/WritingPad.js @@ -0,0 +1,210 @@ +/** + * 功能:签名canvas面板初始化,为WritingPad.js手写面板js服务。 + * 作者:黄金锋 (549387177@qq.com) + * 日期:2015-11-15 15:51:01 + * 版本:version 1.0 + */ + +(function (window, document, $) { + 'use strict'; + + // Get a regular interval for drawing to the screen + window.requestAnimFrame = (function (callback) { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimaitonFrame || + function (callback) { + window.setTimeout(callback, 1000 / 60); + }; + })(); + + /* + * Plugin Constructor + */ + + var pluginName = 'jqSignature', + defaults = { + lineColor: '#222222', + lineWidth: 1, + border: '1px dashed #CCFF99', + background: '#FFFFFF', + width: 500, + height: 200, + autoFit: false + }, + canvasFixture = ''; + + function Signature(element, options) { + // DOM elements/objects + this.element = element; + this.$element = $(this.element); + this.canvas = false; + this.$canvas = false; + this.ctx = false; + // Drawing state + this.drawing = false; + this.currentPos = { + x: 0, + y: 0 + }; + this.lastPos = this.currentPos; + // Determine plugin settings + this._data = this.$element.data(); + this.settings = $.extend({}, defaults, options, this._data); + // Initialize the plugin + this.init(); + } + + Signature.prototype = { + // Initialize the signature canvas + init: function () { + // Set up the canvas + this.$canvas = $(canvasFixture).appendTo(this.$element); + this.$canvas.attr({ + width: this.settings.width, + height: this.settings.height + }); + this.$canvas.css({ + boxSizing: 'border-box', + width: this.settings.width + 'px', + height: this.settings.height + 'px', + border: this.settings.border, + background: this.settings.background, + cursor: 'crosshair' + }); + // Fit canvas to width of parent + if (this.settings.autoFit === true) { + this._resizeCanvas(); + } + this.canvas = this.$canvas[0]; + this._resetCanvas(); + // Set up mouse events + this.$canvas.on('mousedown touchstart', $.proxy(function (e) { + this.drawing = true; + this.lastPos = this.currentPos = this._getPosition(e); + }, this)); + this.$canvas.on('mousemove touchmove', $.proxy(function (e) { + this.currentPos = this._getPosition(e); + }, this)); + this.$canvas.on('mouseup touchend', $.proxy(function (e) { + this.drawing = false; + // Trigger a change event + var changedEvent = $.Event('jq.signature.changed'); + this.$element.trigger(changedEvent); + }, this)); + // Prevent document scrolling when touching canvas + $(document).on('touchstart touchmove touchend', $.proxy(function (e) { + if (e.target === this.canvas) { + e.preventDefault(); + } + }, this)); + // Start drawing + var that = this; + (function drawLoop() { + window.requestAnimFrame(drawLoop); + that._renderCanvas(); + })(); + }, + // Clear the canvas + clearCanvas: function () { + this.canvas.width = this.canvas.width; + this._resetCanvas(); + }, + // Get the content of the canvas as a base64 data URL + getDataURL: function () { + return this.canvas.toDataURL(); + }, + + reLoadData: function () { + this.$canvas.remove(); + this._data = this.$element.data(); + + //for (var i in this.settings) { + // alert(i+":"+this.settings[i]); + //} + + //this.settings = $.extend({}, defaults, this._data); + this.init(); + }, + // Get the position of the mouse/touch + _getPosition: function (event) { + var xPos, yPos, rect; + rect = this.canvas.getBoundingClientRect(); + event = event.originalEvent; + // Touch event + if (event.type.indexOf('touch') !== -1) { // event.constructor === TouchEvent + xPos = event.touches[0].clientX - rect.left; + yPos = event.touches[0].clientY - rect.top; + } + // Mouse event + else { + xPos = event.clientX - rect.left; + yPos = event.clientY - rect.top; + } + return { + x: xPos, + y: yPos + }; + }, + // Render the signature to the canvas + _renderCanvas: function () { + if (this.drawing) { + this.ctx.moveTo(this.lastPos.x, this.lastPos.y); + this.ctx.lineTo(this.currentPos.x, this.currentPos.y); + this.ctx.stroke(); + this.lastPos = this.currentPos; + } + }, + // Reset the canvas context + _resetCanvas: function () { + this.ctx = this.canvas.getContext("2d"); + this.ctx.strokeStyle = this.settings.lineColor; + this.ctx.lineWidth = this.settings.lineWidth; + }, + // Resize the canvas element + _resizeCanvas: function () { + var width = this.$element.outerWidth(); + this.$canvas.attr('width', width); + this.$canvas.css('width', width + 'px'); + } + }; + + /* + * Plugin wrapper and initialization + */ + + $.fn[pluginName] = function (options) { + var args = arguments; + if (options === undefined || typeof options === 'object') { + return this.each(function () { + if (!$.data(this, 'plugin_' + pluginName)) { + $.data(this, 'plugin_' + pluginName, new Signature(this, options)); + } + }); + } + else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { + var returns; + this.each(function () { + var instance = $.data(this, 'plugin_' + pluginName); + if (instance instanceof Signature && typeof instance[options] === 'function') { + var myArr = Array.prototype.slice.call(args, 1); + returns = instance[options].apply(instance, myArr); + } + if (options === 'destroy') { + $.data(this, 'plugin_' + pluginName, null); + } + //if (options === 'reLoadData') { + // //this.$canvas.remove(); + // $.data(this, 'plugin_' + pluginName, null); + // this._data = this.$element.data(); + // this.settings = $.extend({}, defaults, options, this._data); + // this.init(); + //} + }); + return returns !== undefined ? returns : this; + } + }; + +})(window, document, jQuery); \ No newline at end of file diff --git a/static/js/lib/jq-signature/jq-signature.js b/static/js/lib/jq-signature/jq-signature.js new file mode 100644 index 0000000..a98f4fd --- /dev/null +++ b/static/js/lib/jq-signature/jq-signature.js @@ -0,0 +1,235 @@ + +var WritingPad = function () { + + var current = null; + + $(function () { + + initHtml(); + + initTable(); + + initSignature(); + //if ($(".modal")) { + // $(".modal").modal("toggle"); + //} else { + // alert("没用手写面板"); + //} + + $(document).on("click", "#myClose,.close", null, function () { + $('#mymodal').modal('hide'); + $("#mymodal").remove(); + + }); + + $(document).on("click", "#mySave", null, function () { + + var myImg = $('#myImg').empty(); + var dataUrl = $('.js-signature').jqSignature('getDataURL'); + var img = $('').attr('src', dataUrl); + $(myImg).append($('

').text("图片保存在这里")); + $(myImg).append(img); + + }); + + $(document).on("click", "#myEmpty", null, function () { + $('.js-signature').jqSignature('clearCanvas'); + + }); + + $(document).on("click", "#myBackColor", null, function () { + + $('#colorpanel').css('left', '95px').css('top', '45px').css("display", "block").fadeIn(); + //$("canvas").css("background", "#EEEEEE"); + $("#btnSave").data("sender", "#myBackColor"); + }); + + $(document).on("click", "#myColor", null, function () { + $('#colorpanel').css('left', '205px').css('top', '45px').css("display", "block").fadeIn(); + $("#btnSave").data("sender", "#myColor"); + }); + + $(document).on("mouseover", "#myTable", null, function () { + + if ((event.srcElement.tagName == "TD") && (current != event.srcElement)) { + if (current != null) { current.style.backgroundColor = current._background } + event.srcElement._background = event.srcElement.style.backgroundColor; + //$("input[name=DisColor]").css("background-color", event.srcElement.style.backgroundColor); + //var color = event.srcElement.style.backgroundColor; + //var strArr = color.substring(4, color.length - 1).split(','); + //var num = showRGB(strArr); + //$("input[name=HexColor]").val(num); + current = event.srcElement; + } + + }); + + $(document).on("mouseout", "#myTable", null, function () { + + if (current != null) current.style.backgroundColor = current._background + + }); + + $(document).on("click", "#myTable", null, function () { + + if (event.srcElement.tagName == "TD") { + var color = event.srcElement._background; + if (color) { + $("input[name=DisColor]").css("background-color", color); + var strArr = color.substring(4, color.length - 1).split(','); + var num = showRGB(strArr); + $("input[name=HexColor]").val(num); + } + } + + }); + + $(document).on("click", "#btnSave", null, function () { + + $('#colorpanel').css("display", "none"); + var typeData = $("#btnSave").data("sender"); + var HexColor = $("input[name=HexColor]").val(); + var data = $(".js-signature").data(); + if (typeData == "#myColor") { + data["plugin_jqSignature"]["settings"]["lineColor"] = HexColor; + $('.js-signature').jqSignature('reLoadData'); + } + if (typeData == "#myBackColor") { + + data["plugin_jqSignature"]["settings"]["background"] = HexColor; + $('.js-signature').jqSignature('reLoadData'); + } + }); + + $("#mymodal").on('hide.bs.modal', function () { + $("#colorpanel").remove(); + $("#mymodal").remove(); + $("#myTable").remove(); + }); + + }); + + function initHtml() { + + var html = '

-