123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- Namespace.register("U.MD.UI");
- U.MD.UI.upload = function (url, cb, hashcallback) {
-
- var _str = U.UF.CI.isSupportFlash();
-
-
- if (_str == "HTML5") {
- U.MD.UI.upload.html5(url, cb, hashcallback);
- }
-
- else if (_str == "Flash") {
- U.MD.UI.upload.flash(url, cb, hashcallback);
- }
-
- else {
- U.MD.UI.upload.input(url, cb, hashcallback);
- }
- }
- U.MD.UI.upload.uploadFileInfo = [];
- U.MD.UI.upload.upfiles = function (r,url, cb, hashcallback) {
- U.MD.UI.inputSelect({
-
- error: function (r) {
- console.log("上传错误:" + r);
- },
-
- getHashCallBack: function (filehash, fileinfo, callback) {
-
- hashcallback(filehash, fileinfo, function (isupload) {
-
- if (isupload) {
-
- U.UF.UP.html5Upload.select(fileinfo, filehash, function (fileservername, filesize) {
-
- U.UF.UP.html5Upload.loop(fileinfo, filehash, fileservername, filesize, function (value) {
-
- if (value == true) {
- callback.getData(filehash, fileservername, fileinfo);
- var _nextuploadfile = U.MD.UI.delUploadFile(fileinfo.fileel, fileinfo);
-
- if (_nextuploadfile) {
- U.MD.UI.inputUpload(_nextuploadfile, callback);
- }
- }
-
- else {
- callback.progress(value, fileinfo.fileid, "上传中");
- }
- });
- });
- }
- else {
- var _nextuploadfile = U.MD.UI.delUploadFile(fileinfo.fileel, fileinfo);
-
- if (_nextuploadfile) {
- U.MD.UI.inputUpload(_nextuploadfile, callback);
- }
- }
- });
- },
-
- progress: U.MD.UI.progress,
-
- getData: function (filehash, fileservername, file) {
- var _type = file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length),
- _thumbnailname = 'gif|jpg|jpeg|png'.indexOf(_type.toLowerCase()) > -1 ? (Guid.newGuid() + "." + _type) : null;
-
- if (_thumbnailname) {
- U.A.Request(US.DISK, ['CreateThumbnail', fileservername, _thumbnailname], function (r) { });
- }
-
- U.A.Request(US.CD, [US.DB, 'UseStudio_Disk', 'CreateUploadFile', U.UF.C.queryString("UserId", url), file.fileid, U.UF.C.queryString("DirectoryId", url), file.name, fileservername, _thumbnailname, filehash, file.size, 1, file.name, _type, U.UF.C.queryString("Encrypt", url)],
- function (request) {
- cb({ data: [fileservername, fileservername, file.fileid, file.size, U.UF.C.queryString("Encrypt", url), U.UF.C.queryString("DirectoryId", url)] }, file);
- });
- }
- });
- this.value = "";
- }
- U.MD.UI.upload.html5 = function (url, cb, hashcallback) {
-
- U.MD.UI.create();
- var _clickuploadel = U.selectEl("#U_MD_UI_UP_DRT")[0];
- _clickuploadel.innerText = "";
-
- $$("input", { "multiple": "true", "type": "file", "accept": "*/*", "onchange": function (r) {
- U.MD.UI.upload.upfiles(r, url, cb, hashcallback);
- return false;
- }, "style": { "cssText": "display: block; position: relative; width: 100%; height: 100%; cursor: pointer; border: 0; color: #666; background: #eee; -moz-user-select: -moz-none; -webkit-user-select: none; opacity: 0; filter: alpha(opacity=0); -moz-opacity: 0;" }
- }, _clickuploadel);
- if ($("#U_MD_UI_UP_C")[0].length != 0)
- U.MD.UI.upload.upfiles(event, url, cb, hashcallback);
- }
- U.MD.UI.upload.flash = function (url, cb, hashcallback) {
- U.MD.UI.create();
- var _url = url,
- _cb = cb,
- _hashcallback = hashcallback,
- _clickuploadel = U.selectEl("#U_MD_UI_UP_DRT")[0];
- _clickuploadel.innerText = "";
-
- U.UF.UP.addFlashUploadBottom(_clickuploadel, "flashupload", { "width": _clickuploadel.clientWidth, "height": _clickuploadel.offsetHeight }, {
- error: U.MD.UI.flashError,
-
- select: function (filesinfo) {
- U.MD.UI.flashSelect(filesinfo, _url, U.UF.C.isFunction(_hashcallback));
- },
-
- getHashCallBack: function (md5, fileid) {
- var _fileinfo = U.MD.UI.getFileInfoById(fileid)[0];
-
- _hashcallback(md5, _fileinfo, function (isupload) {
-
- if (isupload) {
-
- U.UF.UP.flashUpload($("*flashupload")[0], fileid, _url);
- }
- else {
- U.MD.UI.flashContinueUpload(fileid, _url, U.UF.C.isFunction(_hashcallback));
- }
- });
- },
- progress: U.MD.UI.progress,
- uploadComplete: U.MD.UI.flashUploadComplete,
-
-
- getData: function (r, fileid) {
- if (U.UF.C.isFunction(_cb)) {
- _cb(r, U.MD.UI.getFileInfoById(fileid)[0]);
- }
-
- U.MD.UI.flashContinueUpload(fileid, _url, U.UF.C.isFunction(_hashcallback));
- },
- endUpload: U.MD.UI.deleteUploadAllFile
- }, "*");
- }
- U.MD.UI.upload.input = function (url, cb, hashcallback) {
- U.MD.UI.create();
- var _clickuploadel = U.selectEl("#U_MD_UI_UP_DRT")[0];
- _clickuploadel.innerText = "";
-
- $$("input", {
- "multiple": "true", "type": "file", "accept": "*/*", "onchange": U.MD.UI.inputSelect,
- "style": { "cssText": "display: block; position: relative; width: 100%; height: 100%; cursor: pointer; border: 0; color: #666; background: #eee; -moz-user-select: -moz-none; -webkit-user-select: none; opacity: 0; filter: alpha(opacity=0); -moz-opacity: 0;" }
- }, _clickuploadel);
- }
- U.MD.UI.create = function () {
- var _flashtop = U.selectEl("#U_MD_UI_UP_O")[0];
- if (_flashtop) {
- U.UF.F.windowTopCenter(_flashtop);
- }
- else {
- var _uploadel,
- _topel,
- _titleel,
- _bottom,
- _switchel;
- _uploadel = $$("div", { "id": "U_MD_UI_UP", "className": "U_MD_UI_UP" });
- _topel = $$("div", { "className": "U_MD_UI_UP_O" }, _uploadel);
-
- _titleel = $$("div", { "className": "U_MD_UI_UP_T" }, _topel);
- $$("div", { "className": "U_MD_UI_UP_TO", "innerHTML": "普通上传" }, _titleel);
- $$("div", { "className": "U_MD_UI_UP_Z", "innerHTML": "提示声明: 严谨上传包括反动、暴力、色情、违法及侵权内容的文件;严格遵守保密法律法规,任何危害用户或犯法的行为,都必须受到法律追究。" }, _topel);
-
- $$("div", { "id": "U_MD_UI_UP_C", "className": "U_MD_UI_UP_C" }, _topel);
-
- _bottom = $$("div", { "className": "U_MD_UI_UP_D" }, _topel);
- _switchel = $$("div", { "className": "U_MD_UI_UP_DR" }, _bottom);
- $$("div", { "className": "U_MD_UI_UP_DRO", "innerHTML": "点击上传" }, _switchel);
- $$("div", { "className": "U_MD_UI_UP_DRO U_MD_UI_UP_DRT", "id": "U_MD_UI_UP_DRT" }, _switchel);
-
- return new U.UF.UI.form("<div class='U_MD_F_S_TI'>上传</div>", _uploadel, {
- "id": "U_MD_UI_UP_O",
- "style": { "width": "700px", "height": "560px" },
- "ondrop" :"U.MD.DK.C.Dropload()",
- "ondragover":"event.preventDefault()",
- }, { isnarrow: false, isenlarge: false }).form;
- }
- }
- U.MD.UI.getFileInfoById = function (fileid) {
- var i, j,
- _allfiles = U.MD.UI.upload.uploadFileInfo;
- for (i = 0; i < _allfiles.length; i++) {
- j = _allfiles[i].objIndexOf({ "fileid": fileid });
-
- if (j > -1) {
-
- return [_allfiles[i][j], j, i];
- }
- }
- return [null, -1, -1];
- }
- U.MD.UI.inputSelect = function () {
- }
- U.MD.UI.inputSelect = function (callback) {
-
- var event = window.event || arguments.callee.caller.arguments[0];
- var _fileinfo,
- _fileinfos = [],
- _files = event.target.files;
- if (event.target.files==undefined)
- _files = event.dataTransfer==undefined?undefined:event.dataTransfer.files;
- if(_files==undefined)
- return false;
-
- for (var i = 0; i < _files.length; i++) {
- _fileinfos.push(_files[i]);
- }
- U.MD.UI.upload.uploadFileInfo.push(_fileinfos);
- U.MD.UI.printUploadFiles(_fileinfos);
- U.MD.UI.inputUpload(_fileinfos[0], callback);
- }
- U.MD.UI.inputUpload = function (file, callback) {
- file.isupload = true;
-
- U.UF.UP.html5Upload.fileMd5(file, function (progress, finish, filehash) {
-
- if (!progress) {
-
- if (U.UF.C.isFunction(callback.error)) {
- callback.error(finish);
- }
- }
-
- else if (finish) {
- callback.progress({ "Loaded": 1, "Total": 1 }, file.fileid, "");
-
- if (U.UF.C.isFunction(callback.getHashCallBack)) {
- callback.getHashCallBack(filehash, file, callback);
- }
- }
-
- else {
- if (U.UF.C.isFunction(callback.progress)) {
- callback.progress(progress, file.fileid, "解析中");
- }
- }
- });
- }
- U.MD.UI.flashSelect = function (uploadfiles, url, isgethash) {
- U.MD.UI.printUploadFiles(uploadfiles, true);
- U.MD.UI.upload.uploadFileInfo.push(uploadfiles);
- U.MD.UI.flashUpload(uploadfiles[0], url, isgethash);
- }
- U.MD.UI.flashUpload = function (uploadfile, url, isgethash) {
- var _flashbottom = U.selectEl("*flashupload")[0],
- _fileid = uploadfile.fileid
- ;
- uploadfile.isupload = true;
-
- if (isgethash) {
-
- U.UF.UP.generateFileHash($("*flashupload")[0], _fileid);
- }
-
- else {
-
- U.UF.UP.flashUpload(_flashbottom, _fileid, url);
- }
- }
- U.MD.UI.flashUploadComplete = function (fileid) {
-
- }
- U.UF.UP.deleteUploadAllFile = function () {
- }
- U.MD.UI.flashEmptyUpload = function (el) {
- var _flashbottom = U.selectEl("*flashupload")[0];
- if (_flashbottom) {
- U.UF.UP.deleteUploadAllFile(_flashbottom);
- }
- }
- U.MD.UI.flashError = function (errorinfo) {
- if (errorinfo.message) {
- var _meeage = "上传处理失败:" + errorinfo.message;
- if (UE.errorID == 1502) {
- _meeage = "文件太大,电脑内存不足";
- }
- U.alert(_meeage);
- U.UF.C.console(errorinfo);
- }
- }
- U.MD.UI.printUploadFiles = function (uploadfiles, isflash) {
- var _type,
- _info,
- _uploaddiv,
- _panel,
- _panel_one,
- _progressel,
- _uploadcontent = U.selectEl("#U_MD_UI_UP_C"),
- _frag = $$("frag");
-
- for (i = 0; i < uploadfiles.length; i++) {
- uploadfiles[i].fileid = Guid.newGuid();
- _type = U.UF.UP.getFileNameAndExtension(uploadfiles[i]["name"])[1];
-
- _uploaddiv = $$("div", { "className": "U_MD_UI_UP_CO" }, _frag);
- _panel = $$("div", { "className": "U_MD_UI_UP_COO" }, _uploaddiv);
- _panel_one = $$("div", { "className": "U_MD_UI_UP_COI U_Img ", "style": { "cssText": "background-position:-12px 1px"} }, _panel);
- $$("div", { "className": "U_MD_UI_UP_COION", "innerHTML": _type }, _panel_one);
- _panel_one = $$("div", { "className": "U_MD_UI_UP_COT" }, _panel);
- $$("div", { "className": "U_MD_UI_UP_COTS U_MD_D_Text_Abbreviation", "innerHTML": uploadfiles[i].name }, _panel_one);
- $$("div", { "className": "U_MD_UI_UP_COTX", "innerHTML": "容量大小:" + U.UF.UP.minUnitToMaxUnit(uploadfiles[i]["size"]) }, _panel);
- _panel_one = $$("div", { "className": "U_MD_UI_UP_COS U_MD_D_Text_Abbreviation" }, _panel);
- $$("div", { "className": "U_MD_UI_UP_COSN", "innerHTML": "准备上传" }, _panel_one);
- $$("div", { "className": "U_MD_UI_UP_COSI U_Img" }, _panel_one);
- _panel_one = $$("div", { "className": "U_MD_UI_UP_COC U_MD_UI_UP_COX", "title": "等待响应..." }, _panel_one);
- $$("img", { "onerror": U.MD.C.imgError, "src": US.DOMAIN + "img/ULG.gif" }, _panel_one);
- $$("div", { "className": "U_MD_UI_UP_COX", "titlle": "点击撤销删除上传", "innerHTML": "撤销",
- "onclick": function () {
- U.MD.UI.delUploadFile(_uploaddiv, uploadfiles[0], isflash);
- }
- }, _panel);
- _progressel = $$("div", { "className": "U_MD_UI_UP_COU" }, _uploaddiv);
- uploadfiles[i].fileel = _uploaddiv;
- uploadfiles[i].progressel = _progressel;
- }
-
- _uploadcontent.append(_frag);
- }
- U.MD.UI.delUploadFile = function (uploadel, uploadfile, isflash) {
- var i, j,
- _allfiles = U.MD.UI.upload.uploadFileInfo,
- _fileinfo = U.MD.UI.getFileInfoById(uploadfile.fileid),
- _allfilesnum = _fileinfo[2],
- _filesnum = _fileinfo[1];
- U.selectEl(uploadel).remove();
- if (_filesnum != -1) {
-
- _allfiles[_allfilesnum].splice(_filesnum, 1)[0];
-
- if (!_allfiles[_allfilesnum].length) {
- _allfiles.splice(_allfilesnum, 1);
- }
-
- if (isflash) {
- U.UF.UP.deleteUploadFile($("*flashupload")[0], _filesnum, _allfilesnum);
- }
-
- else {
- U.UF.UP.html5Upload.deleteUploadFile(uploadfile);
- }
-
- if (uploadfile.isupload) {
-
- if (_allfiles.length) {
-
- for (i = 0; i < _allfiles.length; i++) {
- for (j = 0; j < _allfiles[i].length; j++) {
- if (!_allfiles[i][j].isupload) {
- return _allfiles[i][j];
- }
- }
- }
- }
- else {
-
- if (isflash) {
- U.MD.UI.flashEmptyUpload();
- }
- else {
- U.UF.UP.html5Upload.deleteUploadAllFile();
- }
- }
- }
- }
- }
- U.MD.UI.progress = function (progress, fileid, msg) {
- var _fileinfo = U.MD.UI.getFileInfoById(fileid)[0],
- _progresschilds = U.selectEl($(_fileinfo.fileel).childs(0).childs(0)[3]).Child(),
- _progress = Math.floor((progress.Loaded / progress.Total) * 100);
- _fileinfo.progressel.style.width = _progress + "%";
- _progresschilds[0].innerText = msg;
- _progresschilds[1].style.display = "none";
- _progresschilds[2].style.display = "block";
- }
- U.MD.UI.flashContinueUpload = function (fileid, url, isgethash) {
- var _fileinfo = U.MD.UI.getFileInfoById(fileid)[0],
- _nextuploadfile = U.MD.UI.delUploadFile(_fileinfo.fileel, _fileinfo, true);
-
- if (_nextuploadfile) {
- U.MD.UI.flashUpload(_nextuploadfile, url, isgethash);
- }
- }
|