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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<template>
    <div class="app-process">
        <ul class="app-process__op">
            <li class="cl-comm__icon" @click="toBack">
                <cl-svg name="back" />
            </li>
            <li class="cl-comm__icon" @click="toRefresh">
                <cl-svg name="refresh" />
            </li>
            <li class="cl-comm__icon" @click="toHome">
                <cl-svg name="home" />
            </li>
        </ul>
 
        <div class="app-process__container">
            <el-scrollbar :ref="setRefs('scroller')" class="app-process__scroller">
                <div class="app-process__list">
                    <div
                        v-for="(item, index) in process.list"
                        :key="index"
                        :ref="setRefs(`item-${index}`)"
                        class="app-process__item"
                        :class="{ active: item.active }"
                        :data-index="index"
                        @click="onTap(item, Number(index))"
                        @contextmenu.stop.prevent="openCM($event, item)"
                    >
                        <span class="label tracking-wider">
                            {{ item.meta.label || item.name || item.path }}
                        </span>
 
                        <cl-svg class="close" name="close" @mousedown.stop="onDel(Number(index))" />
                    </div>
                </div>
            </el-scrollbar>
        </div>
 
        <ul class="app-process__op">
            <li class="cl-comm__icon" @click="toFull">
                <cl-svg name="screen-normal" v-if="app.isFull" />
                <cl-svg name="screen-full" v-else />
            </li>
        </ul>
    </div>
</template>
 
<script lang="ts" setup>
defineOptions({
    name: 'app-process'
});
 
import { onMounted, watch } from 'vue';
import { last } from 'lodash-es';
import { useCool } from '/@/cool';
import { ContextMenu } from '@cool-vue/crud';
import { useBase } from '/$/base';
import { useI18n } from 'vue-i18n';
 
const { refs, setRefs, route, router, mitt } = useCool();
const { process, app } = useBase();
const { t } = useI18n();
 
// 刷新当前路由
function toRefresh() {
    mitt.emit('view.refresh');
}
 
// 回首页
function toHome() {
    router.push('/');
}
 
// 返回上一页
function toBack() {
    router.back();
}
 
// 设置全屏
function toFull() {
    app.setFull(!app.isFull);
}
 
// 跳转
function toPath() {
    const d = process.list.find(e => e.active);
 
    if (!d) {
        const next = last(process.list);
        router.push(next ? next.fullPath : '/');
    }
}
 
// 移动到
function scrollTo(left: number) {
    refs.scroller.wrapRef.scrollTo({
        left,
        behavior: 'smooth'
    });
}
 
// 调整滚动位置
function adScroll(index: number) {
    const el = refs[`item-${index}`];
 
    if (el) {
        scrollTo(el.offsetLeft - (refs.scroller.wrapRef.clientWidth + el.clientWidth) / 2);
    }
}
 
// 选择
function onTap(item: Process.Item, index: number) {
    adScroll(index);
    router.push(item.fullPath);
}
 
// 删除
function onDel(index: number) {
    process.remove(index);
    toPath();
}
 
// 右键菜单
function openCM(e: any, item: Process.Item) {
    ContextMenu.open(e, {
        list: [
            {
                label: t('关闭当前'),
                hidden: item.path !== route.path,
                callback(done) {
                    done();
 
                    process.close();
                    toPath();
                }
            },
            {
                label: t('关闭其他'),
                callback(done) {
                    done();
 
                    process.set(process.list.filter(e => e.fullPath == item.fullPath));
                    toPath();
                }
            },
            {
                label: t('关闭所有'),
                callback(done) {
                    done();
 
                    process.clear();
                    toPath();
                }
            }
        ]
    });
}
 
watch(
    () => route.path,
    function (val) {
        adScroll(process.list.findIndex(e => e.fullPath === val) || 0);
    }
);
 
onMounted(() => {
    // 添加滚轮事件监听器
    refs.scroller.wrapRef?.addEventListener(
        'wheel',
        function (event: WheelEvent) {
            // 滚动的速度因子,可以根据需要调整
            const scrollSpeed = 2;
 
            // 计算滚动的距离
            const distance = event.deltaY * scrollSpeed;
 
            scrollTo(refs.scroller.wrapRef.scrollLeft + distance);
        },
        { passive: false }
    );
});
</script>
 
<style lang="scss" scoped>
.app-process {
    display: flex;
    align-items: center;
    position: relative;
    padding: 5px 10px;
    user-select: none;
    background-color: var(--el-bg-color);
    margin-bottom: 10px;
    overflow: hidden;
 
    &__op {
        display: flex;
        align-items: center;
        list-style: none;
 
        .cl-comm__icon {
            margin-right: 5px;
 
            &:last-child {
                margin-right: 0;
            }
        }
    }
 
    &__container {
        height: 100%;
        flex: 1;
        position: relative;
        margin: 0 5px;
    }
 
    &__scroller {
        height: 40px;
        width: 100%;
        white-space: nowrap;
        position: absolute;
        left: 0;
        top: 0;
    }
 
    &__item {
        display: inline-flex;
        align-items: center;
        justify-content: space-between;
        height: 26px;
        padding: 0 8px;
        cursor: pointer;
        color: var(--el-text-color-regular);
        border-radius: var(--el-border-radius-base);
        margin-right: 5px;
        border: 1px solid var(--el-fill-color-dark);
 
        .close {
            width: 0;
            overflow: hidden;
            transition: width 0.2s ease-in-out;
            font-size: 14px;
            border-radius: 4px;
            opacity: 0;
 
            &:hover {
                background-color: rgba(0, 0, 0, 0.1);
            }
        }
 
        .label {
            font-size: 12px;
            line-height: 1;
        }
 
        &:last-child {
            margin-right: 0;
        }
 
        &:hover:not(.active) {
            background-color: var(--el-fill-color-light);
        }
 
        &.active {
            background-color: var(--el-color-primary);
            border-color: var(--el-color-primary);
            color: #fff;
        }
 
        &:hover,
        &.active {
            .close {
                margin-left: 10px;
                margin-right: -2px;
                width: 14px;
                opacity: 1;
            }
        }
    }
}
</style>