finish auth

This commit is contained in:
AceDataCloud committed 2022-02-04 16:24:14 +08:00
1 parent f7d93c3abf
commit 903e7040f0
163 files changed
+34 -16975

No files matched your search

+25 -4
View File
@@ -15,7 +15,7 @@ import { defineComponent } from 'vue';
import QrCode from 'qrcode.vue';
import WechatService from '@/services/common/wechat/service';
import UserService from '@/services/common/user/service';
import { IWechatQRCode, IWechatQRCodeResponse, IWechatLoginStatusResponse } from '@/services/common/wechat/types';
import { IWechatQRCodeResponse, IWechatLoginStatusResponse } from '@/services/common/wechat/types';
import { IUserDetailResponse, IUser } from '@/services/common/user/types';
interface IData {
@@ -23,6 +23,27 @@ interface IData {
ticket: string | undefined;
}
const openPostPage = (
url: string,
data: {
[key: string]: string;
}
) => {
const form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
document.body.removeChild(form);
};
export default defineComponent({
name: 'Login',
components: {
@@ -54,8 +75,9 @@ export default defineComponent({
getUserInfo(id: string) {
UserService.get(id).then(async ({ data }: { data: IUserDetailResponse }) => {
await this.$store.dispatch('setUser', data as IUser);
this.$router.push({
path: this.$route.query.redirect ? this.$route.query.redirect.toString() : '/'
const redirectTarget = this.$route.query.redirect ? this.$route.query.redirect.toString() : '/';
openPostPage(redirectTarget, {
accessToken: this.$store.getters.accessToken
});
});
},
@@ -63,7 +85,6 @@ export default defineComponent({
if (!this.ticket) {
return;
}
// return;
WechatService.getLoginStatus(this.ticket)
.then(
async ({
-3
View File
@@ -1,3 +0,0 @@
<template>
<div>dd</div>
</template>
-178
View File
@@ -1,178 +0,0 @@
<template>
<el-row :gutter="20">
<el-col :span="16" :offset="4">
<loading :loading="loading" />
<div class="px-4 pt-4">
<success-info v-model:show="succeed" :content="$t('content.message.saved')"></success-info>
<div id="vditor" class="vditor" />
</div>
<el-button type="primary" size="medium" round class="btn btn-publish" @click="publishing = true">
{{ $t('common.button.publish') }}
</el-button>
<el-dialog v-model="publishing">
<publication :article-id="id" />
</el-dialog>
</el-col>
</el-row>
</template>
<script lang="ts">
import Vditor from '@/libs/vditor/index';
import { Breadcrumb, Loading, SuccessInfo } from '@/components/common/index';
import { Publication } from '@/components/content/index';
import { defaultOptions } from '@/settings/editor';
import '@/libs/vditor/assets/scss/index.scss';
import { defineComponent } from 'vue';
import ArticleService from '@/services/content/article/service';
import { IArticle, IArticleDetailResponse } from '@/services/content/article/types';
interface IData {
id: string;
vditor: null | Vditor;
item: null | IArticle;
loading: boolean;
succeed: boolean;
publishing: boolean;
}
export default defineComponent({
components: {
Breadcrumb,
Loading,
SuccessInfo,
Publication
},
data(): IData {
return {
id: this.$route.params.id.toString(),
vditor: null,
item: null,
loading: false,
succeed: false,
publishing: false
};
},
async mounted() {
this.loading = true;
ArticleService.get(this.id).then(({ data: data }: { data: IArticleDetailResponse }): void => {
this.item = data;
this.loading = false;
if (this.vditor?.initialized && this.item) {
this.vditor.setValue(this.item);
}
});
this.initVditor();
this.listenKeyboard();
},
computed: {},
methods: {
listenKeyboard() {
document.addEventListener(
'keydown',
(e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault();
this.onSave();
}
},
false
);
},
initVditor() {
const options = {
width: '100%',
height: '0',
tab: '\t',
mode: 'ir',
icon: 'ant',
debugger: false,
after: () => {
if (this.vditor?.getValue()) {
return;
}
if (this.item?.content) {
if (!this.item.title) {
this.item.title = this.$t('content.text.notitle');
}
this.vditor?.setValue(this.item);
}
}
};
this.vditor = new Vditor('vditor', {
...defaultOptions,
...options
});
},
onSave() {
const title = this.vditor?.getTitle(this.$t('content.text.notitle'));
const content = this.vditor?.getContent();
ArticleService.update(this.id, {
title: title,
content: content
}).then(({ data: data }: { data: IArticleDetailResponse }): void => {
this.item = data;
if (this.vditor && this.item) {
if (!this.item.title) {
this.item.title = this.$t('content.text.notitle');
}
this.vditor.setValue(this.item);
}
this.succeed = true;
});
}
}
});
</script>
<style lang="scss">
.vditor {
box-shadow: 0 1px 7px #ddd;
border: none;
margin-bottom: 100px;
margin-top: 20px;
}
.vditor-toolbar-wrapper {
background-color: #f5f5f5;
width: 100%;
height: 35px;
position: fixed;
padding-left: 0 !important;
top: 60px;
z-index: 1000;
left: 0;
}
.vditor-toolbar {
background-color: #f5f5f5;
border-bottom: none;
left: 50%;
height: 35px;
position: absolute;
transform: translateX(-50%);
width: 700px;
margin: auto;
}
.vditor-toolbar--pin {
// position: fixed;
top: 60px;
}
.vditor-reset {
min-height: 100vh;
padding-top: 80px !important;
padding-bottom: 80px !important;
&:focus {
background-color: #fff !important;
}
}
.btn {
&.btn-publish {
position: fixed;
right: 100px;
bottom: 100px;
}
}
</style>
-166
View File
@@ -1,166 +0,0 @@
<template>
<el-row :gutter="20">
<el-col :span="24">
<div class="px-4 pt-4">
<el-card shadow="hover">
<div class="mb-5">
<breadcrumb />
</div>
<el-button size="mini" round type="primary" @click="onCreate" class="btn-create">
{{ $t('common.button.new') }}</el-button
>
<el-table :data="items" v-loading="loading">
<el-table-column prop="title" :label="$t('common.entity.title')"> </el-table-column>
<el-table-column prop="created_at" :label="$t('common.entity.createdAt')">
<template #default="scope">
{{ $dayjs.format(scope.row.created_at) }}
</template>
</el-table-column>
<el-table-column prop="updated_at" :label="$t('common.entity.updatedAt')">
<template #default="scope">
{{ $dayjs.format(scope.row.updated_at) }}
</template>
</el-table-column>
<el-table-column :label="$t('common.entity.operation')">
<template #default="scope">
<el-button @click="onEdit(scope.row)" round type="primary" size="mini">
{{ $t('common.button.edit') }}
</el-button>
<el-button @click="onPublish(scope.row)" round type="success" size="mini">
{{ $t('common.button.publish') }}
</el-button>
<el-button @click="onDelete(scope.row)" round type="danger" size="mini">
{{ $t('common.button.delete') }}
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
class="float-right"
@change="onPageChange"
:total="total"
:current-page="currentPage"
></pagination>
</el-card>
</div>
</el-col>
</el-row>
</template>
<script lang="ts">
import { Breadcrumb, Pagination } from '@/components/common/index';
import ArticleService from '@/services/content/article/service';
import { IArticle, IArticleListResponse, IArticleDetailResponse } from '@/services/content/article/types';
import { defineComponent } from 'vue';
import { RouteQueryAndHash } from 'vue-router';
import { DEFAULT_LIMIT } from '@/settings/article';
interface IData {
items: IArticle[];
loading: boolean;
total: number;
limit: number;
offset: number;
}
export default defineComponent({
components: {
Breadcrumb,
Pagination
},
data(): IData {
return {
total: 0,
limit: this.$route.query.limit ? parseInt(this.$route.query.limit.toString()) : DEFAULT_LIMIT,
offset: this.$route.query.offset ? parseInt(this.$route.query.offset.toString()) : 0,
items: [],
loading: false
};
},
computed: {
currentPage(): number {
return this.offset / this.limit + 1;
}
},
async mounted() {
this.onLoadData();
},
methods: {
onLoadData() {
this.loading = true;
ArticleService.getAll(this.offset, this.limit).then(({ data: data }: { data: IArticleListResponse }): void => {
this.total = data.count;
this.items = data.results;
this.loading = false;
});
},
onPublish(row: IArticle) {
this.$router.push({
name: 'article-publish',
params: {
id: row.id
}
});
},
onEdit(row: IArticle) {
this.$router.push({
name: 'article-detail',
params: {
id: row.id
}
});
},
onDelete(row: IArticle) {
this.$confirm(this.$t('common.message.confirmDelete'), this.$t('common.button.info'), {
confirmButtonText: this.$t('common.button.confirm'),
cancelButtonText: this.$t('common.button.cancel'),
type: 'warning'
}).then(() => {
if (!row.id) {
return;
}
ArticleService.delete(row.id).then((): void => {
this.items = this.items.filter((item) => item.id !== row.id);
});
});
},
onCreate() {
ArticleService.create({}).then(({ data: data }: { data: IArticleDetailResponse }): void => {
console.log('data', data);
this.$router.push({
name: 'article-detail',
params: {
id: data.id
}
});
});
},
onPageChange(val: number) {
this.limit = DEFAULT_LIMIT;
this.offset = (val - 1) * this.limit;
const route = {
name: this.$route.name,
query: {
...this.$route.query,
offset: this.offset,
limit: this.limit
}
};
this.$router.push(route as RouteQueryAndHash);
this.onLoadData();
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
// height: calc(100vh - 100px);
position: relative;
.btn-create {
position: absolute;
right: 20px;
top: 20px;
}
}
</style>
-88
View File
@@ -1,88 +0,0 @@
<template>
<p>
{{ chatValue }}
</p>
<el-input v-model="inputValue"> </el-input>
<el-button @click="onSend"> Send </el-button>
<el-button @click="onLaunch()"> Launch </el-button>
<el-button @click="onOpen('https://www.baidu.com')"> Open </el-button>
<el-button @click="onClose"> Close </el-button>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
interface IData {
socket: WebSocket | undefined;
inputValue: string;
chatValue: string;
id: string;
}
export default defineComponent({
data(): IData {
return {
id: this.$route.params.id.toString(),
socket: undefined,
inputValue: '',
chatValue: ''
};
},
mounted() {
this.socket = new WebSocket(
`${window.location.protocol === 'https:' ? 'wss://' : 'ws://'}/${window.location.host}/ws/publish/${
this.id
}?access_token=${this.$store.getters.accessToken}`
);
this.socket.onmessage = this.onMessage;
},
methods: {
onMessage(e) {
console.log('e');
const data = JSON.parse(e.data);
this.chatValue += data.message;
},
onLaunch() {
if (!this.socket) {
return;
}
this.socket.send(
JSON.stringify({
command: 'launch'
})
);
},
onOpen(url: string) {
if (!this.socket) {
return;
}
this.socket.send(
JSON.stringify({
command: 'open',
payload: {
url: url
}
})
);
},
onClose() {
if (!this.socket) {
return;
}
this.socket.send(
JSON.stringify({
command: 'close'
})
);
},
onSend() {
if (!this.socket) {
return;
}
this.socket.send(
JSON.stringify({
message: this.inputValue
})
);
}
}
});
</script>
-3
View File
@@ -1,3 +0,0 @@
<template>
</template>
-155
View File
@@ -1,155 +0,0 @@
<template>
<el-row :gutter="20">
<el-col :span="24">
<div class="px-4 pt-4">
<el-card shadow="hover">
<div class="mb-5">
<breadcrumb />
</div>
<div class="mb-4">
<el-alert
:title="$t('content.message.extensionNotInstalled')"
type="warning"
show-icon
v-if="!extensionInstalled"
>
</el-alert>
</div>
<el-table :data="items" v-loading="loading">
<el-table-column prop="icon" :label="$t('common.entity.icon')">
<template #default="scope">
<img :src="scope.row.icon" class="w-10" />
</template>
</el-table-column>
<el-table-column prop="name" :label="$t('common.entity.platform')"> </el-table-column>
<el-table-column prop="description" :label="$t('common.entity.description')"> </el-table-column>
<el-table-column :label="$t('common.entity.operation')">
<template #default="scope">
<el-button
@click="onSetup(scope.row.alias)"
round
type="primary"
size="mini"
v-if="!isSetup[scope.row.alias]"
>
{{ $t('common.button.setup') }}
</el-button>
<el-button @click="onDelete(scope.row.alias)" round type="danger" size="mini" v-else>
{{ $t('common.button.delete') }}
</el-button>
</template>
</el-table-column>
<el-table-column :label="$t('common.entity.status')">
<template #default="scope">
<el-button type="success" circle v-if="isSetup[scope.row.alias]">
<el-icon :size="13">
<check />
</el-icon>
</el-button>
<el-button type="info" circle v-else>
<el-icon :size="13">
<close />
</el-icon>
</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</el-col>
</el-row>
</template>
<script lang="ts">
import { Breadcrumb } from '@/components/common/index';
import PlatformService from '@/services/content/platform/service';
import { IPlatform, IPlatformListResponse } from '@/services/content/platform/types';
import { defineComponent } from 'vue';
import { getDomainByAlias, IAlias } from '@/settings/platform';
import { ICookie } from '@/types/cookie';
import { Check, Close } from '@element-plus/icons';
import { ElMessageBox, ElMessage } from 'element-plus';
interface IData {
items: IPlatform[];
loading: boolean;
}
export default defineComponent({
components: {
Breadcrumb,
Check,
Close
},
data(): IData {
return {
items: [],
loading: false
};
},
computed: {
extensionInstalled(): boolean {
return !!document.getElementById('extension-id');
},
extensionId(): string | undefined | null {
return document.getElementById('extension-id')?.getAttribute('value');
},
extensionVersion(): string | undefined | null {
return document.getElementById('extension-version')?.getAttribute('value');
},
isSetup(): { [key: string]: boolean } {
let result: { [key: string]: boolean } = {};
this.items.forEach((item: IPlatform) => {
const alias = item.alias;
const cookies: ICookie[] | undefined = this.$store.getters.cookies(alias);
result[alias] = !!cookies;
});
return result;
}
},
async mounted() {
this.loading = true;
PlatformService.getAll().then(({ data: data }: { data: IPlatformListResponse }): void => {
this.items = data.results;
this.loading = false;
});
},
methods: {
onSetup(alias: string) {
const domain = getDomainByAlias(alias as IAlias);
if (window.hasOwnProperty('chrome') && this.extensionId) {
chrome.runtime.sendMessage(
this.extensionId?.toString(),
{ command: 'getCookies', domain },
(cookies: ICookie[]) => {
console.log(cookies);
this.$store.dispatch('setCookies', {
alias,
value: cookies
});
ElMessage.success(this.$t('platform.message.setupSuccessfully'));
}
);
}
},
onDelete(alias: string) {
ElMessageBox.confirm(this.$t('platform.message.confirmDelete'), {
confirmButtonText: this.$t('common.button.confirm'),
cancelButtonText: this.$t('common.button.cancel'),
type: 'warning'
}).then(() => {
this.$store.dispatch('setCookies', {
alias,
value: undefined
});
});
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
height: calc(100vh - 100px);
}
</style>
-154
View File
@@ -1,154 +0,0 @@
<template>
<el-row :gutter="20">
<el-col :span="24">
<div class="px-4 pt-4">
<el-card shadow="hover">
<div class="mb-5">
<breadcrumb />
</div>
<el-table :data="items" v-loading="loading">
<el-table-column prop="icon" :label="$t('common.entity.icon')" width="150px">
<template #default="scope">
<img :src="scope.row.platform.icon" class="w-10" />
</template>
</el-table-column>
<el-table-column :label="$t('common.entity.platform')" width="300px">
<template #default="scope">
{{ scope.row.platform.name }}
</template>
</el-table-column>
<el-table-column prop="article" :label="$t('common.entity.article')">
<template #default="scope">
<router-link :to="{ name: 'article-detail', params: { id: scope.row.article.id } }">
{{ scope.row.article.title }}
</router-link>
</template>
</el-table-column>
<el-table-column :label="$t('common.entity.publishAt')">
<template #default="scope">
{{ $dayjs.format(scope.row.created_at) }}
</template>
</el-table-column>
<el-table-column :label="$t('common.entity.status')">
<template #default="scope">
<el-button
type="info"
size="small"
round
v-if="isEqual(getPublicationState(scope.row), PUBLICATION_STATE_PENDING)"
>
{{ $t('publication.state.' + getPublicationState(scope.row)) }}</el-button
>
<el-button
type="primary"
size="small"
round
v-if="isEqual(getPublicationState(scope.row), PUBLICATION_STATE_RUNNING)"
>
{{ $t('publication.state.' + getPublicationState(scope.row)) }}</el-button
>
<el-button
type="success"
size="small"
round
v-if="isEqual(getPublicationState(scope.row), PUBLICATION_STATE_FINISHED)"
>
{{ $t('publication.state.' + getPublicationState(scope.row)) }}</el-button
>
</template>
</el-table-column>
</el-table>
<pagination
class="float-right"
@change="onPageChange"
:total="total"
:current-page="currentPage"
></pagination>
</el-card>
</div>
</el-col>
</el-row>
</template>
<script lang="ts">
import { Breadcrumb, Pagination } from '@/components/common/index';
import PublicationService from '@/services/content/Publication/service';
import { IPublication, IPublicationListResponse } from '@/services/content/Publication/types';
import { defineComponent } from 'vue';
import { Check, Close } from '@element-plus/icons';
import { PUBLICATION_STATE_MAP } from '@/services/content/publication/constants';
import { Constants, Methods } from '@/mixins/index';
import { DEFAULT_LIMIT } from '@/settings/article';
import { RouteQueryAndHash } from 'vue-router';
interface IData {
items: IPublication[];
loading: boolean;
total: number;
limit: number;
offset: number;
}
export default defineComponent({
mixins: [Constants, Methods],
components: {
Breadcrumb,
Check,
Close,
Pagination
},
data(): IData {
return {
items: [],
limit: this.$route.query.limit ? parseInt(this.$route.query.limit.toString()) : DEFAULT_LIMIT,
offset: this.$route.query.offset ? parseInt(this.$route.query.offset.toString()) : 0,
total: 0,
loading: false
};
},
computed: {
currentPage(): number {
return this.offset / this.limit + 1;
}
},
async mounted() {
this.onLoadData();
},
methods: {
onLoadData() {
this.loading = true;
PublicationService.getAll(this.offset, this.limit).then(
({ data: data }: { data: IPublicationListResponse }): void => {
this.total = data.count;
this.items = data.results;
this.loading = false;
}
);
},
getPublicationState(publication: IPublication) {
return PUBLICATION_STATE_MAP[publication.state];
},
onPageChange(val: number) {
this.limit = DEFAULT_LIMIT;
this.offset = (val - 1) * this.limit;
const route = {
name: this.$route.name,
query: {
...this.$route.query,
offset: this.offset,
limit: this.limit
}
};
this.$router.push(route as RouteQueryAndHash);
this.onLoadData();
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
height: calc(100vh - 100px);
}
</style>
View File
Whitespace-only changes.
-91
View File
@@ -1,91 +0,0 @@
<template>
<el-row :gutter="20">
<el-col :span="24">
<div class="px-4 pt-4">
</div>
</el-col>
</el-row>
</template>
<script lang="ts">
import { Breadcrumb, Pagination } from '@/components/common/index';
import PublicationService from '@/services/content/Publication/service';
import { IPublication, IPublicationListResponse } from '@/services/content/Publication/types';
import { defineComponent } from 'vue';
import { Check, Close } from '@element-plus/icons';
import { PUBLICATION_STATE_MAP } from '@/services/content/publication/constants';
import { Constants, Methods } from '@/mixins/index';
import { DEFAULT_LIMIT } from '@/settings/article';
import { RouteQueryAndHash } from 'vue-router';
interface IData {
items: IPublication[];
loading: boolean;
total: number;
limit: number;
offset: number;
}
export default defineComponent({
mixins: [Constants, Methods],
components: {
Breadcrumb,
Check,
Close,
Pagination
},
data(): IData {
return {
items: [],
limit: this.$route.query.limit ? parseInt(this.$route.query.limit.toString()) : DEFAULT_LIMIT,
offset: this.$route.query.offset ? parseInt(this.$route.query.offset.toString()) : 0,
total: 0,
loading: false
};
},
computed: {
currentPage(): number {
return this.offset / this.limit + 1;
}
},
async mounted() {
this.onLoadData();
},
methods: {
onLoadData() {
this.loading = true;
PublicationService.getAll(this.offset, this.limit).then(
({ data: data }: { data: IPublicationListResponse }): void => {
this.total = data.count;
this.items = data.results;
this.loading = false;
}
);
},
getPublicationState(publication: IPublication) {
return PUBLICATION_STATE_MAP[publication.state];
},
onPageChange(val: number) {
this.limit = DEFAULT_LIMIT;
this.offset = (val - 1) * this.limit;
const route = {
name: this.$route.name,
query: {
...this.$route.query,
offset: this.offset,
limit: this.limit
}
};
this.$router.push(route as RouteQueryAndHash);
this.onLoadData();
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
height: calc(100vh - 100px);
}
</style>
View File
Whitespace-only changes.