123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
- <div class="form global-form">
- <el-form class="form-list" :model="formData" :rules="rules" ref="ruleForm">
- <el-form-item
- v-for="item in formConfig"
- :prop="item.prop"
- :key="item.label"
- >
- <!-- 输入框 -->
- <el-input
- v-if="item.type === 'input'"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- :style="{ width: item.width }"
- @change="item.change && item.change(formData[item.prop])"
- :placeholder="item.placeholder"
- clearable
- ></el-input>
- <!-- 密码框 -->
- <el-input
- v-if="item.type === 'password'"
- :type="flag ? 'text' : 'password'"
- v-model="formData[item.prop]"
- autocomplete="off"
- :style="{ width: item.width }"
- @change="item.change && item.change(formData[item.prop])"
- :placeholder="item.placeholder"
- clearable
- >
- <i
- v-if="!flag"
- slot="suffix"
- class="el-input__icon iconfont"
- style="font-size: 22px;"
- @click="showPassword"
- ></i
- >
- <i
- v-else
- slot="suffix"
- class="el-input__icon iconfont"
- style="font-size: 22px"
- @click="showPassword"
- ></i
- >
- </el-input>
- <!-- 文本域 -->
- <el-input
- v-if="item.type === 'textarea'"
- type="textarea"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- :style="{ width: item.width }"
- :maxlength="item.maxlength"
- :rows="item.rows"
- :show-word-limit="item.showWordLimit"
- @change="item.change && item.change(formData[item.prop])"
- ></el-input>
- <!-- 下拉框 -->
- <el-select
- v-if="item.type === 'select'"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- :style="{ width: item.width }"
- @change="item.change && item.change(formData[item.prop])"
- clearable
- :multiple="multiple"
- :placeholder="item.placeholder">
- <el-option
- v-for="option in item.selectList"
- :label="option.name"
- :value="option.id"
- :key="option.id"
- ></el-option>
- </el-select>
- <!-- 下拉框: selectList为obj类型-->
- <el-select
- v-if="item.type === 'selectObj'"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- :style="{ width: item.width }"
- @change="item.change && item.change(formData[item.prop])"
- filterable
- clearable
- :placeholder="item.placeholder"
- >
- <el-option
- v-for="(item, key) in item.selectList"
- :key="parseInt(key)"
- :label="item"
- :value="parseInt(key)"
- ></el-option>
- </el-select>
- <!-- 单选框 -->
- <el-radio-group
- v-if="item.type === 'radio'"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- @change="item.change && item.change(formData[item.prop])"
- >
- <el-radio
- v-for="radio in item.radios"
- :label="radio.label"
- :key="radio.label"
- ></el-radio>
- </el-radio-group>
- <!-- 复选框 -->
- <el-checkbox-group
- v-if="item.type === 'checkbox'"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- @change="item.change && item.change(formData[item.prop])"
- >
- <el-checkbox
- v-for="item in item.checkboxs"
- :label="item.label"
- :key="item.label"
- >{{ item.label }}</el-checkbox
- >
- </el-checkbox-group>
- <!-- 开关 -->
- <el-switch
- v-if="item.type === 'switch'"
- v-model="formData[item.prop]"
- :disabled="item.disabled"
- @change="item.change && item.change(formData[item.prop])"
- ></el-switch>
- <!-- 插槽 -->
- <template v-if="item.type === 'slot'">
- <slot :name="item.slotName"></slot>
- </template>
- </el-form-item>
- </el-form>
- <div class="submit-btn">
- <el-button
- @click.native="submit"
- :loading="submitLoading"
- v-if="showLoginBtn"
- >
- LOGIN
- </el-button>
- <el-button
- @click.native="submit"
- :loading="submitLoading"
- v-if="showRegisterBtn"
- >
- REGISTER
- </el-button>
- <el-button @click.native="close" v-if="showDeleteBtn">取 消</el-button>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "GlobalForm",
- props: {
- showDeleteBtn: {
- type: Boolean,
- default: true,
- },
- showLoginBtn: {
- type: Boolean,
- default: true,
- },
- showRegisterBtn: {
- type: Boolean,
- default: true,
- },
- // 表单配置
- formConfig: {
- type: Array,
- required: true,
- },
- // 表单数据
- formData: {
- type: Object,
- required: true,
- },
- // 表单规则
- rules: {
- type: Object,
- },
- submitLoading: {
- type: Boolean,
- },
- },
- data() {
- return {
- flag: false,
- };
- },
- methods: {
- submit() {
- this.$refs.ruleForm.validate((valid) => {
- if (valid) {
- this.$emit("handleSubmit");
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- close() {
- this.$emit("handleClose");
- },
- showPassword() {
- this.flag = !this.flag;
- },
- },
- };
- </script>
- <style lang="scss" scope>
- .global-form {
- padding: 0 30px;
- margin-top: 20px;
- .el-input__inner {
- height: 50px;
- line-height: 50px;
- }
- .el-input__suffix .el-input__suffix-inner{
- margin-top: 5px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .submit-btn {
- display: flex;
- justify-content: center;
- .el-button {
- background-color: #e90000;
- width: 156px;
- height: 50px;
- color: #fff;
- border-radius: 6px;
- font-weight: 600;
- }
- }
- }
- </style>
|