template-page-1.vue 18 KB

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