平台默认的attachment(非attachmentSimple)相关的组件点图标调用的是$model.previewOrRemoveItem.bind($model)打开附件查看
如果要调用自己当前.w对应的js中的方法,可以如下修改
$model.getModel().preview.bind($model.getModel(),$object,$model)
其中preview是js中的函数名
attachment组件js文件中定义如下:
Model.prototype.preview = function(event, owner) { var docPath = event.docPath.get(); var docID = event.docID.get(); var docName = event.docName.get(); var fileID = event.fileID.get(); if (owner.$state.get() == 'upload' && owner.$access.get() % 4 >= 2) { if (!fileID && fileID == "") { var changeLog = DocUtils.InnerUtils.evalChangeLog(owner.changeLog, docID); // 兼容一种情况,一个页面上有多个附件,其他附件传的文件当前附件没有changeLog // 所以不会有fileID if (changeLog) { fileID = changeLog.cache_name; } else { return; } } var url = DocUtils.InnerUtils.getdocServerAction({ "docPath" : docPath, urlPattern : "/repository/file/view/" + fileID + "/last/content", isFormAction : false, context : this.getContext() }); window.open(url); } else if (owner.$state.get() == 'remove') { owner.deleteDoc(docID, docName); } };
attachmentPC组件js文件中定义如下:
Model.prototype.preview = function(event,owner){ if (owner.$state.get() == 'upload' && owner.$access.get() % 4 >= 2) { var fileID = event.fileID.get(); var docID = event.docID.get(); var docName = event.docName.get(); var fileType = docName.substring(docName.indexOf(".")); if (fileType != 'pdf') {// 判断文件类型,如果不是pdf就用平台默认的浏览的方式打开 if (!fileID && fileID == "") { var changeLog = DocUtils.InnerUtils.evalChangeLog(owner.changeLog, docID); if (changeLog) { fileID = changeLog.cache_name; owner.browseDoc(docID, event.docName.get(), fileID); } } else { owner.browseDoc(docID, event.docName.get(), fileID); } } else {// 文件类型是pdf就获取url自己调用需要的方法打开 var url = DocUtils.InnerUtils.getdocServerAction({ "docPath" : docPath, urlPattern : "/repository/file/view/" + fileID + "/last/content", isFormAction : false, context : this.getContext() }); window.open(url); } } else if (owner.$state.get() == 'remove') { owner.deleteDoc(event); }
注意需要加引用
var DocUtils = require('$UI/system/components/justep/docCommon/docUtil');
评一波