add login
This commit is contained in:
1 parent
1ac9441a4d
commit
89e65f373f
19 files changed
+183
-28
No files matched your search
@@ -16,6 +16,7 @@
|
||||
"eslint-plugin-vue": "^7.17.0",
|
||||
"husky": "^7.0.2",
|
||||
"prettier": "^2.3.2",
|
||||
"qrcode.vue": "3.3.0",
|
||||
"vue": "^3.2.6",
|
||||
"vue-i18n": "^9.1.7",
|
||||
"vue-loading-overlay": "^4.0",
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import title from './title';
|
||||
import message from './message';
|
||||
|
||||
export default {
|
||||
title,
|
||||
message
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
scanToLogin: '使用微信扫码关注公众号「知数云」即可登录/注册'
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
wechatLogin: '微信登录'
|
||||
};
|
||||
@@ -1,7 +1,9 @@
|
||||
import common from './common/index';
|
||||
import content from './content/index';
|
||||
import auth from './auth/index';
|
||||
|
||||
export default {
|
||||
common,
|
||||
content
|
||||
content,
|
||||
auth
|
||||
};
|
||||
@@ -1,13 +1,18 @@
|
||||
<template>
|
||||
<el-main>
|
||||
<router-view />
|
||||
</el-main>
|
||||
<el-container>
|
||||
<el-main> <router-view /> </el-main>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { TopHeader } from '@/components/common/index';
|
||||
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
TopHeader
|
||||
},
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
@@ -19,8 +24,6 @@ export default defineComponent({
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.el-main {
|
||||
// background-color: #283443;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
height: calc(100vh);
|
||||
}
|
||||
</style>
|
||||
@@ -1,23 +1,88 @@
|
||||
<template>
|
||||
<div class="page-login"></div>
|
||||
<el-row>
|
||||
<el-col :span="6" :offset="9">
|
||||
<el-card shadow="hover" class="panel">
|
||||
<h2 class="title mt-5">{{ $t('auth.title.wechatLogin') }}</h2>
|
||||
<div class="pt-7 pb-10" v-loading="!qrLink">
|
||||
<qr-code :value="qrLink" :size="200" class="m-auto" v-if="qrLink" />
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import QrCode from 'qrcode.vue';
|
||||
import WechatService from '@/services/common/wechat/service';
|
||||
import { IWechatQRCode, IWechatQRCodeResponse, IWechatLoginStatusResponse } from '@/services/common/wechat/types';
|
||||
|
||||
interface IData {
|
||||
qrLink: string | undefined;
|
||||
ticket: string | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Login',
|
||||
data() {
|
||||
return {};
|
||||
components: {
|
||||
QrCode
|
||||
},
|
||||
methods: {}
|
||||
data(): IData {
|
||||
return {
|
||||
qrLink: undefined,
|
||||
ticket: undefined
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.initQRCode();
|
||||
},
|
||||
watch: {
|
||||
ticket(val) {
|
||||
if (val) {
|
||||
this.detectLoginStatus();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initQRCode() {
|
||||
WechatService.createQRCode4Login().then(({ data }: { data: IWechatQRCodeResponse }) => {
|
||||
this.qrLink = data.url;
|
||||
this.ticket = data.ticket;
|
||||
});
|
||||
},
|
||||
detectLoginStatus() {
|
||||
if (!this.ticket) {
|
||||
return;
|
||||
}
|
||||
// return;
|
||||
WechatService.getLoginStatus(this.ticket)
|
||||
.then(
|
||||
({
|
||||
data: {
|
||||
access_token,
|
||||
refresh_token,
|
||||
user: { id }
|
||||
}
|
||||
}: {
|
||||
data: IWechatLoginStatusResponse;
|
||||
}) => {
|
||||
this.$store.dispatch('setRefreshToken', refresh_token);
|
||||
}
|
||||
)
|
||||
.catch((error) => {
|
||||
setTimeout(() => {
|
||||
this.detectLoginStatus();
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
$background-color: #283443;
|
||||
.page-login {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: #283443;
|
||||
.panel {
|
||||
.title {
|
||||
text-align: center;
|
||||
font-size: 22px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -16,8 +16,8 @@ import { Breadcrumb, Loading, SuccessInfo } from '@/components/common/index';
|
||||
import { defaultOptions } from '@/settings/editor';
|
||||
import '@/libs/vditor/assets/scss/index.scss';
|
||||
import { defineComponent } from 'vue';
|
||||
import { ArticleService } from '@/services';
|
||||
import { IArticle, IArticleDetailResponse } from '@/services/article/types';
|
||||
import ArticleService from '@/services/content/article/service';
|
||||
import { IArticle, IArticleDetailResponse } from '@/services/content/article/types';
|
||||
|
||||
interface IData {
|
||||
id: string | string[];
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { Breadcrumb } from '@/components/common/index';
|
||||
import ArticleService from '@/services/article/service';
|
||||
import { IArticle, IArticleListResponse } from '@/services/article/types';
|
||||
import ArticleService from '@/services/content/article/service';
|
||||
import { IArticle, IArticleListResponse } from '@/services/content/article/types';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
interface IData {
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { Breadcrumb } from '@/components/common/index';
|
||||
import PlatformService from '@/services/platform/service';
|
||||
import { IPlatform, IPlatformListResponse } from '@/services/platform/types';
|
||||
import PlatformService from '@/services/content/platform/service';
|
||||
import { IPlatform, IPlatformListResponse } from '@/services/content/platform/types';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
interface IData {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../../instance';
|
||||
import { IWechatQRCode, IWechatQRCodeResponse, IWechatLoginStatusResponse } from './types';
|
||||
|
||||
class WechatService {
|
||||
key = 'wechat';
|
||||
|
||||
async createQRCode4Login(): Promise<AxiosResponse<IWechatQRCodeResponse>> {
|
||||
return await httpClient.post(`/${this.key}/qrcode`, {
|
||||
scene: 'login'
|
||||
});
|
||||
}
|
||||
|
||||
async getLoginStatus(ticket: string): Promise<AxiosResponse<IWechatLoginStatusResponse>> {
|
||||
return httpClient.post(`/${this.key}/auth`, {
|
||||
ticket: ticket
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new WechatService();
|
||||
@@ -0,0 +1,14 @@
|
||||
export interface IWechatQRCode {
|
||||
ticket: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface IWechatQRCodeResponse extends IWechatQRCode {}
|
||||
|
||||
export interface IWechatLoginStatusResponse {
|
||||
refresh_token: string;
|
||||
access_token: string;
|
||||
user: {
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../instance';
|
||||
import httpClient from '../../instance';
|
||||
import { IArticle, IArticleDetailResponse, IArticleListResponse } from './types';
|
||||
|
||||
class ArticleService {
|
||||
File renamed without changes.
@@ -1,5 +1,5 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../instance';
|
||||
import httpClient from '../../instance';
|
||||
import { IPlatform, IPlatformDetailResponse, IPlatformListResponse } from './types';
|
||||
|
||||
class PlatformService {
|
||||
File renamed without changes.
@@ -1,3 +1,4 @@
|
||||
import ArticleService from './article/service';
|
||||
import ArticleService from './content/article/service';
|
||||
import PlatformService from './content/platform/service';
|
||||
|
||||
export { ArticleService };
|
||||
export { ArticleService, PlatformService };
|
||||
+32
-2
@@ -1,18 +1,48 @@
|
||||
import { createStore } from 'vuex';
|
||||
import { createStore, ActionContext } from 'vuex';
|
||||
|
||||
interface IUser {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface IState {
|
||||
count: number;
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
user: IUser | undefined;
|
||||
}
|
||||
|
||||
const store = createStore({
|
||||
state(): IState {
|
||||
return {
|
||||
count: 0
|
||||
count: 0,
|
||||
accessToken: undefined,
|
||||
refreshToken: undefined,
|
||||
user: undefined
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
increment(state: IState) {
|
||||
state.count++;
|
||||
},
|
||||
setAccessToken(state: IState, payload: string) {
|
||||
state.accessToken = payload;
|
||||
},
|
||||
setRefreshToken(state: IState, payload: string) {
|
||||
state.refreshToken = payload;
|
||||
},
|
||||
setUser(state: IState, payload: IUser) {
|
||||
state.user = {
|
||||
...state.user,
|
||||
...payload
|
||||
};
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setRefreshToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setRefreshToken', payload);
|
||||
},
|
||||
setAccessToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setAccessToken', payload);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1915,6 +1915,11 @@ purgecss@^4.0.3:
|
||||
postcss "^8.2.1"
|
||||
postcss-selector-parser "^6.0.2"
|
||||
|
||||
qrcode.vue@3.3.0:
|
||||
version "3.3.0"
|
||||
resolved "https://registry.yarnpkg.com/qrcode.vue/-/qrcode.vue-3.3.0.tgz#2842b0b6d1a9457732b8a0e26e50889d7c46981b"
|
||||
integrity sha512-pLBm1cY/NgWz/NUN3+yO04KyC11P6inxyeThUWvrEYq8my45fnVSZy3PIiNPlaPbMHra0oItOKw912hFQy3zww==
|
||||
|
||||
queue-microtask@^1.2.2:
|
||||
version "1.2.3"
|
||||
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
|
||||
|
||||
Reference in new issue
Block a user