template-page-1.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <zj-page-template ref="zjpage" style="width: 100%;height: 100%;" :get-table-data="getTableData" :options-evens="evens"
  3. :options-evens-group="selBtn(optionsEvensGroup)"
  4. :table-attributes="{ ...defaultTableAttributes, ...tableAttributes }"
  5. :table-events="{ ...defaultTableEvents, ...tableEvents }" :column-parsing="columnParsing" :reduction="reduction"
  6. :plan="[...plan, ...morePlan]" :operation="operation" :operation-column-width="operationColumnWidth"
  7. :show-table="showTable" :code-gather="codeGather" @columnWidthChange="columnWidthChange"
  8. @columnListChange="columnListChange">
  9. <sel-export-column-list :column-list="columnList" @determine="exportDetermine" @cancel="columnList = []" />
  10. <slot />
  11. </zj-page-template>
  12. </template>
  13. <script>
  14. import { zfireSave, zfireDel, commonDict } from "@/api/user";
  15. import SelExportColumnList from './sel-export-column-list'
  16. export default {
  17. components: {
  18. SelExportColumnList
  19. },
  20. props: {
  21. // 事件组合
  22. optionsEvensGroup: {
  23. type: Array,
  24. default: () => []
  25. },
  26. // 表格属性
  27. tableAttributes: {
  28. type: Object,
  29. default: () => ({})
  30. },
  31. // 表格事件
  32. tableEvents: {
  33. type: Object,
  34. default: () => ({})
  35. },
  36. // 表格列解析渲染数据更改
  37. columnParsing: {
  38. type: Function
  39. },
  40. // 获取列表的方法
  41. getList: {
  42. type: Function
  43. },
  44. // 导出的方法
  45. exportList: {
  46. type: Function
  47. },
  48. morePlan: {
  49. type: Array,
  50. default: () => []
  51. },
  52. operation: {
  53. type: Function
  54. },
  55. operationColumnWidth: {
  56. type: Number,
  57. default: 140
  58. }
  59. },
  60. data() {
  61. return {
  62. // 菜单id
  63. moduleId: this.$route.meta.moduleId,
  64. // 菜单名
  65. moduleName: this.$route.meta.title,
  66. // 搜索的参数
  67. parameter: {},
  68. plan: [
  69. {
  70. name: '默认方案',
  71. paramCallback: () => {
  72. return []
  73. }
  74. }
  75. ],
  76. // 按钮集合
  77. evens: [],
  78. // 表格属性
  79. defaultTableAttributes: {},
  80. // 表格事件
  81. defaultTableEvents: {},
  82. // 记录初始的id
  83. columnsIds: {},
  84. // 导出弹窗
  85. columnList: [],
  86. showTable: false,
  87. codeGather: {}
  88. }
  89. },
  90. computed: {
  91. userid() {
  92. return this.$store.getters.userid
  93. }
  94. },
  95. mounted() {
  96. if (this.exportList) {
  97. this.evens = [
  98. [
  99. {
  100. name: '导出',
  101. click: this.export,
  102. loading: false
  103. }
  104. ]
  105. ]
  106. }
  107. },
  108. methods: {
  109. getDictCode(params) {
  110. commonDict(params).then(res => {
  111. if (res.data.length) {
  112. res.data.map(item => {
  113. if (!this.codeGather[params.code]) {
  114. this.$set(this.codeGather,params.code,[])
  115. }
  116. this.$set(this.codeGather,params.code,[...this.codeGather[params.code],{
  117. label: item.dictValue,
  118. value: item.dictCode
  119. }])
  120. })
  121. }
  122. })
  123. },
  124. selBtn(arr) {
  125. for (var i = 0; i < arr.length; i++) {
  126. if (Array.isArray(arr[i])) {
  127. this.selBtn(arr[i])
  128. }
  129. if (
  130. !(arr[i].isRole || arr[i].isRole === undefined) ||
  131. arr[i].length == 0
  132. ) {
  133. arr.splice(i, 1)
  134. i--
  135. }
  136. }
  137. return arr
  138. },
  139. // 获取列表数据函数
  140. async getTableData(data) {
  141. if (!this.getList) {
  142. return
  143. }
  144. try {
  145. this.parameter = {
  146. pageNum: data.page,
  147. pageSize: data.size,
  148. orderBy: data.orderBy,
  149. params: data.querylist,
  150. moduleId: this.moduleId
  151. }
  152. var res = await this.getList(this.parameter)
  153. // res.data.records = []
  154. if (res.code == 200) {
  155. if (!this.showTable) {
  156. this.$nextTick(() => {
  157. this.showTable = true
  158. })
  159. }
  160. res.fieldBeans.forEach(k => {
  161. if (k.frontCode) {
  162. this.getDictCode({ code: k.frontCode })
  163. }
  164. });
  165. return res
  166. }
  167. } catch (error) {
  168. console.log(error)
  169. }
  170. },
  171. // 监听列表显示状态与排序变化
  172. columnListChange(columnList) {
  173. zfireSave(
  174. this.$refs.zjpage.columnList.map((item, index) => {
  175. var data = {
  176. ...item.exportField,
  177. sortNum: index,
  178. isCopy: item.isCopy,
  179. isTotal: item.isTotal,
  180. isShow: !item.hidden,
  181. moduleId: this.moduleId,
  182. adminUserId: this.userid
  183. }
  184. return data
  185. }),
  186. this.moduleId
  187. )
  188. .then(res => {
  189. })
  190. .catch(err => {
  191. this.$message.error('保存失败')
  192. })
  193. },
  194. // 监听列宽度变化
  195. columnWidthChange({ newWidth, oldWidth, column }) {
  196. zfireSave(
  197. this.$refs.zjpage.columnList.map((item, index) => {
  198. if (item.exportField.jname === column.property) {
  199. item.exportField.width = newWidth
  200. }
  201. return {
  202. ...item.exportField,
  203. sortNum: index,
  204. isCopy: item.isCopy,
  205. isTotal: item.isTotal,
  206. isShow: !item.hidden,
  207. moduleId: this.moduleId,
  208. adminUserId: this.userid
  209. }
  210. }),
  211. this.moduleId
  212. )
  213. .then(res => {
  214. })
  215. .catch(err => {
  216. this.$message.error('保存失败')
  217. })
  218. },
  219. // 表格恢复初始默认状态
  220. reduction() {
  221. zfireDel({}, this.userid, this.moduleId)
  222. .then(res => {
  223. this.$refs.zjpage.refresh()
  224. })
  225. .catch(err => {
  226. this.$message.error('操作失败')
  227. })
  228. },
  229. // 导出
  230. export() {
  231. this.columnList = this.$refs.zjpage.columnList
  232. },
  233. exportDetermine(data) {
  234. if (!this.exportList) {
  235. return
  236. }
  237. this.evens[0][0].loading = true
  238. this.exportList(
  239. {
  240. ...this.parameter,
  241. pageSize: -1,
  242. exportFields: data
  243. },
  244. `${this.moduleName}.xlsx`
  245. )
  246. .then(res => {
  247. this.$message({
  248. message: '导出成功',
  249. type: 'success'
  250. })
  251. this.columnList = []
  252. this.evens[0][0].loading = false
  253. })
  254. .catch(() => {
  255. this.$message.error('导出失败')
  256. this.columnList = []
  257. this.evens[0][0].loading = false
  258. })
  259. },
  260. refreshList() {
  261. this.$refs.zjpage.refresh()
  262. }
  263. }
  264. }
  265. </script>
  266. <style lang="scss" scoped>
  267. @font-face {
  268. font-family: "aliyun_iconfont";
  269. src: url("//at.alicdn.com/t/font_2075393_0cjq4n8ykvds.woff2?t=1647587689181") format("woff2"),
  270. url("//at.alicdn.com/t/font_2075393_0cjq4n8ykvds.woff?t=1647587689181") format("woff"),
  271. url("//at.alicdn.com/t/font_2075393_0cjq4n8ykvds.ttf?t=1647587689181") format("truetype");
  272. }
  273. ::v-deep .el-table__cell {
  274. padding: 0 !important;
  275. }
  276. ::v-deep .el-table__column-filter-trigger {
  277. .el-icon-arrow-down {
  278. font-family: aliyun_iconfont !important;
  279. font-size: 13px;
  280. line-height: 34px;
  281. font-style: normal;
  282. font-weight: 400;
  283. font-variant: normal;
  284. text-transform: none;
  285. vertical-align: baseline;
  286. display: inline-block;
  287. -webkit-font-smoothing: antialiased;
  288. transform: translate(-2px, 1px);
  289. color: #c0c4cc;
  290. }
  291. .el-icon-arrow-down:before {
  292. content: "\e64c" !important;
  293. }
  294. }
  295. ::v-deep .zj-buttons-group {
  296. .el-upload-list {
  297. display: none !important;
  298. }
  299. }
  300. ::v-deep .operation-btns {
  301. width: 100%;
  302. height: 100%;
  303. display: flex;
  304. flex-direction: row;
  305. align-items: center;
  306. &>*:not(:last-child) {
  307. margin-right: 5px;
  308. }
  309. .el-button {
  310. margin-left: 0 !important;
  311. }
  312. }
  313. ::v-deep .is-disabled {
  314. .el-textarea__inner,
  315. .el-input__inner {
  316. background-color: #fff;
  317. color: #606266;
  318. }
  319. }
  320. </style>