index.vue 64 KB

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