【Bex5】Grid单元格通过CellRender渲染附件,上传、下载、删除

  • GridCellRender
	Model.prototype.mainGridCellRender = function(event){
				event.html = "<div> <a class='btn btn-link file-operation' style='padding:0px;font-weight: bold;'  data-btn-type='upload'>上传</a> </div>";
				if (event.colVal && event.colVal.length > 2) {
					var array = JSON.parse(event.colVal);
					for (var i = 0; i < array.length; i++) {
						var htmlArray =[];
						htmlArray.push("<div>");
						htmlArray.push("  <a class='btn btn-link file-operation' style='padding:0px;color: red;' data-btn-type='del' data-file-index={3}>删除</a>");
						htmlArray.push("  <a class='btn btn-link file-operation' style='padding-top:0px; padding-bottom: 0px' data-btn-type='download' data-file-id={0} data-doc-path={1}>{2}</a>");
						htmlArray.push("</div>");
						event.html += justep.String.format(htmlArray.join(""), array[i].fileID, array[i].docPath, array[i].docName, i);
					}
					event.html = "<div style='margin: -8px 0px;'>" + event.html + "</div>";
				}
			}
	};
  • GridRowClick
	Model.prototype.mainGridRowClick = function(event){
		var dataset = event.domEvent.target.dataset;
		if (dataset.btnType === "download") {
			var url = DocUtils.InnerUtils.getdocServerAction({
				docPath : dataset.docPath,
				urlPattern : "/repository/file/download/" + dataset.fileId + "/last/content",
				isFormAction : false,
				context : this.getContext(),
				useCookie : false
			});
			window.open(url);
		} else if (dataset.btnType === "upload") {
			// 触发上传文件事件
			this._uploader._row = event.row;
			this._uploader.inputElement.click();
		} else if(dataset.btnType === "del") {
			this.comp("msg").show({
				type : "YesNo",
				title : "系统提示",
				message : "是否确认要删除这个文件?",
				callback : function(param) {
					if (param && param.button === "yes") {
						var row =event.row;
						var array = JSON.parse(row.val("file"));
						array.splice(dataset.fileIndex,1);
						row.val("pfile", JSON.stringify(array));
						row.data.saveData();
					}
				}
			});
		}
	};
  • InitUploader
	Model.prototype.initUploader = function() {
		// 初始化uploader
		// 初始化上传文件按钮
		var actionUrl = "/BusinessServer/business-action?" + this.getContext().getBSessionID();
		var uploader = new Uploader(this.getElementByXid("btnUpload"), {
			multiple : false,
			actionUrl : actionUrl,
			name : "in",
			requestHeader : {
				"Accept" : "application/json"
			},
			data : {
				process : this.getContext().getCurrentProcess(),
				activity : this.getContext().getCurrentActivity(),
				action : "uploadDocFileAction",
				subPath : "file"
			},
		});
		this._uploader = uploader;
		var me = this;
		this._uploader.on('onSuccess', function(event) {
			// 保存
			var files = this._row.val("file");
			if (files && files.length > 0) {
				files = JSON.parse(files);
			} else {
				files = [];
			}
			files.push({
				"docID" : event.response.data.value.docID,
				"docName" : event.file.name,
				"size" : event.file.size,
				"docPath" : event.response.data.value.docPath,
				"fileID" : event.response.data.value.fileID,
				"time" : event.file.lastModifiedDate.toISOString()
			});
			this._row.val("pfile", JSON.stringify(files));
			this._row.data.saveData();
			layer.close(me._layerIndex);
		});

		this._uploader.on('onStart', function(event) {
			// 开始上传文件事件
			me._layerIndex = layer.load(1);
			event.file.data.name = encodeURI(event.file.name);
		});
	};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值