index.vue 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  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. console.log(111, this.relyFileds);
  758. this.conditionDefaultValueMap = "";
  759. },
  760. // 添加依赖字段取消
  761. isSearchCancel() {
  762. this.relyOption = null;
  763. this.conditionDefaultValueMap = "";
  764. this.isSearchDialog = false;
  765. this.tableFieldList[this.serachIndex].isSearch = false;
  766. },
  767. isSearchBtn() {
  768. if (this.relyOption == 0) {
  769. this.conditionDefault[this.isSearchIndex] =
  770. this.conditionDefaultValueMap;
  771. } else {
  772. if (this.tableDataList.length !== 0) {
  773. this.relyFileds.tableName =
  774. this.tableDataList[this.editIndex - 1]?.dtTableName;
  775. }
  776. this.conditionDefault[this.isSearchIndex] =
  777. "#{" +
  778. this.relyFileds.tableName +
  779. "." +
  780. this.conditionDefaultValueMap;
  781. }
  782. this.isSearchDialog = false;
  783. this.conditionDefaultValueMap = "";
  784. this.relyFileds.tableName = "";
  785. },
  786. // 获取路由表单数据
  787. async getMenuList() {
  788. let res = await listGroup();
  789. this.menus = this.handleTree(res.data, "menuId");
  790. },
  791. // 递归拼接查询语句
  792. getSQLString(tableFieldList, fieldArr, tableArr, sqlType = "mysql") {
  793. let prefix = "{DBNAME}.";
  794. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  795. for (let i = 0; i < tableFieldList.length; i++) {
  796. let temp = tableFieldList[i];
  797. if (temp.isShow) {
  798. let tempArr = prefix + temp.tableName + "." + temp.fieldName;
  799. if (temp.isChildren) {
  800. tempArr += asOrSpace + temp.tableName + "_" + temp.fieldName;
  801. }
  802. fieldArr.push(tempArr);
  803. }
  804. if (temp.relationTable && temp.relationFieldName && temp.relationType) {
  805. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  806. tableArr.push(
  807. temp.relationType +
  808. " " +
  809. isNeedUsername +
  810. prefix +
  811. temp.relationTable +
  812. asOrSpace +
  813. temp.relationTable +
  814. " ON " +
  815. prefix +
  816. temp.relationTable +
  817. "." +
  818. temp.relationFieldName +
  819. " = " +
  820. prefix +
  821. temp.tableName +
  822. "." +
  823. temp.fieldName
  824. );
  825. }
  826. }
  827. // 如果主键不包含显示,则添加至sql语句中
  828. let isNotInclude = this.tableFieldList.find(
  829. (val) => !val.isShow && val.fieldName == this.tableItemForm.selectFields
  830. );
  831. if (isNotInclude) {
  832. fieldArr.push(
  833. prefix + isNotInclude.tableName + "." + isNotInclude.fieldName
  834. );
  835. }
  836. },
  837. // 拼接查询sql语句
  838. getSQLStr() {
  839. let prefix = "{DBNAME}.";
  840. let sqlType = this.databaseType; //数据库类型
  841. // let sqlType = "oracle";
  842. let sql = "";
  843. // mysql
  844. sql += "SELECT ";
  845. let fieldNameArr = [],
  846. relaTypeArr = [];
  847. this.getSQLString(
  848. this.tableFieldList,
  849. fieldNameArr,
  850. relaTypeArr,
  851. sqlType
  852. );
  853. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  854. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  855. sql +=
  856. fieldNameArr.join(",") +
  857. " FROM " +
  858. isNeedUsername +
  859. prefix +
  860. this.tableItemForm.tableName +
  861. asOrSpace +
  862. this.tableItemForm.tableName;
  863. if (relaTypeArr.length) {
  864. sql += " " + relaTypeArr.join(" ");
  865. }
  866. return sql;
  867. },
  868. /** 查询列表 */
  869. getList(queryParams) {
  870. if (!this.tableItemForm.tableName) return;
  871. let data = {
  872. databaseName: this.databaseName,
  873. databaseType: this.databaseType,
  874. tableName: this.tableItemForm.tableName,
  875. };
  876. // 获取当前表单结构信息
  877. getListName(data).then((res) => {
  878. this.tableFieldList = res.map((item, index) => {
  879. return {
  880. id: this.tableItemForm.tableName + "_" + item.fieldName,
  881. fieldName: item.fieldName,
  882. fieldDescription: item.fieldDescription,
  883. relationTable: "",
  884. relationFieldName: "",
  885. relaFieldNameList: [],
  886. disableRelaFieldName: false,
  887. relationType: "",
  888. relationShowField: [],
  889. relationShowFiledList: [],
  890. disableRelaType: false,
  891. isShow: true,
  892. isSearch: false,
  893. isExport: true,
  894. relationTableList: this.relationTableList,
  895. tableName: this.tableItemForm.tableName,
  896. relationFieldList: [],
  897. };
  898. });
  899. });
  900. },
  901. // 关联表变化回调
  902. async ralationTableChange(row) {
  903. this.tableFieldList = this.tableFieldList.filter((item) => {
  904. return !row.relationFieldList.some((val) => {
  905. return val.id == item.id;
  906. });
  907. });
  908. row.relationFieldName = "";
  909. row.relationType = "";
  910. row.disableRelaFieldName = false;
  911. row.disableRelaType = false;
  912. row.relationFieldList = [];
  913. if (!row.relationTable) {
  914. return;
  915. }
  916. // 获取关联表的字段
  917. let data = {
  918. databaseName: this.databaseName,
  919. databaseType: this.databaseType,
  920. tableName: row.relationTable,
  921. };
  922. let res = await getListName(data);
  923. // 关联字段下拉列表数据
  924. row.relaFieldNameList = res.map((item) => {
  925. return {
  926. fieldName: item.fieldName,
  927. fieldDescription: item.fieldDescription,
  928. };
  929. });
  930. let relationTableList = row.relationTableList.filter(
  931. (item) => row.relationTable != item.tableName
  932. );
  933. row.relationFieldList = row.relaFieldNameList.map((item, index) => {
  934. return {
  935. id: row.relationTable + "_" + item.fieldName,
  936. fieldName: item.fieldName,
  937. fieldDescription: item.fieldDescription,
  938. relationTable: "",
  939. relationFieldName: "",
  940. relaFieldNameList: [],
  941. disableRelaFieldName: false,
  942. relationType: "",
  943. relationShowField: [],
  944. relationShowFiledList: [],
  945. disableRelaType: false,
  946. isShow: true,
  947. isSearch: false,
  948. isExport: true,
  949. relationTableList,
  950. tableName: row.relationTable,
  951. relationFieldList: [],
  952. isChildren: true,
  953. };
  954. });
  955. row.disableRelaFieldName = true;
  956. },
  957. // 关联类型变化回调
  958. relationTypeChangeHandler(row) {
  959. let tempRelationFieldList = row.relationFieldList.filter((item) => {
  960. return !this.tableFieldList.find((val) => val.id === item.id);
  961. });
  962. this.tableFieldList = [...this.tableFieldList, ...tempRelationFieldList];
  963. },
  964. // 关联字段回调
  965. relationFieldChange(row) {
  966. if (!row.relationFieldName) {
  967. row.relationType = "";
  968. row.disableRelaType = false;
  969. row.relaFieldNameList = [];
  970. return;
  971. }
  972. row.disableRelaType = true;
  973. },
  974. // 递归获取列表信息
  975. getCol(
  976. tableFieldList,
  977. columns,
  978. searchFieldList = [],
  979. tableExportField = {}
  980. ) {
  981. if (!tableFieldList.length) return;
  982. for (let i = 0; i < tableFieldList.length; i++) {
  983. let temp = tableFieldList[i];
  984. let tempFieldName = "",
  985. exportFieldName = "";
  986. if (temp.isChildren) {
  987. tempFieldName = temp.tableName + "_" + temp.fieldName;
  988. exportFieldName = temp.tableName + "@" + temp.fieldName;
  989. } else {
  990. tempFieldName = temp.fieldName;
  991. exportFieldName = temp.fieldName;
  992. }
  993. if (temp.isShow) {
  994. let tempObj = {};
  995. tempObj[tempFieldName] = temp.fieldDescription;
  996. columns.push(tempObj);
  997. }
  998. if (temp.isSearch) {
  999. searchFieldList.push(temp.tableName + "." + temp.fieldName);
  1000. }
  1001. if (temp.isExport) {
  1002. tableExportField[exportFieldName] = temp.fieldDescription;
  1003. }
  1004. }
  1005. },
  1006. // 获取所有表格
  1007. async getAllTable() {
  1008. let data = {
  1009. databaseName: this.databaseName,
  1010. databaseType: this.databaseType,
  1011. };
  1012. let res = await getFormName(data);
  1013. const baseTable = await this.getDicts("base_table");
  1014. this.tableList = res.data.filter((item) => {
  1015. return !baseTable.data.some(
  1016. (value) =>
  1017. value.dictValue.toLowerCase() == item.tableName.toLowerCase()
  1018. );
  1019. });
  1020. },
  1021. // 确认添加一个表格
  1022. confirmAddHandler(formName) {
  1023. this.$refs[formName].validate((valid) => {
  1024. if (valid) {
  1025. let columns = [],
  1026. searchFieldList = [];
  1027. this.getCol(this.tableFieldList, columns, searchFieldList);
  1028. // 判断是否有包含查询字段
  1029. if (!searchFieldList.length) {
  1030. this.$message.warning("请至少选择一个包含查询字段");
  1031. return false;
  1032. }
  1033. let echoData = {};
  1034. // 判断修改还是新增
  1035. if (this.relateTitle) {
  1036. echoData = {
  1037. tableName: this.tableItemForm.tableName,
  1038. tableFieldData: this.tableFieldList,
  1039. };
  1040. console.log(echoData);
  1041. let tableKey = uuidv4();
  1042. let sqlKey = uuidv4();
  1043. this.relyFileds.tableFieldList = this.tableFieldList;
  1044. this.relyFileds.tableName = this.tableItemForm.tableName;
  1045. this.tableItemForm.rowId = Date.now();
  1046. this.tableDataList.push({
  1047. dtName: this.tableItemForm.title,
  1048. dtTableName: this.tableItemForm.tableName,
  1049. rowId: this.tableItemForm.rowId,
  1050. selectFields: this.tableItemForm.selectFields,
  1051. orderByColumn: this.tableItemForm.orderByColumn,
  1052. timeFormate: this.tableItemForm.timeFormate,
  1053. primaryKey: this.tableItemForm.selectFields,
  1054. rowId: this.tableItemForm.rowId,
  1055. tId: this.tId,
  1056. tableKey: tableKey,
  1057. sortOrder: this.tableItemForm.isAsc,
  1058. sqlKey: sqlKey,
  1059. dtColumnName: columns,
  1060. timeFormat: "yyyy-MM-dd",
  1061. searchFieldList: searchFieldList,
  1062. conditionDefaultValueMap: this.conditionDefault,
  1063. tableSql: this.getSQLStr(),
  1064. tableExportField: "",
  1065. echoData: JSON.stringify(echoData),
  1066. });
  1067. // 选择依赖字段
  1068. this.groupList.push({
  1069. tableFieldList: this.tableFieldList,
  1070. tableItemForm: this.tableItemForm,
  1071. conditionDefaultValueMap: this.conditionDefaultValueMap,
  1072. });
  1073. if (this.groupTitle) {
  1074. this.addDragData.push({
  1075. rowId: this.tableItemForm.rowId,
  1076. tId: this.tId,
  1077. dtName: this.tableItemForm.title,
  1078. tableKey: tableKey,
  1079. dtTableName: this.tableItemForm.tableName,
  1080. primaryKey: this.tableItemForm.selectFields,
  1081. orderByColumn: this.tableItemForm.orderByColumn,
  1082. sortOrder: this.tableItemForm.isAsc,
  1083. sqlKey: sqlKey,
  1084. dtColumnName: columns,
  1085. timeFormat: "yyyy-MM-dd",
  1086. searchFieldList: searchFieldList,
  1087. conditionDefaultValueMap: this.conditionDefault,
  1088. tableSql: this.getSQLStr(),
  1089. tableExportField: "",
  1090. echoData: JSON.stringify(echoData),
  1091. });
  1092. }
  1093. } else {
  1094. echoData = {
  1095. tableName: this.tableItemForm.tableName,
  1096. tableFieldData: this.tableFieldList,
  1097. };
  1098. console.log("123456", echoData);
  1099. this.tableDataList.forEach((item, index) => {
  1100. if (item.tId == this.tableItemForm.tId) {
  1101. item.conditionDefaultValueMap = this.conditionDefault;
  1102. console.log(this.conditionDefault);
  1103. item.echoData = JSON.stringify(echoData);
  1104. item.sortOrder = this.tableItemForm.isAsc;
  1105. item.orderByColumn = this.tableItemForm.orderByColumn;
  1106. item.primaryKey = this.tableItemForm.selectFields;
  1107. item.dtTableName = this.tableItemForm.tableName;
  1108. item.dtName = this.tableItemForm.title;
  1109. item.dtColumnName = JSON.stringify(columns);
  1110. item.searchFieldList = searchFieldList;
  1111. }
  1112. });
  1113. }
  1114. this.isShowForm = false;
  1115. echoData = {};
  1116. this.tableItemForm = {};
  1117. this.tableFieldList = [];
  1118. this.relyFiledsList = [];
  1119. this.conditionDefault = {};
  1120. this.conditionDefaultValueMap = "";
  1121. this.formdata.conditionDefaultValueMap = {};
  1122. } else {
  1123. this.$message.error("请完善表单信息");
  1124. return false;
  1125. }
  1126. });
  1127. },
  1128. // 修改一个表格数据
  1129. relateOne(row, index) {
  1130. this.editIndex = index;
  1131. console.log(row);
  1132. // console.log(this.orderByFieldList)
  1133. if (row.tableKey) {
  1134. this.menuId = row.menuId;
  1135. this.conditionDefault = row.conditionDefaultValueMap;
  1136. let echoData = JSON.parse(row.echoData);
  1137. console.log(this.tableDataList);
  1138. this.tableDataList.forEach((item, index) => {
  1139. if (item.tableKey == row.tableKey) {
  1140. if (index == 0) {
  1141. this.relyFileds.tableFieldList = "";
  1142. } else {
  1143. let beforeEcho = JSON.parse(
  1144. this.tableDataList[index - 1].echoData
  1145. );
  1146. this.relyFileds.tableFieldList = beforeEcho.tableFieldData;
  1147. }
  1148. }
  1149. });
  1150. this.tableFieldList = echoData.tableFieldData;
  1151. this.tableItemForm.tId = row.tId;
  1152. this.tableItemForm.rowId = row.tableKey;
  1153. this.tableItemForm.isAsc = false;
  1154. this.tableItemForm.orderByColumn = row.orderByColumn;
  1155. this.tableItemForm.title = row.dtName;
  1156. this.tableItemForm.tableName = row.dtTableName;
  1157. this.tableItemForm.selectFields = row.primaryKey;
  1158. this.tableItemForm.timeFormate = row.timeFormat;
  1159. } else {
  1160. (this.tableItemForm.rowId = row.rowId),
  1161. (this.tableItemForm.title = row.dtName);
  1162. this.tableItemForm.selectFields = row.selectFields;
  1163. this.tableItemForm.tableName = row.dtTableName;
  1164. this.tableItemForm.orderByColumn = row.orderByColumn;
  1165. this.tableItemForm.timeFormate = row.timeFormat;
  1166. this.getList();
  1167. this.groupList.forEach((item) => {
  1168. if (item.tableItemForm.rowId == row.rowId) {
  1169. item.tableFieldList = this.tableFieldList;
  1170. }
  1171. });
  1172. }
  1173. this.getAllTable();
  1174. // console.log('修改', this.groupList);
  1175. // 展示字段的回显
  1176. this.relateTitle = false;
  1177. this.isShowForm = true;
  1178. },
  1179. // 删除表格组
  1180. DeleteTableGroup(row) {
  1181. const fIds = row.id || this.ids;
  1182. const menus = row.menuId || this.menuIds;
  1183. this.$modal
  1184. .confirm(
  1185. '是否确认删除动态单编号为"' +
  1186. fIds +
  1187. '"的数据项?删除后表格中所有的数据都将删除!'
  1188. )
  1189. .then(function () {
  1190. return delMenu(menus);
  1191. })
  1192. .then(async () => {
  1193. await delGroup(fIds);
  1194. this.getTableList();
  1195. this.reloadRouter();
  1196. await getRouters();
  1197. this.$modal.msgSuccess("删除成功");
  1198. })
  1199. .catch(() => {});
  1200. },
  1201. // 取消新增
  1202. cancelAddHandler() {
  1203. this.isShowForm = false;
  1204. this.tableItemForm = {};
  1205. this.tableFieldList = [];
  1206. },
  1207. // 关联类型变化回调
  1208. relationTypeChangeHandler(row) {
  1209. let tempRelationFieldList = row.relationFieldList.filter((item) => {
  1210. return !this.tableFieldList.find((val) => val.id === item.id);
  1211. });
  1212. this.tableFieldList = [...this.tableFieldList, ...tempRelationFieldList];
  1213. },
  1214. // 更新路由
  1215. reloadRouter() {
  1216. this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
  1217. this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
  1218. });
  1219. },
  1220. // 获取目标menu
  1221. getTargetMenu(menus) {
  1222. for (let i = 0; i < menus.length; i++) {
  1223. if (menus[i].menuId == this.groupForm.routePath) {
  1224. return menus[i];
  1225. } else if (menus.children?.length) {
  1226. return this.getTargetMenu(menus.children);
  1227. }
  1228. }
  1229. return false;
  1230. },
  1231. // 获取父级menuId
  1232. getParentMenuId(menuId, menus) {
  1233. let res;
  1234. for (let i = 0; i < menus.length; i++) {
  1235. let item = menus[i];
  1236. if (item.menuId == menuId) {
  1237. res = item.parentId;
  1238. break;
  1239. } else if (item.children?.length) {
  1240. if (
  1241. this.getParentMenuId(
  1242. menuId,
  1243. JSON.parse(JSON.stringify(item.children))
  1244. )
  1245. ) {
  1246. res = this.getParentMenuId(
  1247. menuId,
  1248. JSON.parse(JSON.stringify(item.children))
  1249. );
  1250. }
  1251. }
  1252. }
  1253. return res;
  1254. },
  1255. // 修改表格回显数据
  1256. async initTableData(tId) {
  1257. let res = await getTableInfo(tId);
  1258. console.log("回显数据", res);
  1259. if (res.code == 200) {
  1260. if (!this.formData.routePath) {
  1261. this.$message.warning("该表格菜单路由已经删除,请重新配置");
  1262. }
  1263. // this.formData.routePath
  1264. this.editData = res.data;
  1265. let val = await getParticMenu(res.data.tableKey);
  1266. if (val.code == 200) {
  1267. this.menuId = val.data.menuId;
  1268. }
  1269. } else {
  1270. this.$message.error("数据回显失败");
  1271. }
  1272. },
  1273. // 新增动态表格组
  1274. addTableGroup(formName) {
  1275. this.$refs[formName].validate(async (valid) => {
  1276. if (valid) {
  1277. // console.log('groupList', this.groupList);
  1278. if (this.addDragData.length < 2) {
  1279. this.$message.error("请包含多个表格");
  1280. return;
  1281. }
  1282. if (this.groupTitle) {
  1283. let uuid = uuidv4();
  1284. let groupKeyObj = {
  1285. groupKey: uuid,
  1286. };
  1287. let payLoad = {
  1288. component: "relateTable/relateTableEdit",
  1289. icon: "",
  1290. isCache: "0",
  1291. isFrame: "1",
  1292. menuName: this.groupForm.groupName,
  1293. menuType: "C",
  1294. orderNum: this.menuOrderNum,
  1295. parentId: this.groupForm.routePath,
  1296. path: groupKeyObj.groupKey,
  1297. query: JSON.stringify(groupKeyObj),
  1298. status: "0",
  1299. visible: "0",
  1300. tenantId: this.tenantId,
  1301. };
  1302. let result;
  1303. result = await addMenu(payLoad);
  1304. if (result.code == 200) {
  1305. this.reloadRouter();
  1306. let data = {
  1307. groupKey: groupKeyObj.groupKey,
  1308. groupName: "",
  1309. groupDescription: "",
  1310. groupTableInfo: [],
  1311. dragTables: [],
  1312. };
  1313. console.log(this.addDragData);
  1314. // return;
  1315. this.addDragData.forEach((item, index) => {
  1316. item.menuId = result.data;
  1317. // item.sqlKey = tableKeyObj.tableKey
  1318. let echo = JSON.parse(item.echoData);
  1319. console.log(echo);
  1320. echo.formData = this.groupForm;
  1321. // item.echoData = JSON.stringify(echo)
  1322. data.groupTableInfo.push({
  1323. tableKey: item.tableKey,
  1324. sort: index,
  1325. tablename: item.dtTableName,
  1326. menuId: result.data,
  1327. });
  1328. });
  1329. data.groupName = this.groupForm.groupName;
  1330. data.groupDescription = this.groupForm.groupDescription;
  1331. data.groupTableInfo = JSON.stringify(data.groupTableInfo);
  1332. data.dragTables = this.addDragData;
  1333. // 添加表格组
  1334. let res = await addGroup(data);
  1335. console.log(res);
  1336. if (res.code == 200) {
  1337. this.$message.success("创建成功");
  1338. this.isShowTable = false;
  1339. this.groupForm = {};
  1340. } else {
  1341. this.$message.success("创建失败");
  1342. this.isShowTable = false;
  1343. this.groupForm = {};
  1344. }
  1345. }
  1346. } else {
  1347. let data = {
  1348. groupKey: this.echogroup.groupKey,
  1349. groupName: "",
  1350. groupDescription: "",
  1351. groupTableInfo: [],
  1352. dragTables: [],
  1353. id: this.groupId,
  1354. };
  1355. this.addDragData.forEach((item, index) => {
  1356. // item.sqlKey = tableKeyObj.tableKey
  1357. let echo = JSON.parse(item.echoData);
  1358. // echo.formData = this.groupForm
  1359. // console.log(echo);
  1360. item.echoData = JSON.stringify(echo);
  1361. data.groupTableInfo.push({
  1362. tableKey: item.tableKey,
  1363. sort: index,
  1364. tablename: item.dtTableName,
  1365. menuId: item.menuId,
  1366. });
  1367. });
  1368. data.groupName = this.groupForm.groupName;
  1369. data.groupDescription = this.groupForm.groupDescription;
  1370. data.groupTableInfo = JSON.stringify(data.groupTableInfo);
  1371. data.dragTables = this.addDragData;
  1372. console.log(data);
  1373. let res = await updataGroup(data);
  1374. if (res.code == 200) {
  1375. let payLoad = {
  1376. menuId: this.menuId,
  1377. menuName: this.groupForm.groupName,
  1378. parentId: this.groupForm.routePath,
  1379. component: "relateTable/relateTableEdit",
  1380. icon: "",
  1381. isCache: "0",
  1382. isFrame: "1",
  1383. menuType: "C",
  1384. orderNum: this.menuOrderNum,
  1385. status: "0",
  1386. visible: "0",
  1387. tenantId: this.tenantId,
  1388. };
  1389. let result = await updateMenu(payLoad);
  1390. if (result.code == 200) {
  1391. this.$message.success("修改成功");
  1392. this.isShowTable = false;
  1393. this.groupForm = {};
  1394. } else {
  1395. this.$message.success("修改失败");
  1396. this.isShowTable = false;
  1397. this.groupForm = {};
  1398. }
  1399. }
  1400. }
  1401. this.isShowTable = false;
  1402. this.addDragData = [];
  1403. this.groupForm = {};
  1404. this.tableDataList = [];
  1405. this.reloadRouter();
  1406. this.getTableList();
  1407. } else {
  1408. this.$message.error("请完善表单信息");
  1409. return false;
  1410. }
  1411. });
  1412. },
  1413. /** 新增按钮操作 */
  1414. async handleAdd() {
  1415. await this.getMenuList();
  1416. if (this.groupTitle) {
  1417. this.groupForm.groupName = "";
  1418. this.groupForm.groupDescription = "";
  1419. this.groupForm.routePath = undefined;
  1420. this.tableDataList = [];
  1421. }
  1422. this.groupTitle = true;
  1423. this.isShowTable = true;
  1424. },
  1425. // 取消
  1426. cancelGroup() {
  1427. this.groupTitle = true;
  1428. this.isShowTable = false;
  1429. },
  1430. // 获取路由表单数据
  1431. async getMenuList() {
  1432. let res = await getMenuList();
  1433. this.menus = this.handleTree(res.data, "menuId");
  1434. },
  1435. /** 转换菜单数据结构 */
  1436. normalizer(node) {
  1437. if (node.children && !node.children.length) {
  1438. delete node.children;
  1439. }
  1440. return {
  1441. id: node.menuId,
  1442. label: node.menuName,
  1443. children: node.children,
  1444. };
  1445. },
  1446. // 修改动态表格组回显
  1447. async UpdateTableGroup(row) {
  1448. await this.getMenuList();
  1449. // let id = JSON.parse(row.id)
  1450. getTable({ id: row.id }).then((res) => {
  1451. this.echogroup = res.data;
  1452. this.groupId = res.data.id;
  1453. // 关联表格
  1454. this.groupTableInfo = JSON.parse(res.data.groupTableInfo);
  1455. this.menuId = res.data.dragTables[0].menuId;
  1456. this.groupForm = res.data;
  1457. // res.data.dragTables.forEach(item => {
  1458. // if(item.orderByColumn.includes('.')){
  1459. // item.orderByColumn = item.orderByColumn.split('.')[1]
  1460. // }
  1461. // })
  1462. this.addDragData = res.data.dragTables;
  1463. // 菜单路由回显
  1464. this.tableDataList = this.groupForm.dragTables;
  1465. this.groupForm.routePath = this.getParentMenuId(
  1466. res.data.dragTables[0].menuId,
  1467. this.menus,
  1468. {}
  1469. );
  1470. if (!this.groupForm.routePath) {
  1471. this.$message.warning("该表格菜单路由已经删除,请重新配置");
  1472. }
  1473. });
  1474. this.groupTitle = false;
  1475. this.isShowTable = true;
  1476. },
  1477. // 取消按钮
  1478. cancel() {
  1479. this.open = false;
  1480. this.reset();
  1481. },
  1482. // 表单重置
  1483. reset() {
  1484. this.form = {
  1485. tId: null,
  1486. dtName: null,
  1487. dtNickname: null,
  1488. tableKey: null,
  1489. sqlKey: null,
  1490. dtTableName: null,
  1491. dtNotes: null,
  1492. dtColumnName: null,
  1493. timeFormat: null,
  1494. spare: null,
  1495. spare1: null,
  1496. delFlag: null,
  1497. createBy: null,
  1498. createTime: null,
  1499. updateBy: null,
  1500. updateTime: null,
  1501. isSelection: null,
  1502. };
  1503. this.resetForm("form");
  1504. },
  1505. /** 搜索按钮操作 */
  1506. handleQuery() {
  1507. this.queryParams.pageNum = 1;
  1508. this.getList();
  1509. },
  1510. /** 重置按钮操作 */
  1511. resetQuery() {
  1512. this.resetForm("queryForm");
  1513. this.getTableList();
  1514. },
  1515. // 多选框选中数据
  1516. handleSelectionChange(selection) {
  1517. console.log(selection);
  1518. this.ids = selection.map((item) => item.id);
  1519. this.Keys = selection.map((item) => item.sqlKey);
  1520. selection.forEach((vals) => {
  1521. this.menuIds = vals.groupTableInfo.map((item) => item.menuId);
  1522. console.log(this.menuIds);
  1523. });
  1524. this.selection = selection;
  1525. this.single = selection.length !== 1;
  1526. this.multiple = !selection.length;
  1527. },
  1528. /** 修改按钮操作 */
  1529. async handleUpdate(row) {
  1530. // 兼容勾选单个的修改
  1531. let tId = row?.tId || this.ids[0];
  1532. // this.$router.push({
  1533. // path: "/system/fromModel/index/tableMange",
  1534. // query: {
  1535. // tId: tId,
  1536. // },
  1537. // });
  1538. },
  1539. /** 提交按钮 */
  1540. submitForm() {
  1541. this.$refs["form"].validate((valid) => {
  1542. if (valid) {
  1543. if (this.form.tId != null) {
  1544. updateTable(this.form).then((response) => {
  1545. this.$modal.msgSuccess("修改成功");
  1546. this.open = false;
  1547. this.getList();
  1548. });
  1549. } else {
  1550. addTable(this.form).then((response) => {
  1551. this.$modal.msgSuccess("新增成功");
  1552. this.open = false;
  1553. this.getList();
  1554. });
  1555. }
  1556. }
  1557. });
  1558. },
  1559. /** 删除按钮操作 */
  1560. handleDelete(row) {
  1561. console.log(row);
  1562. this.tableDataList.forEach((item, index) => {
  1563. if (row.tableKey == item.tableKey) {
  1564. this.tableDataList.splice(index, 1);
  1565. }
  1566. });
  1567. },
  1568. // 更新路由
  1569. reloadRouter() {
  1570. this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
  1571. this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
  1572. });
  1573. },
  1574. // 新增一个联动表格
  1575. addOneTable() {
  1576. this.relateTitle = true;
  1577. if (this.relateTitle) {
  1578. this.tableItemForm = {};
  1579. this.tableFieldList = [];
  1580. this.conditionDefaultValueMap = "";
  1581. }
  1582. if (!this.groupTitle) {
  1583. // console.log(this.tableDataList[this.tableDataList.length-1].dtTableName)
  1584. this.relyFileds.tableName =
  1585. this.tableDataList[this.tableDataList.length - 1].dtTableName;
  1586. let echoData = JSON.parse(
  1587. this.tableDataList[this.tableDataList.length - 1].echoData
  1588. );
  1589. this.relyFileds.tableFieldList = echoData.tableFieldData;
  1590. }
  1591. this.getAllTable();
  1592. // 注意校验最后一条数据是否合法
  1593. this.isShowForm = true;
  1594. },
  1595. // 重置表单
  1596. // tableItemFormReset() {
  1597. // Object.assign(this.tableItemForm, {
  1598. // title: "",
  1599. // tableId: "",
  1600. // tableName: "",
  1601. // showFields: [],
  1602. // theRelateField: "",
  1603. // executeOptions: [],
  1604. // });
  1605. // },
  1606. // handlePreview() {
  1607. // this.$router.push({
  1608. // path: "/system/fromModel/index/relateTableEdit",
  1609. // });
  1610. // },
  1611. },
  1612. };
  1613. </script>
  1614. <style scoped lang="scss">
  1615. ::v-deep .el-dialog:not(.is-fullscreen) {
  1616. width: 900px !important;
  1617. }
  1618. .isSearch {
  1619. ::v-deep .el-dialog:not(.is-fullscreen) {
  1620. width: 320px !important;
  1621. }
  1622. ::v-deep .el-input--medium .el-input__inner {
  1623. margin-bottom: 10px !important;
  1624. }
  1625. }
  1626. .tablefiled {
  1627. ::v-deep .el-input--medium .el-input__inner {
  1628. width: 70px !important;
  1629. }
  1630. }
  1631. ::v-deep .el-input--medium .el-input__inner {
  1632. width: 230px !important;
  1633. }
  1634. ::v-deep .btn {
  1635. text-align: right !important;
  1636. }
  1637. .ipt {
  1638. height: 36px;
  1639. line-height: 36px;
  1640. font-size: 14px;
  1641. width: 100%;
  1642. outline: none;
  1643. text-align: center;
  1644. background-color: #fff;
  1645. border: 1px solid #dcdfe6;
  1646. color: #606266;
  1647. display: inline-block;
  1648. border-radius: 4px;
  1649. }
  1650. .isNullDesc {
  1651. border-color: #ff4949 !important;
  1652. }
  1653. .ipt:focus {
  1654. border-color: #1890ff;
  1655. }
  1656. ::v-deep .vue-treeselect--has-value .vue-treeselect__input {
  1657. vertical-align: middle !important;
  1658. }
  1659. .formWrap {
  1660. display: flex;
  1661. justify-content: center;
  1662. }
  1663. ::v-deep .el-table {
  1664. margin-top: 10px;
  1665. }
  1666. .nameipt {
  1667. display: inline;
  1668. margin-left: 10px;
  1669. ::v-deep .el-input--medium .el-input__inner {
  1670. width: 30%;
  1671. }
  1672. ::v-deep .el-input--medium {
  1673. display: inline;
  1674. }
  1675. }
  1676. .desc {
  1677. margin-left: 10px;
  1678. }
  1679. ::v-deep .vue-treeselect--has-value .vue-treeselect__input {
  1680. vertical-align: middle !important;
  1681. }
  1682. .treeselect {
  1683. .vue-treeselect {
  1684. width: 230px !important;
  1685. }
  1686. }
  1687. </style>
  1688. <style lang="scss">
  1689. .vue-treeselect {
  1690. z-index: 9999 !important;
  1691. }
  1692. </style>