login重构
This commit is contained in:
parent
970f013f7a
commit
0a0b2fed2e
|
|
@ -87,24 +87,28 @@
|
|||
</el-row>
|
||||
<div>
|
||||
<div class="qrcode" ref="qrCodeUrl"></div>
|
||||
<vue-qr :logoSrc="imageUrl" text="https://blog.csdn.net/weixin_42601136" :size="200"></vue-qr>
|
||||
<vue-qr
|
||||
:logoSrc="imageUrl"
|
||||
text="https://blog.csdn.net/weixin_42601136"
|
||||
:size="200"
|
||||
></vue-qr>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, inject } from "vue";
|
||||
import { ref, onMounted, inject } from "vue";
|
||||
import axios from "axios";
|
||||
import { getQRService, getUUIDService, loginService, registerService } from "@/api/user.js";
|
||||
import router from "@/router/index.js";
|
||||
import VueQr from 'vue-qr'
|
||||
import VueQr from 'vue-qr'; // 确保你已经注册了这个组件
|
||||
|
||||
export default {
|
||||
components: {
|
||||
VueQr, // 注册 VueQr 组件
|
||||
},
|
||||
setup() {
|
||||
const isLogin = ref(true);
|
||||
if (localStorage.getItem("token") !== null) {
|
||||
router.push("/videoList");
|
||||
}
|
||||
|
||||
|
||||
const globalData = inject("globalData");
|
||||
|
||||
var uuid = "";
|
||||
//表单数据
|
||||
var loginData = ref({
|
||||
|
|
@ -112,7 +116,7 @@ var loginData = ref({
|
|||
email: "lijun.lj@foxmail.com",
|
||||
password: "",
|
||||
ip:"",
|
||||
});
|
||||
});l
|
||||
const registerData = ref({
|
||||
username: "",
|
||||
email: "",
|
||||
|
|
@ -142,6 +146,14 @@ const rules = {
|
|||
],
|
||||
email: [{}],
|
||||
};
|
||||
onMounted(() => {
|
||||
const token = localStorage.getItem("token");
|
||||
if (token !== null) {
|
||||
isLogin.value = true; // 更新登录状态
|
||||
router.push("/videoList"); // 跳转到视频列表页面
|
||||
// 你可以在这里获取 UID 并更新 uid.value
|
||||
}
|
||||
});
|
||||
|
||||
const creatQrCode =async () =>{
|
||||
var qrcode = new qrcode(this.$refs.qrCodeUrl, {
|
||||
|
|
@ -156,24 +168,6 @@ const creatQrCode =async () =>{
|
|||
|
||||
//登录接口调用
|
||||
const login = async () => {
|
||||
// let req = axios.create({
|
||||
// baseURL: "/api",
|
||||
// timeout: 5000,
|
||||
// });
|
||||
// await req
|
||||
// .post("/user/login", {
|
||||
// email: loginData.value.username,
|
||||
// password: loginData.value.password,
|
||||
// })
|
||||
// .then((response) => {
|
||||
// alert(response.data.message);
|
||||
// resp = response.data;
|
||||
// jwt = resp.data;
|
||||
// console.log(jwt);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.error(error);
|
||||
// });
|
||||
let result = await loginService(loginData);
|
||||
globalData.token = result.data;
|
||||
localStorage.setItem("token", result.data.token);
|
||||
|
|
@ -184,7 +178,6 @@ const login = async () => {
|
|||
//token.value= result.data;
|
||||
router.push("/videoList");
|
||||
};
|
||||
|
||||
const getUUID= async() => {
|
||||
try {
|
||||
const response = await getUUIDService({"device":"windows"});
|
||||
|
|
@ -246,4 +239,7 @@ const register = async () => {
|
|||
alert(result.message);
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue