|
|
@@ -11,12 +11,12 @@
|
|
|
const pmShare = (function () {
|
|
|
const spreadDom = $('#shareSpread');
|
|
|
let shareSeleted = null;
|
|
|
- let spreadObj = {workBook: null, sheet: null};
|
|
|
+ let spreadObj = { workBook: null, sheet: null };
|
|
|
let preSelection = null;
|
|
|
//项目分享类型,由别人分享给自己的,和自己分享给别人的
|
|
|
- const shareType = {receive: 'receive', shareTo: 'shareTo'};
|
|
|
+ const shareType = { receive: 'receive', shareTo: 'shareTo' };
|
|
|
//操作类型
|
|
|
- const oprType = {copy: 'copy', cancel: 'cancel'};
|
|
|
+ const oprType = { copy: 'copy', cancel: 'cancel' };
|
|
|
let tree = null,
|
|
|
actualIDShareInfo = {};//项目真实树ID与项目分享信息映射
|
|
|
const treeCol = 0;
|
|
|
@@ -30,26 +30,26 @@ const pmShare = (function () {
|
|
|
}
|
|
|
};
|
|
|
const headers = [
|
|
|
- {name: '工程列表', dataCode: 'name', width: 300, rateWidth: 0.55, vAlign: 'center', hAlign: 'left'},
|
|
|
- {name: '来自', dataCode: 'from', width: 80, rateWidth: 0.15, vAlign: 'center', hAlign: 'left'},
|
|
|
- {name: '分享时间', dataCode: 'shareDate', width: 140, rateWidth: 0.15, vAlign: 'center', hAlign: 'left'},
|
|
|
- {name: '总造价', dataCode: 'totalCost', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00'},
|
|
|
- {name: '项目类别', dataCode: 'valuationType', width: 100, vAlign: 'center', hAlign: 'left'},
|
|
|
+ { name: '工程列表', dataCode: 'name', width: 300, rateWidth: 0.55, vAlign: 'center', hAlign: 'left' },
|
|
|
+ { name: '来自', dataCode: 'from', width: 80, rateWidth: 0.15, vAlign: 'center', hAlign: 'left' },
|
|
|
+ { name: '分享时间', dataCode: 'shareDate', width: 140, rateWidth: 0.15, vAlign: 'center', hAlign: 'left' },
|
|
|
+ { name: '总造价', dataCode: 'totalCost', width: 100, vAlign: 'center', hAlign: 'right', formatter: '0.00' },
|
|
|
+ { name: '项目类别', dataCode: 'valuationType', width: 100, vAlign: 'center', hAlign: 'left' },
|
|
|
];
|
|
|
const spreadOpts = {
|
|
|
workBook: {
|
|
|
- tabStripVisible: false,
|
|
|
+ tabStripVisible: false,
|
|
|
allowContextMenu: false,
|
|
|
- allowCopyPasteExcelStyle : false,
|
|
|
+ allowCopyPasteExcelStyle: false,
|
|
|
allowExtendPasteRange: false,
|
|
|
- allowUserDragDrop : false,
|
|
|
+ allowUserDragDrop: false,
|
|
|
allowUserDragFill: false,
|
|
|
- scrollbarMaxAlign : true
|
|
|
+ scrollbarMaxAlign: true
|
|
|
},
|
|
|
sheet: {
|
|
|
isProtected: true,
|
|
|
- frozenlineColor : '#ababab',
|
|
|
- protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
|
|
|
+ frozenlineColor: '#ababab',
|
|
|
+ protectionOptions: { allowResizeRows: true, allowResizeColumns: true },
|
|
|
clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
|
|
|
}
|
|
|
};
|
|
|
@@ -60,11 +60,11 @@ const pmShare = (function () {
|
|
|
};
|
|
|
//设置选中行底色
|
|
|
//@param
|
|
|
- function setSelStyle(sel, backColor,sheet) {
|
|
|
+ function setSelStyle(sel, backColor, sheet) {
|
|
|
sel.row = sel.row === -1 ? 0 : sel.row;
|
|
|
renderSheetFunc(sheet, function () {
|
|
|
let style = projTreeObj.getSelStyle(backColor);
|
|
|
- for(let i = 0; i < sel.rowCount; i++){
|
|
|
+ for (let i = 0; i < sel.rowCount; i++) {
|
|
|
let row = i + sel.row;
|
|
|
sheet.setStyle(row, -1, style);
|
|
|
}
|
|
|
@@ -77,21 +77,21 @@ const pmShare = (function () {
|
|
|
tree.selected = node;
|
|
|
shareSeleted = node;
|
|
|
//恢复底色
|
|
|
- if(oldSel){
|
|
|
+ if (oldSel) {
|
|
|
setSelStyle(oldSel, projTreeObj.setting.style.defalutBackColor, spreadObj.sheet);
|
|
|
}
|
|
|
//设置选中行底色
|
|
|
- if(newSel){
|
|
|
+ if (newSel) {
|
|
|
setSelStyle(newSel, projTreeObj.setting.style.selectedColor, spreadObj.sheet);
|
|
|
}
|
|
|
preSelection = newSel;
|
|
|
}
|
|
|
//渲染时方法,停止渲染
|
|
|
//@param {Object}sheet {Function}func @return {void}
|
|
|
- function renderSheetFunc(sheet, func){
|
|
|
+ function renderSheetFunc(sheet, func) {
|
|
|
sheet.suspendEvent();
|
|
|
sheet.suspendPaint();
|
|
|
- if(func){
|
|
|
+ if (func) {
|
|
|
func();
|
|
|
}
|
|
|
sheet.resumeEvent();
|
|
|
@@ -99,11 +99,11 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//设置表选项
|
|
|
//@param {Object}workBook {Object}opts @return {void}
|
|
|
- function setSpreadOptions (workBook, opts) {
|
|
|
- for(let opt in opts.workBook){
|
|
|
+ function setSpreadOptions(workBook, opts) {
|
|
|
+ for (let opt in opts.workBook) {
|
|
|
workBook.options[opt] = opts.workBook[opt];
|
|
|
}
|
|
|
- for(let opt in opts.sheet){
|
|
|
+ for (let opt in opts.sheet) {
|
|
|
workBook.getActiveSheet().options[opt] = opts.sheet[opt];
|
|
|
}
|
|
|
}
|
|
|
@@ -114,9 +114,9 @@ const pmShare = (function () {
|
|
|
sheet.setColumnCount(headers.length);
|
|
|
sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
|
|
|
//let spreadWidth = getWorkBookWidth();
|
|
|
- for(let i = 0, len = headers.length; i < len; i++){
|
|
|
+ for (let i = 0, len = headers.length; i < len; i++) {
|
|
|
sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
|
|
|
- if(headers[i].formatter){
|
|
|
+ if (headers[i].formatter) {
|
|
|
sheet.setFormatter(-1, i, headers[i].formatter);
|
|
|
}
|
|
|
sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
|
|
|
@@ -129,18 +129,18 @@ const pmShare = (function () {
|
|
|
//表监听事件
|
|
|
//@param {Object}workBook @return {void}
|
|
|
function bindEvent(workBook, events) {
|
|
|
- if(Object.keys(events).length === 0){
|
|
|
+ if (Object.keys(events).length === 0) {
|
|
|
return;
|
|
|
}
|
|
|
const Events = GC.Spread.Sheets.Events;
|
|
|
- for(let event in events){
|
|
|
+ for (let event in events) {
|
|
|
workBook.bind(Events[event], events[event]);
|
|
|
}
|
|
|
}
|
|
|
//建表
|
|
|
//@return {void}
|
|
|
- function buildSheet(){
|
|
|
- spreadObj.workBook = new GC.Spread.Sheets.Workbook(spreadDom[0], {sheetCount: 1});
|
|
|
+ function buildSheet() {
|
|
|
+ spreadObj.workBook = new GC.Spread.Sheets.Workbook(spreadDom[0], { sheetCount: 1 });
|
|
|
sheetCommonObj.spreadDefaultStyle(spreadObj.workBook);
|
|
|
spreadObj.sheet = spreadObj.workBook.getActiveSheet();
|
|
|
setSpreadOptions(spreadObj.workBook, spreadOpts);
|
|
|
@@ -178,7 +178,7 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//此项目是否可以拷贝
|
|
|
//@param {String}userID {Object}project @return {Boolean}
|
|
|
- function isAllowCopy(userID, project){
|
|
|
+ function isAllowCopy(userID, project) {
|
|
|
let myShareInfo = getShareInfo(userID, project);
|
|
|
if (!myShareInfo) {
|
|
|
return false;
|
|
|
@@ -196,7 +196,7 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//获取树节点
|
|
|
//@param {Object}tree @return {Object}
|
|
|
- function getTreeNodeCell(tree){
|
|
|
+ function getTreeNodeCell(tree) {
|
|
|
let indent = 20;
|
|
|
let levelIndent = -5;
|
|
|
let halfBoxLength = 5;
|
|
|
@@ -276,23 +276,23 @@ const pmShare = (function () {
|
|
|
if (centerX < x + w) {
|
|
|
drawLine(ctx, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
|
|
|
let img;
|
|
|
- if(node.data.projType === projectType.folder){
|
|
|
+ if (node.data.projType === projectType.folder) {
|
|
|
img = document.getElementById('folder_open_pic');
|
|
|
imgWidth = 15;
|
|
|
}
|
|
|
- else if(node.data.projType === projectType.project){
|
|
|
+ else if (node.data.projType === projectType.project) {
|
|
|
img = document.getElementById('proj_pic');
|
|
|
imgWidth = 18;
|
|
|
}
|
|
|
- else if(node.data.projType === projectType.engineering){
|
|
|
+ else if (node.data.projType === projectType.engineering) {
|
|
|
img = document.getElementById('eng_pic');
|
|
|
imgWidth = 14;
|
|
|
}
|
|
|
- else if(node.data.projType === projectType.tender){
|
|
|
+ else if (node.data.projType === projectType.tender) {
|
|
|
img = document.getElementById('tender_pic');
|
|
|
imgWidth = 14;
|
|
|
}
|
|
|
- ctx.drawImage(img, centerX+indent/2+3, centerY - 7, imgWidth,imgHeight);
|
|
|
+ ctx.drawImage(img, centerX + indent / 2 + 3, centerY - 7, imgWidth, imgHeight);
|
|
|
}
|
|
|
// Draw Vertical Line
|
|
|
if (centerX < x + w) {
|
|
|
@@ -322,12 +322,12 @@ const pmShare = (function () {
|
|
|
}
|
|
|
};
|
|
|
// Draw Text
|
|
|
- arguments[2] = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
|
|
|
+ arguments[2] = x + (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3;
|
|
|
arguments[4] = w - (node.depth() + 1) * indent - node.depth() * levelIndent - imgWidth - 3;
|
|
|
GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
|
|
|
};
|
|
|
TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
|
|
|
- let info = {x: x, y: y, row: context.row, col: context.col, cellStyle: cellStyle, cellRect: cellRect, sheetArea: context.sheetArea};
|
|
|
+ let info = { x: x, y: y, row: context.row, col: context.col, cellStyle: cellStyle, cellRect: cellRect, sheetArea: context.sheetArea };
|
|
|
let node = tree.items[info.row];
|
|
|
if (node && node.data.projType === projectType.tender) {
|
|
|
info.isReservedLocation = true;
|
|
|
@@ -343,13 +343,13 @@ const pmShare = (function () {
|
|
|
let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
|
|
|
let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
|
|
|
zoom = hitinfo.sheet.zoom();
|
|
|
- let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
|
|
|
+ let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, { sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
|
|
|
//(图标+名字)区域
|
|
|
- function withingClickArea(){
|
|
|
- return hitinfo.x > centerX + halfBoxLength && hitinfo.x < centerX + halfBoxLength + imgWidth + indent/2+3 + textLength;
|
|
|
+ function withingClickArea() {
|
|
|
+ return hitinfo.x > centerX + halfBoxLength && hitinfo.x < centerX + halfBoxLength + imgWidth + indent / 2 + 3 + textLength;
|
|
|
}
|
|
|
//点击单位工程
|
|
|
- if(node.data.projType === projectType.tender){
|
|
|
+ if (node.data.projType === projectType.tender) {
|
|
|
/*let newTab = window.open('about:blank');
|
|
|
//打开项目的实际ID
|
|
|
BeforeOpenProject(node.data.actualTreeInfo.ID, {'fullFolder': GetFullFolder(node.parent)}, function () {
|
|
|
@@ -405,11 +405,11 @@ const pmShare = (function () {
|
|
|
let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
|
|
|
zoom = hitinfo.sheet.zoom();
|
|
|
let node = tree.items[hitinfo.row];
|
|
|
- let nodeIndent = node ? (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3 : 0;
|
|
|
- let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
|
|
|
+ let nodeIndent = node ? (node.depth() + 1) * indent + node.depth() * levelIndent + imgWidth + 3 : 0;
|
|
|
+ let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, { sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
|
|
|
let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
|
|
|
- if(textLength > cellWidth - nodeIndent){
|
|
|
- TREE_SHEET_HELPER.showTipsDiv(text,{pos: {}},hitinfo);
|
|
|
+ if (textLength > cellWidth - nodeIndent) {
|
|
|
+ TREE_SHEET_HELPER.showTipsDiv(text, { pos: {} }, hitinfo);
|
|
|
}
|
|
|
};
|
|
|
TreeNodeCellType.prototype.processMouseLeave = function (hitinfo) {
|
|
|
@@ -449,9 +449,9 @@ const pmShare = (function () {
|
|
|
let text = options.sheet.getText(options.row, options.col);
|
|
|
let acStyle = options.sheet.getActualStyle(options.row, options.col),
|
|
|
zoom = options.sheet.zoom();
|
|
|
- let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: options.sheet, row: options.row, col: options.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
|
|
|
+ let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, { sheet: options.sheet, row: options.row, col: options.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
|
|
|
const imgIndent = 5;
|
|
|
- let nowX = Math.floor(x) + textLength + imgIndent,
|
|
|
+ let nowX = Math.floor(x) + textLength + imgIndent,
|
|
|
nowY = Math.floor((y + (y + h)) / 2) - 7;
|
|
|
if (node.data.allowCooperate) {
|
|
|
ctx.drawImage(editImg, nowX, nowY, editImgWidth, editImgHeight);
|
|
|
@@ -482,11 +482,11 @@ const pmShare = (function () {
|
|
|
let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
|
|
|
let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
|
|
|
zoom = hitinfo.sheet.zoom();
|
|
|
- let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
|
|
|
- if(hitinfo.x - hitinfo.cellRect.x > 0 && hitinfo.x - hitinfo.cellRect.x < textLength){
|
|
|
+ let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, { sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
|
|
|
+ if (hitinfo.x - hitinfo.cellRect.x > 0 && hitinfo.x - hitinfo.cellRect.x < textLength) {
|
|
|
//由..分享,弹出分享者信息
|
|
|
- if(dataCode === 'from'){
|
|
|
- if(node.data.shareType === shareType.receive){
|
|
|
+ if (dataCode === 'from') {
|
|
|
+ if (node.data.shareType === shareType.receive) {
|
|
|
$('#userinfo').find('h4').text(node.data.userInfo.name);
|
|
|
$('#userinfo').find('h6').text(node.data.userInfo.company);
|
|
|
let mobileHtml = `<i class="fa fa-tablet"> ${node.data.userInfo.mobile ? node.data.userInfo.mobile : ''}</i>`;
|
|
|
@@ -510,38 +510,73 @@ const pmShare = (function () {
|
|
|
let value = hitInfo.sheet.getValue(hitInfo.row, hitInfo.col);
|
|
|
let acStyle = hitInfo.sheet.getActualStyle(hitInfo.row, hitInfo.col),
|
|
|
zoom = hitInfo.sheet.zoom();
|
|
|
- let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitInfo.sheet, row: hitInfo.row, col: hitInfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
|
|
|
- if (sheet && hitInfo.x - hitInfo.cellRect.x > 0 && hitInfo.x - hitInfo.cellRect.x < textLength) {
|
|
|
- canvas.style.cursor='pointer';
|
|
|
+ let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, { sheet: hitInfo.sheet, row: hitInfo.row, col: hitInfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
|
|
|
+ if (sheet && hitInfo.x - hitInfo.cellRect.x > 0 && hitInfo.x - hitInfo.cellRect.x < textLength) {
|
|
|
+ canvas.style.cursor = 'pointer';
|
|
|
return true;
|
|
|
- }else{
|
|
|
- canvas.style.cursor='default';
|
|
|
+ } else {
|
|
|
+ canvas.style.cursor = 'default';
|
|
|
}
|
|
|
return false;
|
|
|
};
|
|
|
return new InteractionCell();
|
|
|
}
|
|
|
|
|
|
+ function isUnread(unreadList, node) {
|
|
|
+ if (!unreadList) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const actualID = node && node.data && node.data.actualTreeInfo && node.data.actualTreeInfo.ID || null;
|
|
|
+ if (!actualID) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return !!unreadList.find(ID => ID === actualID);
|
|
|
+ }
|
|
|
const foreColor = '#007bff';
|
|
|
- const cancelForeColor = 'red';
|
|
|
+ const dangerColor = '#dc3545';
|
|
|
+ // 标记已读
|
|
|
+ // 打开任意的单位工程,都会将其父分享条目标记和自身为已读
|
|
|
+ // eg:被分享了一个建设项目,和其下一个单位工程,打开该一个单位工程,建设项目标记为已读、该单位工程也标记为已读
|
|
|
+ function handleMarkRead(unreadList, markReadProjectIDs) {
|
|
|
+ const col = headers.findIndex(item => item.dataCode === 'shareDate');
|
|
|
+ const sheet = spreadObj.workBook.getActiveSheet();
|
|
|
+ const style = new GC.Spread.Sheets.Style();
|
|
|
+ projTreeObj.renderSheetFuc(sheet, function () {
|
|
|
+ markReadProjectIDs.forEach(projectID => {
|
|
|
+ SHARE_TO.removeUnread(projectID, unreadList);
|
|
|
+ tree.items.forEach(node => {
|
|
|
+ if (node.data && node.data.actualTreeInfo && node.data.actualTreeInfo.ID === projectID) {
|
|
|
+ const row = node.serialNo();
|
|
|
+ sheet.setStyle(row, col, style);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
//显示树结构数据
|
|
|
//@param {Array}nodes {Array}headers @return {void}
|
|
|
- function showTreeData(nodes, headers){
|
|
|
+ function showTreeData(nodes, headers) {
|
|
|
let sheet = spreadObj.workBook.getActiveSheet();
|
|
|
- let fuc = function(){
|
|
|
+ let fuc = function () {
|
|
|
sheet.setRowCount(nodes.length);
|
|
|
- for(let i = 0; i < nodes.length; i++){
|
|
|
+ for (let i = 0; i < nodes.length; i++) {
|
|
|
let treeNodeCell = getTreeNodeCell(tree);
|
|
|
sheet.getCell(i, treeCol).cellType(treeNodeCell);
|
|
|
- for(let j = 0; j < headers.length; j++){
|
|
|
+ for (let j = 0; j < headers.length; j++) {
|
|
|
sheet.getRange(-1, j, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[j]['hAlign']]);
|
|
|
sheet.getRange(-1, j, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[j]['vAlign']]);
|
|
|
let dataCode = headers[j].dataCode;
|
|
|
- if(dataCode === 'from'){
|
|
|
+ if (dataCode === 'from') {
|
|
|
let style = new GC.Spread.Sheets.Style();
|
|
|
style.foreColor = foreColor;
|
|
|
sheet.setStyle(i, j, style);
|
|
|
sheet.getCell(i, j).cellType(getInteractionCell());
|
|
|
+ } else if (dataCode === 'shareDate') {
|
|
|
+ let style = new GC.Spread.Sheets.Style();
|
|
|
+ if (isUnread(unreadShareList, nodes[i])) {
|
|
|
+ style.foreColor = dangerColor;
|
|
|
+ }
|
|
|
+ sheet.setStyle(i, j, style);
|
|
|
}
|
|
|
sheet.setValue(i, j, nodes[i].data[dataCode] !== null && typeof nodes[i].data[dataCode] !== 'undefined' ? nodes[i].data[dataCode] : '');
|
|
|
}
|
|
|
@@ -549,6 +584,10 @@ const pmShare = (function () {
|
|
|
};
|
|
|
renderSheetFunc(sheet, fuc);
|
|
|
}
|
|
|
+ // 获取实际树ID为某值的所有节点
|
|
|
+ function getNodesByActualID(ID, items) {
|
|
|
+ return items.filter(node => node.data && node.data.actualTreeInfo && node.data.actualTreeInfo.ID === ID);
|
|
|
+ }
|
|
|
//同一棵树,可能存在相同数据显示多条的问题(传入的datas中不存在相同数据)
|
|
|
//将真实树结构数据存在actualTreeInfo中,外部树结构数据用uuid重置。
|
|
|
//@param {Array}datas
|
|
|
@@ -557,12 +596,12 @@ const pmShare = (function () {
|
|
|
for (let data of datas) {
|
|
|
//项目真实ID与项目分享信息映射,方便确定项目的权限
|
|
|
if (!actualIDShareInfo[data.ID]) {
|
|
|
- actualIDShareInfo[data.ID] = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, shareInfo: data.shareInfo};
|
|
|
+ actualIDShareInfo[data.ID] = { ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, shareInfo: data.shareInfo };
|
|
|
}
|
|
|
IDMapping[data.ID] = uuid.v1();
|
|
|
}
|
|
|
for (let data of datas) {
|
|
|
- data.actualTreeInfo = {ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID};
|
|
|
+ data.actualTreeInfo = { ID: data.ID, ParentID: data.ParentID, NextSiblingID: data.NextSiblingID };
|
|
|
data.ID = IDMapping[data.ID];
|
|
|
data.NextSiblingID = IDMapping[data.NextSiblingID] ? IDMapping[data.NextSiblingID] : -1;
|
|
|
data.ParentID = IDMapping[data.ParentID] ? IDMapping[data.ParentID] : -1;
|
|
|
@@ -584,7 +623,7 @@ const pmShare = (function () {
|
|
|
for (let data of datas) {
|
|
|
if (data.userInfo) {
|
|
|
//shareInfo中我的条目
|
|
|
- let selfInfo = _.find(data.shareInfo, {userID: userID});
|
|
|
+ let selfInfo = _.find(data.shareInfo, { userID: userID });
|
|
|
data.shareDate = selfInfo ? selfInfo.shareDate : ''
|
|
|
data.from = data.userInfo.name;
|
|
|
data.to = '分享给 我';
|
|
|
@@ -605,9 +644,9 @@ const pmShare = (function () {
|
|
|
allDatas = allDatas.concat(data.children);
|
|
|
}
|
|
|
}
|
|
|
- for(let proj of allDatas){
|
|
|
+ for (let proj of allDatas) {
|
|
|
let summaryProj = summaryInfo[proj.ID];
|
|
|
- if(summaryProj){
|
|
|
+ if (summaryProj) {
|
|
|
proj.totalCost = summaryProj.totalCost;
|
|
|
}
|
|
|
}
|
|
|
@@ -619,11 +658,11 @@ const pmShare = (function () {
|
|
|
//建立ID索引
|
|
|
for (let data of treeDatas) {
|
|
|
//新建一个简单对象,防止污染treeDatas的数据
|
|
|
- treeMapping[data.ID] = {ID: data.ID, prev: null, next: null};
|
|
|
+ treeMapping[data.ID] = { ID: data.ID, prev: null, next: null };
|
|
|
}
|
|
|
//绑定prev next
|
|
|
for (let data of treeDatas) {
|
|
|
- let me = treeMapping[data.ID],
|
|
|
+ let me = treeMapping[data.ID],
|
|
|
next = treeMapping[data.NextSiblingID];
|
|
|
if (next) {
|
|
|
me.next = next;
|
|
|
@@ -634,17 +673,17 @@ const pmShare = (function () {
|
|
|
let result = _.find(treeDatas, function (data) {
|
|
|
return !treeMapping[data.ID].prev
|
|
|
});
|
|
|
- return result ? result.ID : -1;
|
|
|
+ return result ? result.ID : -1;
|
|
|
}
|
|
|
//获取可成树的数据
|
|
|
//@param {Array}datas @return {Array}
|
|
|
- function getTreeDatas(groupedDatas, ungroupedDatas){
|
|
|
+ function getTreeDatas(groupedDatas, ungroupedDatas) {
|
|
|
//设置新的树结构数据
|
|
|
for (let data of groupedDatas) {
|
|
|
setTreeInfo([data].concat(data.children));
|
|
|
}
|
|
|
//未分类分段
|
|
|
- let tenders = _.filter(ungroupedDatas, {projType: projectType.tender});
|
|
|
+ let tenders = _.filter(ungroupedDatas, { projType: projectType.tender });
|
|
|
setTreeInfo(tenders);
|
|
|
let rst = [];
|
|
|
//整理树结构
|
|
|
@@ -652,7 +691,7 @@ const pmShare = (function () {
|
|
|
//第一个根节点数据
|
|
|
let firstID = getFirstID(groupedDatas);
|
|
|
//新建未分类建设项目及单项工程
|
|
|
- let ungroupedProj = {ID: uuid.v1(), ParentID: -1, NextSiblingID: firstID, name: '未分类建设项目', projType: projectType.project};
|
|
|
+ let ungroupedProj = { ID: uuid.v1(), ParentID: -1, NextSiblingID: firstID, name: '未分类建设项目', projType: projectType.project };
|
|
|
/*if (groupedDatas.length > 0) {
|
|
|
groupedDatas[groupedDatas.length - 1].NextSiblingID = ungroupedProj.ID;
|
|
|
}*/
|
|
|
@@ -672,10 +711,10 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//按照时间排序
|
|
|
//@param {Array}datas @return {void}
|
|
|
- function sortByDate(datas){
|
|
|
+ function sortByDate(datas) {
|
|
|
datas.sort(function (a, b) {
|
|
|
- let shareInfoA = _.find(a.shareInfo, {userID}),
|
|
|
- shareInfoB = _.find(b.shareInfo, {userID});
|
|
|
+ let shareInfoA = _.find(a.shareInfo, { userID }),
|
|
|
+ shareInfoB = _.find(b.shareInfo, { userID });
|
|
|
let aV = shareInfoA ? Date.parse(shareInfoA.shareDate) : 0,
|
|
|
bV = shareInfoB ? Date.parse(shareInfoB.shareDate) : 0;
|
|
|
//时间越晚越靠前
|
|
|
@@ -698,14 +737,14 @@ const pmShare = (function () {
|
|
|
data.allowCooperate = isAllowCoop(userID, data);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
//建立树
|
|
|
//@return void
|
|
|
- function initShareTree(){
|
|
|
+ function initShareTree() {
|
|
|
$.bootstrapLoading.start();
|
|
|
//获取分享数据
|
|
|
- CommonAjax.post('/pm/api/receiveProjects', {user_id: userID}, function (rstData) {
|
|
|
+ CommonAjax.post('/pm/api/receiveProjects', { user_id: userID }, function (rstData) {
|
|
|
// 排序 --分享的文件按照时间先后顺序排序,分享文件下的子文件,按照原本树结构显示,不需要排序
|
|
|
sortByDate(rstData.grouped);
|
|
|
sortByDate(rstData.ungrouped);
|
|
|
@@ -720,7 +759,7 @@ const pmShare = (function () {
|
|
|
tree.selected = tree.items[0];
|
|
|
showTreeData(tree.items, headers);
|
|
|
//初始选择
|
|
|
- let initSel = spreadObj.sheet.getSelections()[0] ? spreadObj.sheet.getSelections()[0] : {row: 0, rowCount: 1};
|
|
|
+ let initSel = spreadObj.sheet.getSelections()[0] ? spreadObj.sheet.getSelections()[0] : { row: 0, rowCount: 1 };
|
|
|
initSelection(initSel);
|
|
|
autoFlashHeight();
|
|
|
spreadObj.sheet.frozenColumnCount(4);
|
|
|
@@ -734,7 +773,7 @@ const pmShare = (function () {
|
|
|
selector: '#shareSpread',
|
|
|
build: function ($trigger, e) {
|
|
|
let target = SheetDataHelper.safeRightClickSelection($trigger, e, spreadObj.workBook);
|
|
|
- initSelection({row: target.row, rowCount: 1}, preSelection ? preSelection : null, spreadObj.sheet);
|
|
|
+ initSelection({ row: target.row, rowCount: 1 }, preSelection ? preSelection : null, spreadObj.sheet);
|
|
|
return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
|
|
|
},
|
|
|
items: {
|
|
|
@@ -768,11 +807,11 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//初始化视图
|
|
|
//@return void
|
|
|
- function initView(){
|
|
|
- if(tree){
|
|
|
+ function initView() {
|
|
|
+ if (tree) {
|
|
|
tree = null;
|
|
|
}
|
|
|
- if(spreadObj.workBook){
|
|
|
+ if (spreadObj.workBook) {
|
|
|
spreadObj.workBook.destroy();
|
|
|
spreadObj.workBook = null;
|
|
|
}
|
|
|
@@ -782,11 +821,11 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//根据建设项目获取单项工程
|
|
|
//@param {Number}projID @return {void}
|
|
|
- function setEng(projID){
|
|
|
- let engQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: projectType.engineering, userID: userID, ParentID: projID};
|
|
|
- CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: engQuery, options: '-_id -property'}, function (rstData) {
|
|
|
+ function setEng(projID) {
|
|
|
+ let engQuery = { $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], projType: projectType.engineering, userID: userID, ParentID: projID };
|
|
|
+ CommonAjax.post('/pm/api/getProjectsByQuery', { user_id: userID, query: engQuery, options: '-_id -property' }, function (rstData) {
|
|
|
$('#copyShare_selectEng').empty();
|
|
|
- for(let eng of rstData){
|
|
|
+ for (let eng of rstData) {
|
|
|
let opt = $('<option>').val(eng.ID).text(eng.name);
|
|
|
$('#copyShare_selectEng').append(opt);
|
|
|
}
|
|
|
@@ -794,15 +833,15 @@ const pmShare = (function () {
|
|
|
}
|
|
|
//从其他建设项目中复制中,建设项目的文件层次结构名称和顺序
|
|
|
//@param {Array}treeData @return {Array}
|
|
|
- function getFileHierarchyInfo(treeData){
|
|
|
- let tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
|
|
|
+ function getFileHierarchyInfo(treeData) {
|
|
|
+ let tree = idTree.createNew({ id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1 });
|
|
|
tree.loadDatas(treeData);
|
|
|
let items = tree.items;
|
|
|
let rst = [];
|
|
|
- function getFileHierarchyName(node){
|
|
|
+ function getFileHierarchyName(node) {
|
|
|
let nodeName = node.data.name;
|
|
|
let name = [];
|
|
|
- while (node.parent){
|
|
|
+ while (node.parent) {
|
|
|
name.push(node.parent.data.name ? node.parent.data.name : '');
|
|
|
node = node.parent;
|
|
|
}
|
|
|
@@ -810,22 +849,22 @@ const pmShare = (function () {
|
|
|
name.push(nodeName);
|
|
|
return name.join('\\');
|
|
|
}
|
|
|
- for(let node of items){
|
|
|
- if(node.children.length === 0 ){//project
|
|
|
- rst.push({ID: node.data.ID, fileHierarchyName: getFileHierarchyName(node)})
|
|
|
+ for (let node of items) {
|
|
|
+ if (node.children.length === 0) {//project
|
|
|
+ rst.push({ ID: node.data.ID, fileHierarchyName: getFileHierarchyName(node) })
|
|
|
}
|
|
|
}
|
|
|
return rst;
|
|
|
}
|
|
|
//设置拷贝工程下拉选择
|
|
|
//@return {void}
|
|
|
- function setCopyModal(){
|
|
|
+ function setCopyModal() {
|
|
|
//获取建设项目
|
|
|
- let projQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], projType: {$in: [projectType.project, projectType.folder]}, userID: userID};
|
|
|
- CommonAjax.post('/pm/api/getProjectsByQuery', {user_id: userID, query: projQuery, options: '-_id -property'}, function (rstData) {
|
|
|
+ let projQuery = { $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], projType: { $in: [projectType.project, projectType.folder] }, userID: userID };
|
|
|
+ CommonAjax.post('/pm/api/getProjectsByQuery', { user_id: userID, query: projQuery, options: '-_id -property' }, function (rstData) {
|
|
|
let fileHierarchyData = getFileHierarchyInfo(rstData);
|
|
|
$('#copyShare_selectProj').empty();
|
|
|
- for(let proj of fileHierarchyData){
|
|
|
+ for (let proj of fileHierarchyData) {
|
|
|
let opt = $('<option>').val(proj.ID).text(proj.fileHierarchyName);
|
|
|
$('#copyShare_selectProj').append(opt);
|
|
|
}
|
|
|
@@ -884,7 +923,7 @@ const pmShare = (function () {
|
|
|
$.bootstrapLoading.progressStart('拷贝项目', true);
|
|
|
$("#progress_modal_body").text('正在拷贝项目,请稍候……');
|
|
|
await ajaxPost('/pm/api/copyProjects', { projectMap: copyMap, user_id: userID, tenderCount: 1 });
|
|
|
- importProcessChecking();
|
|
|
+ importProcessChecking(null, null, projTreeObj.emitTreeChange);
|
|
|
} catch (err) {
|
|
|
alert(err);
|
|
|
}
|
|
|
@@ -901,21 +940,77 @@ const pmShare = (function () {
|
|
|
}
|
|
|
return `${orgName} (${userInfo.name}分享拷贝)`;
|
|
|
}
|
|
|
+ //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
|
|
|
+ function updateAfterCancel(userID, projectID) {
|
|
|
+ for (let item of tree.items) {
|
|
|
+ if (item.data.actualTreeInfo && item.data.actualTreeInfo.ID === projectID) {
|
|
|
+ _.remove(item.data.shareInfo, function (data) {
|
|
|
+ return data.userID === userID;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理节点操作属性变更(是否可拷贝、是否可编辑)
|
|
|
+ function handlePropChange(projectID, prop) {
|
|
|
+ const actualShareData = actualIDShareInfo[projectID];
|
|
|
+ if (actualShareData) {
|
|
|
+ const shareItem = actualShareData.shareInfo.find(s => s.userID === userID);
|
|
|
+ if (shareItem) {
|
|
|
+ Object.assign(shareItem, prop);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const nodes = getNodesByActualID(projectID, tree.items);
|
|
|
+ nodes.forEach(node => {
|
|
|
+ const shareItem = node.data.shareInfo.find(s => s.userID === userID);
|
|
|
+ if (shareItem) {
|
|
|
+ Object.assign(shareItem, prop);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const treeData = tree.items.map(item => item.data);
|
|
|
+ setPermissionsInfo(treeData);
|
|
|
+ showTreeData(tree.items, headers);
|
|
|
+ }
|
|
|
+ function handleCancelShare(cancelProjID) {
|
|
|
+ const node = tree.items.find(item => item.data.actualTreeInfo && item.data.actualTreeInfo.ID === cancelProjID);
|
|
|
+ if (node) {
|
|
|
+ tree.removeNode(node);
|
|
|
+ }
|
|
|
+ //更新与清除节点数据相同,且未被清除缓存分享信息
|
|
|
+ updateAfterCancel(userID, cancelProjID);
|
|
|
+ //重新设置actualIDShareInfo,以正确更新权限(清除了分享信息后,可能会导致权限变化 eg:清除了新的分享,则存留的分享项目采用旧的)
|
|
|
+ actualIDShareInfo = {};
|
|
|
+ let treeDatas = [];
|
|
|
+ for (let item of tree.items) {
|
|
|
+ treeDatas.push(item.data);
|
|
|
+ let actualTreeInfo = item.data.actualTreeInfo;
|
|
|
+ if (actualTreeInfo && !actualIDShareInfo[actualTreeInfo.ID]) {
|
|
|
+ actualIDShareInfo[actualTreeInfo.ID] = {
|
|
|
+ ID: actualTreeInfo.ID,
|
|
|
+ ParentID: actualTreeInfo.ParentID,
|
|
|
+ NextSiblingID: actualTreeInfo.NextSiblingID,
|
|
|
+ shareInfo: item.data.shareInfo
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //重新设置权限
|
|
|
+ setPermissionsInfo(treeDatas);
|
|
|
+ showTreeData(tree.items, headers);
|
|
|
+ }
|
|
|
//事件监听器
|
|
|
//@return void
|
|
|
- function eventListener(){
|
|
|
+ function eventListener() {
|
|
|
//tab
|
|
|
$('#tab_pm_share').on('shown.bs.tab', function () {
|
|
|
//侧滑隐藏
|
|
|
$('.slide-sidebar').removeClass('open');
|
|
|
$('.slide-sidebar').css('width', '0');
|
|
|
projTreeObj.tree = null;
|
|
|
- if(projTreeObj.workBook){
|
|
|
+ if (projTreeObj.workBook) {
|
|
|
projTreeObj.workBook.destroy();
|
|
|
projTreeObj.workBook = null;
|
|
|
}
|
|
|
gcTreeObj.tree = null;
|
|
|
- if(gcTreeObj.workBook){
|
|
|
+ if (gcTreeObj.workBook) {
|
|
|
gcTreeObj.workBook.destroy();
|
|
|
gcTreeObj.workBook = null;
|
|
|
}
|
|
|
@@ -955,48 +1050,25 @@ const pmShare = (function () {
|
|
|
//确认拷贝
|
|
|
$('#copyShare_confirm').click(function () {
|
|
|
let selProj = $('#copyShare_selectProj').select().val();
|
|
|
- if(!selProj){
|
|
|
+ if (!selProj) {
|
|
|
$('#copyShareProj-info').show();
|
|
|
return;
|
|
|
}
|
|
|
copyShareProject(tree.selected, parseInt(selProj));
|
|
|
});
|
|
|
//清除分享
|
|
|
- //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
|
|
|
- function updateAfterCancel(userID, projectID) {
|
|
|
- for (let item of tree.items) {
|
|
|
- if (item.data.actualTreeInfo && item.data.actualTreeInfo.ID === projectID) {
|
|
|
- _.remove(item.data.shareInfo, function (data) {
|
|
|
- return data.userID === userID;
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
$('#cancelShareConfirm').click(function () {
|
|
|
$.bootstrapLoading.start();
|
|
|
- let cancelProjID = tree.selected.data.actualTreeInfo.ID;
|
|
|
- CommonAjax.post('/pm/api/share', {user_id: userID, type: oprType.cancel, projectID: cancelProjID, shareData:[{userID: userID}]}, function (rstData) {
|
|
|
- tree.removeNode(tree.selected);
|
|
|
- //更新与清除节点数据相同,且为被清除缓存分享信息
|
|
|
- updateAfterCancel(userID, cancelProjID);
|
|
|
- //重新设置actualIDShareInfo,以正确更新权限(清除了分享信息后,可能会导致权限变化 eg:清除了新的分享,则存留的分享项目采用旧的)
|
|
|
- actualIDShareInfo = {};
|
|
|
- let treeDatas = [];
|
|
|
- for (let item of tree.items) {
|
|
|
- treeDatas.push(item.data);
|
|
|
- let actualTreeInfo = item.data.actualTreeInfo;
|
|
|
- if (actualTreeInfo && !actualIDShareInfo[actualTreeInfo.ID]) {
|
|
|
- actualIDShareInfo[actualTreeInfo.ID] = {
|
|
|
- ID: actualTreeInfo.ID,
|
|
|
- ParentID: actualTreeInfo.ParentID,
|
|
|
- NextSiblingID: actualTreeInfo.NextSiblingID,
|
|
|
- shareInfo: item.data.shareInfo
|
|
|
- };
|
|
|
- }
|
|
|
- }
|
|
|
- //重新设置权限
|
|
|
- setPermissionsInfo(treeDatas);
|
|
|
- showTreeData(tree.items, headers);
|
|
|
+ const cancelProjID = tree.selected.data.actualTreeInfo.ID;
|
|
|
+ const permissionType = commonConstants.SharePermissionChangeType.CANCEL;
|
|
|
+ CommonAjax.post('/pm/api/share', { user_id: userID, type: oprType.cancel, permissionType, projectID: cancelProjID, shareData: [{ userID: userID }] }, function (rstData) {
|
|
|
+ handleCancelShare(cancelProjID);
|
|
|
+
|
|
|
+ // 推送已打开的项目,通知已取消分享
|
|
|
+ SHARE_TO.emitPermissionChange(permissionType, userID, cancelProjID, rstData.emitTenders);
|
|
|
+ // 清除已读
|
|
|
+ SHARE_TO.removeUnread(cancelProjID, unreadShareList);
|
|
|
+
|
|
|
$.bootstrapLoading.end();
|
|
|
}, function () {
|
|
|
$.bootstrapLoading.end();
|
|
|
@@ -1004,7 +1076,16 @@ const pmShare = (function () {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- return {spreadObj, headers, initView, eventListener}
|
|
|
+ return {
|
|
|
+ spreadObj,
|
|
|
+ headers,
|
|
|
+ initView,
|
|
|
+ eventListener,
|
|
|
+ initShareTree,
|
|
|
+ handlePropChange,
|
|
|
+ handleCancelShare,
|
|
|
+ handleMarkRead
|
|
|
+ }
|
|
|
})();
|
|
|
|
|
|
$(document).ready(function () {
|