Commit b04db3d6d87b7d01c6dc37c20d02b3b416933b85
1 parent
45d20355
升级 highlight 插件的版本
Showing
6 changed files
with
117 additions
and
20 deletions
ruoyi-ui/package.json
ruoyi-ui/src/api/tool/codegen.js
0 → 100644
ruoyi-ui/src/main.js
| ... | ... | @@ -21,8 +21,8 @@ import Pagination from "@/components/Pagination"; |
| 21 | 21 | // 自定义表格工具扩展 |
| 22 | 22 | import RightToolbar from "@/components/RightToolbar" |
| 23 | 23 | // 代码高亮插件 |
| 24 | -import hljs from 'highlight.js' | |
| 25 | -import 'highlight.js/styles/github-gist.css' | |
| 24 | +// import hljs from 'highlight.js' | |
| 25 | +// import 'highlight.js/styles/github-gist.css' | |
| 26 | 26 | import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; |
| 27 | 27 | |
| 28 | 28 | // 全局方法挂载 |
| ... | ... | @@ -57,7 +57,7 @@ Vue.component('Pagination', Pagination) |
| 57 | 57 | Vue.component('RightToolbar', RightToolbar) |
| 58 | 58 | |
| 59 | 59 | Vue.use(permission) |
| 60 | -Vue.use(hljs.vuePlugin); | |
| 60 | +// Vue.use(hljs.vuePlugin); | |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * If you don't want to use mock-server | ... | ... |
ruoyi-ui/src/views/tool/gen/editTable.vue
| ... | ... | @@ -90,7 +90,8 @@ |
| 90 | 90 | <el-option label="单选框" value="radio" /> |
| 91 | 91 | <el-option label="复选框" value="checkbox" /> |
| 92 | 92 | <el-option label="日期控件" value="datetime" /> |
| 93 | - <el-option label="上传控件" value="uploadImage" /> | |
| 93 | + <el-option label="图片上传" value="imageUpload" /> | |
| 94 | + <el-option label="文件上传" value="fileUpload" /> | |
| 94 | 95 | <el-option label="富文本控件" value="editor" /> |
| 95 | 96 | </el-select> |
| 96 | 97 | </template> |
| ... | ... | @@ -112,7 +113,7 @@ |
| 112 | 113 | </el-table> |
| 113 | 114 | </el-tab-pane> |
| 114 | 115 | <el-tab-pane label="生成信息" name="genInfo"> |
| 115 | - <gen-info-form ref="genInfo" :info="info" :menus="menus"/> | |
| 116 | + <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/> | |
| 116 | 117 | </el-tab-pane> |
| 117 | 118 | </el-tabs> |
| 118 | 119 | <el-form label-width="100px"> |
| ... | ... | @@ -143,6 +144,8 @@ export default { |
| 143 | 144 | activeName: "cloum", |
| 144 | 145 | // 表格的高度 |
| 145 | 146 | tableHeight: document.documentElement.scrollHeight - 245 + "px", |
| 147 | + // 表信息 | |
| 148 | + tables: [], | |
| 146 | 149 | // 表列信息 |
| 147 | 150 | cloumns: [], |
| 148 | 151 | // 字典信息 |
| ... | ... | @@ -160,6 +163,7 @@ export default { |
| 160 | 163 | getGenTable(tableId).then(res => { |
| 161 | 164 | this.cloumns = res.data.rows; |
| 162 | 165 | this.info = res.data.info; |
| 166 | + this.tables = res.data.tables; | |
| 163 | 167 | }); |
| 164 | 168 | /** 查询字典下拉列表 */ |
| 165 | 169 | getDictOptionselect().then(response => { |
| ... | ... | @@ -167,7 +171,7 @@ export default { |
| 167 | 171 | }); |
| 168 | 172 | /** 查询菜单下拉列表 */ |
| 169 | 173 | getMenuTreeselect().then(response => { |
| 170 | - this.menus = this.handleTree(response.data, "id"); | |
| 174 | + this.menus = this.handleTree(response.data, "menuId"); | |
| 171 | 175 | }); |
| 172 | 176 | } |
| 173 | 177 | }, | ... | ... |
ruoyi-ui/src/views/tool/gen/genInfoForm.vue
| ... | ... | @@ -4,9 +4,10 @@ |
| 4 | 4 | <el-col :span="12"> |
| 5 | 5 | <el-form-item prop="tplCategory"> |
| 6 | 6 | <span slot="label">生成模板</span> |
| 7 | - <el-select v-model="info.tplCategory"> | |
| 7 | + <el-select v-model="info.tplCategory" @change="tplSelectChange"> | |
| 8 | 8 | <el-option label="单表(增删改查)" value="crud" /> |
| 9 | 9 | <el-option label="树表(增删改查)" value="tree" /> |
| 10 | + <el-option label="主子表(增删改查)" value="sub" /> | |
| 10 | 11 | </el-select> |
| 11 | 12 | </el-form-item> |
| 12 | 13 | </el-col> |
| ... | ... | @@ -126,8 +127,8 @@ |
| 126 | 127 | </span> |
| 127 | 128 | <el-select v-model="info.treeCode" placeholder="请选择"> |
| 128 | 129 | <el-option |
| 129 | - v-for="column in info.columns" | |
| 130 | - :key="column.columnName" | |
| 130 | + v-for="(column, index) in info.columns" | |
| 131 | + :key="index" | |
| 131 | 132 | :label="column.columnName + ':' + column.columnComment" |
| 132 | 133 | :value="column.columnName" |
| 133 | 134 | ></el-option> |
| ... | ... | @@ -144,8 +145,8 @@ |
| 144 | 145 | </span> |
| 145 | 146 | <el-select v-model="info.treeParentCode" placeholder="请选择"> |
| 146 | 147 | <el-option |
| 147 | - v-for="column in info.columns" | |
| 148 | - :key="column.columnName" | |
| 148 | + v-for="(column, index) in info.columns" | |
| 149 | + :key="index" | |
| 149 | 150 | :label="column.columnName + ':' + column.columnComment" |
| 150 | 151 | :value="column.columnName" |
| 151 | 152 | ></el-option> |
| ... | ... | @@ -162,8 +163,47 @@ |
| 162 | 163 | </span> |
| 163 | 164 | <el-select v-model="info.treeName" placeholder="请选择"> |
| 164 | 165 | <el-option |
| 165 | - v-for="column in info.columns" | |
| 166 | - :key="column.columnName" | |
| 166 | + v-for="(column, index) in info.columns" | |
| 167 | + :key="index" | |
| 168 | + :label="column.columnName + ':' + column.columnComment" | |
| 169 | + :value="column.columnName" | |
| 170 | + ></el-option> | |
| 171 | + </el-select> | |
| 172 | + </el-form-item> | |
| 173 | + </el-col> | |
| 174 | + </el-row> | |
| 175 | + <el-row v-show="info.tplCategory == 'sub'"> | |
| 176 | + <h4 class="form-header">关联信息</h4> | |
| 177 | + <el-col :span="12"> | |
| 178 | + <el-form-item> | |
| 179 | + <span slot="label"> | |
| 180 | + 关联子表的表名 | |
| 181 | + <el-tooltip content="关联子表的表名, 如:sys_user" placement="top"> | |
| 182 | + <i class="el-icon-question"></i> | |
| 183 | + </el-tooltip> | |
| 184 | + </span> | |
| 185 | + <el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange"> | |
| 186 | + <el-option | |
| 187 | + v-for="(table, index) in tables" | |
| 188 | + :key="index" | |
| 189 | + :label="table.tableName + ':' + table.tableComment" | |
| 190 | + :value="table.tableName" | |
| 191 | + ></el-option> | |
| 192 | + </el-select> | |
| 193 | + </el-form-item> | |
| 194 | + </el-col> | |
| 195 | + <el-col :span="12"> | |
| 196 | + <el-form-item> | |
| 197 | + <span slot="label"> | |
| 198 | + 子表关联的外键名 | |
| 199 | + <el-tooltip content="子表关联的外键名, 如:user_id" placement="top"> | |
| 200 | + <i class="el-icon-question"></i> | |
| 201 | + </el-tooltip> | |
| 202 | + </span> | |
| 203 | + <el-select v-model="info.subTableFkName" placeholder="请选择"> | |
| 204 | + <el-option | |
| 205 | + v-for="(column, index) in subColumns" | |
| 206 | + :key="index" | |
| 167 | 207 | :label="column.columnName + ':' + column.columnComment" |
| 168 | 208 | :value="column.columnName" |
| 169 | 209 | ></el-option> |
| ... | ... | @@ -185,6 +225,10 @@ export default { |
| 185 | 225 | type: Object, |
| 186 | 226 | default: null |
| 187 | 227 | }, |
| 228 | + tables: { | |
| 229 | + type: Array, | |
| 230 | + default: null | |
| 231 | + }, | |
| 188 | 232 | menus: { |
| 189 | 233 | type: Array, |
| 190 | 234 | default: [] |
| ... | ... | @@ -192,6 +236,7 @@ export default { |
| 192 | 236 | }, |
| 193 | 237 | data() { |
| 194 | 238 | return { |
| 239 | + subColumns: [], | |
| 195 | 240 | rules: { |
| 196 | 241 | tplCategory: [ |
| 197 | 242 | { required: true, message: "请选择生成模板", trigger: "blur" } |
| ... | ... | @@ -212,6 +257,11 @@ export default { |
| 212 | 257 | }; |
| 213 | 258 | }, |
| 214 | 259 | created() {}, |
| 260 | + watch: { | |
| 261 | + 'info.subTableName': function(val) { | |
| 262 | + this.setSubTableColumns(val); | |
| 263 | + } | |
| 264 | + }, | |
| 215 | 265 | methods: { |
| 216 | 266 | /** 转换菜单数据结构 */ |
| 217 | 267 | normalizer(node) { |
| ... | ... | @@ -219,10 +269,31 @@ export default { |
| 219 | 269 | delete node.children; |
| 220 | 270 | } |
| 221 | 271 | return { |
| 222 | - id: node.id, | |
| 223 | - label: node.name, | |
| 272 | + id: node.menuId, | |
| 273 | + label: node.menuName, | |
| 224 | 274 | children: node.children |
| 225 | 275 | }; |
| 276 | + }, | |
| 277 | + /** 选择子表名触发 */ | |
| 278 | + subSelectChange(value) { | |
| 279 | + this.info.subTableFkName = ''; | |
| 280 | + }, | |
| 281 | + /** 选择生成模板触发 */ | |
| 282 | + tplSelectChange(value) { | |
| 283 | + if(value !== 'sub') { | |
| 284 | + this.info.subTableName = ''; | |
| 285 | + this.info.subTableFkName = ''; | |
| 286 | + } | |
| 287 | + }, | |
| 288 | + /** 设置关联外键 */ | |
| 289 | + setSubTableColumns(value) { | |
| 290 | + for (var item in this.tables) { | |
| 291 | + const name = this.tables[item].tableName; | |
| 292 | + if (value === name) { | |
| 293 | + this.subColumns = this.tables[item].columns; | |
| 294 | + break; | |
| 295 | + } | |
| 296 | + } | |
| 226 | 297 | } |
| 227 | 298 | } |
| 228 | 299 | }; | ... | ... |
ruoyi-ui/src/views/tool/gen/index.vue
| ... | ... | @@ -32,7 +32,7 @@ |
| 32 | 32 | ></el-date-picker> |
| 33 | 33 | </el-form-item> |
| 34 | 34 | <el-form-item> |
| 35 | - <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | |
| 35 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | |
| 36 | 36 | <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> |
| 37 | 37 | </el-form-item> |
| 38 | 38 | </el-form> |
| ... | ... | @@ -41,6 +41,7 @@ |
| 41 | 41 | <el-col :span="1.5"> |
| 42 | 42 | <el-button |
| 43 | 43 | type="primary" |
| 44 | + plain | |
| 44 | 45 | icon="el-icon-download" |
| 45 | 46 | size="mini" |
| 46 | 47 | @click="handleGenTable" |
| ... | ... | @@ -50,6 +51,7 @@ |
| 50 | 51 | <el-col :span="1.5"> |
| 51 | 52 | <el-button |
| 52 | 53 | type="info" |
| 54 | + plain | |
| 53 | 55 | icon="el-icon-upload" |
| 54 | 56 | size="mini" |
| 55 | 57 | @click="openImportTable" |
| ... | ... | @@ -59,6 +61,7 @@ |
| 59 | 61 | <el-col :span="1.5"> |
| 60 | 62 | <el-button |
| 61 | 63 | type="success" |
| 64 | + plain | |
| 62 | 65 | icon="el-icon-edit" |
| 63 | 66 | size="mini" |
| 64 | 67 | :disabled="single" |
| ... | ... | @@ -69,6 +72,7 @@ |
| 69 | 72 | <el-col :span="1.5"> |
| 70 | 73 | <el-button |
| 71 | 74 | type="danger" |
| 75 | + plain | |
| 72 | 76 | icon="el-icon-delete" |
| 73 | 77 | size="mini" |
| 74 | 78 | :disabled="multiple" |
| ... | ... | @@ -80,7 +84,7 @@ |
| 80 | 84 | </el-row> |
| 81 | 85 | |
| 82 | 86 | <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange"> |
| 83 | - <el-table-column type="selection" width="55"></el-table-column> | |
| 87 | + <el-table-column type="selection" align="center" width="55"></el-table-column> | |
| 84 | 88 | <el-table-column label="序号" type="index" width="50" align="center"> |
| 85 | 89 | <template slot-scope="scope"> |
| 86 | 90 | <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span> |
| ... | ... | @@ -165,7 +169,7 @@ |
| 165 | 169 | :name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" |
| 166 | 170 | :key="key" |
| 167 | 171 | > |
| 168 | - <highlightjs autodetect :code="value" /> | |
| 172 | + <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre> | |
| 169 | 173 | </el-tab-pane> |
| 170 | 174 | </el-tabs> |
| 171 | 175 | </el-dialog> |
| ... | ... | @@ -177,6 +181,15 @@ |
| 177 | 181 | import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen"; |
| 178 | 182 | import importTable from "./importTable"; |
| 179 | 183 | import { downLoadZip } from "@/utils/zipdownload"; |
| 184 | +// 代码高亮插件 | |
| 185 | +import hljs from "highlight.js/lib/highlight"; | |
| 186 | +import "highlight.js/styles/github-gist.css"; | |
| 187 | +hljs.registerLanguage("java", require("highlight.js/lib/languages/java")); | |
| 188 | +hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml")); | |
| 189 | +hljs.registerLanguage("html", require("highlight.js/lib/languages/xml")); | |
| 190 | +hljs.registerLanguage("vue", require("highlight.js/lib/languages/xml")); | |
| 191 | +hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript")); | |
| 192 | +hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql")); | |
| 180 | 193 | |
| 181 | 194 | export default { |
| 182 | 195 | name: "Gen", |
| ... | ... | @@ -290,6 +303,13 @@ export default { |
| 290 | 303 | this.preview.open = true; |
| 291 | 304 | }); |
| 292 | 305 | }, |
| 306 | + /** 高亮显示 */ | |
| 307 | + highlightedCode(code, key) { | |
| 308 | + const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm")); | |
| 309 | + var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length); | |
| 310 | + const result = hljs.highlight(language, code || "", true); | |
| 311 | + return result.value || ' '; | |
| 312 | + }, | |
| 293 | 313 | // 多选框选中数据 |
| 294 | 314 | handleSelectionChange(selection) { |
| 295 | 315 | this.ids = selection.map(item => item.tableId); |
| ... | ... | @@ -318,4 +338,4 @@ export default { |
| 318 | 338 | } |
| 319 | 339 | } |
| 320 | 340 | }; |
| 321 | -</script> | |
| 322 | 341 | \ No newline at end of file |
| 342 | +</script> | ... | ... |