|
|
@@ -3,32 +3,20 @@
|
|
|
<ElMenuItem class="menu-logo" index="logo" disabled>
|
|
|
LOGO
|
|
|
</ElMenuItem>
|
|
|
- <ElSubmenu index="group">
|
|
|
- <template #title>{{selectedGroup.name}}</template>
|
|
|
- <template v-if="groupList.length > 0">
|
|
|
- <ElMenuItem v-for="group in groupList" :key="group.id" :index="`group-${group.id}`">{{group.name}}</ElMenuItem>
|
|
|
- </template>
|
|
|
- <template v-else>
|
|
|
- <ElMenuItem disabled>暂未加入任何小组</ElMenuItem>
|
|
|
- </template>
|
|
|
- </ElSubmenu>
|
|
|
<ElSubmenu index="project">
|
|
|
<template #title>{{selectedProject.name}}</template>
|
|
|
<template v-if="projectList.length > 0">
|
|
|
<ElMenuItem v-for="project in projectList" :key="project.id" :index="`project-${project.id}`">{{project.name}}</ElMenuItem>
|
|
|
</template>
|
|
|
- <template v-else-if="selectedGroup.id === -1">
|
|
|
- <ElMenuItem disabled>请先选择小组</ElMenuItem>
|
|
|
- </template>
|
|
|
<template v-else>
|
|
|
- <ElMenuItem disabled>该小组暂无项目</ElMenuItem>
|
|
|
+ <ElMenuItem disabled>暂无项目</ElMenuItem>
|
|
|
</template>
|
|
|
</ElSubmenu>
|
|
|
<template v-if="userLoggedIn">
|
|
|
<ElSubmenu index="user" class="user">
|
|
|
<template #title>{{userInfo.username}}</template>
|
|
|
- <ElMenuItem index="user-create">创建小组</ElMenuItem>
|
|
|
- <ElMenuItem index="user-join">加入小组</ElMenuItem>
|
|
|
+ <ElMenuItem index="user-project">创建项目</ElMenuItem>
|
|
|
+ <ElMenuItem index="user-invite">邀请成员</ElMenuItem>
|
|
|
<ElMenuItem index="user-logout">登出</ElMenuItem>
|
|
|
</ElSubmenu>
|
|
|
</template>
|
|
|
@@ -36,21 +24,120 @@
|
|
|
<ElLink type="primary" href="/login" class="user">登录</ElLink>
|
|
|
</template>
|
|
|
</ElMenu>
|
|
|
+ <ElDrawer v-model="showProjectDrawer">
|
|
|
+ <template #title><span>创建项目</span></template>
|
|
|
+ <div class="drawer-content">
|
|
|
+ <div class="form-container">
|
|
|
+ <ElForm :model="createProjectForm">
|
|
|
+ <ElFormItem label="项目名" prop="name">
|
|
|
+ <ElInput v-model="createProjectForm.name" placeholder="请输入要创建的项目名"></ElInput>
|
|
|
+ </ElFormItem>
|
|
|
+ <ElFormItem label="项目描述" prop="description">
|
|
|
+ <ElInput
|
|
|
+ v-model="createProjectForm.description"
|
|
|
+ placeholder="请输入项目描述"
|
|
|
+ type="textarea"
|
|
|
+ :autosize="{ minRows: 3, maxRows: 3}"
|
|
|
+ ></ElInput>
|
|
|
+ </ElFormItem>
|
|
|
+ <ElFormItem>
|
|
|
+ <ElButton @click="createProject" type="primary">创建</ElButton>
|
|
|
+ </ElFormItem>
|
|
|
+ </ElForm>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </ElDrawer>
|
|
|
+ <ElDrawer v-model="showInviteDrawer">
|
|
|
+ <template #title><span>邀请成员</span></template>
|
|
|
+ <div class="drawer-content">
|
|
|
+ <div class="form-container">
|
|
|
+ <ElForm :model="inviteProjectForm">
|
|
|
+ <ElFormItem label="项目" prop="projectId">
|
|
|
+ <ElSelect v-model="inviteProjectForm.projectId" placeholder="请选择成员将要加入的项目">
|
|
|
+ <ElOption v-for="project in projectList" :key="project.id" :value="project.id" :label="project.name"></ElOption>
|
|
|
+ </ElSelect>
|
|
|
+ </ElFormItem>
|
|
|
+ <ElFormItem label="手机号" prop="phone">
|
|
|
+ <ElInput v-model="inviteProjectForm.phone" placeholder="请输入成员注册所用手机号"></ElInput>
|
|
|
+ </ElFormItem>
|
|
|
+ <ElFormItem>
|
|
|
+ <ElButton @click="inviteMember" type="primary">邀请</ElButton>
|
|
|
+ </ElFormItem>
|
|
|
+ </ElForm>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </ElDrawer>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
+
|
|
|
import { useProjectList } from '@/composable/useProject';
|
|
|
-import { useGroupList } from '@/composable/useGroup';
|
|
|
import { useUser } from '@/composable/useUser';
|
|
|
-import { defineComponent } from 'vue';
|
|
|
+import { defineComponent, ref, reactive } from 'vue';
|
|
|
+import { PortalAPI, ProjectAPI } from '@/api';
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'Menu',
|
|
|
- setup(_, { emit }) {
|
|
|
- const { projectListOfCurrentGroup: projectList, selectedProject, handleProjectChange } = useProjectList();
|
|
|
- const { groupList, selectedGroup, handleGroupChange } = useGroupList();
|
|
|
+ setup() {
|
|
|
+ const { projectList, selectedProject, handleProjectChange } = useProjectList();
|
|
|
const { userInfo, userLoggedIn, userLogOut } = useUser();
|
|
|
|
|
|
+ const showProjectDrawer = ref(false);
|
|
|
+ const showInviteDrawer = ref(false);
|
|
|
+
|
|
|
+ const openProjectDrawer = () => {
|
|
|
+ showProjectDrawer.value = true;
|
|
|
+ };
|
|
|
+ const openInviteDrawer = () => {
|
|
|
+ showInviteDrawer.value = true;
|
|
|
+ };
|
|
|
+ const createProjectForm = reactive({
|
|
|
+ name: '',
|
|
|
+ description: '',
|
|
|
+ });
|
|
|
+ const createProject = () => {
|
|
|
+ ProjectAPI.createProject(createProjectForm.name, createProjectForm.description);
|
|
|
+ };
|
|
|
+
|
|
|
+ interface InviteProjectForm {
|
|
|
+ projectId: undefined | number;
|
|
|
+ phone: string;
|
|
|
+ }
|
|
|
+
|
|
|
+ const inviteProjectForm = reactive<InviteProjectForm>({
|
|
|
+ projectId: undefined,
|
|
|
+ phone: '',
|
|
|
+ });
|
|
|
+ const inviteMember = async () => {
|
|
|
+ let invitedUserId: number;
|
|
|
+
|
|
|
+ const res = await PortalAPI.getUserIdByPhoneNumber(inviteProjectForm.phone) as unknown as {id: number};
|
|
|
+
|
|
|
+ if (res) {
|
|
|
+ invitedUserId = res.id;
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ type: 'error',
|
|
|
+ message: '成员不存在,请再次确认手机号',
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!inviteProjectForm.projectId) {
|
|
|
+ ElMessage({
|
|
|
+ type: 'error',
|
|
|
+ message: '请选择有效的项目',
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ProjectAPI.addProjectMember({
|
|
|
+ projectId: inviteProjectForm.projectId,
|
|
|
+ invitedUserId,
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
const handleSelect = (index: string) => {
|
|
|
const [type, id] = index.split('-');
|
|
|
switch (type) {
|
|
|
@@ -61,15 +148,11 @@ export default defineComponent({
|
|
|
handleProjectChange(parseInt(id, 10));
|
|
|
break;
|
|
|
}
|
|
|
- case 'group': {
|
|
|
- handleGroupChange(parseInt(id, 10));
|
|
|
- break;
|
|
|
- }
|
|
|
case 'user': {
|
|
|
- if (id === 'create') {
|
|
|
- emit('show-create-group-drawer');
|
|
|
- } else if (id === 'join') {
|
|
|
- emit('show-join-group-drawer');
|
|
|
+ if (id === 'project') {
|
|
|
+ openProjectDrawer();
|
|
|
+ } else if (id === 'invite') {
|
|
|
+ openInviteDrawer();
|
|
|
} else if (id === 'logout') {
|
|
|
userLogOut();
|
|
|
}
|
|
|
@@ -84,12 +167,20 @@ export default defineComponent({
|
|
|
return {
|
|
|
projectList,
|
|
|
selectedProject,
|
|
|
- groupList,
|
|
|
- selectedGroup,
|
|
|
+
|
|
|
handleSelect,
|
|
|
+
|
|
|
userInfo,
|
|
|
userLoggedIn,
|
|
|
userLogOut,
|
|
|
+
|
|
|
+ showProjectDrawer,
|
|
|
+ showInviteDrawer,
|
|
|
+
|
|
|
+ createProjectForm,
|
|
|
+ createProject,
|
|
|
+ inviteProjectForm,
|
|
|
+ inviteMember,
|
|
|
};
|
|
|
},
|
|
|
});
|
|
|
@@ -116,4 +207,11 @@ export default defineComponent({
|
|
|
height: 60px;
|
|
|
margin: 0 20px;
|
|
|
}
|
|
|
+.drawer-content {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+}
|
|
|
+.form-container {
|
|
|
+ width: 80%;
|
|
|
+}
|
|
|
</style>
|