editTable.vue 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. <template>
  2. <el-card>
  3. <el-row type="flex" justify="space-between">
  4. <el-col :span="1.5" style="display: flex; align-items: center;">
  5. <el-form label-width="100px" style="display: flex; align-items: center;">
  6. <el-form-item style="text-align: center;margin: 0 0 0 -100px;">
  7. <el-button size="mini" type="primary" v-if="activeName=='basic' || activeName=='cloum'" @click="submitForm()">保存</el-button>
  8. <el-button size="mini" @click="close()">返回</el-button>
  9. </el-form-item>
  10. </el-form>
  11. </el-col>
  12. </el-row>
  13. <el-tabs v-model="activeName">
  14. <el-tab-pane label="基本信息" name="basic">
  15. <basic-info-form ref="basicInfo" :info="info" />
  16. </el-tab-pane>
  17. <el-tab-pane label="字段信息" name="cloum">
  18. <el-row type="flex" style="margin-bottom: 20px;" v-if="activeName=='cloum'" :gutter="10" justify="end">
  19. <el-col :span="1.5" style="display: flex; align-items: center;">
  20. <el-button style="background-color: #FFE9ED;color: #E58481;border: 1px solid #E58481;" type="warning" plain
  21. icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:post:add']">新增</el-button>
  22. </el-col>
  23. <el-col :span="1.5" style="display: flex; align-items: center;">
  24. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  25. v-hasPermi="['system:post:remove']" style="background-color: #FFD6B0;color: #EA551A;border: 1px solid #F4AD6B;">删除</el-button>
  26. </el-col>
  27. <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
  28. </el-row>
  29. <el-table ref="dragTable" @row-dblclick="dbSelectedZd" align="center" :data="cloumns" row-key="columnId"
  30. :max-height="tableHeight" @selection-change="handleSelectionChange">
  31. <el-table-column type="selection" width="55" align="center" />
  32. <el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" align="center" />
  33. <el-table-column label="字段列名" prop="columnName" min-width="10%" :show-overflow-tooltip="true" align="center" />
  34. <el-table-column label="字段描述" min-width="10%" align="center">
  35. <template slot-scope="scope">
  36. <el-input v-model="scope.row.columnComment"></el-input>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="物理类型" prop="columnType" align="center" min-width="10%" :show-overflow-tooltip="true" />
  40. <el-table-column label="字段显示规则" align="center" prop="mask" min-width="13%" />
  41. <el-table-column label="排序" min-width="8%" align="center" prop="sort" />
  42. <el-table-column label="输入字段" min-width="10%" align="center">
  43. <template slot-scope="scope">
  44. <el-checkbox true-label="Y" false-label="N" v-model="scope.row.isIn"></el-checkbox>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="显示字段" min-width="10%" align="center">
  48. <template slot-scope="scope">
  49. <el-checkbox true-label="Y" false-label="N" v-model="scope.row.isOut"></el-checkbox>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="查询" min-width="8%" align="center">
  53. <template slot-scope="scope">
  54. <el-checkbox true-label="1" false-label="0" v-model="scope.row.isQuery"></el-checkbox>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="关联HR字段" min-width="13%" align="center" prop="hrParentId">
  58. <template slot-scope="scope">
  59. <div>
  60. {{scope.row.hrParentId | zdFn}}
  61. </div>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="缺省值" min-width="10%" align="center" prop="defaultValue" />
  65. <el-table-column label="外键" min-width="10%" align="center" prop="foreignKey">
  66. <template slot-scope="scope">
  67. <div>
  68. {{scope.row.foreignKey | zdFn}}
  69. </div>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="必填" min-width="8%" align="center">
  73. <template slot-scope="scope">
  74. <el-checkbox true-label="1" false-label="0" v-model="scope.row.isRequired"></el-checkbox>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="显示类型" min-width="12%" align="center">
  78. <template slot-scope="scope">
  79. <el-select v-model="scope.row.htmlType">
  80. <el-option label="文本框" value="input" />
  81. <el-option label="文本域" value="textarea" />
  82. <el-option label="下拉框" value="select" />
  83. <el-option label="单选框" value="radio" />
  84. <el-option label="复选框" value="checkbox" />
  85. <el-option label="日期控件" value="datetime" />
  86. <el-option label="图片上传" value="imageUpload" />
  87. <el-option label="文件上传" value="fileUpload" />
  88. <el-option label="富文本控件" value="editor" />
  89. <el-option label="hr" value="hr" />
  90. </el-select>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="字典类型" min-width="12%" align="center">
  94. <template slot-scope="scope">
  95. <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
  96. <el-option v-for="dict in dictOptions" :key="dict.dictType" :label="dict.dictName" :value="dict.dictType">
  97. <span style="float: left">{{ dict.dictName }}</span>
  98. <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
  99. </el-option>
  100. </el-select>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!-- 添加或修改岗位对话框 -->
  105. <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openZd" width="70vw" append-to-body>
  106. <el-form ref="formZd" :model="formZd" :rules="rulesZd" label-width="120px">
  107. <el-row>
  108. <el-col :span="8">
  109. <el-form-item label="字段名:" prop="columnName">
  110. <el-input :disabled="this.formZd.columnId" v-model="formZd.columnName" placeholder="请输入字段名" />
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="8">
  114. <el-form-item label="字段描述:" prop="columnComment">
  115. <el-input v-model="formZd.columnComment" placeholder="请输入字段描述" />
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="8">
  119. <el-form-item label="物理类型:" prop="columnType">
  120. <el-input v-model="formZd.columnType" placeholder="请输入物理类型" />
  121. </el-form-item>
  122. </el-col>
  123. </el-row>
  124. <el-row>
  125. <el-col :span="8">
  126. <el-form-item label="字段显示规则:" prop="mask">
  127. <el-input v-model="formZd.mask" placeholder="请输入字段显示规则" />
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="8">
  131. <el-form-item label="排序:" prop="sort">
  132. <el-input-number style="width: 100%;" v-model="formZd.sort" placeholder="请输入排序" />
  133. </el-form-item>
  134. </el-col>
  135. <el-col :span="8">
  136. <el-form-item label="外键(FK):" prop="foreignKey">
  137. <!-- <el-select style="width: 100%;" filterable v-model="formZd.foreignKey" placeholder="请选择外键(FK)" clearable size="small">
  138. <el-option v-for="dict in columList" :key="dict.columnId" :label="dict.columnName" :value="dict.columnId" />
  139. </el-select> -->
  140. <div style="cursor: pointer;" @click="fkzdFn">
  141. <el-input readonly style="width: 100%;" v-model="ForeName" placeholder="请选择外键(FK)" />
  142. </div>
  143. </el-form-item>
  144. </el-col>
  145. </el-row>
  146. <el-row>
  147. <el-col :span="8">
  148. <el-form-item label="关联HR字段:" prop="hrParentId">
  149. <el-select style="width: 100%;" v-model="formZd.hrParentId" placeholder="请选择关联HR字段" clearable>
  150. <el-option v-for="dict in columHRList" :key="dict.columnId" :label="dict.columnName" :value="dict.columnId" />
  151. </el-select>
  152. </el-form-item>
  153. </el-col>
  154. <el-col :span="8">
  155. <el-form-item label="缺省值:" prop="defaultValue">
  156. <el-input v-model="formZd.defaultValue" placeholder="请输入缺省值" />
  157. </el-form-item>
  158. </el-col>
  159. <el-col :span="8">
  160. <el-form-item label="行数:" prop="numRows">
  161. <el-input-number style="width: 100%;" v-model="formZd.numRows" placeholder="请输入行数" />
  162. </el-form-item>
  163. </el-col>
  164. </el-row>
  165. <el-row>
  166. <el-col :span="8">
  167. <el-form-item label="列数:" prop="numColumns">
  168. <el-input-number style="width: 100%;" v-model="formZd.numColumns" placeholder="请输入列数" />
  169. </el-form-item>
  170. </el-col>
  171. <el-col :span="8">
  172. <el-form-item label="字段翻译器:" prop="fieldTranslator">
  173. <el-input v-model="formZd.fieldTranslator" placeholder="请输入字段翻译器" />
  174. </el-form-item>
  175. </el-col>
  176. <el-col :span="8">
  177. <el-form-item label="扩展属性:" prop="extendedAttributes">
  178. <el-input v-model="formZd.extendedAttributes" placeholder="请输入扩展属性" />
  179. </el-form-item>
  180. </el-col>
  181. </el-row>
  182. <el-row>
  183. <el-col :span="8">
  184. <el-form-item label="查询方式:" prop="queryType">
  185. <el-select style="width: 100%;" v-model="formZd.queryType">
  186. <el-option label="=" value="EQ" />
  187. <el-option label="!=" value="NE" />
  188. <el-option label=">" value="GT" />
  189. <el-option label=">=" value="GTE" />
  190. <el-option label="<" value="LT" />
  191. <el-option label="<=" value="LTE" />
  192. <el-option label="LIKE" value="LIKE" />
  193. <el-option label="BETWEEN" value="BETWEEN" />
  194. </el-select>
  195. </el-form-item>
  196. </el-col>
  197. <el-col :span="8">
  198. <el-form-item label="显示类型:" prop="htmlType">
  199. <el-select style="width: 100%;" v-model="formZd.htmlType">
  200. <el-option label="文本框" value="input" />
  201. <el-option label="文本域" value="textarea" />
  202. <el-option label="下拉框" value="select" />
  203. <el-option label="单选框" value="radio" />
  204. <el-option label="复选框" value="checkbox" />
  205. <el-option label="日期控件" value="datetime" />
  206. <el-option label="图片上传" value="imageUpload" />
  207. <el-option label="文件上传" value="fileUpload" />
  208. <el-option label="富文本控件" value="editor" />
  209. <el-option label="hr" value="hr" />
  210. </el-select>
  211. </el-form-item>
  212. </el-col>
  213. <el-col :span="8">
  214. <el-form-item label="字典类型:" prop="dictType">
  215. <template slot-scope="scope">
  216. <el-select style="width: 100%;" v-model="formZd.dictType" clearable filterable placeholder="请选择">
  217. <el-option v-for="dict in dictOptions" :key="dict.dictType" :label="dict.dictName" :value="dict.dictType">
  218. <span style="float: left">{{ dict.dictName }}</span>
  219. <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
  220. </el-option>
  221. </el-select>
  222. </template>
  223. </el-form-item>
  224. </el-col>
  225. </el-row>
  226. <el-row>
  227. <el-col :span="8">
  228. <el-form-item label="显示字段" prop="isOut">
  229. <el-checkbox true-label="Y" false-label="N" v-model="formZd.isOut"></el-checkbox>
  230. </el-form-item>
  231. </el-col>
  232. <el-col :span="8">
  233. <el-form-item label="输入字段" prop="isIn">
  234. <el-checkbox true-label="Y" false-label="N" v-model="formZd.isIn"></el-checkbox>
  235. </el-form-item>
  236. </el-col>
  237. <el-col :span="8">
  238. <el-form-item label="查询条件" prop="isQuery">
  239. <el-checkbox true-label="1" false-label="0" v-model="formZd.isQuery"></el-checkbox>
  240. </el-form-item>
  241. </el-col>
  242. </el-row>
  243. <el-row>
  244. <el-col :span="8">
  245. <el-form-item label="必填" prop="isRequired">
  246. <el-checkbox true-label="1" false-label="0" v-model="formZd.isRequired"></el-checkbox>
  247. </el-form-item>
  248. </el-col>
  249. </el-row>
  250. </el-form>
  251. <div slot="footer" class="dialog-footer">
  252. <el-button type="primary" @click="submitFormZd">确 定</el-button>
  253. <el-button @click="cancel">取 消</el-button>
  254. </div>
  255. </el-dialog>
  256. </el-tab-pane>
  257. <!-- <el-tab-pane label="生成信息" name="genInfo">
  258. <gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/>
  259. </el-tab-pane> -->
  260. <el-tab-pane label="关联表" name="genInfo">
  261. <el-row style="margin-bottom: 20px;" type="flex" :gutter="10" justify="end">
  262. <el-col :span="1.5">
  263. <el-button @click="handleAdd_gl" icon="el-icon-plus" size="mini" style="background-color: #FFE9ED;color: #E58481;border: 1px solid #E58481;">新增</el-button>
  264. </el-col>
  265. <el-col :span="1.5">
  266. <el-button icon="el-icon-delete" @click="handleDel_gl" size="mini" style="background-color: #FFD6B0;color: #EA551A;border: 1px solid #F4AD6B;"
  267. :disabled="multiple1">删除</el-button>
  268. </el-col>
  269. </el-row>
  270. <el-table ref="dragTable" @row-dblclick="dbSelected" v-loading="loading" :data="postList" row-key="columnId"
  271. align="center" :max-height="tableHeight" @selection-change="handleSelectionChange1">
  272. <el-table-column type="selection" width="55" align="center" />
  273. <el-table-column label="id" width="60" align="center" prop="id" />
  274. <el-table-column label="可用" align="center" prop="isDel">
  275. <template slot-scope="scope">
  276. <el-checkbox true-label="Y" disabled false-label="N" v-model="scope.row.isDel"></el-checkbox>
  277. </template>
  278. </el-table-column>
  279. <el-table-column label="序号" align="center" prop="sort" />
  280. <el-table-column label="描述" align="center" prop="description" />
  281. <el-table-column label="关联表" align="center" prop="tableName" />
  282. <el-table-column label="字段(关联到主表PK)" width="160px" align="center" prop="columnName" />
  283. <el-table-column label="显示条件" align="center" prop="displayConditions" />
  284. <el-table-column label="关联方式" align="center" prop="relationType">
  285. <template slot-scope="scope">
  286. {{scope.row.relationType | relationTypeFn}}
  287. </template>
  288. </el-table-column>
  289. <el-table-column label="内嵌编辑" align="center" prop="embedEdit">
  290. <template slot-scope="scope">
  291. {{scope.row.embedEdit | embedEditFn}}
  292. </template>
  293. </el-table-column>
  294. <el-table-column label="修改人" align="center" prop="updateBy" />
  295. <el-table-column label="修改时间" align="center" prop="updateTime" />
  296. </el-table>
  297. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  298. @pagination="tabList" />
  299. </el-tab-pane>
  300. <el-tab-pane label="数据库SQL" name="genSql">
  301. <el-row type="flex" justify="end">
  302. <el-button @click="zxCreaBtn" size="mini" style="background-color: #FFE9ED;color: #E58481;border: 1px solid #E58481;">执行创建语句</el-button>
  303. <el-button @click="sxCreaBtn" size="mini" style="background-color: #FFD6B0;color: #EA551A;border: 1px solid #F4AD6B;">刷新创建语句</el-button>
  304. </el-row>
  305. <el-form>
  306. <el-form-item label="创建语句:" style="margin-top: 20px;">
  307. <el-input class="resizeNone" v-model="tableSqlData.createSql" type="textarea" />
  308. </el-form-item>
  309. <el-form-item label="修改日志:">
  310. <el-input class="resizeNone" v-model="tableSqlData.createLog" type="textarea" />
  311. </el-form-item>
  312. </el-form>
  313. </el-tab-pane>
  314. </el-tabs>
  315. <!-- 添加或修改岗位对话框 -->
  316. <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
  317. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  318. <el-form-item label="描述:" prop="postName">
  319. <el-input v-model="form.description" placeholder="请输入描述" />
  320. </el-form-item>
  321. <el-form-item label="关联表:" prop="relationParentId">
  322. <el-select style="width: 100%;" v-model="form.relationParentId" placeholder="请选择关联表" @change="relationFn"
  323. v-loadmore="loadMore">
  324. <el-option v-for="item in tableList.rows" :key="item.tableId" :label="item.tableComment" :value="item.tableId">
  325. </el-option>
  326. </el-select>
  327. </el-form-item>
  328. <el-form-item label="字段:" prop="relationChildId">
  329. <el-select style="width: 100%;" v-model="form.relationChildId" placeholder="请选择字段" v-loadmore="loadMore">
  330. <el-option v-for="item in genList" v-if="item.foreignKey" :key="item.columnId" :label="item.columnName" :value="item.columnId">
  331. </el-option>
  332. </el-select>
  333. </el-form-item>
  334. <el-form-item label="显示条件:" prop="displayConditions">
  335. <el-input v-model="form.displayConditions" controls-position="right" placeholder="请输入显示条件" />
  336. </el-form-item>
  337. <el-form-item label="关联方式:" prop="relationType">
  338. <el-select style="width: 100%;" v-model="form.relationType" placeholder="请选择关联方式" clearable size="small">
  339. <el-option v-for="dict in relationType" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  340. </el-select>
  341. </el-form-item>
  342. <el-form-item label="内嵌编辑:" prop="embedEdit">
  343. <el-select style="width: 100%;" v-model="form.embedEdit" placeholder="岗位状态" clearable size="small">
  344. <el-option v-for="dict in embedEdit" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  345. </el-select>
  346. </el-form-item>
  347. <el-form-item label="序号:" prop="sort">
  348. <el-input-number style="width: 100%;" v-model="form.sort" controls-position="right" :min="0" />
  349. </el-form-item>
  350. <el-form-item label="是否可用:" prop="isDel">
  351. <el-checkbox true-label="Y" false-label="N" v-model="form.isDel"></el-checkbox>
  352. </el-form-item>
  353. </el-form>
  354. <div slot="footer" class="dialog-footer">
  355. <el-button type="primary" @click="addGlfn">确 定</el-button>
  356. <el-button @click="cancel">取 消</el-button>
  357. </div>
  358. </el-dialog>
  359. <!-- 快速搜索对话框 -->
  360. <el-dialog :close-on-click-modal="false" :title="titleopenquery" :visible.sync="openquery" width="1200px" append-to-body>
  361. <el-form ref="formquery" @row-dblclick="dbSelectedZd" :model="formquery" :rules="rules" label-width="100px">
  362. <dynamic-forms :ref="item.columnName" :config="formquery.fixedData" @inputs = "changeFn" :formConfig="item" v-for="(item,index) in queryData.queryList" :key='index' />
  363. <el-form-item style="display: inline-block;">
  364. <el-button type="primary" @click="handleQuery">搜索</el-button>
  365. <el-button @click="openquery = false">取消</el-button>
  366. </el-form-item>
  367. </el-form>
  368. <el-table stripe @row-dblclick="tableBtn" :data="postListquery.rows" @selection-change="handleSelectionChange">
  369. <el-table-column :label="item.columnComment" align="center" :prop="item.columnName" v-for="(item,index) in postListquery.tableHeadList" :key="index" />
  370. </el-table>
  371. <pagination
  372. v-show="totalquery>0"
  373. :total="totalquery"
  374. :page.sync="aliemg.pageNo"
  375. :limit.sync="aliemg.pageSize"
  376. @pagination="getLisail"
  377. />
  378. </el-dialog>
  379. </el-card>
  380. </template>
  381. <script>
  382. import {
  383. getGenTable,
  384. updateGenTable,
  385. delPost,
  386. tabList,
  387. listTable,
  388. addGenTable,
  389. setGenTable,
  390. delGenTable,
  391. listAllColumnsByTableId,
  392. genTableColumnList,
  393. tableSql,
  394. zxImplement,
  395. getReload,
  396. addGenTableColumn,
  397. delGenTableColumn,
  398. setGenTableColumn,
  399. getGenTableColumn,
  400. getByIdWithForeignKey,
  401. listIndexfou,
  402. tableQuery,
  403. qurGenTable
  404. } from "@/api/tool/gen";
  405. import {
  406. optionselect as getDictOptionselect
  407. } from "@/api/system/dict/type";
  408. import {
  409. listMenu as getMenuTreeselect
  410. } from "@/api/system/menu";
  411. import basicInfoForm from "./basicInfoForm";
  412. import genInfoForm from "./genInfoForm";
  413. import Sortable from 'sortablejs'
  414. let _this = ''
  415. export default {
  416. name: "GenEdit",
  417. components: {
  418. basicInfoForm,
  419. genInfoForm
  420. },
  421. data() {
  422. _this = this
  423. return {
  424. ForeName: '',
  425. totalquery:0,
  426. // 多行查询
  427. titleopenquery:'快速查询',
  428. // 获取输入框的参数
  429. queryLisr:{
  430. table:'gen_table_column'
  431. },
  432. aliemg:{
  433. table:'gen_table_column',
  434. orderBy:'create_time desc',
  435. pageNo:1,
  436. pageSize:10,
  437. fixedData:{
  438. condition:''
  439. }
  440. },
  441. postListquery:{},
  442. queryData: {},
  443. openquery:false,
  444. formquery:{},
  445. // 字段信息
  446. tableSqlData: [],
  447. columList: [],
  448. columHRList: [],
  449. foreignKey: [],
  450. openZd: false,
  451. formZd: {
  452. columnId: ''
  453. },
  454. rulesZd: {
  455. columnName: [{
  456. required: true,
  457. message: "请输入字段名",
  458. trigger: "blur"
  459. }],
  460. columnComment: [{
  461. required: true,
  462. message: "请输入字段描述",
  463. trigger: "blur"
  464. }],
  465. columnType: [{
  466. required: true,
  467. message: "请输入物理类型",
  468. trigger: "blur"
  469. }],
  470. mask: [{
  471. required: true,
  472. message: "请输入字段显示规则",
  473. trigger: "blur"
  474. }],
  475. sort: [{
  476. required: true,
  477. message: "请输入序号",
  478. trigger: "blur"
  479. }],
  480. },
  481. loadingZd: '',
  482. // 关联表
  483. title: "",
  484. loading: false,
  485. open: false,
  486. form: {},
  487. rules: {
  488. relationParentId: [{
  489. required: true,
  490. message: "请选择关联表",
  491. trigger: "blur"
  492. }],
  493. relationChildId: [{
  494. required: true,
  495. message: "请选择字段",
  496. trigger: "blur"
  497. }],
  498. relationType: [{
  499. required: true,
  500. message: "请选择关联条件",
  501. trigger: "blur"
  502. }],
  503. },
  504. postList: [],
  505. total: 1,
  506. tableList: {},
  507. // 关联方式
  508. // 内嵌编辑
  509. genList: [],
  510. glbParams: {
  511. pageNum: 1,
  512. pageSize: 10,
  513. },
  514. // 关联表查询参数
  515. queryParams: {
  516. relationParentId: this.$route.params && this.$route.params.tableId,
  517. pageNum: 1,
  518. pageSize: 10,
  519. },
  520. // 选中选项卡的 name
  521. activeName: "basic",
  522. // 表格的高度
  523. tableHeight: document.documentElement.scrollHeight - 245 + "px",
  524. // 表信息
  525. tables: [],
  526. // 表列信息
  527. cloumns: [],
  528. // 字典信息
  529. dictOptions: [],
  530. // 菜单信息
  531. menus: [],
  532. // 表详细信息
  533. info: {},
  534. // 选中数组
  535. ids: [],
  536. ids1: [],
  537. // 非单个禁用
  538. single: true,
  539. single1: true,
  540. // 非多个禁用
  541. multiple: true,
  542. multiple1: true,
  543. // 关联方式
  544. relationType: [],
  545. // 内嵌编辑
  546. embedEdit: [],
  547. };
  548. },
  549. filters: {
  550. zdFn(data) {
  551. let is = ''
  552. for (let item of _this.columList) {
  553. if (item.columnId == data) {
  554. is = item.columnName
  555. }
  556. }
  557. return is
  558. },
  559. relationTypeFn(data) {
  560. let is = ''
  561. for (let item of _this.relationType) {
  562. if (item.dictValue == data) {
  563. is = item.dictLabel
  564. }
  565. }
  566. return is
  567. },
  568. embedEditFn(data) {
  569. let is = ''
  570. for (let item of _this.embedEdit) {
  571. if (item.dictValue == data) {
  572. is = item.dictLabel
  573. }
  574. }
  575. return is
  576. },
  577. },
  578. created() {
  579. const tableId = this.$route.params && this.$route.params.tableId;
  580. if (tableId) {
  581. // 获取表详细信息
  582. getGenTable(tableId).then(res => {
  583. this.cloumns = res.data.rows;
  584. this.info = res.data.info;
  585. this.tables = res.data.tables;
  586. });
  587. //查询数据库sql
  588. tableSql(tableId).then(res => {
  589. if (res.data) {
  590. this.tableSqlData = res.data
  591. }
  592. })
  593. /** 查询字典下拉列表 */
  594. getDictOptionselect().then(response => {
  595. this.dictOptions = response.data;
  596. });
  597. // 关联HR字段
  598. genTableColumnList({
  599. tableId,
  600. htmlType: 'HR'
  601. }).then(response => {
  602. this.columHRList = response.rows;
  603. });
  604. // 关联字段
  605. listAllColumnsByTableId({
  606. tableId
  607. }).then(response => {
  608. this.columList = response.data;
  609. });
  610. // 关联表数据
  611. listTable(this.glbParams).then(response => {
  612. this.tableList = response;
  613. });
  614. /** 查询菜单下拉列表 */
  615. // getMenuTreeselect().then(response => {
  616. // this.menus = this.handleTree(response.data, "menuId");
  617. // });
  618. // 关联方式
  619. this.getDicts("relation_type").then(response => {
  620. this.relationType = response.data;
  621. });
  622. // 内嵌编辑
  623. this.getDicts("embed_edit").then(response => {
  624. this.embedEdit = response.data;
  625. });
  626. }
  627. this.tabList()
  628. },
  629. methods: {
  630. tableBtn(row){
  631. this.openquery = false
  632. this.ForeName = row.column_name
  633. this.formZd.foreignKey = row.column_id
  634. },
  635. fkzdFn() {
  636. this.queryedit()
  637. this.getLisail()
  638. this.openquery = true
  639. },
  640. changeFn(obj) {
  641. console.log(obj)
  642. for(let key in obj){
  643. this.formquery.fixedData[key] = obj[key]
  644. }
  645. },
  646. // 快速查询
  647. queryedit(){
  648. this.loading = true;
  649. tableQuery(this.queryLisr).then(response => {
  650. let data = response.data
  651. this.queryData = data
  652. this.loading = false;
  653. })
  654. },
  655. handleQuery(){
  656. for(let item of this.queryData.queryList){
  657. if(item.htmlType == 'checkbox' || item.htmlType == 'imageUpload' || item.htmlType == 'fileUpload'){
  658. this.formquery[item.columnName] = this.$refs[item.columnName][0].config
  659. } else{
  660. this.formquery[item.columnName] = this.$refs[item.columnName][0].config[item.columnName]
  661. }
  662. }
  663. this.aliemg.fixedData.condition = this.formquery
  664. this.getLisail()
  665. },
  666. // 快速查询列表
  667. getLisail() {
  668. this.loading = true;
  669. listIndexfou(this.aliemg).then(response => {
  670. if(response.data !== undefined){
  671. // this.tableDataalid = response.data.tableHeadList;
  672. this.postListquery = response.data
  673. this.postListquery.rows.filter(route => {
  674. if(route.dept_id !== undefined){
  675. route.dept_id = route.dept_id.value
  676. }
  677. })
  678. console.log(this.tableDataalid,67)
  679. this.totalquery = response.data.total;
  680. }
  681. this.loading = false;
  682. }
  683. );
  684. },
  685. submitFormZd() {
  686. this.$refs["formZd"].validate(valid => {
  687. if (valid) {
  688. const tableId = this.$route.params && this.$route.params.tableId;
  689. this.formZd.tableId = tableId
  690. if (this.formZd.columnId != undefined) {
  691. setGenTableColumn(this.formZd).then(response => {
  692. this.msgSuccess("修改成功");
  693. this.openZd = false;
  694. // 获取表详细信息
  695. getGenTable(tableId).then(res => {
  696. this.cloumns = res.data.rows;
  697. this.info = res.data.info;
  698. this.tables = res.data.tables;
  699. });
  700. });
  701. } else {
  702. addGenTableColumn(this.formZd).then(response => {
  703. this.msgSuccess("新增成功");
  704. this.openZd = false;
  705. // 获取表详细信息
  706. getGenTable(tableId).then(res => {
  707. this.cloumns = res.data.rows;
  708. this.info = res.data.info;
  709. this.tables = res.data.tables;
  710. });
  711. });
  712. }
  713. }
  714. });
  715. },
  716. sxCreaBtn() {
  717. const tableId = this.$route.params && this.$route.params.tableId
  718. getReload({
  719. tableId,
  720. createSql: this.tableSqlData.createSql,
  721. createLog: this.tableSqlData.createLog,
  722. id: this.tableSqlData.id
  723. }).then(res => {
  724. this.msgSuccess('刷新成功')
  725. //查询数据库sql
  726. tableSql(tableId).then(res => {
  727. if (res.data) {
  728. this.tableSqlData = res.data
  729. }
  730. })
  731. })
  732. },
  733. zxCreaBtn() {
  734. const _this = this
  735. this.$confirm('是否确认执行创建语句?', "警告", {
  736. confirmButtonText: "确定",
  737. cancelButtonText: "取消",
  738. type: "warning"
  739. }).then(function() {
  740. return zxImplement({
  741. tableId: _this.$route.params && _this.$route.params.tableId,
  742. createSql: _this.tableSqlData.createSql,
  743. createLog: _this.tableSqlData.createLog,
  744. id: _this.tableSqlData.id
  745. })
  746. }).then(res => {
  747. _this.msgSuccess('执行成功')
  748. })
  749. },
  750. dbSelectedZd(row) {
  751. this.reset();
  752. const id = row.columnId
  753. getByIdWithForeignKey(id).then(response => {
  754. let data = response.data
  755. data.foreignKey = data.foreignKey ? data.foreignKey - 0 : ''
  756. this.formZd = data;
  757. console.log(data,8890)
  758. if(data.fkInfo){
  759. this.ForeName = data.fkInfo.value
  760. }
  761. this.openZd = true;
  762. this.title = "修改字段信息";
  763. });
  764. },
  765. dbSelected(row) {
  766. this.reset();
  767. const id = row.id
  768. qurGenTable(id).then(response => {
  769. let data = response.data
  770. data.relationType = data.relationType + ""
  771. data.embedEdit = data.embedEdit?(data.embedEdit + ""): data.embedEdit
  772. getGenTable(data.relationParentId).then(res => {
  773. this.genList = res.data.rows;
  774. this.form = data;
  775. this.open = true;
  776. this.title = "修改关联表";
  777. });
  778. });
  779. },
  780. addGlfn() {
  781. this.$refs["form"].validate(valid => {
  782. if (valid) {
  783. let datas = JSON.parse(JSON.stringify(this.form))
  784. datas.relationParentId = this.info.tableId
  785. if (this.form.id != undefined) {
  786. setGenTable(datas).then(response => {
  787. this.msgSuccess("修改成功");
  788. this.open = false;
  789. this.tabList();
  790. });
  791. } else {
  792. addGenTable(datas).then(response => {
  793. this.msgSuccess("新增成功");
  794. this.open = false;
  795. this.tabList();
  796. });
  797. }
  798. }
  799. });
  800. },
  801. relationFn(data) {
  802. getGenTable(data).then(res => {
  803. this.genList = res.data.rows;
  804. });
  805. },
  806. loadMore() {
  807. const _this = this
  808. let num = _this.tableList.total % 10 == 0 ? _this.tableList.total / 10 : ((_this.tableList.total - _this.tableList
  809. .total % 10) / 10 + 1)
  810. console.log(num, 1)
  811. if (this.glbParams.pageNum < num) {
  812. this.glbParams.pageNum++
  813. // 关联表数据
  814. listTable(this.glbParams).then(response => {
  815. let data = response
  816. data.rows = _this.tableList.rows.concat(data.rows)
  817. _this.tableList = data;
  818. });
  819. }
  820. },
  821. // 取消按钮
  822. cancel() {
  823. this.open = false;
  824. this.reset();
  825. this.openZd = false;
  826. this.resetZd();
  827. },
  828. // 关联表数据
  829. tabList() {
  830. this.loading = true;
  831. tabList(this.queryParams).then(response => {
  832. this.postList = response.rows;
  833. this.total = response.total;
  834. this.loading = false;
  835. });
  836. },
  837. /** 新增按钮操作 */
  838. handleAdd_gl() {
  839. this.reset();
  840. this.open = true;
  841. console.log(this.form)
  842. this.title = "新增关联表";
  843. },
  844. handleDel_gl(row) {
  845. const ids = row.id || this.ids1;
  846. console.log(ids, 1223)
  847. this.$confirm('是否确认删除id为"' + ids + '"的数据项?', "警告", {
  848. confirmButtonText: "确定",
  849. cancelButtonText: "取消",
  850. type: "warning"
  851. }).then(function() {
  852. return delGenTable(ids);
  853. }).then(() => {
  854. this.tabList();
  855. this.msgSuccess("删除成功");
  856. })
  857. },
  858. // 表单重置
  859. reset() {
  860. this.form = {
  861. isDel: 'N'
  862. };
  863. this.resetForm("form");
  864. },
  865. resetZd() {
  866. this.formZd = {
  867. };
  868. this.resetForm("formZd");
  869. },
  870. /** 提交按钮 */
  871. submitForm() {
  872. let isInFlag = 0
  873. let isOutFlag = 0
  874. console.log(this.cloumns,333)
  875. for(let item of this.cloumns){
  876. if(item.isIn=='Y'){
  877. isInFlag++
  878. }
  879. if(item.isOut=='Y'){
  880. isOutFlag++
  881. }
  882. }
  883. if(isInFlag>1){
  884. this.msgError('"输入字段"最多只能选择一个!')
  885. return
  886. }
  887. if(isOutFlag>1){
  888. this.msgError('"显示字段"最多只能选择一个!')
  889. return
  890. }
  891. const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
  892. // const genForm = this.$refs.genInfo.$refs.genInfoForm;
  893. Promise.all([basicForm].map(this.getFormPromise)).then(res => {
  894. const validateResult = res.every(item => !!item);
  895. if (validateResult) {
  896. const genTable = Object.assign({}, basicForm.model);
  897. genTable.columns = this.cloumns;
  898. // genTable.params = {
  899. // treeCode: genTable.treeCode,
  900. // treeName: genTable.treeName,
  901. // treeParentCode: genTable.treeParentCode,
  902. // parentMenuId: genTable.parentMenuId
  903. // };
  904. updateGenTable(genTable).then(res => {
  905. this.msgSuccess(res.msg);
  906. if (res.code === 200) {
  907. this.close();
  908. }
  909. });
  910. } else {
  911. this.msgError("表单校验未通过,请重新检查提交内容");
  912. }
  913. });
  914. },
  915. getFormPromise(form) {
  916. return new Promise(resolve => {
  917. form.validate(res => {
  918. resolve(res);
  919. });
  920. });
  921. },
  922. /** 关闭按钮 */
  923. close() {
  924. this.$store.dispatch("tagsView/delView", this.$route);
  925. this.$router.push({
  926. path: "/tool/gen",
  927. query: {
  928. t: Date.now()
  929. }
  930. })
  931. },
  932. // 多选框选中数据
  933. handleSelectionChange(selection) {
  934. this.ids = selection.map(item => item.columnId)
  935. this.single = selection.length != 1
  936. this.multiple = !selection.length
  937. },
  938. // 多选框选中数据
  939. handleSelectionChange1(selection) {
  940. this.ids1 = selection.map(item => item.id)
  941. this.single1 = selection.length != 1
  942. this.multiple1 = !selection.length
  943. },
  944. /** 删除按钮操作 */
  945. handleDelete(row) {
  946. const ids = row.id || this.ids;
  947. const tableId = this.$route.params && this.$route.params.tableId;
  948. this.$confirm('是否确认删除字段编号为"' + ids + '"的数据项?', "警告", {
  949. confirmButtonText: "确定",
  950. cancelButtonText: "取消",
  951. type: "warning"
  952. }).then(function() {
  953. return delGenTableColumn(ids);
  954. }).then(() => {
  955. // 获取表详细信息
  956. getGenTable(tableId).then(res => {
  957. this.cloumns = res.data.rows;
  958. this.info = res.data.info;
  959. this.tables = res.data.tables;
  960. });
  961. this.msgSuccess("删除成功");
  962. })
  963. },
  964. handleAdd() {
  965. this.resetZd();
  966. this.openZd = true;
  967. this.title = "新增字段信息";
  968. }
  969. },
  970. mounted() {
  971. const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
  972. const sortable = Sortable.create(el, {
  973. handle: ".allowDrag",
  974. onEnd: evt => {
  975. const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
  976. this.cloumns.splice(evt.newIndex, 0, targetRow);
  977. for (let index in this.cloumns) {
  978. this.cloumns[index].sort = parseInt(index) + 1;
  979. }
  980. }
  981. });
  982. }
  983. };
  984. </script>
  985. <style lang="scss">
  986. .pagination-container {
  987. height: 35px;
  988. }
  989. .resizeNone {
  990. width: 60vw;
  991. border-radius: 3px;
  992. .el-textarea__inner {
  993. //el_input中的隐藏属性
  994. resize: none; //主要是这个样式
  995. height: 200px;
  996. }
  997. }
  998. </style>