tanghc 3 years ago
parent
commit
f05822a40c

+ 4 - 0
changelog.md

@@ -1,5 +1,9 @@
 # changelog
 
+## 1.4.11
+
+- 优化交互
+
 ## 1.4.10
 
 - 修复PostgreSQL数值类型映射问题

+ 0 - 14
front/src/router/index.js

@@ -70,20 +70,6 @@ export const constantRoutes = [
     ]
   },
   {
-    path: '/group',
-    component: Layout,
-    meta: { title: '模板组管理', icon: 'example' },
-    redirect: '/group/list',
-    children: [
-      {
-        path: 'list',
-        name: 'List',
-        component: () => import('@/views/group/index'),
-        meta: { title: '模板组管理' }
-      }
-    ]
-  },
-  {
     path: '/template',
     component: Layout,
     meta: { title: '模板管理', icon: 'table' },

+ 3 - 0
front/src/utils/global.js

@@ -76,6 +76,9 @@ Object.assign(Vue.prototype, {
       }
     }).catch(function() {})
   },
+  handleCommand: function(command) {
+    command()
+  },
   /**
    * 重置表单
    * @param formName 表单元素的ref

+ 4 - 2
front/src/views/generate/GenerateConfig/index.vue

@@ -341,12 +341,14 @@ export default {
       this.setAttr(current_datasource_id_key, id)
     },
     getCurrentDataSourceId() {
-      const id = this.getAttr(current_datasource_id_key);
+      const id = this.getAttr(current_datasource_id_key)
       return parseInt(id) || ''
     },
     onDataSourceAdd() {
       this.datasourceTitle = '新建连接'
-      Object.keys(this.datasourceFormData).forEach(key=>{this.datasourceFormData[key]=''})
+      Object.keys(this.datasourceFormData).forEach(key => {
+        this.datasourceFormData[key] = ''
+      })
       this.datasourceFormData.id = 0
       this.datasourceDlgShow = true
       this.$nextTick(() => {

+ 142 - 39
front/src/views/template/index.vue

@@ -1,35 +1,54 @@
 <template>
   <div class="app-container">
-    <el-button type="primary" size="mini" icon="el-icon-plus" style="margin-bottom: 10px;" @click="onAdd">新增模板</el-button>
-    <el-table
-      :data="tableData"
-      border
-      highlight-current-row
-    >
-      <el-table-column
-        prop="groupName"
-        label="组名称"
-        width="200"
-      />
-      <el-table-column
-        prop="name"
-        label="模板名称"
-        width="200"
-      />
-      <el-table-column
-        prop="fileName"
-        label="文件名称"
-      />
-      <el-table-column
-        label="操作"
-        width="150"
+    <el-button type="primary" size="mini" icon="el-icon-plus" style="margin-bottom: 10px;" @click="onGroupAdd">添加模板组</el-button>
+    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
+      <el-tab-pane v-for="item in groupData" :key="item.id" :name="`${item.id}`" :label="item.groupName">
+        <span slot="label">
+          {{ item.groupName }}
+          <el-dropdown
+            v-show="item.id === currentTab.id"
+            trigger="click"
+            style="margin-left: 5px;"
+            @command="handleCommand"
+          >
+            <span class="el-dropdown-link">
+              <el-tooltip placement="top" content="更多操作" :open-delay="500">
+                <a class="el-icon-setting el-icon--right"></a>
+              </el-tooltip>
+            </span>
+            <el-dropdown-menu slot="dropdown">
+              <el-dropdown-item icon="el-icon-edit" :command="onGroupInfoUpdate">修改</el-dropdown-item>
+              <el-dropdown-item icon="el-icon-delete" :command="onGroupInfoDelete">删除</el-dropdown-item>
+            </el-dropdown-menu>
+          </el-dropdown>
+        </span>
+      </el-tab-pane>
+      <el-button type="text" size="mini" icon="el-icon-plus" style="margin-bottom: 10px;" @click="onAdd">新增模板</el-button>
+      <el-table
+        :data="tableData"
+        border
+        highlight-current-row
       >
-        <template slot-scope="scope">
-          <el-button type="text" size="mini" @click="onTableUpdate(scope.row)">修改</el-button>
-          <el-button type="text" size="mini" @click="onTableDelete(scope.row)">删除</el-button>
-        </template>
-      </el-table-column>
-    </el-table>
+        <el-table-column
+          prop="name"
+          label="模板名称"
+          width="200"
+        />
+        <el-table-column
+          prop="fileName"
+          label="文件名称"
+        />
+        <el-table-column
+          label="操作"
+          width="150"
+        >
+          <template slot-scope="scope">
+            <el-button type="text" size="mini" @click="onTableUpdate(scope.row)">修改</el-button>
+            <el-button type="text" size="mini" @click="onTableDelete(scope.row)">删除</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+    </el-tabs>
   </div>
 </template>
 
@@ -37,22 +56,52 @@
 export default {
   data() {
     return {
-      tableData: []
+      activeName: '',
+      tableData: [],
+      groupData: [],
+      currentTab: { id: 0 }
     }
   },
   created() {
-    this.loadTable()
+    this.reload()
   },
   methods: {
-    loadTable: function() {
-      this.groupId = this.$route.query.groupId;
-      if (typeof this.groupId === 'undefined') {
-        this.groupId = '';
+    reload() {
+      this.loadGroup()
+    },
+    loadGroup: function() {
+      this.post('/group/list', {}, function(resp) {
+        this.groupData = resp.data
+        let id = this.currentTab.id
+        if (!id && this.groupData.length > 0) {
+          id = this.groupData[0].id
+        }
+        if (id) {
+          this.selectTab(id)
+        }
+      })
+    },
+    selectTab(id) {
+      for (const group of this.groupData) {
+        if (group.id === id) {
+          this.currentTab = group
+          break
+        }
       }
-      this.post(`/template/list?groupId=${this.groupId}`, {}, function(resp) {
+      this.loadTable(id)
+    },
+    loadTable: function(groupId) {
+      this.activeName = `${groupId}`
+      this.post(`/template/list?groupId=${groupId}`, {}, function(resp) {
         this.tableData = resp.data
       })
     },
+    handleClick(tab) {
+      const id = parseInt(tab.name)
+      if (id) {
+        this.selectTab(parseInt(id))
+      }
+    },
     onTableUpdate: function(row) {
       this.goRoute(`edit/${row.id}`)
     },
@@ -61,13 +110,67 @@ export default {
         this.post('/template/del', row, function() {
           done()
           this.tip('删除成功')
-          this.loadTable()
+          this.reload()
         })
       })
     },
     onAdd: function() {
-      this.goRoute(`edit/0?groupId=${this.groupId}`)
-    }
+      this.goRoute(`edit/0?groupId=${this.currentTab.id}`)
+    },
+    // group
+    onGroupInfoUpdate() {
+      this.onGroupUpdate(this.currentTab)
+    },
+    onGroupInfoDelete() {
+      this.onGroupDelete(this.currentTab)
+    },
+    onGroupAdd: function() {
+      this.groupTitle = '增加模板组'
+      this.$prompt('请输入组名称', '增加模板组', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        inputValue: '',
+        inputPattern: /^.{1,64}$/,
+        inputErrorMessage: '不能为空且长度在64以内'
+      }).then(({ value }) => {
+        const data = {
+          groupName: value
+        }
+        this.post('/group/add', data, resp => {
+          this.currentTab = resp.data
+          this.reload()
+        })
+      }).catch(() => {
+      })
+    },
+    onGroupUpdate: function(row) {
+      this.$prompt('请输入组名称', '修改模板组', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        inputValue: row.groupName,
+        inputPattern: /^.{1,64}$/,
+        inputErrorMessage: '不能为空且长度在64以内'
+      }).then(({ value }) => {
+        const data = {
+          id: row.id,
+          groupName: value
+        }
+        this.post('/group/update', data, resp => {
+          this.reload()
+        })
+      }).catch(() => {
+      })
+    },
+    onGroupDelete: function(row) {
+      this.confirm(`确认要删除【${row.groupName}】吗?`, function(done) {
+        this.post('/group/del', row, function() {
+          done()
+          this.tip('删除成功')
+          this.currentTab.id = 0
+          this.reload()
+        })
+      })
+    },
   }
 }
 </script>

+ 9 - 0
gen/src/main/java/com/gitee/gen/controller/TemplateGroupController.java

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
+import java.util.Objects;
 
 /**
  * @author : zsljava
@@ -56,6 +57,10 @@ public class TemplateGroupController {
      */
     @RequestMapping("add")
     public Result insert(@RequestBody TemplateGroup templateGroup) {
+        TemplateGroup group = templateGroupService.getByName(templateGroup.getGroupName());
+        if (group != null) {
+            throw new RuntimeException(templateGroup.getGroupName() + " 已存在");
+        }
         templateGroupService.insertIgnoreNull(templateGroup);
         return Action.ok(templateGroup);
     }
@@ -68,6 +73,10 @@ public class TemplateGroupController {
      */
     @RequestMapping("update")
     public Result update(@RequestBody TemplateGroup templateGroup) {
+        TemplateGroup group = templateGroupService.getByName(templateGroup.getGroupName());
+        if (group != null && !Objects.equals(group.getId(), templateGroup.getId())) {
+            throw new RuntimeException(templateGroup.getGroupName() + " 已存在");
+        }
         templateGroupService.updateIgnoreNull(templateGroup);
         return Action.ok();
     }

+ 8 - 0
gen/src/main/java/com/gitee/gen/mapper/TemplateGroupMapper.java

@@ -30,6 +30,14 @@ public interface TemplateGroupMapper {
     TemplateGroup getById(Integer id);
 
     /**
+     * 根据name查询
+     *
+     * @param name name
+     * @return 返回记录,没有返回null
+     */
+    TemplateGroup getByName(String name);
+
+    /**
      * 新增,插入所有字段
      *
      * @param templateGroup 新增的记录

+ 4 - 0
gen/src/main/java/com/gitee/gen/service/TemplateGroupService.java

@@ -102,4 +102,8 @@ public class TemplateGroupService {
         templateConfigMapper.deleteByGroupId(templateGroup.getId());
         return delete;
     }
+
+    public TemplateGroup getByName(String name) {
+        return templateGroupMapper.getByName(name);
+    }
 }

+ 10 - 1
gen/src/main/resources/mybatis/TemplateGroupMapper.xml

@@ -27,7 +27,16 @@
         SELECT
         <include refid="baseColumns" />
         FROM template_group t
-        WHERE id = #{id}
+        WHERE id = #{id} AND t.is_deleted = 0
+        LIMIT 1
+    </select>
+
+    <select id="getByName" resultMap="BaseResultMap" parameterType="String">
+        SELECT
+        <include refid="baseColumns" />
+        FROM template_group t
+        WHERE group_name = #{name} AND t.is_deleted = 0
+        LIMIT 1
     </select>
 
     <!-- 插入全部字段 -->