Pārlūkot izejas kodu

feat: 职员接口调试

赖奇 1 gadu atpakaļ
vecāks
revīzija
ae7641d3d2

+ 51 - 0
apps/web-ele/src/api/worker/index.ts

@@ -0,0 +1,51 @@
+import type { PageConfig, WorkerEntity } from '@vben/types';
+
+import { parseQueryValues } from '@vben/utils';
+
+import { requestClient } from '#/api/request';
+
+interface WorkerPartialEntity
+  extends Partial<Omit<WorkerEntity, 'worker_gh' | 'worker_xm'>> {
+  worker_xm?: string;
+  worker_gh?: string;
+}
+
+interface WorkerQueryParams extends PageConfig, WorkerPartialEntity {
+  [key: `${string}.value`]: boolean | number | string;
+}
+
+/**
+ * 职员信息_列表
+ */
+export async function getWorkerListApi(params: WorkerQueryParams) {
+  return requestClient.post<any>('/api/query/list?pagevalue=63', {
+    ...params,
+  });
+}
+
+/**
+ * 职员信息_详情
+ */
+export async function getWorkerDetailApi(data: { worker_id: string }) {
+  return requestClient.post<any>(
+    '/api/query/view?pagevalue=64',
+    {
+      ...parseQueryValues(data),
+    },
+    { formatData: true }, // 格式化返回数据
+  );
+}
+
+/**
+ * 职员信息_新增
+ */
+export async function addWorkerApi(data: WorkerEntity) {
+  return requestClient.post<any>('/api/add?pagevalue=65', { ...data });
+}
+
+/**
+ * 职员信息_编辑
+ */
+export async function editWorkerApi(data: WorkerEntity) {
+  return requestClient.post<any>('/api/up?pagevalue=66', { ...data });
+}

+ 2 - 1
apps/web-ele/src/locales/langs/en-US/page.json

@@ -26,6 +26,7 @@
     "couponManage": "Coupon",
     "examineManage": "Examine",
     "examineSubsidy": "Subsidy",
-    "examineCoupon": "Coupon"
+    "examineCoupon": "Coupon",
+    "workerManage": "Worker"
   }
 }

+ 2 - 1
apps/web-ele/src/locales/langs/zh-CN/page.json

@@ -26,6 +26,7 @@
     "couponManage": "优惠券管理",
     "examineManage": "审核管理",
     "examineSubsidy": "补贴审核",
-    "examineCoupon": "优惠劵审核"
+    "examineCoupon": "优惠劵审核",
+    "workerManage": "职员管理"
   }
 }

+ 210 - 0
apps/web-ele/src/views/system-manage/worker-manage/form.vue

@@ -0,0 +1,210 @@
+<script lang="ts" setup>
+import type { WorkerEntity } from '@vben/types';
+
+import { computed, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+
+import { ElMessage } from 'element-plus';
+
+import { useVbenForm, z } from '#/adapter/form';
+import { addWorkerApi, editWorkerApi, getWorkerDetailApi } from '#/api/worker';
+
+const emit = defineEmits(['finish']);
+const data = ref();
+const formType = ref<'create' | 'detail' | 'edit'>('create');
+
+const titleMap = {
+  create: '新增职员',
+  detail: '职员详情',
+  edit: '编辑职员',
+} as const;
+
+const getTitle = computed(() => titleMap[formType.value]);
+
+const [BaseForm, baseFormApi] = useVbenForm({
+  showDefaultActions: false,
+  // 所有表单项共用,可单独在表单内覆盖
+  commonConfig: {
+    labelWidth: 130,
+    // 所有表单项
+    componentProps: {
+      class: 'w-full',
+    },
+  },
+  wrapperClass: 'grid-cols-1 lg:grid-cols-2',
+  schema: [
+    // { title: '姓名', field: 'worker_xm' },
+    // { title: '工号', field: 'worker_gh' },
+    // { title: '类别', field: 'worker_lb' },
+    // { title: '状态', field: 'worker_zt' },
+    // { title: '所属部门', field: 'worker_ssbm' },
+    // { title: '二级部门', field: 'worker_ssbm2' },
+    // { title: '岗位', field: 'worker_gw' },
+    // { title: '联系地址', field: 'worker_lxdz' },
+    // { title: '联系电话', field: 'worker_dh' },
+    // { title: '邮箱', field: 'worker_email' },
+    // { title: '紧急联系人', field: 'worker_jjlxr' },
+    // { title: '紧急联系电话', field: 'worker_jjlxdh' },
+    // { title: '创建时间', field: 'worker_createdate' },
+    // { title: '创建者', field: 'worker_create' },
+    // { title: '是否绑定微信', field: 'worker_iswxbind' },
+
+    {
+      component: 'Input',
+      fieldName: 'worker_xm',
+      label: '姓名',
+      rules: z.string().min(1, '请输入姓名'),
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_gh',
+      label: '工号',
+      rules: z.string().min(1, '请输入工号'),
+    },
+    {
+      component: 'Select',
+      fieldName: 'worker_lb',
+      label: '类别',
+      componentProps: {
+        options: [
+          { label: '合同工', value: '合同工' },
+          { label: '实习工', value: '实习工' },
+          { label: '临时工', value: '临时工' },
+        ],
+      },
+      rules: z.string().min(1, '请选择类别'),
+    },
+    {
+      component: 'Select',
+      fieldName: 'worker_zt',
+      label: '状态',
+      componentProps: {
+        options: [
+          { label: '在职', value: '在职' },
+          { label: '离职', value: '离职' },
+          { label: '退假', value: '退假' },
+        ],
+      },
+      rules: z.string().min(1, '请选择状态'),
+    },
+    // {
+    //   component: 'Input',
+    //   fieldName: 'worker_ssbm',
+    //   label: '所属部门',
+    //   rules: z.string().min(1, '请输入所属部门'),
+    // },
+    // {
+    //   component: 'Input',
+    //   fieldName: 'worker_ssbm2',
+    //   label: '二级部门',
+    // },
+    {
+      component: 'Input',
+      fieldName: 'worker_gw',
+      label: '岗位',
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_lxdz',
+      label: '联系地址',
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_dh',
+      label: '联系电话',
+      rules: z.string().min(1, '请输入联系电话'),
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_email',
+      label: '邮箱',
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_jjlxr',
+      label: '紧急联系人',
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_jjlxdh',
+      label: '紧急联系电话',
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_userid',
+      label: '关联渠道id',
+    },
+  ],
+});
+
+const [Modal, modalApi] = useVbenModal({
+  class: 'w-7/12',
+  onCancel() {
+    modalApi.close();
+  },
+  async onConfirm() {
+    // 校验输入的数据
+    const formValues = await baseFormApi.getValues();
+    const validate = await baseFormApi.validate();
+    if (!validate.valid) {
+      return;
+    }
+
+    try {
+      const apiMap = {
+        create: () => addWorkerApi(formValues as unknown as WorkerEntity),
+        edit: () =>
+          editWorkerApi({
+            ...formValues,
+            'worker_id.value': data.value.row.worker_id,
+          } as unknown as WorkerEntity),
+      };
+
+      if (formType.value === 'detail') {
+        modalApi.close();
+        return;
+      }
+
+      await apiMap[formType.value]();
+      ElMessage.success('操作成功');
+      emit('finish');
+      modalApi.close();
+    } catch {}
+  },
+  async onOpenChange(isOpen) {
+    if (isOpen) {
+      data.value = modalApi.getData();
+
+      formType.value = data.value.formType;
+
+      baseFormApi.setState({
+        commonConfig: { disabled: formType.value === 'detail' },
+      });
+
+      if (data.value.formType === 'create') {
+        return;
+      }
+
+      try {
+        modalApi.setState({ loading: true });
+        const detailData = await getWorkerDetailApi({
+          worker_id: data.value.row.worker_id,
+        });
+
+        baseFormApi.setValues(detailData);
+      } catch {
+        // console.log(error);
+      }
+
+      modalApi.setState({ loading: false });
+    }
+  },
+});
+</script>
+
+<template>
+  <Modal :title="getTitle">
+    <BaseForm />
+  </Modal>
+</template>

+ 157 - 0
apps/web-ele/src/views/system-manage/worker-manage/index.vue

@@ -0,0 +1,157 @@
+<script lang="ts" setup>
+import type { VbenFormProps } from '@vben/common-ui';
+
+import type { VxeGridProps } from '#/adapter/vxe-table';
+
+import { Page, useVbenModal } from '@vben/common-ui';
+import { MdiDetail, MdiEdit } from '@vben/icons';
+import { parseQueryValues } from '@vben/utils';
+
+import { useVbenVxeGrid } from '#/adapter/vxe-table';
+import { getWorkerListApi } from '#/api/worker';
+import { $t } from '#/locales';
+
+import EditForm from './form.vue';
+
+const formOptions: VbenFormProps = {
+  // 默认展开
+  collapsed: true,
+  // 控制表单是否显示折叠按钮
+  showCollapseButton: true,
+  // 按下回车时是否提交表单
+  submitOnEnter: true,
+  schema: [
+    {
+      component: 'Input',
+      fieldName: 'worker_xm',
+      label: '姓名',
+      componentProps: {
+        placeholder: $t('ui.placeholder.input'),
+        allowClear: true,
+      },
+    },
+    {
+      component: 'Input',
+      fieldName: 'worker_dh',
+      label: '联系电话',
+      componentProps: {
+        placeholder: $t('ui.placeholder.input'),
+        allowClear: true,
+      },
+    },
+  ],
+  wrapperClass: 'grid-cols-1 md:grid-cols-3 lg:grid-cols-5',
+};
+
+const gridOptions: VxeGridProps<any> = {
+  toolbarConfig: {
+    custom: true,
+    export: true,
+    // import: true,
+    refresh: true,
+    zoom: true,
+  },
+  height: 'auto',
+  exportConfig: {},
+  pagerConfig: {},
+  rowConfig: {
+    isHover: true,
+  },
+  stripe: true,
+
+  proxyConfig: {
+    response: {
+      result: 'Data',
+      total: 'Total',
+    },
+    ajax: {
+      query: async ({ page }, formValues) => {
+        return await getWorkerListApi({
+          pageindex: page.currentPage,
+          rows: page.pageSize,
+          ...parseQueryValues(formValues),
+        });
+      },
+    },
+  },
+
+  columns: [
+    // { title: '职员id', field: 'worker_id' },
+    { title: '姓名', field: 'worker_xm' },
+    { title: '工号', field: 'worker_gh' },
+    { title: '类别', field: 'worker_lb' },
+    { title: '状态', field: 'worker_zt' },
+    // { title: '所属部门', field: 'worker_ssbm' },
+    // { title: '二级部门', field: 'worker_ssbm2' },
+    { title: '岗位', field: 'worker_gw' },
+    { title: '联系地址', field: 'worker_lxdz' },
+    { title: '联系电话', field: 'worker_dh' },
+    { title: '邮箱', field: 'worker_email' },
+    // { title: '紧急联系人', field: 'worker_jjlxr' },
+    // { title: '紧急联系电话', field: 'worker_jjlxdh', width: 120 },
+    { title: '创建时间', field: 'worker_createdate' },
+    { title: '创建者', field: 'worker_create' },
+    // { title: '是否绑定微信', field: 'worker_iswxbind', width: 120 },
+    {
+      title: '操作',
+      field: 'action',
+      fixed: 'right',
+      slots: { default: 'action' },
+      width: 140,
+    },
+  ],
+};
+
+const [Grid, gridApi] = useVbenVxeGrid({ gridOptions, formOptions });
+
+const [Modal, modalApi] = useVbenModal({
+  fullscreenButton: false,
+  closeOnClickModal: false,
+  closeOnPressEscape: false,
+  connectedComponent: EditForm,
+});
+
+/* 创建 */
+function handleCreate() {
+  modalApi.setData({ formType: 'create' }).open();
+}
+
+/* 编辑 */
+function handleEdit(row: any) {
+  modalApi.setData({ formType: 'edit', row }).open();
+}
+
+/* 详情 */
+function handleDetail(row: any) {
+  modalApi.setData({ formType: 'detail', row }).open();
+}
+
+function handleFinish() {
+  gridApi.reload();
+}
+</script>
+
+<template>
+  <Page auto-content-height>
+    <Grid table-title="职员列表">
+      <template #toolbar-tools>
+        <el-button type="primary" @click="handleCreate"> 新增 </el-button>
+      </template>
+      <template #action="{ row }">
+        <el-button
+          round
+          @click="() => handleDetail(row)"
+          :icon="MdiDetail"
+          class="!p-2"
+        />
+        <el-button
+          round
+          @click="() => handleEdit(row)"
+          :icon="MdiEdit"
+          class="!p-2"
+        />
+      </template>
+    </Grid>
+    <Modal @finish="handleFinish" />
+  </Page>
+</template>

+ 1 - 0
packages/types/src/index.ts

@@ -6,4 +6,5 @@ export type * from './product';
 export type * from './scqy';
 export type * from './subsidyapplications';
 export type * from './user';
+export type * from './worker';
 export type * from '@vben-core/typings';

+ 73 - 0
packages/types/src/worker.ts

@@ -0,0 +1,73 @@
+/** 职员 */
+// CREATE TABLE `worker` (
+//   `worker_id` varchar(32) NOT NULL COMMENT '职员ID(列表显示)(查询条件)',
+//   `worker_xm` varchar(30) NOT NULL COMMENT '姓名(查询条件)(列表显示)',
+//   `worker_gh` varchar(30) NOT NULL COMMENT '工号(查询条件)(列表显示)',
+//   `worker_lb` varchar(10) NOT NULL COMMENT '类别(合同工/实习工/临时工)(查询条件)(列表显示)',
+//   `worker_zt` varchar(10) NOT NULL COMMENT '状态(在职/离职/退假)(查询条件)(列表显示)',
+//   `worker_ssbm` int(11) NOT NULL COMMENT '所属部门(查询条件)(列表显示)',
+//   `worker_ssbm2` int(11) DEFAULT NULL COMMENT '二级部门',
+//   `worker_gw` varchar(20) DEFAULT NULL COMMENT '岗位(查询条件)(列表显示)',
+//   `worker_lxdz` varchar(100) DEFAULT NULL COMMENT '联系地址',
+//   `worker_dh` varchar(20) NOT NULL COMMENT '联系电话(查询条件)(列表显示)',
+//   `worker_email` varchar(50) DEFAULT NULL COMMENT '邮箱',
+//   `worker_jjlxr` varchar(20) DEFAULT NULL COMMENT '紧急联系人',
+//   `worker_jjlxdh` varchar(20) DEFAULT NULL COMMENT '紧急联系电话',
+//   `worker_createdate` datetime NOT NULL COMMENT '创建时间(禁止编辑)(查询条件)(列表显示)(降序)',
+//   `worker_create` varchar(32) NOT NULL COMMENT '创建者(禁止编辑)(列表显示)',
+//   `worker_updater` varchar(32) DEFAULT NULL COMMENT '更新者(禁止插入)(禁止前端编辑)',
+//   `worker_updatetime` datetime DEFAULT NULL COMMENT '更新时间(禁止插入)(禁止前端编辑)',
+//   `worker_deletecode` tinyint(2) DEFAULT NULL COMMENT '删除标志(禁止插入)(禁止前端编辑)',
+//   `worker_wxopenid` varchar(50) DEFAULT NULL COMMENT '微信openid',
+//   `worker_iswxbind` tinyint(2) DEFAULT NULL COMMENT '是否绑定微信',
+//   `worker_userid` varchar(50) DEFAULT NULL COMMENT '关联渠道id',
+//   PRIMARY KEY (`worker_id`)
+// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='职员';
+
+/** 职员 */
+interface WorkerEntity {
+  /** 职员ID(列表显示)(查询条件) */
+  worker_id: string;
+  /** 姓名(查询条件)(列表显示) */
+  worker_xm: string;
+  /** 工号(查询条件)(列表显示) */
+  worker_gh: string;
+  /** 类别(合同工/实习工/临时工)(查询条件)(列表显示) */
+  worker_lb: string;
+  /** 状态(在职/离职/退假)(查询条件)(列表显示) */
+  worker_zt: string;
+  /** 所属部门(查询条件)(列表显示) */
+  worker_ssbm: string;
+  /** 二级部门 */
+  worker_ssbm2: string;
+  /** 岗位(查询条件)(列表显示) */
+  worker_gw: string;
+  /** 联系地址 */
+  worker_lxdz: string;
+  /** 联系电话(查询条件)(列表显示) */
+  worker_dh: string;
+  /** 邮箱 */
+  worker_email: string;
+  /** 紧急联系人 */
+  worker_jjlxr: string;
+  /** 紧急联系电话 */
+  worker_jjlxdh: string;
+  /** 创建时间(禁止编辑)(查询条件)(列表显示)(降序) */
+  worker_createdate: string;
+  /** 创建者(禁止编辑)(列表显示) */
+  worker_create: string;
+  /** 更新者(禁止插入)(禁止前端编辑) */
+  worker_updater: string;
+  /** 更新时间(禁止插入)(禁止前端编辑) */
+  worker_updatetime: string;
+  /** 删除标志(禁止插入)(禁止前端编辑) */
+  worker_deletecode: string;
+  /** 微信openid */
+  worker_wxopenid: string;
+  /** 是否绑定微信 */
+  worker_iswxbind: string;
+  /** 关联渠道id */
+  worker_userid: string;
+}
+
+export type { WorkerEntity };