Skip to content

Commit

Permalink
feat: 支持 GitLab Snippet(后端 > 2.14.186)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 19, 2024
1 parent ab59213 commit 17b04f5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.85",
"version": "2.14.87",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
3 changes: 3 additions & 0 deletions src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { t } = i18n.global;
export const useSettingsStore = defineStore('settingsStore', {
state: (): SettingsStoreState => {
return {
syncPlatform: '',
gistToken: '',
githubUser: '',
defaultUserAgent: '',
Expand All @@ -36,6 +37,7 @@ export const useSettingsStore = defineStore('settingsStore', {
const { showNotify } = useAppNotifyStore();
const res = await settingsApi.getSettings();
if (res?.data?.status === 'success' && res?.data?.data) {
this.syncPlatform = res.data.data.syncPlatform || '';
this.gistToken = res.data.data.gistToken || '';
this.githubUser = res.data.data.githubUser || '';
this.defaultUserAgent = res.data.data.defaultUserAgent || '';
Expand Down Expand Up @@ -71,6 +73,7 @@ export const useSettingsStore = defineStore('settingsStore', {
const { showNotify } = useAppNotifyStore();
const res = await settingsApi.setSettings(data);
if (res?.data?.status === 'success' && res?.data?.data) {
this.syncPlatform = res.data.data.syncPlatform || '';
this.gistToken = res.data.data.gistToken || '';
this.githubUser = res.data.data.githubUser || '';
this.defaultUserAgent = res.data.data.defaultUserAgent || '';
Expand Down
1 change: 1 addition & 0 deletions src/types/store/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface SettingsBase {
}

interface SettingsPostData {
syncPlatform?: string;
gistToken?: string;
githubUser?: string;
defaultUserAgent?: string;
Expand Down
38 changes: 36 additions & 2 deletions src/views/My.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@
type="text"
input-align="left"
:left-icon="iconUser"
/>
>
<template #button>
<nut-button :disabled="!isEditing" :plain="!isEditing" size="mini" :type="isEditing ? 'primary' : 'info' " @click="toggleSyncPlatform">{{ syncPlatformInput === 'gitlab' ? ( isEditing ?'切换回 Gist' : 'GitLab Snippet (β)') : ( isEditing ?'切换到 GitLab Snippet (β)' : 'Gist') }}</nut-button>
</template>
</nut-input>
<nut-input
v-if="storageType !== 'manual'"
class="input"
Expand Down Expand Up @@ -258,7 +262,7 @@ const router = useRouter();
const { showNotify } = useAppNotifyStore();
const { currentUrl: host } = useHostAPI();
const settingsStore = useSettingsStore();
const { githubUser, gistToken, syncTime, avatarUrl, defaultUserAgent, defaultTimeout } =
const { githubUser, gistToken, syncTime, avatarUrl, defaultUserAgent, defaultTimeout, syncPlatform } =
storeToRefs(settingsStore);
const displayAvatar = computed(() => {
Expand All @@ -278,7 +282,9 @@ const onClickAbout = () => {
router.push(`/aboutUs`);
};
// 编辑 更新
const syncPlatformInput = ref("");
const userInput = ref("");
const tokenInput = ref("");
const uaInput = ref("");
Expand All @@ -293,13 +299,15 @@ const toggleEditMode = async () => {
isEditLoading.value = true;
if (isEditing.value) {
await settingsStore.editSettings({
syncPlatform: syncPlatformInput.value,
githubUser: userInput.value,
gistToken: tokenInput.value,
defaultUserAgent: uaInput.value,
defaultTimeout: timeoutInput.value,
});
setDisplayInfo();
} else {
syncPlatformInput.value = syncPlatform.value;
userInput.value = githubUser.value;
tokenInput.value = gistToken.value;
uaInput.value = defaultUserAgent.value;
Expand All @@ -314,8 +322,34 @@ const exitEditMode = () => {
isEditing.value = false;
isEditLoading.value = false;
};
const toggleSyncPlatform = () => {
if (syncPlatformInput.value === 'gitlab') {
syncPlatformInput.value = ''
Toast.text(`已切换到 ${syncPlatformInput.value === 'gitlab' ? 'GitLab Snippet' : 'Gist'}`);
} else {
Dialog({
title: '切换同步平台',
content: 'GitLab Snippet 正在测试中, 相关文案仍然是 Gist, 请备份数据后使用',
popClass: 'auto-dialog',
okText: `使用 ${syncPlatformInput.value === 'gitlab' ? 'Gist' : ' Snippet'}`,
cancelText: '取消',
onOk: () => {
if (syncPlatformInput.value === 'gitlab') {
syncPlatformInput.value = ''
} else {
syncPlatformInput.value = 'gitlab'
}
Toast.text(`已切换到 ${syncPlatformInput.value === 'gitlab' ? 'GitLab Snippet' : 'Gist'}`);
},
closeOnPopstate: true,
lockScroll: false,
});
}
};
const setDisplayInfo = () => {
syncPlatformInput.value = syncPlatform.value || '';
userInput.value = githubUser.value || t(`myPage.placeholder.noGithubUser`);
tokenInput.value = gistToken.value
? gistToken.value.slice(0, 6) + "************"
Expand Down
3 changes: 2 additions & 1 deletion src/views/Sync.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
/>
</nut-button>
<nut-button
v-if="syncPlatform !== 'gitlab'"
class="upload-all-btn btn"
type="info"
plain
Expand Down Expand Up @@ -207,7 +208,7 @@ const artifactsStore = useArtifactsStore();
const settingsStore = useSettingsStore();
const { isLoading, fetchResult, bottomSafeArea, showFloatingRefreshButton } = storeToRefs(globalStore);
const { artifacts } = storeToRefs(artifactsStore);
const { artifactStore: artifactStoreUrl, artifactStoreStatus } = storeToRefs(settingsStore);
const { artifactStore: artifactStoreUrl, artifactStoreStatus, syncPlatform } = storeToRefs(settingsStore);
const { showNotify } = useAppNotifyStore();
const swipeDisabled = ref(false);
const isEditPanelVisible = ref(false);
Expand Down

0 comments on commit 17b04f5

Please sign in to comment.