This commit is contained in:
吴先生 2023-07-14 13:21:01 +08:00
parent 6ea47ce850
commit 0ac3181dcd
3 changed files with 87 additions and 27 deletions

View File

@ -67,14 +67,13 @@
</template> </template>
</el-menu> </el-menu>
<el-icon <div
:size="24"
class="icon_switch" class="icon_switch"
@click="isCollapse = !isCollapse" @click="isCollapse = !isCollapse"
> >
<img src="../../assets/images/fold.png" alt="" v-if="isCollapse" /> <img src="../../assets/images/fold.png" alt="" v-if="isCollapse" />
<img src="../../assets/images/expand.png" alt="" v-else /> <img src="../../assets/images/expand.png" alt="" v-else />
</el-icon> </div>
</el-scrollbar> </el-scrollbar>
</el-aside> </el-aside>
<el-main class="content_main"> <el-main class="content_main">

View File

@ -11,6 +11,7 @@
size="medium" size="medium"
ref="formRef" ref="formRef"
@keyup.enter.native="handleSubmit" @keyup.enter.native="handleSubmit"
v-if="formPhoneIf"
> >
<el-form-item prop="user"> <el-form-item prop="user">
<el-input <el-input
@ -43,6 +44,31 @@
<span class="info1">&nbsp;</span> <span class="info1">&nbsp;</span>
</el-button> </el-button>
</el-form> </el-form>
<el-form
v-else
:model="dataPhone"
size="medium"
ref="formPhoneCodeRef"
:rules="rules"
@keyup.enter.native="handlePhoneSubmit"
>
<el-form-item> 验证码已发送至手机为{{ phone }} </el-form-item>
<el-form-item prop="phoneCode">
<el-input
v-model="dataPhone.phoneCode"
style="width: 100%"
placeholder="验证码"
prefix-icon="Lock"
></el-input>
</el-form-item>
<el-button
class="login-btn-submit"
type="primary"
@click="handlePhoneSubmit(formPhoneCodeRef)"
>
<span class="info1">&nbsp;</span>
</el-button>
</el-form>
</div> </div>
<slideVerify <slideVerify
v-show="slideVerifyShow" v-show="slideVerifyShow"
@ -69,6 +95,13 @@ const data = reactive({
password: "", password: "",
}); });
let phone = ref("");
const dataPhone = ref({
phoneCode: "", //
smsAuthCode: "", //
loginAuthCode: "",
});
console.log("paramsData", paramsData); console.log("paramsData", paramsData);
if (paramsData) { if (paramsData) {
console.log("存在"); console.log("存在");
@ -85,33 +118,15 @@ const slideVerifySuccess = () => {
slideVerifyShow.value = false; slideVerifyShow.value = false;
loading.value = true; loading.value = true;
var params = { var params = {
user: encrypt(data.user), loginName: encrypt(data.user),
password: encrypt(data.password), password: encrypt(data.password),
}; };
http.post("/api/auth/login", params).then((resp) => { http.post("/api/auth/login", params).then((resp) => {
if (resp.code == 200) { if (resp.code == 200) {
var user = { console.log(resp.data.loginAuthCode);
token: resp.data.token, phone.value = resp.data.phone;
name: resp.data.name, postPhoneCode(resp.data.loginAuthCode);
menus: resp.data.menus,
buttons: resp.data.buttons,
accountType: resp.data.accountType,
};
tools.data.set("user", user);
if (remembIf) {
tools.data.set("params", {
user: data.user,
password: data.password,
});
} else {
tools.data.remove("params");
}
ElMessage.success("登录成功");
//loading.value = false;
Router.push("/");
//
} else { } else {
ElMessage.error(resp.message); ElMessage.error(resp.message);
loading.value = false; loading.value = false;
@ -126,6 +141,52 @@ const handleSubmit = async () => {
} }
}); });
}; };
const postPhoneCode = (loginAuthCode) => {
var formData = new FormData();
dataPhone.value.loginAuthCode = loginAuthCode;
formData.append("loginAuthCode", loginAuthCode);
http.post("/api/auth/phone_code", formData).then((resp) => {
if (resp.code == 200) {
dataPhone.value.smsAuthCode = resp.data.smsAuthCode;
formPhoneIf.value = false;
}
});
};
const formPhoneIf = ref(true);
const formPhoneCodeRef = ref(null);
const rules = reactive({
phoneCode: [{ required: true, message: "请输入验证码", trigger: "blur" }],
});
const handlePhoneSubmit = (formEl) => {
if (!formEl) return;
formEl.validate((valid, fields) => {
if (valid) {
http.post("/api/auth/token", dataPhone.value).then((resp) => {
if (resp.code == 200) {
var user = {
token: resp.data.token,
name: resp.data.userInfo.userName,
menus: resp.data.menuList,
permissions: resp.data.permissions,
};
tools.data.set("user", user);
ElMessage.success("登录成功");
//loading.value = false;
Router.push("/");
//
} else {
ElMessage.error(resp.message);
}
});
} else {
console.log("error submit!", fields);
}
});
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.login_content { .login_content {

View File

@ -29,8 +29,8 @@ export default defineConfig({
proxy: { proxy: {
'/api': { '/api': {
// target: 'http://10.0.0.29:9999', // target: 'http://10.0.0.29:9999',
target: 'https://fywz.btdit.cn/', // target: 'https://fywz.btdit.cn/',
// target: 'http://10.0.0.65:7777/', // 刘进 target: 'http://10.0.0.63:7777', // 刘进
changeOrigin: true, changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '') // rewrite: (path) => path.replace(/^\/api/, '')
// ws: true,// 开启webSocket // ws: true,// 开启webSocket