genInfoForm.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <el-form ref="genInfoForm" :model="info" :rules="rules" label-width="150px">
  3. <el-row>
  4. <el-col :span="12">
  5. <el-form-item prop="tplCategory">
  6. <span slot="label">生成模板</span>
  7. <el-select v-model="info.tplCategory" @change="tplSelectChange">
  8. <el-option label="单表(增删改查)" value="crud" />
  9. <el-option label="树表(增删改查)" value="tree" />
  10. <el-option label="主子表(增删改查)" value="sub" />
  11. </el-select>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="12">
  15. <el-form-item prop="tplWebType">
  16. <span slot="label">前端类型</span>
  17. <el-select v-model="info.tplWebType">
  18. <el-option label="Vue2 Element UI 模版" value="element-ui" />
  19. <el-option label="Vue3 Element Plus 模版" value="element-plus" />
  20. </el-select>
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="12">
  24. <el-form-item prop="packageName">
  25. <span slot="label">
  26. 生成包路径
  27. <el-tooltip content="生成在哪个java包下,例如 com.ruoyi.system" placement="top">
  28. <i class="el-icon-question"></i>
  29. </el-tooltip>
  30. </span>
  31. <el-input v-model="info.packageName" />
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="12">
  35. <el-form-item prop="moduleName">
  36. <span slot="label">
  37. 生成模块名
  38. <el-tooltip content="可理解为子系统名,例如 system" placement="top">
  39. <i class="el-icon-question"></i>
  40. </el-tooltip>
  41. </span>
  42. <el-input v-model="info.moduleName" />
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="12">
  46. <el-form-item prop="businessName">
  47. <span slot="label">
  48. 生成业务名
  49. <el-tooltip content="可理解为功能英文名,例如 user" placement="top">
  50. <i class="el-icon-question"></i>
  51. </el-tooltip>
  52. </span>
  53. <el-input v-model="info.businessName" />
  54. </el-form-item>
  55. </el-col>
  56. <el-col :span="12">
  57. <el-form-item prop="functionName">
  58. <span slot="label">
  59. 生成功能名
  60. <el-tooltip content="用作类描述,例如 用户" placement="top">
  61. <i class="el-icon-question"></i>
  62. </el-tooltip>
  63. </span>
  64. <el-input v-model="info.functionName" />
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="12">
  68. <el-form-item prop="genType">
  69. <span slot="label">
  70. 生成代码方式
  71. <el-tooltip content="默认为zip压缩包下载,也可以自定义生成路径" placement="top">
  72. <i class="el-icon-question"></i>
  73. </el-tooltip>
  74. </span>
  75. <el-radio v-model="info.genType" label="0">zip压缩包</el-radio>
  76. <el-radio v-model="info.genType" label="1">自定义路径</el-radio>
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="12">
  80. <el-form-item>
  81. <span slot="label">
  82. 上级菜单
  83. <el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
  84. <i class="el-icon-question"></i>
  85. </el-tooltip>
  86. </span>
  87. <treeselect
  88. :append-to-body="true"
  89. v-model="info.parentMenuId"
  90. :options="menus"
  91. :normalizer="normalizer"
  92. :show-count="true"
  93. placeholder="请选择系统菜单"
  94. />
  95. </el-form-item>
  96. </el-col>
  97. <el-col :span="24" v-if="info.genType == '1'">
  98. <el-form-item prop="genPath">
  99. <span slot="label">
  100. 自定义路径
  101. <el-tooltip content="填写磁盘绝对路径,若不填写,则生成到当前Web项目下" placement="top">
  102. <i class="el-icon-question"></i>
  103. </el-tooltip>
  104. </span>
  105. <el-input v-model="info.genPath">
  106. <el-dropdown slot="append">
  107. <el-button type="primary">
  108. 最近路径快速选择
  109. <i class="el-icon-arrow-down el-icon--right"></i>
  110. </el-button>
  111. <el-dropdown-menu slot="dropdown">
  112. <el-dropdown-item @click.native="info.genPath = '/'">恢复默认的生成基础路径</el-dropdown-item>
  113. </el-dropdown-menu>
  114. </el-dropdown>
  115. </el-input>
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. <el-row v-show="info.tplCategory == 'tree'">
  120. <h4 class="form-header">其他信息</h4>
  121. <el-col :span="12">
  122. <el-form-item>
  123. <span slot="label">
  124. 树编码字段
  125. <el-tooltip content="树显示的编码字段名, 如:dept_id" placement="top">
  126. <i class="el-icon-question"></i>
  127. </el-tooltip>
  128. </span>
  129. <el-select v-model="info.treeCode" placeholder="请选择">
  130. <el-option
  131. v-for="(column, index) in info.columns"
  132. :key="index"
  133. :label="column.columnName + ':' + column.columnComment"
  134. :value="column.columnName"
  135. ></el-option>
  136. </el-select>
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="12">
  140. <el-form-item>
  141. <span slot="label">
  142. 树父编码字段
  143. <el-tooltip content="树显示的父编码字段名, 如:parent_Id" placement="top">
  144. <i class="el-icon-question"></i>
  145. </el-tooltip>
  146. </span>
  147. <el-select v-model="info.treeParentCode" placeholder="请选择">
  148. <el-option
  149. v-for="(column, index) in info.columns"
  150. :key="index"
  151. :label="column.columnName + ':' + column.columnComment"
  152. :value="column.columnName"
  153. ></el-option>
  154. </el-select>
  155. </el-form-item>
  156. </el-col>
  157. <el-col :span="12">
  158. <el-form-item>
  159. <span slot="label">
  160. 树名称字段
  161. <el-tooltip content="树节点的显示名称字段名, 如:dept_name" placement="top">
  162. <i class="el-icon-question"></i>
  163. </el-tooltip>
  164. </span>
  165. <el-select v-model="info.treeName" placeholder="请选择">
  166. <el-option
  167. v-for="(column, index) in info.columns"
  168. :key="index"
  169. :label="column.columnName + ':' + column.columnComment"
  170. :value="column.columnName"
  171. ></el-option>
  172. </el-select>
  173. </el-form-item>
  174. </el-col>
  175. </el-row>
  176. <el-row v-show="info.tplCategory == 'sub'">
  177. <h4 class="form-header">关联信息</h4>
  178. <el-col :span="12">
  179. <el-form-item>
  180. <span slot="label">
  181. 关联子表的表名
  182. <el-tooltip content="关联子表的表名, 如:sys_user" placement="top">
  183. <i class="el-icon-question"></i>
  184. </el-tooltip>
  185. </span>
  186. <el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange">
  187. <el-option
  188. v-for="(table, index) in tables"
  189. :key="index"
  190. :label="table.tableName + ':' + table.tableComment"
  191. :value="table.tableName"
  192. ></el-option>
  193. </el-select>
  194. </el-form-item>
  195. </el-col>
  196. <el-col :span="12">
  197. <el-form-item>
  198. <span slot="label">
  199. 子表关联的外键名
  200. <el-tooltip content="子表关联的外键名, 如:user_id" placement="top">
  201. <i class="el-icon-question"></i>
  202. </el-tooltip>
  203. </span>
  204. <el-select v-model="info.subTableFkName" placeholder="请选择">
  205. <el-option
  206. v-for="(column, index) in subColumns"
  207. :key="index"
  208. :label="column.columnName + ':' + column.columnComment"
  209. :value="column.columnName"
  210. ></el-option>
  211. </el-select>
  212. </el-form-item>
  213. </el-col>
  214. </el-row>
  215. </el-form>
  216. </template>
  217. <script>
  218. import Treeselect from "@riophae/vue-treeselect";
  219. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  220. export default {
  221. components: { Treeselect },
  222. props: {
  223. info: {
  224. type: Object,
  225. default: null
  226. },
  227. tables: {
  228. type: Array,
  229. default: null
  230. },
  231. menus: {
  232. type: Array,
  233. default: []
  234. },
  235. },
  236. data() {
  237. return {
  238. subColumns: [],
  239. rules: {
  240. tplCategory: [
  241. { required: true, message: "请选择生成模板", trigger: "blur" }
  242. ],
  243. packageName: [
  244. { required: true, message: "请输入生成包路径", trigger: "blur" }
  245. ],
  246. moduleName: [
  247. { required: true, message: "请输入生成模块名", trigger: "blur" }
  248. ],
  249. businessName: [
  250. { required: true, message: "请输入生成业务名", trigger: "blur" }
  251. ],
  252. functionName: [
  253. { required: true, message: "请输入生成功能名", trigger: "blur" }
  254. ],
  255. }
  256. };
  257. },
  258. watch: {
  259. 'info.subTableName': function(val) {
  260. this.setSubTableColumns(val);
  261. },
  262. 'info.tplWebType': function(val) {
  263. if (val === '') {
  264. this.info.tplWebType = "element-ui";
  265. }
  266. }
  267. },
  268. methods: {
  269. /** 转换菜单数据结构 */
  270. normalizer(node) {
  271. if (node.children && !node.children.length) {
  272. delete node.children;
  273. }
  274. return {
  275. id: node.menuId,
  276. label: node.menuName,
  277. children: node.children
  278. };
  279. },
  280. /** 选择子表名触发 */
  281. subSelectChange(value) {
  282. this.info.subTableFkName = '';
  283. },
  284. /** 选择生成模板触发 */
  285. tplSelectChange(value) {
  286. if(value !== 'sub') {
  287. this.info.subTableName = '';
  288. this.info.subTableFkName = '';
  289. }
  290. },
  291. /** 设置关联外键 */
  292. setSubTableColumns(value) {
  293. for (var item in this.tables) {
  294. const name = this.tables[item].tableName;
  295. if (value === name) {
  296. this.subColumns = this.tables[item].columns;
  297. break;
  298. }
  299. }
  300. }
  301. }
  302. };
  303. </script>