Browse Source

feat: 导入接口遇到重名的,增加重命名

vian 4 years ago
parent
commit
4633a556fb

+ 9 - 0
web/building_saas/pm/html/project-management.html

@@ -766,6 +766,15 @@
                         </div>
                         </div>
                     </div>
                     </div>
                 </div>
                 </div>
+                <div id="import-rename" style="display: none;">
+                    <p style="color: #dc3545;">项目已存在,请重命名</p>
+                    <div class="form-group row">
+                        <label for="staticEmail" class="col-auto col-form-label col-form-label-sm">建设项目</label>
+                        <div class="col">
+                            <input type="text" class="form-control form-control-sm" placeholder="输入建设项目名称" id="import-rename-input" autocomplete="off">
+                        </div>
+                    </div>
+                </div>
             </div>
             </div>
             <div class="modal-footer">
             <div class="modal-footer">
                 <a id="interface-import-confirm" href="javascript:void(0);" class="btn btn-primary">确定导入</a>
                 <a id="interface-import-confirm" href="javascript:void(0);" class="btn btn-primary">确定导入</a>

+ 3 - 2
web/building_saas/standard_interface/import/base.js

@@ -520,11 +520,12 @@ const INTERFACE_EXPORT_BASE = (() => {
     console.log(templateData);
     console.log(templateData);
     // 处理建设项目数据
     // 处理建设项目数据
     // 确定建设项目的名称(不允许重复)
     // 确定建设项目的名称(不允许重复)
-    const sameDepthProjs = getProjs(projTreeObj.tree.selected);
+    /* const sameDepthProjs = getProjs(projTreeObj.tree.selected);
     const matchedProject = sameDepthProjs.find(node => node.data.name === importData.name);
     const matchedProject = sameDepthProjs.find(node => node.data.name === importData.name);
     if (matchedProject) {
     if (matchedProject) {
+      alert('test');
       importData.name += `(${moment(Date.now()).format('YYYY-MM-DD HH:mm:ss')})`;
       importData.name += `(${moment(Date.now()).format('YYYY-MM-DD HH:mm:ss')})`;
-    }
+    } */
     importData.compilation = compilationData._id;
     importData.compilation = compilationData._id;
     importData.userID = userID;
     importData.userID = userID;
     importData.ID = templateData.projectBeginID;
     importData.ID = templateData.projectBeginID;

+ 26 - 4
web/building_saas/standard_interface/import/view.js

@@ -32,9 +32,15 @@ const IMPORT_VIEW = (() => {
   }
   }
 
 
   // 导入相关事件监听器
   // 导入相关事件监听器
+  let importData = null;
+  let areaKey = '';
   function importListener() {
   function importListener() {
     // 文件选择变更
     // 文件选择变更
     $('#interface-import-file').change(function () {
     $('#interface-import-file').change(function () {
+      importData = null;
+      areaKey = '';
+      $('#import-rename-input').val('');
+      $('#import-rename').hide();
       const file = $(this)[0].files[0];
       const file = $(this)[0].files[0];
       $('#interface-import-label').text(file && file.name || '请选择导入文件');
       $('#interface-import-label').text(file && file.name || '请选择导入文件');
     });
     });
@@ -55,10 +61,24 @@ const IMPORT_VIEW = (() => {
         if (!parentArea || !subArea) {
         if (!parentArea || !subArea) {
           throw '请选择有效地区。';
           throw '请选择有效地区。';
         }
         }
-        const areaKey = `${parentArea}@${subArea}`;
-        await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.IMPORT);
-        const onlyImportMatchBills = areaKey === '广东@中山';
-        const importData = await INTERFACE_EXPORT_BASE.extractImportData(INTERFACE_IMPORT.entry, file, areaKey, false, onlyImportMatchBills);
+        const curAreaKey = `${parentArea}@${subArea}`;
+        if (!(importData && areaKey && areaKey === curAreaKey)) {
+          areaKey = curAreaKey;
+          await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.IMPORT);
+          const onlyImportMatchBills = areaKey === '广东@中山';
+          importData = await INTERFACE_EXPORT_BASE.extractImportData(INTERFACE_IMPORT.entry, file, areaKey, false, onlyImportMatchBills);
+        }
+        const constructionName = $('#import-rename').is(':visible') ? $('#import-rename-input').val() : importData.name;
+        // 确定建设项目的名称(不允许重复)
+        const sameDepthProjs = getProjs(projTreeObj.tree.selected);
+        const matchedProject = sameDepthProjs.find(node => node.data.name === constructionName);
+        if (matchedProject || !constructionName) {
+          $('#import-rename-input').val(constructionName);
+          $('#import-rename').show();
+          $('#import-rename-input').focus();
+          return;
+        }
+        importData.name = constructionName;
         $('#interface-import-modal').modal('hide');
         $('#interface-import-modal').modal('hide');
         $.bootstrapLoading.progressStart('导入文件', true);
         $.bootstrapLoading.progressStart('导入文件', true);
         $("#progress_modal_body").text('正在导入接口文件,请稍候……');
         $("#progress_modal_body").text('正在导入接口文件,请稍候……');
@@ -93,6 +113,8 @@ const IMPORT_VIEW = (() => {
 
 
 $(document).ready(() => {
 $(document).ready(() => {
   $('#interface-import-modal').on('show.bs.modal', () => {
   $('#interface-import-modal').on('show.bs.modal', () => {
+    $('#import-rename-input').val('');
+    $('#import-rename').hide();
     $('#interface-import-file').val('');
     $('#interface-import-file').val('');
     $('#interface-import-label').text('请选择导入文件');
     $('#interface-import-label').text('请选择导入文件');
     IMPORT_VIEW.initFileAccept($('#interface-import-file'));
     IMPORT_VIEW.initFileAccept($('#interface-import-file'));