index.vue 57 KB

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