moduleView.vue 6.8 KB

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