mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 18:46:36 +08:00
commit:升级到vue3,更新最近工作流技术栈,支持sa-token
This commit is contained in:
10
OrangeFormsOpen-VUE3/src/store/index.ts
Normal file
10
OrangeFormsOpen-VUE3/src/store/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { createPinia } from 'pinia';
|
||||
import piniaPersist from 'pinia-plugin-persist';
|
||||
import useLoginStore from './login';
|
||||
import useLayoutStore from './layout';
|
||||
import useOtherStore from './other';
|
||||
import useMessage from './message';
|
||||
const pinia = createPinia();
|
||||
pinia?.use(piniaPersist);
|
||||
export { useLoginStore, useLayoutStore, useMessage, useOtherStore };
|
||||
export default pinia;
|
||||
159
OrangeFormsOpen-VUE3/src/store/layout.ts
Normal file
159
OrangeFormsOpen-VUE3/src/store/layout.ts
Normal file
@@ -0,0 +1,159 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import type { ComponentSize } from 'element-plus';
|
||||
import type { MenuItem } from '@/types/upms/menu';
|
||||
import { findItemFromList } from '@/common/utils';
|
||||
import { ANY_OBJECT } from '@/types/generic';
|
||||
import { processMenu, findMenuItem, findMenuItemById } from './utils';
|
||||
|
||||
export default defineStore('layout', {
|
||||
state: () => {
|
||||
return {
|
||||
// 首页路由名称
|
||||
indexName: 'welcome',
|
||||
// 侧边栏是否折叠
|
||||
collapsed: false,
|
||||
// 是否多栏目
|
||||
supportColumn: false,
|
||||
// 是否多标签
|
||||
supportTags: true,
|
||||
// 标签列表
|
||||
tagList: new Array<MenuItem>(),
|
||||
// 菜单列表
|
||||
menuList: new Array<MenuItem>(),
|
||||
// 页面缓存列表
|
||||
cachePages: new Array<string>(),
|
||||
// 当前菜单
|
||||
currentMenu: {} as MenuItem,
|
||||
// 当前栏目
|
||||
currentColumn: {} as MenuItem,
|
||||
// 当前formSize
|
||||
defaultFormItemSize: 'default' as ComponentSize,
|
||||
documentClientHeight: 200,
|
||||
mainContextHeight: 200,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
currentMenuPath(): Array<MenuItem> {
|
||||
const menuPath: Array<MenuItem> = [];
|
||||
this.menuList.forEach(menu => {
|
||||
findMenuItem(menu, this.currentMenu.menuId, menuPath);
|
||||
});
|
||||
return menuPath;
|
||||
},
|
||||
currentMenuId(): string {
|
||||
return this.currentMenu.menuId;
|
||||
},
|
||||
currentColumnId(): string {
|
||||
return this.currentColumn.menuId;
|
||||
},
|
||||
currentFormSize(): string {
|
||||
return this.defaultFormItemSize;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setCollapsed(val: boolean) {
|
||||
this.collapsed = val;
|
||||
},
|
||||
toggleCollapsed() {
|
||||
this.collapsed = !this.collapsed;
|
||||
},
|
||||
setMenuList(menuList: Array<MenuItem>) {
|
||||
menuList.forEach(item => {
|
||||
processMenu(item);
|
||||
});
|
||||
this.menuList = menuList;
|
||||
if (this.supportColumn && menuList && menuList.length) {
|
||||
this.currentColumn = menuList[0];
|
||||
}
|
||||
},
|
||||
setCurrentMenu(menu: MenuItem | null) {
|
||||
if (menu == null || menu.menuId == null) {
|
||||
this.currentMenu = {} as MenuItem;
|
||||
} else {
|
||||
this.currentMenu = menu;
|
||||
// 添加标签:标签列表中不存在时添加到标签列表中
|
||||
if (this.supportTags) {
|
||||
const item: ANY_OBJECT | null = findItemFromList(this.tagList, menu.menuId, 'menuId');
|
||||
if (item == null) {
|
||||
this.tagList.push(menu);
|
||||
}
|
||||
// 添加页面缓存
|
||||
if (menu.formRouterName && this.cachePages.indexOf(menu.formRouterName) === -1) {
|
||||
this.cachePages.push(menu.formRouterName);
|
||||
}
|
||||
}
|
||||
// 设置当前栏目
|
||||
if (this.supportColumn) {
|
||||
for (const m of this.menuList) {
|
||||
if (m.children) {
|
||||
const item = findMenuItemById(menu.menuId, m.children);
|
||||
if (item && this.currentColumn.menuId != m.menuId) {
|
||||
this.currentColumn = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
removeTag(id: string) {
|
||||
let pos = -1;
|
||||
for (let i = 0; i < this.tagList.length; i++) {
|
||||
if (this.tagList[i].menuId == id) {
|
||||
this.tagList.splice(i, 1);
|
||||
pos = Math.min(i, this.tagList.length - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.currentMenuId == id) {
|
||||
this.setCurrentMenu(this.tagList[pos]);
|
||||
}
|
||||
// 移除页面缓存
|
||||
const pages = this.tagList.map(item => item.formRouterName).filter(item => item != null);
|
||||
this.cachePages = this.cachePages.filter(item => {
|
||||
return pages.indexOf(item) !== -1;
|
||||
});
|
||||
},
|
||||
closeOtherTags(id: string) {
|
||||
// 关闭其它标签
|
||||
this.tagList = this.tagList.filter(item => {
|
||||
return item.menuId === id;
|
||||
});
|
||||
const menu = this.tagList[0];
|
||||
if (menu && (menu.onlineFormId == null || menu.onlineFormId === '') && menu.formRouterName) {
|
||||
this.cachePages = [menu.formRouterName];
|
||||
this.setCurrentMenu(menu);
|
||||
}
|
||||
},
|
||||
clearAllTags() {
|
||||
// 关闭所有标签
|
||||
this.tagList = [];
|
||||
this.cachePages = [];
|
||||
this.setCurrentMenu(null);
|
||||
},
|
||||
setCurrentColumn(column: MenuItem) {
|
||||
this.currentColumn = column;
|
||||
},
|
||||
removeCachePage(name: string) {
|
||||
const pos = this.cachePages.indexOf(name);
|
||||
if (pos !== -1) {
|
||||
this.cachePages.splice(pos, 1);
|
||||
}
|
||||
},
|
||||
setCurrentFormSize(size: ComponentSize) {
|
||||
this.defaultFormItemSize = size;
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
// 开启持久存储
|
||||
enabled: true,
|
||||
// 指定哪些state的key需要进行持久存储
|
||||
// storage默认是 sessionStorage存储
|
||||
// paths需要持久存储的key
|
||||
strategies: [
|
||||
{ key: 'tags', paths: ['tagList'] },
|
||||
{ key: 'menu', paths: ['currentColumn', 'currentMenu', 'menuList'] },
|
||||
{ key: 'cachePages', paths: ['cachePages'] },
|
||||
],
|
||||
},
|
||||
});
|
||||
31
OrangeFormsOpen-VUE3/src/store/login.ts
Normal file
31
OrangeFormsOpen-VUE3/src/store/login.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { UserInfo } from '@/types/upms/user';
|
||||
import { initUserInfo } from './utils';
|
||||
|
||||
export default defineStore('login', {
|
||||
state: () => {
|
||||
return {
|
||||
token: '' as string | null,
|
||||
userInfo: {} as UserInfo | null,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
getPermCodeList(): Set<string> {
|
||||
if (this.userInfo == null) return new Set<string>();
|
||||
return new Set<string>(this.userInfo.permCodeList);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setUserInfo(info: UserInfo) {
|
||||
this.userInfo = initUserInfo(info);
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
// 开启持久存储
|
||||
enabled: true,
|
||||
// 指定哪些state的key需要进行持久存储
|
||||
// storage默认是 sessionStorage存储
|
||||
// paths需要持久存储的key
|
||||
strategies: [{ key: 'userInfo', paths: ['userInfo'] }],
|
||||
},
|
||||
});
|
||||
62
OrangeFormsOpen-VUE3/src/store/message.ts
Normal file
62
OrangeFormsOpen-VUE3/src/store/message.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ANY_OBJECT } from '@/types/generic';
|
||||
import { FlowOperationController } from '@/api/flow';
|
||||
|
||||
// 催办消息轮询间隔
|
||||
const MESSAGE_TIMER_INTERVAL = 1000 * 60 * 5;
|
||||
|
||||
export default defineStore('message', {
|
||||
state: () => {
|
||||
return {
|
||||
messageTimer: undefined as number | undefined,
|
||||
messageCount: {} as ANY_OBJECT,
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
setMessageTimer(timer: number) {
|
||||
this.messageTimer = timer;
|
||||
},
|
||||
setMessageCount(data: ANY_OBJECT) {
|
||||
//console.log('setMessageCount >>>', data);
|
||||
if (data) {
|
||||
data.totalCount = data.copyMessageCount + data.remindingMessageCount;
|
||||
}
|
||||
this.messageCount = data;
|
||||
},
|
||||
// 获得消息列表数据
|
||||
loadMessage() {
|
||||
FlowOperationController.getMessageCount(
|
||||
{},
|
||||
{
|
||||
showMask: false,
|
||||
showError: false,
|
||||
},
|
||||
)
|
||||
.then(res => {
|
||||
this.setMessageCount(res.data);
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
},
|
||||
startMessage() {
|
||||
if (this.messageTimer) {
|
||||
clearInterval(this.messageTimer);
|
||||
}
|
||||
|
||||
this.messageTimer = setInterval(() => {
|
||||
this.loadMessage();
|
||||
}, MESSAGE_TIMER_INTERVAL);
|
||||
this.loadMessage();
|
||||
},
|
||||
stopMessage() {
|
||||
if (this.messageTimer) {
|
||||
clearInterval(this.messageTimer);
|
||||
}
|
||||
this.messageTimer = undefined;
|
||||
},
|
||||
reloadMessage() {
|
||||
this.loadMessage();
|
||||
},
|
||||
},
|
||||
});
|
||||
23
OrangeFormsOpen-VUE3/src/store/other.ts
Normal file
23
OrangeFormsOpen-VUE3/src/store/other.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ANY_OBJECT } from '@/types/generic';
|
||||
|
||||
export default defineStore('other', {
|
||||
state: () => {
|
||||
return {
|
||||
userShowNameData: {
|
||||
'${startUserName}': '流程发起人',
|
||||
'${appointedAssignee}': '指定审批人',
|
||||
} as ANY_OBJECT,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
getUserShowNameData(): ANY_OBJECT {
|
||||
return this.userShowNameData;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setUserShowNameData(data: ANY_OBJECT) {
|
||||
this.userShowNameData = data;
|
||||
},
|
||||
},
|
||||
});
|
||||
109
OrangeFormsOpen-VUE3/src/store/utils/index.ts
Normal file
109
OrangeFormsOpen-VUE3/src/store/utils/index.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { UserInfo } from '@/types/upms/user';
|
||||
import { MenuItem } from '@/types/upms/menu';
|
||||
import { SysMenuBindType } from '@/common/staticDict';
|
||||
|
||||
function processMenu(item: MenuItem): void {
|
||||
if (item == null) return;
|
||||
if (item.extraData != null && item.extraData !== '') {
|
||||
const extraData = JSON.parse(item.extraData);
|
||||
delete item.extraData;
|
||||
item.bindType = extraData.bindType || item.bindType;
|
||||
item.onlineFormId = extraData.onlineFormId || item.onlineFormId;
|
||||
item.onlineFlowEntryId = extraData.onlineFlowEntryId || item.onlineFlowEntryId;
|
||||
item.reportPageId = extraData.reportPageId || item.reportPageId;
|
||||
item.formRouterName = extraData.formRouterName || item.formRouterName;
|
||||
item.targetUrl = extraData.targetUrl;
|
||||
}
|
||||
if (item.bindType == null) {
|
||||
if (item.onlineFlowEntryId != null) {
|
||||
item.bindType = SysMenuBindType.WORK_ORDER;
|
||||
} else if (item.reportPageId != null) {
|
||||
item.bindType = SysMenuBindType.REPORT;
|
||||
} else if (item.targetUrl != null) {
|
||||
item.bindType = SysMenuBindType.THRID_URL;
|
||||
} else {
|
||||
item.bindType =
|
||||
item.onlineFormId == null ? SysMenuBindType.ROUTER : SysMenuBindType.ONLINE_FORM;
|
||||
}
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(item => {
|
||||
processMenu(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从给定的数据中找到ID对应的菜单
|
||||
*
|
||||
* @param id 目标ID
|
||||
* @param menuList 源数据列表
|
||||
* @returns 目标对象(ID相同)
|
||||
*/
|
||||
function findMenuItemById(id: string, menuList: Array<MenuItem>): MenuItem | null {
|
||||
if (menuList != null && menuList.length > 0) {
|
||||
for (const menu of menuList) {
|
||||
if (menu.menuId == id) {
|
||||
return menu;
|
||||
} else if (menu.children != null) {
|
||||
const item = findMenuItemById(id, menu.children);
|
||||
if (item != null) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 寻找目标菜单,压入全路径
|
||||
*
|
||||
* @param menuItem 父级菜单
|
||||
* @param menuId 目标ID
|
||||
* @param path 父子菜单集合(全路径)
|
||||
* @returns 目标菜单
|
||||
*/
|
||||
function findMenuItem(menuItem: MenuItem, menuId: string, path: MenuItem[]): MenuItem | null {
|
||||
path.push(menuItem);
|
||||
if (menuItem.menuId == menuId) {
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
let findItem: MenuItem | null = null;
|
||||
if (Array.isArray(menuItem.children)) {
|
||||
for (let i = 0; i < menuItem.children.length; i++) {
|
||||
findItem = findMenuItem(menuItem.children[i], menuId, path);
|
||||
if (findItem != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 没有找到目标,弹出之前压入的菜单
|
||||
if (findItem == null) {
|
||||
path.pop();
|
||||
}
|
||||
return findItem;
|
||||
}
|
||||
|
||||
function initUserInfo(userInfo: UserInfo) {
|
||||
if (userInfo != null && userInfo.headImageUrl != null && userInfo.headImageUrl !== '') {
|
||||
try {
|
||||
userInfo.headImageUrl = JSON.parse(userInfo.headImageUrl);
|
||||
if (Array.isArray(userInfo.headImageUrl)) {
|
||||
userInfo.headImageUrl = userInfo.headImageUrl[0];
|
||||
} else {
|
||||
userInfo.headImageUrl = null;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析头像数据失败!', e);
|
||||
userInfo.headImageUrl = null;
|
||||
}
|
||||
} else {
|
||||
if (userInfo) userInfo.headImageUrl = null;
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
export { processMenu, findMenuItem, initUserInfo, findMenuItemById };
|
||||
Reference in New Issue
Block a user