-
Notifications
You must be signed in to change notification settings - Fork 14
/
manual.vue
62 lines (52 loc) · 1.8 KB
/
manual.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
<template>
<el-dialog v-if="store.market?.registry" v-model="showManual" class="manual-panel" destroy-on-close>
<template #header>高级:手动添加依赖</template>
<k-comment type="warning">
<p>提示:如果你想要安装插件,请前往<router-link to="/market">插件市场</router-link>页面。</p>
</k-comment>
<el-input :class="{ invalid }" v-model="name" @keydown.enter.stop.prevent="onEnter" placeholder="请输入名称"></el-input>
<template v-if="remote">
<p>最新版本:{{ remote['dist-tags']?.latest }}</p>
<p>介绍:{{ remote.description }}</p>
</template>
<template #footer>
<el-button @click="showManual = false">取消</el-button>
<el-button type="primary" :disabled="invalid" @click="onEnter">确定</el-button>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { computed, ref, watch } from 'vue'
import type { Registry } from '@koishijs/registry'
import { store, useConfig } from '@koishijs/client'
import { useDebounceFn } from '@vueuse/core'
import { showManual, addManual } from './utils'
const config = useConfig()
const invalid = computed(() => false)
const name = ref('')
const remote = ref<Registry>()
const fetchRemote = useDebounceFn(async (name2: string) => {
try {
const data = await addManual(name2)
if (name2 === name.value) remote.value = data
} catch {}
}, 500)
watch(name, (name2) => {
if (name2 !== remote.value?.name) remote.value = null
if (!name2) return remote.value = null
fetchRemote(name2)
})
function onEnter() {
if (!remote.value) return
const { name } = remote.value
config.value.market.override[name] = remote.value['dist-tags'].latest
showManual.value = false
}
</script>
<style lang="scss">
.manual-panel {
.k-comment {
margin-top: 0;
}
}
</style>