template-page-1.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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, ...morePlan]"
  13. :operation="operationShow ? caozuojl : operation"
  14. :operationColumnWidth="(operation ? operationColumnWidth : 0) + (operationShow ? 70 : 0)"
  15. :showTable="showTable"
  16. :codeGather="codeGather"
  17. :loading="loading"
  18. :lowerLine="true"
  19. @columnWidthChange="columnWidthChange"
  20. @columnListChange="columnListChange"
  21. >
  22. <template slot="more-search">
  23. <slot name="moreSearch"></slot>
  24. </template>
  25. </zj-page-template>
  26. <sel-export-column-list :columnList="columnList" @determine="exportDetermine" @cancel="columnList = []" />
  27. <slot />
  28. </div>
  29. </template>
  30. <script>
  31. import { zfireSave, zfireDel } from '@/api/fieldMan.js'
  32. import { dictListDict } from '@/api/dataDictionary2.js'
  33. import SelExportColumnList from './sel-export-column-list.vue'
  34. import selectData from './selectData.js'
  35. export default {
  36. components: {
  37. SelExportColumnList
  38. },
  39. props: {
  40. loading: {
  41. type: Boolean,
  42. default: false
  43. },
  44. // 事件组合
  45. optionsEvensGroup: {
  46. type: Array,
  47. default: () => []
  48. },
  49. // 表格属性
  50. tableAttributes: {
  51. type: Object,
  52. default: () => ({})
  53. },
  54. // 表格事件
  55. tableEvents: {
  56. type: Object,
  57. default: () => ({})
  58. },
  59. // 表格列解析渲染数据更改
  60. columnParsing: {
  61. type: Function
  62. },
  63. // 获取列表的方法
  64. getList: {
  65. type: Function
  66. },
  67. // 导出的方法
  68. exportList: {
  69. type: Function
  70. },
  71. // 更多方案
  72. morePlan: {
  73. type: Array,
  74. default: () => []
  75. },
  76. // 操作按钮
  77. operation: {
  78. type: Function
  79. },
  80. // 是否显示操作记录
  81. operationShow: {
  82. type: Boolean,
  83. default: true
  84. },
  85. // 获取操作记录的主键字段
  86. operationRecordkey: {
  87. type: String,
  88. default: ''
  89. },
  90. // 操作按钮单元格宽度
  91. operationColumnWidth: {
  92. type: Number,
  93. default: 140
  94. },
  95. // 自定义列
  96. cstomClumn: {
  97. type: Function
  98. },
  99. // 结构数据钩子
  100. fieldBeansHook: {
  101. type: Function
  102. },
  103. // 菜单名称
  104. customModuleName: {
  105. type: String,
  106. default: ''
  107. }
  108. },
  109. data() {
  110. return {
  111. // 菜单id
  112. moduleId: this.$route.meta.moduleId,
  113. // 菜单名
  114. moduleName: this.customModuleName || this.$route.meta.title,
  115. // 搜索的参数
  116. parameter: {},
  117. // 按钮集合
  118. evens: [],
  119. // 表格属性
  120. defaultTableAttributes: {},
  121. // 表格事件
  122. defaultTableEvents: {},
  123. // 记录初始的id
  124. columnsIds: {},
  125. // 导出弹窗
  126. columnList: [],
  127. showTable: false,
  128. codeGather: {},
  129. frontCodes: [],
  130. pk: '',
  131. createTimeKey: ''
  132. }
  133. },
  134. computed: {
  135. userid() {
  136. return this.$store.getters.userid
  137. },
  138. defaultPlan() {
  139. if (this.createTimeKey) {
  140. var [y, m, d] = new Date(new Date().getTime()).toJSON().split('T').join(' ').substr(0, 10).split('-')
  141. return [
  142. {
  143. name: '默认方案',
  144. paramCallback: () => {
  145. return []
  146. }
  147. },
  148. {
  149. name: '今日',
  150. paramCallback: () => {
  151. return [
  152. { param: this.createTimeKey, compare: '>', value: `${y}-${m}-${Number(d) - 1} 23:59:59` },
  153. { param: this.createTimeKey, compare: '<', value: `${y}-${m}-${Number(d) + 1} 00:00:00` }
  154. ]
  155. }
  156. },
  157. {
  158. name: '昨日',
  159. paramCallback: () => {
  160. return [
  161. { param: this.createTimeKey, compare: '>', value: `${y}-${m}-${Number(d) - 2} 23:59:59` },
  162. { param: this.createTimeKey, compare: '<', value: `${y}-${m}-${Number(d)} 00:00:00` }
  163. ]
  164. }
  165. }
  166. ]
  167. }
  168. return [
  169. {
  170. name: '默认方案',
  171. paramCallback: () => {
  172. return []
  173. }
  174. }
  175. ]
  176. }
  177. },
  178. mounted() {
  179. if (this.exportList) {
  180. this.evens = [
  181. [
  182. {
  183. name: '导出',
  184. click: this.export,
  185. loading: false
  186. }
  187. ]
  188. ]
  189. }
  190. },
  191. methods: {
  192. caozuojl(h, { row, index, column }) {
  193. return (
  194. <div class="operation-btns">
  195. <el-button
  196. size="mini"
  197. type="text"
  198. onClick={() => {
  199. console.log(row[this.operationRecordkey || this.pk || 'id'])
  200. }}
  201. >
  202. 操作记录
  203. </el-button>
  204. {this.operation ? this.operation(h, { row, index, column }) : null}
  205. </div>
  206. )
  207. },
  208. selBtn(arr) {
  209. for (var i = 0; i < arr.length; i++) {
  210. if (Array.isArray(arr[i])) {
  211. this.selBtn(arr[i])
  212. }
  213. if (!(arr[i].isRole || arr[i].isRole === undefined) || arr[i].length == 0) {
  214. arr.splice(i, 1)
  215. i--
  216. }
  217. }
  218. return arr
  219. },
  220. // 获取下拉对应数据
  221. getCodeGather() {
  222. let codes = this.frontCodes.filter(key => (this.codeGather[key] ? false : true))
  223. if (codes && codes.length) {
  224. var codeGather = {}
  225. Promise.all(
  226. codes.map(code => {
  227. if (selectData[code]) {
  228. return selectData[code]()
  229. }
  230. return dictListDict({ code: code })
  231. })
  232. ).then(resAll => {
  233. codes.map((code, index) => {
  234. var arr = resAll[index].data.map(item => {
  235. return { value: item.dictCode, label: item.dictValue }
  236. })
  237. codeGather[code] = arr
  238. })
  239. this.codeGather = { ...this.codeGather, ...codeGather }
  240. })
  241. }
  242. },
  243. // 获取列表数据函数
  244. async getTableData(data) {
  245. if (!this.getList) {
  246. return
  247. }
  248. try {
  249. this.parameter = {
  250. pageNum: data.page,
  251. pageSize: data.size,
  252. orderBy: data.orderBy,
  253. params: data.querylist,
  254. moduleId: this.moduleId
  255. }
  256. var res = await this.getList(this.parameter)
  257. if (res.code == 200) {
  258. if (!this.showTable) {
  259. this.$nextTick(() => {
  260. this.showTable = true
  261. })
  262. }
  263. if (this.fieldBeansHook) {
  264. res.fieldBeans = this.fieldBeansHook(res.fieldBeans) || res.fieldBeans
  265. }
  266. for (var item of res.fieldBeans) {
  267. if (!this.createTimeKey && item.jname === 'createTime') {
  268. this.createTimeKey = `${item.tbName ? item.tbName + '.' : ''}${item.colName}`
  269. }
  270. if (item.pk) {
  271. this.pk = item.colName
  272. }
  273. if (item.frontCode && !~this.frontCodes.indexOf(item.frontCode)) {
  274. this.frontCodes.push(item.frontCode)
  275. }
  276. if (this.cstomClumn && item.label === 'cstomClumn') {
  277. this.cstomClumn(item.jname, res.data.records, res.fieldBeans, this.parameter)
  278. }
  279. }
  280. this.getCodeGather()
  281. return res
  282. }
  283. } catch (error) {
  284. console.log(error)
  285. }
  286. },
  287. // 监听列表显示状态与排序变化
  288. columnListChange(columnList) {
  289. zfireSave(
  290. this.$refs.zjpage.columnList.map((item, index) => {
  291. var data = {
  292. ...item.exportField,
  293. sortNum: index,
  294. isCopy: item.isCopy,
  295. isTotal: item.isTotal,
  296. isShow: !item.hidden,
  297. moduleId: this.moduleId,
  298. adminUserId: this.userid
  299. }
  300. return data
  301. }),
  302. this.moduleId
  303. )
  304. .then(res => {})
  305. .catch(err => {
  306. this.$message.error('保存失败')
  307. })
  308. },
  309. // 监听列宽度变化
  310. columnWidthChange({ newWidth, oldWidth, column }) {
  311. zfireSave(
  312. this.$refs.zjpage.columnList.map((item, index) => {
  313. if (item.exportField.jname === column.property) {
  314. item.exportField.width = newWidth
  315. }
  316. return {
  317. ...item.exportField,
  318. sortNum: index,
  319. isCopy: item.isCopy,
  320. isTotal: item.isTotal,
  321. isShow: !item.hidden,
  322. moduleId: this.moduleId,
  323. adminUserId: this.userid
  324. }
  325. }),
  326. this.moduleId
  327. )
  328. .then(res => {})
  329. .catch(err => {
  330. this.$message.error('保存失败')
  331. })
  332. },
  333. // 表格恢复初始默认状态
  334. reduction() {
  335. zfireDel({}, this.userid, this.moduleId)
  336. .then(res => {
  337. this.refreshList(true)
  338. })
  339. .catch(err => {
  340. this.$message.error('操作失败')
  341. })
  342. },
  343. // 导出
  344. export() {
  345. this.columnList = this.$refs.zjpage.columnList
  346. },
  347. exportDetermine(data) {
  348. if (!this.exportList) {
  349. return
  350. }
  351. const loading = this.$loading({
  352. lock: true,
  353. text: 'Loading',
  354. spinner: 'el-icon-loading',
  355. background: 'rgba(0, 0, 0, 0.7)'
  356. })
  357. this.evens[0][0].loading = true
  358. this.exportList(
  359. {
  360. ...this.parameter,
  361. pageSize: -1,
  362. exportFields: data
  363. },
  364. `${this.moduleName}.xlsx`
  365. )
  366. .then(res => {
  367. this.$message({
  368. message: '导出成功',
  369. type: 'success'
  370. })
  371. this.columnList = []
  372. this.evens[0][0].loading = false
  373. loading.close()
  374. })
  375. .catch(err => {
  376. this.$message.error('导出失败')
  377. this.columnList = []
  378. this.evens[0][0].loading = false
  379. loading.close()
  380. })
  381. },
  382. refreshList(bool) {
  383. if (bool === true) {
  384. this.showTable = false
  385. this.$refs.zjpage.refresh()
  386. } else {
  387. this.$refs.zjpage.refresh()
  388. }
  389. }
  390. }
  391. }
  392. </script>
  393. <style lang="scss" scoped>
  394. .template-page-1 {
  395. width: 100%;
  396. height: 100%;
  397. position: relative;
  398. box-sizing: border-box;
  399. min-width: 860px;
  400. overflow: auto;
  401. }
  402. .zj-page-template {
  403. position: relative;
  404. z-index: 0;
  405. }
  406. @font-face {
  407. font-family: 'aliyun_iconfont';
  408. src: url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff2') format('woff2'),
  409. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff') format('woff'),
  410. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.ttf') format('truetype');
  411. }
  412. ::v-deep .el-table__cell {
  413. padding: 0 !important;
  414. }
  415. ::v-deep .el-table--mini td,
  416. ::v-deep .el-table--mini th {
  417. padding: 0 !important;
  418. }
  419. ::v-deep .el-table__column-filter-trigger {
  420. .el-icon-arrow-down {
  421. font-family: aliyun_iconfont !important;
  422. font-size: 13px;
  423. line-height: 34px;
  424. font-style: normal;
  425. font-weight: 400;
  426. font-variant: normal;
  427. text-transform: none;
  428. vertical-align: baseline;
  429. display: inline-block;
  430. -webkit-font-smoothing: antialiased;
  431. transform: translate(-2px, 1px);
  432. color: #c0c4cc;
  433. width: 20px;
  434. text-align: center;
  435. }
  436. .el-icon-arrow-down:before {
  437. content: '\e64c' !important;
  438. }
  439. }
  440. ::v-deep .zj-buttons-group {
  441. .el-upload-list {
  442. display: none !important;
  443. }
  444. }
  445. ::v-deep .operation-btns {
  446. width: 100%;
  447. height: 35px;
  448. display: flex;
  449. flex-direction: row;
  450. align-items: center;
  451. & > *:not(:last-child) {
  452. margin-right: 5px;
  453. }
  454. .el-button {
  455. margin-left: 0 !important;
  456. }
  457. }
  458. ::v-deep .is-disabled {
  459. .el-textarea__inner,
  460. .el-input__inner,
  461. .el-radio__label,
  462. .el-radio__input {
  463. background-color: #fff !important;
  464. color: #606266 !important;
  465. // border: none !important;
  466. }
  467. }
  468. ::v-deep .el-checkbox.is-bordered.is-checked,
  469. ::v-deep .el-radio.is-bordered.is-checked {
  470. border-color: #409eff !important;
  471. }
  472. ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner,
  473. ::v-deep .el-radio__input.is-checked .el-radio__inner {
  474. border-color: #409eff !important;
  475. background: #409eff !important;
  476. }
  477. ::v-deep .el-checkbox.is-bordered {
  478. margin-left: 0 !important;
  479. margin-right: 10px !important;
  480. }
  481. </style>