¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> |
| | | <el-form-item label="表åç§°" prop="tableName"> |
| | | <el-input |
| | | v-model="queryParams.tableName" |
| | | placeholder="请è¾å
¥è¡¨åç§°" |
| | | clearable |
| | | size="small" |
| | | @keyup.enter.native="handleQuery" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="表æè¿°" prop="tableComment"> |
| | | <el-input |
| | | v-model="queryParams.tableComment" |
| | | placeholder="请è¾å
¥è¡¨æè¿°" |
| | | clearable |
| | | size="small" |
| | | @keyup.enter.native="handleQuery" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="å建æ¶é´"> |
| | | <el-date-picker |
| | | v-model="dateRange" |
| | | size="small" |
| | | style="width: 240px" |
| | | value-format="yyyy-MM-dd" |
| | | type="daterange" |
| | | range-separator="-" |
| | | start-placeholder="å¼å§æ¥æ" |
| | | end-placeholder="ç»ææ¥æ" |
| | | ></el-date-picker> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">æç´¢</el-button> |
| | | <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">éç½®</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <el-row :gutter="10" class="mb8"> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="primary" |
| | | plain |
| | | icon="el-icon-download" |
| | | size="mini" |
| | | @click="handleGenTable" |
| | | v-hasPermi="['tool:gen:code']" |
| | | >çæ</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="info" |
| | | plain |
| | | icon="el-icon-upload" |
| | | size="mini" |
| | | @click="openImportTable" |
| | | v-hasPermi="['tool:gen:import']" |
| | | >导å
¥</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="success" |
| | | plain |
| | | icon="el-icon-edit" |
| | | size="mini" |
| | | :disabled="single" |
| | | @click="handleEditTable" |
| | | v-hasPermi="['tool:gen:edit']" |
| | | >ä¿®æ¹</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="danger" |
| | | plain |
| | | icon="el-icon-delete" |
| | | size="mini" |
| | | :disabled="multiple" |
| | | @click="handleDelete" |
| | | v-hasPermi="['tool:gen:remove']" |
| | | >å é¤</el-button> |
| | | </el-col> |
| | | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| | | </el-row> |
| | | |
| | | <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange"> |
| | | <el-table-column type="selection" align="center" width="55"></el-table-column> |
| | | <el-table-column label="åºå·" type="index" width="50" align="center"> |
| | | <template slot-scope="scope"> |
| | | <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column |
| | | label="表åç§°" |
| | | align="center" |
| | | prop="tableName" |
| | | :show-overflow-tooltip="true" |
| | | width="120" |
| | | /> |
| | | <el-table-column |
| | | label="表æè¿°" |
| | | align="center" |
| | | prop="tableComment" |
| | | :show-overflow-tooltip="true" |
| | | width="120" |
| | | /> |
| | | <el-table-column |
| | | label="å®ä½" |
| | | align="center" |
| | | prop="className" |
| | | :show-overflow-tooltip="true" |
| | | width="120" |
| | | /> |
| | | <el-table-column label="å建æ¶é´" align="center" prop="createTime" width="160" /> |
| | | <el-table-column label="æ´æ°æ¶é´" align="center" prop="updateTime" width="160" /> |
| | | <el-table-column label="æä½" align="center" class-name="small-padding fixed-width"> |
| | | <template slot-scope="scope"> |
| | | <el-button |
| | | type="text" |
| | | size="small" |
| | | icon="el-icon-view" |
| | | @click="handlePreview(scope.row)" |
| | | v-hasPermi="['tool:gen:preview']" |
| | | >é¢è§</el-button> |
| | | <el-button |
| | | type="text" |
| | | size="small" |
| | | icon="el-icon-edit" |
| | | @click="handleEditTable(scope.row)" |
| | | v-hasPermi="['tool:gen:edit']" |
| | | >ç¼è¾</el-button> |
| | | <el-button |
| | | type="text" |
| | | size="small" |
| | | icon="el-icon-delete" |
| | | @click="handleDelete(scope.row)" |
| | | v-hasPermi="['tool:gen:remove']" |
| | | >å é¤</el-button> |
| | | <el-button |
| | | type="text" |
| | | size="small" |
| | | icon="el-icon-refresh" |
| | | @click="handleSynchDb(scope.row)" |
| | | v-hasPermi="['tool:gen:edit']" |
| | | >忥</el-button> |
| | | <el-button |
| | | type="text" |
| | | size="small" |
| | | icon="el-icon-download" |
| | | @click="handleGenTable(scope.row)" |
| | | v-hasPermi="['tool:gen:code']" |
| | | >çæä»£ç </el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <pagination |
| | | v-show="total>0" |
| | | :total="total" |
| | | :page.sync="queryParams.pageNum" |
| | | :limit.sync="queryParams.pageSize" |
| | | @pagination="getList" |
| | | /> |
| | | <!-- é¢è§çé¢ --> |
| | | <el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body class="scrollbar"> |
| | | <el-tabs v-model="preview.activeName"> |
| | | <el-tab-pane |
| | | v-for="(value, key) in preview.data" |
| | | :label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" |
| | | :name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" |
| | | :key="key" |
| | | > |
| | | <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre> |
| | | </el-tab-pane> |
| | | </el-tabs> |
| | | </el-dialog> |
| | | <import-table ref="import" @ok="handleQuery" /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen"; |
| | | import importTable from "./importTable"; |
| | | import { downLoadZip } from "@/utils/download"; |
| | | import hljs from "highlight.js/lib/highlight"; |
| | | import "highlight.js/styles/github-gist.css"; |
| | | hljs.registerLanguage("java", require("highlight.js/lib/languages/java")); |
| | | hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml")); |
| | | hljs.registerLanguage("html", require("highlight.js/lib/languages/xml")); |
| | | hljs.registerLanguage("vue", require("highlight.js/lib/languages/xml")); |
| | | hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript")); |
| | | hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql")); |
| | | |
| | | export default { |
| | | name: "Gen", |
| | | components: { importTable }, |
| | | data() { |
| | | return { |
| | | // é®ç½©å± |
| | | loading: true, |
| | | // å¯ä¸æ è¯ç¬¦ |
| | | uniqueId: "", |
| | | // é䏿°ç» |
| | | ids: [], |
| | | // éä¸è¡¨æ°ç» |
| | | tableNames: [], |
| | | // éå个ç¦ç¨ |
| | | single: true, |
| | | // éå¤ä¸ªç¦ç¨ |
| | | multiple: true, |
| | | // æ¾ç¤ºæç´¢æ¡ä»¶ |
| | | showSearch: true, |
| | | // æ»æ¡æ° |
| | | total: 0, |
| | | // è¡¨æ°æ® |
| | | tableList: [], |
| | | // æ¥æèå´ |
| | | dateRange: "", |
| | | // æ¥è¯¢åæ° |
| | | queryParams: { |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | tableName: undefined, |
| | | tableComment: undefined |
| | | }, |
| | | // é¢è§åæ° |
| | | preview: { |
| | | open: false, |
| | | title: "代ç é¢è§", |
| | | data: {}, |
| | | activeName: "domain.java" |
| | | } |
| | | }; |
| | | }, |
| | | created() { |
| | | this.getList(); |
| | | }, |
| | | activated() { |
| | | const time = this.$route.query.t; |
| | | if (time != null && time != this.uniqueId) { |
| | | this.uniqueId = time; |
| | | this.queryParams.pageNum = Number(this.$route.query.pageNum); |
| | | this.getList(); |
| | | } |
| | | }, |
| | | methods: { |
| | | /** æ¥è¯¢è¡¨éå */ |
| | | getList() { |
| | | this.loading = true; |
| | | listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => { |
| | | this.tableList = response.rows; |
| | | this.total = response.total; |
| | | this.loading = false; |
| | | } |
| | | ); |
| | | }, |
| | | /** æç´¢æé®æä½ */ |
| | | handleQuery() { |
| | | this.queryParams.pageNum = 1; |
| | | this.getList(); |
| | | }, |
| | | /** çæä»£ç æä½ */ |
| | | handleGenTable(row) { |
| | | const tableNames = row.tableName || this.tableNames; |
| | | if (tableNames == "") { |
| | | this.msgError("è¯·éæ©è¦çæçæ°æ®"); |
| | | return; |
| | | } |
| | | if(row.genType === "1") { |
| | | genCode(row.tableName).then(response => { |
| | | this.msgSuccess("æåçæå°èªå®ä¹è·¯å¾ï¼" + row.genPath); |
| | | }); |
| | | } else { |
| | | downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi"); |
| | | } |
| | | }, |
| | | /** åæ¥æ°æ®åºæä½ */ |
| | | handleSynchDb(row) { |
| | | const tableName = row.tableName; |
| | | this.$confirm('确认è¦å¼ºå¶åæ¥"' + tableName + '"è¡¨ç»æåï¼', "è¦å", { |
| | | confirmButtonText: "ç¡®å®", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning" |
| | | }).then(function() { |
| | | return synchDb(tableName); |
| | | }).then(() => { |
| | | this.msgSuccess("忥æå"); |
| | | }).catch(() => {}); |
| | | }, |
| | | /** æå¼å¯¼å
¥è¡¨å¼¹çª */ |
| | | openImportTable() { |
| | | this.$refs.import.show(); |
| | | }, |
| | | /** éç½®æé®æä½ */ |
| | | resetQuery() { |
| | | this.dateRange = []; |
| | | this.resetForm("queryForm"); |
| | | this.handleQuery(); |
| | | }, |
| | | /** é¢è§æé® */ |
| | | handlePreview(row) { |
| | | previewTable(row.tableId).then(response => { |
| | | this.preview.data = response.data; |
| | | this.preview.open = true; |
| | | }); |
| | | }, |
| | | /** é«äº®æ¾ç¤º */ |
| | | highlightedCode(code, key) { |
| | | const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm")); |
| | | var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length); |
| | | const result = hljs.highlight(language, code || "", true); |
| | | return result.value || ' '; |
| | | }, |
| | | // å¤éæ¡é䏿°æ® |
| | | handleSelectionChange(selection) { |
| | | this.ids = selection.map(item => item.tableId); |
| | | this.tableNames = selection.map(item => item.tableName); |
| | | this.single = selection.length != 1; |
| | | this.multiple = !selection.length; |
| | | }, |
| | | /** ä¿®æ¹æé®æä½ */ |
| | | handleEditTable(row) { |
| | | const tableId = row.tableId || this.ids[0]; |
| | | this.$router.push({ path: '/tool/gen-edit/index', query: { tableId: tableId, pageNum: this.queryParams.pageNum } }); |
| | | }, |
| | | /** å é¤æé®æä½ */ |
| | | handleDelete(row) { |
| | | const tableIds = row.tableId || this.ids; |
| | | this.$confirm('æ¯å¦ç¡®è®¤å é¤è¡¨ç¼å·ä¸º"' + tableIds + '"çæ°æ®é¡¹?', "è¦å", { |
| | | confirmButtonText: "ç¡®å®", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning" |
| | | }).then(function() { |
| | | return delTable(tableIds); |
| | | }).then(() => { |
| | | this.getList(); |
| | | this.msgSuccess("å 餿å"); |
| | | }).catch(() => {}); |
| | | } |
| | | } |
| | | }; |
| | | </script> |