mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-27 07:20:18 +08:00
feat(projects): add alova examples (#647)
* feat: optimistic subpackage `@sa/alova` * feat: add alova examples
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { actionDelegationMiddleware, useAutoRequest } from '@sa/alova/client';
|
||||
import { ref } from 'vue';
|
||||
import { alova } from '@/serviceAlova/request';
|
||||
|
||||
const getLastTime = alova.Get<{ time: string }>('/mock/getLastTime', { cacheFor: null });
|
||||
const isStop = ref(false);
|
||||
const { loading, data } = useAutoRequest(getLastTime, {
|
||||
enableVisibility: true,
|
||||
enableNetwork: false,
|
||||
enableFocus: false,
|
||||
initialData: {
|
||||
time: ''
|
||||
},
|
||||
async middleware(_, next) {
|
||||
await actionDelegationMiddleware('autoRequest:1')(_, () => Promise.resolve());
|
||||
if (!isStop.value) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const toggleStop = () => {
|
||||
isStop.value = !isStop.value;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSpace vertical>
|
||||
<NAlert type="info">
|
||||
{{ $t('page.alova.scenes.visibilityRequestTips') }}
|
||||
</NAlert>
|
||||
<NButton type="primary" @click="toggleStop">
|
||||
<icon-carbon-play v-if="isStop" class="mr-2" />
|
||||
<icon-carbon-stop v-else class="mr-2" />
|
||||
{{ isStop ? $t('page.alova.scenes.startRequest') : $t('page.alova.scenes.stopRequest') }}
|
||||
</NButton>
|
||||
<NSpace align="center">
|
||||
<span>{{ $t('page.alova.scenes.refreshTime') }}: {{ data.time || '--' }}</span>
|
||||
<NSpin v-if="loading" :size="12" />
|
||||
</NSpace>
|
||||
</NSpace>
|
||||
</template>
|
||||
71
src/views/alova/scenes/modules/captcha-verification.vue
Normal file
71
src/views/alova/scenes/modules/captcha-verification.vue
Normal file
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { actionDelegationMiddleware, useCaptcha, useForm } from '@sa/alova/client';
|
||||
import { $t } from '@/locales';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import { sendCaptcha, verifyCaptcha } from '@/serviceAlova/api';
|
||||
|
||||
defineOptions({
|
||||
name: 'CaptchaVerification'
|
||||
});
|
||||
|
||||
const { loading, send, countdown } = useCaptcha(sendCaptcha, {
|
||||
middleware: actionDelegationMiddleware('captcha:send')
|
||||
});
|
||||
const label = computed(() => {
|
||||
return countdown.value > 0
|
||||
? $t('page.login.codeLogin.reGetCode', { time: countdown.value })
|
||||
: $t('page.login.codeLogin.getCode');
|
||||
});
|
||||
const {
|
||||
form,
|
||||
loading: submiting,
|
||||
send: submit
|
||||
} = useForm(formData => verifyCaptcha(formData.phone, formData.code), {
|
||||
initialForm: {
|
||||
phone: '',
|
||||
code: ''
|
||||
}
|
||||
});
|
||||
|
||||
const { formRef, validate } = useNaiveForm();
|
||||
|
||||
const rules = computed<Record<keyof typeof form.value, App.Global.FormRule[]>>(() => {
|
||||
const { formRules } = useFormRules();
|
||||
|
||||
return {
|
||||
phone: formRules.phone,
|
||||
code: formRules.code
|
||||
};
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
await validate();
|
||||
await submit();
|
||||
// request
|
||||
window.$message?.success($t('page.login.common.validateSuccess'));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NForm ref="formRef" :model="form" :rules="rules" size="large" :show-label="false" @keyup.enter="handleSubmit">
|
||||
<NFormItem path="phone">
|
||||
<NInput v-model:value="form.phone" :placeholder="$t('page.login.common.phonePlaceholder')" :maxlength="11" />
|
||||
</NFormItem>
|
||||
<NFormItem path="code">
|
||||
<div class="w-full flex-y-center gap-16px">
|
||||
<NInput v-model:value="form.code" :placeholder="$t('page.login.common.codePlaceholder')" />
|
||||
<NButton size="large" :disabled="countdown > 0" :loading="loading" @click="send(form.phone)">
|
||||
{{ label }}
|
||||
</NButton>
|
||||
</div>
|
||||
</NFormItem>
|
||||
<NSpace vertical :size="18" class="w-full">
|
||||
<NButton type="primary" size="large" round block :loading="submiting" @click="handleSubmit">
|
||||
{{ $t('common.confirm') }}
|
||||
</NButton>
|
||||
</NSpace>
|
||||
</NForm>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
13
src/views/alova/scenes/modules/cross-component-request.vue
Normal file
13
src/views/alova/scenes/modules/cross-component-request.vue
Normal file
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { accessAction } from '@sa/alova/client';
|
||||
|
||||
const handleAutoRequestSend = async () => {
|
||||
accessAction(/^autoRequest/, async ({ send }) => {
|
||||
await send();
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NButton @click="handleAutoRequestSend">{{ $t('page.alova.scenes.triggerAllRequest') }}</NButton>
|
||||
</template>
|
||||
43
src/views/alova/scenes/modules/network-toggle-request.vue
Normal file
43
src/views/alova/scenes/modules/network-toggle-request.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { actionDelegationMiddleware, useAutoRequest } from '@sa/alova/client';
|
||||
import { ref } from 'vue';
|
||||
import { alova } from '@/serviceAlova/request';
|
||||
|
||||
const getLastTime = alova.Get<{ time: string }>('/mock/getLastTime', { cacheFor: null });
|
||||
const isStop = ref(false);
|
||||
const { loading, data } = useAutoRequest(getLastTime, {
|
||||
enableVisibility: false,
|
||||
enableNetwork: true,
|
||||
enableFocus: false,
|
||||
initialData: {
|
||||
time: ''
|
||||
},
|
||||
async middleware(_, next) {
|
||||
await actionDelegationMiddleware('autoRequest:2')(_, () => Promise.resolve());
|
||||
if (!isStop.value) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const toggleStop = () => {
|
||||
isStop.value = !isStop.value;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSpace vertical>
|
||||
<NAlert type="info">
|
||||
{{ $t('page.alova.scenes.networkRequestTips') }}
|
||||
</NAlert>
|
||||
<NButton type="primary" @click="toggleStop">
|
||||
<icon-carbon-play v-if="isStop" class="mr-2" />
|
||||
<icon-carbon-stop v-else class="mr-2" />
|
||||
{{ isStop ? $t('page.alova.scenes.startRequest') : $t('page.alova.scenes.stopRequest') }}
|
||||
</NButton>
|
||||
<NSpace align="center">
|
||||
<span>{{ $t('page.alova.scenes.refreshTime') }}: {{ data.time || '--' }}</span>
|
||||
<NSpin v-if="loading" :size="12" />
|
||||
</NSpace>
|
||||
</NSpace>
|
||||
</template>
|
||||
41
src/views/alova/scenes/modules/polling-request.vue
Normal file
41
src/views/alova/scenes/modules/polling-request.vue
Normal file
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { actionDelegationMiddleware, useAutoRequest } from '@sa/alova/client';
|
||||
import { ref } from 'vue';
|
||||
import { alova } from '@/serviceAlova/request';
|
||||
|
||||
const getLastTime = alova.Get<{ time: string }>('/mock/getLastTime', { cacheFor: null });
|
||||
const isStop = ref(false);
|
||||
const { loading, data } = useAutoRequest(getLastTime, {
|
||||
pollingTime: 3000,
|
||||
initialData: {
|
||||
time: ''
|
||||
},
|
||||
async middleware(_, next) {
|
||||
await actionDelegationMiddleware('autoRequest:3')(_, () => Promise.resolve());
|
||||
if (!isStop.value) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const toggleStop = () => {
|
||||
isStop.value = !isStop.value;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSpace vertical>
|
||||
<NAlert type="info">
|
||||
{{ $t('page.alova.scenes.pollingRequestTips') }}
|
||||
</NAlert>
|
||||
<NButton type="primary" @click="toggleStop">
|
||||
<icon-carbon-play v-if="isStop" class="mr-2" />
|
||||
<icon-carbon-stop v-else class="mr-2" />
|
||||
{{ isStop ? $t('page.alova.scenes.startRequest') : $t('page.alova.scenes.stopRequest') }}
|
||||
</NButton>
|
||||
<NSpace align="center">
|
||||
<span>{{ $t('page.alova.scenes.refreshTime') }}: {{ data.time || '--' }}</span>
|
||||
<NSpin v-if="loading" :size="12" />
|
||||
</NSpace>
|
||||
</NSpace>
|
||||
</template>
|
||||
Reference in New Issue
Block a user