add publish function
This commit is contained in:
1 parent
bdf8f363e1
commit
672b5559a2
21 files changed
+268
-19
No files matched your search
+2
-1
@@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
extends: ['plugin:vue/vue3-essential', 'prettier'],
|
||||
rules: {
|
||||
'vue/no-unused-vars': 'error'
|
||||
'vue/no-unused-vars': 'error',
|
||||
semi: 'off'
|
||||
}
|
||||
};
|
||||
@@ -9,6 +9,7 @@
|
||||
"dependencies": {
|
||||
"@element-plus/icons": "^0.0.11",
|
||||
"@types/chrome": "^0.0.157",
|
||||
"@types/humps": "^2.0.1",
|
||||
"axios": "^0.21.1",
|
||||
"dayjs": "^1.10.7",
|
||||
"diff-match-patch": "^1.0.5",
|
||||
@@ -16,6 +17,7 @@
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-vue": "^7.17.0",
|
||||
"humps": "^2.0.1",
|
||||
"husky": "^7.0.2",
|
||||
"prettier": "^2.3.2",
|
||||
"qrcode.vue": "3.3.0",
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<template>
|
||||
<el-card shadow="hover">
|
||||
<el-table :data="platforms" 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 :label="$t('common.entity.operation')">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" size="small" round @click="onPublish(scope.row)">
|
||||
{{ $t('common.button.publish') }}</el-button
|
||||
>
|
||||
</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.id, articleId), PUBLICATION_STATE_PENDING)"
|
||||
>
|
||||
{{ $t('publication.state.' + getPublicationState(scope.row.id, articleId)) }}</el-button
|
||||
>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
round
|
||||
v-if="isEqual(getPublicationState(scope.row.id, articleId), PUBLICATION_STATE_RUNNING)"
|
||||
>
|
||||
{{ $t('publication.state.' + getPublicationState(scope.row.id, articleId)) }}</el-button
|
||||
>
|
||||
<el-button
|
||||
type="success"
|
||||
size="small"
|
||||
round
|
||||
v-if="isEqual(getPublicationState(scope.row.id, articleId), PUBLICATION_STATE_FINISHED)"
|
||||
>
|
||||
{{ $t('publication.state.' + getPublicationState(scope.row.id, articleId)) }}</el-button
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IPlatform, IPlatformListResponse } from '@/services/content/platform/types';
|
||||
import {
|
||||
CREDENTIAL_TYPE_COOKIES,
|
||||
IPublication,
|
||||
IPublicationCreateRequest,
|
||||
IPublicationDetailResponse,
|
||||
IPublicationListResponse
|
||||
} from '@/services/content/Publication/types';
|
||||
import { PUBLICATION_STATE_MAP } from '@/services/content/publication/constants';
|
||||
import PlatformService from '@/services/content/platform/service';
|
||||
import PublicationService from '@/services/content/publication/service';
|
||||
import { Constants, Methods } from '@/mixins/index';
|
||||
|
||||
interface IData {
|
||||
platforms: IPlatform[];
|
||||
publications: IPublication[];
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
mixins: [Constants, Methods],
|
||||
components: {},
|
||||
data(): IData {
|
||||
return {
|
||||
platforms: [],
|
||||
publications: [],
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
props: {
|
||||
articleId: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
this.loading = true;
|
||||
Promise.all([PlatformService.getAll(), PublicationService.getAll()]).then(([data1, data2]) => {
|
||||
const platforms = data1.data.results;
|
||||
const publications = data2.data.results;
|
||||
this.platforms = platforms;
|
||||
this.publications = publications;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
onPublish(platform: IPlatform) {
|
||||
const articleId = this.articleId;
|
||||
const data: IPublicationCreateRequest = {
|
||||
platform: platform.id,
|
||||
article: articleId,
|
||||
credential: JSON.stringify(this.$store.getters.cookies(platform.alias)),
|
||||
credentialType: CREDENTIAL_TYPE_COOKIES
|
||||
};
|
||||
PublicationService.create(data).then(({ data: data }: { data: IPublicationDetailResponse }) => {
|
||||
console.log('data', data);
|
||||
this.onRefreshPublications();
|
||||
});
|
||||
},
|
||||
onRefreshPublications() {
|
||||
PublicationService.getAll().then(({ data: data }: { data: IPublicationListResponse }) => {
|
||||
this.publications = data.results;
|
||||
});
|
||||
},
|
||||
getPublicationState(platformId: number, articleId: string) {
|
||||
const publications: IPublication[] = this.publications;
|
||||
const filteredPublications: IPublication[] = publications.filter((item: IPublication) => {
|
||||
return item.article.id === articleId && item.platform.id === platformId;
|
||||
});
|
||||
if (filteredPublications && filteredPublications.length > 0) {
|
||||
return PUBLICATION_STATE_MAP[filteredPublications[0].state];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss"></style>
|
||||
@@ -0,0 +1,2 @@
|
||||
import Publication from './Publication.vue';
|
||||
export { Publication };
|
||||
@@ -2,10 +2,12 @@ import common from './common/index';
|
||||
import content from './content/index';
|
||||
import platform from './platform/index';
|
||||
import auth from './auth/index';
|
||||
import publication from './publication';
|
||||
|
||||
export default {
|
||||
common,
|
||||
content,
|
||||
platform,
|
||||
auth
|
||||
auth,
|
||||
publication
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import state from './state';
|
||||
|
||||
export default {
|
||||
state
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
export default {
|
||||
pending: '等待发布',
|
||||
running: '发布中',
|
||||
finished: '发布成功'
|
||||
};
|
||||
+1
-1
@@ -7,7 +7,6 @@ import i18n from './i18n/index';
|
||||
import './assets/css/tailwind.css';
|
||||
import './assets/scss/style.scss';
|
||||
import dayjs from './plugins/dayjs';
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(router);
|
||||
@@ -17,4 +16,5 @@ app.use(i18n);
|
||||
app.use(dayjs, {
|
||||
formatString: 'YYYY-MM-DD HH:mm:ss'
|
||||
});
|
||||
// app.mixin(constants);
|
||||
app.mount('#app');
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
PUBLICATION_STATE_PENDING,
|
||||
PUBLICATION_STATE_FINISHED,
|
||||
PUBLICATION_STATE_RUNNING
|
||||
} from '@/services/content/publication/constants';
|
||||
|
||||
interface IData {
|
||||
PUBLICATION_STATE_PENDING: string;
|
||||
PUBLICATION_STATE_RUNNING: string;
|
||||
PUBLICATION_STATE_FINISHED: string;
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'Constants',
|
||||
data(): IData {
|
||||
return {
|
||||
PUBLICATION_STATE_PENDING: PUBLICATION_STATE_PENDING,
|
||||
PUBLICATION_STATE_RUNNING: PUBLICATION_STATE_RUNNING,
|
||||
PUBLICATION_STATE_FINISHED: PUBLICATION_STATE_FINISHED
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
import Constants from './constants';
|
||||
import Methods from './methods';
|
||||
|
||||
export { Constants, Methods };
|
||||
@@ -0,0 +1,14 @@
|
||||
interface IData {
|
||||
isEqual: (a: any, b: any) => boolean;
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'Methods',
|
||||
data(): IData {
|
||||
return {
|
||||
isEqual(a: any, b: any): boolean {
|
||||
return a === b;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -68,15 +68,15 @@ export default defineComponent({
|
||||
.then(
|
||||
async ({
|
||||
data: {
|
||||
access_token,
|
||||
refresh_token,
|
||||
accessToken,
|
||||
refreshToken,
|
||||
user: { id }
|
||||
}
|
||||
}: {
|
||||
data: IWechatLoginStatusResponse;
|
||||
}) => {
|
||||
await this.$store.dispatch('setRefreshToken', refresh_token);
|
||||
await this.$store.dispatch('setAccessToken', access_token);
|
||||
await this.$store.dispatch('setRefreshToken', refreshToken);
|
||||
await this.$store.dispatch('setAccessToken', accessToken);
|
||||
this.getUserInfo(id);
|
||||
}
|
||||
)
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
<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>
|
||||
@@ -13,6 +19,7 @@
|
||||
<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';
|
||||
@@ -20,26 +27,29 @@ import ArticleService from '@/services/content/article/service';
|
||||
import { IArticle, IArticleDetailResponse } from '@/services/content/article/types';
|
||||
|
||||
interface IData {
|
||||
id: string | string[];
|
||||
id: string;
|
||||
vditor: null | Vditor;
|
||||
item: null | IArticle;
|
||||
loading: boolean;
|
||||
succeed: boolean;
|
||||
publishing: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
Breadcrumb,
|
||||
Loading,
|
||||
SuccessInfo
|
||||
SuccessInfo,
|
||||
Publication
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
id: this.$route.params.id,
|
||||
id: this.$route.params.id.toString(),
|
||||
vditor: null,
|
||||
item: null,
|
||||
loading: false,
|
||||
succeed: false
|
||||
succeed: false,
|
||||
publishing: false
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
@@ -157,4 +167,12 @@ export default defineComponent({
|
||||
background-color: #fff !important;
|
||||
}
|
||||
}
|
||||
|
||||
.btn {
|
||||
&.btn-publish {
|
||||
position: fixed;
|
||||
right: 100px;
|
||||
bottom: 100px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -54,6 +54,7 @@ import { IArticle, IArticleListResponse, IArticleDetailResponse } from '@/servic
|
||||
import { defineComponent } from 'vue';
|
||||
import { RouteQueryAndHash } from 'vue-router';
|
||||
import { DEFAULT_LIMIT } from '@/settings/article';
|
||||
|
||||
interface IData {
|
||||
items: IArticle[];
|
||||
loading: boolean;
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface IWechatQRCode {
|
||||
export interface IWechatQRCodeResponse extends IWechatQRCode {}
|
||||
|
||||
export interface IWechatLoginStatusResponse {
|
||||
refresh_token: string;
|
||||
access_token: string;
|
||||
refreshToken: string;
|
||||
accessToken: string;
|
||||
user: IUser;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class ArticleService {
|
||||
return await httpClient.get(`/${this.key}/?limit=${limit}&offset=${offset}`);
|
||||
}
|
||||
|
||||
async get(id: string | string[]): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
async get(id: string): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
return httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ class ArticleService {
|
||||
return httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
async update(id: string | string[], data: IArticle): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
async update(id: string, data: IArticle): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
return httpClient.put(`/${this.key}/${id}`, data);
|
||||
}
|
||||
|
||||
async delete(id: string | string[]): Promise<AxiosResponse<null>> {
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export const PUBLICATION_STATE_PENDING = 'pending';
|
||||
export const PUBLICATION_STATE_RUNNING = 'running';
|
||||
export const PUBLICATION_STATE_FINISHED = 'finished';
|
||||
|
||||
export const PUBLICATION_STATE_MAP: {
|
||||
[key: string]: string;
|
||||
} = {
|
||||
Pending: PUBLICATION_STATE_PENDING,
|
||||
Running: PUBLICATION_STATE_RUNNING,
|
||||
Finished: PUBLICATION_STATE_FINISHED
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../../instance';
|
||||
import { IPublication, IPublicationDetailResponse, IPublicationListResponse } from './types';
|
||||
import { IPublication, IPublicationDetailResponse, IPublicationListResponse, IPublicationCreateRequest } from './types';
|
||||
|
||||
class PublicationService {
|
||||
key = 'publications';
|
||||
@@ -13,7 +13,7 @@ class PublicationService {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async create(data: IPublication): Promise<AxiosResponse<IPublicationDetailResponse>> {
|
||||
async create(data: IPublicationCreateRequest): Promise<AxiosResponse<IPublicationDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
import { IArticle } from '../article/types';
|
||||
import { IPlatform } from '../platform/types';
|
||||
|
||||
export interface IPublication {
|
||||
id: number;
|
||||
name: string;
|
||||
state: string;
|
||||
platform: IPlatform;
|
||||
article: IArticle;
|
||||
}
|
||||
|
||||
export const CREDENTIAL_TYPE_COOKIES = 'Cookies';
|
||||
export const CREDENTIAL_TYPE_TOKEN = 'Token';
|
||||
|
||||
export interface IPublicationCreateRequest {
|
||||
article: string;
|
||||
platform: number;
|
||||
credential: string;
|
||||
state?: string;
|
||||
credentialType?: typeof CREDENTIAL_TYPE_COOKIES | typeof CREDENTIAL_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
export interface IPublicationListResponse {
|
||||
@@ -9,4 +25,4 @@ export interface IPublicationListResponse {
|
||||
results: IPublication[];
|
||||
}
|
||||
|
||||
export interface IPublicationDetailResponse extends IPublication {}
|
||||
export type IPublicationDetailResponse = IPublication;
|
||||
@@ -1,6 +1,7 @@
|
||||
import router from '@/router';
|
||||
import store from '@/store';
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import { camelizeKeys, decamelizeKeys } from 'humps';
|
||||
|
||||
const httpClient: AxiosInstance = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
@@ -12,14 +13,21 @@ const httpClient: AxiosInstance = axios.create({
|
||||
|
||||
httpClient.interceptors.request.use((config) => {
|
||||
const accessToken = store.getters.accessToken;
|
||||
console.log('accesstoken', accessToken);
|
||||
if (accessToken) {
|
||||
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
if (config.data) {
|
||||
config.data = decamelizeKeys(config.data);
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
httpClient.interceptors.response.use(
|
||||
(response) => {
|
||||
if (response.data && response.headers['content-type'] === 'application/json') {
|
||||
response.data = camelizeKeys(response.data);
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
|
||||
@@ -230,6 +230,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/har-format/-/har-format-1.2.7.tgz#debfe36378f26c4fc2abca1df99f00a8ff94fd29"
|
||||
integrity sha512-/TPzUG0tJn5x1TUcVLlDx2LqbE58hyOzDVAc9kf8SpOEmguHjU6bKUyfqb211AdqLOmU/SNyXvLKPNP5qTlfRw==
|
||||
|
||||
"@types/humps@^2.0.1":
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/humps/-/humps-2.0.1.tgz#fc87ccbe59913240c3fdca5f0dd43cb9f073eb72"
|
||||
integrity sha512-cxIGJjiOQRl5s/KjqoTa0u39qKrVD3T6+6eGsERva0MLBp9AMVG8udKn9JZgVDe9zF0J9H4SRVzKILK6iZ9IZQ==
|
||||
|
||||
"@types/lodash@^4.14.172":
|
||||
version "4.14.172"
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.172.tgz#aad774c28e7bfd7a67de25408e03ee5a8c3d028a"
|
||||
@@ -1290,6 +1295,11 @@ htmlparser2@^6.1.0:
|
||||
domutils "^2.5.2"
|
||||
entities "^2.0.0"
|
||||
|
||||
humps@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/humps/-/humps-2.0.1.tgz#dd02ea6081bd0568dc5d073184463957ba9ef9aa"
|
||||
integrity sha1-3QLqYIG9BWjcXQcxhEY5V7qe+ao=
|
||||
|
||||
husky@^7.0.2:
|
||||
version "7.0.2"
|
||||
resolved "https://registry.yarnpkg.com/husky/-/husky-7.0.2.tgz#21900da0f30199acca43a46c043c4ad84ae88dff"
|
||||
|
||||
Reference in new issue
Block a user