xiejun
2023-05-29 3821dc55664384df25b6f7d712b889c17537bf06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<template>
<basic-container>
  <avue-crud ref="crud"
             :data="data"
             :option="option"
             @sort-change="sortChange"
             v-loading="loading"
             :page="page"
             @selection-change="selectionChange"
             @on-load="onLoad">
      <template slot="menu">
        <el-button type="text">文字按钮</el-button>
      </template>
  </avue-crud>
</basic-container>
</template>
 
<script>
import { MasterTable,TableData } from "@/api/GetItem";
export default {
  name: "Crud.vue",
  data(){
    return{
      loading:false,
      data:[],
      option:{
        //默认高度,
        align:'center',
        menuAlign:'center',
        addBtn:false,
        editBtn:false,
        selection:true,
        selectionFixed:false,
        index:true,
        column:[]
      },
      List:[],
      columnType: {
        text: "input",
        combox: "select",
        truefalse: "switch",
        number: "number",
        datetime:"datetime",
      },
      page:{
        total: 0,
        currentPage: 1,
        pageSize: 10,
        pageSizes: [10, 30, 50, 100, 200],
      },
    }
  },
  created() {
      this.CrudHeaderRend();
      this.CrudRend()
  },
  activated() {
    this.doLayout()
  },
  methods:{
    doLayout() {
      this.$nextTick(() => {
        this.$refs.crud.doLayout();
      });
    },
    //表格头渲染
    CrudHeaderRend(){
      MasterTable({codeClassifyOid:"D9CF223F-317D-71EB-BD11-433A94CAD9F3",functionId: 5,_: 1685067339479}).then(res=>{
        this.List=res.data.tableDefineVO.cols[0];
        this.List.forEach(item=>{
          let columnItem={
            label:item.title,
            prop:item.field,
            type:this.columnType[item.type],
            sortable:item.sort,
            width:item.minWidth
          };
          this.option.column.push(columnItem);
 
        })
      })
    },
    //表格数据
    CrudRend(){
      TableData({templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        page: this.page.currentPage,
        limit: this.page.pageSize,
        _: 1685089123575
      }).then(res=>{
        this.page.total=res.data.total;
        this.data=res.data.data;
      })
    },
    // 排序
    sortChange(val){
      this.loading=true;
      let order=""
      if(val.order == "ascending"){
        order="asc";
      }else {
        order="desc";
      }
      TableData(  {
        templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        order:order,
        sort:val.prop,
        page: this.page.currentPage,
        limit: this.page.pageSize,
      }).then(res=>{
        setTimeout(() => {
          this.data=res.data.data;
          this.loading=false;
        }, 100);
      })
    },
    //分页刷新
    async onLoad(val){
      console.log(val)
     await TableData({templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        page: val.currentPage,
        limit: val.pageSize,
        _: 1685089123575
      }).then(res=>{
       this.data=res.data.data;
      })
    },
    //多选
    selectionChange(row){
      console.log(row)
    }
  }
}
</script>
 
<style scoped>
 
</style>