-
Notifications
You must be signed in to change notification settings - Fork 14
/
confirm.vue
95 lines (82 loc) · 2.39 KB
/
confirm.vue
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
<template>
<el-dialog v-if="store.market?.registry" v-model="showConfirm" class="confirm-panel" destroy-on-close>
<template #header>确认安装</template>
<table>
<colgroup>
<col width="auto">
<col width="auto">
<col width="1rem">
<col width="auto">
</colgroup>
<thead>
<tr>
<th>依赖</th>
<th>旧版本</th>
<th></th>
<th>新版本</th>
</tr>
</thead>
<tbody>
<tr v-for="(version, name) in config.market.override" :key="name">
<td>{{ name }}</td>
<td>{{ store.dependencies?.[name]?.resolved || '未安装' }}</td>
<td class="arrow"><span><k-icon name="arrow-right"></k-icon></span></td>
<td>{{ version || '移除依赖' }}</td>
</tr>
</tbody>
</table>
<template #footer>
<div class="left">
<el-checkbox :disabled="!hasRemove" v-model="removeConfig">
为新卸载的依赖删除配置
</el-checkbox>
</div>
<div class="right">
<el-button @click="showConfirm = false">取消</el-button>
<el-button type="danger" @click="clear">丢弃改动</el-button>
<el-button type="primary" @click="confirm">确认安装</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { store, useContext, useConfig } from '@koishijs/client'
import { showConfirm, install } from './utils'
const ctx = useContext()
const config = useConfig()
const removeConfig = ref(config.value.market?.removeConfig)
function clear() {
showConfirm.value = false
config.value.market.override = {}
}
const hasRemove = computed(() => {
return Object.values(config.value.market.override).some(version => !version)
})
function confirm() {
showConfirm.value = false
return install(config.value.market.override, async () => {
for (const [name, value] of Object.entries(config.value.market.override)) {
if (!value || store.dependencies?.[name]?.resolved) continue
ctx.configWriter?.ensure(name, true)
}
})
}
</script>
<style lang="scss">
.confirm-panel {
td.arrow {
padding: 0;
span {
display: flex;
justify-content: center;
align-items: center;
}
}
.el-dialog__footer {
display: flex;
justify-content: space-between;
align-items: center;
}
}
</style>