index.vue 63 KB

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