UNPKG

platform-project

Version:

平台项目

491 lines (445 loc) 19.1 kB
let AssistantList = require('./components/AssistantList.js'); let MultiSelect = require('./components/MultiSelect.js'); $('div[data-node="search-panel"]').assistantSearch(); $('.multi-select').multiSelect(function ($li) { var key = $li.attr('data-value'); if ($li.hasClass('selected')) { $('table [data-name="' + key + '"]').removeClass('hidden'); } else { $('table [data-name="' + key + '"]').addClass('hidden'); } }); /** * 首页 */ $(function () { var Util = require('./util.js'); var HTMLFactory = require('./HTMLFactory.js'); require('./components/FileDownloader.js'); // 搜索 var searchText = '', searchTimeOut; var isSeach = false; $('#product-id').on('input', function () { if (searchTimeOut) { clearTimeout(searchTimeOut); } searchTimeOut = setTimeout(function () { searchText = $('#product-id').val(); isSeach = true; getSearchList(searchText, isSeach); }, 1000) }) // 获取用户列表 function getSearchList(searchText, isSeach) { if (isSeach) { console.log(searchText); isSeach = false; if (!searchText) {//清空搜索栏 getProductList(1); return; } $('.page-area').css('display', 'none'); Util.doAjax({ url: '/api/projects/search', method: 'GET', data: { query: searchText, }, success: function (data) { var list = data.productList; var $left = $('.group-list .left-list'); var $right = $('.group-list .right-list'); $left.empty(); $right.empty(); if (!list || !list.length || list.length === 0) { $left.html('未找到搜索结果'); return; } for (var i = 0; i < list.length; i++) { var itemData = list[i]; var groupItem = HTMLFactory.createGroupItem(itemData); if (i % 2 === 0) { //放左边 $left.append($(groupItem)); } else { $right.append($(groupItem)); } //点击权限操作 $(".group-list .lock-tag").on('click', function () { var href = $(this).attr('data-href'); var restype = 0; //restype(资源类型 0:product 1:project) var resid = $(this).parent().parent().parent().attr('data-id'); var productid = resid; if (href) { window.location.href = href + '?resid=' + resid + '&restype=' + restype + '&productid=' + productid; } }) //下载按钮 $('.group-list a[data-node="file-downloader"]').fileDownloader(); } }, }); } } //点击项目标题 $(".group-list").on('click', '.product-item .title-area', function () { var $btn = $(this); var $tr = $btn.parent(); var id = $tr.attr('data-id'); window.location.href = './project.html?projectId=' + id; }); //产品头部右侧的修改设置按钮 $('.group-list').on('click', '.group-item .top .setup-tag', function () { var $item = $(this).parent().parent().parent(); var productId = $item.attr('data-id'); Util.doAjax({ url: '/api/product/edit', method: 'POST', data: { productId: productId }, success: function (data) { $('.create-product-mask .title-area .title').html('修改产品资料'); $('.create-product-mask').attr('data-id', productId).attr('data-action', 'edit'); $('.create-product-mask').removeClass('hidden'); $('.create-product-mask .name .value').val(data.productName); $('.create-product-mask .desc .value').val(data.productDesc); $('.create-product-mask .manager .value').val(data.productManager); $('.create-product-mask .kms .value').val(data.kmsAddress); $('.create-product-mask .jira .value').val(data.jiraAddress); $('.create-product-mask .status .item-' + data.status).click(); }, }); }); //表格中条目后面的编辑描述按钮 $(".group-list").delegate(".edit-desc-btn", "click", function (e) { //填入描述信息 var e = e || window.event; var $btn = $(e.target); var $tr = $btn.parent().parent(); var id = $tr.attr('data-id'); Util.doAjax({ url: '/api/project/description', method: 'POST', data: { projectId: id, }, success: function (data) { $('.edit-describe-mask .describe textarea').val(data.description); //显示弹窗 $('.edit-describe-mask').attr('data-id', id).removeClass('hidden'); }, }); }); $('.group-list').delegate('.product-list .lock-btn', 'click', function (e) { var href = $(this).attr('data-href'); var restype = 1; //restype(资源类型 0:product 1:project) var productid = $(this).parent().parent().parent().parent().parent().parent().attr('data-id'); var resid = $(this).parent().parent().attr('data-id'); if (href) { window.location.href = href + '?resid=' + resid + '&restype=' + restype + '&productid=' + productid; } }) $('.group-list').delegate('.product-list .build-log-btn', 'click', function (e) { var url = $(this).attr('data-href'); Util.doAjax({ url: url, method: 'POST', success: function (data) { window.open(url); } }); }) $('.group-list').delegate('.product-list .update-log-btn', 'click', function (e) { var url = $(this).attr('data-href'); Util.doAjax({ url: url, method: 'POST', success: function (data) { window.open(url); } }); }) //编辑项目描述 $('.edit-describe-mask .save-btn').on('click', function () { var projectId = $('.edit-describe-mask').attr('data-id'); var desc = $('.edit-describe-mask .content textarea').val(); if (!desc || desc.trim().length === 0) { Util.prompt('请填写描述内容!'); return; } Util.doAjax({ url: '/api/project/description/save', method: 'POST', data: { projectId: projectId, description: desc }, success: function (data) { $('.edit-describe-mask').addClass('hidden'); Util.prompt('修改成功!'); }, }); }); //显示全部 $(".group-list").delegate(".show-all-btn", "click", function (e) { var $btn = $(e.target); var $item = $btn.parent(); var $productList = $item.find('.product-list'); if ($btn.html() === '显示全部') { var tableHeight = $item.find('table').height(); $productList.stop().animate({ 'max-height': tableHeight + 'px' }, 100, function () { $btn.html('收起全部'); }); } else { $productList.stop().animate({ 'max-height': '310px' }, 100, function () { $btn.html('显示全部'); }); } }); //列表中的下载按钮 $('.group-list').on('click', '.product-item .download-btn', function () { var $btn = $(this); var paramObj = Util.parseURL($btn.attr('data-url')); var archiveId = paramObj.archiveId; if (!archiveId) { Util.prompt('没有可以下载的文件'); return; } Util.doDownload('/api/archive/download?archiveId=' + archiveId); }); // //列表中的构建日志按钮 // $('.group-list').on('click', '.product-item .build-log-btn', function(){ // var $btn = $(this); // var paramObj = Util.parseURL($btn.attr('data-url')); // var archiveId = paramObj.archiveId; // var items = [$btn.parent().parent().find('.title-area .title').html()]; // Util.doAjax({ // url: '/api/archive/download', // method: 'POST', // data: { // archiveId: archiveId, // items: items, // }, // success: function (data) { // }, // }); // }); // //列表中的变更日志按钮 // $('.group-list').on('click', '.product-item .upload-log-btn', function(){ // var $btn = $(this); // var paramObj = Util.parseURL($btn.attr('data-url')); // var archiveId = paramObj.archiveId; // Util.doAjax({ // url: '/api/archive/download', // method: 'POST', // data: { // archiveId: archiveId, // // items: items, // }, // success: function (data) { // }, // }); // }); //获取第一页的数据 getProductList(1); /** * 点击版本名称 */ $('.group-list').delegate(".version-name", "click", function (e) { var e = e || window.event; var $btn = $(e.target); var $tr = $btn.parent(); var archiveId = $tr.attr('data-archiveid'); // var archiveId = 126; getSummary(archiveId, 'POST'); }); function getSummary(archiveId, method) { Util.doAjax({ url: '/api/archive/summary', method: method, data: { archiveId: archiveId, pageNumber: 1, pageSize: 4, }, success: function (data) { var $versionDetailPropmt = $('.version-detail-mask'); //填充基本信息 $versionDetailPropmt.attr('data-archiveid', archiveId); $versionDetailPropmt.find('.title').html(Util.substring(data.projectName || '', 10)).attr('title', data.projectName); $versionDetailPropmt.find('.version-name .value').html(Util.substring(data.version || '', 18)).attr('title', data.version); $versionDetailPropmt.find('.create-time .value').html(Util.formatTime(data.createTime || '')); $versionDetailPropmt.find('.size .value').html(data.fileSize || 0); $versionDetailPropmt.find('.desc-info .value').html(data.versionDesc || ''); $versionDetailPropmt.find('.build-log-btn').attr('href', data.buildLog); $versionDetailPropmt.find('.update-log-btn').attr('href', data.changelog); $versionDetailPropmt.find('.group-download-btn').attr('data-url', data.downLoad); var $infoTable = $versionDetailPropmt.find('.info-table'); var infoTableHtml = ''; var scmList = data.scm.scm; if (scmList && scmList.length && scmList.length > 0) { for (var i = 0; i < scmList.length; i++) { var scm = scmList[i]; infoTableHtml += HTMLFactory.createSCMItem(scm); } $infoTable.find('tbody').html(infoTableHtml); } var $handleTable = $versionDetailPropmt.find('.handle-table'); var handleTableHtml = ''; var downloadList = data.downloadList.files; if (downloadList && downloadList.length && downloadList.length > 0) { for (var i = 0; i < downloadList.length; i++) { var download = downloadList[i]; download.id = i + 1; handleTableHtml += HTMLFactory.createDownLoadItem(download); } $handleTable.find('tbody').html(handleTableHtml); } $versionDetailPropmt.find('.vo-checkbox').vo_checkbox(); $handleTable.find('a[data-node="file-downloader"]').fileDownloader(); $versionDetailPropmt.removeClass('hidden'); }, }); } //版本详情弹窗中的批量下载按钮 $('.version-detail-prompt').on('click', '.group-download-btn', function () { var $btn = $(this); var archiveId = $('.version-detail-mask').attr('data-archiveid'); if (!archiveId) { Util.prompt('没有可以下载的文件'); return; } var items = []; $('.version-detail-mask .handle-table .vo-checkbox.checked').each(function () { items.push($(this).parent().parent().find('.file-name').attr('title')); }); Util.doDownload('/api/archive/download?archiveId=' + archiveId + '&items=' + items); }); //版本详情弹窗中的单个下载按钮 $('.version-detail-prompt').on('click', '.handle-table .download-btn', function () { var $btn = $(this); var name = $btn.parent().parent().find('.file-name').attr('title'); var archiveId = $('.version-detail-mask').attr('data-archiveid'); Util.doDownload('/api/archive/download?archiveId=' + archiveId + '&items=' + [name]); }); //版本详情弹窗中的单个删除文件按钮 $('.version-detail-prompt').on('click', '.handle-table .delete-btn', function () { deleteVersion($(this)); }); function deleteVersion($this) { var $btn = $this; var name = $btn.parent().parent().find('.file-name').attr('title'); var archiveId = $('.version-detail-mask').attr('data-archiveid'); var deletePrompt = Util.deletePrompt(); deletePrompt.find('.msg').html('确认删除该文件?'); deletePrompt.find('.sure-btn').click(function () { deletePrompt.remove(); Util.doAjax({ url: '/api/archive/delfile', method: 'POST', data: { archiveId: archiveId, fileName: name }, success: function (data) { console.log(data); if (data.code == 0) { Util.prompt('删除成功!'); $btn.parent().parent().remove(); } }, }); }); } //版本详情弹窗中的构建日志按钮 // $('.version-detail-prompt').on('click', '.build-log-btn', function () { // var $btn = $(this); // var archiveId = $('.version-detail-mask').attr('data-archiveid'); // Util.doAjax({ // url: '/api/archive/buildlog', // method: 'POST', // data: { // archiveId: archiveId, // }, // success: function (data) { // }, // }); // }); //版本详情弹窗中的变更日志按钮 // $('.version-detail-prompt').on('click', '.update-log-btn', function () { // var $btn = $(this); // var archiveId = $('.version-detail-mask').attr('data-archiveid'); // Util.doAjax({ // url: '/api/archive/changelog', // method: 'POST', // data: { // archiveId: archiveId, // }, // success: function (data) { // }, // }); // }); /** * 获取指定页码的列表数据 */ function getProductList(pageNum) { $('.page-area').css('display', 'block'); Util.doAjax({ url: '/api/productPage', method: 'POST', data: { pageNumber: pageNum, pageSize: 4, }, success: function (data) { var list = data.productList; if (!list || !list.length || list.length === 0) { return; } //处理页码 var total = +data.totalPages; if (total > 1 && $('.page-area .vo_pagination').length === 0) { var pagination = new Virgo.pagination({ node: $(".group-list .page-area"), // isNeedQuick: false, isNeedInput: false, callback: function (cur) { getProductList(cur); } }); pagination.trigger(1, total); } var $left = $('.group-list .left-list'); var $right = $('.group-list .right-list'); $left.empty(); $right.empty(); for (var i = 0; i < list.length; i++) { var itemData = list[i]; var groupItem = HTMLFactory.createGroupItem(itemData); if (i % 2 === 0) { //放左边 $left.append($(groupItem)); } else { $right.append($(groupItem)); } //点击权限操作 $(".group-list .lock-tag").on('click', function () { var href = $(this).attr('data-href'); var restype = 0; //restype(资源类型 0:product 1:project) var resid = $(this).parent().parent().parent().attr('data-id'); var productid = resid; if (href) { window.location.href = href + '?resid=' + resid + '&restype=' + restype + '&productid=' + productid; } }) //下载按钮 $('.group-list a[data-node="file-downloader"]').fileDownloader(); } }, }); } });