-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(projects): login, antdv useApp, form
- Loading branch information
1 parent
ed68c8f
commit 53c2010
Showing
21 changed files
with
461 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script setup lang="ts"> | ||
import { App } from 'ant-design-vue'; | ||
import { defineComponent, createTextVNode } from 'vue'; | ||
defineOptions({ | ||
name: 'AppProvider' | ||
}); | ||
const ContextHolder = defineComponent({ | ||
name: 'ContextHolder', | ||
setup() { | ||
const { message, modal, notification } = App.useApp(); | ||
function register() { | ||
window.$message = message; | ||
window.$modal = modal; | ||
window.$notification = notification; | ||
} | ||
register(); | ||
}, | ||
render() { | ||
return createTextVNode(); | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<App class="h-full"> | ||
<ContextHolder /> | ||
<slot></slot> | ||
</App> | ||
</template> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const REG_USER_NAME = /^[\u4e00-\u9fa5a-zA-Z0-9_-]{4,16}$/; | ||
|
||
/** | ||
* phone reg | ||
*/ | ||
export const REG_PHONE = | ||
/^[1](([3][0-9])|([4][01456789])|([5][012356789])|([6][2567])|([7][0-8])|([8][0-9])|([9][012356789]))[0-9]{8}$/; | ||
|
||
/** | ||
* password reg | ||
* @description 6-18 characters, including letters, numbers, and underscores | ||
*/ | ||
export const REG_PWD = /^\w{6,18}$/; | ||
|
||
/** | ||
* email reg | ||
*/ | ||
export const REG_EMAIL = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; | ||
|
||
/** | ||
* six digit code reg | ||
*/ | ||
export const REG_CODE_SIX = /^\d{6}$/; | ||
|
||
/** | ||
* four digit code reg | ||
*/ | ||
export const REG_CODE_FOUR = /^\d{4}$/; | ||
|
||
/** | ||
* url reg | ||
*/ | ||
export const REG_URL = | ||
/(((^https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)$/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { ref } from 'vue'; | ||
import type { FormInstance } from 'ant-design-vue'; | ||
import { REG_USER_NAME, REG_PHONE, REG_PWD, REG_CODE_SIX, REG_EMAIL } from '@/constants/reg'; | ||
import { $t } from '@/locales'; | ||
|
||
export function useFormRules() { | ||
const constantRules = { | ||
userName: [ | ||
createRequiredRule($t('form.userName.required')), | ||
{ | ||
pattern: REG_USER_NAME, | ||
message: $t('form.userName.invalid'), | ||
trigger: 'change' | ||
} | ||
], | ||
phone: [ | ||
createRequiredRule($t('form.phone.required')), | ||
{ | ||
pattern: REG_PHONE, | ||
message: $t('form.phone.invalid'), | ||
trigger: 'change' | ||
} | ||
], | ||
pwd: [ | ||
createRequiredRule($t('form.pwd.required')), | ||
{ | ||
pattern: REG_PWD, | ||
message: $t('form.pwd.invalid'), | ||
trigger: 'change' | ||
} | ||
], | ||
code: [ | ||
createRequiredRule($t('form.code.required')), | ||
{ | ||
pattern: REG_CODE_SIX, | ||
message: $t('form.code.invalid'), | ||
trigger: 'change' | ||
} | ||
], | ||
email: [ | ||
createRequiredRule($t('form.email.required')), | ||
{ | ||
pattern: REG_EMAIL, | ||
message: $t('form.email.invalid'), | ||
trigger: 'change' | ||
} | ||
] | ||
} satisfies Record<string, App.Global.FormRule[]>; | ||
|
||
function createRequiredRule(message: string) { | ||
return { | ||
required: true, | ||
message | ||
}; | ||
} | ||
|
||
return { | ||
constantRules, | ||
createRequiredRule | ||
}; | ||
} | ||
|
||
export function useAntdForm() { | ||
const formRef = ref<FormInstance | null>(null); | ||
|
||
async function validate() { | ||
await formRef.value?.validate(); | ||
} | ||
|
||
return { | ||
formRef, | ||
validate | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './auth'; | ||
// export * from './route'; | ||
export * from './route'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { request } from '../request'; | ||
|
||
/** | ||
* get user routes | ||
* @param example whether to use example data, default: 0 | ||
*/ | ||
export function fetchGetUserRoutes(example: '0' | '1' = '0') { | ||
return request<App.Service.Response<Api.Route.UserRoute>>('/route/getUserRoute', { params: { example } }); | ||
} | ||
|
||
/** | ||
* whether the route is exist | ||
* @param routeName route name | ||
* @param example whether to use example data, default: 0 | ||
*/ | ||
export function fetchIsRouteExist(routeName: string, example: '0' | '1' = '0') { | ||
return request<App.Service.Response<boolean>>('/route/isRouteExist', { params: { routeName, example } }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { createAxios } from '@sa/request'; | ||
import { localStg } from '@/utils/storage'; | ||
import { createOfetch as createRequest } from '@sa/request'; | ||
import { createServiceConfig, createProxyPattern } from '~/env.config'; | ||
|
||
const { baseURL, otherBaseURL } = createServiceConfig(import.meta.env); | ||
|
||
const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y'; | ||
|
||
export const request = createAxios({ | ||
export const request = createRequest({ | ||
baseURL: isHttpProxy ? createProxyPattern() : baseURL, | ||
headers: { | ||
apifoxToken: 'XL299LiMEDZ0H5h3A29PxwQXdMJqWyY2' | ||
}, | ||
onRequest({ options }) { | ||
if (options.headers) { | ||
const token = localStg.get('token'); | ||
|
||
const Authorization = token ? `Bearer ${token}` : ''; | ||
|
||
Object.assign(options.headers, { Authorization }); | ||
} | ||
} | ||
}); | ||
|
||
export const demoRequest = createAxios({ baseURL: isHttpProxy ? createProxyPattern('demo') : otherBaseURL.demo }); | ||
export const demoRequest = createRequest({ baseURL: isHttpProxy ? createProxyPattern('demo') : otherBaseURL.demo }); |
Oops, something went wrong.