| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- // 扫描仪操作对象
- var Scanner = function() {
- };
- (function() {
- Scanner.prototype = {
- construct : Scanner,
- // 私有属性
- _parameter : {
- 'domId' : null, // 控件容器ID
- 'locationPath' : null, // 扫描文件的本地存储路径
- 'produceFilenameFunc' : null, // 生成扫描文件名称的函数体
- 'prefix' : 'XXX', // 生成文件的名称前缀
- 'saveType' : 1, // 生成文件的格式{int} 1:JPG, 2:Tif, 3:Pdf
- 'dpi' : 200, // 生成文件的dpi设置,默认150
- 'colorType' : 3, // 扫描影像色彩{int} 1=黑白, 2=灰度, 3=彩色
- 'isDoubleSide' : 2, // 是否开启双面扫描设置{int} 2=开启, 1=关闭
- 'isDelNullPage' : 1, // 是否开启去除空白页面{int} 1=开启, 2=关闭
- 'isRoteWord' : 1, // 是否开启识别文字方向{int} 1=开启 , 2=关闭
- 'isRectification' : 1, // 是否开启纠偏{int} 1=开启 ,2=关闭
- //'srcFileFullPathArr' : new Array(), // 存放本次业务所拍摄的所有文档全路径的数组
- 'scannerCtrl' : null, // 扫描仪底层控制驱动
- 'fso' : new ActiveXObject('Scripting.FileSystemObject'), // JS文件操作对象
- 'scannerCtrlInitHtml' : '<%-- ActiveX控件对象 --%>'
- + '<object id="scannerCtrl" '
- + 'style="width: 600px; height:600px; "'
- + 'align="middle" CODEBASE="/web/jsp/shoudan/scanner/DocuScan.CAB#version=1,0,0,9"'
- + 'classid="CLSID:3C281245-3378-428E-B15B-9CF5251F1568"> '
- + '<PARAM NAME="EnableToolBar" VALUE="false" /> </object>'
- },
-
- getParameter : function(key) {
- return this._parameter[key];
- },
- setParameter : function(key, value) {
- this._parameter[key] = value;
- },
-
- /**
- * 【扫描】接口方法
- */
- scan : function() {
- this.setParameter("prefix", this._executeFunc(this.getParameter("produceFilenameFunc")));
- // 进行扫描的参数设置
- this._changeDPI(this.getParameter("dpi")); // 设置扫描质量dpi
- this._changeSaveType(this.getParameter("saveType")); // 设置扫描影像的格式
- this._changeColor(this.getParameter("colorType")); // 设置扫描影像色彩
- this._changeDoubleSide(this.getParameter("isDoubleSide")); // 设置是否开启双面扫描设置
- this._changeDelNullPage(this.getParameter("isDelNullPage")); // 设置是否开启去除空白页面
- this._changeRoteWord(this.getParameter("isRoteWord")); // 设置是否开启识别文字方向
- this._changeRectification(this.getParameter("isRectification")); // 设置是否开启纠偏
- // 进行扫描的路径设置
- this._changeSavePath(this.getParameter("locationPath")); // 设置扫描文件的存放路径
- this._changePreFix(this.getParameter("prefix")); // 设置扫描文件的名称
- var locationPath = this.getParameter("locationPath");
-
- var flag = this._createDestSavePath(locationPath); // 创建文件存放路径是否成功标志
- if(flag){
- this._startScan();
- }else{// 创建文件夹失败,导致目标文件夹不存在
- alert("目标存放文件夹不存在!");
- }
- },
- /**
- * 【重新扫描】接口方法
- * @introduction 点击【重新扫描】后,删除已有的扫描文件后再进行一次扫描。先调用控件提供的全部删除方法,后使用自身的删除私有方法
- */
- rescan : function() {
- this._dellAll(); // 调用控件的全部删除方法
- this._deleteLocalTempFile(this._getPath()); // 调用自身的删除方法再次进行删除
- // 再次进行扫描
- this.scan();
- },
- /**
- * 【获取文件路径】接口方法
- *
- * @return String[] 返回扫描文件在本地上的储存路径的数组
- */
- getFilePath : function() {
- return this._getPath();
- },
-
- /**
- * 【设备状态初始化】公用方法
- * @introduction 进入页面时触发的初始化动作
- */
- initialization : function() {
- //scanner._initSettingDiv();
- },
-
- /**
- * 【设备状态反初始化】公用方法
- * @introduction 离开页面是触发的反初始化动作
- */
- deinitialization : function() {
- this._dellAll(); // 删除所有的本地临时文件
- this._deleteLocalTempFile(this._getPath()); // 调用自身的删除方法再次进行删除
- },
- /**
- * 【打开设置窗口】接口方法
- *
- * @introduction
- */
- openSetting : function() {
- $('#settingDiv').fwwindow('open');
- // <Object>标签会遮挡无窗体元素,所以要在在弹出窗的遮罩层下垫底一块透明的iFrame,让弹出窗高于<Object>,缺点就是<Object>会被完全挡掉。
- $(".fwwindow-mask").append(
- "<iframe style='position: absolute; z-index: -1; width: 100%; height: 100%; " +
- "top: 0;left:0;scrolling:no;' frameborder='0'></iframe>");
- },
-
- /**
- * 【初始化设置Div窗口】私有方法
- */
- _initSettingDiv : function() {
- $('#settingDiv').fwwindow({
- title : '设置',
- width : 200,
- modal : true,
- closed : true,
- height : 200
- });
- },
-
- /**
- * 【执行入参方法】私有方法
- *
- * @param value=入参为一个方法结构体
- */
- _executeFunc : function(value) {
- var produceFilenameFunc = value;
- return produceFilenameFunc();
- },
- /**
- * 【扫描】私有方法
- */
- _startScan : function() {
- scannerCtrl.BeginScan();
- },
- /**
- * 【插扫】私有方法
- */
- _insertScan : function() {
- scannerCtrl.InsertScan();
- },
- /**
- * 【重扫】私有方法
- */
- _reScan : function() {
- scannerCtrl.ReScan();
- },
- /**
- * 【扫描设置】私有方法
- */
- _scanSetting : function() {
- scannerCtrl.ScanSetting();
- },
- /**
- * 【删除】私有方法
- */
- _delItem : function() {
- scannerCtrl.DelItem();
- },
- /**
- * 【全部删除】私有方法
- */
- _dellAll : function() {
- scannerCtrl.DellAll();
- },
- /**
- * 【获取文件路径】私有方法
- */
- _getPath : function() {
- var allFileFullPathArr = scannerCtrl.GetALLFile();
- allFileFullPathArr = allFileFullPathArr.split("|");
- return allFileFullPathArr;
- },
- /**
- * 【打印】私有方法
- */
- _printFile : function() {
- scannerCtrl.PrintFile("D:\\1\\1.bmp|D:\\1\\2.bmp");
- // 可以通过
- // scannerCtrl.Rectification = 2;
- // 这样的方式修改属性
- },
-
- /**
- * 根据文件夹路径创建该文件夹
- * return {boolean} true=创建成功 false=创建失败
- */
- _createDestSavePath : function(path) {
- var flag = null; //创建是否成功标志
- //创建JavaScript的本地文件操作对象
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- //判断该文件夹是否已经存在。若存在则返回创建成功,不存在则创建文件夹(多级文件夹创建)
- if (!fso.FolderExists(path)) { //该文件夹不存在
- //多级文件夹目录创建
- var folderFragment = path.split("\\");
- //待创建的文件夹路径,每循环一次则添加一次子级文件夹的名称,从而进入子级文件夹的创建
- var folderPath = "";
- for ( var index in folderFragment) {
- folderPath = folderPath + folderFragment[index] + "\\";
- //一级一级判断该级文件夹是否存在,不存在则创建
- if (!fso.FolderExists(folderPath)) {
- fso.CreateFolder(folderPath);
- }
- }
- }
- //判断是否该文件夹是否创建成功
- if (fso.FolderExists(path)) {
- flag = true;
- return flag;
- } else {
- flag = false;
- return flag;
- }
- },
-
- /**
- * 【生成目标文件的全路径】私有方法
- *
- * return {string} 目标文件的全路径
- *//*
- _makeFileFullName : function() {
- var locationPath = this.getParameter("locationPath"); // 目标文件存放路径
- var postfix = this.getParameter("postfix"); // 目标文件生成格式后缀
- var filename = this._executeFunc(this.getParameter("produceFilenameFunc")); // 目标文件名称
- var fileFullName = locationPath + filename + postfix; // 目标文件全路径
- return fileFullName;
- },*/
-
- /**
- * 【JS删除文件操作】私有方法
- * @param fileFullPath=文件的全路径
- */
- _deleteFile : function(fileFullPath) {
- var fso = this.getParameter("fso");
- if (fso.FileExists(fileFullPath)) {
- fso.DeleteFile(fileFullPath);
- }
- },
-
- /**
- * 【删除所有本地所有的扫描文件】私有方法
- */
- _deleteLocalTempFile : function(srcFileFullPathArr){
- for(var index = 0; index < srcFileFullPathArr.length; index++){
- this._deleteFile(srcFileFullPathArr[index]);
- this.setParameter("srcFileFullPathArr", []);// 本次业务存放扫描件的数据也要对应清空
- }
- },
-
- /**
- * 【改变扫描文件的存放路径】私有方法
- * @param locationPath = 文件的存放文件
- */
- _changeSavePath : function(locationPath){
- scannerCtrl.SavePath = locationPath;
- },
-
- /**
- * 【改变扫描文件的名称】私有方法
- * @param {string} preFix = 文件名称
- */
- _changePreFix : function(preFix){
- scannerCtrl.PreFix = preFix;
- },
-
- /**
- * 【改变是保存文件的格式】私有方法
- * @param {int} 1:JPG 2:Tif 3:Pdf
- */
- _changeSaveType : function(type){
- scannerCtrl.SaveType = type;
- },
-
- /**
- * 【改变扫描影像色彩】私有方法
- * @param {int} 1=黑白 2=灰度 3=彩色
- */
- _changeColor : function(colorType){
- scannerCtrl.Colour = colorType;
- },
-
- /**
- * 【改变是否开启双面扫描设置】私有方法
- * @param {int} 2=开启, 1=关闭
- */
- _changeDoubleSide : function(isDoubleSide){
- scannerCtrl.DoubleSide = isDoubleSide;
- },
-
- /**
- * 【改变是否开启去除空白页面】私有方法
- * @param {int} 1=开启 2=关闭
- */
- _changeDelNullPage : function(isDelNullPage){
- scannerCtrl.DelNullPage = isDelNullPage;
- },
-
- /**
- * 【改变是否开启识别文字方向】私有方法 #
- * @param {int} 1=开启 2=关闭
- */
- _changeRoteWord : function(isRoteWord){
- scannerCtrl.RoteWord = isRoteWord;
- },
-
- /**
- * 【改变DPI大小】私有方法 #
- * @param {int} 1=开启 2=关闭
- */
- _changeDPI : function(dpi){
- scannerCtrl.DPI = dpi;
- },
-
- /**
- * 【改变是否开启纠偏】私有方法
- * @param {int} 1=开启 2=关闭
- */
- _changeRectification : function(isRectification){
- scannerCtrl.Rectification = isRectification;
- }
- };
- // 扫描仪操作对象设置并初始化
- Scanner.config = function(initParam) {
- var scanner = new Scanner();
- scanner.setParameter('domId', initParam['domId']);
- scanner.setParameter('locationPath', initParam['locationPath']);
- scanner.setParameter('produceFilenameFunc', initParam['produceFilenameFunc']);
- /*$('#' + scanner.getParameter('domId')).html(
- scanner.getParameter('scannerCtrlInitHtml'));*/
- return scanner;
- };
-
- })();
|