update: 应用管理添加集成菜单弹窗、cardbox组件添加遮罩层

This commit is contained in:
easy 2023-02-27 17:49:40 +08:00
parent c24be85601
commit 72c72888df
8 changed files with 323 additions and 96 deletions

View File

@ -18,3 +18,16 @@ export const getAppInfo_api = (id:string) => server.get(`/application/${id}`);
export const addApp_api = (data: object) => server.post(`/application`, data);
// 更新应用
export const updateApp_api = (id: string, data: object) => server.put(`/application/${id}`, data);
// ---------集成菜单-----------
// 获取所属系统
export const getOwner_api = (data: object) => server.post(`/menu/owner`, data);
export const getOwnerStandalone_api = (appId: string, data: object) => server.post(`/application/${appId}/_/api/menu/owner`, data);
// 获取对应系统菜单树
export const getOwnerTree_api = (owner: string) => server.post(`/menu/owner/tree/${owner}`, {});
export const getOwnerTreeStandalone_api = (appId: string, owner: string) => server.post(`/application/${appId}/_/api/menu/owner/tree/${owner}`, {});
// 保存集成菜单
export const saveOwnerMenu_api = (owner: string, appId: string, data: object) => server.patch(`/menu/owner/${owner}/${appId}/_all`, data);

View File

@ -40,11 +40,19 @@
</div>
</div>
</div>
<div class="card-mask" v-if="props.hasMark">
<div class="mask-content">
<slot name="mark" />
</div>
</div>
</div>
<!-- 按钮 -->
<slot name="bottom-tool">
<div v-if="showTool && actions && actions.length" class="card-tools">
<div
v-if="showTool && actions && actions.length"
class="card-tools"
>
<div
v-for="item in actions"
:key="item.key"
@ -79,10 +87,14 @@
</template>
<script setup lang="ts">
import { SearchOutlined, CheckOutlined, DeleteOutlined } from '@ant-design/icons-vue';
import {
SearchOutlined,
CheckOutlined,
DeleteOutlined,
} from '@ant-design/icons-vue';
import BadgeStatus from '@/components/BadgeStatus/index.vue';
import { StatusColorEnum } from '@/utils/consts.ts';
import type { ActionsType } from '@/components/Table/index.vue'
import type { ActionsType } from '@/components/Table/index.vue';
import { PropType } from 'vue';
type EmitProps = {
@ -90,14 +102,14 @@ type EmitProps = {
(e: 'click', data: Record<string, any>): void;
};
type TableActionsType = Partial<ActionsType>
type TableActionsType = Partial<ActionsType>;
const emit = defineEmits<EmitProps>();
const props = defineProps({
value: {
type: Object as PropType<Record<string, any>>,
default: () => {}
default: () => {},
},
showStatus: {
type: Boolean,
@ -124,8 +136,12 @@ const props = defineProps({
},
active: {
type: Boolean,
default: false
}
default: false,
},
hasMark: {
type: Boolean,
default: false,
},
});
const handleClick = () => {
@ -167,9 +183,13 @@ const handleClick = () => {
position: relative;
border: 1px solid #e6e6e6;
&.hover {
&:hover {
cursor: pointer;
box-shadow: 0 0 24px rgba(#000, 0.1);
.card-mask {
visibility: visible;
}
}
&.active {
@ -269,12 +289,12 @@ const handleClick = () => {
width: 100%;
height: 100%;
color: #fff;
background-color: rgba(#000, 0);
background-color: rgba(#000, .5);
visibility: hidden;
cursor: pointer;
transition: all 0.3s;
> div {
.mask-content {
display: flex;
align-items: center;
justify-content: center;
@ -282,11 +302,6 @@ const handleClick = () => {
height: 100%;
padding: 0 !important;
}
&.show {
background-color: rgba(#000, 0.5);
visibility: visible;
}
}
}

View File

@ -710,6 +710,7 @@
<a-select
v-model:value="form.data.apiServer.roleIdList"
:options="form.roleIdList"
mode="multiple"
placeholder="请选中角色"
></a-select>
<PermissionButton
@ -869,7 +870,7 @@
'sso',
'configuration',
'oauth2',
'client_id',
'clientId',
]"
:rules="[
{
@ -1003,7 +1004,6 @@
v-model:file-list="form.fileList"
accept=".jpg,.png,.jfif,.pjp,.pjpeg,.jpeg"
:maxCount="1"
name="avatar"
list-type="picture-card"
:show-upload-list="false"
:headers="{
@ -1022,6 +1022,7 @@
.logoUrl
"
alt="avatar"
width="100%"
/>
<div v-else>
<AIcon
@ -1295,6 +1296,7 @@
<a-form-item label="角色">
<a-select
v-model:value="form.data.sso.roleIdList"
mode="multiple"
:options="form.roleIdList"
placeholder="请选中角色"
></a-select>
@ -1372,7 +1374,10 @@
</a-button>
<div class="dialog">
<MenuDialog ref="dialogRef" />
<MenuDialog
ref="dialogRef"
:mode="routeQuery.id ? 'edit' : 'add'"
/>
</div>
</div>
</template>
@ -1389,7 +1394,7 @@ import {
} from '@/api/system/apply';
import FormLabel from './FormLabel.vue';
import RequestTable from './RequestTable.vue';
import MenuDialog from './MenuDialog.vue';
import MenuDialog from '../../componenets/MenuDialog.vue';
import { getImage } from '@/utils/comm';
import type { formType, dictType, optionsType } from '../typing';
import { getRoleList_api } from '@/api/system/user';
@ -1400,32 +1405,34 @@ import {
UploadFile,
} from 'ant-design-vue';
import { randomString } from '@/utils/utils';
import { cloneDeep } from 'lodash';
import { cloneDeep, difference } from 'lodash';
import { useMenuStore } from '@/store/menu';
const emit = defineEmits(['changeApplyType']);
const routeQuery = useRoute().query;
const menuStory = useMenuStore();
const deptPermission = 'system/Department';
const rolePermission = 'system/Role';
const dialogRef = ref();
//
const initForm: formType = {
name: '',
provider: 'internal-standalone',
integrationModes: [],
config: '',
description: '',
page: {
//
baseUrl: '',
routeType: 'hash',
parameters: [{ label: '', value: '' }],
parameters: [],
},
apiClient: {
// API
baseUrl: '',
headers: [{ label: '', value: '' }], //
parameters: [{ label: '', value: '' }], //
headers: [], //
parameters: [], //
authConfig: {
// API
type: 'oauth2', // , none, bearer, oauth2, basic, other
@ -1447,13 +1454,12 @@ const initForm: formType = {
},
apiServer: {
// API
appId: '',
appId: randomString(16),
secureKey: randomString(), //
redirectUri: '', // URL
roleIdList: [], //
orgIdList: [], //
ipWhiteList: '', // IP
signature: '', // , MD5SHA256
enableOAuth2: false, // OAuth2
},
sso: {
@ -1497,9 +1503,9 @@ const initForm: formType = {
const formRef = ref<FormInstance>();
const form = reactive({
data: { ...initForm },
integrationModesISO: [] as string[],
roleIdList: [] as optionsType,
orgIdList: [] as dictType,
integrationModesISO: [] as string[], // 使
roleIdList: [] as optionsType, //
orgIdList: [] as dictType, //
errorNumInfo: {
page: new Set(),
@ -1509,7 +1515,6 @@ const form = reactive({
},
fileList: [] as any[],
fileUrlList: [] as string[],
uploadLoading: false,
});
//
@ -1591,6 +1596,7 @@ function init() {
() => form.data.provider,
(n) => {
emit('changeApplyType', n);
if (routeQuery.id) return;
if (n === 'wechat-webapp' || n === 'dingtalk-ent-app') {
form.data.integrationModes = ['ssoClient'];
form.integrationModesISO = ['ssoClient'];
@ -1616,6 +1622,7 @@ function getInfo(id: string) {
(item: any) => item.value,
),
} as formType;
form.data.apiServer && (form.data.apiServer.appId = id);
});
}
//
@ -1651,6 +1658,23 @@ function clickAddItem(data: string[], target: string) {
function clickSave() {
formRef.value?.validate().then(() => {
const params = cloneDeep(form.data);
//
const list = ['page', 'apiClient', 'apiServer', 'ssoClient'];
difference(list, params.integrationModes).forEach((item) => {
if (item === 'ssoClient') {
// @ts-ignore
delete params['sso'];
}
delete params[item];
});
clearNullProp(params);
if (
params.provider === 'internal-standalone' &&
params.integrationModes.includes('page')
) {
// @ts-ignore
delete params.page.parameters;
}
if (
params.provider === 'internal-standalone' &&
@ -1674,15 +1698,19 @@ function clickSave() {
const request = routeQuery.id
? updateApp_api(routeQuery.id as string, params)
: addApp_api(params);
request.then((resp) => {
request.then((resp: any) => {
if (resp.status === 200) {
const isPage = params.integrationModes.includes('page');
if (isPage) {
form.data = params;
dialogRef.value && dialogRef.value.openDialog();
dialogRef.value &&
dialogRef.value.openDialog(
routeQuery.id || resp.result.id,
form.data.provider,
);
} else {
message.success('保存成功');
jumpPage('system/Apply');
menuStory.jumpPage('system/Apply');
}
}
});
@ -1722,9 +1750,15 @@ function changeBackUpload(info: UploadChangeParam<UploadFile<any>>) {
function test(...args: any[]) {
console.log('test:', args);
}
function jumpPage(arg0: string) {
throw new Error('Function not implemented.');
function clearNullProp(obj: object) {
if (typeof obj !== 'object') return;
for (const prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
const val = obj[prop];
if (val === '') delete obj[prop];
else if (typeof val === 'object') clearNullProp(obj[prop]);
}
}
}
</script>

View File

@ -1,49 +0,0 @@
<template>
<a-modal
v-model:visible="dialog.visible"
title="集成菜单"
width="600px"
@ok="dialog.handleOk"
class="edit-dialog-container"
:confirmLoading="dialog.loading"
cancelText="取消"
okText="确定"
>
</a-modal>
</template>
<script setup lang="ts">
const emits = defineEmits(['confirm']);
//
const dialog = reactive({
visible: false,
loading: false,
handleOk: () => {
emits('confirm');
},
/**
* 设置表单类型
* @param type 弹窗类型
* @param defaultForm 表单回显对象
*/
changeVisible: () => {
dialog.visible = true;
}
});
//
defineExpose({
openDialog: dialog.changeVisible,
});
</script>
<style scoped>
</style>

View File

@ -88,6 +88,7 @@ const tableData = computed(() => {
return props.value.slice((current.value - 1) * 10, current.value * 10);
});
if(props.value.length < 1) addRow()
watch(
() => props.value,
(n, o) => {

View File

@ -19,7 +19,7 @@ export type formType = {
name: string;
provider: applyType;
integrationModes: string[];
config: string;
config?: string;
description: string;
page: { // 页面集成
baseUrl: string,
@ -54,7 +54,7 @@ export type formType = {
roleIdList: string[], // 角色列表
orgIdList: string[], // 部门列表
ipWhiteList: string, // IP白名单
signature: 'MD5' | 'SHA256' | '', // 签名方式, 可选值MD5SHA256
signature?: 'MD5' | 'SHA256' | '', // 签名方式, 可选值MD5SHA256
enableOAuth2: boolean, // 是否启用OAuth2
},
sso: { // 统一单点登陆集成

View File

@ -0,0 +1,196 @@
<template>
<a-modal
v-model:visible="dialog.visible"
title="集成菜单"
width="600px"
@ok="dialog.handleOk"
@cancel="dialog.cancel"
class="edit-dialog-container"
:confirmLoading="dialog.loading"
cancelText="取消"
okText="确定"
>
<a-select
v-model:value="form.checkedSystem"
@change="(value) => value && getTree(value as string)"
style="width: 200px"
placeholder="请选择集成系统"
>
<a-select-option
v-for="item in form.systemList"
:value="item.value"
>{{ item.label }}</a-select-option
>
</a-select>
<p style="margin: 20px 0 0 0" v-show="form.menuTree.length > 0">当前集成菜单</p>
<a-tree
v-model:checkedKeys="form.checkedMenu"
v-model:expandedKeys="form.expandedKeys"
checkable
:tree-data="form.menuTree"
:fieldNames="{ key: 'id', title: 'name' }"
@check="treeCheck"
>
<template #title="{ name }">
<span>{{ name }}</span>
</template>
</a-tree>
</a-modal>
</template>
<script setup lang="ts">
import { optionItemType } from '@/views/system/DataSource/typing';
import { applyType } from '../Save/typing';
import {
getOwner_api,
getOwnerStandalone_api,
getOwnerTree_api,
getOwnerTreeStandalone_api,
saveOwnerMenu_api,
} from '@/api/system/apply';
import { CheckInfo } from 'ant-design-vue/lib/vc-tree/props';
import { useMenuStore } from '@/store/menu';
import { message } from 'ant-design-vue';
import { getMenuTree_api } from '@/api/system/menu';
const menuStory = useMenuStore();
const props = defineProps<{
mode: 'add' | 'edit';
}>();
//
const dialog = reactive({
visible: false,
loading: false,
handleOk: () => {
const items = filterTree(form.menuTree, [
...form.checkedMenu,
...form.half,
]);
if (form.checkedSystem) {
if (items && items.length !== 0) {
saveOwnerMenu_api('iot', form.id, items).then((resp) => {
if (resp.status === 200) {
message.success('操作成功');
dialog.visible = false;
}
});
} else {
message.warning('请勾选配置菜单');
}
} else {
message.warning('请选择所属系统');
}
},
cancel: () => {
if (props.mode === 'add')
menuStory.jumpPage('system/Apply/Save', {}, { id: form.id });
dialog.visible = false;
},
changeVisible: (id: string, provider: applyType) => {
form.id = id;
form.provider = provider;
form.checkedSystem = undefined;
form.checkedMenu = [];
dialog.visible = true;
if (id) {
getSystemList();
getMenus();
}
},
});
//
defineExpose({
openDialog: dialog.changeVisible,
});
const form = reactive({
id: '',
checkedSystem: '' as undefined | string,
checkedMenu: [] as string[],
expandedKeys: [] as string[],
half: [] as string[],
provider: '' as applyType,
systemList: [] as optionItemType[],
menuTree: [] as any[],
});
/**
* 与集成系统关联的菜单
* @param params
*/
function getTree(params: string) {
const api =
form.provider === 'internal-standalone'
? getOwnerTreeStandalone_api(form.id, params)
: getOwnerTree_api(params);
api.then((resp: any) => {
form.menuTree = resp.result;
form.expandedKeys = resp.result.map((item: any) => item.id);
});
}
/**
* 获取当前用户可访问菜单
*/
function getMenus() {
const params = {
terms: [
{
column: 'appId',
value: form.id,
},
],
};
getMenuTree_api(params).then((resp: any) => {
if (resp.status === 200) {
form.menuTree = resp.result;
const keys = resp.result.map((item: any) => item.id) as string[];
form.expandedKeys = keys;
form.checkedMenu = keys;
}
});
}
/**
* 获取集成系统选项
*/
function getSystemList() {
const api =
form.provider === 'internal-standalone'
? getOwnerStandalone_api(form.id, ['iot'])
: getOwner_api(['iot']);
api.then((resp: any) => {
if (resp.status === 200) {
form.systemList = resp.result.map((item: string) => ({
label: item,
value: item,
}));
}
});
}
//
function treeCheck(checkedKeys: any, e: CheckInfo) {
form.checkedMenu = checkedKeys;
form.half = e.halfCheckedKeys as string[];
}
//-
function filterTree(nodes: any[], list: any[]) {
if (!nodes?.length) {
return nodes;
}
return nodes.filter((it) => {
//
if (list.indexOf(it.id) <= -1) {
return false;
}
//
it.children = filterTree(it.children, list);
return true;
});
}
</script>
<style scoped></style>

View File

@ -42,6 +42,7 @@
enabled: 'success',
disabled: 'error',
}"
hasMark
>
<template #img>
<slot name="img">
@ -118,6 +119,14 @@
</PermissionButton>
</a-tooltip>
</template>
<template #mark>
<AIcon
type="EyeOutlined"
style="font-size: 24px"
@click="() => table.toSave(slotProps.id, true)"
/>
</template>
</CardBox>
</template>
@ -151,11 +160,15 @@
</template>
</JTable>
</div>
<div class="dialogs">
<MenuDialog ref="dialogRef" mode="edit" />
</div>
</page-container>
</template>
<script setup lang="ts" name="Apply">
import PermissionButton from '@/components/PermissionButton/index.vue';
import MenuDialog from './componenets/MenuDialog.vue';
import {
getApplyList_api,
changeApplyStatus_api,
@ -254,6 +267,7 @@ const params = ref({});
const search = (newParams: any) => (params.value = { ...newParams });
const tableRef = ref();
const dialogRef = ref();
const table = {
refresh: () => {
tableRef.value.reload();
@ -344,7 +358,10 @@ const table = {
title: '集成菜单',
},
icon: 'MenuUnfoldOutlined',
onClick: () => {},
onClick: () => {
dialogRef.value &&
dialogRef.value.openDialog(data.id, data.provider);
},
});
// api
if (otherServers.includes('apiServer'))