0000815,未登入時需先登入

main
Wayne 2 years ago
parent 370963f653
commit db77b14659

@ -123,6 +123,12 @@ const routes = [
component: () => component: () =>
import("../views/Login/index.vue"), import("../views/Login/index.vue"),
}, },
{
path: "/actlogin",
name: "ActLogin",
component: () =>
import("../views/Login/actLogin.vue"),
},
{ {
path: "/test", path: "/test",
name: "Test", name: "Test",
@ -138,9 +144,10 @@ const router = createRouter({
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start(); NProgress.start();
if (to.path !== "/" && to.path !== "/login" && to.path !== "/register") { if (to.path !== "/" && to.path !== "/login" && to.path !== "/actlogin" && to.path !== "/register") {
if (!sessionStorage.getItem("token")) { if (!sessionStorage.getItem("token")) {
next("/"); sessionStorage.setItem("redirect", to.fullPath);
return next("/actlogin");
} }
// if(!store.state.user.userInfo){ // if(!store.state.user.userInfo){
@ -148,7 +155,7 @@ router.beforeEach((to, from, next) => {
// } // }
} }
next(); return next();
}); });
router.afterEach(() => { router.afterEach(() => {

@ -241,8 +241,6 @@ function genCard(vcard) {
"uri": "${vcard.nfcurl}&cardid=1" "uri": "${vcard.nfcurl}&cardid=1"
} }
}, },
{ {
"type": "box", "type": "box",
"layout": "vertical", "layout": "vertical",

@ -367,15 +367,10 @@ function genCard(vcard) {
"contents": [ "contents": [
{ {
"type": "text", "type": "text",
"text": "前端布魯", "text": "${vcard.title}",
"size": "md", "size": "md",
"weight": "bold", "weight": "bold",
"color": "#888888", "color": "#888888"
"action": {
"type": "uri",
"label": "action",
"uri": "https://utel.zltest.com.tw/card/?params=TE%2BoyUn0Yl7Vj76pKdp9VaL0LtXOVTpMx5BbbOvd1yM%3D&cardid=1"
}
} }
] ]
}, },
@ -439,7 +434,12 @@ function genCard(vcard) {
], ],
"paddingAll": "0px", "paddingAll": "0px",
"justifyContent": "center", "justifyContent": "center",
"alignItems": "center" "alignItems": "center",
"action": {
"type": "uri",
"label": "action",
"uri": "${vcard.nfcurl}&cardid=2"
}
} }
} }
} }

@ -337,13 +337,13 @@ function genCard(vcard) {
} }
], ],
"paddingAll": "0px", "paddingAll": "0px",
"justifyContent": "center",
"alignItems": "center",
"action": { "action": {
"type": "uri", "type": "uri",
"label": "action", "label": "action",
"uri": "https://utel.zltest.com.tw/card/?params=i7Kq7O59hPX1MJ%2Bqd8zQKBwuyc%2F%2BZ%2BZs%2BZXtXBy4zvg%3D&cardid=1" "uri": "${vcard.nfcurl}&cardid=3"
}, }
"justifyContent": "center",
"alignItems": "center"
} }
} }
} }

@ -0,0 +1,92 @@
<script setup>
import { login, bindCard } from "@/api";
import { useRouter, useRoute } from 'vue-router';
const route = useRoute();
const router = useRouter();
const liff = window.liff;
try {
if (!liff.isLoggedIn()) liff.login({ redirectUri: window.location.href });
} catch (err) {
console.log(`liff.state init error ${err}`);
showToast("登入失敗。請聯絡管理員");
router.push("/login");
}
if (!sessionStorage.getItem("token")) { //
const profile = await liff.getProfile();
const id_token = liff.getIDToken();
let loginRes = await login({ line_id: profile.userId, token: id_token });
if (loginRes.code === 200) {
if (route.query.act === "openright") {
showToast("您已經是本站會員");
}
sessionStorage.setItem("token", loginRes.data.token);
sessionStorage.setItem("uid", loginRes.data.uid);
} else if (loginRes.code === 202) { //
if (route.query.act === "openright") {
if (route.query.verify) {
//
Dialog.confirm({
title: "卡片綁定",
message: "確認是否綁定這張卡片",
})
.then(async () => {
//
let bindRes = await bindCard({
uid: loginRes.data.uid,
verify: route.query.verify,
});
if (bindRes.code === 200) {
showSuccessToast("綁定成功");
} else {
showToast.fail("綁定失敗");
}
})
.catch(() => { });
}
}
sessionStorage.setItem("token", loginRes.data.token);
sessionStorage.setItem("uid", loginRes.data.uid);
} else if (loginRes.code === 201) { //
if (route.query.act === "openright") { //
if (route.query.verify) {
router.push({
path: "/register",
query: {
verify: route.query.verify,
},
});
}
} else if (route.query.aid) { //
router.push({
path: "/register",
query: {
aid: route.query.aid,
},
});
} else {
showToast("請先註冊成為本站會員");
router.push({
path: "/register",
query: { refer: route.query.refer },
});
}
} else {
showToast("登入失敗。請聯絡管理員");
router.push("/login");
}
}
router.push(sessionStorage.getItem("redirect"));
sessionStorage.removeItem("redirect");
</script>
Loading…
Cancel
Save