index copy.vue 53 KB

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