From eb52624b4ea5303198d4dddc19a3366c87283ff3 Mon Sep 17 00:00:00 2001 From: yangfeng <wanwan926_4@163.com> Date: 星期一, 05 二月 2024 17:50:44 +0800 Subject: [PATCH] 登录页面接口联调 --- vite.config.ts | 2 src/stores/craftModel.ts | 2 - src/views/login/loginView.vue | 41 +++++++++++++++----- src/api/index.ts | 27 +++++++++++++ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 75758a4..03bbe0e 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -263,3 +263,30 @@ data: params }) } + +/** + * 鑾峰彇楠岃瘉鐮� + */ +export function getCaptcha() { + return request({ + url: '/api/base/captcha', + method: 'post' + }) +} + +export interface loginParams { + username: string + password: string + captcha: string + captchaId: string +} +/** + * 鐧诲綍 + */ +export function login(params: loginParams) { + return request({ + url: '/api/base/login', + method: 'post', + data: params + }) +} diff --git a/src/stores/craftModel.ts b/src/stores/craftModel.ts index b1e86fc..fddaddc 100644 --- a/src/stores/craftModel.ts +++ b/src/stores/craftModel.ts @@ -13,7 +13,6 @@ function getCraftModelList() { if (taskStore.activeTask?.Procedure.ID) { craftModelList.value = [] - console.log(taskStore, '8877994455') const procedureModel = taskStore.activeTask?.ProcedureModel const craftObj = [ { @@ -61,7 +60,6 @@ if (taskStore.activeTask?.Procedure.ID && !loading.value && hasMore.value) { page.value++ loading.value = true - console.log(taskStore, '998877994455') // apiGetCraftModelList({ // procedureId: taskStore.activeTask?.Procedure.ID, // page: page.value, diff --git a/src/views/login/loginView.vue b/src/views/login/loginView.vue index 2c768ed..533d652 100644 --- a/src/views/login/loginView.vue +++ b/src/views/login/loginView.vue @@ -20,7 +20,7 @@ /> </el-form-item> <el-form-item label="" prop="code"> - <el-input v-model="ruleForm.code" autocomplete="off" style="width: 70%"> </el-input> + <el-input v-model="ruleForm.code" placeholder="楠岃瘉鐮�" autocomplete="off" style="width: 70%"> </el-input> <img class="login-code" :src="captcha" @click="getCaptchaData" /> </el-form-item> <el-form-item> @@ -35,7 +35,10 @@ <script setup lang="ts"> import { ref, reactive, onMounted } from 'vue' import type { FormInstance, FormRules } from 'element-plus' -import { getCaptcha } from '@/api' +import { getCaptcha, login } from '@/api' +import { setToken } from '@/common/utils/index' +import { ElMessage } from 'element-plus' +import { useRouter } from 'vue-router' const ruleFormRef = ref<FormInstance>() @@ -72,23 +75,19 @@ }) const captcha = ref('') +const captchaId = ref('') const getCaptchaData = () => { getCaptcha().then((rsp) => { if (rsp.code == 200) { - this.captchaId = rsp.data.captchaId - this.captcha = rsp.data.picPath + captcha.value = rsp.data.picPath + captchaId.value = rsp.data.captchaId } }) } onMounted(() => { // 鑾峰彇楠岃瘉鐮� - getCaptcha().then((rsp) => { - if (rsp.code == 200) { - this.captchaId = rsp.data.captchaId - this.captcha = rsp.data.picPath - } - }) + getCaptchaData() }) const rules = reactive<FormRules<typeof ruleForm>>({ @@ -97,11 +96,31 @@ accountNumber: [{ validator: checkAge, trigger: 'blur' }] }) +const router = useRouter() + const submitForm = (formEl: FormInstance | undefined) => { if (!formEl) return formEl.validate((valid) => { if (valid) { - console.log('submit!') + login({ + username: ruleForm.accountNumber, + password: ruleForm.pass, + captcha: ruleForm.code, + captchaId: captchaId.value + }).then((rsp) => { + if (rsp.code == 200) { + console.log(rsp) + setToken(rsp.token) + ElMessage({ + message: '鐧诲綍鎴愬姛锛�', + type: 'success' + }) + ruleForm.accountNumber = '' + ruleForm.pass = '' + ruleForm.code = '' + router.push('/') + } + }) } else { console.log('error submit!') return false diff --git a/vite.config.ts b/vite.config.ts index f8c66bf..d1c84cd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -24,7 +24,7 @@ }, '/api': { // http://192.168.20.119:8003 http://192.168.20.25:7010 - target: 'http://192.168.20.118:8001', + target: 'http://192.168.20.119:8001', ws: true, changeOrigin: true } -- Gitblit v1.8.0