appPackage.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // 下载文件
  2. function dataURLtoBlob(dataurl) {
  3. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  4. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  5. while (n--) {
  6. u8arr[n] = bstr.charCodeAt(n);
  7. }
  8. return new Blob([u8arr], { type: mime });
  9. }
  10. function downloadFile(blob, url, name){
  11. if (window.navigator.msSaveBlob) {
  12. try {
  13. window.navigator.msSaveBlob(blob, name)
  14. } catch (e) {
  15. console.log(e);
  16. }
  17. } else {
  18. // 谷歌浏览器 创建a标签 添加download属性下载
  19. var a = document.createElement("a");
  20. a.setAttribute("href",url);
  21. a.setAttribute("download",name);
  22. a.setAttribute("target","_blank");
  23. var clickEvent = document.createEvent("MouseEvents"); //创建
  24. clickEvent.initEvent("click", true, true);//初始化
  25. a.dispatchEvent(clickEvent);//触发
  26. }
  27. }
  28. function downloadFileByBase64(base64,name){
  29. var myBlob = dataURLtoBlob(base64);
  30. var myUrl = URL.createObjectURL(myBlob);
  31. downloadFile(myBlob, myUrl,name)
  32. }
  33. function downloadNewFile(){
  34. var base64 = NetcaPDFSeal.getSignPDFBytes();
  35. var file = 'data:application/pdf;base64,' + base64;
  36. var name = new Date();
  37. name = name.getTime();
  38. downloadFileByBase64(file, name+'.pdf');
  39. }
  40. // 演示功能
  41. function demonstrationFn(){
  42. var obj = {
  43. 'netcasave':false,
  44. 'netcaFirstSeparator':false,
  45. 'netcaSecondSeparator':false,
  46. 'netcaThirdSeparaor':false,
  47. 'netcaSetting':false,
  48. 'netcaAbout':false
  49. };
  50. checkObjHasOwnProperty(obj);
  51. hideExtraCheckboxesIE(obj);
  52. removeExtraCheckboxes();
  53. hideExtraCheckboxes();
  54. }
  55. /**检查obj是否有指定属性存在*/
  56. function checkObjHasOwnProperty(obj){
  57. if(!obj.hasOwnProperty('openFile')){
  58. obj.openFile = true
  59. }
  60. if(!obj.hasOwnProperty('netcasave')){
  61. obj.netcasave = true
  62. }
  63. if(!obj.hasOwnProperty('viewFind')){
  64. obj.viewFind = true
  65. }
  66. if(!obj.hasOwnProperty('zoomOut')){
  67. obj.zoomOut = true
  68. }
  69. if(!obj.hasOwnProperty('zoomIn')){
  70. obj.zoomIn = true
  71. }
  72. if(!obj.hasOwnProperty('scaleSelectContainer')){
  73. obj.scaleSelectContainer = true
  74. }
  75. if(!obj.hasOwnProperty('netcaFirstSeparator')){
  76. obj.netcaFirstSeparator = true
  77. }
  78. if(!obj.hasOwnProperty('previous')){
  79. obj.previous = true
  80. }
  81. if(!obj.hasOwnProperty('next')){
  82. obj.next = true
  83. }
  84. if(!obj.hasOwnProperty('netcaSecondSeparator')){
  85. obj.netcaSecondSeparator = true
  86. }
  87. if(!obj.hasOwnProperty('verify')){
  88. obj.verify = true
  89. }
  90. if(!obj.hasOwnProperty('netcasign')){
  91. obj.netcasign = true
  92. }
  93. if(!obj.hasOwnProperty('netcaThirdSeparaor')){
  94. obj.netcaThirdSeparaor = true
  95. }
  96. if(!obj.hasOwnProperty('netcaSetting')){
  97. obj.netcaSetting = true
  98. }
  99. if(!obj.hasOwnProperty('netcaAbout')){
  100. obj.netcaAbout = true
  101. }
  102. if(!obj.hasOwnProperty('netcastaff')){
  103. obj.netcastaff = true
  104. }
  105. if(!obj.hasOwnProperty('netcaorganization')){
  106. obj.netcaorganization = true
  107. }
  108. if(!obj.hasOwnProperty('netcalegalperson')){
  109. obj.netcalegalperson = true
  110. }
  111. if(!obj.hasOwnProperty('print')){
  112. obj.print = true
  113. }
  114. if(!obj.hasOwnProperty('closeFile')){
  115. obj.closeFile = true
  116. }
  117. }
  118. /**
  119. * 非IE浏览器下,移除多余的checkbox
  120. * */
  121. function removeExtraCheckboxes(){
  122. var arr = [2,7,11,14,15,16];
  123. if(!NetcaPDFSeal._isIE()){
  124. for(var i=0;i<arr.length;i++){
  125. (function(i){
  126. $('input[name="checkbox'+arr[i]+'"]').parent().remove()
  127. })(i);
  128. }
  129. }
  130. }
  131. /**
  132. * 根据toolbarButton的true/false,隐藏多余的checkbox
  133. * */
  134. function hideExtraCheckboxes(){
  135. var arr1 = [4,5,6,8,9,10,12,13,20,21,22,23,24,28];
  136. for(var j=0;j<arr1.length;j++){
  137. (function(j){
  138. if($('.netca_btn'+arr1[j]+'').css('display') === 'none'){
  139. $('input[name="checkbox'+arr1[j]+'"]').parent().remove()
  140. }
  141. })(j);
  142. }
  143. }
  144. /** IE 隐藏多余的checkbox
  145. * */
  146. function hideExtraCheckboxesIE(obj) {
  147. for (var k in obj) {
  148. if(k === 'print' && obj[k] === false){
  149. $('#checkbox20').parent().remove();
  150. }
  151. if(k === 'zoomOut' && obj[k] === false){
  152. $('#checkbox4').parent().remove();
  153. }
  154. if(k === 'zoomIn' && obj[k] === false){
  155. $('#checkbox5').parent().remove();
  156. }
  157. if(k === 'scaleSelectContainer' && obj[k] === false){
  158. $('#checkbox6').parent().remove();
  159. }
  160. if(k === 'previous' && obj[k] === false){
  161. $('#checkbox8').parent().remove();
  162. }
  163. if(k === 'next' && obj[k] === false){
  164. $('#checkbox9').parent().remove();
  165. }
  166. if(k === 'netcapage' && obj[k] === false){
  167. $('#checkbox10').parent().remove();
  168. }
  169. if(k === 'openFile' && obj[k] === false){
  170. $('#checkbox1').parent().remove();
  171. }
  172. if(k === 'netcasave' && obj[k] === false){
  173. $('#checkbox2').parent().remove();
  174. }
  175. if(k === 'viewFind' && obj[k] === false){
  176. $('#checkbox3').parent().remove();
  177. }
  178. if(k === 'netcaFirstSeparator' && obj[k] === false){
  179. $('#checkbox7').parent().remove();
  180. }
  181. if(k === 'netcaSecondSeparator' && obj[k] === false){
  182. $('#checkbox11').parent().remove();
  183. }
  184. if(k === 'netcaThirdSeparaor' && obj[k] === false){
  185. $('#checkbox14').parent().remove();
  186. }
  187. if(k === 'verfity' && obj[k] === false){
  188. $('#checkbox13').parent().remove();
  189. }
  190. if(k === 'netcaSetting' && obj[k] === false){
  191. $('#checkbox15').parent().remove();
  192. }
  193. if(k === 'netcaAbout' && obj[k] === false){
  194. $('#checkbox16').parent().remove();
  195. }
  196. if(k === 'netcasign' && obj[k] === false){
  197. $('#checkbox21').parent().remove();
  198. }
  199. if(k === 'netcastaff' && obj[k] === false){
  200. $('#checkbox22').parent().remove();
  201. }
  202. if(k === 'netcaorganization' && obj[k] === false){
  203. $('#checkbox23').parent().remove();
  204. }
  205. if(k === 'netcalegalperson' && obj[k] === false){
  206. $('#checkbox24').parent().remove();
  207. }
  208. if(k === 'closeFile' && obj[k] === false){
  209. $('#checkbox28').parent().remove();
  210. }
  211. }
  212. }
  213. function getSignCallBack(res){
  214. console.log("签名信息", JSON.parse(res))
  215. }
  216. function getVerifyCallBack(res){
  217. console.log("验证信息", JSON.parse(res))
  218. }
  219. // NetcaPDFSeal.setSignCallbackEvent(getSignCallBack);
  220. // NetcaPDFSeal.setVerifyCallbackEvent(getVerifyCallBack);