feat(X-Pack): 第三方平台用户组织角色配置

This commit is contained in:
fit2cloud-chenyw 2024-02-29 16:27:27 +08:00
parent 927d0f783b
commit 0cac70f1bb
5 changed files with 194 additions and 8 deletions

View File

@ -2136,7 +2136,9 @@ export default {
dsIntervalTime: '数据源检测时间间隔',
dsExecuteTime: '数据源检测频率',
frontTimeOut: '请求超时时间',
logLiveTime: '日志保留时间'
logLiveTime: '日志保留时间',
platformOid: '第三方平台用户组织',
platformRid: '第三方平台用户角色'
},
template_manage: {
name_already_exists_type: '分类名称已存在',

View File

@ -18,7 +18,9 @@ const state = reactive({
dsExecuteTime: 'minute',
frontTimeOut: '30'
}),
settingList: []
settingList: [],
orgOptions: [],
roleOptions: []
})
const rule = reactive<FormRules>({
@ -36,7 +38,10 @@ const buildSettingList = () => {
const pkey = item.pkey.startsWith('basic.') ? item.pkey : `basic.${item.pkey}`
const sort = item.sort
const type = item.type
const pval = state.form[item.pkey]
let pval = state.form[item.pkey]
if (Array.isArray(pval)) {
pval = pval.join(',')
}
return { pkey, pval, type, sort }
})
}
@ -99,7 +104,9 @@ const closeLoading = () => {
loadingInstance.value?.close()
}
const edit = list => {
const edit = (list, orgOptions, roleOptions) => {
state.orgOptions = orgOptions || []
state.roleOptions = roleOptions || []
state.settingList = list.map(item => {
const pkey = item.pkey
if (pkey === 'basic.logLiveTime') {
@ -114,11 +121,62 @@ const edit = list => {
item['label'] = `setting_${pkey}`
item['pkey'] = pkey.split('.')[1]
let pval = item.pval
if (item.pkey.includes('platformRid') && pval?.length) {
pval = pval.split(',')
if (!rule['platformRid']) {
rule['platformRid'] = [
{
required: true,
message: t('common.require'),
trigger: ['blur', 'change']
}
]
}
}
if (item.pkey.includes('platformOid')) {
if (!rule['platformOid']) {
rule['platformOid'] = [
{
required: true,
message: t('common.require'),
trigger: ['blur', 'change']
}
]
}
}
state.form[item['pkey']] = pval || state.form[item['pkey']]
return item
})
dialogVisible.value = true
}
const loadRoleOptions = async () => {
const oid = state.form['platformOid']
if (!oid) {
return
}
const res = await request.get({ url: `/role/queryWithOid/${oid}` })
const data = res.data
const map = groupBy(data)
state.roleOptions[0].children = map.get(false)
state.roleOptions[1].children = map.get(true)
}
const groupBy = list => {
const map = new Map()
list.forEach(item => {
const readonly = item.readonly
let arr = map.get(readonly)
if (!arr) {
arr = []
}
arr.push({ value: item.id, label: item.name, disabled: false })
map.set(readonly, arr)
})
return map
}
const oidChange = () => {
state.form['platformRid'] = []
loadRoleOptions()
}
defineExpose({
edit
})
@ -200,6 +258,29 @@ defineExpose({
type="number"
/>
</div>
<div v-else-if="item.pkey === 'platformOid'">
<el-tree-select
class="edit-all-line"
v-model="state.form[item.pkey]"
:data="state.orgOptions"
check-strictly
:render-after-expand="false"
@change="oidChange"
/>
</div>
<div v-else-if="item.pkey === 'platformRid'">
<el-tree-select
class="edit-all-line"
v-model="state.form[item.pkey]"
:data="state.roleOptions"
:highlight-current="true"
multiple
:render-after-expand="false"
:placeholder="$t('common.please_select') + $t('user.role')"
show-checkbox
check-on-click-node
/>
</div>
<v-else />
</el-form-item>
</el-form>

View File

@ -18,29 +18,77 @@ import request from '@/config/axios'
import { SettingRecord } from '@/views/system/common/SettingTemplate'
import { reactive } from 'vue'
import { cloneDeep } from 'lodash-es'
import { useI18n } from '@/hooks/web/useI18n'
const { t } = useI18n()
const editor = ref()
const infoTemplate = ref()
const tooltips = [
{
key: 'setting_basic.frontTimeOut',
val: '请求超时时间(单位:秒,注意:保存后刷新浏览器生效)'
},
{
key: 'setting_basic.platformOid',
val: '作用域包括认证设置和平台对接'
},
{
key: 'setting_basic.platformRid',
val: '作用域包括认证设置和平台对接'
}
]
const state = reactive({
templateList: [] as SettingRecord[]
templateList: [] as SettingRecord[],
orgOptions: [],
roleOptions: [
{
value: 'admin',
label: t('role.org_admin'),
children: null,
disabled: false
},
{
value: 'readonly',
label: t('role.average_role'),
children: null,
disabled: false
}
]
})
let originData = []
const selectedOid = ref('')
const selectedOName = ref('')
const selectedRid = ref<string[]>([])
const selectedRName = ref<string[]>([])
const search = cb => {
const url = '/sysParameter/basic/query'
originData = []
state.templateList = []
request.get({ url }).then(res => {
request.get({ url }).then(async res => {
originData = cloneDeep(res.data)
const data = res.data
for (let index = 0; index < data.length; index++) {
const item = data[index]
if (item.pkey === 'basic.autoCreateUser') {
item.pval = item.pval === 'true' ? '开启' : '未开启'
} else if (item.pkey === 'basic.platformOid') {
selectedOid.value = item.pval
await loadOrgOptions()
item.pval = selectedOName.value || '默认组织'
} else if (item.pkey === 'basic.platformRid') {
const pval = item.pval
if (pval?.length) {
const pvalArray = pval.split(',')
selectedRid.value = pvalArray
await loadRoleOptions()
if (selectedRName.value.length) {
item.pval = selectedRName.value.join(',')
} else {
item.pval = '普通角色'
}
} else {
selectedRid.value = []
item.pval = '普通角色'
}
} else {
item.pval = item.pval
}
@ -58,6 +106,56 @@ const refresh = () => {
refresh()
const edit = () => {
editor?.value.edit(cloneDeep(originData))
editor?.value.edit(
cloneDeep(originData),
cloneDeep(state.orgOptions),
cloneDeep(state.roleOptions)
)
}
const loadOrgOptions = async () => {
const res = await request.post({ url: '/org/mounted', data: {} })
const data = res.data
formatOrg(data)
state.orgOptions = data
}
const loadRoleOptions = async () => {
const res = await request.get({ url: `/role/queryWithOid/${selectedOid.value}` })
const data = res.data
const map = groupBy(data)
state.roleOptions[0].children = map.get(false)
state.roleOptions[1].children = map.get(true)
}
const formatOrg = list => {
const stack = [...list]
while (stack.length) {
const item = stack.pop()
if (item.id === selectedOid.value) {
selectedOName.value = item.name
}
item.value = item.id
item.label = item.name
item.disabled = item.readOnly
if (item.children?.length) {
item.children.forEach(kid => stack.push(kid))
}
}
}
const groupBy = list => {
const map = new Map()
selectedRName.value = []
list.forEach(item => {
if (selectedRid.value.includes(item.id)) {
selectedRName.value.push(item.name)
}
const readonly = item.readonly
let arr = map.get(readonly)
if (!arr) {
arr = []
}
arr.push({ value: item.id, label: item.name, disabled: false })
map.set(readonly, arr)
})
return map
}
</script>

@ -1 +1 @@
Subproject commit d9d2d9a8a9eb67c4d3c68027d80fb4c5459c5c25
Subproject commit 82a7623b95f46e9f5b4bc7f58b50b29f2f0f0d05

View File

@ -8,6 +8,7 @@ import io.dataease.api.permissions.role.vo.RoleVO;
import io.dataease.auth.DeApiPath;
import io.dataease.auth.DePermit;
import io.dataease.model.KeywordRequest;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@ -90,4 +91,8 @@ public interface RoleApi {
@Operation(summary = "查询组织内角色")
@PostMapping("/byCurOrg")
List<RoleVO> byCurOrg(@RequestBody KeywordRequest request);
@Hidden
@GetMapping("/queryWithOid/{oid}")
List<RoleVO> queryWithOid(@PathVariable("oid") Long oid);
}