|
|
@@ -43,6 +43,10 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
+import { setToken } from "@/utils/auth"; // get token from cookie
|
|
|
+import { login, lineLogin } from "@/api/login.js";
|
|
|
+import Cookies from 'js-cookie'
|
|
|
+
|
|
|
export default {
|
|
|
name: "App",
|
|
|
computed: {
|
|
|
@@ -53,6 +57,106 @@ export default {
|
|
|
return this.$store.state.app.navbarType;
|
|
|
},
|
|
|
},
|
|
|
+ data: () => ({
|
|
|
+ api_loading: false,
|
|
|
+ initialized: false,
|
|
|
+ loggedIn: false,
|
|
|
+ inClient: false,
|
|
|
+ name: "",
|
|
|
+ userId: "",
|
|
|
+ pictureUrl: "",
|
|
|
+ }),
|
|
|
+ created: function() {
|
|
|
+ console.log(`process.env.ENV: ${process.env.ENV}`)
|
|
|
+ console.log(`process.env.VUE_APP_LIFF_ID: ${process.env.VUE_APP_LIFF_ID}`)
|
|
|
+ },
|
|
|
+ mounted: function() {
|
|
|
+ this.initializeLiff()
|
|
|
+ if (process.env.ENV != 'production') {
|
|
|
+ this.initVConsole()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ initializeLiff: function () {
|
|
|
+ this.api_loading = true
|
|
|
+ liff.init(
|
|
|
+ {
|
|
|
+ liffId: process.env.VUE_APP_LIFF_ID,
|
|
|
+ withLoginOnExternalBrowser: true,
|
|
|
+ },
|
|
|
+ data => {
|
|
|
+ this.initialized = true
|
|
|
+ this.loggedIn = liff.isLoggedIn()
|
|
|
+ this.inClient = liff.isInClient()
|
|
|
+ this.api_loading = false
|
|
|
+ },
|
|
|
+ err => {
|
|
|
+ console.log('LIFF initialization failed', err)
|
|
|
+ this.api_loading = false
|
|
|
+ }
|
|
|
+ ).then(() => {
|
|
|
+ // Start to use liff's api
|
|
|
+ liff
|
|
|
+ .getProfile().then(profile => {
|
|
|
+ this.name = profile.displayName
|
|
|
+ this.pictureUrl = profile.pictureUrl
|
|
|
+ this.userId = profile.userId
|
|
|
+ //application login
|
|
|
+ //console.log(`profile.userId: ${this.userId}`)
|
|
|
+ //console.log(`AccessToken: ${liff.getAccessToken()}`)
|
|
|
+ this.logins()
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(`Error at getProfile: ${err}`)
|
|
|
+ this.name = ""
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
+ initVConsole: async function() {
|
|
|
+ window.vConsole = new window.VConsole({
|
|
|
+ defaultPlugins: ['system', 'network', 'element', 'storage'],
|
|
|
+ maxLogNumber: 1000,
|
|
|
+ onReady: function () {
|
|
|
+ console.log('vConsole is ready.')
|
|
|
+ },
|
|
|
+ onClearLog: function () {
|
|
|
+ console.log('on clearLog')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ doLogout: function() {
|
|
|
+ if (liff.isLoggedIn()) {
|
|
|
+ liff.logout()
|
|
|
+ this.loggedIn = false
|
|
|
+ window.location.reload()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ logins: function () {
|
|
|
+ let requer = {
|
|
|
+ username: this.userId,
|
|
|
+ password: '',
|
|
|
+ name : this.name,
|
|
|
+ deptId : this.$route.query.busid,
|
|
|
+ };
|
|
|
+ //获取token
|
|
|
+ this.$store
|
|
|
+ .dispatch("user/LineLogin", requer)
|
|
|
+ .then(() => {
|
|
|
+ //Cookies.set('phone',this.loginForm.phone);
|
|
|
+ // Cookies.set('password',this.loginForm.password);
|
|
|
+ // 获取用户信息
|
|
|
+ this.$store.dispatch("user/GetInfo").then((res) => {
|
|
|
+ if(res.code==200){
|
|
|
+ //this.$router.push({ path: "/" }).catch(() => {});
|
|
|
+ console.log(`line login ok.`)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(`linelogin Error at logins: ${err}`)
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ }
|
|
|
};
|
|
|
//这里做一个rem的fong-size的适应 默认size是1rem=100px 默认设计图是375的
|
|
|
var windowWidth = document.documentElement.getBoundingClientRect().width;
|
|
|
@@ -60,6 +164,7 @@ windowWidth = windowWidth > 750 ? 750 : windowWidth;
|
|
|
var fontSize = windowWidth / 3.75;
|
|
|
document.documentElement.style.fontSize = fontSize + "px";
|
|
|
// store.state.app.navbarShow
|
|
|
+
|
|
|
</script>
|
|
|
<style lang="scss">
|
|
|
#app {
|