editTable.vue 8.4 KB

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