index.vue 40 KB

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