parent
f1bda3fd50
commit
29b69d5138
@ -0,0 +1,11 @@
|
|||||||
|
import liff from "@line/liff";
|
||||||
|
|
||||||
|
async function initLiff(app) {
|
||||||
|
await liff.init({ liffId: process.env.VUE_APP_LINE_LIFF_ID });
|
||||||
|
if (!liff.isLoggedIn()){
|
||||||
|
liff.login({ redirectUri: window.location.href });
|
||||||
|
}
|
||||||
|
app.provide('liff', liff);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default initLiff;
|
||||||
@ -1,330 +1,343 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="reg-container">
|
<div class="reg-container">
|
||||||
<van-nav-bar :title="title" />
|
<van-nav-bar :title="title" />
|
||||||
<van-form @submit="onSubmit">
|
<van-form @submit="onSubmit">
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-field
|
<van-field
|
||||||
v-model="form.real_name"
|
v-model="form.real_name"
|
||||||
label="姓名"
|
label="姓名"
|
||||||
name="pattern"
|
name="pattern"
|
||||||
required
|
required
|
||||||
placeholder="請輸入您的姓名"
|
placeholder="請輸入您的姓名"
|
||||||
:rules="[{ required: true, message: '姓名為必填' }]"
|
:rules="[{ required: true, message: '姓名為必填' }]"
|
||||||
/>
|
/>
|
||||||
<van-field
|
<van-field
|
||||||
v-model="form.company"
|
v-model="form.company"
|
||||||
label="公司名稱"
|
label="公司名稱"
|
||||||
name=""
|
name=""
|
||||||
required
|
required
|
||||||
placeholder="請輸入您的公司名稱"
|
placeholder="請輸入您的公司名稱"
|
||||||
:rules="[{ required: true, message: '公司名稱必填' }]"
|
:rules="[{ required: true, message: '公司名稱必填' }]"
|
||||||
/>
|
/>
|
||||||
<van-field
|
<van-field
|
||||||
v-model="form.title"
|
v-model="form.title"
|
||||||
label="職稱"
|
label="職稱"
|
||||||
name=""
|
name=""
|
||||||
placeholder="請輸入您的職稱"
|
placeholder="請輸入您的職稱"
|
||||||
/>
|
/>
|
||||||
<van-field
|
<van-field
|
||||||
v-model="form.phone"
|
v-model="form.phone"
|
||||||
label="手機"
|
label="手機"
|
||||||
name=""
|
name=""
|
||||||
required
|
required
|
||||||
placeholder="Ex. 0900000001 不要有空格"
|
placeholder="Ex. 0900000001 不要有空格"
|
||||||
:rules="[{ required: true, message: '手機號必填' },{ pattern: /\d{10}/ , message: '手機號格式錯誤' }]"
|
:rules="[
|
||||||
/>
|
{ required: true, message: '手機號必填' },
|
||||||
<van-field
|
{ pattern: /\d{10}/, message: '手機號格式錯誤' },
|
||||||
v-model="form.tel"
|
]"
|
||||||
label="市話"
|
/>
|
||||||
name=""
|
<van-field
|
||||||
placeholder="請輸入您的市話"
|
v-model="form.tel"
|
||||||
/>
|
label="市話"
|
||||||
<van-field
|
name=""
|
||||||
v-model="form.email"
|
placeholder="請輸入您的市話"
|
||||||
label="Email"
|
/>
|
||||||
name=""
|
<van-field
|
||||||
required
|
v-model="form.email"
|
||||||
placeholder="請輸入您的Email"
|
label="Email"
|
||||||
:rules="[{ required: true, message: 'Email必填' },{ pattern: /^([\w\.\-]){1,64}\@([\w\.\-]){1,64}/ , message: 'Email格式錯誤' }]"
|
name=""
|
||||||
/>
|
required
|
||||||
<van-field
|
placeholder="請輸入您的Email"
|
||||||
v-model="form.address"
|
:rules="[
|
||||||
label="住址"
|
{ required: true, message: 'Email必填' },
|
||||||
name=""
|
{
|
||||||
placeholder="請輸入您的地址"
|
pattern: /^([\w\.\-]){1,64}\@([\w\.\-]){1,64}/,
|
||||||
/>
|
message: 'Email格式錯誤',
|
||||||
<van-field
|
},
|
||||||
v-model="form.url"
|
]"
|
||||||
label="網址"
|
/>
|
||||||
name=""
|
<van-field
|
||||||
placeholder="請輸入您的網址"
|
v-model="form.address"
|
||||||
:rules="[{ validator: validatorUrl, message: '網址格式不正確,Ex. http://' }]"
|
label="住址"
|
||||||
/>
|
name=""
|
||||||
<van-field
|
placeholder="請輸入您的地址"
|
||||||
v-model="form.line"
|
/>
|
||||||
label="Line"
|
<van-field
|
||||||
name=""
|
v-model="form.url"
|
||||||
placeholder="請輸入您的Line ID"
|
label="網址"
|
||||||
/>
|
name=""
|
||||||
<van-field
|
placeholder="請輸入您的網址"
|
||||||
v-model="form.facebook"
|
:rules="[
|
||||||
label="Facebook"
|
{ validator: validatorUrl, message: '網址格式不正確,Ex. http://' },
|
||||||
name=""
|
]"
|
||||||
placeholder="請輸入您的臉書連結"
|
/>
|
||||||
/>
|
<van-field
|
||||||
<van-field
|
v-model="form.line"
|
||||||
v-model="form.ig"
|
label="Line"
|
||||||
label="IG"
|
name=""
|
||||||
name=""
|
placeholder="請輸入您的Line ID"
|
||||||
placeholder="請輸入您的IG ID"
|
/>
|
||||||
/>
|
<van-field
|
||||||
<van-field
|
v-model="form.facebook"
|
||||||
v-model="form.youtube"
|
label="Facebook"
|
||||||
label="YouTube"
|
name=""
|
||||||
name=""
|
placeholder="請輸入您的臉書連結"
|
||||||
placeholder="請輸入您的Youtube連結"
|
/>
|
||||||
/>
|
<van-field
|
||||||
<van-uploader
|
v-model="form.ig"
|
||||||
:after-read="afterRead"
|
label="IG"
|
||||||
:max-count="1"
|
name=""
|
||||||
name="averter"
|
placeholder="請輸入您的IG ID"
|
||||||
>
|
/>
|
||||||
<div class="upload-main">
|
<van-field
|
||||||
<img class="upload-img" :src="form.avatar" alt="" v-if="form.avatar">
|
v-model="form.youtube"
|
||||||
<img class="upload-img" src="@/assets/images/upload.jpg" alt="" v-else>
|
label="YouTube"
|
||||||
<p>上傳圖片,預設為Line頭像</p>
|
name=""
|
||||||
</div>
|
placeholder="請輸入您的Youtube連結"
|
||||||
</van-uploader>
|
/>
|
||||||
</van-cell-group>
|
<van-uploader :after-read="afterRead" :max-count="1" name="averter">
|
||||||
<div style="margin: 16px;">
|
<div class="upload-main">
|
||||||
<van-button round block type="primary" native-type="submit">
|
<img
|
||||||
送出註冊
|
class="upload-img"
|
||||||
</van-button>
|
:src="form.avatar"
|
||||||
<br/>
|
alt=""
|
||||||
<van-button round block type="default" @click="leaveReg">
|
v-if="form.avatar"
|
||||||
以後在說
|
/>
|
||||||
</van-button>
|
<img
|
||||||
</div>
|
class="upload-img"
|
||||||
</van-form>
|
src="@/assets/images/upload.jpg"
|
||||||
|
alt=""
|
||||||
|
v-else
|
||||||
|
/>
|
||||||
|
<p>上傳圖片,預設為Line頭像</p>
|
||||||
|
</div>
|
||||||
|
</van-uploader>
|
||||||
|
</van-cell-group>
|
||||||
|
<div style="margin: 16px">
|
||||||
|
<van-button round block type="primary" native-type="submit">
|
||||||
|
送出註冊
|
||||||
|
</van-button>
|
||||||
|
<br />
|
||||||
|
<van-button round block type="default" @click="leaveReg">
|
||||||
|
以後在說
|
||||||
|
</van-button>
|
||||||
|
</div>
|
||||||
|
</van-form>
|
||||||
<van-overlay :show="crop.show" @click="crop.show = false" />
|
<van-overlay :show="crop.show" @click="crop.show = false" />
|
||||||
<div class="cropper-section" v-if="crop.show">
|
<div class="cropper-section" v-if="crop.show">
|
||||||
<div class="crop-area">
|
<div class="crop-area">
|
||||||
<cropper
|
<cropper
|
||||||
class="cropper"
|
class="cropper"
|
||||||
ref="myCrop"
|
ref="myCrop"
|
||||||
:src="crop.img"
|
:src="crop.img"
|
||||||
:stencil-props="{
|
:stencil-props="{
|
||||||
aspectRatio: 1/1
|
aspectRatio: 1 / 1,
|
||||||
}"
|
}"
|
||||||
:auto-zoom="true"
|
:auto-zoom="true"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="crop-btn">
|
<div class="crop-btn">
|
||||||
<van-button type="primary" size="small" plain @click="onClose">取消</van-button>
|
<van-button type="primary" size="small" plain @click="onClose"
|
||||||
<van-button type="success" size="small" plain @click="onCrop">剪裁</van-button>
|
>取消</van-button
|
||||||
|
>
|
||||||
|
<van-button type="success" size="small" plain @click="onCrop"
|
||||||
|
>剪裁</van-button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import axios from 'axios'
|
import axios from "axios";
|
||||||
|
|
||||||
|
import { ref, inject } from "vue";
|
||||||
|
|
||||||
import { ref } from 'vue'
|
import store from "@/store";
|
||||||
|
import router from "@/router";
|
||||||
|
import { useRoute } from "vue-router";
|
||||||
|
|
||||||
import store from '@/store'
|
import { Toast } from "vant";
|
||||||
import router from '@/router'
|
|
||||||
import { useRoute } from 'vue-router'
|
|
||||||
|
|
||||||
import {Toast} from 'vant'
|
import { Cropper } from "vue-advanced-cropper";
|
||||||
|
import "vue-advanced-cropper/dist/style.css";
|
||||||
|
|
||||||
import { Cropper } from 'vue-advanced-cropper';
|
import { register, checkLineId } from "@/api";
|
||||||
import 'vue-advanced-cropper/dist/style.css';
|
|
||||||
|
|
||||||
import { register , checkLineId } from '@/api'
|
|
||||||
|
|
||||||
const URL = window.URL || window.webkitURL;
|
const URL = window.URL || window.webkitURL;
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute();
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
verify: route.query.verify || null,
|
verify: route.query.verify || null,
|
||||||
aid: route.query.aid || undefined
|
aid: route.query.aid || undefined,
|
||||||
})
|
});
|
||||||
|
|
||||||
const title = ref('註冊成為會員')
|
const title = ref("註冊成為會員");
|
||||||
|
|
||||||
const myCrop = ref(null)
|
const myCrop = ref(null);
|
||||||
|
|
||||||
const crop = ref({
|
const crop = ref({
|
||||||
show: false,
|
show: false,
|
||||||
img: null,
|
img: null,
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
if(route.query.verify){
|
if (route.query.verify) {
|
||||||
title.value = '會員開通'
|
title.value = "會員開通";
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatorUrl = (val) => {
|
const validatorUrl = (val) => {
|
||||||
if(val.length>0){
|
if (val.length > 0) {
|
||||||
return /(https?:\/\/|line:\/\/|tel:|mailto:)\S+/.test(val)
|
return /(https?:\/\/|line:\/\/|tel:|mailto:)\S+/.test(val);
|
||||||
}else{
|
} else {
|
||||||
return true
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const leaveReg = () => {
|
||||||
|
window.location.replace("/error.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCrop = () => {
|
||||||
|
const { canvas } = myCrop.value.getResult();
|
||||||
|
if (canvas) {
|
||||||
|
const imgFile = new FormData();
|
||||||
|
canvas.toBlob(async (blob) => {
|
||||||
|
let ufile = new File([blob], "image.jpg");
|
||||||
|
imgFile.append("user_id", form.value.user_id);
|
||||||
|
imgFile.append("fileType", "IMAGE");
|
||||||
|
imgFile.append("file", ufile);
|
||||||
|
|
||||||
|
crop.value.show = false;
|
||||||
|
|
||||||
|
Toast.loading({
|
||||||
|
duration: 0,
|
||||||
|
message: "圖片上傳中...",
|
||||||
|
forbidClick: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
let res = await axios.post(
|
||||||
|
`${process.env.VUE_APP_API_URL}/user/uploadAvatar`,
|
||||||
|
imgFile,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res.data.code == 200) {
|
||||||
|
form.value.avatar = res.data.data;
|
||||||
|
Toast.success("上傳成功");
|
||||||
|
} else {
|
||||||
|
Toast.fail("上傳失敗");
|
||||||
|
}
|
||||||
|
}, "image/jpeg");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
const leaveReg = ()=>{
|
const onClose = () => {
|
||||||
window.location.replace('/error.html')
|
crop.value.show = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const afterRead = async (file, name) => {
|
||||||
|
crop.value.show = true;
|
||||||
|
|
||||||
const onCrop = () => {
|
const ofile = file.file;
|
||||||
const { canvas } = myCrop.value.getResult();
|
|
||||||
if (canvas) {
|
|
||||||
const imgFile = new FormData();
|
|
||||||
canvas.toBlob(async (blob) => {
|
|
||||||
let ufile = new File([blob], "image.jpg");
|
|
||||||
imgFile.append("user_id", form.value.user_id)
|
|
||||||
imgFile.append("fileType", "IMAGE")
|
|
||||||
imgFile.append('file', ufile)
|
|
||||||
|
|
||||||
crop.value.show = false
|
|
||||||
|
|
||||||
Toast.loading({
|
|
||||||
duration: 0,
|
|
||||||
message: '圖片上傳中...',
|
|
||||||
forbidClick: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
let res = await axios.post(
|
|
||||||
`${process.env.VUE_APP_API_URL}/user/uploadAvatar`,
|
|
||||||
imgFile,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (res.data.code == 200) {
|
|
||||||
form.value.avatar = res.data.data
|
|
||||||
Toast.success('上傳成功');
|
|
||||||
}else{
|
|
||||||
Toast.fail('上傳失敗');
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 'image/jpeg');
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const onClose = () =>{
|
|
||||||
crop.value.show = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const afterRead = async(file, name) => {
|
|
||||||
crop.value.show = true
|
|
||||||
|
|
||||||
const ofile = file.file
|
|
||||||
|
|
||||||
crop.value.img = URL.createObjectURL(ofile);
|
crop.value.img = URL.createObjectURL(ofile);
|
||||||
return
|
return;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
try{
|
const liff = window.liff;
|
||||||
if(!liff){
|
try {
|
||||||
console.log('liff is undefined')
|
if (!liff.isLoggedIn()) liff.login({ redirectUri: window.location.href });
|
||||||
Toast('系統錯誤,請重新登入')
|
} catch (err) {
|
||||||
router.push('/login')
|
console.log(`liff.state init error ${err}`);
|
||||||
}
|
Toast("登入失敗。請聯絡管理員");
|
||||||
}catch(e){
|
router.push("/login");
|
||||||
console.log(e.message)
|
}
|
||||||
Toast('系統錯誤,請重新登入')
|
|
||||||
router.push('/login')
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const profile = await liff.getProfile()
|
|
||||||
|
|
||||||
let checkRes = await checkLineId(profile.userId)
|
const profile = await liff.getProfile();
|
||||||
|
|
||||||
if(checkRes.code!==200){
|
|
||||||
Toast('您已是我們的會員,請直接登入')
|
|
||||||
router.push('/login')
|
|
||||||
}
|
|
||||||
|
|
||||||
const id_token = liff.getIDToken()
|
let checkRes = await checkLineId(profile.userId);
|
||||||
|
|
||||||
Toast.loading({
|
|
||||||
duration: 0,
|
|
||||||
message: '資料傳送中...',
|
|
||||||
forbidClick: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
let regRes = await register({line_id: profile.userId, token: id_token , ...form.value})
|
if (checkRes.code !== 200) {
|
||||||
|
Toast("您已是我們的會員,請直接登入");
|
||||||
|
router.push("/login");
|
||||||
|
}
|
||||||
|
|
||||||
if(regRes.code === 500){
|
const id_token = liff.getIDToken();
|
||||||
if (liff.isLoggedIn()) {
|
|
||||||
liff.logout();
|
Toast.loading({
|
||||||
}
|
duration: 0,
|
||||||
Toast('line 登入已過期')
|
message: "資料傳送中...",
|
||||||
// return router.push('/login')
|
forbidClick: true,
|
||||||
}else if(regRes.code === 200){
|
});
|
||||||
Toast('註冊成功')
|
|
||||||
sessionStorage.setItem('token',regRes.data.token)
|
let regRes = await register({
|
||||||
sessionStorage.setItem('uid',regRes.data.uid)
|
line_id: profile.userId,
|
||||||
return router.push('/')
|
line_name: profile.displayName,
|
||||||
}else{
|
line_picture: profile.pictureUrl,
|
||||||
Toast('註冊失敗')
|
token: id_token,
|
||||||
// return router.push('/login')
|
...form.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (regRes.code === 500) {
|
||||||
|
if (liff.isLoggedIn()) {
|
||||||
|
liff.logout();
|
||||||
}
|
}
|
||||||
}
|
Toast("line 登入已過期");
|
||||||
|
return;
|
||||||
|
} else if (regRes.code === 200) {
|
||||||
|
Toast("註冊成功");
|
||||||
|
sessionStorage.setItem("token", regRes.data.token);
|
||||||
|
sessionStorage.setItem("uid", regRes.data.uid);
|
||||||
|
return router.push("/");
|
||||||
|
} else {
|
||||||
|
Toast("註冊失敗");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.container{
|
.container {
|
||||||
padding-bottom: 30px;
|
padding-bottom: 30px;
|
||||||
}
|
}
|
||||||
.title{
|
.title {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-img{
|
.upload-img {
|
||||||
width: 80px;
|
width: 80px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cropper {
|
.cropper {
|
||||||
height: 300px;
|
height: 300px;
|
||||||
// width: 300px;
|
// width: 300px;
|
||||||
background: #DDD;
|
background: #ddd;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cropper-section{
|
.cropper-section {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
top: 50px;
|
top: 50px;
|
||||||
// left: 0;
|
// left: 0;
|
||||||
height: 350px;
|
height: 350px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
background: #DDD;
|
background: #ddd;
|
||||||
z-index: 8888;
|
z-index: 8888;
|
||||||
.crop-area{
|
.crop-area {
|
||||||
margin: 5 auto;
|
margin: 5 auto;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 330px;
|
height: 330px;
|
||||||
}
|
}
|
||||||
.crop-btn{
|
.crop-btn {
|
||||||
background-color: #666;
|
background-color: #666;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
Reference in new issue