editTable.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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="editor" />
  93. </el-select>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="字典类型" min-width="12%">
  97. <template slot-scope="scope">
  98. <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
  99. <el-option
  100. v-for="dict in dictOptions"
  101. :key="dict.dictType"
  102. :label="dict.dictName"
  103. :value="dict.dictType">
  104. <span style="float: left">{{ dict.dictName }}</span>
  105. <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
  106. </el-option>
  107. </el-select>
  108. </template>
  109. </el-table-column>
  110. </el-table>
  111. </el-tab-pane>
  112. <el-tab-pane label="生成信息" name="genInfo">
  113. <gen-info-form ref="genInfo" :info="info" :menus="menus"/>
  114. </el-tab-pane>
  115. </el-tabs>
  116. <el-form label-width="100px">
  117. <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
  118. <el-button type="primary" @click="submitForm()">提交</el-button>
  119. <el-button @click="close()">返回</el-button>
  120. </el-form-item>
  121. </el-form>
  122. </el-card>
  123. </template>
  124. <script>
  125. import { getGenTable, updateGenTable } from "@/api/tool/gen";
  126. import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
  127. import { listMenu as getMenuTreeselect } from "@/api/system/menu";
  128. import basicInfoForm from "./basicInfoForm";
  129. import genInfoForm from "./genInfoForm";
  130. import Sortable from 'sortablejs'
  131. export default {
  132. name: "GenEdit",
  133. components: {
  134. basicInfoForm,
  135. genInfoForm
  136. },
  137. data() {
  138. return {
  139. // 选中选项卡的 name
  140. activeName: "cloum",
  141. // 表格的高度
  142. tableHeight: document.documentElement.scrollHeight - 245 + "px",
  143. // 表列信息
  144. cloumns: [],
  145. // 字典信息
  146. dictOptions: [],
  147. // 菜单信息
  148. menus: [],
  149. // 表详细信息
  150. info: {}
  151. };
  152. },
  153. created() {
  154. const tableId = this.$route.params && this.$route.params.tableId;
  155. if (tableId) {
  156. // 获取表详细信息
  157. getGenTable(tableId).then(res => {
  158. this.cloumns = res.data.rows;
  159. this.info = res.data.info;
  160. });
  161. /** 查询字典下拉列表 */
  162. getDictOptionselect().then(response => {
  163. this.dictOptions = response.data;
  164. });
  165. /** 查询菜单下拉列表 */
  166. getMenuTreeselect().then(response => {
  167. this.menus = this.handleTree(response.data, "menuId");
  168. });
  169. }
  170. },
  171. methods: {
  172. /** 提交按钮 */
  173. submitForm() {
  174. const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
  175. const genForm = this.$refs.genInfo.$refs.genInfoForm;
  176. Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
  177. const validateResult = res.every(item => !!item);
  178. if (validateResult) {
  179. const genTable = Object.assign({}, basicForm.model, genForm.model);
  180. genTable.columns = this.cloumns;
  181. genTable.params = {
  182. treeCode: genTable.treeCode,
  183. treeName: genTable.treeName,
  184. treeParentCode: genTable.treeParentCode,
  185. parentMenuId: genTable.parentMenuId
  186. };
  187. updateGenTable(genTable).then(res => {
  188. this.msgSuccess(res.msg);
  189. if (res.code === 200) {
  190. this.close();
  191. }
  192. });
  193. } else {
  194. this.msgError("表单校验未通过,请重新检查提交内容");
  195. }
  196. });
  197. },
  198. getFormPromise(form) {
  199. return new Promise(resolve => {
  200. form.validate(res => {
  201. resolve(res);
  202. });
  203. });
  204. },
  205. /** 关闭按钮 */
  206. close() {
  207. this.$store.dispatch("tagsView/delView", this.$route);
  208. this.$router.push({ path: "/tool/gen", query: { t: Date.now()}})
  209. }
  210. },
  211. mounted() {
  212. const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
  213. const sortable = Sortable.create(el, {
  214. handle: ".allowDrag",
  215. onEnd: evt => {
  216. const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
  217. this.cloumns.splice(evt.newIndex, 0, targetRow);
  218. for (let index in this.cloumns) {
  219. this.cloumns[index].sort = parseInt(index) + 1;
  220. }
  221. }
  222. });
  223. }
  224. };
  225. </script>