|
@@ -7,7 +7,21 @@ const SHARE_TO = (() => {
|
|
|
CANCEL: 'cancel',
|
|
|
};
|
|
|
|
|
|
- const { SharePermissionChangeType: PermissionType, PageTarget } = commonConstants;
|
|
|
+ const { SharePermissionChangeType: PermissionType, PageTarget, ShareLibType } = commonConstants;
|
|
|
+
|
|
|
+
|
|
|
+ const Mode = {
|
|
|
+ PROJECT: 1,
|
|
|
+ RATION_LIB: 2
|
|
|
+ };
|
|
|
+
|
|
|
+ const ModeToLibType = {
|
|
|
+ [Mode.RATION_LIB]: ShareLibType.RATION_LIB
|
|
|
+ };
|
|
|
+
|
|
|
+ // 当前模式
|
|
|
+ let curMode = Mode.PROJECT;
|
|
|
+
|
|
|
|
|
|
// 当前分享的项目ID
|
|
|
let curProjectID;
|
|
@@ -25,9 +39,13 @@ const SHARE_TO = (() => {
|
|
|
const rencentCount = 5;
|
|
|
|
|
|
// 获取初始数据:1.最近分享人 2.联系人 3.已分享人
|
|
|
- async function getInitalData(projectID) {
|
|
|
+ async function getInitialData(projectID) {
|
|
|
return await ajaxPost('/pm/api/getInitialShareData', { user_id: userID, count: rencentCount, projectID }, false);
|
|
|
+ }
|
|
|
|
|
|
+ // 获取分享库的初始数据
|
|
|
+ async function getInitialLibData(libType) {
|
|
|
+ return await ajaxPost('/pm/api/getInitialShareLibData', { user_id: userID, count: rencentCount, libType }, false);
|
|
|
}
|
|
|
|
|
|
// 获取头像视图html
|
|
@@ -122,16 +140,16 @@ const SHARE_TO = (() => {
|
|
|
<div class="col-5">${company}</div>
|
|
|
<div class="col ml-auto p-0">
|
|
|
<div class="d-flex justify-content-end">
|
|
|
- <div>
|
|
|
- <div class="custom-control custom-checkbox">
|
|
|
- <input type="checkbox" class="custom-control-input allow-copy" id="${copyLabelFor}" data-user="${user._id}" ${user.allowCopy ? 'checked' : ''}>
|
|
|
- <label class="custom-control-label" for="${copyLabelFor}">允许拷贝</label>
|
|
|
- </div>
|
|
|
- <div class="custom-control custom-checkbox">
|
|
|
- <input type="checkbox" class="custom-control-input allow-edit" id="${editLabelFor}" data-user="${user._id}" ${user.allowCooperate ? 'checked' : ''}>
|
|
|
- <label class="custom-control-label" for="${editLabelFor}">允许编辑</label>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ ${curMode === Mode.PROJECT ? `<div>
|
|
|
+ <div class="custom-control custom-checkbox">
|
|
|
+ <input type="checkbox" class="custom-control-input allow-copy" id="${copyLabelFor}" data-user="${user._id}" ${user.allowCopy ? 'checked' : ''}>
|
|
|
+ <label class="custom-control-label" for="${copyLabelFor}">允许拷贝</label>
|
|
|
+ </div>
|
|
|
+ <div class="custom-control custom-checkbox">
|
|
|
+ <input type="checkbox" class="custom-control-input allow-edit" id="${editLabelFor}" data-user="${user._id}" ${user.allowCooperate ? 'checked' : ''}>
|
|
|
+ <label class="custom-control-label" for="${editLabelFor}">允许编辑</label>
|
|
|
+ </div>
|
|
|
+ </div>` : ''}
|
|
|
<div class="ml-3 d-flex align-items-center">
|
|
|
<button class="btn btn-sm btn-outline-danger cancel-share" data-user="${user._id}">取消分享</button>
|
|
|
</div>
|
|
@@ -153,7 +171,11 @@ const SHARE_TO = (() => {
|
|
|
});
|
|
|
// 取消分享
|
|
|
$('#shared-list .cancel-share').click(function () {
|
|
|
- handleShareAction.call(this, ShareType.CANCEL);
|
|
|
+ if (curMode === Mode.PROJECT) {
|
|
|
+ handleShareAction.call(this, ShareType.CANCEL);
|
|
|
+ } else {
|
|
|
+ handleShareLibAction.call(this, ShareType.CANCEL, ModeToLibType[curMode]);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -177,16 +199,16 @@ const SHARE_TO = (() => {
|
|
|
<div class="col-5">${company}</div>
|
|
|
<div class="col ml-auto p-0">
|
|
|
<div class="d-flex justify-content-end">
|
|
|
- <div>
|
|
|
- <div class="custom-control custom-checkbox">
|
|
|
- <input type="checkbox" class="custom-control-input" id="allow-copy" checked="">
|
|
|
- <label class="custom-control-label" for="allow-copy">允许拷贝</label>
|
|
|
- </div>
|
|
|
- <div class="custom-control custom-checkbox">
|
|
|
- <input type="checkbox" class="custom-control-input" id="allow-edit">
|
|
|
- <label class="custom-control-label" for="allow-edit">允许编辑</label>
|
|
|
- </div>
|
|
|
+ ${curMode === Mode.PROJECT ? `<div>
|
|
|
+ <div class="custom-control custom-checkbox">
|
|
|
+ <input type="checkbox" class="custom-control-input" id="allow-copy" checked="">
|
|
|
+ <label class="custom-control-label" for="allow-copy">允许拷贝</label>
|
|
|
</div>
|
|
|
+ <div class="custom-control custom-checkbox">
|
|
|
+ <input type="checkbox" class="custom-control-input" id="allow-edit">
|
|
|
+ <label class="custom-control-label" for="allow-edit">允许编辑</label>
|
|
|
+ </div>
|
|
|
+ </div>` : ''}
|
|
|
<div class="ml-3 d-flex align-items-center"><button class="btn btn-sm btn-primary" id="share-to" data-user="${user._id}">分享给Ta</button></div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -204,7 +226,11 @@ const SHARE_TO = (() => {
|
|
|
});
|
|
|
// 分享给事件
|
|
|
$('#share-to').click(function () {
|
|
|
- handleShareAction.call(this, ShareType.CREATE, user);
|
|
|
+ if (curMode === Mode.PROJECT) {
|
|
|
+ handleShareAction.call(this, ShareType.CREATE, user);
|
|
|
+ } else {
|
|
|
+ handleShareLibAction.call(this, ShareType.CREATE, ModeToLibType[curMode], user);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -219,6 +245,52 @@ const SHARE_TO = (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async function handleShareLibAction(shareType, libType, user) {
|
|
|
+ try {
|
|
|
+ $.bootstrapLoading.start();
|
|
|
+ const receiver = $(this).data('user');
|
|
|
+ let shareData;
|
|
|
+ if (shareType === ShareType.CREATE) {
|
|
|
+ shareData = [{ receiver }];
|
|
|
+ } else if (shareType === ShareType.CANCEL) {
|
|
|
+ shareData = [{ receiver, isCancel: true }];
|
|
|
+ }
|
|
|
+ const postData = {
|
|
|
+ type: shareType,
|
|
|
+ user_id: userID,
|
|
|
+ count: rencentCount,
|
|
|
+ libType,
|
|
|
+ shareData
|
|
|
+ };
|
|
|
+ const rst = await ajaxPost('/pm/api/shareLib', postData);
|
|
|
+ // 请求成功后刷新视图
|
|
|
+ if (shareType === ShareType.CREATE || shareType === ShareType.CANCEL) {
|
|
|
+ if (shareType === ShareType.CREATE) {
|
|
|
+ curSharedUsers.unshift(user);
|
|
|
+ $('#share-phone').val('');
|
|
|
+ initSearchResultView();
|
|
|
+ } else {
|
|
|
+ curSharedUsers = curSharedUsers.filter(user => user._id !== receiver);
|
|
|
+ }
|
|
|
+ if (Array.isArray(rst.recentUsers)) {
|
|
|
+ initRecentView(rst.recentUsers);
|
|
|
+ }
|
|
|
+ if (Array.isArray(rst.contacts)) {
|
|
|
+ initContactsView(rst.contacts)
|
|
|
+ }
|
|
|
+ initSharedView(curSharedUsers);
|
|
|
+ refreshShareTip(curSharedUsers);
|
|
|
+ refreshTreeView();
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err);
|
|
|
+ alert(`${String(err)} 请重试。`);
|
|
|
+ initSharedView(curSharedUsers);
|
|
|
+ } finally {
|
|
|
+ $.bootstrapLoading.end();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 添加分享、编辑分享、取消分享的动作
|
|
|
async function handleShareAction(shareType, user) {
|
|
|
try {
|
|
@@ -470,25 +542,37 @@ const SHARE_TO = (() => {
|
|
|
}
|
|
|
|
|
|
// 初始化分享给的页面
|
|
|
- async function initModal(projectID) {
|
|
|
+ // mode: 模式,分享项目、分享库
|
|
|
+ async function initModal(mode, projectID) {
|
|
|
try {
|
|
|
- curProjectID = projectID;
|
|
|
+ curMode = mode;
|
|
|
$.bootstrapLoading.start();
|
|
|
// 恢复
|
|
|
$('#share-phone').val('');
|
|
|
initSearchResultView();
|
|
|
$('#share-hint').text('');
|
|
|
- const { isFree, sharedUsers, recentUsers, contacts } = await getInitalData(projectID);
|
|
|
- if (isFree) {
|
|
|
- hintBox.versionBox('此功能仅在专业版中提供,免费版可选择单位工程进行分享。');
|
|
|
+ let sharedUsers = [];
|
|
|
+ let recentUsers = [];
|
|
|
+ let contacts = [];
|
|
|
+ let data;
|
|
|
+ if (mode === Mode.PROJECT) {
|
|
|
+ curProjectID = projectID;
|
|
|
+ data = await getInitialData(projectID);
|
|
|
+ if (data.isFree) {
|
|
|
+ return hintBox.versionBox('此功能仅在专业版中提供,免费版可选择单位工程进行分享。');
|
|
|
+ }
|
|
|
} else {
|
|
|
- curSharedUsers = sharedUsers;
|
|
|
- initSharedView(sharedUsers);
|
|
|
- initRecentView(recentUsers);
|
|
|
- initContactsView(contacts);
|
|
|
- setTimeout(() => $('#share-phone').focus(), 200);
|
|
|
- $('#share').modal('show');
|
|
|
+ data = await getInitialLibData(ModeToLibType[curMode]);
|
|
|
}
|
|
|
+ sharedUsers = data.sharedUsers;
|
|
|
+ recentUsers = data.recentUsers;
|
|
|
+ contacts = data.contacts;
|
|
|
+ curSharedUsers = sharedUsers;
|
|
|
+ initSharedView(sharedUsers);
|
|
|
+ initRecentView(recentUsers);
|
|
|
+ initContactsView(contacts);
|
|
|
+ setTimeout(() => $('#share-phone').focus(), 200);
|
|
|
+ $('#share').modal('show');
|
|
|
} catch (err) {
|
|
|
console.log(err);
|
|
|
alert(err);
|
|
@@ -595,6 +679,7 @@ const SHARE_TO = (() => {
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
+ Mode,
|
|
|
initModal,
|
|
|
handleEventListener,
|
|
|
permissionChangeListener,
|