moduleView.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="module-view"
  3. :style="{height:attrs.calculateH?'100%':'auto'}"
  4. v-loading="load"
  5. :ref="viewID"
  6. element-loading-text="拼命加载中"
  7. element-loading-spinner="el-icon-loading"
  8. element-loading-background="rgba(0, 0, 0, 0.5)"
  9. >
  10. <div class="search" v-if="searchConfig" v-show="!hideSearch">
  11. <by-form :propConfig="searchConfig" :ref="searchID"></by-form>
  12. <div class="search-btn">
  13. <el-button type="primary" size="small" icon="el-icon-search" @click="search">搜索</el-button>
  14. <el-button size="small" icon="el-icon-refresh" @click="resert">重置</el-button>
  15. </div>
  16. </div>
  17. <div class="tool-box" v-if="toolConfig">
  18. <by-tool :propConfig="toolConfig" :ref="toolID" @clickHandle="clickHandle" />
  19. </div>
  20. <div class="module-main" v-if="tableConfig">
  21. <slot name="left"></slot>
  22. <div class="table">
  23. <by-table :propConfig="tableConfig" :ref="tableID" @pagination="paginationChange" @detail="detail" @onChangeRow="onChangeRow" />
  24. </div>
  25. </div>
  26. <transition name="el-zoom-in-center" v-if="modalConfig">
  27. <div class="view-modal" v-show="modalShow">
  28. <div class="tool-box" v-if="modalConfig.tool">
  29. <by-tool :propConfig="modalConfig.tool" @clickHandle="modalHandle" ref="toolForm" />
  30. </div>
  31. <div class="view-form">
  32. <by-form :propConfig="modalConfig.form" :ref="formID"></by-form>
  33. </div>
  34. </div>
  35. </transition>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. import { Component, Prop, Vue, Watch,Mixins } from "vue-property-decorator";
  40. import ModuleViewHandle from '@/benyun/compVue/ModuleViewHandle'
  41. interface Page{
  42. pageNo?:number,
  43. pageSize?:number,
  44. total?:number
  45. }
  46. @Component
  47. export default class ModuleView extends ModuleViewHandle {
  48. modalShow=false;
  49. get attrs(){
  50. return this.config.attr ? this.config.attr : {};
  51. }
  52. //搜索配置
  53. get searchConfig(){
  54. return this.config?.search ? this.config.search : null;
  55. }
  56. //工具栏配置
  57. get toolConfig(){
  58. return this.config?.tool ? this.config.tool : null
  59. }
  60. //表格配置
  61. get tableConfig(){
  62. return this.config?.table ? this.config.table : null
  63. }
  64. //弹窗
  65. get modalConfig(){
  66. return this.config.modal ? this.config.modal : null
  67. }
  68. calculateCount=0;
  69. created(){
  70. if(this.propConfig){
  71. this.setConfig(this.propConfig)
  72. }
  73. }
  74. mounted(){
  75. // this.getList()
  76. this.$nextTick(()=>{
  77. if(this.attrs.calculateH){
  78. this.initTable();
  79. }
  80. })
  81. }
  82. initTable(){
  83. if(!this.$refs[this.tableID]){
  84. this.calculateCount ++;
  85. if(this.calculateCount > 5){
  86. return
  87. }
  88. setTimeout(()=>{
  89. this.initTable()
  90. },500)
  91. return
  92. }
  93. let fHeight = 0;
  94. let tHeight = 0;
  95. let vHeight = (this as any).$el.offsetHeight;
  96. if(this.$refs[this.searchID] && !this.hideSearch){
  97. fHeight = (this.$refs[this.searchID] as any).$el.offsetHeight + 32 + 8;
  98. }
  99. if(this.$refs[this.toolID]){
  100. tHeight = (this.$refs[this.toolID] as any).$el.offsetHeight + 16;
  101. }
  102. if(this.config.table && vHeight > 0){
  103. const h = vHeight - 32 - fHeight - tHeight - 48;
  104. this.config.table.attr.height = h;
  105. if(this.$refs[this.tableID]){
  106. (this.$refs[this.tableID] as any).recalculate();
  107. }
  108. }
  109. }
  110. search(){
  111. (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0});
  112. this.$emit('search');
  113. // this.searchHandle()
  114. }
  115. detail(row:any){
  116. this.$emit('detail',row);
  117. if(this.$refs[this.formID]){
  118. (this.$refs[this.formID] as any).setValue(row);
  119. this.modalShow = true;
  120. }
  121. }
  122. //清除搜索条件
  123. clearSearch(){
  124. (this.$refs[this.searchID] as any).clearValue();
  125. }
  126. resert(){
  127. this.resertHandle()
  128. }
  129. clickHandle(e:string){
  130. if(e == 'onAdd'){
  131. this.modalShow = true;
  132. }
  133. if((this as any)[e]){
  134. (this as any)[e]()
  135. }else{
  136. this.$emit('clickHandle',e)
  137. }
  138. if(e == 'toggleSearch'){
  139. this.calculateCount=0;
  140. setTimeout(()=>{
  141. this.initTable()
  142. },100)
  143. }
  144. }
  145. //弹窗工具栏
  146. modalHandle(e:string){
  147. if(e == 'onReturn'){
  148. this.modalShow = false;
  149. (this.$refs[this.formID] as any).clearValue();
  150. }else{
  151. this.$emit('modalHandle',e)
  152. }
  153. }
  154. closeModal(){
  155. this.modalShow=false;
  156. }
  157. getSelectData(){
  158. let data:Array<any>=[];
  159. if(this.$refs[this.tableID]){
  160. data=(this.$refs[this.tableID] as any).getSelectData()
  161. }
  162. return data;
  163. }
  164. //清除选中表格
  165. clearCheckboxRow(){
  166. if(this.$refs[this.tableID]){
  167. (this.$refs[this.tableID] as any).clearCheckboxRow()
  168. }
  169. }
  170. //设置表格数据
  171. setTableValue(data:Array<any>){
  172. if(this.$refs[this.tableID]){
  173. (this.$refs[this.tableID] as any).setValue(data)
  174. }
  175. }
  176. getPage(){
  177. let p = {};
  178. if(this.$refs[this.tableID]){
  179. p=(this.$refs[this.tableID] as any).getPage()
  180. }
  181. return p;
  182. }
  183. setPage(page:Page){
  184. if(this.$refs[this.tableID]){
  185. (this.$refs[this.tableID] as any).setPage(page)
  186. }
  187. }
  188. //分页的变化
  189. paginationChange(page:any){
  190. this.$emit('pagination',page)
  191. // this.getList();
  192. }
  193. getFormValidate(callBack:Function){
  194. (this.$refs[this.formID] as any).validate().then(()=>{
  195. callBack()
  196. })
  197. }
  198. getFormValue(){
  199. if(this.$refs[this.formID]){
  200. (this.$refs[this.formID] as any)
  201. return (this.$refs[this.formID] as any).getValue();
  202. }
  203. return null
  204. }
  205. initFormTool(){
  206. if(this.$refs.toolForm){
  207. (this.$refs.toolForm as any).initTools();
  208. }
  209. }
  210. onChangeRow(row:any){
  211. this.$emit('onChangeRow',row);
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .module-view{
  217. width: 100%;
  218. box-sizing: border-box;
  219. padding: 16px;
  220. position: relative;
  221. .view-modal{
  222. height: 100%;
  223. width: 100%;
  224. position: absolute;
  225. left: 0;
  226. top: 0;
  227. box-sizing: border-box;
  228. padding: 16px;
  229. background-color: #FFF;
  230. z-index: 999;
  231. .view-form{
  232. width: 100%;
  233. height: calc(100% - 48px);
  234. overflow-y: auto;
  235. }
  236. }
  237. .search{
  238. width: 100%;
  239. padding-bottom: 8px;
  240. .search-btn{
  241. width: 100%;
  242. display: flex;
  243. justify-content: flex-end;
  244. }
  245. }
  246. .tool-box{
  247. width: 100%;
  248. padding-bottom:16px;
  249. }
  250. .module-main{
  251. width: 100%;
  252. display: flex;
  253. .table{
  254. width: 100%;
  255. }
  256. }
  257. }
  258. </style>