zhtengw 在 kodbox 的 main.js #39438 左右有“文件历史记录”功能的自定义右键菜单的实现方式,可以参考一下。相关代码如下:
exports['default'] = Backbone.View.extend({
init: function init() {
this.pathAction = this.root.pathAction;
this.rightMenu = new _rightMenu2['default']({ parent: this });
this.listenTo(this.root.rightMenu, {
'rightMenu.beforeShow': this.menuShow
});
},
menuShow: function menuShow(menu, menuType) {
var allow = ['.menu-path-file', '.menu-tree-file', '.menu-simple-file', '.menu-path-guest-file'];
if (!_.includes(allow, menuType)) return;
this.menuAppend(menu, data);
// 自动显示or隐藏;
var data = this.pathAction.makeParamItem();
var historyShow = _.get(data, 'sourceID') && this.pathAction.auth.canWrite(menu.$target);
var method = historyShow ? 'menuItemShow' : 'menuItemHide';
$.contextMenu[method](menu, 'file-history');
$.contextMenu[method](menu, 'file-history-replace');
},
menuAppend: function menuAppend(menu) {
if (menu.extendFileHistory) return;
var self = this;
var menuView = {
'file-history': {
name: LNG['explorer.history.list'],
className: "hidden ",
icon: "icon-history", // icon样式或html;
callback: function callback(action, option) {
var fileInfo = self.pathAction.makeParamItem();
self.initHistory(fileInfo.path);
}
}
};
var menuReplace = {
'file-history-replace': {
name: LNG['explorer.history.uploadNew'],
className: "hidden ",
icon: "icon-upload", // icon样式或html;
callback: function callback(action, option) {
var sourceInfo = self.pathAction.makeParamItem();
self.uploadNewVersion(sourceInfo);
}
}
};
$.contextMenu.menuAdd(menuView, menu, false, '.more-action');
$.contextMenu.menuAdd(menuReplace, menu, false, '.fav-add'); //before
menu.extendFileHistory = true;
},
uploadNewVersion: function uploadNewVersion(sourceInfo) {
/** 无关代码,省略 **/
},
// 上传新版本成功,刷新列表;
uploadVersionNotify: function uploadVersionNotify(uploadView, sourceInfo) {
/** 无关代码,省略 **/
},
// 请求历史记录列表,并初始化界面;
initHistory: function initHistory(filePath, page, pageNum) {
/** 无关代码,省略 **/
},
initDialog: function initDialog(data) {
/** 无关代码,省略 **/
},
bindEvent: function bindEvent(dialog, sourceInfo) {
/** 无关代码,省略 **/
},
bindEditDesc: function bindEditDesc($main) {
/** 无关代码,省略 **/
},
pageLoad: function pageLoad(pageInfo, path, dialog) {
/** 无关代码,省略 **/
}
});
```