feat: 权限接口请求优化以及修复其他问题 (#290)
This commit is contained in:
parent
c122589a2e
commit
32b1c4888d
@ -1,5 +1,4 @@
|
|||||||
import axios from './base'
|
import axios from './base'
|
||||||
|
|
||||||
// 空间
|
// 空间
|
||||||
export const createSpace = ({ name, description, members }: any) => {
|
export const createSpace = ({ name, description, members }: any) => {
|
||||||
return axios.post('/workspace', { name, description, members })
|
return axios.post('/workspace', { name, description, members })
|
||||||
@ -29,7 +28,7 @@ export const getUserList = (username: string) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 协作权限列表
|
// 获取协作权限下拉框枚举
|
||||||
export const getPermissionList = () => {
|
export const getPermissionList = () => {
|
||||||
return axios.get('collaborator/getPermissionList')
|
return axios.get('collaborator/getPermissionList')
|
||||||
}
|
}
|
||||||
@ -72,4 +71,4 @@ export const getCollaboratorPermissions = (surveyId: string) => {
|
|||||||
surveyId
|
surveyId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -26,7 +26,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import { useStore } from 'vuex'
|
import { useStore } from 'vuex'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -58,18 +58,18 @@ const tabArr = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
const tabs = ref([])
|
const tabs = ref([])
|
||||||
onMounted(async () => {
|
watch(() => store.state.cooperPermissions, (newVal) => {
|
||||||
await store.dispatch('fetchCooperPermissions', route.params.id)
|
tabs.value = []
|
||||||
// 如果有问卷管理权限,则加入问卷编辑和投放菜单
|
// 如果有问卷管理权限,则加入问卷编辑和投放菜单
|
||||||
if (store.state.cooperPermissions.includes(SurveyPermissions.SurveyManage)) {
|
if (newVal.includes(SurveyPermissions.SurveyManage)) {
|
||||||
tabs.value.push(tabArr[0])
|
tabs.value.push(tabArr[0])
|
||||||
tabs.value.push(tabArr[1])
|
tabs.value.push(tabArr[1])
|
||||||
}
|
}
|
||||||
// 如果有数据分析权限,则加入数据分析菜单
|
// 如果有数据分析权限,则加入数据分析菜单
|
||||||
if (store.state.cooperPermissions.includes(SurveyPermissions.DataManage)) {
|
if (newVal.includes(SurveyPermissions.DataManage)) {
|
||||||
tabs.value.push(tabArr[2])
|
tabs.value.push(tabArr[2])
|
||||||
}
|
}
|
||||||
})
|
}, { immediate: true })
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.nav {
|
.nav {
|
||||||
|
@ -5,7 +5,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const handleNavigateHome = () => window.open('/survey', '_self')
|
import { useRouter } from 'vue-router'
|
||||||
|
const router = useRouter()
|
||||||
|
const handleNavigateHome = () => {
|
||||||
|
router.push({
|
||||||
|
name: 'survey'
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.back-btn {
|
.back-btn {
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
row-class-name="tableview-row"
|
row-class-name="tableview-row"
|
||||||
cell-class-name="tableview-cell"
|
cell-class-name="tableview-cell"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
@row-click="onRowClick"
|
|
||||||
>
|
>
|
||||||
<el-table-column column-key="space" width="20" />
|
<el-table-column column-key="space" width="20" />
|
||||||
<el-table-column
|
<el-table-column
|
||||||
@ -98,9 +97,7 @@ const isAdmin = (id: string) => {
|
|||||||
UserRole.Admin
|
UserRole.Admin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const onRowClick = () => {
|
|
||||||
console.log('onRowClick')
|
|
||||||
}
|
|
||||||
const handleModify = async (id: string) => {
|
const handleModify = async (id: string) => {
|
||||||
await store.dispatch('list/getSpaceDetail', id)
|
await store.dispatch('list/getSpaceDetail', id)
|
||||||
modifyType.value = 'edit'
|
modifyType.value = 'edit'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory, type RouteLocationNormalized, type NavigationGuardNext } from 'vue-router'
|
||||||
import type { RouteRecordRaw } from 'vue-router'
|
import type { RouteRecordRaw } from 'vue-router'
|
||||||
import { useStore } from 'vuex'
|
import { useStore, type Store } from 'vuex'
|
||||||
import { SurveyPermissions } from '@/management/utils/types/workSpace'
|
import { SurveyPermissions } from '@/management/utils/types/workSpace'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import 'element-plus/theme-chalk/src/message.scss'
|
import 'element-plus/theme-chalk/src/message.scss'
|
||||||
@ -23,7 +23,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
path: '/survey/:id/edit',
|
path: '/survey/:id/edit',
|
||||||
meta: {
|
meta: {
|
||||||
needLogin: true,
|
needLogin: true,
|
||||||
premissions: [SurveyPermissions.SurveyManage]
|
permissions: [SurveyPermissions.SurveyManage]
|
||||||
},
|
},
|
||||||
name: 'QuestionEdit',
|
name: 'QuestionEdit',
|
||||||
component: () => import('../pages/edit/index.vue'),
|
component: () => import('../pages/edit/index.vue'),
|
||||||
@ -94,7 +94,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
name: 'analysisPage',
|
name: 'analysisPage',
|
||||||
meta: {
|
meta: {
|
||||||
needLogin: true,
|
needLogin: true,
|
||||||
premissions: [SurveyPermissions.DataManage]
|
permissions: [SurveyPermissions.DataManage]
|
||||||
},
|
},
|
||||||
component: () => import('../pages/analysis/AnalysisPage.vue')
|
component: () => import('../pages/analysis/AnalysisPage.vue')
|
||||||
},
|
},
|
||||||
@ -103,7 +103,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
name: 'publish',
|
name: 'publish',
|
||||||
meta: {
|
meta: {
|
||||||
needLogin: true,
|
needLogin: true,
|
||||||
premissions: [SurveyPermissions.SurveyManage]
|
permissions: [SurveyPermissions.SurveyManage]
|
||||||
},
|
},
|
||||||
component: () => import('../pages/publish/PublishPage.vue')
|
component: () => import('../pages/publish/PublishPage.vue')
|
||||||
},
|
},
|
||||||
@ -132,57 +132,60 @@ const router = createRouter({
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
const store = useStore()
|
const store = useStore();
|
||||||
|
// 初始化用户信息
|
||||||
if (!store.state.user?.initialized) {
|
if (!store.state.user?.initialized) {
|
||||||
store?.dispatch('user/init')
|
await store.dispatch('user/init');
|
||||||
}
|
}
|
||||||
|
// 更新页面标题
|
||||||
if (to.meta.title) {
|
if (to.meta.title) {
|
||||||
document.title = to.meta.title as string
|
document.title = to.meta.title as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (to.meta.needLogin) {
|
if (to.meta.needLogin) {
|
||||||
if (store?.state?.user?.hasLogined) {
|
await handleLoginGuard(to, from, next, store);
|
||||||
if (to.meta.premissions) {
|
} else {
|
||||||
const params = to.params
|
next();
|
||||||
await store.dispatch('fetchCooperPermissions', params.id)
|
}
|
||||||
if (
|
});
|
||||||
(to.meta.premissions as []).some((permission) =>
|
|
||||||
store.state?.cooperPermissions?.includes(permission)
|
async function handleLoginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext, store: Store<any>) {
|
||||||
)
|
if (store.state.user?.hasLogined) {
|
||||||
) {
|
await handlePermissionsGuard(to, from, next, store);
|
||||||
next()
|
} else {
|
||||||
} else {
|
next({
|
||||||
ElMessage.warning('您没有该问卷的相关协作权限')
|
name: 'login',
|
||||||
next({
|
query: { redirect: encodeURIComponent(to.path) },
|
||||||
name: 'survey'
|
});
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handlePermissionsGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext, store: Store<any>) {
|
||||||
|
const currSurveyId = to?.params?.id || ''
|
||||||
|
const prevSurveyId = from?.params?.id || ''
|
||||||
|
// 如果跳转页面不存在surveyId 或者不需要页面权限,则直接跳转
|
||||||
|
if (!to.meta.permissions || !currSurveyId) {
|
||||||
|
next()
|
||||||
|
} else {
|
||||||
|
// 如果跳转编辑页面,且跳转页面和上一页的surveyId不同,判断是否有对应页面权限
|
||||||
|
if (currSurveyId !== prevSurveyId) {
|
||||||
|
await store.dispatch('fetchCooperPermissions', currSurveyId)
|
||||||
|
if (hasRequiredPermissions(to.meta.permissions as string[], store.state.cooperPermissions)) {
|
||||||
|
next();
|
||||||
} else {
|
} else {
|
||||||
next()
|
ElMessage.warning('您没有该问卷的相关协作权限');
|
||||||
|
next({ name: 'survey' });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
next({
|
next();
|
||||||
name: 'login',
|
|
||||||
query: {
|
|
||||||
redirect: encodeURIComponent(to.path)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
function hasRequiredPermissions(requiredPermissions: string[], userPermissions: string[]) {
|
||||||
|
return requiredPermissions.some(permission => userPermissions.includes(permission));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// router.afterEach(async (to, from) => {
|
|
||||||
// const store = useStore()
|
|
||||||
// if (to.meta.premissions) {
|
|
||||||
// const params = to.params
|
|
||||||
// await store.dispatch('fetchCooperPermissions', params.id)
|
|
||||||
// if (!(to.meta.premissions as []).some((permission) => store.state?.cooperPermissions?.includes(permission))) {
|
|
||||||
// ElMessage.warning('您没有该问卷的相关协作权限')
|
|
||||||
// router.push({
|
|
||||||
// name: 'survey'
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
export default router
|
export default router
|
||||||
|
@ -14,7 +14,6 @@ export default {
|
|||||||
},
|
},
|
||||||
async fetchCooperPermissions({ commit }, id) {
|
async fetchCooperPermissions({ commit }, id) {
|
||||||
const res = await getCollaboratorPermissions(id)
|
const res = await getCollaboratorPermissions(id)
|
||||||
console.log(res.data)
|
|
||||||
if (res.code === CODE_MAP.SUCCESS) {
|
if (res.code === CODE_MAP.SUCCESS) {
|
||||||
commit('setCooperPermissions', res.data.permissions)
|
commit('setCooperPermissions', res.data.permissions)
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,6 @@ const emit = defineEmits(['addOther', 'optionChange', 'change'])
|
|||||||
const moduleConfig = inject('moduleConfig')
|
const moduleConfig = inject('moduleConfig')
|
||||||
const optionConfigVisible = ref(false)
|
const optionConfigVisible = ref(false)
|
||||||
const openOptionConfig = () => {
|
const openOptionConfig = () => {
|
||||||
console.log('open')
|
|
||||||
optionConfigVisible.value = true
|
optionConfigVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,8 @@
|
|||||||
<div v-for="item in renderData" :key="item.field">
|
<div v-for="item in renderData" :key="item.field">
|
||||||
<QuestionWrapper
|
<QuestionWrapper
|
||||||
class="gap"
|
class="gap"
|
||||||
v-bind="$attrs"
|
|
||||||
:moduleConfig="item"
|
:moduleConfig="item"
|
||||||
:qIndex="item.qIndex"
|
|
||||||
:indexNumber="item.indexNumber"
|
:indexNumber="item.indexNumber"
|
||||||
:showTitle="true"
|
|
||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
></QuestionWrapper>
|
></QuestionWrapper>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<QuestionRuleContainer
|
<QuestionRuleContainer
|
||||||
v-if="visible"
|
v-if="visible"
|
||||||
v-bind="$attrs"
|
|
||||||
:moduleConfig="questionConfig"
|
:moduleConfig="questionConfig"
|
||||||
:indexNumber="indexNumber"
|
:indexNumber="indexNumber"
|
||||||
:showTitle="true"
|
:showTitle="true"
|
||||||
|
@ -102,7 +102,6 @@ const submitSurver = async () => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const params = normalizationRequestBody()
|
const params = normalizationRequestBody()
|
||||||
console.log(params)
|
|
||||||
const res: any = await submitForm(params)
|
const res: any = await submitForm(params)
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
store.commit('setRouter', 'successPage')
|
store.commit('setRouter', 'successPage')
|
||||||
|
@ -10,7 +10,6 @@ export default {
|
|||||||
const questionArr = []
|
const questionArr = []
|
||||||
|
|
||||||
item.forEach((questionKey) => {
|
item.forEach((questionKey) => {
|
||||||
console.log('题目重新计算')
|
|
||||||
const question = { ...questionData[questionKey] }
|
const question = { ...questionData[questionKey] }
|
||||||
// 开启显示序号
|
// 开启显示序号
|
||||||
if (question.showIndex) {
|
if (question.showIndex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user