template-page-1.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <template>
  2. <div class="template-page-1">
  3. <zj-page-template
  4. ref="zjpage"
  5. :getTableData="getTableData"
  6. :optionsEvens="evens"
  7. :optionsEvensGroup="selBtn(optionsEvensGroup)"
  8. :tableAttributes="{ ...defaultTableAttributes, ...tableAttributes }"
  9. :tableEvents="{ ...defaultTableEvents, ...tableEvents }"
  10. :columnParsing="columnParsing"
  11. :reduction="reduction"
  12. :plan="[...defaultPlan, ...timePlan, ...paramList, ...morePlan]"
  13. :operation="operationShow && pk ? caozuojl : operation"
  14. :operationColumnWidth="(operation ? operationColumnWidth : 0) + (operationShow && pk ? 70 : 0)"
  15. :showTable="showTable"
  16. :codeGather="codeGather"
  17. :loading="loading"
  18. :lowerLine="true"
  19. :onSavePlan="onSavePlan"
  20. :onClosePlain="onClosePlain"
  21. :defaultSearchData="defaultSearchData"
  22. :replaceOrNotMap="replaceOrNotMap"
  23. @columnWidthChange="columnWidthChange"
  24. @columnListChange="columnListChange"
  25. >
  26. <template slot="more-search">
  27. <slot name="moreSearch"></slot>
  28. </template>
  29. </zj-page-template>
  30. <sel-export-column-list :columnList="columnList" @determine="exportDetermine" @cancel="columnList = []" />
  31. <slot />
  32. <el-dialog title="定义方案名" :visible.sync="dialogVisible" width="380px" :before-close="handleClose">
  33. <el-input size="mini" maxlength="8" show-word-limit v-model="inputText" placeholder="请输入名称"></el-input>
  34. <span slot="footer" class="dialog-footer">
  35. <el-button size="mini" @click="handleClose">取 消</el-button>
  36. <el-button size="mini" type="primary" @click="onSavePlanqd">确 定</el-button>
  37. </span>
  38. </el-dialog>
  39. <el-dialog title="操作记录" :visible.sync="logDialogVisible" width="800px">
  40. <zj-table
  41. :columns="pgxxColumns"
  42. :tableData="pgxxTableData"
  43. :tableAttributes="{
  44. height: '100%',
  45. border: true
  46. }"
  47. ></zj-table>
  48. </el-dialog>
  49. </div>
  50. </template>
  51. <script>
  52. import { commonLogList } from '@/api/common.js'
  53. import { zfireSave, zfireDel } from '@/api/fieldMan.js'
  54. import { dictListDict } from '@/api/dataDictionary2.js'
  55. import { zfireParamList, zfireParamSave, zfireParamDelete } from '@/api/zfireParam.js'
  56. import SelExportColumnList from './sel-export-column-list.vue'
  57. import selectData from './selectData.js'
  58. export default {
  59. components: {
  60. SelExportColumnList
  61. },
  62. props: {
  63. loading: {
  64. type: Boolean,
  65. default: false
  66. },
  67. // 事件组合
  68. optionsEvensGroup: {
  69. type: Array,
  70. default: () => []
  71. },
  72. // 表格属性
  73. tableAttributes: {
  74. type: Object,
  75. default: () => ({})
  76. },
  77. // 表格事件
  78. tableEvents: {
  79. type: Object,
  80. default: () => ({})
  81. },
  82. // 表格列解析渲染数据更改
  83. columnParsing: {
  84. type: Function
  85. },
  86. // 获取列表的方法
  87. getList: {
  88. type: Function
  89. },
  90. // 导出的方法
  91. exportList: {
  92. type: Function
  93. },
  94. // 更多方案
  95. morePlan: {
  96. type: Array,
  97. default: () => []
  98. },
  99. // 操作按钮
  100. operation: {
  101. type: Function
  102. },
  103. // 是否显示操作记录
  104. operationShow: {
  105. type: Boolean,
  106. default: true
  107. },
  108. // 获取操作记录的主键字段
  109. operationRecordkey: {
  110. type: String,
  111. default: ''
  112. },
  113. // 操作按钮单元格宽度
  114. operationColumnWidth: {
  115. type: Number,
  116. default: 140
  117. },
  118. // 自定义列
  119. cstomClumn: {
  120. type: Function
  121. },
  122. // 结构数据钩子
  123. fieldBeansHook: {
  124. type: Function
  125. },
  126. // 菜单名称
  127. customModuleName: {
  128. type: String,
  129. default: ''
  130. },
  131. defaultSearchData: {
  132. type: Array,
  133. default: () => []
  134. },
  135. replaceOrNotMap: {
  136. type: Boolean,
  137. default: true
  138. },
  139. setModuleId: {
  140. type: [String, Number],
  141. default: null
  142. }
  143. },
  144. data() {
  145. return {
  146. logDialogVisible: false,
  147. dialogVisible: false,
  148. // 搜索的参数
  149. parameter: {},
  150. // 按钮集合
  151. evens: [],
  152. // 表格属性
  153. defaultTableAttributes: {},
  154. // 表格事件
  155. defaultTableEvents: {},
  156. // 记录初始的id
  157. columnsIds: {},
  158. // 导出弹窗
  159. columnList: [],
  160. showTable: false,
  161. codeGather: {},
  162. frontCodes: [],
  163. pk: '',
  164. planItem: null,
  165. inputText: '',
  166. defaultPlan: [
  167. {
  168. name: '默认方案',
  169. paramCallback: () => {
  170. return []
  171. }
  172. }
  173. ],
  174. paramList: [],
  175. timePlan: [],
  176. pgxxColumns: [
  177. {
  178. columnAttributes: {
  179. label: '帐号',
  180. prop: 'userName'
  181. }
  182. },
  183. {
  184. columnAttributes: {
  185. label: '操作内容',
  186. prop: 'content'
  187. }
  188. },
  189. {
  190. columnAttributes: {
  191. label: 'ip',
  192. prop: 'ip'
  193. }
  194. },
  195. {
  196. columnAttributes: {
  197. label: '模块名称',
  198. prop: 'moduleName'
  199. }
  200. }
  201. ],
  202. pgxxTableData: []
  203. }
  204. },
  205. computed: {
  206. userid() {
  207. return this.$store.getters.userid
  208. },
  209. moduleId() {
  210. return this.setModuleId || this.$route.meta.moduleId
  211. },
  212. moduleName() {
  213. return this.customModuleName || this.$route.meta.title
  214. }
  215. },
  216. mounted() {
  217. if (this.exportList) {
  218. this.evens = [
  219. [
  220. {
  221. name: '导出',
  222. click: this.export,
  223. loading: false
  224. }
  225. ]
  226. ]
  227. }
  228. this.getZfireParamList()
  229. },
  230. methods: {
  231. setDefaultPlan(createTimeKey) {
  232. this.$nextTick(() => {
  233. if (createTimeKey) {
  234. var [y, m, d] = new Date(new Date().getTime()).toJSON().split('T').join(' ').substr(0, 10).split('-')
  235. this.timePlan = [
  236. {
  237. name: '今日',
  238. paramCallback: () => {
  239. return [
  240. { param: createTimeKey, compare: '>', value: `${y}-${m}-${Number(d) - 1} 23:59:59` },
  241. { param: createTimeKey, compare: '<', value: `${y}-${m}-${Number(d) + 1} 00:00:00` }
  242. ]
  243. }
  244. },
  245. {
  246. name: '昨日',
  247. paramCallback: () => {
  248. return [
  249. { param: createTimeKey, compare: '>', value: `${y}-${m}-${Number(d) - 2} 23:59:59` },
  250. { param: createTimeKey, compare: '<', value: `${y}-${m}-${Number(d)} 00:00:00` }
  251. ]
  252. }
  253. }
  254. ]
  255. }
  256. })
  257. },
  258. // 关闭方案命名弹窗
  259. handleClose() {
  260. this.planItem = null
  261. this.inputText = ''
  262. this.dialogVisible = false
  263. },
  264. // 获取方案记录
  265. getZfireParamList() {
  266. zfireParamList({
  267. moduleId: this.moduleId
  268. }).then(res => {
  269. this.paramList = res.data.map(item => {
  270. return {
  271. name: item.name,
  272. id: item.id,
  273. closable: true,
  274. paramCallback: () => {
  275. return item.items.map(dav => {
  276. if (dav.value[0] == '[' && dav.value[dav.value.length - 1] == ']') {
  277. return {
  278. param: dav.param,
  279. compare: dav.compare,
  280. value: dav.value.substring(1, dav.value.length - 1).split(',')
  281. }
  282. }
  283. return { param: dav.param, compare: dav.compare, value: dav.value }
  284. })
  285. }
  286. }
  287. })
  288. })
  289. },
  290. // 点击获取保存方案数据
  291. onSavePlan(p) {
  292. if (this.paramList.length >= 10) {
  293. this.$message.error('自定义方案最多支持保留10个')
  294. return
  295. }
  296. if (p.length) {
  297. this.planItem = p
  298. this.dialogVisible = true
  299. } else {
  300. this.$message.error('请先设置搜索条件')
  301. }
  302. },
  303. // 确定保存方案
  304. onSavePlanqd() {
  305. if (this.inputText) {
  306. zfireParamSave({
  307. moduleId: this.moduleId,
  308. name: this.inputText,
  309. items: this.planItem
  310. }).then(res => {
  311. this.handleClose()
  312. this.getZfireParamList()
  313. })
  314. } else {
  315. this.$message.error('请先填写方案名称')
  316. }
  317. },
  318. // 删除方案
  319. onClosePlain(p) {
  320. if (p.id) {
  321. this.$confirm('删除此方案, 是否继续?', '提示', {
  322. confirmButtonText: '确定',
  323. cancelButtonText: '取消',
  324. type: 'warning'
  325. })
  326. .then(() => {
  327. zfireParamDelete({ id: p.id }).then(res => {
  328. this.$message({
  329. message: '删除成功',
  330. type: 'success'
  331. })
  332. this.getZfireParamList()
  333. })
  334. })
  335. .catch(() => {})
  336. }
  337. },
  338. // 全局操作记录按钮
  339. caozuojl(h, { row, index, column }) {
  340. return (
  341. <div class="operation-btns">
  342. <el-button
  343. size="mini"
  344. type="text"
  345. onClick={() => {
  346. if (row[this.pk]) {
  347. commonLogList({
  348. objId: row[this.pk],
  349. pageNum: 1,
  350. pageSize: -1
  351. }).then(res => {
  352. this.pgxxTableData = res.data.records
  353. this.logDialogVisible = true
  354. })
  355. }
  356. }}
  357. >
  358. 操作记录
  359. </el-button>
  360. {this.operation ? this.operation(h, { row, index, column }) : null}
  361. </div>
  362. )
  363. },
  364. selBtn(arr) {
  365. for (var i = 0; i < arr.length; i++) {
  366. if (Array.isArray(arr[i])) {
  367. this.selBtn(arr[i])
  368. }
  369. if (!(arr[i].isRole || arr[i].isRole === undefined) || arr[i].length == 0) {
  370. arr.splice(i, 1)
  371. i--
  372. }
  373. }
  374. return arr
  375. },
  376. // 获取下拉对应数据
  377. getCodeGather() {
  378. let codes = this.frontCodes.filter(key => (this.codeGather[key] ? false : true))
  379. if (codes && codes.length) {
  380. var codeGather = {}
  381. Promise.all(
  382. codes.map(code => {
  383. if (selectData[code]) {
  384. return selectData[code]()
  385. }
  386. return dictListDict({ code: code })
  387. })
  388. ).then(resAll => {
  389. codes.map((code, index) => {
  390. var arr = resAll[index].data.map(item => {
  391. return { value: item.dictCode, label: item.dictValue }
  392. })
  393. codeGather[code] = arr
  394. })
  395. this.codeGather = { ...this.codeGather, ...codeGather }
  396. })
  397. }
  398. },
  399. // 获取列表数据函数
  400. async getTableData(data) {
  401. if (!this.getList) {
  402. return
  403. }
  404. try {
  405. this.parameter = {
  406. pageNum: data.page,
  407. pageSize: data.size,
  408. orderBy: data.orderBy,
  409. params: data.querylist,
  410. moduleId: this.moduleId
  411. }
  412. var res = await this.getList(this.parameter)
  413. if (res.code == 200) {
  414. if (!this.showTable) {
  415. this.$nextTick(() => {
  416. this.showTable = true
  417. })
  418. }
  419. if (this.fieldBeansHook) {
  420. res.fieldBeans = this.fieldBeansHook(res.fieldBeans) || res.fieldBeans
  421. }
  422. for (let item of res.fieldBeans) {
  423. if (item.jname === 'createTime') {
  424. this.setDefaultPlan(`${item.tbName ? item.tbName + '.' : ''}${item.colName}`)
  425. }
  426. if (item.pk) {
  427. this.$nextTick(() => {
  428. this.pk = item.colName
  429. })
  430. }
  431. if (item.frontCode && !~this.frontCodes.indexOf(item.frontCode)) {
  432. this.frontCodes.push(item.frontCode)
  433. }
  434. if (this.cstomClumn && item.label === 'cstomClumn') {
  435. this.cstomClumn(item.jname, res.data.records, res.fieldBeans, this.parameter)
  436. }
  437. }
  438. this.getCodeGather()
  439. return res
  440. }
  441. } catch (error) {
  442. console.log(error)
  443. }
  444. },
  445. // 监听列表显示状态与排序变化
  446. columnListChange(columnList) {
  447. zfireSave(
  448. this.$refs.zjpage.columnList.map((item, index) => {
  449. var data = {
  450. ...item.exportField,
  451. sortNum: index,
  452. isCopy: item.isCopy,
  453. isTotal: item.isTotal,
  454. isShow: !item.hidden,
  455. moduleId: this.moduleId,
  456. adminUserId: this.userid
  457. }
  458. return data
  459. }),
  460. this.moduleId
  461. )
  462. .then(res => {})
  463. .catch(err => {
  464. this.$message.error('保存失败')
  465. })
  466. },
  467. // 监听列宽度变化
  468. columnWidthChange({ newWidth, oldWidth, column }) {
  469. zfireSave(
  470. this.$refs.zjpage.columnList.map((item, index) => {
  471. if (item.exportField.jname === column.property) {
  472. item.exportField.width = newWidth
  473. }
  474. return {
  475. ...item.exportField,
  476. sortNum: index,
  477. isCopy: item.isCopy,
  478. isTotal: item.isTotal,
  479. isShow: !item.hidden,
  480. moduleId: this.moduleId,
  481. adminUserId: this.userid
  482. }
  483. }),
  484. this.moduleId
  485. )
  486. .then(res => {})
  487. .catch(err => {
  488. this.$message.error('保存失败')
  489. })
  490. },
  491. // 表格恢复初始默认状态
  492. reduction() {
  493. zfireDel({}, this.userid, this.moduleId)
  494. .then(res => {
  495. this.refreshList(true)
  496. })
  497. .catch(err => {
  498. this.$message.error('操作失败')
  499. })
  500. },
  501. // 导出
  502. export() {
  503. this.columnList = this.$refs.zjpage.columnList
  504. },
  505. exportDetermine(data) {
  506. if (!this.exportList) {
  507. return
  508. }
  509. const loading = this.$loading({
  510. lock: true,
  511. text: 'Loading',
  512. spinner: 'el-icon-loading',
  513. background: 'rgba(0, 0, 0, 0.7)'
  514. })
  515. this.evens[0][0].loading = true
  516. this.exportList(
  517. {
  518. ...this.parameter,
  519. pageSize: -1,
  520. exportFields: data
  521. },
  522. `${this.moduleName}.xlsx`
  523. )
  524. .then(res => {
  525. this.$message({
  526. message: '导出成功',
  527. type: 'success'
  528. })
  529. this.columnList = []
  530. this.evens[0][0].loading = false
  531. loading.close()
  532. })
  533. .catch(err => {
  534. this.$message.error('导出失败')
  535. this.columnList = []
  536. this.evens[0][0].loading = false
  537. loading.close()
  538. })
  539. },
  540. refreshList(bool) {
  541. if (bool === true) {
  542. this.showTable = false
  543. this.$refs.zjpage.refresh()
  544. } else {
  545. this.$refs.zjpage.refresh()
  546. }
  547. }
  548. }
  549. }
  550. </script>
  551. <style lang="scss" scoped>
  552. .template-page-1 {
  553. width: 100%;
  554. height: 100%;
  555. position: relative;
  556. box-sizing: border-box;
  557. min-width: 860px;
  558. overflow: auto;
  559. }
  560. .zj-page-template {
  561. position: relative;
  562. z-index: 0;
  563. }
  564. @font-face {
  565. font-family: 'aliyun_iconfont';
  566. src: url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff2') format('woff2'),
  567. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff') format('woff'),
  568. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.ttf') format('truetype');
  569. }
  570. ::v-deep .el-table__cell {
  571. padding: 0 !important;
  572. }
  573. ::v-deep .el-table--mini td,
  574. ::v-deep .el-table--mini th {
  575. padding: 0 !important;
  576. }
  577. ::v-deep .el-table__column-filter-trigger {
  578. .el-icon-arrow-down {
  579. font-family: aliyun_iconfont !important;
  580. font-size: 13px;
  581. line-height: 34px;
  582. font-style: normal;
  583. font-weight: 400;
  584. font-variant: normal;
  585. text-transform: none;
  586. vertical-align: baseline;
  587. display: inline-block;
  588. -webkit-font-smoothing: antialiased;
  589. transform: translate(-2px, 1px);
  590. color: #c0c4cc;
  591. width: 20px;
  592. text-align: center;
  593. }
  594. .el-icon-arrow-down:before {
  595. content: '\e64c' !important;
  596. }
  597. }
  598. ::v-deep .zj-buttons-group {
  599. .el-upload-list {
  600. display: none !important;
  601. }
  602. }
  603. ::v-deep .operation-btns {
  604. width: 100%;
  605. height: 35px;
  606. display: flex;
  607. flex-direction: row;
  608. align-items: center;
  609. & > *:not(:last-child) {
  610. margin-right: 5px;
  611. }
  612. .el-button {
  613. margin-left: 0 !important;
  614. }
  615. }
  616. ::v-deep .is-disabled {
  617. .el-textarea__inner,
  618. .el-input__inner,
  619. .el-radio__label,
  620. .el-radio__input {
  621. background-color: #fff !important;
  622. color: #606266 !important;
  623. // border: none !important;
  624. }
  625. }
  626. ::v-deep .el-checkbox.is-bordered.is-checked,
  627. ::v-deep .el-radio.is-bordered.is-checked {
  628. border-color: #409eff !important;
  629. }
  630. ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner,
  631. ::v-deep .el-radio__input.is-checked .el-radio__inner {
  632. border-color: #409eff !important;
  633. background: #409eff !important;
  634. }
  635. ::v-deep .el-checkbox.is-bordered {
  636. margin-left: 0 !important;
  637. margin-right: 10px !important;
  638. }
  639. </style>