Skip to content

Commit

Permalink
wip: coding
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Jun 24, 2022
1 parent 537af57 commit 1878c2e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"echarts-wordcloud": "^2.0.0",
"element-plus": "2.2.6",
"intro.js": "^5.1.0",
"js-md5": "^0.7.3",
"lodash-es": "^4.17.21",
"mitt": "^3.0.0",
"mockjs": "^1.1.0",
Expand All @@ -59,6 +60,7 @@
"@intlify/vite-plugin-vue-i18n": "^3.4.0",
"@purge-icons/generated": "^0.8.1",
"@types/intro.js": "^3.0.2",
"@types/js-md5": "^0.4.3",
"@types/lodash-es": "^4.17.6",
"@types/node": "^18.0.0",
"@types/nprogress": "^0.2.0",
Expand Down
11 changes: 9 additions & 2 deletions src/api/register/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import { IUserModel } from '@/api-types/user'

const request = useAxios()

interface ICodeModel {
url: string
uuid: string
}

export const getCodeApi = async () => {
return (await request.get<IResponse<string>>({ url: 'user/captcha' })).data
const res = await request.get<IResponse<ICodeModel>>({ url: 'user/captcha' })
return res && res.data
}

export const registerApi = async (data: Omit<IUserModel, 'is_admin'>) => {
return (await request.post<IResponse<IUserModel>>({ url: 'user/register', data })).data
const res = await request.post<IResponse<IUserModel>>({ url: 'user/register', data })
return res && res.data
}
27 changes: 20 additions & 7 deletions src/views/Login/components/RegisterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ElButton, ElInput, FormRules, ElMessage } from 'element-plus'
import { getCodeApi, registerApi } from '@/api/register'
import { useValidator } from '@/hooks/web/useValidator'
import { IUserModel } from '@/api-types/user'
import md5 from 'js-md5'
import { cloneDeep } from 'lodash-es'
const emit = defineEmits(['to-login'])
Expand Down Expand Up @@ -99,7 +101,7 @@ const rules: FormRules = {
required('密码不能为空'),
{
validator: (_, value, callback) =>
lengthRange(value, callback, { min: 6, max: 20, message: '密码长度必须在6-20之间' })
lengthRange(value, callback, { min: 5, max: 20, message: '密码长度必须在5-20之间' })
},
{
validator: (_, value, callback) => notSpecialCharacters(value, callback, '密码不能是特殊字符')
Expand All @@ -109,7 +111,7 @@ const rules: FormRules = {
required('确认密码不能为空'),
{
validator: (_, value, callback) =>
lengthRange(value, callback, { min: 6, max: 20, message: '确认密码长度必须在6-20之间' })
lengthRange(value, callback, { min: 5, max: 20, message: '确认密码长度必须在5-20之间' })
},
{
validator: (_, value, callback) =>
Expand All @@ -130,9 +132,14 @@ const toLogin = () => {
}
const codeUrl = ref('')
const codeUuid = ref('')
const getCode = async () => {
const { result } = await getCodeApi()
codeUrl.value = result
const res = await getCodeApi()
if (res) {
const { url, uuid } = res.result
codeUrl.value = url
codeUuid.value = uuid
}
}
getCode()
Expand All @@ -145,8 +152,14 @@ const loginRegister = async () => {
try {
loading.value = true
const formData = await getFormData<Omit<IUserModel, 'is_admin'>>()
const { result } = await registerApi(formData)
if (result) {
const res = await registerApi(
Object.assign(cloneDeep(formData), {
uuid: codeUuid.value,
password: md5(formData.password),
check_password: md5(formData.check_password)
})
)
if (res) {
ElMessage.success('注册成功')
toLogin()
}
Expand Down Expand Up @@ -175,7 +188,7 @@ const loginRegister = async () => {
<template #code="form">
<div class="w-[100%] flex">
<ElInput v-model="form['code']" :placeholder="t('login.codePlaceholder')" class="flex-2" />
<div v-html="codeUrl" class="h-38px flex-1 cursor-pointer" @click="getCode"></div>
<div v-html="codeUrl" class="h-38px flex-1 cursor-pointer w-150px" @click="getCode"></div>
</div>
</template>

Expand Down
5 changes: 3 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function pathResolve(dir: string) {

// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
let env = null
let env = {} as any
const isBuild = command === 'build'
if (!isBuild) {
env = loadEnv((process.argv[3] === '--mode' ? process.argv[4] : process.argv[3]), root)
Expand Down Expand Up @@ -146,7 +146,8 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
'intro.js',
'qrcode',
'@wangeditor/editor',
'@wangeditor/editor-for-vue'
'@wangeditor/editor-for-vue',
'js-md5'
]
}
}
Expand Down

0 comments on commit 1878c2e

Please sign in to comment.