Add online registry branch switcher

This commit is contained in:
the1812 2021-11-30 23:05:07 +08:00
parent 88820ff0b5
commit 7ad515c2f6
4 changed files with 47 additions and 33 deletions

View File

@ -13,11 +13,6 @@ export enum SettingsPanelDockSide {
Right = '右侧', Right = '右侧',
} }
export enum Branch {
Master = 'master',
Preview = 'preview'
}
const entry: ComponentEntry = async ({ metadata }) => { const entry: ComponentEntry = async ({ metadata }) => {
const { isIframe } = await import('@/core/utils') const { isIframe } = await import('@/core/utils')
if (isIframe()) { if (isIframe()) {
@ -69,11 +64,6 @@ export const component: ComponentMetadata = {
displayName: '更新源', displayName: '更新源',
dropdownEnum: CdnTypes, dropdownEnum: CdnTypes,
}, },
branch: {
defaultValue: Branch.Preview,
displayName: '更新分支',
dropdownEnum: Branch,
},
dockSide: { dockSide: {
defaultValue: SettingsPanelDockSide.Left, defaultValue: SettingsPanelDockSide.Left,
displayName: '设置面板停靠', displayName: '设置面板停靠',

View File

@ -5,13 +5,6 @@
<div class="online-registry-header-title"> <div class="online-registry-header-title">
在线仓库 在线仓库
</div> </div>
<div class="online-registry-header-search">
<VIcon icon="search" :size="18" />
<TextBox
v-model="searchKeyword"
placeholder="搜索功能"
/>
</div>
<VIcon <VIcon
icon="mdi-refresh" icon="mdi-refresh"
:size="22" :size="22"
@ -27,6 +20,23 @@
@click="popupOpen = false" @click="popupOpen = false"
/> />
</div> </div>
<div class="online-registry-header">
<div class="online-registry-header-search">
<VIcon icon="search" :size="18" />
<TextBox
v-model="searchKeyword"
placeholder="搜索功能"
/>
</div>
<div class="online-registry-header-branch">
分支:
<VDropdown v-model="selectedBranch" :items="registryBranches">
<template #item="{ item }">
{{ item }}
</template>
</VDropdown>
</div>
</div>
<div class="online-registry-separator"></div> <div class="online-registry-separator"></div>
<div ref="content" class="online-registry-content"> <div ref="content" class="online-registry-content">
<VLoading v-if="loading" /> <VLoading v-if="loading" />
@ -47,10 +57,12 @@
<script lang="ts"> <script lang="ts">
import { monkey } from '@/core/ajax' import { monkey } from '@/core/ajax'
import { cdnRoots } from '@/core/cdn-types' import { cdnRoots } from '@/core/cdn-types'
import { meta } from '@/core/meta'
import { getGeneralSettings } from '@/core/settings' import { getGeneralSettings } from '@/core/settings'
import { logError } from '@/core/utils/log' import { logError } from '@/core/utils/log'
import { import {
VIcon, VIcon,
VDropdown,
TextBox, TextBox,
VPopup, VPopup,
VLoading, VLoading,
@ -59,10 +71,13 @@ import {
import Fuse from 'fuse.js' import Fuse from 'fuse.js'
import { DocSourceItem } from 'registry/lib/docs' import { DocSourceItem } from 'registry/lib/docs'
import RegistryItem from './RegistryItem.vue' import RegistryItem from './RegistryItem.vue'
import { registryBranches } from './third-party'
const general = getGeneralSettings()
export default Vue.extend({ export default Vue.extend({
components: { components: {
VIcon, VIcon,
VDropdown,
TextBox, TextBox,
VPopup, VPopup,
RegistryItem, RegistryItem,
@ -76,6 +91,11 @@ export default Vue.extend({
}, },
}, },
data() { data() {
const branches = [
general.registryBranch,
meta.compilationInfo.branch,
registryBranches[0],
].filter(it => registryBranches.includes(it) && Boolean(it))
return { return {
searchKeyword: '', searchKeyword: '',
popupOpen: false, popupOpen: false,
@ -84,6 +104,8 @@ export default Vue.extend({
filteredList: [], filteredList: [],
// packList: [], // packList: [],
fuse: null, fuse: null,
registryBranches,
selectedBranch: branches[0],
} }
}, },
watch: { watch: {
@ -97,6 +119,10 @@ export default Vue.extend({
this.filteredList = fuseResult.map(it => it.item) this.filteredList = fuseResult.map(it => it.item)
this.$nextTick().then(() => this.$refs.content.scrollTo(0, 0)) this.$nextTick().then(() => this.$refs.content.scrollTo(0, 0))
}, 200), }, 200),
selectedBranch(newBranch: string) {
general.registryBranch = newBranch
this.fetchFeatures()
},
}, },
mounted() { mounted() {
this.fetchFeatures() this.fetchFeatures()
@ -106,7 +132,7 @@ export default Vue.extend({
if (this.loading) { if (this.loading) {
return return
} }
const fetchPath = cdnRoots[getGeneralSettings().cdnRoot](getGeneralSettings().branch) const fetchPath = cdnRoots[general.cdnRoot](general.branch)
try { try {
this.loading = true this.loading = true
const featureListUrl = `${fetchPath}doc/features/features.json` const featureListUrl = `${fetchPath}doc/features/features.json`
@ -157,14 +183,17 @@ export default Vue.extend({
} }
&-header { &-header {
padding: 12px; padding: 12px;
@include h-center(6px); @include h-center(12px);
& + & {
padding-top: 0;
}
&-title { &-title {
flex: 1;
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;
} }
&-search { &-search {
flex: 1; flex: 1;
margin: 0 12px;
justify-content: center; justify-content: center;
@include h-center(6px); @include h-center(6px);
.be-textbox { .be-textbox {
@ -173,6 +202,10 @@ export default Vue.extend({
font-size: 12px; font-size: 12px;
} }
} }
&-branch {
@include h-center(6px);
font-size: 12px;
}
&-refresh-icon, &-refresh-icon,
&-close-icon { &-close-icon {
padding: 4px; padding: 4px;

View File

@ -1,13 +0,0 @@
// import { ComponentMetadata } from '../types'
// export const component: ComponentMetadata = {
// name: 'onlineRegistry',
// displayName: '在线功能仓库',
// entry: () => {
// },
// tags: [componentsTags.general],
// description: {
// 'zh-CN': '浏览在线功能仓库, 为脚本挑选并安装需要的功能.',
// },
// }

View File

@ -0,0 +1,4 @@
import { registerAndGetData } from '@/plugins/data'
const defaultRegistryBranches = ['master', 'preview']
export const [registryBranches] = registerAndGetData('settingsPanel.registryBranches', [...defaultRegistryBranches])