소스 검색

feat: save

gemercheung 1 년 전
부모
커밋
1de789344a
8개의 변경된 파일256개의 추가작업 그리고 71개의 파일을 삭제
  1. 12 18
      src/request/organization.ts
  2. 23 1
      src/request/users.ts
  3. 4 23
      src/view/organization-add.vue
  4. 2 4
      src/view/organization-edit.vue
  5. 5 2
      src/view/organization.vue
  6. 6 0
      src/view/quisk.ts
  7. 144 0
      src/view/users-add.vue
  8. 60 23
      src/view/users.vue

+ 12 - 18
src/request/organization.ts

@@ -3,7 +3,9 @@ import { ResPage } from './type'
 import { organizationTypeEnum } from '@/store/organization'
 import * as URL from "./URL";
 
-export type AddOrgParamType = {
+// 
+
+export type OrganizationType = {
     ancestors: string
     contact: string
     orderNum: number
@@ -11,35 +13,27 @@ export type AddOrgParamType = {
     parentId: number
     orgName: string
     password: string
-    type: number | null
-    userName: string
-}
-
-export type OrganizationType = {
-    orgId: number
-    orgName: string
-    type: organizationTypeEnum
-    userId: string
+    type: organizationTypeEnum | null
     userName: string
 
 }
 
-export const addOrgFetch = (params: any) =>
+export const addOrgFetch = (params: Partial<OrganizationType>) =>
     sendFetch<PageProps<OrganizationType>>(URL.addOrganization, {
         method: "post",
         body: JSON.stringify(params),
     });
-    export const alterOrgFetch = (params: any) =>
-        sendFetch<PageProps<OrganizationType>>(URL.alterOrganization, {
-            method: "post",
-            body: JSON.stringify(params),
-        });
-export const delOrgFetch = (params: any) =>
+export const alterOrgFetch = (params: PageProps<Partial<OrganizationType>>) =>
+    sendFetch<PageProps<OrganizationType>>(URL.alterOrganization, {
+        method: "post",
+        body: JSON.stringify(params),
+    });
+export const delOrgFetch = (params: PageProps<Partial<OrganizationType>>) =>
     sendFetch<PageProps<OrganizationType>>(URL.delOrganization, {
         method: "post",
         body: JSON.stringify(params),
     });
-export const getOrgListFetch = (params: any) =>
+export const getOrgListFetch = (params: PageProps<Partial<OrganizationType>>) =>
     sendFetch<ResPage<PageProps<OrganizationType>>>(URL.organizationPage, {
         method: "post",
         body: JSON.stringify(params),

+ 23 - 1
src/request/users.ts

@@ -3,9 +3,20 @@ import { ResPage } from './type'
 import * as URL from "./URL";
 
 export type UserType = {
+    createBy: string
+    createTime: string
+    fdkkId: number
+    head: string
+    nickName: string
     orgId: number
     orgName: string
-    type: number
+    status: number
+    tbStatus: number
+    updateBy: string
+    updateTime: string
+    userId: number
+    userName: string
+    roleNames: string
 }
 
 
@@ -15,3 +26,14 @@ export const getUserpageFetch = (params: any) =>
         body: JSON.stringify(params),
     });
 
+
+export const addUserFetch = (params: any) =>
+    sendFetch<ResPage<PageProps<UserType>>>(URL.addUser, {
+        method: "post",
+        body: JSON.stringify(params),
+    });
+export const updateUserStatusFetch = (params: Pick<UserType, 'userId' | 'status'>) =>
+    sendFetch<ResPage<PageProps<UserType>>>(URL.changeUserStatus, {
+        method: "post",
+        body: JSON.stringify(params),
+    });

+ 4 - 23
src/view/organization-add.vue

@@ -48,7 +48,7 @@
 import { QuiskExpose } from "@/helper/mount";
 import type { FormInstance, FormRules } from "element-plus";
 // import { ElMessage } from "element-plus";
-import { AddOrgParamType } from '@/request/organization'
+import type { OrganizationType } from '@/request/organization'
 import { OrganizationTypeDesc } from '@/store/organization'
 
 import { ref, reactive, unref } from "vue";
@@ -79,9 +79,9 @@ const rules = reactive<FormRules>({
 },)
 
 const props = defineProps<{
-  submit: (data: AddOrgParamType) => Promise<any>;
+  submit: (data: OrganizationType) => Promise<any>;
 }>();
-const data = ref<AddOrgParamType & {}>({
+const data = ref<OrganizationType & {}>({
   ancestors: "",
   contact: "",
   orderNum: 0,
@@ -107,30 +107,11 @@ defineExpose<QuiskExpose>({
       setParentId();
       const res = await unref(baseFormRef)?.validate();
       if (res) {
-        await props.submit(data.value as any as AddOrgParamType);
+        await props.submit(data.value as any as OrganizationType);
       }
     } else {
       throw "";
     }
-
-
-    // await baseForm.value.validate((valid: any, fields: any) => {
-    //   if (valid) {
-    //     throw "1111";
-    //   } else {
-    //     console.log('error submit!', fields)
-    //   }
-    // })
-
-    // try {
-    //   const res = await baseForm.value.validate();
-    //   console.log('res', res)
-
-
-    // } catch (error) {
-    //   throw error;
-    // }
-
   },
 });
 </script>

+ 2 - 4
src/view/organization-edit.vue

@@ -18,7 +18,6 @@
 import { QuiskExpose } from "@/helper/mount";
 import type { FormInstance, FormRules } from "element-plus";
 import type { OrganizationType } from "@/request/organization";
-import { AddOrgParamType } from '@/request/organization'
 import { OrganizationTypeDesc } from '@/store/organization'
 import { ref, reactive, unref, watchEffect } from "vue";
 import { user } from '@/store/user'
@@ -46,9 +45,9 @@ const rules = reactive<FormRules>({
 
 const props = defineProps<{
   org: OrganizationType,
-  submit: (data: AddOrgParamType) => Promise<any>;
+  submit: (data: OrganizationType) => Promise<any>;
 }>();
-const data = ref<AddOrgParamType & {}>({
+const data = ref<OrganizationType & {}>({
   ancestors: "",
   contact: "",
   orderNum: 0,
@@ -67,7 +66,6 @@ const setParentId = () => {
   }
 }
 watchEffect(() => {
-
   if (props.org) {
     data.value = { ...props.org}
   }

+ 5 - 2
src/view/organization.vue

@@ -28,11 +28,14 @@
       <el-table :data="relicsArray" border>
         <el-table-column label="单位名称" prop="orgName"></el-table-column>
         <el-table-column label="类型" prop="type" v-slot:default="{ row }: { row: OrganizationType }">
-          {{ OrganizationTypeDesc[row.type] }}
+          {{ row.type ? OrganizationTypeDesc[row.type] : '' }}
         </el-table-column>
         <el-table-column label="单位账号" prop="userName"></el-table-column>
         <el-table-column label="单位联系人" prop="contact"></el-table-column>
-        <el-table-column label="创建时间" prop="updateTime"></el-table-column>
+
+        <el-table-column label="创建时间" prop="updateTime" v-slot:default="{ row }">
+          {{ row.updateTime && row.updateTime.substr(0, 16) }}
+        </el-table-column>
         <el-table-column label="创建人" prop="createByName"></el-table-column>
         <el-table-column label="操作" width="100px" fixed="right">
           <template #default="{ row }: { row: OrganizationType }">

+ 6 - 0
src/view/quisk.ts

@@ -4,6 +4,7 @@ import DeviceEdit from "./device-edit.vue";
 import SceneSelect from "./scene-select.vue";
 import OrganizationAdd from "./organization-add.vue";
 import OrganizationEdit from "./organization-edit.vue";
+import UsersAdd from "./users-add.vue";
 
 export const relicsEdit = quiskMountFactory(RelicsEdit, {
   title: "创建文物",
@@ -27,4 +28,9 @@ export const organizationAdd = quiskMountFactory(OrganizationAdd, {
 export const organizationEdit = quiskMountFactory(OrganizationEdit, {
   title: "编辑单位",
   width: 520,
+});
+
+export const usersAdd = quiskMountFactory(UsersAdd, {
+  title: "创建用户",
+  width: 520,
 });

+ 144 - 0
src/view/users-add.vue

@@ -0,0 +1,144 @@
+<template>
+  <!-- 
+    "nickName": "",
+  "orgId": 0,
+  "password": "",
+  "status": 0,
+  "userId": "",
+  "userName": "" 
+  -->
+  <el-form label-width="100px" :model="data" :rules="rules" ref="baseFormRef">
+    <el-form-item label="单位名称" prop="orgName" required>
+      <!-- <el-input v-model="data.orgName" style="width: 300px" :maxlength="500" placeholder="请输入" /> -->
+      <el-autocomplete style="width: 300px" v-model="data.orgName" :fetch-suggestions="querySearch" clearable
+        class="inline-input w-50" placeholder="请输入" @select="handleSelect" />
+    </el-form-item>
+
+    <el-form-item label="姓名" prop="nickName" required>
+      <el-input v-model="data.nickName" style="width: 300px" :maxlength="500" placeholder="请输入" />
+    </el-form-item>
+    <el-form-item label="账号" prop="userName" required>
+      <el-input v-model="data.userName" style="width: 300px" :maxlength="500" placeholder="请输入字母或数字组合" />
+    </el-form-item>
+    <el-form-item label="密码" prop="password" required>
+      <el-input autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" v-model="data.password"
+        :type="addPassFlag ? 'text' : 'password'" style="width: 300px" :maxlength="500"
+        placeholder="请输入8-16位数字、字母大小写组合">
+        <template #suffix>
+          <span @click="addPassFlag = !addPassFlag" style="cursor: pointer;">
+            <el-icon v-if="addPassFlag">
+              <View />
+            </el-icon>
+            <el-icon v-else>
+              <Hide />
+            </el-icon>
+          </span>
+        </template>
+      </el-input>
+
+    </el-form-item>
+  </el-form>
+</template>
+
+<script setup lang="ts">
+import { QuiskExpose } from "@/helper/mount";
+import type { FormInstance, FormRules } from "element-plus";
+// import { ElMessage } from "element-plus";
+import type { OrganizationType } from '@/request/organization'
+import {
+  getOrgListFetch,
+
+  UserType
+} from "@/request";
+
+import { ref, reactive, unref, onMounted } from "vue";
+import { View, Hide } from '@element-plus/icons-vue';
+import { user } from '@/store/user'
+
+const addPassFlag = ref(false)//图标显示标识
+
+const baseFormRef = ref<FormInstance>();
+
+type SelectType = {
+  value: string, id: number
+}
+
+const allOrgs = ref<SelectType[]>([]);
+
+const rules = reactive<FormRules>({
+
+  orgName: [
+    { required: true, message: "请输入单位名称", trigger: "select" },
+  ],
+  nickName: [
+    { required: true, message: "请输入姓名", trigger: "blur" },
+    // { required: true, pattern: /^1[3456789]\d{9}$/, message: "请输入正确手机号", trigger: "blur" },
+  ],
+  userName: [
+    { required: true, message: "请输入账号", trigger: "blur" },
+    // { required: true, pattern: /^1[3456789]\d{9}$/, message: "请输入正确手机号", trigger: "blur" },
+  ],
+  password: [
+    { required: true, pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$/, message: "请输入8-16位数字、字母大小写组合", trigger: "blur" },
+    { required: true, min: 8, message: '密码太短!', trigger: "blur" },
+  ],
+},)
+
+const props = defineProps<{
+  submit: (data: OrganizationType) => Promise<any>;
+}>();
+const data = ref<Partial<OrganizationType> & Partial<UserType>>({
+  nickName: "",
+  orgId: 0,
+  password: "",
+  status: 0,
+  userId: 0,
+  userName: ""
+});
+
+onMounted(async () => {
+  const data = await getOrgListFetch({
+    pageNum: 1,
+    pageSize: 10000,
+  })
+  console.log('allOrgs', data.records);
+  allOrgs.value = Array.from(data.records).map((item: OrganizationType) => {
+    const i: SelectType = { value: item['orgName'], id: item['orgId'] }
+    return i
+  });
+
+})
+
+// const setParentId = () => {
+//   if (user.value) {
+//     const isSuper = user.value.roles.filter(item => item.roleKey === "super_admin").length > 0;
+//     data.value.parentId = isSuper ? 0 : Number(user.value.orgId)
+//   }
+// }
+const handleSelect = (item: SelectType) => {
+  data.value.orgId = item.id
+  console.log('handleSelect-id', item.id)
+}
+const querySearch = (queryString: string, cb: any) => {
+  const results = queryString
+    ? allOrgs.value.filter(i => i.value.toLowerCase().includes(queryString.toLowerCase()))
+    : allOrgs.value
+  console.log('queryString', queryString)
+  console.log('results', results)
+  cb(results)
+}
+defineExpose<QuiskExpose>({
+  async submit() {
+
+    if (unref(baseFormRef)) {
+
+      const res = await unref(baseFormRef)?.validate();
+      if (res) {
+        await props.submit(data.value as any as OrganizationType);
+      }
+    } else {
+      throw "";
+    }
+  },
+});
+</script>

+ 60 - 23
src/view/users.vue

@@ -4,13 +4,10 @@
       <div class="search">
         <el-form label-width="100px" inline>
           <el-form-item label="用户账号">
-            <el-input v-model="pageProps.cameraSn" clearable style="width: 250px" placeholder="请输入" />
+            <el-input v-model="pageProps.userName" clearable style="width: 250px" placeholder="请输入" />
           </el-form-item>
           <el-form-item label="所属单位">
-            <!-- <el-select style="width: 250px" v-model="pageProps.cameraType" clearable>
-              <el-option :value="Number(key)" :label="type" v-for="(type, key) in DeviceTypeDesc" />
-            </el-select> -->
-            <el-input v-model="pageProps.cameraSn" clearable style="width: 250px" placeholder="请输入" />
+            <el-input v-model="pageProps.orgName" clearable style="width: 250px" placeholder="请输入" />
           </el-form-item>
 
           <el-form-item>
@@ -18,6 +15,7 @@
             <el-button type="primary" plain @click="pageProps = { ...initProps }">
               重置
             </el-button>
+            <el-button type="primary" @click="addHandler"> 创建用户 </el-button>
           </el-form-item>
         </el-form>
       </div>
@@ -25,24 +23,31 @@
 
     <div class="relics-content">
       <el-table :data="relicsArray" border>
-        <el-table-column label="姓名" prop="cameraSn"></el-table-column>
-
-        <el-table-column label="账号" prop="snCode" v-slot:default="{ row }: { row: Device }">
+        <el-table-column label="姓名" prop="nickName"></el-table-column>
+        <el-table-column label="账号" prop="userName"></el-table-column>
+        <!-- <el-table-column label="账号" prop="userName" v-slot:default="{ row }: { row: Device }">
           {{ DeviceTypeDesc[row.cameraType] }}
-        </el-table-column>
+        </el-table-column> -->
 
-        <el-table-column label="所属单位" prop="createBy"> </el-table-column>
-        <el-table-column label="角色" prop="createBy"> </el-table-column>
+        <el-table-column label="所属单位" prop="orgName"> </el-table-column>
+        <el-table-column label="角色" prop="roleNames"> </el-table-column>
         <el-table-column label="创建人" prop="createBy"> </el-table-column>
         <el-table-column label="创建时间" prop="createTime" v-slot:default="{ row }">
           {{ row.createTime && row.createTime.substr(0, 16) }}
         </el-table-column>
-        <el-table-column label="状态" prop="createBy"> </el-table-column>
+        <el-table-column align="center" label="状态" prop="status" v-slot:default="{ row }">
+          <el-switch inline-prompt width="60" v-model="row.status" :before-change="() => beforeChangeStatus(row)"
+            :active-value='1' :inactive-value='0' active-text="启用" inactive-text="禁用"
+            style="--el-switch-on-color: #13ce66; " />
+        </el-table-column>
         <el-table-column label="操作" width="100px" fixed="right">
           <template #default="{ row }">
-            <!-- <el-button link type="danger" @click="delHandler(row.cameraId)" size="small">
+            <el-button link type="primary" @click="editHandler(row)" size="small">
+              编辑
+            </el-button>
+            <el-button link type="danger" @click="delHandler(row)" size="small">
               删除
-            </el-button> -->
+            </el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -59,29 +64,61 @@
 import { onActivated, ref, watch } from "vue";
 import {
   getUserpageFetch,
-  PageProps
+  addUserFetch,
+  updateUserStatusFetch,
+  PageProps,
+  UserType
 } from "@/request";
-import { Device } from "@/request/type";
-import { DeviceTypeDesc } from "@/store/device";
-// import { ElMessageBox } from "element-plus";
-// import { deviceEdit } from "./quisk";
+import { usersAdd } from "./quisk";
+import { openLoading, closeLoading } from "@/helper/loading";
+
 import { debounce } from "@/util";
 
-const initProps: PageProps<{}> = {
+const initProps: PageProps<Partial<Pick<UserType, "userName" | "orgName">>> = {
   pageNum: 1,
   pageSize: 10,
+  userName: '',
+  orgName: ''
 };
+
 const pageProps = ref({ ...initProps });
 const total = ref<number>(0);
-const relicsArray = ref<Device[]>([]);
+const relicsArray = ref<UserType[]>([]);
 
 const refresh = debounce(async () => {
   const data = await getUserpageFetch(pageProps.value);
 
-  // total.value = data.total;
-  // relicsArray.value = data.records;
+  total.value = data.total;
+  relicsArray.value = data.records;
 });
+const addHandler = async () => {
+  await usersAdd({ submit: addUserFetch });
+  await refresh();
+}
+const editHandler = (row: UserType) => {
+
+}
+const delHandler = (row: UserType) => {
 
+}
+const beforeChangeStatus = (row: UserType): Promise<boolean> => {
+  openLoading()
+  return new Promise(async (resolve, reject) => {
+    try {
+      const anti = !row.status
+      console.log('anti', anti)
+      await updateUserStatusFetch({
+        userId: row.userId,
+        status: Number(anti)
+      });
+      resolve(true)
+    } catch (error) {
+      reject(false)
+    }
+
+    closeLoading();
+  })
+}
 watch(pageProps, refresh, { deep: true, immediate: true });
 onActivated(refresh);
 </script>