editTable.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <el-card>
  3. <el-tabs v-model="activeName">
  4. <el-tab-pane label="基本信息" name="basic">
  5. <basic-info-form ref="basicInfo" :info="info" />
  6. </el-tab-pane>
  7. <el-tab-pane label="字段信息" name="cloum">
  8. <el-table ref="dragTable" :data="cloumns" row-key="columnId" :max-height="tableHeight">
  9. <el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" />
  10. <el-table-column
  11. label="字段列名"
  12. prop="columnName"
  13. min-width="10%"
  14. :show-overflow-tooltip="true"
  15. />
  16. <el-table-column label="字段描述" min-width="10%">
  17. <template slot-scope="scope">
  18. <el-input v-model="scope.row.columnComment"></el-input>
  19. </template>
  20. </el-table-column>
  21. <el-table-column
  22. label="物理类型"
  23. prop="columnType"
  24. min-width="10%"
  25. :show-overflow-tooltip="true"
  26. />
  27. <el-table-column label="Java类型" min-width="11%">
  28. <template slot-scope="scope">
  29. <el-select v-model="scope.row.javaType">
  30. <el-option label="Long" value="Long" />
  31. <el-option label="String" value="String" />
  32. <el-option label="Integer" value="Integer" />
  33. <el-option label="Double" value="Double" />
  34. <el-option label="BigDecimal" value="BigDecimal" />
  35. <el-option label="Date" value="Date" />
  36. </el-select>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="java属性" min-width="10%">
  40. <template slot-scope="scope">
  41. <el-input v-model="scope.row.javaField"></el-input>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="插入" min-width="5%">
  45. <template slot-scope="scope">
  46. <el-checkbox true-label="1" v-model="scope.row.isInsert"></el-checkbox>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="编辑" min-width="5%">
  50. <template slot-scope="scope">
  51. <el-checkbox true-label="1" v-model="scope.row.isEdit"></el-checkbox>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="列表" min-width="5%">
  55. <template slot-scope="scope">
  56. <el-checkbox true-label="1" v-model="scope.row.isList"></el-checkbox>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="查询" min-width="5%">
  60. <template slot-scope="scope">
  61. <el-checkbox true-label="1" v-model="scope.row.isQuery"></el-checkbox>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="查询方式" min-width="10%">
  65. <template slot-scope="scope">
  66. <el-select v-model="scope.row.queryType">
  67. <el-option label="=" value="EQ" />
  68. <el-option label="!=" value="NE" />
  69. <el-option label=">" value="GT" />
  70. <el-option label=">=" value="GTE" />
  71. <el-option label="<" value="LT" />
  72. <el-option label="<=" value="LTE" />
  73. <el-option label="LIKE" value="LIKE" />
  74. <el-option label="BETWEEN" value="BETWEEN" />
  75. </el-select>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="必填" min-width="5%">
  79. <template slot-scope="scope">
  80. <el-checkbox true-label="1" v-model="scope.row.isRequired"></el-checkbox>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="显示类型" min-width="12%">
  84. <template slot-scope="scope">
  85. <el-select v-model="scope.row.htmlType">
  86. <el-option label="文本框" value="input" />
  87. <el-option label="文本域" value="textarea" />
  88. <el-option label="下拉框" value="select" />
  89. <el-option label="单选框" value="radio" />
  90. <el-option label="复选框" value="checkbox" />
  91. <el-option label="日期控件" value="datetime" />
  92. <el-option label="图片上传" value="imageUpload" />
  93. <el-option label="文件上传" value="fileUpload" />
  94. <el-option label="富文本控件" value="editor" />
  95. </el-select>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="字典类型" min-width="12%">
  99. <template slot-scope="scope">
  100. <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
  101. <el-option
  102. v-for="dict in dictOptions"
  103. :key="dict.dictType"
  104. :label="dict.dictName"
  105. :value="dict.dictType">
  106. <span style="float: left">{{ dict.dictName }}</span>
  107. <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
  108. </el-option>
  109. </el-select>
  110. </template>
  111. </el-table-column>
  112. </el-table>
  113. </el-tab-pane>
  114. <el-tab-pane label="生成信息" name="genInfo">
  115. <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/>
  116. </el-tab-pane>
  117. </el-tabs>
  118. <el-form label-width="100px">
  119. <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
  120. <el-button type="primary" @click="submitForm()">提交</el-button>
  121. <el-button @click="close()">返回</el-button>
  122. </el-form-item>
  123. </el-form>
  124. </el-card>
  125. </template>
  126. <script>
  127. import { getGenTable, updateGenTable } from "@/api/tool/gen";
  128. import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
  129. import { listMenu as getMenuTreeselect } from "@/api/system/menu";
  130. import basicInfoForm from "./basicInfoForm";
  131. import genInfoForm from "./genInfoForm";
  132. import Sortable from 'sortablejs'
  133. export default {
  134. name: "GenEdit",
  135. components: {
  136. basicInfoForm,
  137. genInfoForm
  138. },
  139. data() {
  140. return {
  141. // 选中选项卡的 name
  142. activeName: "cloum",
  143. // 表格的高度
  144. tableHeight: document.documentElement.scrollHeight - 245 + "px",
  145. // 表信息
  146. tables: [],
  147. // 表列信息
  148. cloumns: [],
  149. // 字典信息
  150. dictOptions: [],
  151. // 菜单信息
  152. menus: [],
  153. // 表详细信息
  154. info: {}
  155. };
  156. },
  157. created() {
  158. const tableId = this.$route.query && this.$route.query.tableId;
  159. if (tableId) {
  160. // 获取表详细信息
  161. getGenTable(tableId).then(res => {
  162. this.cloumns = res.data.rows;
  163. this.info = res.data.info;
  164. this.tables = res.data.tables;
  165. });
  166. /** 查询字典下拉列表 */
  167. getDictOptionselect().then(response => {
  168. this.dictOptions = response.data;
  169. });
  170. /** 查询菜单下拉列表 */
  171. getMenuTreeselect().then(response => {
  172. this.menus = this.handleTree(response.data, "menuId");
  173. });
  174. }
  175. },
  176. methods: {
  177. /** 提交按钮 */
  178. submitForm() {
  179. const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
  180. const genForm = this.$refs.genInfo.$refs.genInfoForm;
  181. Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
  182. const validateResult = res.every(item => !!item);
  183. if (validateResult) {
  184. const genTable = Object.assign({}, basicForm.model, genForm.model);
  185. genTable.columns = this.cloumns;
  186. genTable.params = {
  187. treeCode: genTable.treeCode,
  188. treeName: genTable.treeName,
  189. treeParentCode: genTable.treeParentCode,
  190. parentMenuId: genTable.parentMenuId
  191. };
  192. updateGenTable(genTable).then(res => {
  193. this.msgSuccess(res.msg);
  194. if (res.code === 200) {
  195. this.close();
  196. }
  197. });
  198. } else {
  199. this.msgError("表单校验未通过,请重新检查提交内容");
  200. }
  201. });
  202. },
  203. getFormPromise(form) {
  204. return new Promise(resolve => {
  205. form.validate(res => {
  206. resolve(res);
  207. });
  208. });
  209. },
  210. /** 关闭按钮 */
  211. close() {
  212. this.$store.dispatch("tagsView/delView", this.$route);
  213. this.$router.push({ path: "/tool/gen", query: { t: Date.now(), pageNum: this.$route.query.pageNum } })
  214. }
  215. },
  216. mounted() {
  217. const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
  218. const sortable = Sortable.create(el, {
  219. handle: ".allowDrag",
  220. onEnd: evt => {
  221. const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
  222. this.cloumns.splice(evt.newIndex, 0, targetRow);
  223. for (let index in this.cloumns) {
  224. this.cloumns[index].sort = parseInt(index) + 1;
  225. }
  226. }
  227. });
  228. }
  229. };
  230. </script>