办学质量监测教学评价系统
Flex
9 小时以前 48954e86178c5c3d95f64b59d9a88f22a51ff1ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<script setup lang="ts">
import type { Role } from '#/api/system/user/model';
 
import { computed, h, ref } from 'vue';
 
import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
 
import { Tag } from 'ant-design-vue';
 
import { useVbenForm } from '#/adapter/form';
import { findUserInfo, userAdd, userUpdate } from '#/api/system/user';
import { authScopeOptions } from '#/views/system/role/data';
 
import { drawerSchema, AssigningWorkSchema } from './data';
import { deptList } from '#/api/system/dept/index';
 
const emit = defineEmits<{ reload: [] }>();
 
const isUpdate = ref(false); //当前是否为编辑
const isLook = ref(false); //当前是否为查看
const title = computed(() => {
  let text = '';
  text = "工作下发"
  return text;
});
 
const [BasicForm, formApi] = useVbenForm({
  commonConfig: {
    formItemClass: 'col-span-2',
    componentProps: {
      class: 'w-full',
    },
    labelWidth: 80,
  },
  schema: AssigningWorkSchema(),
  showDefaultActions: false,
  wrapperClass: 'grid-cols-2',
});
 
/**
 * 生成角色的自定义label
 * 也可以用option插槽来做
 * renderComponentContent: () => ({
    option: ({value, label, [disabled, key, title]}) => '',
  }),
 */
function genRoleOptionlabel(role: Role) {
  const found = authScopeOptions.find((item) => item.value === role.dataScope);
  if (!found) {
    return role.roleName;
  }
  return h('div', { class: 'flex items-center gap-[6px]' }, [
    h('span', null, role.roleName),
    h(Tag, { color: found.color }, () => found.label),
  ]);
}
// 打开以及编辑都会调用该事件
const [BasicDrawer, drawerApi] = useVbenDrawer({
  onCancel: handleCancel,
  onConfirm: handleConfirm,
  async onOpenChange(isOpen) {
    drawerApi.drawerLoading(true);
    if (isOpen) {
      // 初始化一下表单选项
      const deptlist = await (
        await deptList()
      ).map((item) => {
        return {
          ...item,
          value: item.deptId,
          label: item.deptName,
        };
      });
      formApi.updateSchema([
        {
          componentProps: { options: deptlist },
          fieldName: 'responsibleDepartment',
        },
      ]);
    }
 
    if (!isOpen) {
      // 需要重置岗位选择
      formApi.updateSchema([
        {
          componentProps: { options: [], placeholder: '请先选择部门' },
          fieldName: 'postIds',
        },
      ]);
      return null;
    }
    const { id } = drawerApi.getData() as { id?: number | string };
    isUpdate.value = !!id;
 
    // 更新 && 赋值
    // const { postIds, posts, roleIds, roles, user } = await findUserInfo(id); //调用接口获取详细信息
 
    const data = {
      id: '0', //工作id,编号
      workName: '工作名称1', //工作名称
      workClass: '工作类别', //工作类别
      workContent: '工作内容', //工作内容
      projectBudget: '项目预算', //项目预算
      amountProject: '项目金额', //项目金额
      responsibleDepartment: '负责部门', //负责部门
      Head: '负责人', //负责人
      Annual: '2025', //年度
      assessmentTime: '2025-06-25', //考核时间
      assessmentIndicators: '考核指标', //考核指标
      File: '文件地址', //文件上传
      taskStatus: '任务状态', //任务状态
      assignmentStatus: '分配状态', //分配状态
      workProgress: '工作进度', //工作进度
    };
 
    console.log(data);
    console.log(id);
 
    if (data && id) {
      await Promise.all([
        // 添加基础信息
        formApi.setValues(data),
      ]);
    }
    drawerApi.drawerLoading(false);
    console.log(isLook.value);
  },
});
// 表单提交,编辑与新增都会调用这个方法体
async function handleConfirm() {
  try {
    drawerApi.drawerLoading(true);
    const { valid } = await formApi.validate();
    if (!valid) {
      return;
    }
    const data = cloneDeep(await formApi.getValues());  //表单内的数据
    console.log(data)
    // await (isUpdate.value ? userUpdate(data) : userAdd(data));
    emit('reload');
    await handleCancel();
  } catch (error) {
    console.error(error);
  } finally {
    drawerApi.drawerLoading(false);
  }
}
 
async function handleCancel() {
  drawerApi.close();
  await formApi.resetForm();
}
 
function IsShowConfirmButton(params: type) {
  if (isLook.value) {
    return false;
  }
  return true;
}
 
// 在这加载些数据
</script>
 
<template>
  <BasicDrawer :close-on-click-modal="false" :title="title" class="w-[600px]">
    <BasicForm />
  </BasicDrawer>
</template>