shuishen
2024-01-29 2cec09706b01d65def3f945bdcde13e620a71c2e
src/views/system/tenant.vue
@@ -1,106 +1,63 @@
<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
        <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" :page.sync="page"
            :permission="permissionList" :before-open="beforeOpen" @row-del="rowDel" @row-update="rowUpdate"
            @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="permission.tenant_delete"
                   plain
                <el-button type="danger" size="small" icon="el-icon-delete" v-if="permission.tenant_delete" plain
                   @click="handleDelete">删 除
        </el-button>
        <el-tooltip class="item" effect="dark" content="给租户配置账号额度、过期时间等授权信息" placement="top">
          <el-button size="small"
                     plain
                     v-if="userInfo.role_name.includes('administrator')"
                     icon="el-icon-setting"
                    <el-button size="small" plain v-if="userInfo.role_name.includes('administrator')" icon="el-icon-setting"
                     @click="handleSetting">授权配置
          </el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="给租户配置独立数据源以实现数据库隔离" placement="top">
          <el-button size="small"
                     plain
                     v-if="userInfo.role_name.includes('administrator')"
                     icon="el-icon-coin"
                    <el-button size="small" plain v-if="userInfo.role_name.includes('administrator')" icon="el-icon-coin"
                     @click="handleDatasource">数据源配置
          </el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="将菜单产品包与租户配置绑定" placement="top">
          <el-button size="small"
                     plain
                     v-if="userInfo.role_name.includes('administrator')"
                     icon="el-icon-notebook-1"
                     @click="handlePackage">产品包配置
                    <el-button size="small" plain v-if="userInfo.role_name.includes('administrator')"
                        icon="el-icon-notebook-1" @click="handlePackage">产品包配置
          </el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="将自定义的菜单集合定制为租户绑定的菜单产品包" placement="top">
          <el-button size="small"
                     plain
                     v-if="userInfo.role_name.includes('administrator')"
                     icon="el-icon-notebook-2"
                     @click="handlePackageSetting">产品包管理
                    <el-button size="small" plain v-if="userInfo.role_name.includes('administrator')"
                        icon="el-icon-notebook-2" @click="handlePackageSetting">产品包管理
          </el-button>
        </el-tooltip>
      </template>
      <template slot-scope="{row}"
                slot="accountNumber">
            <template slot-scope="{row}" slot="accountNumber">
        <el-tag>{{ row.accountNumber > 0 ? row.accountNumber : '不限制' }}</el-tag>
      </template>
      <template slot-scope="{row}"
                slot="expireTime">
            <template slot-scope="{row}" slot="expireTime">
        <el-tag>{{ row.expireTime ? row.expireTime : '不限制' }}</el-tag>
      </template>
    </avue-crud>
    <el-dialog title="租户授权配置"
               append-to-body
               :visible.sync="box"
               width="450px">
        <el-dialog title="租户授权配置" append-to-body :visible.sync="box" width="450px">
      <avue-form :option="settingOption" v-model="settingForm" @submit="handleSubmit"/>
    </el-dialog>
    <el-dialog title="租户数据源配置"
               append-to-body
               :visible.sync="datasourceBox"
               width="450px">
        <el-dialog title="租户数据源配置" append-to-body :visible.sync="datasourceBox" width="450px">
      <avue-form :option="datasourceOption" v-model="datasourceForm" @submit="handleDatasourceSubmit"/>
    </el-dialog>
    <el-dialog title="租户产品包配置"
               append-to-body
               :visible.sync="packageBox"
               width="450px">
        <el-dialog title="租户产品包配置" append-to-body :visible.sync="packageBox" width="450px">
      <avue-form ref="formPackage" :option="packageOption" v-model="packageForm" @submit="handlePackageSubmit"/>
    </el-dialog>
    <el-dialog title="租户产品包管理"
               append-to-body
               :visible.sync="packageSettingBox"
               width="1000px">
        <el-dialog title="租户产品包管理" append-to-body :visible.sync="packageSettingBox" width="1000px">
      <tenant-package></tenant-package>
    </el-dialog>
  </basic-container>
</template>
<script>
import {getList, getDetail, remove, update, add, setting, datasource, packageInfo, packageSetting} from "@/api/system/tenant";
import {getDetail as packageDetail} from "@/api/system/tenantpackage";
import {mapGetters} from "vuex";
import {getMenuTree} from "@/api/system/menu";
import {validatenull} from "@/util/validate";
import { getList, getDetail, remove, update, add, setting, datasource, packageInfo, packageSetting } from "@/api/system/tenant"
import { getDetail as packageDetail } from "@/api/system/tenantpackage"
import { mapGetters } from "vuex"
import { getMenuTree } from "@/api/system/menu"
import { validatenull } from "@/util/validate"
export default {
  data() {
@@ -136,6 +93,7 @@
            prop: "tenantId",
            width: 100,
            search: true,
                        searchLabelWidth: 60,
            addDisplay: false,
            editDisplay: false,
            span: 24,
@@ -289,15 +247,15 @@
          },
        ]
      },
    };
        }
  },
  watch: {
    'packageForm.packageId'() {
      if (!validatenull(this.packageForm.packageId)) {
        packageDetail(this.packageForm.packageId).then(res => {
          this.packageForm.menuId = res.data.data.menuId;
          this.initData();
        });
                    this.packageForm.menuId = res.data.data.menuId
                    this.initData()
                })
      }
    }
  },
@@ -309,51 +267,51 @@
        viewBtn: this.vaildData(this.permission.tenant_view, false),
        delBtn: this.vaildData(this.permission.tenant_delete, false),
        editBtn: this.vaildData(this.permission.tenant_edit, false)
      };
            }
    },
    ids() {
      let ids = [];
            let ids = []
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
                ids.push(ele.id)
            })
            return ids.join(",")
    },
    tenantId() {
      return this.selectionList[0].tenantId;
            return this.selectionList[0].tenantId
    }
  },
  methods: {
    initData() {
      getMenuTree().then(res => {
        const column = this.findObject(this.packageOption.column, "menuId");
        column.dicData = res.data.data;
      });
                const column = this.findObject(this.packageOption.column, "menuId")
                column.dicData = res.data.data
            })
    },
    rowSave(row, done, loading) {
      add(row).then(() => {
        this.onLoad(this.page);
                this.onLoad(this.page)
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
                })
                done()
      }, error => {
        window.console.log(error);
        loading();
      });
                window.console.log(error)
                loading()
            })
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(() => {
        this.onLoad(this.page);
                this.onLoad(this.page)
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
                })
                done()
      }, error => {
        window.console.log(error);
        loading();
      });
                window.console.log(error)
                loading()
            })
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
@@ -362,52 +320,52 @@
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
                    return remove(row.id)
        })
        .then(() => {
          this.onLoad(this.page);
                    this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
                    })
                })
    },
    beforeOpen(done, type) {
      if (["view"].includes(type)) {
        getDetail(this.form.id).then(res => {
          const data = res.data.data;
                    const data = res.data.data
          if (!(data.accountNumber > 0)) {
            data.accountNumber = "不限制";
                        data.accountNumber = "不限制"
          }
          if (!data.expireTime) {
            data.expireTime = "不限制";
                        data.expireTime = "不限制"
          }
          this.form = data;
        });
                    this.form = data
                })
      }
      done();
            done()
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
            this.query = {}
            this.onLoad(this.page)
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
            this.query = params
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            done()
    },
    selectionChange(list) {
      this.selectionList = list;
            this.selectionList = list
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
            this.selectionList = []
            this.$refs.crud.toggleSelection()
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
                this.$message.warning("请选择至少一条数据")
                return
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
@@ -415,140 +373,139 @@
        type: "warning"
      })
        .then(() => {
          return remove(this.ids);
                    return remove(this.ids)
        })
        .then(() => {
          this.onLoad(this.page);
                    this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.$refs.crud.toggleSelection();
        });
                    })
                    this.$refs.crud.toggleSelection()
                })
    },
    handleSetting() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
                this.$message.warning("请选择至少一条数据")
                return
      }
      if (this.selectionList.length === 1) {
        getDetail(this.selectionList[0].id).then(res => {
          const data = res.data.data;
          this.settingForm.accountNumber = data.accountNumber;
          this.settingForm.expireTime = data.expireTime;
        });
                    const data = res.data.data
                    this.settingForm.accountNumber = data.accountNumber
                    this.settingForm.expireTime = data.expireTime
                })
      } else {
        this.settingForm.accountNumber = -1;
        this.settingForm.expireTime = '';
                this.settingForm.accountNumber = -1
                this.settingForm.expireTime = ''
      }
      this.box = true;
            this.box = true
    },
    handleDatasource() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
                this.$message.warning("请选择至少一条数据")
                return
      }
      if (this.selectionList.length !== 1) {
        this.$message.warning("只能选择一条数据");
        return;
                this.$message.warning("只能选择一条数据")
                return
      }
      getDetail(this.selectionList[0].id).then(res => {
        const data = res.data.data;
        this.datasourceForm.datasourceId = data.datasourceId;
      });
      this.datasourceBox = true;
                const data = res.data.data
                this.datasourceForm.datasourceId = data.datasourceId
            })
            this.datasourceBox = true
    },
    handlePackage() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
                this.$message.warning("请选择至少一条数据")
                return
      }
      if (this.selectionList.length !== 1) {
        this.$message.warning("只能选择一条数据");
        return;
                this.$message.warning("只能选择一条数据")
                return
      }
      if (this.selectionList.length === 1) {
        packageInfo(this.selectionList[0].id).then(res => {
          const data = res.data.data;
          this.packageForm.packageId = data.id;
          this.packageForm.menuId = data.menuId;
        });
                    const data = res.data.data
                    this.packageForm.packageId = data.id
                    this.packageForm.menuId = data.menuId
                })
      } else {
        this.packageForm.menuId = '';
                this.packageForm.menuId = ''
      }
      this.packageBox = true;
            this.packageBox = true
      //更新字典远程数据
      setTimeout(() => {
        const form = this.$refs.formPackage;
        form.updateDic('packageId');
      }, 10);
                const form = this.$refs.formPackage
                form.updateDic('packageId')
            }, 10)
    },
    handlePackageSetting() {
      this.packageSettingBox = true;
            this.packageSettingBox = true
    },
    handleSubmit(form, done, loading) {
      setting(this.ids, form).then(() => {
        this.onLoad(this.page);
                this.onLoad(this.page)
        this.$message({
          type: "success",
          message: "配置成功!"
        });
        done();
        this.box = false;
                })
                done()
                this.box = false
      }, error => {
        window.console.log(error);
        loading();
      });
                window.console.log(error)
                loading()
            })
    },
    handleDatasourceSubmit(form, done, loading) {
      datasource(this.tenantId, form.datasourceId).then(() => {
        this.$message({
          type: "success",
          message: "配置成功!"
        });
        done();
        this.datasourceBox = false;
                })
                done()
                this.datasourceBox = false
      }, error => {
        window.console.log(error);
        loading();
      });
                window.console.log(error)
                loading()
            })
    },
    handlePackageSubmit(form, done, loading) {
      packageSetting(this.tenantId, form.packageId).then(() => {
        this.onLoad(this.page);
                this.onLoad(this.page)
        this.$message({
          type: "success",
          message: "配置成功!"
        });
        done();
        this.packageBox = false;
                })
                done()
                this.packageBox = false
      }, error => {
        window.console.log(error);
        loading();
      });
                window.console.log(error)
                loading()
            })
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
            this.page.currentPage = currentPage
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
            this.page.pageSize = pageSize
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
            this.onLoad(this.page, this.query)
    },
    onLoad(page, params = {}) {
      this.loading = true;
            this.loading = true
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.loading = false
                this.selectionClear()
            })
    }
  }
};
}
</script>
<style>
</style>
<style></style>