# 查询界面添加按钮(隐藏按钮)

An image

# 代码实现

//this.buttons,this.boxButtons, this.detailOptions这些属性在【生成页面文档】中可以查看
onInited() {
    //隐藏查询界面按钮
    this.buttons.forEach((btn) => {
        if (btn.name == '高级查询') {
            btn.hidden = true;
            //或者设置只读
            //btn.readonly=true;
        }
    });

    //添加按钮
    //添加自定义按钮,如果需要按钮授权,参照上面【自定义权限按钮】
    this.buttons.splice(3, 0, {
        name: '自定义按钮', //按钮名称
        icon: 'el-icon-document', //按钮图标https://element.eleme.cn/#/zh-CN/component/icon
        type: 'primary', //按钮样式vue2版本见iview文档button,vue3版本见element ui文档button
       // color:"#ecf5ff",//可以自定义颜色
        plain: true,
        onClick: ()=> {
        this.btnClick();
        }
    })

    //弹出框按钮
    this.boxButtons.forEach((btn) => {
        if (btn.name == '保存') {
            btn.hidden = true;
            //或者设置只读
            //btn.readonly=true;
        }
    });

    //弹出框按钮添加按钮同上
    this.boxButtons.push({按钮参数同上})

    //弹出框添加明细表按钮(注意:弹出框明细表添加按钮需要写在onInited中)
    this.detailOptions.buttons.push({按钮参数同上})

   //弹出框一对多二级明细表按钮,可以输出看里面的对象属性:console.log(this.details)
   this.details.forEach(x=>{
       if(x.table=='表名'){
          //隐藏按钮,操作同上
            x.buttons.forEach(x=>{

            })

          //添加按钮,操作同上
          x.buttons.push({})
       }
   })

    //弹出框一对多三级明细表按钮
    this.subDetails.forEach(x=>{
       if(x.table=='表名'){
          //隐藏按钮,操作同上
            x.buttons.forEach(x=>{

            })

          //添加按钮,操作同上
          x.buttons.push({})
       }
   })

},
modelOpenAfter(row) {
    //弹出框明细表按钮
    //隐藏明细表表格按钮(只能写在弹出框打开后方法)
    //可以根据条件隐藏显示,如:this.currentAction==='Add'或this.currentAction==='Update'
    //row为当前编辑的行数据
    this.detailOptions.buttons.forEach((btn) => {
        if (btn.name == '添加行') {
            btn.hidden = true;
            //或者设置只读
            //btn.readonly=true;
        }
    });
}

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