index.vue 52 KB

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