index.vue 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="68px"
  10. >
  11. <el-form-item label="表格组名" prop="dtName">
  12. <el-input
  13. v-model="queryParams.dtName"
  14. placeholder="请输入表格组名"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button
  21. type="primary"
  22. icon="el-icon-search"
  23. size="mini"
  24. @click="handleQuery"
  25. >搜索</el-button
  26. >
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  28. >重置</el-button
  29. >
  30. </el-form-item>
  31. </el-form>
  32. <el-row :gutter="10" class="mb8">
  33. <el-col :span="1.5">
  34. <el-button
  35. type="primary"
  36. plain
  37. icon="el-icon-plus"
  38. size="mini"
  39. @click="handleAdd"
  40. >新增</el-button
  41. >
  42. </el-col>
  43. <el-col :span="1.5">
  44. <el-button
  45. type="danger"
  46. plain
  47. icon="el-icon-delete"
  48. size="mini"
  49. :disabled="multiple"
  50. @click="DeleteTableGroup"
  51. >删除</el-button
  52. >
  53. </el-col>
  54. <!-- <el-col :span="1.5">
  55. <el-button type="danger" plain size="mini" @click="handlePreview"
  56. >动态页面</el-button
  57. >
  58. </el-col> -->
  59. </el-row>
  60. <el-table
  61. v-loading="loading"
  62. :data="tableGroupList"
  63. ref="tableRef"
  64. @selection-change="handleSelectionChange"
  65. >
  66. <el-table-column type="selection" width="55" align="center" />
  67. <el-table-column label="表格主键" align="center" prop="id" />
  68. <el-table-column label="表格组名" align="center" prop="groupName" />
  69. <el-table-column label="描述" align="center" prop="groupDescription" />
  70. <el-table-column label="表格数" align="center" prop="groupCount" />
  71. <el-table-column label="成员表格" width="180">
  72. <template slot-scope="scope">
  73. <el-popover trigger="hover" placement="top">
  74. <p v-for="(item, index) in scope.row.groupTableInfo" :key="index">
  75. {{ index == 0 ? "" : item.tablename }}
  76. </p>
  77. <div slot="reference" class="name-wrapper">
  78. <el-tag size="medium">{{
  79. scope.row.groupTableInfo[0].tablename
  80. }}</el-tag>
  81. </div>
  82. </el-popover>
  83. </template>
  84. </el-table-column>
  85. <el-table-column
  86. label="操作"
  87. align="center"
  88. class-name="small-padding fixed-width"
  89. >
  90. <template slot-scope="scope">
  91. <el-dropdown>
  92. <el-button type="warning" plain size="small">
  93. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  94. </el-button>
  95. <el-dropdown-menu slot="dropdown">
  96. <el-dropdown-item>
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-edit"
  101. @click="UpdateTableGroup(scope.row)"
  102. >修改
  103. </el-button>
  104. </el-dropdown-item>
  105. <el-dropdown-item>
  106. <el-button
  107. size="mini"
  108. type="text"
  109. icon="el-icon-delete"
  110. @click="DeleteTableGroup(scope.row)"
  111. >删除
  112. </el-button>
  113. </el-dropdown-item>
  114. </el-dropdown-menu>
  115. </el-dropdown>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. <pagination
  120. v-show="total > 0"
  121. :total="total"
  122. :page.sync="queryParams.pageNum"
  123. :limit.sync="queryParams.pageSize"
  124. @pagination="getTableList"
  125. />
  126. <!-- 新增联动表格组弹窗 -->
  127. <el-dialog
  128. :title="groupTitle ? '新增动态表格组' : '修改动态表格组'"
  129. :visible.sync="isShowTable"
  130. >
  131. <div class="dialog_wrap">
  132. <el-button
  133. type="primary"
  134. size="small"
  135. icon="el-icon-plus"
  136. @click="addOneTable"
  137. class="mb10"
  138. >新增</el-button
  139. >
  140. <el-form
  141. :model="groupForm"
  142. :rules="grouprules"
  143. ref="groupForm"
  144. label-width="100px"
  145. class="demo-ruleForm"
  146. >
  147. <el-form-item label="菜单名称" prop="groupName">
  148. <el-input
  149. v-model="groupForm.groupName"
  150. placeholder="请输入菜单名称"
  151. @input="iptChange()"
  152. ></el-input>
  153. </el-form-item>
  154. <el-form-item label="菜单描述" prop="groupDescription">
  155. <el-input
  156. v-model="groupForm.groupDescription"
  157. placeholder="请输入菜单描述"
  158. ></el-input>
  159. </el-form-item>
  160. <el-form-item label="菜单路由" prop="routePath">
  161. <div class="treeselect">
  162. <treeselect
  163. :append-to-body="true"
  164. v-model="groupForm.routePath"
  165. :options="menus"
  166. :normalizer="normalizer"
  167. :show-count="true"
  168. placeholder="请选择父级路由"
  169. />
  170. </div>
  171. </el-form-item>
  172. <el-form-item>
  173. <el-table
  174. :data="tableDataList"
  175. border
  176. stripe
  177. @selection-change="handleSelectionChange"
  178. >
  179. <el-table-column label="序号" type="index" />
  180. <el-table-column label="表格标题" prop="dtName" />
  181. <el-table-column
  182. label="表格名称"
  183. prop="dtTableName"
  184. ></el-table-column>
  185. <el-table-column label="表格主键" prop="primaryKey">
  186. <!-- <template slot-scope="scope" v-for="item in conditionDefaultValueMap ">
  187. {{ item }}
  188. </template> -->
  189. </el-table-column>
  190. <el-table-column
  191. label="操作"
  192. align="center"
  193. class-name="small-padding fixed-width"
  194. >
  195. <template slot-scope="scope">
  196. <el-dropdown>
  197. <el-button type="warning" plain size="small">
  198. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  199. </el-button>
  200. <el-dropdown-menu slot="dropdown">
  201. <el-dropdown-item>
  202. <el-button
  203. size="mini"
  204. type="text"
  205. icon="el-icon-edit"
  206. @click="relateOne(scope.row, scope.$index)"
  207. >修改
  208. </el-button>
  209. </el-dropdown-item>
  210. <el-dropdown-item>
  211. <el-button
  212. size="mini"
  213. type="text"
  214. icon="el-icon-delete"
  215. @click="handleDelete(scope.row)"
  216. >删除
  217. </el-button>
  218. </el-dropdown-item>
  219. </el-dropdown-menu>
  220. </el-dropdown>
  221. </template>
  222. </el-table-column>
  223. </el-table>
  224. </el-form-item>
  225. <el-form-item class="btn">
  226. <el-button @click="cancelGroup">取消</el-button>
  227. <el-button type="primary" @click="addTableGroup('groupForm')"
  228. >确认</el-button
  229. >
  230. </el-form-item>
  231. </el-form>
  232. </div>
  233. </el-dialog>
  234. <!-- 编辑某一条表格数据弹窗 -->
  235. <el-dialog
  236. :title="relateTitle ? '添加关联表格' : '修改关联表格'"
  237. :visible.sync="isShowForm"
  238. >
  239. <div class="formWrap">
  240. <el-form
  241. :rules="tableItemRules"
  242. ref="tableItemForm"
  243. style="max-width: 750px; width: 1000px"
  244. :model="tableItemForm"
  245. label-width="100px"
  246. >
  247. <el-form-item label="表格标题:" prop="title">
  248. <el-input
  249. v-model="tableItemForm.title"
  250. style="max-width: 221px"
  251. @change="iptChange()"
  252. @input="iptChange()"
  253. ></el-input>
  254. </el-form-item>
  255. <el-form-item label="表格名称:" prop="tableName">
  256. <el-select
  257. v-model="tableItemForm.tableName"
  258. @change="getList()"
  259. placeholder="请选择表格名称"
  260. @input="iptChange()"
  261. >
  262. <el-option
  263. v-for="item in tableList"
  264. :key="item.tableName"
  265. :label="item.tableComment"
  266. :value="item.tableName"
  267. >
  268. <span style="float: left">{{ item.tableComment }}</span>
  269. <span style="float: right; color: #8492a6; font-size: 13px">{{
  270. item.tableName
  271. }}</span>
  272. </el-option>
  273. </el-select>
  274. </el-form-item>
  275. <el-form-item label="表格主键:" prop="selectFields">
  276. <el-select
  277. v-model="tableItemForm.selectFields"
  278. placeholder="请选择表格主键"
  279. @input="iptChange()"
  280. >
  281. <el-option
  282. v-for="item in tableFieldList"
  283. :key="item.fieldName"
  284. :label="item.fieldDescription"
  285. :value="item.fieldName"
  286. >
  287. <span style="float: left">{{ item.fieldDescription }}</span>
  288. <span style="float: right; color: #8492a6; font-size: 13px">{{
  289. item.fieldName
  290. }}</span>
  291. </el-option>
  292. </el-select>
  293. </el-form-item>
  294. <el-form-item label="时间格式" prop="timeFormate">
  295. <el-select
  296. v-model="tableItemForm.timeFormate"
  297. placeholder="请选择时间格式"
  298. @input="iptChange()"
  299. >
  300. <el-option
  301. v-for="val in dict.type.sys_time_format"
  302. :key="val.value"
  303. :label="val.label"
  304. :value="val.value"
  305. ></el-option>
  306. </el-select>
  307. </el-form-item>
  308. <el-form-item label="排序依赖字段">
  309. <el-select
  310. v-model="tableItemForm.orderByColumn"
  311. placeholder="请选择排序依赖"
  312. @input="iptChange()"
  313. >
  314. <el-option
  315. v-for="val in orderByFieldList"
  316. :key="val.fieldName"
  317. :label="val.fieldDescription"
  318. :value="val.tableName + '.' + val.fieldName"
  319. ></el-option>
  320. </el-select>
  321. </el-form-item>
  322. <el-form-item label="排序方式" v-show="tableItemForm.orderByColumn">
  323. <el-radio v-model="tableItemForm.isAsc" :label="false"
  324. >升序</el-radio
  325. >
  326. <el-radio v-model="tableItemForm.isAsc" :label="true"
  327. >降序</el-radio
  328. >
  329. </el-form-item>
  330. <el-form-item label="展示字段:" prop="FieldList">
  331. <el-table
  332. :data="tableFieldList"
  333. border
  334. ref="dragTable"
  335. row-key="id"
  336. max-height="500px"
  337. class="tablefiled"
  338. >
  339. <el-table-column
  340. type="index"
  341. label="序号"
  342. width="50"
  343. class-name="allowDrag"
  344. >
  345. </el-table-column>
  346. <el-table-column
  347. prop="fieldName"
  348. label="数据字段"
  349. ></el-table-column>
  350. <el-table-column prop="fieldDescription" label="字段描述">
  351. <template slot-scope="scope">
  352. <input
  353. :class="{
  354. isNullDesc:
  355. scope.row.fieldDescription == '' &&
  356. scope.row.isShow &&
  357. isInputInvalid
  358. ? true
  359. : false,
  360. ipt: true,
  361. }"
  362. v-model="scope.row.fieldDescription"
  363. />
  364. </template>
  365. </el-table-column>
  366. <el-table-column width="95px" prop="relationTable" label="关联表">
  367. <template slot-scope="scope">
  368. <el-select
  369. v-model="scope.row.relationTable"
  370. :disabled="
  371. !scope.row.relationTableList ||
  372. !scope.row.relationTableList.length
  373. "
  374. placeholder="请选择关联的表"
  375. clearable
  376. filterable
  377. @change="ralationTableChange(scope.row)"
  378. >
  379. <el-option
  380. v-for="(item, index) in scope.row.relationTableList"
  381. :key="index"
  382. :label="item.tableComment"
  383. :value="item.tableName"
  384. >
  385. <span style="float: left">{{ item.tableComment }}</span>
  386. <span
  387. style="float: right; color: #8492a6; font-size: 13px"
  388. >{{ item.tableName }}</span
  389. >
  390. </el-option>
  391. </el-select>
  392. </template>
  393. </el-table-column>
  394. <el-table-column
  395. width="95px"
  396. prop="relationFieldName"
  397. label="关联条件字段"
  398. >
  399. <template slot-scope="scope">
  400. <el-select
  401. v-model="scope.row.relationFieldName"
  402. @change="relationFieldChange(scope.row)"
  403. :disabled="!scope.row.disableRelaFieldName"
  404. placeholder="关联字段"
  405. filterable
  406. >
  407. <el-option
  408. v-for="(item, index) in scope.row.relaFieldNameList"
  409. :key="index"
  410. :label="item.fieldDescription"
  411. :value="item.fieldName"
  412. >
  413. </el-option>
  414. </el-select>
  415. </template>
  416. </el-table-column>
  417. <el-table-column
  418. width="95px"
  419. prop="relationType"
  420. label="关联方式"
  421. >
  422. <template slot-scope="scope">
  423. <el-select
  424. v-model="scope.row.relationType"
  425. placeholder="请选择关联方式"
  426. :disabled="!scope.row.disableRelaType"
  427. @change="relationTypeChangeHandler(scope.row)"
  428. filterable
  429. >
  430. <el-option
  431. v-for="(item, index) in relaTypeList"
  432. :key="index"
  433. :label="item.label"
  434. :value="item.value"
  435. >
  436. </el-option>
  437. </el-select>
  438. </template>
  439. </el-table-column>
  440. <el-table-column prop="isShow" label="是否显示">
  441. <template slot-scope="scope">
  442. <el-switch v-model="scope.row.isShow"> </el-switch>
  443. </template>
  444. </el-table-column>
  445. <el-table-column prop="isSearch" label="是否包含查询">
  446. <template slot-scope="scope">
  447. <el-switch
  448. v-model="scope.row.isSearch"
  449. @change="isSearchChange($event, scope.row, scope.$index)"
  450. >
  451. </el-switch>
  452. </template>
  453. </el-table-column>
  454. </el-table>
  455. </el-form-item>
  456. <el-form-item class="btn">
  457. <el-button @click="cancelAddHandler">取消</el-button>
  458. <el-button
  459. type="primary"
  460. @click="confirmAddHandler('tableItemForm')"
  461. >确认</el-button
  462. >
  463. </el-form-item>
  464. </el-form>
  465. </div>
  466. </el-dialog>
  467. <!-- 是否包含查询字段依赖值对话框 -->
  468. <div class="isSearch">
  469. <el-dialog title="包含查询依赖值" :visible.sync="isSearchDialog">
  470. <el-select v-model="relyOption" placeholder="请选择依赖方式">
  471. <el-option
  472. v-for="item in relyOptions"
  473. :key="item.value"
  474. :label="item.label"
  475. :value="item.value"
  476. >
  477. </el-option>
  478. </el-select>
  479. <el-input
  480. v-show="relyOption === '0'"
  481. v-model="conditionDefaultValueMap"
  482. placeholder="请输入依赖值"
  483. ></el-input>
  484. <el-select
  485. v-show="relyOption === '1'"
  486. v-model="conditionDefaultValueMap"
  487. placeholder="请选择依赖字段"
  488. >
  489. <el-option
  490. v-for="item in relyFileds.tableFieldList"
  491. :key="item.fieldName"
  492. :label="item.fieldDescription"
  493. :value="item.fieldName"
  494. >
  495. </el-option>
  496. </el-select>
  497. <span slot="footer" class="dialog-footer">
  498. <el-button @click="isSearchCancel">取 消</el-button>
  499. <el-button type="primary" @click="isSearchBtn">确 定</el-button>
  500. </span>
  501. </el-dialog>
  502. </div>
  503. </div>
  504. </template>
  505. <script>
  506. import { listTable, removeTableList } from "@/api/dragform/tableList";
  507. import {
  508. getFormName,
  509. getListName,
  510. dragTablePreview,
  511. } from "@/api/dragform/form.js";
  512. import { delMenu } from "@/api/system/menu";
  513. import { getMenuList, addMenu, getRouters } from "@/api/menu.js";
  514. import { getParticMenu, updateMenu } from "@/api/system/menu.js";
  515. import {
  516. addGroup,
  517. listGroup,
  518. getTable,
  519. delGroup,
  520. updataGroup,
  521. } from "@/api/relateTable/index.js";
  522. import { mapGetters, mapState } from "vuex";
  523. import { v4 as uuidv4 } from "uuid";
  524. import Treeselect from "@riophae/vue-treeselect";
  525. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  526. import json from "highlight.js/lib/languages/json";
  527. import { getTableInfo } from "@/api/system/table.js";
  528. export default {
  529. name: "relateTable",
  530. components: { Treeselect },
  531. dicts: ["sys_time_format", "table_statistic_type"],
  532. data() {
  533. return {
  534. editIndex: 0,
  535. isInputInvalid: false,
  536. // 包含查询依赖字段dialog
  537. isSearchDialog: false,
  538. isSearchIndex: null,
  539. // 依赖方式
  540. relyOption: null,
  541. relyOptions: [
  542. {
  543. value: "0",
  544. label: "自定义依赖值",
  545. },
  546. {
  547. value: "1",
  548. label: "依赖其他字段",
  549. },
  550. ],
  551. // 依赖值
  552. conditionDefaultValueMap: "",
  553. // 上个表格名称及字段
  554. relyFileds: {},
  555. formdata: {
  556. conditionDefaultValueMap: {},
  557. },
  558. conditionDefault: {},
  559. addDragData: [],
  560. groupList: [],
  561. menus: [], //路由列表数据
  562. // 添加关联表格校验规则
  563. tableItemRules: {
  564. // title:[{ required: true, message: '请输入表格标题', trigger: 'blur' }],
  565. // tableName:[{ required: true, message: '请选择表格名称', trigger: 'change' }],
  566. // selectFields: [{ required: true, message: '请选择关联字段', trigger: 'change' }],
  567. },
  568. groupForm: {
  569. groupName: "",
  570. groupDescription: "",
  571. routePath: undefined,
  572. },
  573. grouprules: {
  574. groupName: [
  575. { required: true, message: "请输入表格组名", trigger: "blur" },
  576. ],
  577. groupDescription: [
  578. { required: true, message: "请输入表格描述", trigger: "blur" },
  579. ],
  580. routePath: [
  581. { required: true, message: "请选择路由", trigger: "change" },
  582. ],
  583. },
  584. menuOrderNum: 0,
  585. // 关联方式
  586. relaTypeList: [
  587. {
  588. label: "等值连接",
  589. value: "INNER JOIN",
  590. },
  591. {
  592. label: "左连接",
  593. value: "LEFT JOIN",
  594. },
  595. {
  596. label: "右连接",
  597. value: "RIGHT JOIN",
  598. },
  599. ],
  600. searchFieldList: [],
  601. // 依赖字段
  602. relyFiledsList: [],
  603. // 修改row
  604. updataGroupRow: {},
  605. // 遮罩层
  606. loading: false,
  607. // 选中数组
  608. ids: [],
  609. menuIds: [],
  610. // 选中数组(包含所有数据)
  611. selection: [],
  612. Keys: [],
  613. // 非单个禁用
  614. single: true,
  615. // 非多个禁用
  616. multiple: true,
  617. // 显示搜索条件
  618. showSearch: true,
  619. // 总条数
  620. total: 0,
  621. tableList: [], //所有表格列表
  622. // 弹出层标题
  623. title: "",
  624. // 是否显示弹出层
  625. open: false,
  626. // 查询参数
  627. queryParams: {
  628. groupType: 0,
  629. pageNum: 1,
  630. pageSize: 10,
  631. dtName: null,
  632. dtNickname: null,
  633. tableKey: null,
  634. sqlKey: null,
  635. dtTableName: null,
  636. dtNotes: null,
  637. dtColumnName: null,
  638. timeFormat: null,
  639. spare: null,
  640. spare1: null,
  641. isSelection: null,
  642. },
  643. // 表单参数
  644. form: {},
  645. // 表单校验
  646. rules: {},
  647. // dialog弹窗数据
  648. isShowTable: false,
  649. isShowForm: false,
  650. // 新增关联表数据
  651. tableDataList: [],
  652. tableFieldList: [], // 当前表格字段数据
  653. tableName: "", // 当前表名称
  654. selectFields: "", //关联字段
  655. relateTitle: true,
  656. relateTableName: "", //关联表名称
  657. relateFields: "", //子集关联字段
  658. relateFieldList: [], //子集关联字段数据
  659. groupTitle: true,
  660. tableItemForm: {
  661. tId: "",
  662. rowId: "",
  663. title: "",
  664. tableName: "",
  665. selectFields: "",
  666. isAsc: false,
  667. timeFormate: "",
  668. orderByColumn: "",
  669. },
  670. tableGroupList: [],
  671. // 成员表格提示
  672. tableKeyContent: "",
  673. groupsMenuId: "",
  674. // 修改表格时的menuId
  675. menuId: "",
  676. // 修改是表格的id
  677. groupId: "",
  678. serachIndex: "",
  679. //修改数据回显
  680. echogroup: {},
  681. };
  682. },
  683. async created() {
  684. this.getTableList();
  685. },
  686. async mounted() {
  687. await this.getMenuList();
  688. },
  689. computed: {
  690. selectRelate() {
  691. if (this.tableItemForm.tableName == "") return;
  692. return this.tableList.filter(
  693. (item) => item.tableName !== this.tableItemForm.tableName
  694. );
  695. },
  696. dataArr() {
  697. return this.tableFieldList.filter((item) => item.isShow);
  698. },
  699. ...mapGetters(["addRoutes"]),
  700. ...mapState({
  701. databaseName: (state) => state.user.dataSource.databaseName,
  702. databaseType: (state) => state.user.dataSource.databaseType,
  703. username: (state) => state.user.dataSource.username,
  704. tenantId: (state) => state.user.tenant.tenantId,
  705. }),
  706. orderByFieldList() {
  707. return this.tableFieldList;
  708. },
  709. },
  710. watch: {
  711. "tableItemForm.tableName": function (val) {
  712. if (val) {
  713. this.relationTableList = this.tableList
  714. .filter((item) => item.tableName != val)
  715. .map((item) => {
  716. return {
  717. tableName: item.tableName,
  718. tableComment: item.tableComment,
  719. };
  720. });
  721. } else {
  722. this.relaiptChangetableItemRulestionTableList = [];
  723. }
  724. },
  725. "groupForm.routePath"(nval, oval) {
  726. let targetMenu = this.getTargetMenu(this.menus);
  727. this.menuOrderNum = targetMenu.children ? targetMenu.children.length : 0;
  728. },
  729. },
  730. methods: {
  731. iptChange() {
  732. this.$forceUpdate(); //强制刷新
  733. },
  734. async getTableList() {
  735. let res = await listGroup(this.queryParams);
  736. this.total = res.total;
  737. let info = [];
  738. res.rows.forEach((item) => {
  739. item.groupCount = JSON.parse(item.groupTableInfo).length;
  740. info = JSON.parse(item.groupTableInfo);
  741. this.groupsMenuId = info[0].menuId;
  742. item.menuId = info[0].menuId;
  743. item.groupTableInfo = info;
  744. });
  745. // console.log(info);
  746. this.tableGroupList = res.rows;
  747. // console.log(this.tableGroupList)
  748. },
  749. // 是否包含查询switch
  750. isSearchChange(status, row, index) {
  751. this.serachIndex = index;
  752. this.isSearchIndex = row.tableName + "." + row.fieldName;
  753. if (!status) {
  754. delete this.conditionDefault[this.isSearchIndex];
  755. }
  756. this.isSearchDialog = status;
  757. this.conditionDefaultValueMap = "";
  758. },
  759. // 添加依赖字段取消
  760. isSearchCancel() {
  761. this.relyOption = null;
  762. this.conditionDefaultValueMap = "";
  763. this.isSearchDialog = false;
  764. this.tableFieldList[this.serachIndex].isSearch = false;
  765. },
  766. isSearchBtn() {
  767. if (this.relyOption == 0) {
  768. this.conditionDefault[this.isSearchIndex] =
  769. this.conditionDefaultValueMap;
  770. } else {
  771. if (this.tableDataList.length !== 0) {
  772. this.relyFileds.tableName =
  773. this.tableDataList[this.editIndex - 1]?.dtTableName;
  774. }
  775. this.conditionDefault[this.isSearchIndex] =
  776. "#{" +
  777. this.relyFileds.tableName +
  778. "." +
  779. this.conditionDefaultValueMap;
  780. }
  781. this.isSearchDialog = false;
  782. this.conditionDefaultValueMap = "";
  783. this.relyFileds.tableName = "";
  784. },
  785. // 获取路由表单数据
  786. async getMenuList() {
  787. let res = await listGroup();
  788. this.menus = this.handleTree(res.data, "menuId");
  789. },
  790. // 递归拼接查询语句
  791. getSQLString(tableFieldList, fieldArr, tableArr, sqlType = "mysql") {
  792. let prefix = "{DBNAME}.";
  793. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  794. for (let i = 0; i < tableFieldList.length; i++) {
  795. let temp = tableFieldList[i];
  796. if (temp.isShow) {
  797. let tempArr = prefix + temp.tableName + "." + temp.fieldName;
  798. if (temp.isChildren) {
  799. tempArr += asOrSpace + temp.tableName + "_" + temp.fieldName;
  800. }
  801. fieldArr.push(tempArr);
  802. }
  803. if (temp.relationTable && temp.relationFieldName && temp.relationType) {
  804. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  805. tableArr.push(
  806. temp.relationType +
  807. " " +
  808. isNeedUsername +
  809. prefix +
  810. temp.relationTable +
  811. asOrSpace +
  812. temp.relationTable +
  813. " ON " +
  814. prefix +
  815. temp.relationTable +
  816. "." +
  817. temp.relationFieldName +
  818. " = " +
  819. prefix +
  820. temp.tableName +
  821. "." +
  822. temp.fieldName
  823. );
  824. }
  825. }
  826. // 如果主键不包含显示,则添加至sql语句中
  827. let isNotInclude = this.tableFieldList.find(
  828. (val) => !val.isShow && val.fieldName == this.tableItemForm.selectFields
  829. );
  830. if (isNotInclude) {
  831. fieldArr.push(
  832. prefix + isNotInclude.tableName + "." + isNotInclude.fieldName
  833. );
  834. }
  835. },
  836. // 拼接查询sql语句
  837. getSQLStr() {
  838. let prefix = "{DBNAME}.";
  839. let sqlType = this.databaseType; //数据库类型
  840. // let sqlType = "oracle";
  841. let sql = "";
  842. // mysql
  843. sql += "SELECT ";
  844. let fieldNameArr = [],
  845. relaTypeArr = [];
  846. this.getSQLString(
  847. this.tableFieldList,
  848. fieldNameArr,
  849. relaTypeArr,
  850. sqlType
  851. );
  852. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  853. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  854. sql +=
  855. fieldNameArr.join(",") +
  856. " FROM " +
  857. isNeedUsername +
  858. prefix +
  859. this.tableItemForm.tableName +
  860. asOrSpace +
  861. this.tableItemForm.tableName;
  862. if (relaTypeArr.length) {
  863. sql += " " + relaTypeArr.join(" ");
  864. }
  865. return sql;
  866. },
  867. /** 查询列表 */
  868. getList(queryParams) {
  869. if (!this.tableItemForm.tableName) return;
  870. let data = {
  871. databaseName: this.databaseName,
  872. databaseType: this.databaseType,
  873. tableName: this.tableItemForm.tableName,
  874. };
  875. // 获取当前表单结构信息
  876. getListName(data).then((res) => {
  877. this.tableFieldList = res.map((item, index) => {
  878. return {
  879. id: this.tableItemForm.tableName + "_" + item.fieldName,
  880. fieldName: item.fieldName,
  881. fieldDescription: item.fieldDescription,
  882. relationTable: "",
  883. relationFieldName: "",
  884. relaFieldNameList: [],
  885. disableRelaFieldName: false,
  886. relationType: "",
  887. relationShowField: [],
  888. relationShowFiledList: [],
  889. disableRelaType: false,
  890. isShow: true,
  891. isSearch: false,
  892. isExport: true,
  893. relationTableList: this.relationTableList,
  894. tableName: this.tableItemForm.tableName,
  895. relationFieldList: [],
  896. };
  897. });
  898. });
  899. },
  900. // 关联表变化回调
  901. async ralationTableChange(row) {
  902. this.tableFieldList = this.tableFieldList.filter((item) => {
  903. return !row.relationFieldList.some((val) => {
  904. return val.id == item.id;
  905. });
  906. });
  907. row.relationFieldName = "";
  908. row.relationType = "";
  909. row.disableRelaFieldName = false;
  910. row.disableRelaType = false;
  911. row.relationFieldList = [];
  912. if (!row.relationTable) {
  913. return;
  914. }
  915. // 获取关联表的字段
  916. let data = {
  917. databaseName: this.databaseName,
  918. databaseType: this.databaseType,
  919. tableName: row.relationTable,
  920. };
  921. let res = await getListName(data);
  922. // 关联字段下拉列表数据
  923. row.relaFieldNameList = res.map((item) => {
  924. return {
  925. fieldName: item.fieldName,
  926. fieldDescription: item.fieldDescription,
  927. };
  928. });
  929. let relationTableList = row.relationTableList.filter(
  930. (item) => row.relationTable != item.tableName
  931. );
  932. row.relationFieldList = row.relaFieldNameList.map((item, index) => {
  933. return {
  934. id: row.relationTable + "_" + item.fieldName,
  935. fieldName: item.fieldName,
  936. fieldDescription: item.fieldDescription,
  937. relationTable: "",
  938. relationFieldName: "",
  939. relaFieldNameList: [],
  940. disableRelaFieldName: false,
  941. relationType: "",
  942. relationShowField: [],
  943. relationShowFiledList: [],
  944. disableRelaType: false,
  945. isShow: true,
  946. isSearch: false,
  947. isExport: true,
  948. relationTableList,
  949. tableName: row.relationTable,
  950. relationFieldList: [],
  951. isChildren: true,
  952. };
  953. });
  954. row.disableRelaFieldName = true;
  955. },
  956. // 关联类型变化回调
  957. relationTypeChangeHandler(row) {
  958. let tempRelationFieldList = row.relationFieldList.filter((item) => {
  959. return !this.tableFieldList.find((val) => val.id === item.id);
  960. });
  961. this.tableFieldList = [...this.tableFieldList, ...tempRelationFieldList];
  962. },
  963. // 关联字段回调
  964. relationFieldChange(row) {
  965. if (!row.relationFieldName) {
  966. row.relationType = "";
  967. row.disableRelaType = false;
  968. row.relaFieldNameList = [];
  969. return;
  970. }
  971. row.disableRelaType = true;
  972. },
  973. // 递归获取列表信息
  974. getCol(
  975. tableFieldList,
  976. columns,
  977. searchFieldList = [],
  978. tableExportField = {}
  979. ) {
  980. if (!tableFieldList.length) return;
  981. for (let i = 0; i < tableFieldList.length; i++) {
  982. let temp = tableFieldList[i];
  983. let tempFieldName = "",
  984. exportFieldName = "";
  985. if (temp.isChildren) {
  986. tempFieldName = temp.tableName + "_" + temp.fieldName;
  987. exportFieldName = temp.tableName + "@" + temp.fieldName;
  988. } else {
  989. tempFieldName = temp.fieldName;
  990. exportFieldName = temp.fieldName;
  991. }
  992. if (temp.isShow) {
  993. let tempObj = {};
  994. tempObj[tempFieldName] = temp.fieldDescription;
  995. columns.push(tempObj);
  996. }
  997. if (temp.isSearch) {
  998. searchFieldList.push(temp.tableName + "." + temp.fieldName);
  999. }
  1000. if (temp.isExport) {
  1001. tableExportField[exportFieldName] = temp.fieldDescription;
  1002. }
  1003. }
  1004. },
  1005. // 获取所有表格
  1006. async getAllTable() {
  1007. let data = {
  1008. databaseName: this.databaseName,
  1009. databaseType: this.databaseType,
  1010. };
  1011. let res = await getFormName(data);
  1012. const baseTable = await this.getDicts("base_table");
  1013. this.tableList = res.data.filter((item) => {
  1014. return !baseTable.data.some(
  1015. (value) =>
  1016. value.dictValue.toLowerCase() == item.tableName.toLowerCase()
  1017. );
  1018. });
  1019. },
  1020. // 确认添加一个表格
  1021. confirmAddHandler(formName) {
  1022. this.$refs[formName].validate((valid) => {
  1023. if (valid) {
  1024. let columns = [],
  1025. searchFieldList = [];
  1026. this.getCol(this.tableFieldList, columns, searchFieldList);
  1027. // 判断是否有包含查询字段
  1028. if (!searchFieldList.length) {
  1029. this.$message.warning("请至少选择一个包含查询字段");
  1030. return false;
  1031. }
  1032. let echoData = {};
  1033. // 判断修改还是新增
  1034. if (this.relateTitle) {
  1035. echoData = {
  1036. tableName: this.tableItemForm.tableName,
  1037. tableFieldData: this.tableFieldList,
  1038. };
  1039. console.log(echoData);
  1040. let tableKey = uuidv4();
  1041. let sqlKey = uuidv4();
  1042. this.relyFileds.tableFieldList = this.tableFieldList;
  1043. this.relyFileds.tableName = this.tableItemForm.tableName;
  1044. this.tableItemForm.rowId = Date.now();
  1045. this.tableDataList.push({
  1046. dtName: this.tableItemForm.title,
  1047. dtTableName: this.tableItemForm.tableName,
  1048. rowId: this.tableItemForm.rowId,
  1049. selectFields: this.tableItemForm.selectFields,
  1050. orderByColumn: this.tableItemForm.orderByColumn,
  1051. timeFormate: this.tableItemForm.timeFormate,
  1052. primaryKey: this.tableItemForm.selectFields,
  1053. rowId: this.tableItemForm.rowId,
  1054. tId: this.tId,
  1055. tableKey: tableKey,
  1056. sortOrder: this.tableItemForm.isAsc,
  1057. sqlKey: sqlKey,
  1058. dtColumnName: columns,
  1059. timeFormat: "yyyy-MM-dd",
  1060. searchFieldList: searchFieldList,
  1061. conditionDefaultValueMap: this.conditionDefault,
  1062. tableSql: this.getSQLStr(),
  1063. tableExportField: "",
  1064. echoData: JSON.stringify(echoData),
  1065. });
  1066. // 选择依赖字段
  1067. this.groupList.push({
  1068. tableFieldList: this.tableFieldList,
  1069. tableItemForm: this.tableItemForm,
  1070. conditionDefaultValueMap: this.conditionDefaultValueMap,
  1071. });
  1072. if (this.groupTitle) {
  1073. this.addDragData.push({
  1074. rowId: this.tableItemForm.rowId,
  1075. tId: this.tId,
  1076. dtName: this.tableItemForm.title,
  1077. tableKey: tableKey,
  1078. dtTableName: this.tableItemForm.tableName,
  1079. primaryKey: this.tableItemForm.selectFields,
  1080. orderByColumn: this.tableItemForm.orderByColumn,
  1081. sortOrder: this.tableItemForm.isAsc,
  1082. sqlKey: sqlKey,
  1083. dtColumnName: columns,
  1084. timeFormat: "yyyy-MM-dd",
  1085. searchFieldList: searchFieldList,
  1086. conditionDefaultValueMap: this.conditionDefault,
  1087. tableSql: this.getSQLStr(),
  1088. tableExportField: "",
  1089. echoData: JSON.stringify(echoData),
  1090. });
  1091. }
  1092. } else {
  1093. echoData = {
  1094. tableName: this.tableItemForm.tableName,
  1095. tableFieldData: this.tableFieldList,
  1096. };
  1097. console.log("123456", echoData);
  1098. this.tableDataList.forEach((item, index) => {
  1099. if (item.tId == this.tableItemForm.tId) {
  1100. item.conditionDefaultValueMap = this.conditionDefault;
  1101. console.log(this.conditionDefault);
  1102. item.echoData = JSON.stringify(echoData);
  1103. item.sortOrder = this.tableItemForm.isAsc;
  1104. item.orderByColumn = this.tableItemForm.orderByColumn;
  1105. item.primaryKey = this.tableItemForm.selectFields;
  1106. item.dtTableName = this.tableItemForm.tableName;
  1107. item.dtName = this.tableItemForm.title;
  1108. item.dtColumnName = JSON.stringify(columns);
  1109. item.searchFieldList = searchFieldList;
  1110. }
  1111. });
  1112. }
  1113. this.isShowForm = false;
  1114. echoData = {};
  1115. this.tableItemForm = {};
  1116. this.tableFieldList = [];
  1117. this.relyFiledsList = [];
  1118. this.conditionDefault = {};
  1119. this.conditionDefaultValueMap = "";
  1120. this.formdata.conditionDefaultValueMap = {};
  1121. } else {
  1122. this.$message.error("请完善表单信息");
  1123. return false;
  1124. }
  1125. });
  1126. },
  1127. // 修改一个表格数据
  1128. relateOne(row, index) {
  1129. this.editIndex = index;
  1130. console.log(row);
  1131. // console.log(this.orderByFieldList)
  1132. if (row.tableKey) {
  1133. this.menuId = row.menuId;
  1134. this.conditionDefault = row.conditionDefaultValueMap;
  1135. let echoData = JSON.parse(row.echoData);
  1136. console.log(this.tableDataList);
  1137. this.tableDataList.forEach((item, index) => {
  1138. if (item.tableKey == row.tableKey) {
  1139. if (index == 0) {
  1140. this.relyFileds.tableFieldList = "";
  1141. } else {
  1142. let beforeEcho = JSON.parse(
  1143. this.tableDataList[index - 1].echoData
  1144. );
  1145. this.relyFileds.tableFieldList = beforeEcho.tableFieldData;
  1146. }
  1147. }
  1148. });
  1149. this.tableFieldList = echoData.tableFieldData;
  1150. this.tableItemForm.tId = row.tId;
  1151. this.tableItemForm.rowId = row.tableKey;
  1152. this.tableItemForm.isAsc = false;
  1153. this.tableItemForm.orderByColumn = row.orderByColumn;
  1154. this.tableItemForm.title = row.dtName;
  1155. this.tableItemForm.tableName = row.dtTableName;
  1156. this.tableItemForm.selectFields = row.primaryKey;
  1157. this.tableItemForm.timeFormate = row.timeFormat;
  1158. } else {
  1159. (this.tableItemForm.rowId = row.rowId),
  1160. (this.tableItemForm.title = row.dtName);
  1161. this.tableItemForm.selectFields = row.selectFields;
  1162. this.tableItemForm.tableName = row.dtTableName;
  1163. this.tableItemForm.orderByColumn = row.orderByColumn;
  1164. this.tableItemForm.timeFormate = row.timeFormat;
  1165. this.getList();
  1166. this.groupList.forEach((item) => {
  1167. if (item.tableItemForm.rowId == row.rowId) {
  1168. item.tableFieldList = this.tableFieldList;
  1169. }
  1170. });
  1171. }
  1172. this.getAllTable();
  1173. // console.log('修改', this.groupList);
  1174. // 展示字段的回显
  1175. this.relateTitle = false;
  1176. this.isShowForm = true;
  1177. },
  1178. // 删除表格组
  1179. DeleteTableGroup(row) {
  1180. const fIds = row.id || this.ids;
  1181. const menus = row.menuId || this.menuIds;
  1182. this.$modal
  1183. .confirm(
  1184. '是否确认删除动态单编号为"' +
  1185. fIds +
  1186. '"的数据项?删除后表格中所有的数据都将删除!'
  1187. )
  1188. .then(function () {
  1189. return delMenu(menus);
  1190. })
  1191. .then(async () => {
  1192. await delGroup(fIds);
  1193. this.getTableList();
  1194. this.reloadRouter();
  1195. await getRouters();
  1196. this.$modal.msgSuccess("删除成功");
  1197. })
  1198. .catch(() => {});
  1199. },
  1200. // 取消新增
  1201. cancelAddHandler() {
  1202. this.isShowForm = false;
  1203. this.tableItemForm = {};
  1204. this.tableFieldList = [];
  1205. },
  1206. // 关联类型变化回调
  1207. relationTypeChangeHandler(row) {
  1208. let tempRelationFieldList = row.relationFieldList.filter((item) => {
  1209. return !this.tableFieldList.find((val) => val.id === item.id);
  1210. });
  1211. this.tableFieldList = [...this.tableFieldList, ...tempRelationFieldList];
  1212. },
  1213. // 更新路由
  1214. reloadRouter() {
  1215. this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
  1216. this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
  1217. });
  1218. },
  1219. // 获取目标menu
  1220. getTargetMenu(menus) {
  1221. for (let i = 0; i < menus.length; i++) {
  1222. if (menus[i].menuId == this.groupForm.routePath) {
  1223. return menus[i];
  1224. } else if (menus.children?.length) {
  1225. return this.getTargetMenu(menus.children);
  1226. }
  1227. }
  1228. return false;
  1229. },
  1230. // 获取父级menuId
  1231. getParentMenuId(menuId, menus) {
  1232. let res;
  1233. for (let i = 0; i < menus.length; i++) {
  1234. let item = menus[i];
  1235. if (item.menuId == menuId) {
  1236. res = item.parentId;
  1237. break;
  1238. } else if (item.children?.length) {
  1239. if (
  1240. this.getParentMenuId(
  1241. menuId,
  1242. JSON.parse(JSON.stringify(item.children))
  1243. )
  1244. ) {
  1245. res = this.getParentMenuId(
  1246. menuId,
  1247. JSON.parse(JSON.stringify(item.children))
  1248. );
  1249. }
  1250. }
  1251. }
  1252. return res;
  1253. },
  1254. // 修改表格回显数据
  1255. async initTableData(tId) {
  1256. let res = await getTableInfo(tId);
  1257. console.log("回显数据", res);
  1258. if (res.code == 200) {
  1259. if (!this.formData.routePath) {
  1260. this.$message.warning("该表格菜单路由已经删除,请重新配置");
  1261. }
  1262. // this.formData.routePath
  1263. this.editData = res.data;
  1264. let val = await getParticMenu(res.data.tableKey);
  1265. if (val.code == 200) {
  1266. this.menuId = val.data.menuId;
  1267. }
  1268. } else {
  1269. this.$message.error("数据回显失败");
  1270. }
  1271. },
  1272. // 新增动态表格组
  1273. addTableGroup(formName) {
  1274. this.$refs[formName].validate(async (valid) => {
  1275. if (valid) {
  1276. // console.log('groupList', this.groupList);
  1277. if (this.addDragData.length < 2) {
  1278. this.$message.error("请包含多个表格");
  1279. return;
  1280. }
  1281. if (this.groupTitle) {
  1282. let uuid = uuidv4();
  1283. let groupKeyObj = {
  1284. groupKey: uuid,
  1285. };
  1286. let payLoad = {
  1287. component: "relateTable/relateTableEdit",
  1288. icon: "",
  1289. isCache: "0",
  1290. isFrame: "1",
  1291. menuName: this.groupForm.groupName,
  1292. menuType: "C",
  1293. orderNum: this.menuOrderNum,
  1294. parentId: this.groupForm.routePath,
  1295. path: groupKeyObj.groupKey,
  1296. query: JSON.stringify(groupKeyObj),
  1297. status: "0",
  1298. visible: "0",
  1299. tenantId: this.tenantId,
  1300. };
  1301. let result;
  1302. result = await addMenu(payLoad);
  1303. if (result.code == 200) {
  1304. this.reloadRouter();
  1305. let data = {
  1306. groupKey: groupKeyObj.groupKey,
  1307. groupName: "",
  1308. groupDescription: "",
  1309. groupTableInfo: [],
  1310. dragTables: [],
  1311. };
  1312. console.log(this.addDragData);
  1313. // return;
  1314. this.addDragData.forEach((item, index) => {
  1315. item.menuId = result.data;
  1316. // item.sqlKey = tableKeyObj.tableKey
  1317. let echo = JSON.parse(item.echoData);
  1318. console.log(echo);
  1319. echo.formData = this.groupForm;
  1320. // item.echoData = JSON.stringify(echo)
  1321. data.groupTableInfo.push({
  1322. tableKey: item.tableKey,
  1323. sort: index,
  1324. tablename: item.dtTableName,
  1325. menuId: result.data,
  1326. });
  1327. });
  1328. data.groupName = this.groupForm.groupName;
  1329. data.groupDescription = this.groupForm.groupDescription;
  1330. data.groupTableInfo = JSON.stringify(data.groupTableInfo);
  1331. data.dragTables = this.addDragData;
  1332. // 添加表格组
  1333. let res = await addGroup(data);
  1334. console.log(res);
  1335. if (res.code == 200) {
  1336. this.$message.success("创建成功");
  1337. this.isShowTable = false;
  1338. this.groupForm = {};
  1339. } else {
  1340. this.$message.success("创建失败");
  1341. this.isShowTable = false;
  1342. this.groupForm = {};
  1343. }
  1344. }
  1345. } else {
  1346. let data = {
  1347. groupKey: this.echogroup.groupKey,
  1348. groupName: "",
  1349. groupDescription: "",
  1350. groupTableInfo: [],
  1351. dragTables: [],
  1352. id: this.groupId,
  1353. };
  1354. this.addDragData.forEach((item, index) => {
  1355. // item.sqlKey = tableKeyObj.tableKey
  1356. let echo = JSON.parse(item.echoData);
  1357. // echo.formData = this.groupForm
  1358. // console.log(echo);
  1359. item.echoData = JSON.stringify(echo);
  1360. data.groupTableInfo.push({
  1361. tableKey: item.tableKey,
  1362. sort: index,
  1363. tablename: item.dtTableName,
  1364. menuId: item.menuId,
  1365. });
  1366. });
  1367. data.groupName = this.groupForm.groupName;
  1368. data.groupDescription = this.groupForm.groupDescription;
  1369. data.groupTableInfo = JSON.stringify(data.groupTableInfo);
  1370. data.dragTables = this.addDragData;
  1371. console.log(data);
  1372. let res = await updataGroup(data);
  1373. if (res.code == 200) {
  1374. let payLoad = {
  1375. menuId: this.menuId,
  1376. menuName: this.groupForm.groupName,
  1377. parentId: this.groupForm.routePath,
  1378. component: "relateTable/relateTableEdit",
  1379. icon: "",
  1380. isCache: "0",
  1381. isFrame: "1",
  1382. menuType: "C",
  1383. orderNum: this.menuOrderNum,
  1384. status: "0",
  1385. visible: "0",
  1386. tenantId: this.tenantId,
  1387. };
  1388. let result = await updateMenu(payLoad);
  1389. if (result.code == 200) {
  1390. this.$message.success("修改成功");
  1391. this.isShowTable = false;
  1392. this.groupForm = {};
  1393. } else {
  1394. this.$message.success("修改失败");
  1395. this.isShowTable = false;
  1396. this.groupForm = {};
  1397. }
  1398. }
  1399. }
  1400. this.isShowTable = false;
  1401. this.addDragData = [];
  1402. this.groupForm = {};
  1403. this.tableDataList = [];
  1404. this.reloadRouter();
  1405. this.getTableList();
  1406. } else {
  1407. this.$message.error("请完善表单信息");
  1408. return false;
  1409. }
  1410. });
  1411. },
  1412. /** 新增按钮操作 */
  1413. async handleAdd() {
  1414. await this.getMenuList();
  1415. if (this.groupTitle) {
  1416. this.groupForm.groupName = "";
  1417. this.groupForm.groupDescription = "";
  1418. this.groupForm.routePath = undefined;
  1419. this.tableDataList = [];
  1420. }
  1421. this.groupTitle = true;
  1422. this.isShowTable = true;
  1423. },
  1424. // 取消
  1425. cancelGroup() {
  1426. this.groupTitle = true;
  1427. this.isShowTable = false;
  1428. },
  1429. // 获取路由表单数据
  1430. async getMenuList() {
  1431. let res = await getMenuList();
  1432. this.menus = this.handleTree(res.data, "menuId");
  1433. },
  1434. /** 转换菜单数据结构 */
  1435. normalizer(node) {
  1436. if (node.children && !node.children.length) {
  1437. delete node.children;
  1438. }
  1439. return {
  1440. id: node.menuId,
  1441. label: node.menuName,
  1442. children: node.children,
  1443. };
  1444. },
  1445. // 修改动态表格组回显
  1446. async UpdateTableGroup(row) {
  1447. await this.getMenuList();
  1448. // let id = JSON.parse(row.id)
  1449. getTable({ id: row.id }).then((res) => {
  1450. this.echogroup = res.data;
  1451. this.groupId = res.data.id;
  1452. // 关联表格
  1453. this.groupTableInfo = JSON.parse(res.data.groupTableInfo);
  1454. this.menuId = res.data.dragTables[0].menuId;
  1455. this.groupForm = res.data;
  1456. // res.data.dragTables.forEach(item => {
  1457. // if(item.orderByColumn.includes('.')){
  1458. // item.orderByColumn = item.orderByColumn.split('.')[1]
  1459. // }
  1460. // })
  1461. this.addDragData = res.data.dragTables;
  1462. // 菜单路由回显
  1463. this.tableDataList = this.groupForm.dragTables;
  1464. this.groupForm.routePath = this.getParentMenuId(
  1465. res.data.dragTables[0].menuId,
  1466. this.menus,
  1467. {}
  1468. );
  1469. if (!this.groupForm.routePath) {
  1470. this.$message.warning("该表格菜单路由已经删除,请重新配置");
  1471. }
  1472. });
  1473. this.groupTitle = false;
  1474. this.isShowTable = true;
  1475. },
  1476. // 取消按钮
  1477. cancel() {
  1478. this.open = false;
  1479. this.reset();
  1480. },
  1481. // 表单重置
  1482. reset() {
  1483. this.form = {
  1484. tId: null,
  1485. dtName: null,
  1486. dtNickname: null,
  1487. tableKey: null,
  1488. sqlKey: null,
  1489. dtTableName: null,
  1490. dtNotes: null,
  1491. dtColumnName: null,
  1492. timeFormat: null,
  1493. spare: null,
  1494. spare1: null,
  1495. delFlag: null,
  1496. createBy: null,
  1497. createTime: null,
  1498. updateBy: null,
  1499. updateTime: null,
  1500. isSelection: null,
  1501. };
  1502. this.resetForm("form");
  1503. },
  1504. /** 搜索按钮操作 */
  1505. handleQuery() {
  1506. this.queryParams.pageNum = 1;
  1507. this.getList();
  1508. },
  1509. /** 重置按钮操作 */
  1510. resetQuery() {
  1511. this.resetForm("queryForm");
  1512. this.getTableList();
  1513. },
  1514. // 多选框选中数据
  1515. handleSelectionChange(selection) {
  1516. console.log(selection);
  1517. this.ids = selection.map((item) => item.id);
  1518. this.Keys = selection.map((item) => item.sqlKey);
  1519. selection.forEach((vals) => {
  1520. this.menuIds = vals.groupTableInfo.map((item) => item.menuId);
  1521. console.log(this.menuIds);
  1522. });
  1523. this.selection = selection;
  1524. this.single = selection.length !== 1;
  1525. this.multiple = !selection.length;
  1526. },
  1527. /** 修改按钮操作 */
  1528. async handleUpdate(row) {
  1529. // 兼容勾选单个的修改
  1530. let tId = row?.tId || this.ids[0];
  1531. // this.$router.push({
  1532. // path: "/system/fromModel/index/tableMange",
  1533. // query: {
  1534. // tId: tId,
  1535. // },
  1536. // });
  1537. },
  1538. /** 提交按钮 */
  1539. submitForm() {
  1540. this.$refs["form"].validate((valid) => {
  1541. if (valid) {
  1542. if (this.form.tId != null) {
  1543. updateTable(this.form).then((response) => {
  1544. this.$modal.msgSuccess("修改成功");
  1545. this.open = false;
  1546. this.getList();
  1547. });
  1548. } else {
  1549. addTable(this.form).then((response) => {
  1550. this.$modal.msgSuccess("新增成功");
  1551. this.open = false;
  1552. this.getList();
  1553. });
  1554. }
  1555. }
  1556. });
  1557. },
  1558. /** 删除按钮操作 */
  1559. handleDelete(row) {
  1560. console.log(row);
  1561. this.tableDataList.forEach((item, index) => {
  1562. if (row.tableKey == item.tableKey) {
  1563. this.tableDataList.splice(index, 1);
  1564. }
  1565. });
  1566. },
  1567. // 更新路由
  1568. reloadRouter() {
  1569. this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
  1570. this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
  1571. });
  1572. },
  1573. // 新增一个联动表格
  1574. addOneTable() {
  1575. this.relateTitle = true;
  1576. if (this.relateTitle) {
  1577. this.tableItemForm = {};
  1578. this.tableFieldList = [];
  1579. this.conditionDefaultValueMap = "";
  1580. }
  1581. if (!this.groupTitle) {
  1582. // console.log(this.tableDataList[this.tableDataList.length-1].dtTableName)
  1583. this.relyFileds.tableName =
  1584. this.tableDataList[this.tableDataList.length - 1].dtTableName;
  1585. let echoData = JSON.parse(
  1586. this.tableDataList[this.tableDataList.length - 1].echoData
  1587. );
  1588. this.relyFileds.tableFieldList = echoData.tableFieldData;
  1589. }
  1590. this.getAllTable();
  1591. // 注意校验最后一条数据是否合法
  1592. this.isShowForm = true;
  1593. },
  1594. // 重置表单
  1595. // tableItemFormReset() {
  1596. // Object.assign(this.tableItemForm, {
  1597. // title: "",
  1598. // tableId: "",
  1599. // tableName: "",
  1600. // showFields: [],
  1601. // theRelateField: "",
  1602. // executeOptions: [],
  1603. // });
  1604. // },
  1605. // handlePreview() {
  1606. // this.$router.push({
  1607. // path: "/system/fromModel/index/relateTableEdit",
  1608. // });
  1609. // },
  1610. },
  1611. };
  1612. </script>
  1613. <style scoped lang="scss">
  1614. ::v-deep .el-dialog:not(.is-fullscreen) {
  1615. width: 900px !important;
  1616. }
  1617. .isSearch {
  1618. ::v-deep .el-dialog:not(.is-fullscreen) {
  1619. width: 320px !important;
  1620. }
  1621. ::v-deep .el-input--medium .el-input__inner {
  1622. margin-bottom: 10px !important;
  1623. }
  1624. }
  1625. .tablefiled {
  1626. ::v-deep .el-input--medium .el-input__inner {
  1627. width: 70px !important;
  1628. }
  1629. }
  1630. ::v-deep .el-input--medium .el-input__inner {
  1631. width: 230px !important;
  1632. }
  1633. ::v-deep .btn {
  1634. text-align: right !important;
  1635. }
  1636. .ipt {
  1637. height: 36px;
  1638. line-height: 36px;
  1639. font-size: 14px;
  1640. width: 100%;
  1641. outline: none;
  1642. text-align: center;
  1643. background-color: #fff;
  1644. border: 1px solid #dcdfe6;
  1645. color: #606266;
  1646. display: inline-block;
  1647. border-radius: 4px;
  1648. }
  1649. .isNullDesc {
  1650. border-color: #ff4949 !important;
  1651. }
  1652. .ipt:focus {
  1653. border-color: #1890ff;
  1654. }
  1655. ::v-deep .vue-treeselect--has-value .vue-treeselect__input {
  1656. vertical-align: middle !important;
  1657. }
  1658. .formWrap {
  1659. display: flex;
  1660. justify-content: center;
  1661. }
  1662. ::v-deep .el-table {
  1663. margin-top: 10px;
  1664. }
  1665. .nameipt {
  1666. display: inline;
  1667. margin-left: 10px;
  1668. ::v-deep .el-input--medium .el-input__inner {
  1669. width: 30%;
  1670. }
  1671. ::v-deep .el-input--medium {
  1672. display: inline;
  1673. }
  1674. }
  1675. .desc {
  1676. margin-left: 10px;
  1677. }
  1678. ::v-deep .vue-treeselect--has-value .vue-treeselect__input {
  1679. vertical-align: middle !important;
  1680. }
  1681. .treeselect {
  1682. .vue-treeselect {
  1683. width: 230px !important;
  1684. }
  1685. }
  1686. </style>
  1687. <style lang="scss">
  1688. .vue-treeselect {
  1689. z-index: 9999 !important;
  1690. }
  1691. </style>