forked from FoundKeyGang/FoundKey
wip: refactor(client): migrate components to composition api
This commit is contained in:
parent
ffc07a08d7
commit
41e18aa993
5 changed files with 100 additions and 156 deletions
|
@ -27,8 +27,8 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
import MkPagination from '@/components/ui/pagination.vue';
|
import MkPagination from '@/components/ui/pagination.vue';
|
||||||
import MkTab from '@/components/tab.vue';
|
import MkTab from '@/components/tab.vue';
|
||||||
import FormInfo from '@/components/ui/info.vue';
|
import FormInfo from '@/components/ui/info.vue';
|
||||||
|
@ -36,38 +36,25 @@ import FormLink from '@/components/form/link.vue';
|
||||||
import { userPage } from '@/filters/user';
|
import { userPage } from '@/filters/user';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
let tab = $ref('mute');
|
||||||
components: {
|
|
||||||
MkPagination,
|
|
||||||
MkTab,
|
|
||||||
FormInfo,
|
|
||||||
FormLink,
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['info'],
|
const mutingPagination = {
|
||||||
|
endpoint: 'mute/list' as const,
|
||||||
|
limit: 10,
|
||||||
|
};
|
||||||
|
|
||||||
data() {
|
const blockingPagination = {
|
||||||
return {
|
endpoint: 'blocking/list' as const,
|
||||||
|
limit: 10,
|
||||||
|
};
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
[symbols.PAGE_INFO]: {
|
[symbols.PAGE_INFO]: {
|
||||||
title: this.$ts.muteAndBlock,
|
title: i18n.locale.muteAndBlock,
|
||||||
icon: 'fas fa-ban',
|
icon: 'fas fa-ban',
|
||||||
bg: 'var(--bg)',
|
bg: 'var(--bg)',
|
||||||
},
|
},
|
||||||
tab: 'mute',
|
|
||||||
mutingPagination: {
|
|
||||||
endpoint: 'mute/list' as const,
|
|
||||||
limit: 10,
|
|
||||||
},
|
|
||||||
blockingPagination: {
|
|
||||||
endpoint: 'blocking/list' as const,
|
|
||||||
limit: 10,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
userPage
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="_formRoot">
|
<div class="_formRoot">
|
||||||
<FormTextarea v-model="installThemeCode" class="_formBlock">
|
<FormTextarea v-model="installThemeCode" class="_formBlock">
|
||||||
<template #label>{{ $ts._theme.code }}</template>
|
<template #label>{{ i18n.locale._theme.code }}</template>
|
||||||
</FormTextarea>
|
</FormTextarea>
|
||||||
|
|
||||||
<div class="_formBlock" style="display: flex; gap: var(--margin); flex-wrap: wrap;">
|
<div class="_formBlock" style="display: flex; gap: var(--margin); flex-wrap: wrap;">
|
||||||
<FormButton :disabled="installThemeCode == null" inline @click="() => preview(installThemeCode)"><i class="fas fa-eye"></i> {{ $ts.preview }}</FormButton>
|
<FormButton :disabled="installThemeCode == null" inline @click="() => preview(installThemeCode)"><i class="fas fa-eye"></i> {{ i18n.locale.preview }}</FormButton>
|
||||||
<FormButton :disabled="installThemeCode == null" primary inline @click="() => install(installThemeCode)"><i class="fas fa-check"></i> {{ $ts.install }}</FormButton>
|
<FormButton :disabled="installThemeCode == null" primary inline @click="() => install(installThemeCode)"><i class="fas fa-check"></i> {{ i18n.locale.install }}</FormButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
import * as JSON5 from 'json5';
|
import * as JSON5 from 'json5';
|
||||||
import FormTextarea from '@/components/form/textarea.vue';
|
import FormTextarea from '@/components/form/textarea.vue';
|
||||||
import FormButton from '@/components/ui/button.vue';
|
import FormButton from '@/components/ui/button.vue';
|
||||||
|
@ -20,28 +20,11 @@ import { applyTheme, validateTheme } from '@/scripts/theme';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { addTheme, getThemes } from '@/theme-store';
|
import { addTheme, getThemes } from '@/theme-store';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
let installThemeCode = $ref(null);
|
||||||
components: {
|
|
||||||
FormTextarea,
|
|
||||||
FormButton,
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['info'],
|
function parseThemeCode(code: string) {
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
[symbols.PAGE_INFO]: {
|
|
||||||
title: this.$ts._theme.install,
|
|
||||||
icon: 'fas fa-download',
|
|
||||||
bg: 'var(--bg)',
|
|
||||||
},
|
|
||||||
installThemeCode: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
parseThemeCode(code) {
|
|
||||||
let theme;
|
let theme;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -49,42 +32,48 @@ export default defineComponent({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
text: this.$ts._theme.invalid
|
text: i18n.locale._theme.invalid
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!validateTheme(theme)) {
|
if (!validateTheme(theme)) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
text: this.$ts._theme.invalid
|
text: i18n.locale._theme.invalid
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getThemes().some(t => t.id === theme.id)) {
|
if (getThemes().some(t => t.id === theme.id)) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
text: this.$ts._theme.alreadyInstalled
|
text: i18n.locale._theme.alreadyInstalled
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
},
|
}
|
||||||
|
|
||||||
preview(code) {
|
function preview(code: string): void {
|
||||||
const theme = this.parseThemeCode(code);
|
const theme = parseThemeCode(code);
|
||||||
if (theme) applyTheme(theme, false);
|
if (theme) applyTheme(theme, false);
|
||||||
},
|
}
|
||||||
|
|
||||||
async install(code) {
|
async function install(code: string): Promise<void> {
|
||||||
const theme = this.parseThemeCode(code);
|
const theme = parseThemeCode(code);
|
||||||
if (!theme) return;
|
if (!theme) return;
|
||||||
await addTheme(theme);
|
await addTheme(theme);
|
||||||
os.alert({
|
os.alert({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
text: this.$t('_theme.installed', { name: theme.name })
|
text: i18n.t('_theme.installed', { name: theme.name })
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
[symbols.PAGE_INFO]: {
|
||||||
|
title: i18n.locale._theme.install,
|
||||||
|
icon: 'fas fa-download',
|
||||||
|
bg: 'var(--bg)',
|
||||||
},
|
},
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -17,18 +17,12 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
|
|
||||||
export default defineComponent({
|
const uploads = os.uploads;
|
||||||
data() {
|
const zIndex = os.claimZIndex('high');
|
||||||
return {
|
|
||||||
uploads: os.uploads,
|
|
||||||
zIndex: os.claimZIndex('high'),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -10,32 +10,19 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
import XPie from './pie.vue';
|
import XPie from './pie.vue';
|
||||||
import bytes from '@/filters/bytes';
|
import bytes from '@/filters/bytes';
|
||||||
|
|
||||||
export default defineComponent({
|
const props = defineProps<{
|
||||||
components: {
|
meta: any; // TODO
|
||||||
XPie
|
}>();
|
||||||
},
|
|
||||||
props: {
|
const usage = $computed(() => props.meta.fs.used / props.meta.fs.total);
|
||||||
meta: {
|
const total = $computed(() => props.meta.fs.total);
|
||||||
required: true,
|
const used = $computed(() => props.meta.fs.used);
|
||||||
}
|
const available = $computed(() => props.meta.fs.total - props.meta.fs.used);
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
usage: this.meta.fs.used / this.meta.fs.total,
|
|
||||||
total: this.meta.fs.total,
|
|
||||||
used: this.meta.fs.used,
|
|
||||||
available: this.meta.fs.total - this.meta.fs.used,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
bytes
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -20,30 +20,17 @@
|
||||||
</svg>
|
</svg>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
|
|
||||||
export default defineComponent({
|
const props = defineProps<{
|
||||||
props: {
|
value: number;
|
||||||
value: {
|
}>();
|
||||||
type: Number,
|
|
||||||
required: true
|
const r = 0.45;
|
||||||
}
|
|
||||||
},
|
const color = $computed(() => `hsl(${180 - (props.value * 180)}, 80%, 70%)`);
|
||||||
data() {
|
const strokeDashoffset = $computed(() => (1 - props.value) * (Math.PI * (r * 2)));
|
||||||
return {
|
|
||||||
r: 0.45
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
color(): string {
|
|
||||||
return `hsl(${180 - (this.value * 180)}, 80%, 70%)`;
|
|
||||||
},
|
|
||||||
strokeDashoffset(): number {
|
|
||||||
return (1 - this.value) * (Math.PI * (this.r * 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
Loading…
Reference in a new issue