editTable.vue 8.6 KB

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