ModuleViewHandle.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
  2. import VueViews from '@/benyun/compVue/VueViews'
  3. import lodash from 'lodash' //导入深度拷贝
  4. export default class ModuleViewHandle extends VueViews{
  5. searchID=this.getUuid(); //搜索id
  6. toolID=this.getUuid(); // 工具栏id
  7. tableID=this.getUuid(); //表格id
  8. viewID=this.getUuid();
  9. formID=this.getUuid();
  10. hideSearch=false // 隐藏/显示搜索
  11. load=false
  12. time:any;
  13. timeNum = 0;
  14. constructor() {
  15. super()
  16. }
  17. //显示/隐藏搜索
  18. toggleSearch(){
  19. this.hideSearch = !this.hideSearch
  20. }
  21. getUuid(){
  22. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  23. }
  24. //获取查询值
  25. getQuery(){
  26. let query:any = {};
  27. let page:any = {};
  28. if(this.$refs[this.searchID]){
  29. query = (this.$refs[this.searchID] as any).getValue();
  30. }
  31. if(this.$refs[this.tableID]){
  32. page = (this.$refs[this.tableID] as any).getPage();
  33. }
  34. query.pageNo = page.pageNo;
  35. query.pageSize = page.pageSize;
  36. return query;
  37. }
  38. //获取数据列表
  39. getList(){
  40. if(!this.requestConfig || !this.requestConfig.url){
  41. return
  42. }
  43. if(!this.$refs[this.tableID]){
  44. if(this.timeNum > 4){
  45. clearInterval(this.time)
  46. }
  47. this.time =setInterval(()=>{
  48. this.getList()
  49. },500)
  50. this.timeNum ++;
  51. return
  52. }
  53. clearInterval(this.time)
  54. let query = this.getQuery();
  55. this.$emit("listAfter",query);
  56. this.load = true;
  57. this.requestHandle({
  58. url: this.requestConfig.url+'/list',
  59. method: 'get',
  60. params:query,
  61. success:(res:any) => {
  62. this.load = false;
  63. const data:Array<any>=res.rows?res.rows:res.data?res.data:[];
  64. if(this.$refs[this.tableID]){
  65. (this.$refs[this.tableID] as any).setValue(data);
  66. (this.$refs[this.tableID] as any).setPage({total:res.total})
  67. }
  68. },
  69. fail:(err:any) => {
  70. this.load = false;
  71. this.failHandle(err);
  72. }
  73. })
  74. }
  75. //删除
  76. // onDelete(){
  77. // let data = (this.$refs[this.tableID] as any).getSelectData();
  78. // if(!data || data.length == 0){
  79. // this.$message('请选择数据!')
  80. // return
  81. // }
  82. // let id = '';
  83. // data.forEach((item:any) => {
  84. // if(item.id){
  85. // id = id ? id + ',' + item.id : item.id
  86. // }
  87. // });
  88. // this.requestHandle({
  89. // url: this.requestConfig.url+'/'+id,
  90. // method: 'delete',
  91. // success:(res:any) => {
  92. // this.load = false;
  93. // this.getList();
  94. // },
  95. // fail:(err:any) => {
  96. // this.load = false;
  97. // this.failHandle(err);
  98. // }
  99. // })
  100. // }
  101. //刷新
  102. onRefresh(){
  103. (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0});
  104. this.$emit('onRefresh')
  105. }
  106. // onRefresh(){
  107. // (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0})
  108. // this.getList();
  109. // this.$emit('onRefresh')
  110. // }
  111. //搜索
  112. searchHandle(){
  113. (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0})
  114. this.getList();
  115. }
  116. //重置
  117. resertHandle(){
  118. (this.$refs[this.searchID] as any).clearValue({});
  119. (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0})
  120. this.$emit('resert')
  121. // this.getList();
  122. }
  123. //导出
  124. onExport(){
  125. if(this.requestConfig?.url){
  126. let urlArr = this.requestConfig.url.split('/');
  127. let query = this.getQuery();
  128. (this as any).$download(this.requestConfig.url + '/export',{
  129. ...query
  130. },urlArr[urlArr.length - 1] + `_${new Date().getTime()}.xlsx`)
  131. }
  132. }
  133. failHandle(err:any){
  134. let msg = err.msg ? err.msg :'运行错误!';
  135. this.$message.error(msg)
  136. }
  137. }