zhangzengfei
2023-06-30 db5872786c1e1697a59af41386136ee002bb68ad
src/views/personalCenter/components/SubAccount.vue
@@ -1,14 +1,14 @@
<template>
  <div class="sub-account" v-if="!isShowAdd && !isShowRelate">
    <div class="head-name">子账户管理</div>
    <div class="head-name" v-show="showHeadName">子账号管理</div>
    <div class="search">
      <div class="left">
        <div class="id">
          姓名/手机号
          <el-input v-model="inputText" placeholder="请输入"></el-input>
          用户名/姓名/手机号
          <el-input v-model="inputText" placeholder="请输入" clearable></el-input>
        </div>
        <div class="cluster">
        <div class="cluster" v-show="false">
          授权时长
          <el-select @change="findUserList" v-model="timeLength" placeholder="请选择">
            <el-option v-for="item in durationArr" :key="item.value" :label="item.label" :value="item.value">
@@ -41,6 +41,7 @@
        :data="dataList"
        :fit="true"
        :default-sort="{ prop: 'createTime', order: 'descending' }"
        v-loading="tbLoading"
      >
        <el-table-column label="序号" width="55" class-name="index">
          <template slot-scope="scope">{{ scope.$index + 1 + (page - 1) * size }}</template>
@@ -63,7 +64,7 @@
        <!-- <el-table-column prop="authDuration" label="授权时长">
        </el-table-column> -->
        <!-- <el-table-column prop="dataNames" label="公司"> </el-table-column> -->
        <el-table-column prop="companyName" label="部门" show-overflow-tooltip></el-table-column>
        <el-table-column prop="companyName" label="部门" show-overflow-tooltip min-width="200px"></el-table-column>
        <!-- <el-table-column label="状态">
          <template slot-scope="scope">
@@ -72,9 +73,10 @@
          </template>
        </el-table-column> -->
        <el-table-column label="操作">
        <el-table-column label="操作" align="center" width="100px">
          <template slot-scope="scope">
            <span class="iconfont option" @click="editUser(scope.row)">编辑</span>
            <span class="iconfont option" style="color:red" @click="delUser(scope.row)">删除</span>
          </template>
        </el-table-column>
      </el-table>
@@ -93,10 +95,11 @@
    </div>
  </div>
  <div class="sub-account" v-else-if="isShowAdd">
    <div class="add-title" @click="isShowAdd = false">
    <!-- <div class="add-title" @click="isShowAdd = false">
      <span class="iconfont">&#xe614;</span>
      <span>添加子账户</span>
    </div>
      <span>子账户管理</span>
    </div> -->
    <div class="head-name" style="margin-bottom:20px">子账户编辑</div>
    <el-form
      :model="ruleForm"
      :rules="rules"
@@ -193,9 +196,32 @@
          />
        </div>
      </el-form-item>
      <el-form-item label="短信推送" v-show="isEditing">
        <el-select v-model="smsSceneConfig" multiple collapse-tags style="width: 250px" placeholder="请选择">
          <el-option
            v-for="item in taskOptions"
            style="font-size: 12px"
            :key="item.value"
            :value="item.value"
            :label="item.value"
            :title="item.value"
          ></el-option>
        </el-select>
        <el-select
          v-model="smsLevelConfig"
          multiple
          collapse-tags
          style="margin-left:10px;width: 150px"
          placeholder="请选择"
        >
          <el-option v-for="item in levelOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <el-checkbox v-model="smsEnable" style="margin-left:20px">启用</el-checkbox>
      </el-form-item>
    </el-form>
    <div class="right">
      <div class="button searchBtn" @click="saveSubUser">保存</div>
      <div class="button searchBtn" @click="saveUser">保存</div>
      <div class="button resetBtn" @click="resetUser">重置</div>
      <div class="button resetBtn" style="margin-left:20px" @click="goback">返回</div>
    </div>
@@ -211,7 +237,8 @@
</template>
<script>
import { findUserList, saveSubUser, getMenu, getDataTree } from "@/api/user"
import { findUserList, saveSubUser, getMenu, getDataTree, deleteUser } from "@/api/user"
import { findTaskById, updateTask } from "@/api/report"
import { getAreas, getDic } from "@/api/login"
import Steps from "./Steps"
@@ -223,6 +250,11 @@
    Steps,
    StepsCard,
    TreeMenu
  },
  computed: {
    showHeadName() {
      return this.$route.path === "/personalCenter"
    }
  },
  data() {
    const validateTree = (rule, value, callback) => {
@@ -238,14 +270,15 @@
      }
    }
    return {
      tbLoading: false,
      searchTime: [this.$moment().format("YYYY-MM-DD 00:00:00"), this.$moment().format("YYYY-MM-DD HH:mm:ss")], //搜索时间
      page: 1,
      size: 10, //分页相关
      total: 0, //总数,
      inputText: "", //输入框内容
      activeStep: 0,
      activeIndex: 0,
      industrys: [],
      total: 0, //总数,
      treeHeight: 750,
      treeData: [],
      treeSettings: {
@@ -253,6 +286,7 @@
          enable: true
        }
      },
      taskOptions: [],
      options: {
        lazy: true,
        lazyLoad(node, resolve) {
@@ -323,17 +357,27 @@
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        // password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        userType: [{ required: true, message: "请选择用户类型", trigger: "blur" }],
        trueName: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        menuIds: [{ validator: validateTree, trigger: "blur" }]
        trueName: [{ required: true, message: "请输入姓名", trigger: "blur" }]
        // menuIds: [{ validator: validateTree, trigger: "blur" }]
      },
      sysMenus: [],
      DataTree: [],
      smsSceneConfig: [],
      smsLevelConfig: [],
      smsEnable: false,
      userInfo: {},
      curEditId: "",
      defaultProp: {
        children: "children",
        label: "name"
      }
      },
      levelOptions: [
        { value: "一级", label: "一级" },
        { value: "二级", label: "二级" },
        { value: "三级", label: "三级" },
        { value: "四级", label: "四级" },
        { value: "五级", label: "五级" }
      ]
    }
  },
  created() {
@@ -344,8 +388,10 @@
    this.fetchDataTree()
  },
  mounted() {
    this.taskOptions = this.Constants.sceneNameOptions
    this.TreeDataPool.reset()
    this.TreeDataPool.multiple = true
    this.VideoPhotoData.queryTaskList()
  },
  methods: {
    fetchDataTree() {
@@ -386,7 +432,7 @@
      this.ruleForm.companyName = row.companyName
      this.ruleForm.phoneNum = row.phoneNum
      this.ruleForm.email = row.email
      this.ruleForm.isChangePwd = row.isChangePwd
      this.ruleForm.isChangePwd = false
      this.ruleForm.industryId = row.industryId
      this.ruleForm.areaId = row.areaId
      this.ruleForm.address = [row.provinceId, row.areaId]
@@ -395,11 +441,27 @@
      this.checkedMenu = row.menuIds
      this.checkedData = row.dataIds
      this.smsSceneConfig = []
      this.smsLevelConfig = []
      this.smsEnable = false
      findTaskById({ id: row.id }).then((rsp) => {
        if (rsp && rsp.success && rsp.data != "") {
          if (rsp.data.taskName != "") {
            this.smsSceneConfig = rsp.data.taskName.split(",")
          }
          if (rsp.data.level != "") {
            this.smsLevelConfig = rsp.data.level.split(",")
          }
          this.smsEnable = rsp.data.enable
        }
      })
      // 查询当前用户权限下所有可管理的摄像机
      if (row.dataIds) {
        sessionStorage.setItem("clusterId", row.dataIds[0])
        await this.TreeDataPool.fetchTreeData()
      }
      // 用email字段暂时代替摄像机集合字段
      let checkedCameras = row.email
@@ -413,6 +475,23 @@
        let cameraIds = checkedCameras.split(",")
        this.$refs.ztreeMenus.updateNodes(cameraIds)
      }
    },
    delUser(row) {
      this.$confirm("确认要删除该用户吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        let rsp = await deleteUser({ id: row.id })
        if (rsp && rsp.success) {
          this.$message({
            type: "success",
            message: "删除成功!"
          })
        }
        this.findUserList()
      })
    },
    resetUser() {
      this.ruleForm = {
@@ -431,6 +510,9 @@
        provinceId: "",
        authDuration: 1
      }
      this.smsSceneConfig = []
      this.smsLevelConfig = []
      this.smsEnable = false
      this.$nextTick(() => {
        this.$refs.treeMenus.setCheckedKeys([])
        this.$refs.treeData.setCheckedKeys([])
@@ -444,7 +526,7 @@
        console.log("查询行业列表失败!")
      }
    },
    saveSubUser() {
    saveUser() {
      let _this = this
      this.ruleForm.menuIds = this.$refs.treeMenus.getCheckedKeys()
      this.ruleForm.dataIds = this.$refs.treeData.getCheckedKeys()
@@ -477,6 +559,7 @@
          // 编辑不提交密码
          if (this.isEditing) {
            delete json.password
            json.isChangePwd = false
          }
          if (typeof json.areaId === "string") {
@@ -491,16 +574,34 @@
          saveSubUser(json)
            .then((res) => {
              if (res.success) {
                this.$notify.success(res.data)
                this.isShowAdd = false
                this.isEditing = false
                this.findUserList()
                // 保存消息推送
                if (_this.isEditing) {
                  let smsTaskInfo = {
                    id: _this.ruleForm.id,
                    taskName: _this.smsSceneConfig.join(","),
                    level: _this.smsLevelConfig.join(","),
                    cameras: json.email,
                    person: json.trueName,
                    tel: json.phoneNum,
                    enable: _this.smsEnable,
                    IsDel: "0"
                  }
                  updateTask(smsTaskInfo).then((rsp) => {
                    // console.log(rsp)
                  })
                }
                _this.$notify.success(res.data)
                _this.isShowAdd = false
                _this.isEditing = false
                _this.findUserList()
              } else {
                this.$notify.error(res.msg)
                _this.$notify.error(res.msg)
              }
            })
            .catch((err) => {
              this.$notify.error(err.data.msg)
              _this.$notify.error(err.data.msg)
            })
        } else {
          return false
@@ -508,6 +609,11 @@
      })
    },
    findUserList() {
      this.tbLoading = true
      if (this.inputText.length) {
        this.inputText = this.inputText.trim()
      }
      findUserList({
        inputText: this.inputText,
        page: this.page,
@@ -521,9 +627,12 @@
          } else {
            this.$notify.error("加载子账户列表失败")
          }
          this.tbLoading = false
        })
        .catch((e) => {
          this.$notify.error(e.msg)
          this.tbLoading = false
        })
    },
    goback() {
@@ -539,34 +648,7 @@
      this.inputText = ""
      this.timeLength = null
    },
    // 跳到设备详情
    checkDetail(row) {
      this.$router.push({
        path: "/equipmentDetail",
        query: {
          id: row.devId,
          ip: row.devIp,
          port: row.serverPort,
          ndid: row.id
        }
      })
    },
    // 跳到算法详情
    algorithmDetail(row) {
      this.$router.push({
        path: "/algorithmDetail",
        query: {
          id: row.devId,
          ip: row.devIp,
          port: row.serverPort
        }
      })
    },
    // 查询列表
    save() {},
    //分页功能
    handleSizeChange(size) {
      this.size = size
@@ -578,53 +660,14 @@
      this.findUserList()
    },
    //解绑按钮
    Untying(row) {
      console.log(row)
      this.unbindId = row.id
      this.isShowUnbind = true
    },
    //获得默认时间
    getDateInit() {
      // 要求 默认一个月
      const end = new Date()
      const start = new Date()
      const nowDate = new Date()
      nowDate.setHours(0)
      nowDate.setMinutes(0)
      nowDate.setSeconds(0)
      nowDate.setMilliseconds(0)
      start.setTime(nowDate.getTime() - 3600 * 1000 * 24 * 30)
      end.setTime(nowDate.getTime() + 3600 * 1000 * 24 - 1)
      return [this.$moment(start).format("YYYY-MM-DD HH:mm:ss"), this.$moment(end).format("YYYY-MM-DD HH:mm:ss")]
    },
    // 关闭解绑弹窗
    closeUnbindBox() {
      this.isShowUnbind = false
    },
    //解绑成功回调
    reflash() {
      this.isShowUnbind = false
    },
    clearSearch() {
      this.searchTime = this.getDateInit()
      this.inputText = ""
    },
    //退出集群
    quitCluster(equipment) {
      this.activeEquipment = equipment
      this.showQuit = true
    },
    //加入集群
    joinCluster(equipment) {
      this.activeEquipment = equipment
      this.showJoin = true
    // 生成uuid
    getUuid() {
      let originStr = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      let originChar = "0123456789abcdef"
      let len = originChar.length
      return originStr.replace(/x/g, function(match) {
        return originChar.charAt(Math.floor(Math.random() * len))
      })
    }
  }
}
@@ -690,9 +733,10 @@
    }
  }
  .searchBtn {
    width: 60px;
    height: 32px;
    line-height: 32px;
    width: 50px;
    height: 25px;
    line-height: 25px;
    font-size: 14px;
    text-align: center;
    color: #fff;
    background: #0065ff;
@@ -702,9 +746,10 @@
    display: flex;
  }
  .resetBtn {
    width: 60px;
    height: 32px;
    line-height: 32px;
    width: 50px;
    height: 25px;
    line-height: 25px;
    font-size: 14px;
    text-align: center;
    color: #0065ff;
    box-sizing: border-box;
@@ -913,6 +958,12 @@
      }
    }
  }
  .el-select ::v-deep {
    .el-select__tags-text {
      color: #3d3d3d;
    }
  }
}
</style>