|
@@ -0,0 +1,149 @@
|
|
|
+import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
|
|
|
+import VueViews from '@/benyun/compVue/VueViews'
|
|
|
+import lodash from 'lodash' //导入深度拷贝
|
|
|
+export default class ModuleViewHandle extends VueViews{
|
|
|
+ searchID=this.getUuid(); //搜索id
|
|
|
+ toolID=this.getUuid(); // 工具栏id
|
|
|
+ tableID=this.getUuid(); //表格id
|
|
|
+ hideSearch=false // 隐藏/显示搜索
|
|
|
+ load=false
|
|
|
+ time:any;
|
|
|
+ timeNum = 0;
|
|
|
+
|
|
|
+ value:any=null;
|
|
|
+ config:any={}
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ super()
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示/隐藏搜索
|
|
|
+ toggleSearch(){
|
|
|
+ this.hideSearch = !this.hideSearch
|
|
|
+ }
|
|
|
+
|
|
|
+ getUuid(){
|
|
|
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取查询值
|
|
|
+ getQuery(){
|
|
|
+ let query:any = (this.$refs[this.searchID] as any).getValue();
|
|
|
+ const page:any = (this.$refs[this.tableID] as any).getPage();
|
|
|
+ query.pageNum = page.pageNo;
|
|
|
+ query.pageSize = page.pageSize;
|
|
|
+ return query;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取数据列表
|
|
|
+ getList(){
|
|
|
+ if(!this.$refs[this.tableID]){
|
|
|
+ if(this.timeNum > 4){
|
|
|
+ clearInterval(this.time)
|
|
|
+ }
|
|
|
+ this.time =setInterval(()=>{
|
|
|
+ this.getList()
|
|
|
+ },500)
|
|
|
+ this.timeNum ++;
|
|
|
+ return
|
|
|
+ }
|
|
|
+ clearInterval(this.time)
|
|
|
+ let query = this.getQuery();
|
|
|
+ this.$emit("listAfter",query);
|
|
|
+ this.load = true;
|
|
|
+ this.requestHandle({
|
|
|
+ url: this.requestConfig.url+'/list',
|
|
|
+ method: 'get',
|
|
|
+ params:query,
|
|
|
+ success:(res:any) => {
|
|
|
+ this.load = false;
|
|
|
+ const data:Array<any>=res.rows?res.rows:res.data?res.data:[];
|
|
|
+ if(this.$refs[this.tableID]){
|
|
|
+ (this.$refs[this.tableID] as any).setValue(data);
|
|
|
+ (this.$refs[this.tableID] as any).setPage({total:res.total})
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail:(err:any) => {
|
|
|
+ this.load = false;
|
|
|
+ this.failHandle(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除
|
|
|
+ onDelete(){
|
|
|
+ let data = (this.$refs[this.tableID] as any).getSelectData();
|
|
|
+ if(!data || data.length == 0){
|
|
|
+ this.$message('请选择数据!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let id = '';
|
|
|
+ data.forEach((item:any) => {
|
|
|
+ if(item.id){
|
|
|
+ id = id ? id + ',' + item.id : item.id
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.requestHandle({
|
|
|
+ url: this.requestConfig.url+'/'+id,
|
|
|
+ method: 'delete',
|
|
|
+ success:(res:any) => {
|
|
|
+ this.load = false;
|
|
|
+ this.getList();
|
|
|
+ },
|
|
|
+ fail:(err:any) => {
|
|
|
+ this.load = false;
|
|
|
+ this.failHandle(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ //刷新
|
|
|
+ onRefresh(){
|
|
|
+ (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0})
|
|
|
+ this.getList();
|
|
|
+ }
|
|
|
+
|
|
|
+ //搜索
|
|
|
+ searchHandle(){
|
|
|
+ (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0})
|
|
|
+ this.getList();
|
|
|
+ }
|
|
|
+ //重置
|
|
|
+ resertHandle(){
|
|
|
+ (this.$refs[this.searchID] as any).setValue({})
|
|
|
+ (this.$refs[this.tableID] as any).setPage({pageNo:1,total:0})
|
|
|
+ this.getList();
|
|
|
+ }
|
|
|
+
|
|
|
+ //导出
|
|
|
+ onExport(){
|
|
|
+ if(this.requestConfig?.url){
|
|
|
+ let urlArr = this.requestConfig.url.split('/');
|
|
|
+ let query = this.getQuery();
|
|
|
+ (this as any).$download(this.requestConfig?.url + '/export',{
|
|
|
+ ...query
|
|
|
+ },urlArr[urlArr.length - 1] + `_${new Date().getTime()}.xlsx`)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ failHandle(err:any){
|
|
|
+ let msg = err.msg ? err.msg :'运行错误!';
|
|
|
+ this.$message.error(msg)
|
|
|
+ }
|
|
|
+
|
|
|
+ //请求
|
|
|
+ requestHandle(requestParames:any){
|
|
|
+ if(requestParames && requestParames.url){
|
|
|
+ (this as any).$request(requestParames).then((res:any) => {
|
|
|
+ if(requestParames.success){
|
|
|
+ requestParames.success(res)
|
|
|
+ }
|
|
|
+ }).catch((err:any) => {
|
|
|
+ if(requestParames.fail){
|
|
|
+ requestParames.fail(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|