Skip to content

Commit fb0d5b0

Browse files
feat: api
1 parent 6f2f4d9 commit fb0d5b0

File tree

5 files changed

+213
-69
lines changed

5 files changed

+213
-69
lines changed

ui/src/api/user/resource-authorization.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import { get, put, post, del } from '@/request/index'
33
import type { pageRequest } from '@/api/type/common'
44
import type { Ref } from 'vue'
55

6-
const prefix = '/workspace'
6+
const prefix = '/workspace/' + localStorage.getItem('workspace_id')
77

88
/**
99
* 获取成员列表
1010
* @query 参数
1111
*/
12-
const getUserList: (workspace_id: String) => Promise<Result<any>> = (workspace_id) => {
13-
return get(`${prefix}/${workspace_id}/user_list`)
12+
const getUserList: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
13+
return get(`${prefix}/user_list`, undefined, loading)
1414
}
1515

1616
/**
1717
* 获取资源权限
1818
* @query 参数
1919
*/
20-
const getResourceAuthorization: (workspace_id: String, user_id: string) => Promise<Result<any>> = (
21-
workspace_id,
22-
user_id,
23-
) => {
24-
return get(`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`)
20+
const getResourceAuthorization: (
21+
user_id: string,
22+
loading?: Ref<boolean>,
23+
) => Promise<Result<any>> = (user_id, loading) => {
24+
return get(`${prefix}/user_resource_permission/user/${user_id}`, undefined, loading)
2525
}
2626

2727
/**
@@ -43,11 +43,11 @@ const getResourceAuthorization: (workspace_id: String, user_id: string) => Promi
4343
}
4444
*/
4545
const putResourceAuthorization: (
46-
workspace_id: String,
4746
user_id: string,
4847
body: any,
49-
) => Promise<Result<any>> = (workspace_id, user_id, body) => {
50-
return put(`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`, body)
48+
loading?: Ref<boolean>,
49+
) => Promise<Result<any>> = (user_id, body, loading) => {
50+
return put(`${prefix}/user_resource_permission/user/${user_id}`, body, loading)
5151
}
5252

5353
export default {
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<template>
2+
<div :id="id" ref="PieChartRef" :style="{ height: height, width: width }" />
3+
</template>
4+
<script lang="ts" setup>
5+
import { onMounted, nextTick, watch, onBeforeUnmount } from 'vue'
6+
import * as echarts from 'echarts'
7+
import { numberFormat } from '@/utils/utils'
8+
const props = defineProps({
9+
id: {
10+
type: String,
11+
default: 'lineChartId'
12+
},
13+
width: {
14+
type: String,
15+
default: '100%'
16+
},
17+
height: {
18+
type: String,
19+
default: '200px'
20+
},
21+
option: {
22+
type: Object,
23+
required: true
24+
} // option: { title , data }
25+
})
26+
27+
const color = ['rgba(82, 133, 255, 1)', 'rgba(255, 207, 47, 1)']
28+
29+
const areaColor = ['rgba(82, 133, 255, 0.2)', 'rgba(255, 207, 47, 0.2)']
30+
31+
function initChart() {
32+
let myChart = echarts?.getInstanceByDom(document.getElementById(props.id)!)
33+
if (myChart === null || myChart === undefined) {
34+
myChart = echarts.init(document.getElementById(props.id))
35+
}
36+
const series: any = []
37+
if (props.option?.yData?.length) {
38+
props.option?.yData.forEach((item: any, index: number) => {
39+
series.push({
40+
itemStyle: {
41+
color: color[index]
42+
},
43+
areaStyle: item.area
44+
? {
45+
color: areaColor[index]
46+
}
47+
: null,
48+
...item
49+
})
50+
})
51+
}
52+
const option = {
53+
title: {
54+
text: props.option?.title,
55+
textStyle: {
56+
fontSize: '16px'
57+
}
58+
},
59+
tooltip: {
60+
trigger: 'axis',
61+
valueFormatter: (value: any) => numberFormat(value)
62+
// axisPointer: {
63+
// type: 'cross',
64+
// label: {
65+
// backgroundColor: '#6a7985'
66+
// }
67+
// }
68+
},
69+
legend: {
70+
right: 0,
71+
itemWidth: 8,
72+
textStyle: {
73+
color: '#646A73'
74+
},
75+
icon: 'circle'
76+
},
77+
grid: {
78+
left: '1%',
79+
right: '1%',
80+
bottom: '0',
81+
top: '18%',
82+
containLabel: true
83+
},
84+
xAxis: {
85+
type: 'category',
86+
data: props.option.xData
87+
},
88+
yAxis: {
89+
type: 'value',
90+
splitLine: {
91+
lineStyle: {
92+
color: '#EFF0F1'
93+
}
94+
},
95+
axisLabel: {
96+
formatter: (value: any) => {
97+
return numberFormat(value)
98+
}
99+
}
100+
},
101+
series: series
102+
}
103+
104+
// 渲染数据
105+
myChart.setOption(option, true)
106+
}
107+
108+
function changeChartSize() {
109+
echarts.getInstanceByDom(document.getElementById(props.id)!)?.resize()
110+
}
111+
112+
watch(
113+
() => props.option,
114+
(val) => {
115+
if (val) {
116+
nextTick(() => {
117+
initChart()
118+
})
119+
}
120+
}
121+
)
122+
123+
onMounted(() => {
124+
nextTick(() => {
125+
initChart()
126+
window.addEventListener('resize', changeChartSize)
127+
})
128+
})
129+
130+
onBeforeUnmount(() => {
131+
echarts.getInstanceByDom(document.getElementById(props.id)!)?.dispose()
132+
window.removeEventListener('resize', changeChartSize)
133+
})
134+
</script>
135+
<style lang="scss" scoped></style>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<component
3+
:is="typeComponentMap[type]"
4+
:height="height"
5+
:option="option"
6+
:dataZoom="dataZoom"
7+
class="v-charts"
8+
/>
9+
</template>
10+
<script lang="ts" setup>
11+
import line from './components/LineCharts.vue'
12+
defineOptions({ name: 'AppCharts' })
13+
defineProps({
14+
type: {
15+
type: String,
16+
default: 'line'
17+
},
18+
height: {
19+
type: String,
20+
default: '200px'
21+
},
22+
dataZoom: Boolean,
23+
option: {
24+
type: Object,
25+
required: true
26+
} // { title , xData, yData, formatStr }
27+
})
28+
29+
const typeComponentMap = { line } as any
30+
</script>

ui/src/views/resource-authorization/component/CreateMemberDialog.vue

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
@submit.prevent
2222
>
2323
<el-form-item :label="$t('views.team.teamForm.form.userName.label')" prop="users">
24-
<tags-input v-model:tags="memberForm.users" :placeholder="$t('views.team.teamForm.form.userName.placeholder')" />
24+
<tags-input
25+
v-model:tags="memberForm.users"
26+
:placeholder="$t('views.team.teamForm.form.userName.placeholder')"
27+
/>
2528
</el-form-item>
2629
</el-form>
2730
<template #footer>
@@ -45,7 +48,7 @@ const emit = defineEmits(['refresh'])
4548
const dialogVisible = ref<boolean>(false)
4649
4750
const memberForm = ref({
48-
users: []
51+
users: [],
4952
})
5053
5154
const addMemberFormRef = ref<FormInstance>()
@@ -58,15 +61,15 @@ const rules = ref<FormRules>({
5861
type: 'array',
5962
required: true,
6063
message: t('views.team.teamForm.form.userName.requiredMessage'),
61-
trigger: 'change'
62-
}
63-
]
64+
trigger: 'change',
65+
},
66+
],
6467
})
6568
6669
watch(dialogVisible, (bool) => {
6770
if (!bool) {
6871
memberForm.value = {
69-
users: []
72+
users: [],
7073
}
7174
loading.value = false
7275
}
@@ -79,18 +82,12 @@ const submitMember = async (formEl: FormInstance | undefined) => {
7982
if (!formEl) return
8083
await formEl.validate((valid, fields) => {
8184
if (valid) {
82-
loading.value = true
8385
let idsArray = memberForm.value.users.map((obj: any) => obj.id)
84-
AuthorizationApi.postCreatTeamMember(idsArray)
85-
.then((res) => {
86-
MsgSuccess(t('common.submitSuccess'))
87-
emit('refresh', idsArray)
88-
dialogVisible.value = false
89-
loading.value = false
90-
})
91-
.catch(() => {
92-
loading.value = false
93-
})
86+
AuthorizationApi.postCreatTeamMember(idsArray, loading).then((res) => {
87+
MsgSuccess(t('common.submitSuccess'))
88+
emit('refresh', idsArray)
89+
dialogVisible.value = false
90+
})
9491
}
9592
})
9693
}

ui/src/views/resource-authorization/index.vue

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const memberList = ref<any[]>([]) // 全部成员
8080
const filterMember = ref<any[]>([]) // 搜索过滤后列表
8181
const currentUser = ref<string>('')
8282
const currentType = ref<string>('')
83-
const workspace_id = ref<string>('default')
8483
const filterText = ref('')
8584
8685
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
@@ -114,7 +113,6 @@ function isManage(type: String) {
114113
}
115114
116115
function submitPermissions() {
117-
rLoading.value = true
118116
const obj: any = {
119117
user_resource_permission_list: [],
120118
}
@@ -128,55 +126,39 @@ function submitPermissions() {
128126
})
129127
})
130128
})
131-
AuthorizationApi.putResourceAuthorization(workspace_id.value, currentUser.value, obj)
132-
.then(() => {
133-
MsgSuccess(t('common.submitSuccess'))
134-
ResourcePermissions(workspace_id.value, currentUser.value)
135-
})
136-
.catch(() => {
137-
rLoading.value = false
138-
})
129+
AuthorizationApi.putResourceAuthorization(currentUser.value, obj, rLoading).then(() => {
130+
MsgSuccess(t('common.submitSuccess'))
131+
ResourcePermissions(currentUser.value)
132+
})
139133
}
140134
141135
function clickMemberHandle(item: any) {
142136
currentUser.value = item.id
143137
currentType.value = item.type
144-
ResourcePermissions(workspace_id.value, item.id)
138+
ResourcePermissions(item.id)
145139
}
146140
147141
function getMember(id?: string) {
148-
loading.value = true
149-
AuthorizationApi.getUserList(workspace_id.value)
150-
.then((res) => {
151-
memberList.value = res.data
152-
filterMember.value = res.data
142+
AuthorizationApi.getUserList(loading).then((res) => {
143+
memberList.value = res.data
144+
filterMember.value = res.data
153145
154-
const user = (id && memberList.value.find((p: any) => p.user_id === id)) || null
155-
currentUser.value = user ? user.id : memberList.value[0].id
156-
currentType.value = user ? user.type : memberList.value[0].type
157-
ResourcePermissions(workspace_id.value, currentUser.value)
158-
loading.value = false
159-
})
160-
.catch(() => {
161-
loading.value = false
162-
})
146+
const user = (id && memberList.value.find((p: any) => p.user_id === id)) || null
147+
currentUser.value = user ? user.id : memberList.value[0].id
148+
currentType.value = user ? user.type : memberList.value[0].type
149+
ResourcePermissions(currentUser.value)
150+
})
163151
}
164-
function ResourcePermissions(workspace_id: string, user_id: string) {
165-
rLoading.value = true
166-
AuthorizationApi.getResourceAuthorization(workspace_id, user_id)
167-
.then((res) => {
168-
if (!res.data || Object.keys(res.data).length > 0) {
169-
settingTags.map((item: any) => {
170-
if (Object.keys(res.data).indexOf(item.value) !== -1) {
171-
item.data = res.data[item.value]
172-
}
173-
})
174-
}
175-
rLoading.value = false
176-
})
177-
.catch(() => {
178-
rLoading.value = false
179-
})
152+
function ResourcePermissions(user_id: string) {
153+
AuthorizationApi.getResourceAuthorization(user_id, rLoading).then((res) => {
154+
if (!res.data || Object.keys(res.data).length > 0) {
155+
settingTags.map((item: any) => {
156+
if (Object.keys(res.data).indexOf(item.value) !== -1) {
157+
item.data = res.data[item.value]
158+
}
159+
})
160+
}
161+
})
180162
}
181163
182164
function refresh(data?: string[]) {}

0 commit comments

Comments
 (0)