123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <template>
- <div class="form-box">
- <div class="inner-box">
- <el-form
- :model="formData"
- :ref="form.formName"
- class="demo-dynamic"
- :label-width="form.labelWidth"
- :style="form.formStyle"
- >
- <el-form-item
- v-for="(item, index) in form.body"
- :label="item.label"
- :key="index"
- :rules="item.rules"
- :prop="item.value"
- >
- <el-input
- style="display: inline-block"
- v-if="item.el == 'input'"
- v-model="formData[item.value]"
- :placeholder="item.placeholder"
- :disabled="item.disabled"
- :clearable="item.clearable"
- ></el-input>
- <el-checkbox-group
- v-else-if="item.el == 'checkbox'"
- :placeholder="item.placeholder"
- v-model="formData[item.value]"
- :disabled="item.disabled"
- :clearable="item.clearable"
- >
- <el-checkbox
- v-for="items in item.options"
- :label="items.label"
- :key="items.value"
- >{{ items.label }}</el-checkbox
- >
- </el-checkbox-group>
- <el-select
- v-else-if="item.el == 'select'"
- v-model="formData[item.value]"
- :placeholder="item.placeholder"
- :multiple="item.multiple || false"
- filterable
- style="width: 100%"
- :clearable="item.clearable"
- >
- <el-option
- v-for="items in item.options"
- :key="items.value"
- :label="items.label"
- :value="items.value"
- :disabled="items.disabled"
- >
- </el-option>
- </el-select>
- <el-switch
- v-else-if="item.el == 'switch'"
- v-model="formData[item.value]"
- ></el-switch>
- <el-radio-group
- v-else-if="item.el == 'radio'"
- v-model="formData[item.value]"
- :clearable="item.clearable"
- >
- <el-radio
- v-for="items in item.options"
- :key="items.value"
- :label="items.value"
- :disabled="items.disabled"
- >{{ items.label }}</el-radio
- >
- </el-radio-group>
- <el-date-picker
- v-else-if="item.el == 'datetime'"
- style="width:100% !important"
- v-model="formData[item.value]"
- :placeholder="item.placeholder"
- value-format="YYYY-MM-DD"
- type="datetime"
- ></el-date-picker>
- <el-input
- v-else-if="item.el == 'password'"
- v-model="formData[item.value]"
- :placeholder="item.placeholder"
- :disabled="item.disabled"
- :clearable="item.clearable"
- :type="inputType"
- >
- <template slot="suffix">
- <el-tooltip
- class="item"
- effect="dark"
- content="点击查看密码"
- placement="top-start"
- >
- <i
- @click="changeView"
- :class="
- inputType == 'text'
- ? 'el-input__icon el-icon-success'
- : 'el-input__icon el-icon-view'
- "
- ></i>
- </el-tooltip>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item v-if="form.action" style="text-align: right;">
- <el-button type="primary" @click="submitForm(form.formName)"
- >{{form.subBtn}}</el-button
- >
- <el-button @click="resetForm(form.formName)">{{form.restBtn}}</el-button>
- </el-form-item>
- </el-form>
- </div>
- </div>
- </template>
- <script>
- // form: {
- // initUrl: "/sysmgr/sys/login/addInit", // 初始化接口
- // url: "/market/cfgDataDict/queryList", // 提交接口
- // id: "", // 编辑时用的id 由初始化时获取
- // type: "post", // 请求方式
- // params: "", // get请求桉树
- // events: function () {
- // // 回调方法
- // $vm.$router.push("/leader");
- // },
- // data: {
- // // post请求参数
- // groupId: "",
- // groupName: "",
- // loginNameStr: "",
- // loginNoStr: "",
- // loginPasswd: "",
- // tenantId: null,
- // },
- // body: [
- // // 渲染表单
- // {
- // el: "input", // dom类型
- // placeholder: "请输入", // 提示语
- // label: "输入框", // 表单title
- // value: "loginNoStr", // 表单model绑定的值
- // rules: [
- // // 校验
- // { required: true, message: "请输入工号", trigger: "blur" },
- // ],
- // },
- // {
- // el: "checkbox", // input radio checkbox select datePicker timePicker switch
- // placeholder: "请输入",
- // label: "复选框",
- // value: "checkbox",
- // rules: [
- // { required: true, message: "请输入邮箱地址", trigger: "blur" },
- // ],
- // options: [
- // {
- // label: "选项1",
- // value: "1",
- // disabled: false,
- // },
- // {
- // label: "选项2",
- // value: "2",
- // disabled: false,
- // },
- // ],
- // },
- // {
- // el: "select", // input radio checkbox select datePicker timePicker switch
- // placeholder: "请输入",
- // value: "select",
- // label: "下拉框",
- // rules: [
- // { required: true, message: "请输入邮箱地址", trigger: "blur" },
- // ],
- // options: [
- // {
- // label: "选项1",
- // value: "1",
- // disabled: false,
- // },
- // {
- // label: "选项2",
- // value: "2",
- // disabled: false,
- // },
- // ],
- // },
- // {
- // el: "switch", // input radio checkbox select datePicker timePicker switch
- // placeholder: "请输入",
- // value: "switch",
- // label: "switch",
- // rules: [
- // { required: true, message: "请输入邮箱地址", trigger: "blur" },
- // ],
- // },
- // {
- // el: "radio", // input radio checkbox select datePicker timePicker switch
- // placeholder: "请输入",
- // label: "单选框",
- // value: "radio",
- // rules: [
- // { required: true, message: "请输入邮箱地址", trigger: "blur" },
- // ],
- // options: [
- // {
- // label: "选项1",
- // value: "1",
- // disabled: false,
- // },
- // {
- // label: "选项2",
- // value: "2",
- // disabled: false,
- // },
- // ],
- // },
- // ],
- // },
- export default {
- props: {
- formData: {
- required: true,
- type: Object,
- },
- form: {
- required: true,
- type: Object,
- },
- },
- data() {
- return {
- inputType: "password",
- };
- },
- methods: {
- changeView() {
- if (this.inputType == "password") {
- this.inputType = "text";
- } else {
- this.inputType = "password";
- }
- },
- submitForm(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- let config = {
- url: this.form.url,
- method: this.form.type,
- };
- if (this.form.type == "post") {
- config.headers = {
- "Content-Type": "application/json",
- };
- config.data = this.formData;
- } else {
- config = {
- url: this.form.url,
- method: this.form.type,
- params: this.form.params,
- };
- }
- this.$http(config).then((res) => {
- if (res.data.result == 0) {
- this.$notify({
- title: "成功",
- message: res.data.desc,
- type: "success",
- });
- this.form.events();
- this.$emit("closeDialog");
- }
- });
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- resetForm(formName) {
- this.form.body.map((item) => {
- item.disabled = false;
- });
- this.$refs[formName].resetFields();
- this.$emit("closeDialog");
- },
- initData() {
- this.$http({
- url: this.form.initUrl,
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- data: this.form.data,
- }).then((res) => {
- console.log(res);
- });
- },
- },
- mounted() {
- // this.initData();
- },
- };
- </script>
|