You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oaweb/pages/index.vue

136 lines
4.5 KiB
Vue

<!--
* index.vue
* Copyright (C) 2024 veypi <i@veypi.com>
* 2024-05-31 17:10
* Distributed under terms of the MIT license.
-->
<template>
<div>
<div v-if="ofApps.length > 0">
<div class="flex justify-between">
<h1 class="page-h1">{{ $t('c.myapps') }}</h1>
<div class="my-5 mr-10">
<div class='vbtn bg-gray-300' @click="new_flag = true" v-if="oaer.access().Get('app', '').CanCreate()">
{{ $t('p.index.create') }}
</div>
</div>
</div>
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 text-center">
<div v-for="(item, k) in ofApps" class="flex items-center justify-center" :key="k">
<Appcard :core="item" :is_part="true"></Appcard>
</div>
</div>
</div>
<div class="mt-20" v-if="apps.length > 0">
<h1 class="page-h1">{{ $t('c.app store') }}</h1>
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 text-center">
<div v-for="(item, k) in apps" class="flex items-center justify-center" :key="k">
<Appcard :core="item" :is_part="false"></Appcard>
</div>
</div>
</div>
<UModal v-model="new_flag">
<UCard>
<template #header>
<div class="text-h6">{{ $t('p.index.create') }} </div>
</template>
<div class="p-4">
<Uploader @success="temp_app.icon = $event" dir="app_icon">
<!-- <img alt="LOGO" class="rounded-full w-16 h-16 mx-auto my-4" :src="temp_app.icon"> -->
<div alt="LOGO" class="divimg rounded-full w-16 h-16 mx-auto" :style="`--bgurl:url('${temp_app.icon}')`">
</div>
</Uploader>
<Vinput class="mt-4" v-model="temp_app.name" :validate="/^\w{2,}$/" :label="$t('c.appname')" type="text">
</Vinput>
{{ temp_app.typ }}
<Vinput class='mt-12' v-model="temp_app.typ" type="radio"
:options="{ 'public': $t('atyp.public'), 'apply': $t('atyp.apply'), 'private': $t('atyp.private') }"
:validate="/^\w{2,}$/">
</Vinput>
</div>
<template #footer>
<div class='flex justify-end gap-4'>
<div class="vbtn bg-vignore" @click="new_flag = false">{{ $t('c.cancel') }}</div>
<div class="vbtn bg-vsuccess" @click="create_new">{{ $t('c.ok') }}</div>
</div>
</template>
</UCard>
</UModal>
<!-- <q-dialog :square="false" v-model="new_flag"> -->
<!-- <q-card class="w-4/5 md:w-96 rounded-2xl"> -->
<!-- <q-card-section> -->
<!-- </q-card-section> -->
<!-- <q-separator></q-separator> -->
<!-- <q-card-section> -->
<!-- <q-form @submit="create_new"> -->
<!-- <q-input label="应用名" v-model="temp_app.name" :rules="rules.name"></q-input> -->
<!-- <div class="flex justify-center my-4 items-center" label='icon'> -->
<!-- <uploader @success="temp_app.icon = $event" dir="app_icon"> -->
<!-- <q-avatar> -->
<!-- <img :src="temp_app.icon"> -->
<!-- </q-avatar> -->
<!-- </uploader> -->
<!-- <q-icon class="ml-2" size="1rem" name='autorenew' @click="temp_app.icon = rand_icon()"></q-icon> -->
<!-- </div> -->
<!-- <q-separator></q-separator> -->
<!-- <div class="flex justify-end mt-8"> -->
<!-- <q-btn class="mx-3" @click="new_flag = false">取消</q-btn> -->
<!-- <q-btn type="submit">创建</q-btn> -->
<!-- </div> -->
<!-- </q-form> -->
<!-- </q-card-section> -->
<!-- </q-card> -->
<!-- </q-dialog> -->
</div>
</template>
<script setup lang="ts">
import type { models } from '#imports';
import msg from '@veypi/msg';
import oaer from '@veypi/oaer';
let allApps = ref<models.App[]>([]);
let apps = computed(() => allApps.value.filter(e => e.user_status !== 'ok'))
let ofApps = computed(() => allApps.value.filter(e => e.user_status === 'ok'))
function getApps() {
api.app.List({}).then(
(e) => {
allApps.value = e;
}
);
}
let new_flag = ref(false);
let temp_app = ref({
name: "",
icon: '',
typ: 'public',
});
function create_new() {
api.app.Post({
name: temp_app.value.name,
icon: temp_app.value.icon,
typ: temp_app.value.typ,
status: "ok"
}).then((e: models.App) => {
ofApps.value.push(e);
msg.Info("创建成功");
new_flag.value = false;
}).catch(e => {
msg.Warn("创建失败: " + e);
})
}
onMounted(() => {
getApps();
});
</script>