Skip to content

Commit 6b1c0e7

Browse files
committed
Merge branch 'feature/bpm' of https://github.com/yudaocode/yudao-ui-admin-vue3 into feature/bpm
2 parents f484f95 + cde758d commit 6b1c0e7

File tree

9 files changed

+106
-57
lines changed

9 files changed

+106
-57
lines changed

src/components/SimpleProcessDesignerV2/src/SimpleProcessModel.vue

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { SimpleFlowNode, NodeType, NODE_DEFAULT_TEXT } from './consts'
5151
import { useWatchNode } from './node'
5252
import { ZoomOut, ZoomIn, ScaleToOriginal } from '@element-plus/icons-vue'
5353
import { isString } from '@/utils/is'
54+
import download from "@/utils/download";
5455
5556
defineOptions({
5657
name: 'SimpleProcessModel'
@@ -174,18 +175,7 @@ defineExpose({
174175
/** 导出 JSON */
175176
// TODO @zws:增加一个 download 里面搞个 json 更好
176177
const exportJson = () => {
177-
const blob = new Blob([JSON.stringify(processNodeTree.value)])
178-
const tempLink = document.createElement('a') // 创建a标签
179-
const href = window.URL.createObjectURL(blob) // 创建下载的链接
180-
// filename
181-
const fileName = `model.json`
182-
tempLink.href = href
183-
tempLink.target = '_blank'
184-
tempLink.download = fileName
185-
document.body.appendChild(tempLink)
186-
tempLink.click() // 点击下载
187-
document.body.removeChild(tempLink) // 下载完成移除元素
188-
window.URL.revokeObjectURL(href) // 释放掉 blob 对象
178+
download.json(new Blob([JSON.stringify(processNodeTree.value)]), 'model.json')
189179
}
190180
191181
/** 导入 JSON */
@@ -200,6 +190,7 @@ const importLocalFile = () => {
200190
reader.onload = function () {
201191
if (isString(this.result)) {
202192
processNodeTree.value = JSON.parse(this.result)
193+
emits('save', processNodeTree.value)
203194
}
204195
}
205196
}

src/components/bpmnProcessDesigner/package/designer/ProcessDesigner.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ const importLocalFile = () => {
547547
reader.onload = function () {
548548
let xmlStr = this.result
549549
createNewDiagram(xmlStr)
550+
emit('save', xmlStr)
550551
}
551552
}
552553
/* ------------------------------------------------ refs methods ------------------------------------------------------ */

src/components/bpmnProcessDesigner/package/penal/base/ElementBaseInfo.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ watch(
152152
handleKeyUpdate(props.model.key)
153153
handleNameUpdate(props.model.name)
154154
}
155+
},
156+
{
157+
immediate: true
155158
}
156159
)
157160

src/layout/components/TagsView/src/TagsView.vue

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ import { useDesign } from '@/hooks/web/useDesign'
1212
import { useTemplateRefsList } from '@vueuse/core'
1313
import { ElScrollbar } from 'element-plus'
1414
import { useScrollTo } from '@/hooks/event/useScrollTo'
15+
import { useTagsView } from '@/hooks/web/useTagsView'
16+
import { cloneDeep } from 'lodash-es'
17+
18+
19+
defineOptions({ name: 'TagsView' })
1520
1621
const { getPrefixCls } = useDesign()
1722
1823
const prefixCls = getPrefixCls('tags-view')
1924
2025
const { t } = useI18n()
2126
22-
const { currentRoute, push, replace } = useRouter()
27+
const { currentRoute, push } = useRouter()
28+
29+
const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage } = useTagsView()
2330
2431
const permissionStore = usePermissionStore()
2532
@@ -31,6 +38,10 @@ const visitedViews = computed(() => tagsViewStore.getVisitedViews)
3138
3239
const affixTagArr = ref<RouteLocationNormalizedLoaded[]>([])
3340
41+
const selectedTag = computed(() => tagsViewStore.getSelectedTag)
42+
43+
const setSelectTag = tagsViewStore.setSelectedTag
44+
3445
const appStore = useAppStore()
3546
3647
const tagsViewImmerse = computed(() => appStore.getTagsViewImmerse)
@@ -45,82 +56,73 @@ const initTags = () => {
4556
for (const tag of unref(affixTagArr)) {
4657
// Must have tag name
4758
if (tag.name) {
48-
tagsViewStore.addVisitedView(tag)
59+
tagsViewStore.addVisitedView(cloneDeep(tag))
4960
}
5061
}
5162
}
5263
53-
const selectedTag = ref<RouteLocationNormalizedLoaded>()
54-
5564
// 新增tag
5665
const addTags = () => {
5766
const { name } = unref(currentRoute)
5867
if (name) {
59-
selectedTag.value = unref(currentRoute)
68+
setSelectTag(unref(currentRoute))
6069
tagsViewStore.addView(unref(currentRoute))
6170
}
62-
return false
6371
}
6472
6573
// 关闭选中的tag
6674
const closeSelectedTag = (view: RouteLocationNormalizedLoaded) => {
67-
if (view?.meta?.affix) return
68-
tagsViewStore.delView(view)
69-
if (isActive(view)) {
70-
toLastView()
75+
closeCurrent(view, () => {
76+
if (isActive(view)) {
77+
toLastView()
78+
}
79+
})
80+
}
81+
82+
// 去最后一个
83+
const toLastView = () => {
84+
const visitedViews = tagsViewStore.getVisitedViews
85+
const latestView = visitedViews.slice(-1)[0]
86+
if (latestView) {
87+
push(latestView)
88+
} else {
89+
if (
90+
unref(currentRoute).path === permissionStore.getAddRouters[0].path ||
91+
unref(currentRoute).path === permissionStore.getAddRouters[0].redirect
92+
) {
93+
addTags()
94+
return
95+
}
96+
// You can set another route
97+
push(permissionStore.getAddRouters[0].path)
7198
}
7299
}
73100
74101
// 关闭全部
75102
const closeAllTags = () => {
76-
tagsViewStore.delAllViews()
77-
toLastView()
103+
closeAll(() => {
104+
toLastView()
105+
})
78106
}
79107
80108
// 关闭其它
81109
const closeOthersTags = () => {
82-
tagsViewStore.delOthersViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
110+
closeOther()
83111
}
84112
85113
// 重新加载
86114
const refreshSelectedTag = async (view?: RouteLocationNormalizedLoaded) => {
87-
if (!view) return
88-
tagsViewStore.delCachedView()
89-
const { path, query } = view
90-
await nextTick()
91-
replace({
92-
path: '/redirect' + path,
93-
query: query
94-
})
115+
refreshPage(view)
95116
}
96117
97118
// 关闭左侧
98119
const closeLeftTags = () => {
99-
tagsViewStore.delLeftViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
120+
closeLeft()
100121
}
101122
102123
// 关闭右侧
103124
const closeRightTags = () => {
104-
tagsViewStore.delRightViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
105-
}
106-
107-
// 跳转到最后一个
108-
const toLastView = () => {
109-
const visitedViews = tagsViewStore.getVisitedViews
110-
const latestView = visitedViews.slice(-1)[0]
111-
if (latestView) {
112-
push(latestView)
113-
} else {
114-
if (
115-
unref(currentRoute).path === permissionStore.getAddRouters[0].path ||
116-
unref(currentRoute).path === permissionStore.getAddRouters[0].redirect
117-
) {
118-
addTags()
119-
return
120-
}
121-
// TODO: You can set another route
122-
push('/')
123-
}
125+
closeRight()
124126
}
125127
126128
// 滚动到选中的tag
@@ -209,13 +211,14 @@ const isActive = (route: RouteLocationNormalizedLoaded): boolean => {
209211
// 所有右键菜单组件的元素
210212
const itemRefs = useTemplateRefsList<ComponentRef<typeof ContextMenu & ContextMenuExpose>>()
211213
212-
// 右键菜单装填改变的时候
214+
// 右键菜单状态改变的时候
213215
const visibleChange = (visible: boolean, tagItem: RouteLocationNormalizedLoaded) => {
214216
if (visible) {
215217
for (const v of unref(itemRefs)) {
216218
const elDropdownMenuRef = v.elDropdownMenuRef
217219
if (tagItem.fullPath !== v.tagItem.fullPath) {
218220
elDropdownMenuRef?.handleClose()
221+
setSelectTag(tagItem)
219222
}
220223
}
221224
}
@@ -243,6 +246,16 @@ const move = (to: number) => {
243246
start()
244247
}
245248
249+
const canShowIcon = (item: RouteLocationNormalizedLoaded) => {
250+
if (
251+
(item?.matched?.[1]?.meta?.icon && unref(tagsViewIcon)) ||
252+
(item?.meta?.affix && unref(tagsViewIcon) && item?.meta?.icon)
253+
) {
254+
return true
255+
}
256+
return false
257+
}
258+
246259
onBeforeMount(() => {
247260
initTags()
248261
addTags()

src/store/modules/tagsView.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ import { getRawRoute } from '@/utils/routerHelper'
44
import { defineStore } from 'pinia'
55
import { store } from '../index'
66
import { findIndex } from '@/utils'
7+
import { useUserStoreWithOut } from './user'
78

89
export interface TagsViewState {
910
visitedViews: RouteLocationNormalizedLoaded[]
1011
cachedViews: Set<string>
12+
selectedTag?: RouteLocationNormalizedLoaded
1113
}
1214

1315
export const useTagsViewStore = defineStore('tagsView', {
1416
state: (): TagsViewState => ({
1517
visitedViews: [],
16-
cachedViews: new Set()
18+
cachedViews: new Set(),
19+
selectedTag: undefined
1720
}),
1821
getters: {
1922
getVisitedViews(): RouteLocationNormalizedLoaded[] {
2023
return this.visitedViews
2124
},
2225
getCachedViews(): string[] {
2326
return Array.from(this.cachedViews)
27+
},
28+
getSelectedTag(): RouteLocationNormalizedLoaded | undefined {
29+
return this.selectedTag
2430
}
2531
},
2632
actions: {
@@ -98,8 +104,12 @@ export const useTagsViewStore = defineStore('tagsView', {
98104
},
99105
// 删除所有tag
100106
delAllVisitedViews() {
107+
const userStore = useUserStoreWithOut()
108+
101109
// const affixTags = this.visitedViews.filter((tag) => tag.meta.affix)
102-
this.visitedViews = []
110+
this.visitedViews = userStore.getUser
111+
? this.visitedViews.filter((tag) => tag?.meta?.affix)
112+
: []
103113
},
104114
// 删除其他
105115
delOthersViews(view: RouteLocationNormalizedLoaded) {
@@ -145,6 +155,18 @@ export const useTagsViewStore = defineStore('tagsView', {
145155
break
146156
}
147157
}
158+
},
159+
// 设置当前选中的tag
160+
setSelectedTag(tag: RouteLocationNormalizedLoaded) {
161+
this.selectedTag = tag
162+
},
163+
setTitle(title: string, path?: string) {
164+
for (const v of this.visitedViews) {
165+
if (v.path === (path ?? this.selectedTag?.path)) {
166+
v.meta.title = title
167+
break
168+
}
169+
}
148170
}
149171
},
150172
persist: false

src/utils/download.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const download = {
3333
markdown: (data: Blob, fileName: string) => {
3434
download0(data, fileName, 'text/markdown')
3535
},
36+
// 下载 Json 方法
37+
json: (data: Blob, fileName: string) => {
38+
download0(data, fileName, 'application/json')
39+
},
3640
// 下载图片(允许跨域)
3741
image: ({
3842
url,

src/views/bpm/model/CategoryDraggableModel.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ import { checkPermi } from '@/utils/permission'
262262
import { useUserStoreWithOut } from '@/store/modules/user'
263263
import { useAppStore } from '@/store/modules/app'
264264
import { cloneDeep } from 'lodash-es'
265+
import {useTagsView} from "@/hooks/web/useTagsView";
265266
266267
defineOptions({ name: 'BpmModel' })
267268
@@ -498,6 +499,7 @@ const handleDeleteCategory = async () => {
498499
} catch {}
499500
}
500501
502+
const tagsView = useTagsView();
501503
/** 添加流程模型弹窗 */
502504
const modelFormRef = ref()
503505
const openModelForm = (type: string, id?: number) => {
@@ -507,6 +509,10 @@ const openModelForm = (type: string, id?: number) => {
507509
push({
508510
name: 'BpmModelUpdate',
509511
params: { id, type }
512+
}).then((_) => {
513+
if (type === 'copy') {
514+
tagsView.setTitle('复制流程')
515+
}
510516
})
511517
}
512518
}

src/views/bpm/model/editor/index.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
:additionalModel="controlForm.additionalModel"
1313
:model="model"
1414
@save="save"
15+
:process-id="modelKey"
16+
:process-name="modelName"
1517
/>
1618
<!-- 流程属性器,负责编辑每个流程节点的属性 -->
1719
<MyProcessPenal
@@ -53,6 +55,8 @@ provide('formType', formType)
5355
5456
// 注入流程数据
5557
const xmlString = inject('processData') as Ref
58+
// 注入模型数据
59+
const modelData = inject('modelData') as Ref
5660
5761
const modeler = shallowRef() // BPMN Modeler
5862
const processDesigner = ref()
@@ -69,6 +73,8 @@ const model = ref<ModelApi.ModelVO>() // 流程模型的信息
6973
/** 初始化 modeler */
7074
// TODO @zws:需要初始化,不然首次创建后,无法发布!相当于说,key、name 要去赋值下
7175
const initModeler = async (item) => {
76+
//先初始化模型数据
77+
model.value = modelData.value
7278
modeler.value = item
7379
}
7480

src/views/bpm/model/form/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const formData: any = ref({
145145
const processData = ref<any>()
146146
147147
provide('processData', processData)
148+
provide('modelData', formData)
148149
149150
// 数据列表
150151
const formList = ref([])
@@ -160,6 +161,8 @@ const initData = async () => {
160161
// 复制场景
161162
if (route.params.type === 'copy') {
162163
delete formData.value.id
164+
formData.value.name += '副本'
165+
formData.value.key += '_copy'
163166
}
164167
} else {
165168
// 新增场景

0 commit comments

Comments
 (0)