import { NForm, NFormItem, NInput, NButton } from 'naive-ui' import { setStorage } from '@/utils' import { useI18n } from '@/hooks/web' import { APP_CATCH_KEY } from '@/app-config/appConfig' import { setVariable, getVariableToRefs } from '@/global-variable' import { useSigningActions } from '@/store' import { useAppRoot } from '@/hooks/template' import type { FormInst } from 'naive-ui' export default defineComponent({ name: 'RSigning', setup() { const loginFormRef = ref() const { t } = useI18n() const { signing } = useSigningActions() const { getRootPath } = useAppRoot() const globalSpinning = getVariableToRefs('globalSpinning') const useSigningForm = () => ({ name: 'Ray Admin', pwd: '123456', }) const router = useRouter() const signingForm = ref(useSigningForm()) const rules = { name: { required: true, message: t('views.login.index.NamePlaceholder'), trigger: ['blur', 'input'], }, pwd: { required: true, message: t('views.login.index.PasswordPlaceholder'), trigger: ['blur', 'input'], }, } /** 普通登陆形式 */ const handleLogin = () => { loginFormRef.value?.validate((valid) => { if (!valid) { setVariable('globalSpinning', true) signing(signingForm.value) .then((res) => { if (res.code === 0) { setTimeout(() => { setVariable('globalSpinning', false) window.$message.success(`欢迎${signingForm.value.name}登陆~`) setStorage(APP_CATCH_KEY.token, 'tokenValue') setStorage(APP_CATCH_KEY.signing, res.data) router.push(getRootPath.value) }, 2 * 1000) } }) .catch(() => { window.$message.error('不可以这样哟, 不可以哟') }) } }) } return { signingForm, loginFormRef, handleLogin, rules, globalSpinning, } }, render() { const { $t, globalSpinning } = this return ( {$t('views.login.index.Login')} ) }, })