index.vue 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <el-col :span="18" :class="{ edit: menudata }">
  5. <el-card shadow="always" :body-style="{ padding: '20px' }">
  6. <template #header>
  7. <div>
  8. <span>字段编辑</span>
  9. </div>
  10. </template>
  11. <!-- <Queryfrom
  12. :form-vals="checkedWhere"
  13. @getList="getList"
  14. ref="mychild"
  15. /> -->
  16. <el-select
  17. v-model="tableName"
  18. placeholder="请选择数据表"
  19. filterable
  20. @change="getList"
  21. class="mb10"
  22. >
  23. <el-option
  24. v-for="item in tableList"
  25. :key="item.tableName"
  26. :label="item.tableComment"
  27. :value="item.tableName"
  28. >
  29. <span class="discribe" style="float: left">{{
  30. item.tableComment
  31. }}</span>
  32. <span style="float: right; color: #8492a6; font-size: 13px">{{
  33. item.tableName
  34. }}</span>
  35. </el-option>
  36. </el-select>
  37. <!-- <el-form
  38. :model="tableFieldList"
  39. ref="tableForm"
  40. :rules="rules"
  41. :inline="false"
  42. size="normal"
  43. > -->
  44. <el-table
  45. :data="tableFieldList"
  46. border
  47. ref="dragTable"
  48. row-key="id"
  49. max-height="500px"
  50. >
  51. <!--
  52. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  53. -->
  54. >
  55. <el-table-column
  56. type="index"
  57. label="序号"
  58. width="50"
  59. class-name="allowDrag"
  60. >
  61. </el-table-column>
  62. <el-table-column prop="fieldName" label="数据字段">
  63. </el-table-column>
  64. <el-table-column prop="fieldDescription" label="字段描述">
  65. <template slot-scope="scope">
  66. <!-- <el-form-item size="normal" prop="fieldDescription"> -->
  67. <input
  68. :class="{
  69. isNullDesc:
  70. scope.row.fieldDescription == '' &&
  71. scope.row.isShow &&
  72. isInputInvalid
  73. ? true
  74. : false,
  75. ipt: true,
  76. }"
  77. v-model="scope.row.fieldDescription"
  78. />
  79. <!-- <el-input v-model="scope.row.fieldDescription" /> -->
  80. <!-- </el-form-item> -->
  81. </template>
  82. </el-table-column>
  83. <el-table-column prop="relationTable" label="关联表">
  84. <template slot-scope="scope">
  85. <el-select
  86. v-model="scope.row.relationTable"
  87. :disabled="
  88. !scope.row.relationTableList ||
  89. !scope.row.relationTableList.length
  90. "
  91. placeholder="请选择关联的表"
  92. clearable
  93. filterable
  94. @change="ralationTableChange(scope.row)"
  95. >
  96. <el-option
  97. v-for="item in scope.row.relationTableList"
  98. :key="item.tableName"
  99. :label="item.tableComment"
  100. :value="item.tableName"
  101. >
  102. <span style="float: left">{{ item.tableComment }}</span>
  103. <span
  104. style="float: right; color: #8492a6; font-size: 13px"
  105. >{{ item.tableName }}</span
  106. >
  107. </el-option>
  108. </el-select>
  109. </template>
  110. </el-table-column>
  111. <el-table-column prop="relationFieldName" label="关联条件字段">
  112. <template slot-scope="scope">
  113. <el-select
  114. v-model="scope.row.relationFieldName"
  115. @change="relationFieldChange(scope.row)"
  116. :disabled="!scope.row.disableRelaFieldName"
  117. placeholder="关联字段"
  118. filterable
  119. >
  120. <el-option
  121. v-for="item in scope.row.relaFieldNameList"
  122. :key="item.fieldName"
  123. :label="item.fieldDescription"
  124. :value="item.fieldName"
  125. >
  126. </el-option>
  127. </el-select>
  128. </template>
  129. </el-table-column>
  130. <el-table-column prop="relationType" label="关联方式">
  131. <template slot-scope="scope">
  132. <el-select
  133. v-model="scope.row.relationType"
  134. placeholder="请选择关联方式"
  135. :disabled="!scope.row.disableRelaType"
  136. @change="relationTypeChangeHandler(scope.row)"
  137. filterable
  138. >
  139. <el-option
  140. v-for="item in relaTypeList"
  141. :key="item.value"
  142. :label="item.label"
  143. :value="item.value"
  144. >
  145. </el-option>
  146. </el-select>
  147. </template>
  148. </el-table-column>
  149. <!-- <el-table-column prop="relationShowField" label="关联显示字段">
  150. <template slot-scope="scope">
  151. <el-select
  152. v-model="scope.row.relationShowField"
  153. :disabled="!scope.row.disableRelaFieldName"
  154. placeholder="请选择"
  155. clearable
  156. filterable
  157. multiple
  158. >
  159. <el-option
  160. v-for="item in scope.row.relaFieldNameList"
  161. :key="item.fieldName"
  162. :label="item.fieldDescription"
  163. :value="item.fieldName + ' ' + item.fieldDescription"
  164. >
  165. </el-option>
  166. </el-select>
  167. </template>
  168. </el-table-column> -->
  169. <el-table-column prop="isShow" label="是否显示">
  170. <template slot-scope="scope">
  171. <el-switch v-model="scope.row.isShow"> </el-switch>
  172. </template>
  173. </el-table-column>
  174. <el-table-column prop="isSearch" label="是否包含查询">
  175. <template slot-scope="scope">
  176. <el-switch v-model="scope.row.isSearch"> </el-switch>
  177. </template>
  178. </el-table-column>
  179. <el-table-column prop="isExport" label="是否导出">
  180. <template slot-scope="scope">
  181. <el-switch v-model="scope.row.isExport"> </el-switch>
  182. </template>
  183. </el-table-column>
  184. <!-- <el-table-column prop="isCount" label="是否统计">
  185. <template slot-scope="scope">
  186. <el-switch v-model="scope.row.isCount"> </el-switch>
  187. </template>
  188. </el-table-column> -->
  189. <!-- <el-table-column
  190. label="操作"
  191. align="center"
  192. class-name="small-padding fixed-width"
  193. >
  194. <template slot-scope="scope">
  195. <el-button
  196. size="mini"
  197. type="text"
  198. icon="el-icon-edit"
  199. @click="handleUpdate(scope.row)"
  200. >修改
  201. </el-button>
  202. <el-button
  203. size="mini"
  204. type="text"
  205. icon="el-icon-delete"
  206. @click="handleDelete(scope.row)"
  207. >删除
  208. </el-button>
  209. </template>
  210. </el-table-column> -->
  211. </el-table>
  212. <!-- </el-form> -->
  213. </el-card>
  214. </el-col>
  215. <el-col :span="6" :class="{ menudata: menudata }">
  216. <el-tabs v-model="activeName" @tab-click="tabhandleClick">
  217. <el-tab-pane label="菜单编辑" name="menuedit">
  218. <el-card shadow="always" :body-style="{ padding: '10px' }">
  219. <!-- <template #header>
  220. <div>
  221. <span>菜单编辑</span>
  222. </div>
  223. </template> -->
  224. <el-form
  225. ref="formData"
  226. :model="formData"
  227. label-width="100px"
  228. :rules="rules"
  229. >
  230. <el-form-item label="菜单名称" prop="menuName">
  231. <el-input v-model="formData.menuName"></el-input>
  232. </el-form-item>
  233. <el-form-item label="菜单路由" prop="routePath">
  234. <!-- <el-select v-model="formData.routePath" placeholder="请选择路由">
  235. <el-option label="区域一" value="shanghai"></el-option>
  236. <el-option label="区域二" value="beijing"></el-option>
  237. </el-select> -->
  238. <treeselect
  239. :append-to-body="true"
  240. v-model="formData.routePath"
  241. :options="menus"
  242. :normalizer="normalizer"
  243. @change="treeSelectChange"
  244. :show-count="true"
  245. placeholder="请选择父级路由"
  246. />
  247. </el-form-item>
  248. <el-form-item label="是否显示列表" v-if="false">
  249. <el-switch v-model="formData.isShowList"></el-switch>
  250. </el-form-item>
  251. <el-form-item label="时间格式" prop="timeFormate">
  252. <el-select
  253. v-model="formData.timeFormate"
  254. placeholder="请选择时间格式"
  255. >
  256. <el-option
  257. v-for="val in dict.type.sys_time_format"
  258. :key="val.value"
  259. :label="val.label"
  260. :value="val.value"
  261. ></el-option>
  262. </el-select>
  263. </el-form-item>
  264. <el-form-item label="表格主键" prop="primaryKey">
  265. <el-select
  266. v-model="formData.primaryKey"
  267. placeholder="请选择表格主键"
  268. >
  269. <el-option
  270. v-for="val in primaryKeyList"
  271. :key="val.fieldName"
  272. :label="val.fieldDescription"
  273. :value="val.fieldName"
  274. ></el-option>
  275. </el-select>
  276. </el-form-item>
  277. <el-form-item label="操作列按钮" prop="btnGroupList">
  278. <el-select
  279. v-model="formData.btnGroupList"
  280. placeholder="请选择按钮组"
  281. clearable
  282. multiple
  283. >
  284. <el-option
  285. v-for="val in btnGroupOptions"
  286. :key="val.btnKey"
  287. :label="val.btnGroupName"
  288. :value="val.btnKey"
  289. ></el-option>
  290. </el-select>
  291. </el-form-item>
  292. <el-form-item label="排序依赖字段">
  293. <el-select
  294. v-model="formData.orderByColumn"
  295. placeholder="请选择排序依赖"
  296. >
  297. <el-option
  298. v-for="val in orderByFieldList"
  299. :key="val.fieldName"
  300. :label="val.fieldDescription"
  301. :value="val.tableName + '.' + val.fieldName"
  302. ></el-option>
  303. </el-select>
  304. </el-form-item>
  305. <el-form-item label="排序方式" v-show="formData.orderByColumn">
  306. <el-radio v-model="formData.isAsc" :label="false"
  307. >升序</el-radio
  308. >
  309. <el-radio v-model="formData.isAsc" :label="true"
  310. >降序</el-radio
  311. >
  312. </el-form-item>
  313. <el-form-item>
  314. <el-button size="mini" @click="previewHandle">预览</el-button>
  315. <el-button size="mini" type="primary" @click="createHandle">{{
  316. tId ? "确认修改" : "确认创建"
  317. }}</el-button>
  318. </el-form-item>
  319. </el-form>
  320. </el-card>
  321. </el-tab-pane>
  322. <el-tab-pane label="数据统计" name="datacount">
  323. <el-button
  324. type="primary"
  325. class="inline-large-button"
  326. icon="el-icon-plus"
  327. size="mini"
  328. @click="addDataDialog"
  329. >
  330. 添加数据字段
  331. </el-button>
  332. <!-- <el-button size="mini" type="primary" @click=countHandle>确定统计</el-button> -->
  333. <el-table
  334. :data="dragTableStatisticList"
  335. border
  336. class="mb10"
  337. style="width: 100%"
  338. >
  339. <!-- <el-table-column prop="number" label="序号" width="50"> -->
  340. style="width: 100%">
  341. <el-table-column
  342. type="index"
  343. label="序号"
  344. width="50"
  345. class-name="allowDrag"
  346. >
  347. </el-table-column>
  348. <!-- <el-table-column prop="datafield" label="数据字段" width="80"> -->
  349. <el-table-column
  350. prop="statisticTitle"
  351. label="统计标题"
  352. width="83"
  353. >
  354. </el-table-column>
  355. <el-table-column
  356. prop="statisticField"
  357. label="统计数据"
  358. width="80"
  359. >
  360. </el-table-column>
  361. <!-- <el-table-column prop="type" label="类型" width="50"> -->
  362. <el-table-column prop="statisticType" label="统计类型" width="50">
  363. </el-table-column>
  364. <el-table-column
  365. label="操作"
  366. align="center"
  367. class-name="small-padding fixed-width"
  368. >
  369. <template slot-scope="scope">
  370. <el-dropdown>
  371. <el-button type="warning" plain size="small">
  372. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  373. </el-button>
  374. <el-dropdown-menu slot="dropdown">
  375. <el-dropdown-item>
  376. <el-button
  377. size="mini"
  378. type="text"
  379. icon="el-icon-edit"
  380. @click="handleUpdateStat(scope.row)"
  381. >修改
  382. </el-button>
  383. </el-dropdown-item>
  384. <el-dropdown-item>
  385. <el-button
  386. size="mini"
  387. type="text"
  388. icon="el-icon-delete"
  389. @click="handleDeleteStat(scope.row)"
  390. >删除
  391. </el-button>
  392. </el-dropdown-item>
  393. </el-dropdown-menu>
  394. </el-dropdown>
  395. </template>
  396. </el-table-column>
  397. </el-table>
  398. </el-tab-pane>
  399. <el-tab-pane label="样式编辑" name="styleEdit">
  400. <StyleFormPanel
  401. ref="styleTableRef"
  402. :tableFieldList="tableFieldList"
  403. :dragTableStyleList="dragTableStyleList"
  404. />
  405. </el-tab-pane>
  406. </el-tabs>
  407. </el-col>
  408. </el-row>
  409. <el-dialog title="效果预览" :visible.sync="isShowPreview" width="50%">
  410. <div class="cardBox">
  411. <el-card
  412. shadow="hover"
  413. :body-style="{ padding: '20px' }"
  414. class="card"
  415. v-for="(item, index) in deepragTableStatisticList"
  416. :key="index"
  417. >
  418. <el-tooltip
  419. class="item"
  420. effect="dark"
  421. :content="item.statisticTitle"
  422. placement="top-start"
  423. >
  424. <div class="title">
  425. {{
  426. item.statisticTitle
  427. ? item.statisticTitle
  428. : item.statisticDescription
  429. }}
  430. </div>
  431. </el-tooltip>
  432. <!-- <el-tooltip
  433. class="item"
  434. effect="dark"
  435. :content="item.statisticDescription"
  436. placement="top-start"
  437. >
  438. <div class="description">{{ item.statisticDescription }}</div>
  439. </el-tooltip> -->
  440. <div class="type">
  441. <!-- <div class="statisticType">{{ item.statisticType }}</div> -->
  442. <div class="count">统计结果</div>
  443. </div>
  444. </el-card>
  445. </div>
  446. <el-row :gutter="10" class="mb8">
  447. <el-col :span="18">
  448. <el-input placeholder="请输入" clearable />
  449. </el-col>
  450. <el-col :span="6" class="previewbtn">
  451. <el-button
  452. type="primary"
  453. icon="el-icon-search"
  454. size="small"
  455. @click="() => {}"
  456. >搜索</el-button
  457. >
  458. <el-button icon="el-icon-refresh" size="small" @click="() => {}"
  459. >重置</el-button
  460. >
  461. </el-col>
  462. </el-row>
  463. <el-row :gutter="10" class="mb8">
  464. <el-col :span="1.5">
  465. <el-button
  466. type="primary"
  467. plain
  468. icon="el-icon-plus"
  469. size="mini"
  470. @click="() => {}"
  471. >新增
  472. </el-button>
  473. </el-col>
  474. <el-col :span="1.5">
  475. <el-button
  476. type="success"
  477. plain
  478. icon="el-icon-edit"
  479. size="mini"
  480. :disabled="false"
  481. @click="() => {}"
  482. >修改
  483. </el-button>
  484. </el-col>
  485. <el-col :span="1.5">
  486. <el-button
  487. type="danger"
  488. plain
  489. icon="el-icon-delete"
  490. size="mini"
  491. :disabled="false"
  492. @click="() => {}"
  493. >删除
  494. </el-button>
  495. </el-col>
  496. <el-col :span="1.5">
  497. <el-button plain icon="el-icon-upload2" size="mini" @click="() => {}"
  498. >导入
  499. </el-button>
  500. </el-col>
  501. <el-col :span="1.5">
  502. <el-button
  503. type="warning"
  504. plain
  505. icon="el-icon-download"
  506. size="mini"
  507. @click="() => {}"
  508. >导出
  509. </el-button>
  510. </el-col>
  511. <!-- <right-toolbar
  512. showSearch.sync="true"
  513. @queryTable="() => {}"
  514. ></right-toolbar> -->
  515. </el-row>
  516. <el-table :data="tableDataList" @selection-change="() => {}">
  517. <el-table-column
  518. type="selection"
  519. width="55"
  520. align="center"
  521. ></el-table-column>
  522. <!-- <span v-for="(key, val) in columns" :key="key">
  523. <el-table-column :label="key" align="center" :prop="val" />
  524. </span> -->
  525. <el-table-column
  526. v-for="item in columns"
  527. :key="item.key + item.value"
  528. :label="item.value"
  529. align="center"
  530. :prop="toUpperCase(item.key)"
  531. />
  532. <el-table-column
  533. label="操作"
  534. align="center"
  535. class-name="small-padding fixed-width"
  536. >
  537. <!-- <template slot-scope="scope"> -->
  538. <template>
  539. <!-- <el-button
  540. size="mini"
  541. type="text"
  542. icon="el-icon-edit"
  543. @click="() => {}"
  544. >修改
  545. </el-button>
  546. <el-button
  547. size="mini"
  548. type="text"
  549. icon="el-icon-delete"
  550. @click="() => {}"
  551. >删除
  552. </el-button> -->
  553. <el-dropdown>
  554. <el-button type="warning" plain size="small">
  555. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  556. </el-button>
  557. <el-dropdown-menu slot="dropdown">
  558. <el-dropdown-item
  559. ><el-button
  560. size="mini"
  561. type="text"
  562. icon="el-icon-edit"
  563. @click="() => {}"
  564. >修改</el-button
  565. ></el-dropdown-item
  566. >
  567. <el-dropdown-item
  568. ><el-button
  569. size="mini"
  570. type="text"
  571. icon="el-icon-delete"
  572. @click="() => {}"
  573. >删除</el-button
  574. >
  575. </el-dropdown-item>
  576. </el-dropdown-menu>
  577. </el-dropdown>
  578. </template>
  579. </el-table-column>
  580. </el-table>
  581. <pagination
  582. v-show="total > 0"
  583. :total="total"
  584. :page.sync="queryParams.pageNum"
  585. :limit.sync="queryParams.pageSize"
  586. @pagination="pageList"
  587. />
  588. <template #footer>
  589. <span>
  590. <el-button @click="isShowPreview = false">关闭</el-button>
  591. <el-button type="primary" @click="createHandle">{{
  592. tId ? "确认修改" : "确认创建"
  593. }}</el-button>
  594. </span>
  595. </template>
  596. </el-dialog>
  597. <!-- 添加数据统计对话框 -->
  598. <el-dialog :title="staictitle" :visible.sync="isShowAddData" width="30%">
  599. <el-form label-width="100px" :model="dataCountFormData">
  600. <el-form-item label="统计标题" prop="statisticTitle">
  601. <el-input v-model="dataCountFormData.statisticTitle"></el-input>
  602. </el-form-item>
  603. <el-form-item label="统计数据">
  604. <el-select
  605. v-model="dataCountFormData.statisticField"
  606. placeholder="请选择统计字段"
  607. >
  608. <el-option
  609. v-for="item in dataArr"
  610. :key="item.id"
  611. :label="item.fieldName"
  612. :value="item.tableName + '.' + item.fieldName"
  613. >
  614. <span class="discribe" style="float: left; margin-right: 5px"
  615. >{{ isShowTableName }}
  616. </span>
  617. <span style="float: right; color: #8492a6; font-size: 13px">{{
  618. item.fieldName
  619. }}</span>
  620. </el-option>
  621. </el-select>
  622. </el-form-item>
  623. <!-- <el-form-item label="类型">
  624. <el-select v-model="dataCountFormData.type" placeholder="请选择类型">
  625. <el-option label="数量" value="num"></el-option>
  626. <el-option label="状态" value="status"></el-option> -->
  627. <el-form-item label="统计类型">
  628. <el-select
  629. v-model="dataCountFormData.statisticType"
  630. placeholder="请选择统计类型"
  631. >
  632. <el-option
  633. v-for="item in dataType"
  634. :key="item.dictCode"
  635. :label="item.dictLabel"
  636. :value="item.dictValue"
  637. ></el-option>
  638. <!-- <el-option label="状态" value="status"></el-option> -->
  639. </el-select>
  640. </el-form-item>
  641. </el-form>
  642. <span slot="footer" class="dialog-footer">
  643. <el-button @click="closeAddDialog">取 消</el-button>
  644. <el-button
  645. v-if="staictitle == '修改统计数据字段'"
  646. type="primary"
  647. @click="upadtaData"
  648. >确 定</el-button
  649. >
  650. <el-button v-else type="primary" @click="addData">确 定</el-button>
  651. </span>
  652. </el-dialog>
  653. </div>
  654. </template>
  655. <script>
  656. import {
  657. delTableData,
  658. dragTableInfo,
  659. listTable,
  660. unionListTableData,
  661. getInfoBySqlKey,
  662. addTableData,
  663. addStatistic,
  664. updateStatistic,
  665. } from "@/api/tablelist/commonTable";
  666. import { getDicts } from "@/api/system/dict/data";
  667. import {
  668. getFormName,
  669. getListName,
  670. dragTablePreview,
  671. } from "@/api/dragform/form.js";
  672. import { getTableInfo, editTable } from "@/api/system/table.js";
  673. import { addDragTable } from "@/api/tablelist/commonTable.js";
  674. import { getParticMenu, updateMenu } from "@/api/system/menu.js";
  675. import { getMenuList, addMenu } from "@/api/menu.js";
  676. import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
  677. import { mapState } from "vuex";
  678. import Sortable from "sortablejs";
  679. import Treeselect from "@riophae/vue-treeselect";
  680. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  681. import { v4 as uuidv4 } from "uuid";
  682. import { listBtn } from "@/api/system/btn";
  683. import StyleFormPanel from "./components/StyleFormPanel.vue";
  684. export default {
  685. name: "tableMange",
  686. dicts: ["sys_time_format", "table_statistic_type"],
  687. props: [],
  688. components: { Queryfrom, Treeselect, StyleFormPanel },
  689. data() {
  690. return {
  691. staictitle: "添加统计数据字段",
  692. isInputInvalid: false,
  693. // 修改表格时的menuId
  694. menuId: "",
  695. // 修改表格的id
  696. tId: "",
  697. // 当前模板信息
  698. templateInfo: {},
  699. // 排序方式 默认降序
  700. sortState: true,
  701. // 列信息
  702. columns: {},
  703. // 查询条件
  704. queryFromWhere: {},
  705. // 当前table唯一标识
  706. sqlKey: "",
  707. // 动态数据sqlkey
  708. staticSqlKey: "",
  709. // 表格的高度
  710. tableKey: "",
  711. // tableHeight: document.documentElement.scrollHeight - 245 + "px",
  712. tableList: [], //所有表格列表
  713. tableFieldList: [], // 当前表格字段数据
  714. tableName: "", // 当前表名称
  715. relationTableList: [], //关联表格列表
  716. relationFieldList: [], //关联字段列表
  717. relationTypeList: [], //关联方式列表
  718. total: 0, //表格数据总数
  719. relaTypeList: [
  720. {
  721. label: "等值连接",
  722. value: "INNER JOIN",
  723. },
  724. {
  725. label: "左连接",
  726. value: "LEFT JOIN",
  727. },
  728. {
  729. label: "右连接",
  730. value: "RIGHT JOIN",
  731. },
  732. ],
  733. headerList: [
  734. {
  735. prop: "fieldName",
  736. label: "数据字段",
  737. },
  738. {
  739. prop: "fieldDescription",
  740. label: "字段描述",
  741. },
  742. {
  743. prop: "relationTable",
  744. label: "关联表",
  745. },
  746. {
  747. prop: "relationFieldName",
  748. label: "关联字段",
  749. },
  750. {
  751. prop: "relationType",
  752. label: "关联方式",
  753. },
  754. {
  755. prop: "isShow",
  756. label: "是否显示",
  757. },
  758. {
  759. prop: "isSearch",
  760. label: "是否包含查询",
  761. },
  762. {
  763. prop: "isExport",
  764. label: "是否导出",
  765. },
  766. {
  767. prop: "isCount",
  768. label: "是否统计",
  769. },
  770. ], //表头列表
  771. // 右侧筛选条件勾选数据
  772. // checkedList: [], //勾选的查询框
  773. // checkedWhere:[],//需要渲染的查询表单
  774. // 右侧表单编辑
  775. formData: {
  776. menuName: "",
  777. routePath: undefined,
  778. isShowList: true,
  779. timeFormate: "",
  780. orderByColumn: "",
  781. isAsc: false,
  782. primaryKey: "",
  783. btnGroupList: [],
  784. },
  785. rules: {
  786. menuName: [
  787. { required: true, message: "请输入菜单名称", trigger: "blur" },
  788. ],
  789. routePath: [
  790. { required: true, message: "请选择路由", trigger: "change" },
  791. ],
  792. timeFormate: [
  793. { required: true, message: "请选择时间格式", trigger: "change" },
  794. ],
  795. primaryKey: [
  796. { required: true, message: "请选择表格主键", trigger: "blur" },
  797. ],
  798. fieldDescription: [
  799. { required: true, message: "请输入字段描述", trigger: "blur" },
  800. ],
  801. },
  802. menus: [], //路由列表数据
  803. // 预览弹窗相关
  804. isShowPreview: false, //弹窗显示与隐藏
  805. queryParams: {
  806. pageNum: 1,
  807. pageSize: 10,
  808. orderByColumn: "",
  809. isAsc: false,
  810. basicMap: {
  811. sql: "",
  812. },
  813. },
  814. loading: false, //表格加载
  815. tableDataList: [], //数据
  816. editData: {},
  817. menuOrderNum: 0,
  818. // tab动态切换
  819. activeName: "menuedit",
  820. // 数据统计对象
  821. dataCountFormData: {},
  822. // 添加数据统计表格
  823. dragTableStatisticList: [],
  824. deepragTableStatisticList: [],
  825. tableSqlList: [],
  826. searchFieldList: [],
  827. // 是否切换到数据统计
  828. menudata: false,
  829. // 显示添加字段对话框dataArr
  830. isShowAddData: false,
  831. dataType: [],
  832. uuid: "",
  833. // 样式编辑tab数据
  834. dragTableStyleList: [],
  835. //操作列按钮组数据
  836. btnGroupOptions: [],
  837. };
  838. },
  839. computed: {
  840. // 数据字段
  841. dataArr() {
  842. return this.tableFieldList.filter((item) => item.isShow);
  843. },
  844. // 数据统计字段表名中文
  845. isShowTableName() {
  846. let tableComment;
  847. this.tableList.forEach((item) => {
  848. if (item.tableName === this.tableName) {
  849. tableComment = item.tableComment;
  850. }
  851. });
  852. return tableComment;
  853. },
  854. ...mapState({
  855. databaseName: (state) => state.user.dataSource.databaseName,
  856. databaseType: (state) => state.user.dataSource.databaseType,
  857. username: (state) => state.user.dataSource.username,
  858. tenantId: (state) => state.user.tenant.tenantId,
  859. }),
  860. searchArr() {
  861. if (!this.templateInfo?.where?.length) return [];
  862. return this.templateInfo.where.map((item) => item.conditionName);
  863. },
  864. checkedWhere() {
  865. if (!this.templateInfo?.where?.length) return [];
  866. return this.templateInfo?.where.filter((item) => {
  867. return this.checkedList.includes(item.conditionName);
  868. });
  869. },
  870. orderByFieldList() {
  871. // return this.tableFieldList.filter((item) => item.isShow);
  872. return this.tableFieldList;
  873. },
  874. primaryKeyList() {
  875. return this.tableFieldList.filter((item) => !item.isChildren);
  876. },
  877. // menuOrderNum() {
  878. // if (!this.formData.routePath) return 0;
  879. // let targetMenu = this.getTargetMenu(this.menus);
  880. // console.log(targetMenu);
  881. // if (targetMenu.children?.length) {
  882. // return targetMenu.children.length;
  883. // } else {
  884. // return 0;
  885. // }
  886. // },
  887. },
  888. watch: {
  889. tableName: function (val) {
  890. if (val) {
  891. this.relationTableList = this.tableList
  892. .filter((item) => item.tableName != val)
  893. .map((item) => {
  894. return {
  895. tableName: item.tableName,
  896. tableComment: item.tableComment,
  897. };
  898. });
  899. } else {
  900. this.relationTableList = [];
  901. }
  902. },
  903. "formData.routePath"(nval, oval) {
  904. let targetMenu = this.getTargetMenu(this.menus);
  905. this.menuOrderNum = targetMenu.children ? targetMenu.children.length : 0;
  906. },
  907. },
  908. methods: {
  909. // 字段描述验证规则
  910. // blurval(value){
  911. // this.isInputInvalid = value == '' ? true : false;
  912. // },
  913. // 树形控件change回调
  914. treeSelectChange(val) {
  915. //没有change事件
  916. console.log("val", val);
  917. },
  918. // 获取目标menu
  919. getTargetMenu(menus) {
  920. for (let i = 0; i < menus.length; i++) {
  921. if (menus[i].menuId == this.formData.routePath) {
  922. return menus[i];
  923. } else if (menus.children?.length) {
  924. return this.getTargetMenu(menus.children);
  925. }
  926. }
  927. return false;
  928. },
  929. /** 查询列表 */
  930. getList(queryParams) {
  931. if (!this.tableName) return;
  932. let data = {
  933. databaseName: this.databaseName,
  934. databaseType: this.databaseType,
  935. tableName: this.tableName,
  936. };
  937. let tableComment = this.getTableCommont(this.tableName, this.tableList);
  938. // 获取当前表单结构信息
  939. getListName(data).then((res) => {
  940. // console.log(res);
  941. this.tableFieldList = res.map((item, index) => {
  942. return {
  943. id: this.tableName + "_" + item.fieldName,
  944. fieldName: item.fieldName,
  945. fieldDescription: item.fieldDescription,
  946. relationTable: "",
  947. relationFieldName: "",
  948. relaFieldNameList: [],
  949. disableRelaFieldName: false,
  950. relationType: "",
  951. relationShowField: [],
  952. relationShowFiledList: [],
  953. disableRelaType: false,
  954. isShow: true,
  955. isSearch: false,
  956. isExport: false,
  957. relationTableList: this.relationTableList,
  958. tableName: this.tableName,
  959. tableComment,
  960. relationFieldList: [],
  961. };
  962. });
  963. // console.log(this.tableFieldList);
  964. });
  965. },
  966. // 关联表变化回调
  967. async ralationTableChange(row) {
  968. this.tableFieldList = this.tableFieldList.filter((item) => {
  969. return !row.relationFieldList.some((val) => {
  970. return val.id == item.id;
  971. });
  972. });
  973. row.relationFieldName = "";
  974. row.relationType = "";
  975. row.disableRelaFieldName = false;
  976. row.disableRelaType = false;
  977. row.relationFieldList = [];
  978. if (!row.relationTable) {
  979. return;
  980. }
  981. // 获取关联表的字段
  982. let data = {
  983. databaseName: this.databaseName,
  984. databaseType: this.databaseType,
  985. tableName: row.relationTable,
  986. };
  987. let tableComment = this.getTableCommont(
  988. row.relationTable,
  989. this.tableList
  990. );
  991. let res = await getListName(data);
  992. // 关联字段下拉列表数据
  993. row.relaFieldNameList = res.map((item) => {
  994. return {
  995. fieldName: item.fieldName,
  996. fieldDescription: item.fieldDescription,
  997. };
  998. });
  999. let relationTableList = row.relationTableList.filter(
  1000. (item) => row.relationTable != item.tableName
  1001. );
  1002. row.relationFieldList = row.relaFieldNameList.map((item, index) => {
  1003. return {
  1004. id: row.relationTable + "_" + item.fieldName,
  1005. fieldName: item.fieldName,
  1006. fieldDescription: item.fieldDescription,
  1007. relationTable: "",
  1008. relationFieldName: "",
  1009. relaFieldNameList: [],
  1010. disableRelaFieldName: false,
  1011. relationType: "",
  1012. relationShowField: [],
  1013. relationShowFiledList: [],
  1014. disableRelaType: false,
  1015. isShow: true,
  1016. isSearch: false,
  1017. isExport: false,
  1018. relationTableList,
  1019. tableName: row.relationTable,
  1020. tableComment,
  1021. relationFieldList: [],
  1022. isChildren: true,
  1023. };
  1024. });
  1025. // this.tableFieldList = [...this.tableFieldList, ...row.relationFieldList];
  1026. row.disableRelaFieldName = true;
  1027. },
  1028. // 关联类型变化回调
  1029. relationTypeChangeHandler(row) {
  1030. let tempRelationFieldList = row.relationFieldList.filter((item) => {
  1031. return !this.tableFieldList.find((val) => val.id === item.id);
  1032. });
  1033. this.tableFieldList = [...this.tableFieldList, ...tempRelationFieldList];
  1034. },
  1035. // 关联字段回调
  1036. relationFieldChange(row) {
  1037. if (!row.relationFieldName) {
  1038. row.relationType = "";
  1039. row.disableRelaType = false;
  1040. row.relaFieldNameList = [];
  1041. return;
  1042. }
  1043. row.disableRelaType = true;
  1044. },
  1045. // 勾选框回调
  1046. handleSelectionChange(selection) {
  1047. this.ids = selection.map((item) => item.id);
  1048. // this.single = selection.length != 1;
  1049. this.multiple = !selection.length;
  1050. },
  1051. // 分页查询
  1052. pageList(row) {
  1053. this.$refs.mychild.pageList(
  1054. row == undefined
  1055. ? {
  1056. limit: this.queryParams.pageSize,
  1057. page: this.queryParams.pageNum,
  1058. }
  1059. : row
  1060. );
  1061. },
  1062. // 多选框改变回调
  1063. checkedChangeHandle(val) {},
  1064. // 获取所有表格
  1065. async getAllTable() {
  1066. let data = {
  1067. databaseName: this.databaseName,
  1068. databaseType: this.databaseType,
  1069. };
  1070. let res = await getFormName(data);
  1071. const baseTable = await this.getDicts("base_table");
  1072. this.tableList = res.data.filter((item) => {
  1073. return !baseTable.data.some(
  1074. (value) =>
  1075. value.dictValue.toLowerCase() == item.tableName.toLowerCase()
  1076. );
  1077. });
  1078. },
  1079. //处理表格行拖拽
  1080. initDragTable() {
  1081. const el = this.$refs.dragTable.$el.querySelectorAll(
  1082. ".el-table__body-wrapper > table > tbody"
  1083. )[0];
  1084. const sortable = Sortable.create(el, {
  1085. handle: ".allowDrag",
  1086. onEnd: (evt) => {
  1087. const targetRow = this.tableFieldList.splice(evt.oldIndex, 1)[0];
  1088. this.tableFieldList.splice(evt.newIndex, 0, targetRow);
  1089. for (let index in this.tableFieldList) {
  1090. this.tableFieldList[index].sort = parseInt(index) + 1;
  1091. }
  1092. },
  1093. });
  1094. },
  1095. /** 转换菜单数据结构 */
  1096. normalizer(node) {
  1097. if (node.children && !node.children.length) {
  1098. delete node.children;
  1099. }
  1100. return {
  1101. id: node.menuId,
  1102. label: node.menuName,
  1103. children: node.children,
  1104. };
  1105. },
  1106. // 获取路由表单数据
  1107. async getMenuList() {
  1108. let res = await getMenuList();
  1109. this.menus = this.handleTree(res.data, "menuId");
  1110. },
  1111. // 校验字段合法性(递归版)
  1112. validateField(tableFieldList, validateParams) {
  1113. if (!tableFieldList.length) {
  1114. return;
  1115. }
  1116. for (let i = 0; i < tableFieldList.length; i++) {
  1117. let temp = tableFieldList[i];
  1118. if (!temp.fieldDescription?.trim() && temp.isShow) {
  1119. //描述字段不能为空
  1120. validateParams.isFieldDescrib = true;
  1121. }
  1122. if (
  1123. temp.relationTable &&
  1124. (!temp.relationFieldName || !temp.relationType)
  1125. ) {
  1126. // 关联条件不足
  1127. validateParams.isRelationFieldAll = true;
  1128. }
  1129. if (temp.relationFieldList.length) {
  1130. this.validateField(temp.relationFieldList, validateParams);
  1131. }
  1132. }
  1133. },
  1134. // 校验字段合法性(非递归版)
  1135. validateTableData(tableFieldList) {
  1136. if (!tableFieldList.length) {
  1137. return {
  1138. val: false,
  1139. meg: "字段个数不能为空",
  1140. };
  1141. }
  1142. for (let i = 0; i < tableFieldList.length; i++) {
  1143. let temp = tableFieldList[i];
  1144. if (!temp.fieldDescription?.trim() && temp.isShow) {
  1145. return {
  1146. val: false,
  1147. msg: "显示的字段,字段描述不能为空",
  1148. };
  1149. }
  1150. if (
  1151. temp.relationTable &&
  1152. (!temp.relationFieldName || !temp.relationType)
  1153. ) {
  1154. return {
  1155. val: false,
  1156. msg: "关联条件不足,请完善关联条件",
  1157. };
  1158. }
  1159. }
  1160. if (tableFieldList.filter((item) => item.isShow).length == 0) {
  1161. return {
  1162. val: false,
  1163. msg: "显示的字段数不能为空",
  1164. };
  1165. }
  1166. if (
  1167. tableFieldList.filter((item) => item.isExport && !item.isChildren)
  1168. .length == 0
  1169. ) {
  1170. return {
  1171. val: false,
  1172. msg: "导出字段中至少应有一个主表字段",
  1173. };
  1174. }
  1175. // 导出的字段的描述不能重复
  1176. let describeArr = tableFieldList
  1177. .filter((item) => item.isExport)
  1178. .map((item) => item.fieldDescription);
  1179. let isRepeat = false;
  1180. describeArr.map((item) => {
  1181. if (describeArr.indexOf(item) != describeArr.lastIndexOf(item)) {
  1182. isRepeat = true;
  1183. }
  1184. });
  1185. if (isRepeat) {
  1186. return {
  1187. val: false,
  1188. msg: "导出的字段描述不能重复",
  1189. };
  1190. }
  1191. return {
  1192. val: true,
  1193. msg: "",
  1194. };
  1195. },
  1196. // 递归拼接查询语句
  1197. getSQLString(tableFieldList, fieldArr, tableArr, sqlType = "mysql") {
  1198. let prefix = "{DBNAME}.";
  1199. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  1200. for (let i = 0; i < tableFieldList.length; i++) {
  1201. let temp = tableFieldList[i];
  1202. if (temp.isShow) {
  1203. let tempArr = prefix + temp.tableName + "." + temp.fieldName;
  1204. // 给主表也加上表名前缀
  1205. // if (temp.isChildren) {
  1206. tempArr += asOrSpace + temp.tableName + "_" + temp.fieldName;
  1207. // }
  1208. fieldArr.push(tempArr);
  1209. }
  1210. if (temp.relationTable && temp.relationFieldName && temp.relationType) {
  1211. // fieldArr.push(temp.relationTable + "." + temp.relationFieldName);
  1212. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  1213. tableArr.push(
  1214. temp.relationType +
  1215. " " +
  1216. isNeedUsername +
  1217. prefix +
  1218. temp.relationTable +
  1219. asOrSpace +
  1220. temp.relationTable +
  1221. " ON " +
  1222. prefix +
  1223. temp.relationTable +
  1224. "." +
  1225. temp.relationFieldName +
  1226. " = " +
  1227. prefix +
  1228. temp.tableName +
  1229. "." +
  1230. temp.fieldName
  1231. );
  1232. }
  1233. // if (temp.relationFieldList.length) {
  1234. // this.getSQLString(temp.relationFieldList, fieldArr, tableArr);
  1235. // }
  1236. }
  1237. // 如果主键不包含显示,则添加至sql语句中
  1238. let isNotInclude = this.primaryKeyList.find(
  1239. (val) => !val.isShow && val.fieldName == this.formData.primaryKey
  1240. );
  1241. if (isNotInclude) {
  1242. fieldArr.push(
  1243. prefix + isNotInclude.tableName + "." + isNotInclude.fieldName
  1244. );
  1245. }
  1246. },
  1247. // 拼接查询sql语句
  1248. getSQLStr() {
  1249. let prefix = "{DBNAME}.";
  1250. let sqlType = this.databaseType; //数据库类型
  1251. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  1252. // let sqlType = "oracle";
  1253. let sql = "";
  1254. // mysql
  1255. sql += "SELECT ";
  1256. let fieldNameArr = [],
  1257. relaTypeArr = [];
  1258. this.getSQLString(
  1259. this.tableFieldList,
  1260. fieldNameArr,
  1261. relaTypeArr,
  1262. sqlType
  1263. );
  1264. // if (discriISEmpty) {
  1265. // return false;
  1266. // }
  1267. let styleFieldList = this.$refs.styleTableRef.getStyleTableField();
  1268. styleFieldList = styleFieldList.map((item) => {
  1269. return `${prefix}${item}${asOrSpace}${item.replace(".", "_")}`;
  1270. });
  1271. let set = new Set([...fieldNameArr, ...styleFieldList]);
  1272. fieldNameArr = [...set];
  1273. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  1274. sql +=
  1275. fieldNameArr.join(",") +
  1276. " FROM " +
  1277. isNeedUsername +
  1278. prefix +
  1279. this.tableName +
  1280. asOrSpace +
  1281. this.tableName;
  1282. if (relaTypeArr.length) {
  1283. sql += " " + relaTypeArr.join(" ");
  1284. }
  1285. return sql;
  1286. },
  1287. getStaticSQL(key) {
  1288. let prefix = "{DBNAME}.";
  1289. let sqlType = this.databaseType; //数据库类型
  1290. // let sqlType = "oracle";
  1291. let sql = "";
  1292. // mysql
  1293. sql += "SELECT ";
  1294. let fieldNameArr = [],
  1295. relaTypeArr = [];
  1296. this.getSQLString(
  1297. this.tableFieldList,
  1298. fieldNameArr,
  1299. relaTypeArr,
  1300. sqlType
  1301. );
  1302. let isNeedUsername = sqlType == "oracle" ? this.username + "." : "";
  1303. let asOrSpace = sqlType == "oracle" ? " " : " AS ";
  1304. sql +=
  1305. key +
  1306. " FROM " +
  1307. isNeedUsername +
  1308. prefix +
  1309. this.tableName +
  1310. asOrSpace +
  1311. this.tableName;
  1312. if (relaTypeArr.length) {
  1313. sql += " " + relaTypeArr.join(" ");
  1314. }
  1315. return sql;
  1316. },
  1317. // 处理列表信息
  1318. columnsHandler(columns) {
  1319. let resArr = [];
  1320. columns.forEach((item) => {
  1321. for (const key in item) {
  1322. let tempObj = {};
  1323. tempObj.key = key;
  1324. tempObj.value = item[key];
  1325. resArr.push(tempObj);
  1326. }
  1327. });
  1328. return resArr;
  1329. },
  1330. // 下划线命名转驼峰命名
  1331. toUpperCase(str) {
  1332. let nstr = str.replace(/(?:_)+([^_])/g, function ($0, $1) {
  1333. return $1.toUpperCase();
  1334. });
  1335. nstr = nstr.replace(nstr[0], nstr[0].toLowerCase());
  1336. return nstr;
  1337. },
  1338. // 递归获取列表信息
  1339. getCol(
  1340. tableFieldList,
  1341. columns,
  1342. searchFieldList = [],
  1343. tableExportField = {}
  1344. ) {
  1345. if (!tableFieldList.length) return;
  1346. for (let i = 0; i < tableFieldList.length; i++) {
  1347. let temp = tableFieldList[i];
  1348. let tempFieldName = "",
  1349. exportFieldName = "";
  1350. if (temp.isChildren) {
  1351. tempFieldName = temp.tableName + "_" + temp.fieldName;
  1352. exportFieldName = temp.tableName + "@" + temp.fieldName;
  1353. } else {
  1354. // tempFieldName = temp.fieldName;
  1355. tempFieldName = temp.tableName + "_" + temp.fieldName;
  1356. exportFieldName = temp.fieldName;
  1357. }
  1358. if (temp.isShow) {
  1359. let tempObj = {};
  1360. // if (temp.isChildren) {
  1361. // tempObj[temp.tableName + "_" + temp.fieldName] =
  1362. // temp.fieldDescription;
  1363. // } else {
  1364. // tempObj[temp.fieldName] = temp.fieldDescription;
  1365. // }
  1366. tempObj[tempFieldName] = temp.fieldDescription;
  1367. columns.push(tempObj);
  1368. }
  1369. if (temp.isSearch) {
  1370. searchFieldList.push(temp.tableName + "." + temp.fieldName);
  1371. }
  1372. if (temp.isExport) {
  1373. tableExportField[exportFieldName] = temp.fieldDescription;
  1374. }
  1375. // 递归
  1376. // if (temp.relationFieldList) {
  1377. // this.getCol(
  1378. // temp.relationFieldList,
  1379. // columns,
  1380. // searchFieldList,
  1381. // tableExportField
  1382. // );
  1383. // }
  1384. }
  1385. },
  1386. // 更新路由
  1387. reloadRouter() {
  1388. this.$store.dispatch("GenerateRoutes").then((accessRoutes) => {
  1389. this.$router.addRoutes(accessRoutes); // 动态添加可访问路由表
  1390. });
  1391. },
  1392. // 预览结果回调
  1393. async previewHandle() {
  1394. this.$refs.formData.validate(async (valid) => {
  1395. // 至少包含一个查询项
  1396. if (valid) {
  1397. if (!this.tableName) {
  1398. this.$message.error("请选择数据表");
  1399. return;
  1400. }
  1401. // 检验表单合法性
  1402. let validRes = this.validateTableData(this.tableFieldList);
  1403. if (!validRes.val) {
  1404. this.$message.error(validRes.msg);
  1405. return;
  1406. }
  1407. // let validateParams = {
  1408. // isFieldDescrib: false,
  1409. // isRelationFieldAll: false,
  1410. // };
  1411. // this.validateField(this.tableFieldList, validateParams);
  1412. // console.log(validateParams);
  1413. // if (validateParams.isFieldDescrib) {
  1414. // this.$message.error("需要显示的字段描述不能为空");
  1415. // return;
  1416. // }
  1417. // if (validateParams.isRelationFieldAll) {
  1418. // this.$message.error("请补全关联条件");
  1419. // return;
  1420. // }
  1421. // 拼接预览的sql查询语句
  1422. this.queryParams.basicMap.sql = this.getSQLStr();
  1423. // 获取表头信息
  1424. let tempColumns = [],
  1425. searchFieldList = [];
  1426. this.getCol(this.tableFieldList, tempColumns, searchFieldList);
  1427. if (!searchFieldList.length) {
  1428. this.$message.warning("请至少选择一个包含查询字段");
  1429. return false;
  1430. }
  1431. const dataType = await this.getDicts("table_statistic_type");
  1432. this.deepragTableStatisticList = JSON.parse(
  1433. JSON.stringify(this.dragTableStatisticList)
  1434. );
  1435. this.deepragTableStatisticList.forEach((item) => {
  1436. dataType.data.forEach((val) => {
  1437. if (val.dictValue == item.statisticType) {
  1438. item.statisticType = val.dictLabel;
  1439. }
  1440. });
  1441. });
  1442. this.columns = this.columnsHandler(tempColumns);
  1443. this.queryParams.isAsc = this.formData.isAsc;
  1444. // 发送请求获取预览数据
  1445. let res = await dragTablePreview(this.queryParams);
  1446. this.tableDataList = [];
  1447. res.rows.forEach((item) => {
  1448. this.tableDataList.push(item.resultMap);
  1449. });
  1450. this.total = res.total;
  1451. this.isShowPreview = true;
  1452. } else {
  1453. this.$message.warning("请完善表单");
  1454. return false;
  1455. }
  1456. });
  1457. // this.$refs.tableForm.validate((val) => {
  1458. // if (val) {
  1459. // } else {
  1460. // this.$message.warning("请完善表单");
  1461. // return false;
  1462. // }
  1463. // });
  1464. },
  1465. // 创建回调
  1466. async createHandle() {
  1467. // console.log(123);
  1468. // this.sqlKey = uuidv4();
  1469. this.isInputInvalid = true;
  1470. this.$refs.formData.validate(async (valid) => {
  1471. if (valid) {
  1472. // 检验表单合法性
  1473. let validRes = this.validateTableData(this.tableFieldList);
  1474. if (!validRes.val) {
  1475. this.$message.error(validRes.msg);
  1476. return;
  1477. }
  1478. let columns = [],
  1479. searchFieldList = [],
  1480. tableExportField = {};
  1481. this.getCol(
  1482. this.tableFieldList,
  1483. columns,
  1484. searchFieldList,
  1485. tableExportField
  1486. );
  1487. let echoData = {
  1488. tableName: this.tableName,
  1489. tableFieldData: this.tableFieldList,
  1490. formData: this.formData,
  1491. };
  1492. if (!searchFieldList.length) {
  1493. this.$message.warning("请至少选择一个包含查询字段");
  1494. return false;
  1495. }
  1496. // let validateParams = {
  1497. // isFieldDescrib: false,
  1498. // isRelationFieldAll: false,
  1499. // };
  1500. // this.validateField(this.tableFieldList, validateParams);
  1501. // console.log(validateParams);
  1502. // if (validateParams.isFieldDescrib) {
  1503. // this.$message.error("需要显示的字段描述不能为空");
  1504. // return;
  1505. // }
  1506. // if (validateParams.isRelationFieldAll) {
  1507. // this.$message.error("请补全关联条件");
  1508. // return;
  1509. // }
  1510. // console.log("123", columns);
  1511. this.uuid = uuidv4();
  1512. this.tableKey = uuidv4();
  1513. // 表单
  1514. let result;
  1515. // if (this.tId && this.menuId) {
  1516. if (this.menuId) {
  1517. let payLoad = {
  1518. menuId: this.menuId,
  1519. menuName: this.formData.menuName,
  1520. parentId: this.formData.routePath,
  1521. component: "tablelist/commonTable/listInfo",
  1522. icon: "",
  1523. isCache: "0",
  1524. isFrame: "1",
  1525. menuType: "C",
  1526. orderNum: this.menuOrderNum,
  1527. status: "0",
  1528. visible: "0",
  1529. tenantId: this.tenantId,
  1530. };
  1531. result = await updateMenu(payLoad);
  1532. } else {
  1533. let tableKeyObj = {
  1534. tableKey: this.uuid,
  1535. };
  1536. let payLoad = {
  1537. component: "tablelist/commonTable/listInfo",
  1538. icon: "",
  1539. isCache: "0",
  1540. isFrame: "1",
  1541. menuName: this.formData.menuName,
  1542. // menuId: this.formData.routePath,
  1543. menuType: "C",
  1544. orderNum: this.menuOrderNum,
  1545. parentId: this.formData.routePath,
  1546. path: this.uuid,
  1547. query: JSON.stringify(tableKeyObj),
  1548. status: "0",
  1549. visible: "0",
  1550. tenantId: this.tenantId,
  1551. };
  1552. result = await addMenu(payLoad);
  1553. }
  1554. if (result.code == 200) {
  1555. // 更新路由
  1556. this.reloadRouter();
  1557. // let isAsc = this.formData.isAsc == "ASC" ? 0 : 1;
  1558. let data = {
  1559. tId: this.tId,
  1560. dtName: this.formData.menuName,
  1561. menuId: this.formData.routePath,
  1562. tableKey: this.uuid, // 暂定
  1563. dtTableName: this.tableName,
  1564. primaryKey: this.formData.primaryKey,
  1565. orderByColumn: this.formData.orderByColumn,
  1566. sortOrder: this.formData.isAsc,
  1567. sqlKey: this.tableKey,
  1568. dtColumnName: columns, //列字段标题名称(存储显示字段信息
  1569. timeFormat: this.formData.timeFormate,
  1570. searchFieldList: searchFieldList, //搜索字段数组
  1571. tableSql: this.getSQLStr(), // 暂定
  1572. tableExportField: tableExportField, //导出字段名及列名
  1573. echoData: JSON.stringify(echoData),
  1574. // 样式相关数据
  1575. dragTableStyleList: this.$refs.styleTableRef.getSaveData(),
  1576. };
  1577. this.dragTableStatisticList.forEach((item) => {
  1578. if (this.tId == "") {
  1579. item.tableKey = this.tableKey;
  1580. this.staticSqlKey = uuidv4();
  1581. item.sqlKey = this.staticSqlKey;
  1582. }
  1583. if (item.sqlKey) {
  1584. this.staticSqlKey = item.sqlKey;
  1585. } else {
  1586. this.staticSqlKey = uuidv4();
  1587. item.sqlKey = this.staticSqlKey;
  1588. }
  1589. let key =
  1590. item.statisticType +
  1591. "(" +
  1592. item.statisticField +
  1593. ")" +
  1594. " as result";
  1595. this.tableSqlList.push({
  1596. tableSql: this.getStaticSQL(key),
  1597. sqlKey: this.staticSqlKey,
  1598. });
  1599. this.searchFieldList = searchFieldList;
  1600. });
  1601. let res;
  1602. let res1;
  1603. // if (this.tId && this.menuId) {
  1604. if (this.tId) {
  1605. data.menuId = this.menuId || result.data;
  1606. data.sqlKey = this.editData.sqlKey;
  1607. data.tableKey = this.editData.tableKey;
  1608. data.dragTableBtnRelevanceList = this.getBtnMapList(
  1609. data.tableKey
  1610. );
  1611. res = await editTable(data);
  1612. this.dragTableStatisticList.forEach((item) => {
  1613. item.tableKey = this.editData.tableKey;
  1614. });
  1615. // console.log(res);
  1616. res1 = await updateStatistic({
  1617. tableKey: this.editData.tableKey,
  1618. dragTableStatisticList: this.dragTableStatisticList,
  1619. tableSqlList: this.tableSqlList,
  1620. searchFieldList: this.searchFieldList,
  1621. dtTableName: this.tableName,
  1622. });
  1623. } else {
  1624. data.menuId = result.data;
  1625. data.dragTableBtnRelevanceList = this.getBtnMapList(
  1626. data.tableKey
  1627. );
  1628. res = await addDragTable(data);
  1629. // console.log('123456789', res)
  1630. this.dragTableStatisticList.forEach((item) => {
  1631. item.tableKey = this.uuid;
  1632. });
  1633. if (res.code == 200 && this.dragTableStatisticList.length !== 0) {
  1634. // 新增统计数据
  1635. res1 = addStatistic({
  1636. tableKey: this.uuid,
  1637. dragTableStatisticList: this.dragTableStatisticList,
  1638. tableSqlList: this.tableSqlList,
  1639. searchFieldList: this.searchFieldList,
  1640. dtTableName: this.tableName,
  1641. });
  1642. }
  1643. }
  1644. // 关闭当前页面
  1645. if (this.tId) {
  1646. if (res.code == 200) {
  1647. this.$message.success("修改成功");
  1648. this.$tab.closePage();
  1649. this.$router.push({
  1650. path: "/system/fromModel/index/tablelist",
  1651. });
  1652. } else {
  1653. this.$message.warning("修改失败");
  1654. }
  1655. } else {
  1656. if (res.code == 200) {
  1657. this.$message.success("创建成功");
  1658. this.$tab.closePage();
  1659. this.$router.push({
  1660. path: "/system/fromModel/index/tablelist",
  1661. });
  1662. } else {
  1663. this.$message.warning("创建失败");
  1664. }
  1665. this.isShowPreview = false;
  1666. }
  1667. }
  1668. } else {
  1669. this.$message.warning("请完善表单");
  1670. return false;
  1671. }
  1672. });
  1673. },
  1674. getBtnMapList(tableKey) {
  1675. let res = this.formData.btnGroupList.map((item) => {
  1676. return {
  1677. tableKey,
  1678. btnKey: item,
  1679. };
  1680. });
  1681. return res;
  1682. },
  1683. // 修改表格回显数据
  1684. async initTableData(tId) {
  1685. let res = await getTableInfo(tId);
  1686. if (res.code == 200) {
  1687. this.dragTableStatisticList = res.data.dragTableStatisticList;
  1688. this.dragTableStyleList = res.data.dragTableStyleList;
  1689. let echoData = JSON.parse(res.data.echoData);
  1690. this.tableName = echoData.tableName;
  1691. this.tableFieldList = echoData.tableFieldData;
  1692. let {
  1693. isShowList,
  1694. timeFormate,
  1695. orderByColumn,
  1696. isAsc,
  1697. primaryKey,
  1698. menuName,
  1699. btnGroupList,
  1700. } = echoData.formData;
  1701. Object.assign(this.formData, {
  1702. menuName,
  1703. isShowList,
  1704. timeFormate,
  1705. orderByColumn,
  1706. isAsc,
  1707. primaryKey,
  1708. btnGroupList,
  1709. });
  1710. this.formData.routePath = this.getParentMenuId(
  1711. res.data.menuId,
  1712. this.menus,
  1713. {}
  1714. );
  1715. if (!this.formData.routePath) {
  1716. this.$message.warning("该表格菜单路由已经删除,请重新配置");
  1717. }
  1718. // this.formData.routePath
  1719. this.editData = res.data;
  1720. let val = await getParticMenu(res.data.tableKey);
  1721. if (val.code == 200) {
  1722. this.menuId = val.data.menuId;
  1723. }
  1724. } else {
  1725. this.$message.error("数据回显失败");
  1726. }
  1727. },
  1728. // 获取父级menuId
  1729. getParentMenuId(menuId, menus) {
  1730. let res;
  1731. for (let i = 0; i < menus.length; i++) {
  1732. let item = menus[i];
  1733. if (item.menuId == menuId) {
  1734. res = item.parentId;
  1735. break;
  1736. } else if (item.children?.length) {
  1737. if (
  1738. this.getParentMenuId(
  1739. menuId,
  1740. JSON.parse(JSON.stringify(item.children))
  1741. )
  1742. ) {
  1743. res = this.getParentMenuId(
  1744. menuId,
  1745. JSON.parse(JSON.stringify(item.children))
  1746. );
  1747. }
  1748. }
  1749. }
  1750. return res;
  1751. },
  1752. // tab切换
  1753. tabhandleClick() {
  1754. this.menudata = this.activeName != "menuedit" ? true : false;
  1755. },
  1756. // 添加数据字段对话框
  1757. async addDataDialog() {
  1758. this.staictitle = "添加统计数据字段";
  1759. this.isShowAddData = true;
  1760. this.dataType = await this.getDicts("table_statistic_type");
  1761. this.dataType = this.dataType.data;
  1762. // console.log(this.dataType)
  1763. },
  1764. async updataDialog() {
  1765. // console.log(this.dataType)
  1766. },
  1767. // 修改数据字段
  1768. upadtaData() {
  1769. this.dragTableStatisticList.forEach((item, index) => {
  1770. // console.log(this.dataCountFormData);
  1771. if (item.id !== undefined && item.id == this.dataCountFormData.id) {
  1772. this.dragTableStatisticList[index] = this.dataCountFormData;
  1773. } else if (item.xid == this.dataCountFormData.xid) {
  1774. this.dragTableStatisticList[index] = this.dataCountFormData;
  1775. }
  1776. });
  1777. this.isShowAddData = false;
  1778. // console.log(this.dragTableStatisticList)
  1779. this.dataCountFormData = {};
  1780. },
  1781. // 添加数据字段
  1782. addData() {
  1783. // console.log(this.dataCountFormData);
  1784. this.dataCountFormData.xid = Date.now();
  1785. this.dataCountFormData.tableKey = this.tableKey;
  1786. this.dragTableStatisticList.push(this.dataCountFormData);
  1787. this.isShowAddData = false;
  1788. this.dataCountFormData = {};
  1789. },
  1790. // 关闭添加数据字段
  1791. closeAddDialog() {
  1792. this.isShowAddData = false;
  1793. this.dataCountFormData = {};
  1794. },
  1795. // 确定统计
  1796. countHandle() {
  1797. addStatistic({
  1798. dragTableStatisticList: this.dragTableStatisticList,
  1799. tableSqlList: this.tableSqlList,
  1800. searchFieldList: this.searchFieldList,
  1801. dtTableName: this.tableName,
  1802. }).then((res) => {
  1803. // console.log(res)
  1804. });
  1805. },
  1806. // 修改统计信息
  1807. async handleUpdateStat(row) {
  1808. // console.log(row);
  1809. this.dataCountFormData = row;
  1810. this.dataCountFormData.xid = Date.now();
  1811. this.staictitle = "修改统计数据字段";
  1812. this.dataType = await this.getDicts("table_statistic_type");
  1813. this.dataType = this.dataType.data;
  1814. this.isShowAddData = true;
  1815. // console.log(this.dataCountFormData)
  1816. // console.log(this.dragTableStatisticList);
  1817. },
  1818. // 删除统计信息
  1819. handleDeleteStat(row) {
  1820. this.dragTableStatisticList.forEach((item, index) => {
  1821. if (item.id == row.id) {
  1822. this.dragTableStatisticList.splice(index, 1);
  1823. }
  1824. });
  1825. },
  1826. // 获取当前表描述
  1827. getTableCommont(tableName, tableList) {
  1828. return tableList.find((item) => item.tableName == tableName).tableComment;
  1829. },
  1830. // 获取按钮组数据
  1831. async getBtnList() {
  1832. let res = await listBtn({ isEnablePaging: false, btnParentId: 0 });
  1833. this.btnGroupOptions = res.rows.filter((item) => !item.whetherBind);
  1834. },
  1835. },
  1836. created() {},
  1837. async mounted() {
  1838. this.getAllTable();
  1839. this.initDragTable();
  1840. this.getBtnList();
  1841. await this.getMenuList();
  1842. if (this.$route.query.tId) {
  1843. this.tId = this.$route.query.tId;
  1844. this.initTableData(this.tId);
  1845. }
  1846. },
  1847. };
  1848. </script>
  1849. <style scoped lang="scss">
  1850. .discribe {
  1851. display: block;
  1852. max-width: 200px;
  1853. white-space: nowrap;
  1854. overflow: hidden;
  1855. text-overflow: ellipsis;
  1856. }
  1857. .ipt {
  1858. height: 36px;
  1859. line-height: 36px;
  1860. font-size: 14px;
  1861. width: 100%;
  1862. outline: none;
  1863. text-align: center;
  1864. background-color: #fff;
  1865. border: 1px solid #dcdfe6;
  1866. color: #606266;
  1867. display: inline-block;
  1868. border-radius: 4px;
  1869. }
  1870. .isNullDesc {
  1871. border-color: #ff4949 !important;
  1872. }
  1873. .ipt:focus {
  1874. border-color: #1890ff;
  1875. }
  1876. ::v-deep .right_card {
  1877. min-height: 500px !important;
  1878. }
  1879. ::v-deep .vue-treeselect--has-value .vue-treeselect__input {
  1880. vertical-align: middle !important;
  1881. }
  1882. .menudata {
  1883. width: 30% !important;
  1884. }
  1885. .edit {
  1886. width: 70% !important;
  1887. }
  1888. .mb10 {
  1889. margin-top: 10px;
  1890. }
  1891. .cardBox {
  1892. display: flex;
  1893. align-content: space-between;
  1894. flex-wrap: wrap;
  1895. align-content: flex-start;
  1896. }
  1897. .card {
  1898. /* width:15%; */
  1899. height: 150px;
  1900. flex-basis: 15%;
  1901. margin-bottom: 10px;
  1902. margin-right: 15px;
  1903. min-width: 180px;
  1904. .title {
  1905. /* width:20%; */
  1906. font-size: 18px;
  1907. margin-bottom: 5px;
  1908. white-space: nowrap;
  1909. overflow: hidden;
  1910. text-overflow: ellipsis;
  1911. }
  1912. .description {
  1913. width: 70%;
  1914. font-size: 13px;
  1915. color: #9699a2;
  1916. overflow: hidden;
  1917. text-overflow: ellipsis;
  1918. display: -webkit-box;
  1919. -webkit-box-orient: vertical;
  1920. -webkit-line-clamp: 3;
  1921. word-break: break-all;
  1922. float: left;
  1923. }
  1924. .type {
  1925. float: right;
  1926. margin-top: 40px;
  1927. .statisticType {
  1928. font-size: 18px;
  1929. }
  1930. }
  1931. .count {
  1932. font-size: 25px;
  1933. }
  1934. }
  1935. .mb8 {
  1936. ::v-deep .el-col-18 {
  1937. width: 30% !important;
  1938. min-width: 220px !important;
  1939. }
  1940. ::v-deep .previewbtn {
  1941. min-width: 190px !important;
  1942. }
  1943. }
  1944. </style>