wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { assign } from 'lodash-es';
 
export const useProcessStore = defineStore('process', function () {
    const list = ref<Process.List>([]);
 
    // 添加
    function add(data: any) {
        list.value.forEach((e: Process.Item) => {
            e.active = false;
        });
 
        if (!data.meta) {
            data.meta = {};
        }
 
        if (!data.meta?.isHome && data.meta?.process !== false) {
            const index = list.value.findIndex(e => e.path === data.path);
 
            if (index < 0) {
                list.value.push({
                    ...data,
                    active: true
                });
            } else {
                assign(list.value[index], data, { active: true });
            }
        }
    }
 
    // 关闭当前
    function close() {
        const index = list.value.findIndex(e => e.active);
 
        if (index > -1) {
            list.value.splice(index, 1);
        }
    }
 
    // 移除
    function remove(index: number) {
        list.value.splice(index, 1);
    }
 
    // 设置
    function set(data: Process.Item[]) {
        list.value = data;
    }
 
    // 清空
    function clear() {
        list.value = [];
    }
 
    // 设置标题
    function setTitle(title: string) {
        const item = list.value.find(e => e.active);
 
        if (item) {
            item.meta.label = title;
        }
    }
 
    return {
        list,
        add,
        remove,
        close,
        set,
        clear,
        setTitle
    };
});