zhangxiao
2024-08-13 e611f0e211e257776bd3402ea7a90bb1fa2afdc3
src/views/authority/users/index.vue
@@ -1,69 +1,69 @@
<template>
  <div class="container">
    <authheader :items="menuTips"></authheader>
    <a-card ref="account" class="general-card" :title="$t('menu.user.title')">
      <a-row>
        <a-col :flex="2"></a-col>
        <a-col :flex="1">
          <a-form :model="formModel">
            <a-form-item field="name">
              <a-input v-model="formModel.name" :style="{width:'320px'}" :placeholder="$t('请输入')" />
            </a-form-item>
          </a-form>
        </a-col>
        <a-divider style="height: 40px" direction="vertical" />
        <a-col :flex="'200px'" style="text-align: right">
          <a-button @click="reset" style="margin-right: 20px">
            <template #icon>
              <icon-refresh />
            </template>
            {{ $t("searchTable.form.reset") }}
          </a-button>
          <a-button type="primary" @click="search">
            <template #icon>
              <icon-search />
            </template>
            {{ $t("searchTable.form.search") }}
          </a-button>
        </a-col>
      </a-row>
      <a-divider style="margin-top: 0" />
      <a-row style="margin-bottom: 16px">
        <a-col :span="12">
          <a-space>
            <a-button type="primary" :align="'right'" @click="operation(0)">+ 新建账户</a-button>
          </a-space>
        </a-col>
        <a-col
          :span="12"
          style="display: flex; align-items: center; justify-content: end"
        >
          <a-tooltip :content="$t('searchTable.actions.refresh')">
            <div class="action-icon" @click="search"
    <a-card ref="account" class="general-card">
      <div class="table-page-search-wrapper">
        <div class="search-wrapper">
          <div>
            <a-input
              v-model="formModel.name"
              :style="{ width: '320px' }"
              :placeholder="$t('请输入')"
            />
          </div>
          <div>
            <a-button
              type="primary"
              @click="search"
              style="margin-right: 20px; margin-left: 10px"
            >
              <icon-refresh size="18"
              />
            </div>
          </a-tooltip>
          <a-dropdown @select="handleSelectDensity">
            <a-tooltip :content="$t('searchTable.actions.density')">
              <div class="action-icon">
                <icon-line-height size="18" />
              <template #icon>
                <icon-search />
              </template>
              {{ $t('searchTable.form.search') }}
            </a-button>
            <a-button @click="reset">
              <template #icon>
                <icon-refresh />
              </template>
              {{ $t('searchTable.form.reset') }}
            </a-button>
          </div>
        </div>
        <div class="search-wrapper">
          <div>
            <a-space>
              <a-button type="primary" :align="'right'" @click="operation(0)"
                >+ 新建账户</a-button
              >
            </a-space></div
          >
          <div class="wrapper-icon">
            <a-tooltip :content="$t('searchTable.actions.refresh')">
              <div class="action-icon" @click="search">
                <icon-refresh size="18" />
              </div>
            </a-tooltip>
            <template #content>
              <a-doption
                v-for="item in densityList"
                :key="item.value"
                :value="item.value"
                :class="{ active: item.value === size }"
              >
                <span>{{ item.name }}</span>
              </a-doption>
            </template>
          </a-dropdown>
        </a-col>
      </a-row>
            <a-dropdown @select="handleSelectDensity">
              <a-tooltip :content="$t('searchTable.actions.density')">
                <div class="action-icon">
                  <icon-line-height size="18" />
                </div>
              </a-tooltip>
              <template #content>
                <a-doption
                  v-for="item in densityList"
                  :key="item.value"
                  :value="item.value"
                  :class="{ active: item.value === size }"
                >
                  <span>{{ item.name }}</span>
                </a-doption>
              </template>
            </a-dropdown>
          </div>
        </div>
      </div>
      <a-table
        row-key="id"
        :loading="loading"
@@ -77,42 +77,80 @@
        <template #index="{ rowIndex }">
          {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
        </template>
        <template #dept="{ record }">{{ record.dept ? record.dept.deptName : "" }}</template>
        <template #status="{record}">
          <a-switch checked-value="0" unchecked-value="1" @change="statusChange(record.status,record)"
                    v-model="record.status" />
        <template #dept="{ record }">{{
          record.dept ? record.dept.deptName : ''
        }}</template>
        <template #status="{ record }">
          <a-switch
            checked-value="1"
            unchecked-value="0"
            @change="statusChange(record.status, record)"
            v-model="record.status"
          />
        </template>
        <template #operations="{ record }">
          <a-button type="outline" @click="operation(1,record)">重置密码</a-button>
          <a-button type="outline" @click="operation(2,record)">编辑</a-button>
          <a-popconfirm content="Are you sure you want to delete?" type="success" @ok="operation(3,record)">
            <a-button type="outline">删除</a-button>
          </a-popconfirm>
          <a-button type="outline" @click="operation(4,record)">权限配置</a-button>
          <a-button type="outline" @click="operation(5,record)">部门配置</a-button>
          <a-space>
            <a-button
              type="outline"
              status="success"
              @click="operation(1, record)"
              >重置密码</a-button
            >
            <a-button type="outline" @click="operation(2, record)"
              >编辑</a-button
            >
            <a-popconfirm
              content="Are you sure you want to delete?"
              type="success"
              @ok="operation(3, record)"
            >
              <a-button type="outline" status="danger">删除</a-button>
            </a-popconfirm>
            <a-button
              type="dashed"
              status="warning"
              @click="operation(4, record)"
              >权限配置</a-button
            >
            <a-button status="success" @click="operation(5, record)"
              >部门配置</a-button
            >
          </a-space>
        </template>
      </a-table>
    </a-card>
    <a-modal v-model:visible="visible" :title="save" @cancel="handleCancel(1)" @ok="editHandleOk">
    <a-modal
      v-model:visible="visible"
      :title="save"
      @cancel="handleCancel(1)"
      @ok="editHandleOk"
    >
      <a-form :model="editform">
        <a-form-item field="email" label="用户名">
          <a-input v-model="editform.email" />
        </a-form-item>
        <a-form-item field="name" label="昵称">
          <a-input v-model="editform.nickName" />
        </a-form-item>
        <a-form-item field="userName" label="用户名">
          <a-input v-model="editform.userName" />
        </a-form-item>
        <a-form-item field="phoneNumber" label="手机号">
          <a-input v-model="editform.phoneNumber" />
        </a-form-item>
        <a-form-item field="email" label="邮箱">
          <a-input v-model="editform.email" />
        </a-form-item>
      </a-form>
    </a-modal>
    <a-modal width="50%" v-model:visible="deptvisible" title="部门配置" @cancel="handleCancel(2)"
             @ok="editDeptHandleOk">
    <a-modal
      width="50%"
      v-model:visible="deptvisible"
      title="部门配置"
      @cancel="handleCancel(2)"
      @ok="editDeptHandleOk"
    >
      <div :style="{ display: 'flex' }">
        <a-card :style="{ width: '460px',height: '500px', 'overflow-y': 'auto' }" title="机构" hoverable>
        <a-card
          :style="{ 'width': '460px', 'height': '500px', 'overflow-y': 'auto' }"
          title="机构"
          hoverable
        >
          <a-tree
            class="tree-demo"
            v-model:checked-keys="checkedKeys"
@@ -122,19 +160,15 @@
            :show-line="showLine"
            @check="onCheck"
            :fieldNames="{
              key:'deptId',
              title:'deptName',
              children:'children',
              key: 'deptId',
              title: 'deptName',
              children: 'children',
            }"
            :check-strictly="checkStrictly"
          >
          </a-tree>
        </a-card>
        <a-card
          class="card-demo"
          title="用户所属机构"
          hoverable
        >
        <a-card class="card-demo" title="用户所属机构" hoverable>
          <a-space wrap>
            <a-tag
              v-for="(tag, index) of checkStrictly"
@@ -146,19 +180,26 @@
          </a-space>
        </a-card>
      </div>
    </a-modal>
    <a-modal width="30%" v-model:visible="resourcevisible" title="权限配置" @cancel="handleCancel(3)"
             @ok="editResourceHandleOk">
      <div :style="{ display:'flex', 'flex-direction':'column' }">
        <a-tabs :style="{ width: '100%',height: '500px', 'overflow-y': 'auto' }">
    <a-modal
      width="70%"
      v-model:visible="resourcevisible"
      v-if="resourcevisible"
      title="权限配置"
      @cancel="handleCancel(3)"
      @ok="editResourceHandleOk"
    >
      <div :style="{ 'display': 'flex', 'flex-direction': 'column' }">
        <a-tabs
          :style="{ 'width': '100%', 'height': '500px', 'overflow-y': 'auto' }"
        >
          <a-tab-pane key="1">
            <template #title>
              <icon-calendar />
              菜单
            </template>
            <a-tree
              class="tree-demo"
              class="tree-demo-box"
              v-model:checked-keys="checkedKeysMenu"
              v-model:expanded-keys="expandKdysMenu"
              :checkable="true"
@@ -166,13 +207,73 @@
              :show-line="showLineMenu"
              @check="onCheckMenu"
              :fieldNames="{
               key:'menuId',
              title:'menuName',
              children:'children',
            }"
                key: 'menuId',
                children: 'children',
              }"
              :check-strictly="checkStrictlyMenu"
            >
              <template #extra="nodeData">
                <div :class="{ 'custom-class': nodeData.menuType == 1 }">
                  <span>
                    {{ nodeData.menuName }}
                  </span>
                </div>
              </template>
              <!-- <template #extra="nodeData"> {{ nodeData.menuName }}) </template> -->
            </a-tree>
            <!-- <a-space class="space_select_all">
              <a-button type="primary">全选</a-button>
              <a-button>取消全选</a-button>
            </a-space>
            <div class="table_box" v-if="treeDataMenu[0].children">
              <div class="table_row1">
                <div
                  class="row1_list"
                  v-for="(item, index) in treeDataMenu[0].children"
                  :key="item.menuId"
                >
                  <div class="row1_clo">
                    <a-checkbox
                      :checked="item.menuId"
                      @change="onCheckChange(item, $event)"
                    >
                      {{ item.menuName }}
                    </a-checkbox>
                  </div>
                  <div v-if="item.children" class="row1_clo2">
                    <div
                      class="row2_clo2_1"
                      v-for="(item2, index2) in item.children"
                      :key="item2.menuId"
                    >
                      <div class="row1_clo2_1">
                        <a-checkbox
                          :checked="item2.menuId"
                          @change="onCheckChange(item2, $event)"
                        >
                          {{ item2.menuName }}
                        </a-checkbox>
                      </div>
                      <div v-if="item2.children" class="row1_clo2_2">
                        <div
                          v-for="(item3, index3) in item2.children"
                          :key="item3.menuId"
                        >
                          <a-checkbox
                            :checked="item3.menuId"
                            @change="onCheckChange(item3, $event)"
                          >
                            {{ item3.menuName }}</a-checkbox
                          >
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div> -->
          </a-tab-pane>
          <a-tab-pane key="2">
            <template #title>
@@ -180,14 +281,18 @@
              知识库
            </template>
            <a-space direction="vertical" size="large">
              <a-checkbox-group v-model="checkedKeysKnowledge" direction="vertical" @change="onCheckKnowledge">
              <a-checkbox-group
                v-model="checkedKeysKnowledge"
                direction="vertical"
                @change="onCheckKnowledge"
              >
                <a-checkbox
                  v-for="(knowledg, index) of knowledgeList"
                  :value="knowledg.knowledgeId"
                  :lable="knowledg.knowledgeName"
                  :value="knowledg.id"
                  :lable="knowledg.name"
                  @change="onCheckKnowledge"
                >
                  {{ knowledg.knowledgeName }}
                  {{ knowledg.name }}
                </a-checkbox>
              </a-checkbox-group>
            </a-space>
@@ -197,13 +302,32 @@
              <icon-user />
              智能体
            </template>
            Content of Tab Panel 3
            <a-checkbox-group
              v-model="checkedKeysDialog"
              direction="vertical"
              @change="onCheckDialog"
            >
              <a-checkbox
                v-for="(dialog, index) of DialogsList"
                :value="dialog.id"
                :lable="dialog.name"
                @change="onCheckDialog"
              >
                {{ dialog.name }}
              </a-checkbox>
            </a-checkbox-group>
          </a-tab-pane>
        </a-tabs>
        <a-card :style="{ width: '100%',height: '200px', 'overflow-y': 'auto', margin:'1px'}"
                class="card-demo"
                title="用户所有权限"
                hoverable
        <a-card
          :style="{
            'width': '100%',
            'height': '200px',
            'overflow-y': 'auto',
            'margin': '1px',
          }"
          class="card-demo"
          title="用户所有权限"
          hoverable
        >
          <a-space wrap>
            菜单功能:
@@ -226,403 +350,624 @@
              {{ tag.knowledgeName }}
            </a-tag>
          </a-space>
          <a-divider />
          <a-space wrap>
            智能体:
            <a-tag
              v-for="(tag, index) of checkStrictlyDialog"
              :key="tag.dialogId"
              @close="handleDialogRemove(tag)"
            >
              {{ tag.dialogName }}
            </a-tag>
          </a-space>
        </a-card>
      </div>
    </a-modal>
  </div>
</template>
<script lang="ts" setup>
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import useLoading from "@/hooks/loading";
import { Pagination } from "@/types/global";
import type { TableColumnData } from "@arco-design/web-vue/es/table/interface";
import {
  KnowledgeList,
  OrganizationList,
  ResourceList,
  User,
  UserAdd,
  UserChangePwd,
  UserDelete,
  UserEdit,
  UserList,
  Userstatus
} from "@/api/authority";
import { Modal } from "@arco-design/web-vue";
import Authheader from "@/views/authority/components/authheader.vue";
  import { computed, reactive, ref, h, onMounted } from 'vue';
  import { useI18n } from 'vue-i18n';
  import useLoading from '@/hooks/loading';
  import { Pagination } from '@/types/global';
  import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
  import {
    DialogList,
    KnowledgeList,
    OrganizationList,
    ResourceList,
    User,
    UserAdd,
    UserChangePwd,
    UserDelete,
    UserEdit,
    UserList,
    Userstatus,
  } from '@/api/authority';
  import { Modal } from '@arco-design/web-vue';
  import Authheader from '@/views/authority/components/authheader.vue';
  import { create } from 'lodash';
let treeData = ref([]);
let checkedKeys = ref([]);
let expandKdys = ref([]);
let checkStrictly = ref([]);
  let treeData = ref([]);
  let checkedKeys = ref([]);
  let expandKdys = ref([]);
  let checkStrictly = ref([]);
  let treeDataMenu = ref<any>([]);
  let checkedKeysMenu = ref([]);
  let expandKdysMenu = ref([]);
  let checkStrictlyMenu = ref([]);
let treeDataMenu = ref([]);
let checkedKeysMenu = ref([]);
let expandKdysMenu = ref([]);
let checkStrictlyMenu = ref([]);
  let checkedKeysKnowledge = ref([]);
  let checkStrictlyKnowledge = ref([]);
let checkedKeysKnowledge= ref([]);
let checkStrictlyKnowledge= ref([]);
  let checkedKeysDialog = ref([]);
  let checkStrictlyDialog = ref([]);
let knowledgeList = ref([]);
  let knowledgeList = ref([]);
  let DialogsList = ref([]);
let menuTips = ref(["权限管理", "账号"]);
type SizeProps = "mini" | "small" | "medium" | "large";
const account = ref(null);
const generateFormModel = () => {
  return {
    name: ""
  let menuTips = ref(['权限管理', '账号']);
  type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  const account = ref(null);
  const generateFormModel = () => {
    return {
      name: '',
    };
  };
};
let showLine = ref(true);
const { loading, setLoading } = useLoading(true);
const { t } = useI18n();
let save = ref("新增");
let renderData = ref<User[]>([]);
let formModel = ref(generateFormModel());
let editform = ref<User>({
  createTime: "",
  dept: undefined,
  email: "",
  nickName: "",
  phoneNumber: "",
  status: "",
  userId: "",
  userName: ""
});
let size = ref<SizeProps>("medium");
let visible = ref(false);
let deptvisible = ref(false);
let resourcevisible = ref(false);
let selectUser = ref({});
const onCheck = (newCheckedKeys, event) => {
  let o = { "deptId": event.node.deptId, "deptName": event.node.deptName };
  if (event.checked) {
    checkStrictly.value.push(o);
  } else {
    checkStrictly.value.forEach((val, idx, array) => {
      // val: 当前值
      if (val.deptId == event.node.deptId) {
        checkStrictly.value.splice(idx, 1);
        return true;
      }
    });
  }
};
const onCheckMenu = (newCheckedKeys, event) => {
  let o = { "menuId": event.node.menuId, "menuName": event.node.menuName };
  if (event.checked) {
    checkStrictlyMenu.value.push(o);
  } else {
    checkStrictlyMenu.value.forEach((val, idx, array) => {
      // val: 当前值
      if (val.menuId == event.node.menuId) {
        checkStrictlyMenu.value.splice(idx, 1);
        return true;
      }
    });
  }
};
const onCheckKnowledge = (newCheckedKeys, event) => {
  let o = { "knowledgeId": event.target.value, "knowledgeName": event.target.labels[0].innerText };
  if (event.target.checked) {
    checkStrictlyKnowledge.value.push(o);
  } else {
    checkStrictlyKnowledge.value.forEach((val, idx, array) => {
      // val: 当前值
      if (val.knowledgeId == event.target.value) {
        checkStrictlyKnowledge.value.splice(idx, 1);
        return true;
      }
    });
  }
};
const handleRemove = (key) => {
  checkStrictly.value = checkStrictly.value.filter((tag) => tag !== key);
};
const handleMenuRemove = (key) => {
  checkStrictlyMenu.value = checkStrictlyMenu.value.filter((tag) => tag !== key);
};
const handleKnowledgeRemove = (key) => {
  checkStrictlyKnowledge.value = checkStrictlyKnowledge.value.filter((tag) => tag !== key);
};
const basePagination: Pagination = {
  current: 1,
  pageSize: 20
};
const pagination = reactive({
  ...basePagination
});
const densityList = computed(() => [
  {
    name: t("searchTable.size.mini"),
    value: "mini"
  },
  {
    name: t("searchTable.size.small"),
    value: "small"
  },
  {
    name: t("searchTable.size.medium"),
    value: "medium"
  },
  {
    name: t("searchTable.size.large"),
    value: "large"
  }
]);
const columns = computed<TableColumnData[]>(() => [
  {
    title: t("序号"),
    dataIndex: "index",
    slotName: "index"
  },
  {
    title: t("用户名"),
    dataIndex: "userName"
  },
  {
    title: t("创建时间"),
    dataIndex: "createTime"
  },
  {
    title: t("所属部门"),
    dataIndex: "dept",
    slotName: "dept"
  },
  {
    title: t("状态"),
    dataIndex: "status",
    slotName: "status"
  },
  {
    title: t("searchTable.columns.operations"),
    dataIndex: "operations",
    slotName: "operations"
  }
]);
const statusChange = async (value, record) => {
  await Userstatus(record.userId, value).then((res) => {
  let showLine = ref(true);
  const { loading, setLoading } = useLoading(true);
  const { t } = useI18n();
  let save = ref('新增');
  let renderData = ref<User[]>([]);
  let formModel = ref(generateFormModel());
  let editform = ref<User>({
    createTime: '',
    dept: undefined,
    deptName: '',
    email: '',
    nickName: '',
    phoneNumber: '',
    status: '',
    userId: '',
    userName: '',
  });
};
const handleCancel = (type) => {
  if (type == 1) {
    visible.value = false;
  }
  if (type == 2) {
    deptvisible.value = false;
  }
  if (type == 2) {
    resourcevisible.value = false;
  }
  let size = ref<SizeProps>('medium');
  let visible = ref(false);
  let deptvisible = ref(false);
  let resourcevisible = ref(false);
  let selectUser = ref({});
  // const treeDataList = ref([]);
  const checked1 = ref(false);
};
  //表格复选框选择
  const onCheckChange = (checkedKeysValue: (string | number)[], e: any) => {
    console.log('onCheckChange', checkedKeysValue, e);
  };
const editDeptHandleOk = async () => {
  let depts: Array = [], user: User = { "userId": selectUser.value.userId };
  checkStrictly.value.forEach((val) => {
    depts.push(val.deptId);
  });
  user.dept = depts;
  await UserEdit(user).then((res) => {
    fetchData();
  });
};
  const onCheck = (newCheckedKeys, event) => {
    let o = { deptId: event.node.deptId, deptName: event.node.deptName };
    if (event.checked) {
      checkStrictly.value.push(o);
    } else {
      checkStrictly.value.forEach((val, idx, array) => {
        // val: 当前值
        if (val.deptId == event.node.deptId) {
          checkStrictly.value.splice(idx, 1);
          return true;
        }
      });
    }
  };
  const onCheckMenu = (newCheckedKeys, event) => {
    let o = { menuId: event.node.menuId, menuName: event.node.menuName };
    if (event.checked) {
      checkStrictlyMenu.value.push(o);
    } else {
      checkStrictlyMenu.value.forEach((val, idx, array) => {
        // val: 当前值
        if (val.menuId == event.node.menuId) {
          checkStrictlyMenu.value.splice(idx, 1);
          return true;
        }
      });
    }
  };
  const onCheckKnowledge = (newCheckedKeys, event) => {
    let o = {
      knowledgeId: event.target.value,
      knowledgeName: event.target.labels[0].innerText,
    };
    if (event.target.checked) {
      checkStrictlyKnowledge.value.push(o);
    } else {
      checkStrictlyKnowledge.value.forEach((val, idx, array) => {
        // val: 当前值
        if (val.knowledgeId == event.target.value) {
          checkStrictlyKnowledge.value.splice(idx, 1);
          return true;
        }
      });
    }
  };
const editResourceHandleOk = async () => {
  let resources: Array = [],Knowledges: Array = [], user: User = { "userId": selectUser.value.userId };
  checkStrictlyMenu.value.forEach((val) => {
    resources.push(val.menuId);
  });
  user.resources = resources;
  checkStrictlyKnowledge.value.forEach((val) => {
    Knowledges.push(val.knowledgeId);
  });
  user.knowledges = Knowledges;
  const onCheckDialog = (newCheckedKeys, event) => {
    let o = {
      dialogId: event.target.value,
      dialogName: event.target.labels[0].innerText,
    };
    if (event.target.checked) {
      checkStrictlyDialog.value.push(o);
    } else {
      checkStrictlyDialog.value.forEach((val, idx, array) => {
        // val: 当前值
        if (val.dialogId == event.target.value) {
          checkStrictlyDialog.value.splice(idx, 1);
          return true;
        }
      });
    }
  };
  await UserEdit(user).then((res) => {
    fetchData();
  });
};
  const handleRemove = (key) => {
    checkStrictly.value = checkStrictly.value.filter((tag) => tag !== key);
  };
  const handleMenuRemove = (key) => {
    checkStrictlyMenu.value = checkStrictlyMenu.value.filter(
      (tag) => tag !== key
    );
  };
  const handleKnowledgeRemove = (key) => {
    checkStrictlyKnowledge.value = checkStrictlyKnowledge.value.filter(
      (tag) => tag !== key
    );
  };
  const handleDialogRemove = (key) => {
    checkStrictlyDialog.value = checkStrictlyDialog.value.filter(
      (tag) => tag !== key
    );
  };
const editHandleOk = async () => {
  if (editform.value.userId.length > 0) {
    await UserEdit({
      ...editform.value
    } as unknown as User).then((res) => {
      fetchData();
    });
  } else {
    await UserAdd({
      ...editform.value
    } as unknown as User).then((res) => {
      fetchData();
    });
  }
};
const operation = async (t, record) => {
  if (t == 0) {
    save.value = "新增";
    visible.value = true;
    editform.value.userId = "";
    editform.value.userName = "";
    editform.value.nickName = "";
    editform.value.email = "";
    editform.value.phoneNumber = "";
  }
//重置密码
  if (t == 1) {
    await UserChangePwd(record.userId).then((res) => {
      if (res.code == 20000) {
        Modal.success({
          title: "重置密码",
          content: "该用户密码重置为000000"
        });
      } else {
        Modal.error({
          title: "重置密码",
          content: "该用户密码重置失败"
        });
      }
    });
  }
  //编辑
  if (t == 2) {
    visible.value = true;
    save.value = "编辑";
    editform.value.userId = record.userId;
    editform.value.userName = record.userName;
    editform.value.nickName = record.nickName;
    editform.value.email = record.email;
    editform.value.phoneNumber = record.phoneNumber;
  }
  //删除
  if (t == 3) {
    await UserDelete(record.userId).then((res) => {
      if (res.code == 20000) {
        fetchData();
      }
    });
  }
  //权限
  if (t == 4) {
    resourcevisible.value = true;
    checkedKeysMenu.value = [];
    expandKdysMenu.value = [];
    checkStrictlyMenu.value = [];
    checkStrictlyKnowledge.value=[];
    checkedKeysKnowledge.value=[];
    selectUser.value = record;
    record.resources.forEach((val) => {
      checkStrictlyMenu.value.push({ "menuId": val.menuId, "menuName": val.menuName });
      checkedKeysMenu.value.push(val.menuId);
      expandKdysMenu.value.push(val.menuId);
    });
    record.knowledges.forEach((val) => {
      checkStrictlyKnowledge.value.push({ "knowledgeId": val.knowledgeId, "knowledgeName": val.knowledgeName });
      checkedKeysKnowledge.value.push(val.knowledgeId);
    });
  }
  //机构
  if (t == 5) {
    deptvisible.value = true;
    checkedKeys.value = [];
    expandKdys.value = [];
    checkStrictly.value = [];
    selectUser.value = record;
    expandKdys.value.push("0");
    record.dept.forEach((val) => {
      checkStrictly.value.push({ "deptId": val.deptId, "deptName": val.deptName });
      checkedKeys.value.push(val.deptId);
      expandKdys.value.push(val.deptId);
    });
  }
};
const fetchData = async (
  params: Pagination = { current: 1, pageSize: 20 }
) => {
  setLoading(true);
  try {
    await UserList(params).then((res) => {
      renderData.value = res.rows;
      console.log(renderData);
      pagination.current = params.current;
      pagination.total = res.total;
    });
  } catch (err) {
    // you can report use errorHandler or other
  } finally {
    setLoading(false);
  }
};
const search = () => {
  fetchData({
  const basePagination: Pagination = {
    current: 1,
    pageSize: 15,
  };
  const pagination = reactive({
    ...basePagination,
    ...formModel.value
  } as unknown as Pagination);
};
const onPageChange = (current: number) => {
  fetchData({ ...basePagination, current });
};
const OrganizationData = async (key) => {
  await OrganizationList(key).then((res) => {
    treeData.value = [...res.rows];
  });
};
const MenuData = async (key) => {
  await ResourceList(key).then((res) => {
    treeDataMenu.value = [...res.rows];
  const densityList = computed(() => [
    {
      name: t('searchTable.size.mini'),
      value: 'mini',
    },
    {
      name: t('searchTable.size.small'),
      value: 'small',
    },
    {
      name: t('searchTable.size.medium'),
      value: 'medium',
    },
    {
      name: t('searchTable.size.large'),
      value: 'large',
    },
  ]);
  const columns = computed<TableColumnData[]>(() => [
    {
      title: t('序号'),
      dataIndex: 'index',
      slotName: 'index',
    },
    {
      title: t('用户名'),
      dataIndex: 'email',
    },
    {
      title: t('创建时间'),
      dataIndex: 'createTime',
    },
    {
      title: t('所属部门'),
      dataIndex: 'deptName',
      slotName: 'deptName',
    },
    {
      title: t('状态'),
      dataIndex: 'status',
      slotName: 'status',
    },
    {
      title: t('searchTable.columns.operations'),
      dataIndex: 'operations',
      slotName: 'operations',
    },
  ]);
  const statusChange = async (value, record) => {
    await Userstatus(record.userId, value).then((res) => {});
  };
  const handleCancel = (type) => {
    if (type == 1) {
      visible.value = false;
    }
    if (type == 2) {
      deptvisible.value = false;
    }
    if (type == 2) {
      resourcevisible.value = false;
    }
  };
  const editDeptHandleOk = async () => {
    let depts: Array = [],
      user: User = { userId: selectUser.value.userId };
    checkStrictly.value.forEach((val) => {
      depts.push(val.deptId);
    });
    user.dept = depts;
    await UserEdit(user).then((res) => {
      fetchData();
    });
  };
  const editResourceHandleOk = async () => {
    let resources: Array = [],
      dialogs: Array = [],
      Knowledges: Array = [],
      user: User = { userId: selectUser.value.userId };
    checkStrictlyMenu.value.forEach((val) => {
      resources.push(val.menuId);
    });
    user.resources = resources;
    checkStrictlyKnowledge.value.forEach((val) => {
      Knowledges.push(val.knowledgeId);
    });
    user.knowledges = Knowledges;
    checkStrictlyDialog.value.forEach((val) => {
      dialogs.push(val.dialogId);
    });
    user.dialogs = dialogs;
    await UserEdit(user).then((res) => {
      fetchData();
    });
  };
  const editHandleOk = async () => {
    if (editform.value.userId.length > 0) {
      await UserEdit({
        ...editform.value,
      } as unknown as User).then((res) => {
        fetchData();
      });
    } else {
      await UserAdd({
        ...editform.value,
      } as unknown as User).then((res) => {
        fetchData();
      });
    }
  };
  const operation = async (t, record) => {
    if (t == 0) {
      save.value = '新增';
      visible.value = true;
      editform.value.userId = '';
      editform.value.userName = '';
      editform.value.nickName = '';
      editform.value.email = '';
      editform.value.phoneNumber = '';
    }
    //重置密码
    if (t == 1) {
      await UserChangePwd(record.userId).then((res) => {
        if (res.code == 20000) {
          Modal.success({
            title: '重置密码',
            content: '该用户密码重置为000000',
          });
        } else {
          Modal.error({
            title: '重置密码',
            content: '该用户密码重置失败',
          });
        }
      });
    }
    //编辑
    if (t == 2) {
      visible.value = true;
      save.value = '编辑';
      editform.value.userId = record.userId;
      editform.value.userName = record.userName;
      editform.value.nickName = record.nickName;
      editform.value.email = record.email;
      editform.value.phoneNumber = record.phoneNumber;
    }
    //删除
    if (t == 3) {
      await UserDelete(record.userId).then((res) => {
        if (res.code == 200) {
          fetchData();
        }
      });
    }
    //权限
    if (t == 4) {
      resourcevisible.value = true;
      checkedKeysMenu.value = [];
      expandKdysMenu.value = [];
      checkStrictlyMenu.value = [];
      checkStrictlyKnowledge.value = [];
      checkedKeysKnowledge.value = [];
      checkStrictlyDialog.value = [];
      checkedKeysDialog.value = [];
      selectUser.value = record;
      if (record.resources) {
        record.resources.forEach((val) => {
          checkStrictlyMenu.value.push({
            menuId: val.menuId,
            menuName: val.menuName,
          });
          checkedKeysMenu.value.push(val.menuId);
          expandKdysMenu.value.push(val.menuId);
        });
      }
      if (record.knowledges) {
        record.knowledges.forEach((val) => {
          checkStrictlyKnowledge.value.push({
            knowledgeId: val.id,
            knowledgeName: val.name,
          });
          checkedKeysKnowledge.value.push(val.id);
        });
      }
      if (record.dialogs) {
        record.dialogs.forEach((val) => {
          checkStrictlyDialog.value.push({
            dialogId: val.id,
            dialogName: val.name,
          });
          checkedKeysDialog.value.push(val.id);
        });
      }
    }
    //机构
    if (t == 5) {
      deptvisible.value = true;
      checkedKeys.value = [];
      expandKdys.value = [];
      checkStrictly.value = [];
      selectUser.value = record;
      expandKdys.value.push('0');
      if (record.dept) {
        record.dept.forEach((val) => {
          checkStrictly.value.push({
            deptId: val.deptId,
            deptName: val.deptName,
          });
          checkedKeys.value.push(val.deptId);
          expandKdys.value.push(val.deptId);
        });
      }
    }
  };
  const fetchData = async (
    params: Pagination = { current: 1, pageSize: 20 }
  ) => {
    setLoading(true);
    try {
      await UserList(params).then((res) => {
        for (const user of res.rows) {
          if (user.dept) {
            for (const d of user.dept) {
              if (user.deptName) {
                user.deptName += d.deptName + ',';
              } else {
                user.deptName = d.deptName + ',';
              }
            }
          }
        }
        renderData.value = res.rows;
        console.log(renderData);
        pagination.current = params.current;
        pagination.total = res.total;
      });
    } catch (err) {
      // you can report use errorHandler or other
    } finally {
      setLoading(false);
    }
  };
  const search = () => {
    fetchData({
      ...basePagination,
      ...formModel.value,
    } as unknown as Pagination);
  };
  const onPageChange = (current: number) => {
    fetchData({ ...basePagination, current });
  };
  const OrganizationData = async (key) => {
    await OrganizationList(key).then((res) => {
      treeData.value = [...res.rows];
    });
  };
  const objArr = ref<any>([]);
  const MenuData = async (key) => {
    await ResourceList(key).then((res) => {
      treeDataMenu.value = [...res.rows];
      // addClassToLeafNodes(treeDataMenu.value);
      treeDataList.value = res.rows;
    });
  };
  KnowledgeList().then((res) => {
    knowledgeList.value = res.rows;
  });
};
KnowledgeList().then((res) => {
  knowledgeList.value = res.rows;
});
fetchData();
OrganizationData("");
MenuData();
  DialogList().then((res) => {
    DialogsList.value = res.rows;
  });
  fetchData();
  OrganizationData('');
  MenuData();
const reset = () => {
  formModel.value = generateFormModel();
};
  const reset = () => {
    formModel.value = generateFormModel();
  };
const handleSelectDensity = (
  val: string | number | Record<string, any> | undefined,
  e: Event
) => {
  size.value = val as SizeProps;
};
  const handleSelectDensity = (
    val: string | number | Record<string, any> | undefined,
    e: Event
  ) => {
    size.value = val as SizeProps;
  };
</script>
<style scoped lang="less">
  .card-demo {
    width: 460px;
    margin-left: 24px;
    transition-property: all;
  }
<style scoped>
.card-demo {
  width: 460px;
  margin-left: 24px;
  transition-property: all;
}
  .card-demo:hover {
    transform: translateY(-4px);
  }
  .table-page-search-wrapper {
    padding-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e8e8e8;
    .search-wrapper {
      display: flex;
      .wrapper-icon {
        display: flex;
        align-items: center;
        margin-left: 40px;
        // margin-right: 40px;
      }
    }
  }
  .space_select_all {
    display: flex;
    justify-content: end;
    margin-bottom: 15px;
  }
  .table_box {
    display: flex;
.card-demo:hover {
  transform: translateY(-4px);
}
    border: 1px solid #e8e8e8;
    border-bottom: none;
    .row1_clo {
      min-width: 200px;
      display: flex;
      padding-left: 20px;
      border-right: 1px solid #e8e8e8;
    }
    .table_row1 {
      width: 100%;
      .row1_list {
        display: flex;
        min-height: 40px;
        border-bottom: 1px solid #e8e8e8;
        // line-height: 40px;
      }
    }
    .row1_clo2 {
      width: 100%;
      border-top: none;
      .row2_clo2_1 {
        display: flex;
        width: 100%;
        min-height: 40px;
        line-height: 40px;
        border-bottom: 1px solid #e8e8e8;
        .row1_clo2_1 {
          border-right: 1px solid #e8e8e8;
          min-width: 310px;
          padding-left: 20px;
        }
        .row1_clo2_2 {
          border-top: none;
          border-right: none;
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          div {
            margin-left: 20px;
          }
        }
      }
    }
    .row2_clo2_1:last-child {
      border-bottom: none;
    }
  }
</style>
<style lang="less">
  .ant-table-wrapper {
    .ant-table-tbody {
      tr {
        td {
          .ant-table-row-cell-break-word {
            .ant-table-column-sorter {
              display: none;
            }
          }
        }
      }
    }
    .search-wrapper {
      display: flex;
      .wrapper-icon {
        display: flex;
        align-items: center;
        margin-left: 40px;
        // margin-right: 40px;
      }
    }
  }
</style>
<style lang="less">
  .ant-table-wrapper {
    .ant-table-tbody {
      tr {
        td {
          .ant-table-row-cell-break-word {
            .ant-table-column-sorter {
              display: none;
            }
          }
        }
      }
    }
  }
</style>
<style lang="less" scoped>
  .table-page-search-wrapper {
    .ant-form-inline {
      :deep(.ant-form-item) {
        display: flex;
      }
    }
  }
</style>