当前位置:   article > 正文

vue2实现一个抽屉组件封装_vue2中的右侧抽屉怎么搞

vue2中的右侧抽屉怎么搞

vue2实现一个抽屉组件封装

组件

<!-- 凭证管理 - 添加凭证 -->
<template>
    <div class="add-voucher">
        <el-drawer
            :title="title"
            :visible.sync="dialogVisible"
            :close-on-press-escape="false"
            :close-on-click-modal="false"
            :wrapper-closable="false"
            :destroy-on-close="true"
            direction="rtl"
            :size="650"
            @close="closeDrawer()"
        >
            <div class="drawer-wrap">
                <el-form
                    ref="ruleFormRef"
                    :model="form"
                    label-width="145px"
                    :rules="rules"
                >
                </el-form>
            </div>
            <div class="demo-drawer__footer">
                <el-button @click="closeDrawer">
                    取 消
                </el-button>
                <el-button
                    type="primary"
                    :loading="loading"
                    @click="submitForm('form')"
                >
                    {{ loading ? '提交中 ...' : '确 定' }}
                </el-button>
            </div>
        </el-drawer>
    </div>
</template>

<script>
export default {
    name: 'AddVoucher',
    components: { },
    data() {
        let validatePass2 = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请再次输入密码'));
            } else if (value !== this.form.authPassword) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        };
        let validatePass3 = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请再次输入密码'));
            } else if (value !== this.form.privPassword) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        };
        return {
            dialogVisible: false,
            loading: false,
            cerTypeOptions: [{label: 'SNMPV1/V2', value: 'SNMPV1/V2'}, {label: 'SNMPV3', value: 'SNMPV3'}],
            authProtocolOptions: [{label: '-', value: '-'}, {label: 'MD5', value: 'MD5'}, {label: 'SHA', value: 'SHA'}],
            privProtocolOptions: [{label: '-', value: '-'}, {label: 'DES', value: 'DES'}, {label: 'AES-128', value: 'AES-128'},
                {label: 'AES-192', value: 'AES-192'}, {label: 'AES-256', value: 'AES-256'}],
            cascadeFlot: [],
            form: {
                cerType: 'SNMPV1/V2',
                name: '',
                describe: '',
                readCommunity: '', 
                username: '', 
                authProtocol: '',
                authPassword: '',
                authPasswordRepeat: '',
                privProtocol: '',
                privPassword: '',
                privPasswordRepeat: '',
                writeCommunity: '', 
                context: '', 
                port: '',
                timeOut: '',
            },
            title: '',
            type: '',
            editId: '',
            rules: {
                cerType: [{
                    required: true, message: '请选择', trigger: 'change'
                }],
                authPasswordRepeat: [
                    { validator: validatePass2, trigger: 'blur' }
                ],
                privPasswordRepeat: [
                    { validator: validatePass3, trigger: 'blur' }
                ],
                name: [{
                    required: true, message: '请输入', trigger: 'blur'
                }]
            },
            activeNames: ['1']
        };
    },
    methods: {
        // 打开弹框
        async openDrawer(params) {
            // console.log('openDrawer', params);
            this.loading = false;
            this.dialogVisible = true;
            this.title = params.title;
            this.type = params.type;
            this.editId = params.id;
            if (params.type === 'edit') {
                let {data: resData} = await this.$api.cloudWatch.voucherDetail({id: params.id});
                // console.log('resData', resData);
                if (resData.code === '200' && resData.message === '操作成功') {
                    this.form = Object.assign({}, resData.data);
                } else {
                    this.$message.error(resData.message);
                }
            }
        },
        // 关闭弹框
        closeDrawer() {
            this.$refs.ruleFormRef.resetFields();
            Object.keys(this.form).forEach(key=>{this.form[key] = '';});
            this.dialogVisible = false;
            this.form.cerType = 'SNMPV1/V2';
            this.editId = '';
        },
        // 提交
        submitForm() {
            this.$refs.ruleFormRef.validate(async valid=>{
                if (valid) {
                }
            });
        }
    }
};

</script>
<style  lang="scss" scoped>
.add-voucher {

	::v-deep .el-drawer__header {
		padding-bottom: 15px;
		border-bottom: 1px solid #eee;
		font-size: 16px;
		font-weight: 600;
		color: #333333;
		margin-bottom: 8px;
	}

	.demo-drawer__footer {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		height: 64px;
		line-height: 64px;
		border-top: 1px solid #eee;
		text-align: end;
		padding-right: 24px;
		background-color: #fff;
	}

	.drawer-wrap {
		padding: 16px 26px 16px 16px;
		overflow-y: auto;
		height: calc(100% - 40px);

		::v-deep .el-input__inner {
			width: 400px;
		}

		::v-deep .el-input--small {
			width: 400px;
		}

		.tip {
			margin-bottom: 20px;
			color: #2469F1;
			font-size: 14px;
			font-family: PingFangSC-Semibold, PingFang SC;
		}

		.form-tip {
			color: #999;
			font-size: 14px;
			font-family: PingFangSC-Semibold, PingFang SC;
		}

		.advanced-set {
			display: flex;
			justify-content: end;
			margin-right: 30px;
			margin-bottom: 14px;
			color: #2469F1;
			font-size: 14px;
			font-family: PingFangSC-Semibold, PingFang SC;
			cursor: pointer;
		}

		// ::v-deep .el-collapse-item__header {
		// 	border-bottom: 1px solid transparent;
		// }

		.authentication-wrap {

			.authentication-title {
				display: flex;
				justify-content: center;
				align-items: center;
				font-weight: bold;
				color: #2469F1;

				.line {
					margin-left: 5px;
					width: calc(100% - 100px);
					border-top: 1px solid #2469F1;
				}
			}
		}

		.collapse-title {
			display: flex;
			justify-content: end;
			width: 100%;
			height: 40px;
		}
	}

	::v-deep {

		.el-input--small,
		.el-radio__label,
		.el-checkbox__label {
			font-size: 12px;
			font-weight: 400;
		}

		.el-form-item__label {
			font-size: 12px;
			padding: 0 16px 0 0;
			color: #333333;
		}
	}
}
</style>
  • 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
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253

使用组件

            <AddVoucher
                ref="AddVoucherRef"
                @renewTable="getDataPage"
            />

        addClick() {
            const params = {
                type: 'add',
                title: '添加凭证'
            };
            this.$refs.AddVoucherRef.openDrawer(params);
        },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/43228?site
推荐阅读
相关标签
  

闽ICP备14008679号