移除liff登入

main
Wayne Hsu 3 years ago
parent a84c5fd8b5
commit f517f1b385

@ -2,11 +2,9 @@ NODE_ENV = production
VUE_ENV = development
VUE_APP_BASE_URL = https://localhost:8080
# VUE_APP_BASE_URL = https://localhost:8080
VUE_APP_LINE_LIFF_ID = 1657876696-MKYDJKgm
VUE_APP_BASE_URL = https://5998-220-129-49-197.jp.ngrok.io
VUE_APP_BASE_URL = https://557d-220-129-38-157.jp.ngrok.io
VUE_APP_SEND_URL = https://liff.line.me/1657876696-MKYDJKgm
@ -16,4 +14,8 @@ VUE_APP_SSO_URL = https://sso.h888.fun/api/v1
VUE_APP_IMAGE_URL = https://card.h888.fun/storage
VUE_APP_DOMAIN = localhost
VUE_APP_DOMAIN = 557d-220-129-38-157.jp.ngrok.io
VUE_APP_LINE_CLINE_ID = 1657876696
VUE_APP_LINE_LIFF_ID = 1657876696-MKYDJKgm

@ -4,8 +4,6 @@ VUE_ENV = slash
VUE_APP_BASE_URL = https://card.h888.fun
VUE_APP_LINE_LIFF_ID = 1657876696-MKYDJKgm
VUE_APP_SEND_URL = https://liff.line.me/1657876696-564NGMxy
VUE_APP_API_URL = https://card.h888.fun/appapi/v1
@ -15,3 +13,7 @@ VUE_APP_SSO_URL = https://sso.h888.fun/api/v1
VUE_APP_IMAGE_URL = https://card.h888.fun/storage
VUE_APP_DOMAIN = h888.fun
VUE_APP_LINE_CLINE_ID = 1657876696
VUE_APP_LINE_LIFF_ID = 1657876696-MKYDJKgm

13
package-lock.json generated

@ -10,9 +10,10 @@
"dependencies": {
"@line/liff": "^2.18.2",
"@soerenmartius/vue3-clipboard": "^0.1.2",
"colorthief": "^2.3.2",
"axios": "^1.3.3",
"colorthief": "^2.3.2",
"core-js": "^3.6.5",
"ismobilejs": "^1.1.1",
"js-cookie": "^3.0.1",
"lodash": "^4.17.21",
"moment": "^2.29.1",
@ -9308,6 +9309,11 @@
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true
},
"node_modules/ismobilejs": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ismobilejs/-/ismobilejs-1.1.1.tgz",
"integrity": "sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw=="
},
"node_modules/isobject": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
@ -23426,6 +23432,11 @@
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true
},
"ismobilejs": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ismobilejs/-/ismobilejs-1.1.1.tgz",
"integrity": "sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw=="
},
"isobject": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",

@ -13,9 +13,10 @@
"dependencies": {
"@line/liff": "^2.18.2",
"@soerenmartius/vue3-clipboard": "^0.1.2",
"colorthief": "^2.3.2",
"axios": "^1.3.3",
"colorthief": "^2.3.2",
"core-js": "^3.6.5",
"ismobilejs": "^1.1.1",
"js-cookie": "^3.0.1",
"lodash": "^4.17.21",
"moment": "^2.29.1",

@ -10,12 +10,7 @@
</template>
<script setup>
import { getSiteConfig } from './api'
import { useStore } from 'vuex'
const store = useStore()
// import { getSiteConfig } from './api';
</script>
<style lang="less">

@ -8,14 +8,23 @@ import { VueClipboard } from "@soerenmartius/vue3-clipboard";
import "@/assets/css/normalize.css";
import "@/assets/css/common.less";
import Cookies from "js-cookie";
// import './registerServiceWorker'
(function init(){
//使用URLSearchParams API取得query string的refer參數,並寫到Cookie
const urlParams = new URLSearchParams(window.location.search);
//取得refer參數
const refer = urlParams.get('refer');
(async function initLiff(){
// await liff.init({ liffId: process.env.VUE_APP_LINE_LIFF_ID });
//將refer參數寫入Cookie
if(!Cookies.get('refer_code') && refer){
Cookies.set('refer_code', refer, { expires: 1 });
}
})()
const vue = createApp(App);
vant(vue);

@ -147,9 +147,9 @@ const router = createRouter({
router.beforeEach((to, from, next) => {
NProgress.start();
if (to.path !== "/" && to.path !== "/login" && to.path !== "/register" && to.path !== "/linelogin/" && to.path !== "/linelogin") {
if ( to.path !== "/login" && to.path !== "/register" && to.path !== "/linelogin/" && to.path !== "/linelogin") {
if (!Cookies.get("token")) {
Toast('請重新登入')
Toast('請重新登入,(0001)')
next("/login")
}

@ -10,3 +10,11 @@ function nl2br(str, is_xhtml) {
);
}
export function isMobile() {
try {
document.createEvent("TouchEvent"); return true;
} catch(e) {
return false;
}
}

@ -192,103 +192,96 @@ const is_due = ref(false)
onBeforeMount(async () => {
await liff.init({ liffId: process.env.VUE_APP_LINE_LIFF_ID });
// await liff.init({ liffId: process.env.VUE_APP_LINE_LIFF_ID });
if (!Cookies.get('token')) {
try {
if (!liff.isLoggedIn()){
liff.login({ redirectUri: window.location.href });
}
} catch (err) {
console.log(`liff.state init error ${err}`);
Toast('登入失敗。請聯絡管理員,(1001)')
router.push('/login')
}
const profile = await liff.getProfile()
const id_token = liff.getIDToken()
// if (!Cookies.get('token')) {
// try {
// if (!liff.isLoggedIn()){
// liff.login({ redirectUri: window.location.href });
// }
// } catch (err) {
// console.log(`liff.state init error ${err}`);
// Toast(',(1001)')
// router.push('/login')
// }
let loginRes = await linelogin({ line_id: profile.userId, token: id_token })
// const profile = await liff.getProfile()
// const id_token = liff.getIDToken()
if (loginRes.code === 200) {
if (route.query.act === 'openright') {
Toast('您已經是本站會員')
}
Cookies.set('token', loginRes.data.token,{ expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
Cookies.set('uid', loginRes.data.uid,{ expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
} 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){
Toast.success('綁定成功')
}else{
Toast.fail('綁定失敗')
}
}).catch(()=>{
// let loginRes = await linelogin({ line_id: profile.userId, token: id_token })
})
}
}
Cookies.set('token', loginRes.data.token, { expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
Cookies.set('uid', loginRes.data.uid, { expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
// if (loginRes.code === 200) {
// if (route.query.act === 'openright') {
// Toast('')
// }
// Cookies.set('token', loginRes.data.token,{ expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
// Cookies.set('uid', loginRes.data.uid,{ expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
// } 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){
// Toast.success('')
// }else{
// Toast.fail('')
// }
// }).catch(()=>{
} else if (loginRes.code === 201) {
if (route.query.act === 'openright') {
if (route.query.verify) {
router.push({
path: '/register',
query: {
verify: route.query.verify
}
})
// })
// }
// }
return
}
} else if (route.query.aid) {
router.push({
path: '/register',
query: {
aid: route.query.aid
}
})
return
} else {
Toast('請先註冊成為本站會員')
return router.push({
path: '/register',
query: { refer: route.query.refer }
})
}
// Cookies.set('token', loginRes.data.token, { expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
// Cookies.set('uid', loginRes.data.uid, { expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
// } else if (loginRes.code === 201) {
// if (route.query.act === 'openright') {
// if (route.query.verify) {
// router.push({
// path: '/register',
// query: {
// verify: route.query.verify
// }
// })
// return
// }
// } else if (route.query.aid) {
// router.push({
// path: '/register',
// query: {
// aid: route.query.aid
// }
// })
// return
// } else {
// Toast('')
// return router.push({
// path: '/register',
// query: { refer: route.query.refer }
// })
// }
} else {
Toast('登入失敗。請聯絡管理員,(1002)')
router.push('/login')
}
}
// } else if (loginRes.code === 401) { //token
// handleLogout()
// Toast('(1002)')
// router.push('/login')
// } else {
// Toast(',(1003)')
// router.push('/login')
// }
// }
store.dispatch('user/getUserInfo')
//
nextTick(() => {
// if(userInfo.value.level===0 && userInfo.value.nc_type===0){
// Toast('')
// return router.push('/shop/inputsn')
// }
})
})
@ -347,9 +340,11 @@ const bindTggo = () => {
}
const handleLogout = () => {
console.log({ domain: process.env.VUE_APP_DOMAIN})
Cookies.remove('token',{ domain: process.env.VUE_APP_DOMAIN})
Cookies.remove('uid',{ domain: process.env.VUE_APP_DOMAIN})
// if (liff.isLoggedIn()) {
// liff.logout()
// }
router.push('/login')
}

@ -19,7 +19,7 @@ const code = route.query.code
if(!code){
router.replace('/login')
}else{
const client_id = '1657876696'
const client_id = process.env.VUE_APP_LINE_CLINE_ID
const redirect_uri = `${process.env.VUE_APP_BASE_URL}/home/linelogin`
axios.post('https://api.line.me/oauth2/v2.1/token',new URLSearchParams({

@ -72,16 +72,16 @@ const handleLogin = async ()=>{
}
const handleLineLogin = async () => {
router.push('/')
// const client_id = '1657876696'
// const redirect_uri = ''
// let link = 'https://access.line.me/oauth2/v2.1/authorize?'
// link = link + 'response_type=code'
// link += '&client_id=' + client_id
// link += '&redirect_uri=' + redirect_uri
// link += '&state=login'
// link += '&scope=openid%20profile'
// window.location.href = link
// router.push('/')
const client_id = process.env.VUE_APP_LINE_CLINE_ID
const redirect_uri = process.env.VUE_APP_BASE_URL + '/home/linelogin'
let link = 'https://access.line.me/oauth2/v2.1/authorize?'
link = link + 'response_type=code'
link += '&client_id=' + client_id
link += '&redirect_uri=' + redirect_uri
link += '&state=login'
link += '&scope=openid%20profile'
window.location.href = link
}
</script>

@ -150,29 +150,8 @@ const afterRead = async(file, name) => {
const onSubmit = async () => {
try{
if(!liff){
console.log('liff is undefined')
Toast('系統錯誤,請重新登入')
router.push('/login')
}
}catch(e){
console.log(e.message)
Toast('系統錯誤,請重新登入')
router.push('/login')
}
const profile = await liff.getProfile()
let checkRes = await checkLineId(profile.userId)
if(checkRes.code!==200){
Toast('您已是我們的會員,請直接登入')
router.push('/login')
}
const id_token = liff.getIDToken()
let { id_token } = JSON.parse(sessionStorage.getItem('line'))
Toast.loading({
duration: 0,
@ -180,14 +159,15 @@ const onSubmit = async () => {
forbidClick: true,
});
let regRes = await register({line_id: profile.userId, token: id_token , ...form.value})
if(Cookies.get('refer_code')){
form.value.refer_code = Cookies.get('refer_code')
}
let regRes = await register({token: id_token , ...form.value})
if(regRes.code === 500){
if (liff.isLoggedIn()) {
liff.logout();
}
Toast('line 登入已過期')
// return router.push('/login')
return router.push('/login')
}else if(regRes.code === 200){
Toast('註冊成功')
Cookies.set('token',regRes.data.token, { expires: 365 ,domain: process.env.VUE_APP_DOMAIN})
@ -195,7 +175,7 @@ const onSubmit = async () => {
return router.push('/')
}else{
Toast('註冊失敗')
// return router.push('/login')
return router.push('/login')
}
}

@ -20,7 +20,7 @@
<div class="preview-text">上面圖內分享無效請點下列分享</div>
</div>
<div class="btn-area" @click="sendEcard">
<van-button type="primary" block>分享好友</van-button>
<van-button type="primary" block>發送名片</van-button>
</div>
<div class="btn-area" @click="showChangeTpl" v-show="activeName == '0'">
<van-button type="success" block>切換樣版</van-button>
@ -47,6 +47,7 @@
<script setup>
import liff from "@line/liff";
import Cookies from 'js-cookie'
import isMobile from 'ismobilejs'
import { Toast } from 'vant';
@ -54,6 +55,7 @@ import { onMounted, reactive, ref, toRefs, computed, watch } from 'vue'
import { getCard, getCusCard, getVipCard, updateSendCount } from '@/api'
import { cardFactory } from '@/utils/card'
import { genCard1 } from '@/utils/card2'
@ -82,10 +84,9 @@ const userInfo = computed(() => {
})
onMounted(async () => {
// console.log('liff',liff)
await liff.init({ liffId: process.env.VUE_APP_LINE_LIFF_ID });
if (userInfo.value.nc_type > 2) {
if (userInfo.value.level > 1) {
let vipCardRes = await getVipCard({ userid: Cookies.get('uid') })
state.value.vip_card = vipCardRes.data
} else {
@ -101,7 +102,7 @@ watch(() => activeName.value, function (newVal, oldVal) {
}, { immediate: true })
watch(() => userInfo.value.cus_card, function (newVal, oldVal) {
if (userInfo.value.nc_type > 1 && newVal.length > 0) {
if (userInfo.value.level > 0 && newVal.length > 0) {
state.value.showCusCard = true
}
}, { immediate: true })
@ -123,7 +124,7 @@ async function showFlex(id) {
flex2html("flex", state.value.flexContent)
break
case '1':
if (userInfo.value.nc_type > 1) {
if (userInfo.value.level > 0) {
let card2Res = await getCusCard({ userid: Cookies.get('uid') })
if (card2Res.code === 200) {
if (card2Res.data.cus_card) {
@ -137,7 +138,7 @@ async function showFlex(id) {
}
break
default:
if (userInfo.value.nc_type > 2) {
if (userInfo.value.level > 0) {
// let vipCardRes = await getCusCard({userid: sessionStorage.getItem('uid')})
let res = state.value.vip_card.find(item => { return item.id == id })
if (res.type === 0) {
@ -162,11 +163,17 @@ async function showFlex(id) {
break
}
}
// const sendEcard = async () => {
const sendEcard = async () => {
let isMo = isMobile().any
// window.location.href = 'https://liff.line.me/1657876696-564NGMxy?userid=sc63e7880cd0b65&cardid=1'
// }
if(isMo){
window.location.href = `https://line.me/R/app/1657876696-564NGMxy?userid=${userInfo.value.user_id}&cardid=${parseInt(activeName.value) + 1}`
}else{
window.location.href = `https://liff.line.me/1657876696-564NGMxy?userid=${userInfo.value.user_id}&cardid=${parseInt(activeName.value) + 1}`
}
}
const sendEcard = async () => {
const sendEcard1 = async () => {
if (!liff.isLoggedIn()) {
liff.login({ redirectUri: window.location.href })
}

@ -5567,6 +5567,11 @@
"resolved" "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz"
"version" "2.0.0"
"ismobilejs@^1.1.1":
"integrity" "sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw=="
"resolved" "https://registry.npmjs.org/ismobilejs/-/ismobilejs-1.1.1.tgz"
"version" "1.1.1"
"isobject@^2.0.0":
"integrity" "sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk="
"resolved" "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz"

Loading…
Cancel
Save