소스 검색

feat: save

gemercheung 1 년 전
부모
커밋
f0ea58d212
6개의 변경된 파일165개의 추가작업 그리고 24개의 파일을 삭제
  1. 21 8
      src/request/organization.ts
  2. 15 6
      src/store/organization.ts
  3. 1 0
      src/view/organization-add.vue
  4. 91 0
      src/view/organization-edit.vue
  5. 31 10
      src/view/organization.vue
  6. 6 0
      src/view/quisk.ts

+ 21 - 8
src/request/organization.ts

@@ -1,33 +1,46 @@
 import { sendFetch, PageProps } from './index'
 import { ResPage } from './type'
+import { organizationTypeEnum } from '@/store/organization'
 import * as URL from "./URL";
 
-export type AddOrgParamType= {
+export type AddOrgParamType = {
     ancestors: string
     contact: string
     orderNum: number
     orgId: number
     parentId: number
-    orgName:string
+    orgName: string
     password: string
     type: number | null
     userName: string
-} 
+}
 
-export type organizationType = {
+export type OrganizationType = {
     orgId: number
     orgName: string
-    type: number
+    type: organizationTypeEnum
+    userId: string
+    userName: string
+
 }
 
 export const addOrgFetch = (params: any) =>
-    sendFetch<PageProps<organizationType>>(URL.addOrganization, {
+    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) =>
+    sendFetch<PageProps<OrganizationType>>(URL.delOrganization, {
         method: "post",
         body: JSON.stringify(params),
     });
-
 export const getOrgListFetch = (params: any) =>
-    sendFetch<ResPage<PageProps<organizationType>>>(URL.organizationPage, {
+    sendFetch<ResPage<PageProps<OrganizationType>>>(URL.organizationPage, {
         method: "post",
         body: JSON.stringify(params),
     });

+ 15 - 6
src/store/organization.ts

@@ -1,6 +1,15 @@
-export const OrganizationTypeDesc = {
-  1: "省级",
-  2: "市级",
-  3: "县级",
-  4: "服务商",
-};
+
+export enum organizationTypeEnum {
+  Province = 1,
+  City = 2,
+  Country = 3,
+  Supplier = 4
+}
+
+export const OrganizationTypeDesc: { [key in organizationTypeEnum]: string } = {
+  [organizationTypeEnum.Province]: "省级",
+  [organizationTypeEnum.City]: "市级",
+  [organizationTypeEnum.Country]: "县级",
+  [organizationTypeEnum.Supplier]: "服务商",
+
+};

+ 1 - 0
src/view/organization-add.vue

@@ -50,6 +50,7 @@ import type { FormInstance, FormRules } from "element-plus";
 // import { ElMessage } from "element-plus";
 import { AddOrgParamType } from '@/request/organization'
 import { OrganizationTypeDesc } from '@/store/organization'
+
 import { ref, reactive, unref } from "vue";
 import { View, Hide } from '@element-plus/icons-vue';
 import { user } from '@/store/user'

+ 91 - 0
src/view/organization-edit.vue

@@ -0,0 +1,91 @@
+<template>
+
+  <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-form-item>
+    <el-form-item label="类型" prop="type" required>
+      <!-- <el-input v-model="data.type" style="width: 300px" :maxlength="500" placeholder="请输入" /> -->
+      <el-select style="width: 300px" v-model="data.type">
+        <el-option :value="Number(key)" :label="type" v-for="(type, key) in OrganizationTypeDesc" />
+      </el-select>
+    </el-form-item>
+
+  </el-form>
+</template>
+
+<script setup lang="ts">
+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'
+
+const baseFormRef = ref<FormInstance>();
+
+const rules = reactive<FormRules>({
+  orgName: [
+    { required: true, message: "请输入单位名称", trigger: "blur" },
+  ],
+  type: [
+    { required: true, message: "请选择类型", trigger: "change" },
+  ],
+  contact: [
+    { required: true, message: "请输入联系人", trigger: "blur" },
+  ],
+  userName: [
+    { 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<{
+  org: OrganizationType,
+  submit: (data: AddOrgParamType) => Promise<any>;
+}>();
+const data = ref<AddOrgParamType & {}>({
+  ancestors: "",
+  contact: "",
+  orderNum: 0,
+  orgId: 0,
+  orgName: "",
+  parentId: 0,
+  password: "",
+  type: null,
+  userName: ""
+});
+
+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)
+  }
+}
+watchEffect(() => {
+
+  if (props.org) {
+    data.value = { ...props.org}
+  }
+
+})
+
+defineExpose<QuiskExpose>({
+  async submit() {
+
+    if (unref(baseFormRef)) {
+      setParentId();
+      const res = await unref(baseFormRef)?.validate();
+      if (res) {
+        await props.submit(data.value as any as AddOrgParamType);
+      }
+    } else {
+      throw "";
+    }
+  },
+});
+</script>

+ 31 - 10
src/view/organization.vue

@@ -27,17 +27,19 @@
     <div class="relics-content">
       <el-table :data="relicsArray" border>
         <el-table-column label="单位名称" prop="orgName"></el-table-column>
-        <el-table-column label="类型" prop="type"></el-table-column>
+        <el-table-column label="类型" prop="type" v-slot:default="{ row }: { row: OrganizationType }">
+          {{ 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="userId"></el-table-column>
+        <el-table-column label="创建人" prop="createByName"></el-table-column>
         <el-table-column label="操作" width="100px" fixed="right">
-          <template #default="{ row }">
-            <el-button link type="danger" @click="() => { }" size="small">
+          <template #default="{ row }: { row: OrganizationType }">
+            <el-button link type="primary" @click="editHandler(row)" size="small">
               编辑
             </el-button>
-            <el-button link type="danger" @click="() => { }" size="small">
+            <el-button link type="danger" @click="delOrganization(row)" size="small">
               删除
             </el-button>
           </template>
@@ -57,14 +59,15 @@ import { onActivated, ref, watch } from "vue";
 import {
   getOrgListFetch,
   addOrgFetch,
+  delOrgFetch,
+  alterOrgFetch,
   PageProps
 } from "@/request";
-// import { Device } from "@/request/type";
-// import { DeviceTypeDesc } from "@/store/device";
-// import { ElMessageBox } from "element-plus";
+import type { OrganizationType } from "@/request/organization";
 import { OrganizationTypeDesc } from '@/store/organization'
-import { organizationAdd } from "./quisk";
+import { organizationAdd, organizationEdit } from "./quisk";
 import { debounce } from "@/util";
+import { ElMessageBox } from "element-plus";
 
 const initProps: PageProps<{
   orgName: string
@@ -85,7 +88,6 @@ const relicsArray = ref<any[]>([]);
 
 const refresh = debounce(async () => {
   const data = await getOrgListFetch(pageProps.value);
-  console.log('data', data)
   total.value = data.total;
   relicsArray.value = data.records;
 });
@@ -98,6 +100,25 @@ const addHandler = async () => {
   await organizationAdd({ submit: addOrgFetch });
   await refresh();
 };
+
+const editHandler = async (org: OrganizationType) => {
+  await organizationEdit({ org: org, submit: alterOrgFetch });
+  await refresh();
+};
+const delOrganization = async (org: OrganizationType) => {
+  console.log('org', org)
+  const ok = await ElMessageBox.confirm("确定要删除吗", {
+    type: "warning",
+  });
+  if (ok) {
+    await delOrgFetch({
+      orgId: org.orgId,
+      orgName: org.orgName,
+      type: org.type
+    });
+    await refresh();
+  }
+};
 </script>
 
 <style scoped lang="scss">

+ 6 - 0
src/view/quisk.ts

@@ -3,6 +3,7 @@ import RelicsEdit from "./relics-edit.vue";
 import DeviceEdit from "./device-edit.vue";
 import SceneSelect from "./scene-select.vue";
 import OrganizationAdd from "./organization-add.vue";
+import OrganizationEdit from "./organization-edit.vue";
 
 export const relicsEdit = quiskMountFactory(RelicsEdit, {
   title: "创建文物",
@@ -22,3 +23,8 @@ export const organizationAdd = quiskMountFactory(OrganizationAdd, {
   title: "添加单位",
   width: 520,
 });
+
+export const organizationEdit = quiskMountFactory(OrganizationEdit, {
+  title: "编辑单位",
+  width: 520,
+});