根据后端返回下拉请求地址,前端动态请求拿到下拉数据渲染

后端接口数据:

[
    {
        "id": 1,
        "name": "Default",
        "sort": 0,
        "fold": false,
        "deletable": false,
        "uniqueId": "cloud_esc",
        "infoList": [
            {
                "id": 7,
                "name": "cloud_name",
                "humpName": "cloudName",
                "label": "云平台",
                "dateType": 1,
                "typeValue": "input",
                "dateTypeValue": null,
                "dateTypeName": "短字符",
                "sort": 1,
                "min": "",
                "max": "",
                "regex": null,
                "required": false,
                "edit": true,
                "primaryKey": false,
                "hide": false,
                "hint": "",
                "uniquely": null,
                "deletable": true,
                "groupId": 1,
                "query": true,
                "queryOrder": 1,
                "show": true,
                "showDefault": false,
                "showOrder": 1,
                "uniqueId": "cloud_esc",
                "orderQuery": false,
                "value": null,
                "valueAttribute": null
            },
            {
                "id": 4,
                "name": "dev_id",
                "humpName": "devId",
                "label": "归属物理设备ID",
                "dateType": 1,
                "typeValue": "input",
                "dateTypeValue": null,
                "dateTypeName": "短字符",
                "sort": 1,
                "min": "",
                "max": "",
                "regex": null,
                "required": false,
                "edit": true,
                "primaryKey": false,
                "hide": false,
                "hint": "",
                "uniquely": null,
                "deletable": true,
                "groupId": 1,
                "query": true,
                "queryOrder": 1,
                "show": true,
                "showDefault": false,
                "showOrder": 1,
                "uniqueId": "cloud_esc",
                "orderQuery": false,
                "value": null,
                "valueAttribute": null
            },
            {
                "id": 2,
                "name": "example",
                "humpName": "example",
                "label": "实例名",
                "dateType": 1,
                "typeValue": "input",
                "dateTypeValue": null,
                "dateTypeName": "短字符",
                "sort": 1,
                "min": null,
                "max": null,
                "regex": null,
                "required": false,
                "edit": false,
                "primaryKey": false,
                "hide": false,
                "hint": null,
                "uniquely": false,
                "deletable": false,
                "groupId": 1,
                "query": true,
                "queryOrder": 0,
                "show": true,
                "showDefault": false,
                "showOrder": 0,
                "uniqueId": "cloud_esc",
                "orderQuery": false,
                "value": null,
                "valueAttribute": null
            },
            {
                "id": 3,
                "name": "example_department",
                "humpName": "exampleDepartment",
                "label": "所属科室",
                "dateType": 12,
                "typeValue": "isCascade",
                "dateTypeValue": "/sso-management/department/getDepById?",
                "dateTypeName": "组织",
                "sort": 1,
                "min": null,
                "max": null,
                "regex": null,
                "required": true,
                "edit": false,
                "primaryKey": false,
                "hide": false,
                "hint": null,
                "uniquely": false,
                "deletable": false,
                "groupId": 1,
                "query": true,
                "queryOrder": 1,
                "show": true,
                "showDefault": false,
                "showOrder": 1,
                "uniqueId": "cloud_esc",
                "orderQuery": false,
                "value": null,
                "valueAttribute": [
                    {
                        "child": [
                            {
                                "child": null,
                                "key": 100000023,
                                "key2": null,
                                "name": "测试部门",
                                "parent": null,
                                "pid": 100000022,
                                "value": "测试部门"
                            }
                        ],
                        "key": 100000022,
                        "key2": null,
                        "name": "测试公司",
                        "parent": null,
                        "pid": 0,
                        "value": "测试公司"
                    },
                    {
                        "child": [
                            {
                                "child": [
                                    {
                                        "child": [
                                            {
                                                "child": null,
                                                "key": 100000101,
                                                "key2": null,
                                                "name": "四级部门-1",
                                                "parent": null,
                                                "pid": 100000081,
                                                "value": "四级部门-1"
                                            }
                                        ],
                                        "key": 100000081,
                                        "key2": null,
                                        "name": "三级部门",
                                        "parent": null,
                                        "pid": 100000080,
                                        "value": "三级部门"
                                    },
                                    {
                                        "child": null,
                                        "key": 100000102,
                                        "key2": null,
                                        "name": "三-2级部门",
                                        "parent": null,
                                        "pid": 100000080,
                                        "value": "三-2级部门"
                                    }
                                ],
                                "key": 100000080,
                                "key2": null,
                                "name": "二级部门",
                                "parent": null,
                                "pid": 100000079,
                                "value": "二级部门"
                            }
                        ],
                        "key": 100000079,
                        "key2": null,
                        "name": "一级部门",
                        "parent": null,
                        "pid": 0,
                        "value": "一级部门"
                    },
                    {
                        "child": [
                            {
                                "child": null,
                                "key": 100000083,
                                "key2": null,
                                "name": "a科室",
                                "parent": null,
                                "pid": 100000082,
                                "value": "a科室"
                            },
                            {
                                "child": null,
                                "key": 100000085,
                                "key2": null,
                                "name": "b科室",
                                "parent": null,
                                "pid": 100000082,
                                "value": "b科室"
                            }
                        ],
                        "key": 100000082,
                        "key2": null,
                        "name": "科技科",
                        "parent": null,
                        "pid": 0,
                        "value": "科技科"
                    },
                    {
                        "child": [
                            {
                                "child": null,
                                "key": 100000092,
                                "key2": null,
                                "name": "测试2",
                                "parent": null,
                                "pid": 100000091,
                                "value": "测试2"
                            },
                            {
                                "child": null,
                                "key": 100000093,
                                "key2": null,
                                "name": "测试3",
                                "parent": null,
                                "pid": 100000091,
                                "value": "测试3"
                            }
                        ],
                        "key": 100000091,
                        "key2": null,
                        "name": "测试1",
                        "parent": null,
                        "pid": 0,
                        "value": "测试1"
                    }
                ]
            },
            {
                "id": 5,
                "name": "InstanceId",
                "humpName": "InstanceId",
                "label": "实例ID",
                "dateType": 1,
                "typeValue": "input",
                "dateTypeValue": null,
                "dateTypeName": "短字符",
                "sort": 1,
                "min": "",
                "max": "",
                "regex": null,
                "required": false,
                "edit": true,
                "primaryKey": false,
                "hide": false,
                "hint": "",
                "uniquely": null,
                "deletable": true,
                "groupId": 1,
                "query": true,
                "queryOrder": 1,
                "show": true,
                "showDefault": false,
                "showOrder": 1,
                "uniqueId": "cloud_esc",
                "orderQuery": false,
                "value": null,
                "valueAttribute": null
            },
            {
                "id": 6,
                "name": "OSNameEn",
                "humpName": "OSNameEn",
                "label": "操作系统",
                "dateType": 1,
                "typeValue": "input",
                "dateTypeValue": null,
                "dateTypeName": "短字符",
                "sort": 1,
                "min": "",
                "max": "",
                "regex": null,
                "required": false,
                "edit": true,
                "primaryKey": false,
                "hide": false,
                "hint": "",
                "uniquely": null,
                "deletable": true,
                "groupId": 1,
                "query": true,
                "queryOrder": 1,
                "show": true,
                "showDefault": false,
                "showOrder": 1,
                "uniqueId": "cloud_esc",
                "orderQuery": false,
                "value": null,
                "valueAttribute": null
            }
        ]
    }
]

完整代码如下:

<template>

  <!-- 资源列表页 -->

  <div>

    <div>

      <i

        @click="$router.go(-1)"

        style="

          color: #409eff;

          cursor: pointer;

          margin-right: 5px;

          font-size: 18px;

        "

        class="el-icon-back"

      ></i

      >{{ getCurrentPageTitle }}

    </div>

    <br />

    <el-row class="contentTop">

      <el-col :span="12">

        <el-button type="primary" size="mini" @click="doAdd">新建</el-button>

        <el-button

          size="mini"

          @click="

            drawerImportant = true;

            active = 0;

            currentFile = null;

          "

          >导入</el-button

        >

        <!-- <el-button size="mini">批量更新</el-button>

        <el-button size="mini">删除</el-button> -->

        <el-button size="mini" @click="doExport">导出</el-button>

        <el-button size="mini" @click="doExportTemplate">导出模板</el-button>

      </el-col>

      <el-col :span="10">

        <el-input

          placeholder="请输入内容"

          v-model="inputValue"

          class="input-with-select"

          size="mini"

          clearable

        >

          <el-select

            v-model="selectValue"

            slot="prepend"

            style="width: 120px"

            placeholder="请选择"

            clearable

            @change="changeSelect"

          >

            <el-option

              :label="item.label"

              :value="item.value"

              v-for="item in searchList"

              :key="item.value"

            ></el-option>

          </el-select>

          <el-button

            slot="append"

            icon="el-icon-search"

            @click="doSearch"

          ></el-button>

        </el-input>

      </el-col>

      <el-col :span="0.5">

        <el-button

          icon="el-icon-setting"

          size="mini"

          @click="doSetting"

        ></el-button>

      </el-col>

    </el-row>

    <br />

    <el-row>

      <!-- @cell-click="doClickCell" -->

      <el-table

        :data="tableInfo.list"

        size="mini"

        @selection-change="handleSelectionChange"

        fit

        :stripe="true"

        :row-key="rowKey"

        ref="multipleTable"

        max-height="500"

        border

        id="tableId"

        @sort-change="sortChange"

      >

        <!-- <el-table-column

          type="selection"

          :reserve-selection="true"

          width="55"

        ></el-table-column> -->

        <el-table-column

          v-for="(item, index) in tableInfo.columns"

          v-if="!item.hide"

          :prop="item.name"

          :label="item.label"

          :key="index"

          :show-overflow-tooltip="true"

          sortable="custom"

        >

          <!-- <template slot-scope="scope">

            <el-button

              v-if="item.name == 'example'"

              type="text"

              @click="doClickCell(scope.row)"

              >{{ scope.row[item.name] }}</el-button

            >

            <span v-else>{{ scope.row[item.name] }}</span>

          </template> -->

        </el-table-column>

        <el-table-column fixed="right" label="操作" width="180">

          <template slot-scope="scope">

            <el-button @click="doClickCell(scope.row)" type="text" size="small"

              >详情</el-button

            >

            <el-button

              @click.stop="deleteRow(scope.row.id)"

              type="text"

              size="small"

              >删除</el-button

            >

          </template>

        </el-table-column>

      </el-table>

      <div style="text-align: center">

        <el-pagination

          @size-change="handleSizeChange"

          @current-change="handleCurrentChange"

          :current-page="paramsPage.pageNum"

          :page-sizes="[10, 20, 30, 50, 100]"

          :page-size="paramsPage.pageSize"

          layout="total, sizes, prev, pager, next, jumper"

          :total="tableInfo.total"

        ></el-pagination>

      </div>

    </el-row>

    <el-drawer

      title="列表显示属性配置"

      :visible.sync="drawer"

      direction="rtl"

      size="45%"

    >

      <el-transfer

        style="text-align: left; display: inline-block"

        v-model="transferValue"

        filterable

        :left-default-checked="[]"

        :right-default-checked="[]"

        :render-content="renderFunc"

        :titles="['未选属性', '已选属性']"

        :format="{

          noChecked: '${total}',

          hasChecked: '${checked}/${total}',

        }"

        :props="{

          key: 'name',

          label: 'label',

        }"

        @change="handleChange"

        :data="dataList"

      >

      </el-transfer>

      <br />

      <br />

      <div style="padding: 0 20px">

        <el-button type="primary" size="small" @click="doSettingConfirm"

          >应用</el-button

        >

        <el-button size="small" @click="drawer = false">取消</el-button>

        <el-button style="float: right" size="small" @click="doRest"

          >还原默认</el-button

        >

      </div>

    </el-drawer>

    <el-drawer

      title="创建"

      :visible.sync="drawerAdd"

      direction="rtl"

      size="30%"

    >

      <div style="padding-left: 20px">

        <el-form

          label-position="top"

          label-width="80px"

          :model="formLabelAlign"

        >

          <el-collapse

            v-model="activeNames"

            v-for="(item, index) in modelList"

            :key="index"

          >

            <el-collapse-item :title="item.name" :name="index">

              <el-row :gutter="40" v-for="(v, i) in item.infoList" :key="i">

                <el-col :span="20">

                  <el-form-item :label="v.label">

                    <el-input

                      v-if="v.typeValue == 'input'"

                      v-model="formLabelAlign[v.name]"

                      placeholder="请输入"

                      style="width: 570px"

                    ></el-input>

                    <el-input

                      v-else-if="v.typeValue == 'number'"

                      type="number"

                      v-model="formLabelAlign[v.name]"

                      placeholder="请输入"

                      style="width: 570px"

                    ></el-input>

                    <el-date-picker

                      v-else-if="v.typeValue == 'date'"

                      value-format="yyyy-MM-dd"

                      type="date"

                      v-model="formLabelAlign[v.name]"

                      placeholder="请输入"

                      style="width: 570px"

                    ></el-date-picker>

                    <el-date-picker

                      v-else-if="v.typeValue == 'time'"

                      value-format="yyyy-MM-dd HH:mm:ss"

                      type="datetime"

                      v-model="formLabelAlign[v.name]"

                      placeholder="请输入"

                      style="width: 570px"

                    ></el-date-picker>

                    <el-select

                      v-else-if="

                        v.typeValue == 'select' &&

                        v[`valueAttribute${i}`] &&

                        v[`valueAttribute${i}`].length > 0

                      "

                      v-model="formLabelAlign[v.name]"

                      clearable

                      style="width: 570px"

                    >

                      <el-option

                        v-for="w in v[`valueAttribute${i}`]"

                        :key="w.key"

                        :label="w.value"

                        :value="w.key"

                      >

                      </el-option>

                    </el-select>

                    <el-cascader

                      v-else-if="

                        v.typeValue == 'isCascade' &&

                        v[`valueAttribute${i}`] &&

                        v[`valueAttribute${i}`].length > 0

                      "

                      v-model="formLabelAlign[v.name]"

                      :options="v[`valueAttribute${i}`]"

                      :props="propsCascader"

                      @change="handleChangeCas"

                    ></el-cascader>

                  </el-form-item>

                </el-col>

              </el-row>

            </el-collapse-item>

          </el-collapse>

          <div class="bottomButton">

            <el-button type="primary" @click="doConfirm">提交</el-button>

            <el-button @click="drawerAdd = false">取消</el-button>

          </div>

        </el-form>

      </div>

    </el-drawer>

    <el-drawer

      title="批量导入"

      :visible.sync="drawerImportant"

      direction="rtl"

      size="45%"

    >

      <div style="padding-left: 20px">

        <el-steps :active="active" finish-status="success" align-center>

          <el-step title="上传文件"></el-step>

          <el-step title="选择关联模型"></el-step>

        </el-steps>

        <div style="padding-left: 20px">

          <div v-if="active == 0">

            <div

              style="

                margin: 20px 0;

                background: rgb(255, 244, 226);

                border: 1px solid rgb(255, 223, 172);

              "

            >

              <i style="color: rgb(255, 156, 1)" class="el-icon-info"></i>

              说明:导入编辑需要先导出需要修改的实例,并完成编辑修改后才能进行导入编辑操作

            </div>

            <el-upload

              class="upload-demo"

              drag

              action

              multiple

              :http-request="uploadFiles"

            >

              <i class="el-icon-upload"></i>

              <div class="el-upload__text">

                将文件拖到此处,或<em>点击上传</em>

              </div>

              <div class="el-upload__tip" slot="tip">

                只能上传jpg/png文件,且不超过500kb

                <el-button

                  type="primary"

                  icon="el-icon-download"

                  size="mini"

                  @click="downloadTemplate"

                  >下载模板</el-button

                >

              </div>

            </el-upload>

          </div>

          <div style="margin: 20px 0" v-if="active == 1">

            <el-checkbox v-model="checked">是否导入关联的模型实例</el-checkbox>

          </div>

          <div style="margin-top: 20px">

            <el-button

              v-if="active == 0"

              type="primary"

              :disabled="!currentFile"

              @click="active = 1"

              >下一步</el-button

            >

            <el-button v-if="active == 1" @click="active = 0">上一步</el-button>

            <el-button v-if="active == 1" type="primary" @click="doImportant"

              >开始导入</el-button

            >

            <el-button @click="drawerImportant = false">取消</el-button>

          </div>

        </div>

      </div>

    </el-drawer>

  </div>

</template>

<script>

import { mapGetters, mapMutations } from "vuex";

import tableCell from "./tableCell";

import { unique } from "@/utils/index";

import {

  resourceList,

  deleteResource,

  queryResource,

  findAllModel,

  getAddress,

  exportTemplate,

  uploadResource,

  exportResource,

  exportResourceTemplate,

  addResource,

  batchUpdateField,

  findAll,

  querySelect,

} from "@/api/cmdb/model";

export default {

  data() {

    return {

      inputValue: "",

      select: "",

      valueCade: [],

      selectValue: "",

      drawer: false,

      drawerAdd: false,

      drawerImportant: false,

      checked: false,

      active: 0,

      activeNames: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],

      multipleSelection: [],

      searchList: [],

      modelList: [],

      currentArgs: [],

      formInline: {},

      formLabelAlign: {},

      currentFile: null,

      tableInfo: {

        columns: [],

        list: [],

        total: 0,

      },

      paramsPage: {

        pageNum: 1,

        pageSize: 10,

      },

      dataList: [], // 所有字段数据

      selectFieldList: [],

      transferValue: [], // 右侧数据

      renderFunc(h, option) {

        return (

          <span>

            {/* {option.key} - {option.label} */}

            {option.label}

          </span>

        );

      },

      propsCascader: {

        value: "key",

        label: "value",

        children: "child",

      },

    };

  },

  computed: {

    ...mapGetters(["getCurrentPageTitle", "getActiveModel"]),

  },

  // watch: {

  //   $route: {

  //     handler(to, from) {

  //       this.$set(this.tableInfo, "columns", tableCell[to.params.id]);

  //       this.paramsPage.pageSize = 10;

  //       this.paramsPage.pageNum = 1; //重置页面

  //     },

  //     immediate: true,

  //   },

  // },

  mounted() {

    this.getList();

    this.getSearchList();

    this.getFields();

  },

  methods: {

    ...mapMutations(["setDetailTitle", "setResourceId"]),

    // 当前模型详情查询(新建字段)

    getFields() {

      let params = {

        args: this.getActiveModel.uniqueId,

      };

      findAllModel(params)

        .then((res) => {

          if (res.code == 0) {

            this.modelList = res.data; // 当前模型下包含的分组

            this.modelList.forEach(v1 => {

              v1.infoList.forEach((v2,i2)=> {

                if(v2.typeValue == 'isCascade' || v2.typeValue == 'select') {

                  getAddress(v2.dateTypeValue,{}).then(res2 => {

                   //  v2[`valueAttribute${i2}`] = res2

                        this.$set(v2,`valueAttribute${i2}`,res2 ) // 双向绑定,回显问题

                  })

                }

              })

            })

            // 列表字段显示隐藏

            let arr = [];

            res.data.forEach((v) => {

              arr.push(v.infoList);

            });

            this.dataList = arr.flat(); // 二维数组转一维

            // 右侧数据

            this.transferValue = this.dataList.map((v) => {

              if (v.show) {

                return v.name;

              }

            });

          } else {

            res.desc && this.$message.error(res.desc);

          }

        })

        .catch((err) => {

          err.desc && this.$message.error(err.desc);

        });

    },

    getList(id = "id", order = "", args) {

      let params = {

        currPage: this.paramsPage.pageNum,

        pageSize: this.paramsPage.pageSize,

        uniqueId: this.getActiveModel.uniqueId,

        args: args || [],

        sortName: id,

        sortValue: order == "descending" ? false : true, // true = ASC,false = DESC

      };

      resourceList(params)

        .then((res) => {

          if (res.code == 0) {

            this.tableInfo.columns = res.data.headers;

            this.tableInfo.list = res.data.bodyData.list;

            this.tableInfo.total = res.data.bodyData.total;

          } else {

            res.desc && this.$message.error(res.desc);

          }

        })

        .catch((err) => {

          err.desc && this.$message.error(err.desc);

        });

    },

    // 排序

    sortChange({ column, prop, order }) {

      // console.log(column, prop, order );

      this.getList(prop, order, []);

    },

    changeSelect(key) {

      this.currentKey = key;

    },

    // 按条件搜索

    doSearch() {

      // if (!this.currentKey) {

      //   return this.$message.warning("请选择需要查询的字段名称");

      // }

      let args = [

        {

          key: this.currentKey,

          value: this.inputValue,

          select: false, // true为下拉搜索,一般默认都是输入框

        },

      ];

      this.currentArgs = args;

      this.getList("id", "", this.inputValue ? args : []);

    },

    // 查询下拉

    getSearchList() {

      let params = {

        args: this.getActiveModel.uniqueId,

      };

      queryResource(params).then((res) => {

        if (res.code == 0) {

          this.searchList = res.data;

        }

      });

    },

    rowKey(row) {

      return row.id;

    },

    handleSizeChange(val) {

      this.paramsPage.pageSize = val;

      this.getList();

    },

    handleCurrentChange(val) {

      this.paramsPage.pageNum = val;

      this.getList();

    },

    //多选

    handleSelectionChange(val) {

      // console.log(val);

      this.multipleSelection = val;

    },

    doSetting() {

      this.drawer = true;

    },

    // 还原默认

    doRest() {

      this.dataList.forEach((v) => {

        v.createTime && delete v.createTime;

        v.updateTime && delete v.updateTime;

        // 第一次保存的设置true,其他都隐藏false

        if (v.showDefault) {

          v.show = true;

        } else {

          v.show = false;

        }

      });

      batchUpdateField(this.dataList)

        .then((res) => {

          if (res.code == 0) {

            this.drawer = false;

            this.getList();

            this.getFields();

            this.$message.success(res.desc);

          } else {

            this.drawer = false;

            res.desc && this.$message.error(res.desc);

          }

        })

        .catch((err) => {

          this.drawer = false;

          err.desc && this.$message.error(err.desc);

        });

    },

    // 字段显示配置--应用

    doSettingConfirm() {

      let arr = [];

      arr = this.selectFieldList.map((v) => {

        return v.showDefault;

      });

      // 如果包含true,说明保存过一次,如果不包含true,说明第一次保存,为还原默认设置数据

      if (arr.includes(true)) {

        // console.log('保存过一次');

      } else {

        // console.log('第一次保存');

        // 第一次保存-应用,右侧showDefault设为true

        this.selectFieldList.forEach((v1) => {

          this.transferValue.forEach((v2) => {

            if (v2 == v1.name) {

              v1.showDefault = true;

            }

          });

        });

      }

      batchUpdateField(this.selectFieldList)

        .then((res) => {

          if (res.code == 0) {

            this.drawer = false;

            this.getList();

            this.getFields();

            this.$message.success(res.desc);

          } else {

            this.drawer = false;

            res.desc && this.$message.error(res.desc);

          }

        })

        .catch((err) => {

          this.drawer = false;

          err.desc && this.$message.error(err.desc);

        });

    },

    handleChangeCas(val) {},

    handleChange(value, direction, movedKeys) {

      // console.log(value, direction, movedKeys);

      let arr = [];

      // value为右侧数据;左侧dataList为所有数据

      // 默认全部show设为false,右侧是选中的需要show设为true,否则就为false

      this.dataList.forEach((v1) => {

        v1.show = false;

        v1.createTime && delete v1.createTime;

        v1.updateTime && delete v1.updateTime;

      });

      this.dataList.forEach((v1) => {

        value.forEach((v2) => {

          if (v2 == v1.name) {

            v1.show = true;

            arr.push(v1);

          } else {

            arr.push(v1);

          }

        });

      });

      this.selectFieldList = unique(arr, "id"); // 根据id去重

    },

    doClickCell(row) {

      this.setDetailTitle(row.example);

      this.setResourceId(row.id);

      this.$router.push({ path: `/resource/detail` });

    },

    next() {

      this.active = 2;

    },

    deleteRow(id) {

      let that = this;

      let params = {

        uniqueId: this.getActiveModel.uniqueId,

        id: id,

      };

      that

        .$confirm("确认要删除这条数据?", "提示", {

          confirmButtonText: "确定",

          cancelButtonText: "取消",

          type: "warning",

        })

        .then(() => {

          deleteResource(params)

            .then((res) => {

              if (res.code == 0) {

                that.$message.success(res.desc);

                that.getList();

              } else {

                if (res.desc) {

                  that.$message.error(res.desc);

                }

              }

            })

            .catch((err) => {

              err.desc && that.$message.error(err.desc);

            });

        })

        .catch(() => {

          that.$message({

            type: "info",

            message: "已取消删除",

          });

        });

    },

    doAdd() {

      this.drawerAdd = true;

      this.formLabelAlign = {};

    },

    // 新建--提交

    doConfirm() {

      if (

        this.formLabelAlign.example_department &&

        this.formLabelAlign.example_department.length > 0

      ) {

        this.formLabelAlign.example_department =

          this.formLabelAlign.example_department.join();

      }

      let params = {

        uniqueId: this.getActiveModel.uniqueId,

        args: this.formLabelAlign,

      };

      addResource(params)

        .then((res) => {

          if (res.code == 0) {

            this.getList();

            this.drawerAdd = false;

            this.$message.success(res.desc);

          } else {

            res.desc && this.$message.error(res.desc);

          }

        })

        .catch((err) => {

          err.desc && this.$message.error(err.desc);

        });

    },

    getDownload(res) {

      const blob = new Blob([res]);

      // const fileName = res.headers["content-disposition"].split("=")[1];

      const fileName = this.getActiveModel.uniqueId;

      const elink = document.createElement("a");

      elink.download = window.decodeURIComponent(fileName);

      elink.style.display = "none";

      elink.href = URL.createObjectURL(blob);

      elink.setAttribute("download", `${fileName}.xlsx`); // 下载文件的名称及文件类型后缀

      document.body.appendChild(elink);

      elink.click();

      URL.revokeObjectURL(elink.href); // 释放URL 对象

      document.body.removeChild(elink);

    },

    // 下载模板

    downloadTemplate() {

      let params = {

        uniqueId: this.getActiveModel.uniqueId,

      };

      exportTemplate(params).then((res) => {

        this.getDownload(res);

      });

    },

    // 导出

    doExport() {

      let params = {

        uniqueId: this.getActiveModel.uniqueId,

        currPage: this.paramsPage.pageNum,

        pageSize: this.paramsPage.pageSize,

        args: this.currentArgs,

        titleList: this.multipleSelection.map((v) => v.id),

      };

      exportResource(params).then((res) => {

        this.getDownload(res);

      });

    },

    // 导出模板

    doExportTemplate() {

      let params = {

        uniqueId: this.getActiveModel.uniqueId,

      };

      exportResourceTemplate(params).then((res) => {

        this.getDownload(res);

      });

    },

    // 导入--上传

    uploadFiles(files) {

      const _file = files.file;

      this.currentFile = _file;

      // var formData = new FormData();

      // formData.append("file", _file);

      // formData.append("uniqueId", this.getActiveModel.uniqueId);

      // uploadResource(formData)

      //   .then((res) => {

      //     if (res.code == 0) {

      //       this.getList();

      //       this.drawerImportant = false;

      //       this.$message.success(res.desc);

      //     } else {

      //       res.desc && this.$message.error(res.desc);

      //     }

      //   })

      //   .catch((err) => {

      //     err.desc && this.$message.error(err.desc);

      //   });

    },

    // 开始导入

    doImportant() {

      var formData = new FormData();

      formData.append("file", this.currentFile);

      formData.append("uniqueId", this.getActiveModel.uniqueId);

      uploadResource(formData)

        .then((res) => {

          if (res.type == "application/json") {

            this.$message.success("导入成功");

            this.drawerImportant = false;

            this.getList();

          } else {

            this.drawerImportant = false;

            this.$message.error("导入失败");

          }

        })

        .catch((err) => {

          this.drawerImportant = false;

          this.$message.error("导入失败");

        });

    },

  },

};

</script>

<style scoped lang="scss">

.contentTop {

  display: flex;

  justify-content: space-between;

  align-items: center;

}

::v-deep .el-drawer__open .el-drawer.rtl {

  -webkit-animation: rtl-drawer-in 0.3s 1ms;

  animation: rtl-drawer-in 0.3s 1ms;

  width: 38% !important;

}

::v-deep .el-transfer-panel {

  height: 660px !important;

}

::v-deep .el-transfer-panel__list.is-filterable {

  height: 660px !important;

}

::v-deep .el-upload-dragger {

  width: 530px !important;

}

.bottomButton {

  position: sticky;

  bottom: 0;

  left: 0;

  margin-top: 10px;

}

</style>

  • 11
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值