update platfrom management
This commit is contained in:
1 parent
fb3e8655e9
commit
0b19f69025
9 files changed
+158
-70
No files matched your search
@@ -1,3 +1,3 @@
|
||||
// $--color-primary: #5e72e4;
|
||||
// @import 'element-plus/packages/theme-chalk/src/index';
|
||||
@import 'element-plus/dist/index.css';
|
||||
$--font-path: 'element-plus/theme-chalk/src/fonts';
|
||||
|
||||
@import 'element-plus/theme-chalk/src/index.scss';
|
||||
@@ -1,9 +1,11 @@
|
||||
import common from './common/index';
|
||||
import content from './content/index';
|
||||
import platform from './platform/index';
|
||||
import auth from './auth/index';
|
||||
|
||||
export default {
|
||||
common,
|
||||
content,
|
||||
platform,
|
||||
auth
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import message from './message';
|
||||
|
||||
export default {
|
||||
message
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
confirmDelete: '您确定要移除吗?',
|
||||
setupSuccessfully: '配置成功'
|
||||
};
|
||||
@@ -11,7 +11,7 @@
|
||||
:title="$t('content.message.extensionNotInstalled')"
|
||||
type="warning"
|
||||
show-icon
|
||||
v-if="extensionInstalled"
|
||||
v-if="!extensionInstalled"
|
||||
>
|
||||
</el-alert>
|
||||
</div>
|
||||
@@ -25,9 +25,32 @@
|
||||
<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="small">
|
||||
<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>
|
||||
@@ -43,6 +66,9 @@ 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[];
|
||||
@@ -51,7 +77,9 @@ interface IData {
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
Breadcrumb
|
||||
Breadcrumb,
|
||||
Check,
|
||||
Close
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
@@ -60,20 +88,28 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
extensionInstalled() {
|
||||
return document.getElementById('extension-id');
|
||||
extensionInstalled(): boolean {
|
||||
return !!document.getElementById('extension-id');
|
||||
},
|
||||
extensionId() {
|
||||
extensionId(): string | undefined | null {
|
||||
return document.getElementById('extension-id')?.getAttribute('value');
|
||||
},
|
||||
extensionVersion() {
|
||||
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 => {
|
||||
console.log('data', data);
|
||||
this.items = data.results;
|
||||
this.loading = false;
|
||||
});
|
||||
@@ -82,14 +118,31 @@ export default defineComponent({
|
||||
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) => {
|
||||
console.log(cookies);
|
||||
this.$store.dispatch('setCookies', {
|
||||
alias,
|
||||
value: cookies
|
||||
});
|
||||
});
|
||||
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
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+9
-12
@@ -2,15 +2,14 @@ import { createStore, ActionContext } from 'vuex';
|
||||
import { IUser } from '@/services/common/user/types';
|
||||
import createPersistedState from 'vuex-persistedstate';
|
||||
import { IAlias as IPlatformAlias, PLATFORM_ALIAS_JUEJIN } from '@/settings/platform';
|
||||
import { ICookie, ICookieStore } from '@/types/cookie';
|
||||
|
||||
export interface IState {
|
||||
count: number;
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
user: IUser | undefined;
|
||||
cookies: {
|
||||
[PLATFORM_ALIAS_JUEJIN]: string;
|
||||
};
|
||||
cookies: ICookieStore;
|
||||
}
|
||||
|
||||
const store = createStore({
|
||||
@@ -20,9 +19,7 @@ const store = createStore({
|
||||
accessToken: undefined,
|
||||
refreshToken: undefined,
|
||||
user: undefined,
|
||||
cookies: {
|
||||
[PLATFORM_ALIAS_JUEJIN]: ''
|
||||
}
|
||||
cookies: {}
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
@@ -45,12 +42,12 @@ const store = createStore({
|
||||
state: IState,
|
||||
payload: {
|
||||
alias: IPlatformAlias;
|
||||
value: Array<any>;
|
||||
value: ICookie[];
|
||||
}
|
||||
): void {
|
||||
console.log('cookies', payload);
|
||||
console.log('cookies', JSON.stringify(payload.value));
|
||||
state.cookies[payload.alias] = JSON.stringify(payload.value);
|
||||
state.cookies[payload.alias] = payload.value;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@@ -72,7 +69,7 @@ const store = createStore({
|
||||
{ commit }: ActionContext<IState, IState>,
|
||||
payload: {
|
||||
alias: IPlatformAlias;
|
||||
value: Array<any>;
|
||||
value: ICookie[];
|
||||
}
|
||||
) {
|
||||
console.log('setCookies', payload);
|
||||
@@ -92,9 +89,9 @@ const store = createStore({
|
||||
user(state): IUser | undefined {
|
||||
return state.user;
|
||||
},
|
||||
cookies(state) {
|
||||
return (alias: string) => {
|
||||
return JSON.parse(state.cookies[alias]);
|
||||
cookies(state): (alias: string) => ICookie[] | undefined {
|
||||
return (alias: string): ICookie[] | undefined => {
|
||||
return state.cookies[alias];
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
export interface ICookie {
|
||||
name: string;
|
||||
value: string;
|
||||
domain?: string;
|
||||
path?: string;
|
||||
expirationDate?: string;
|
||||
hostOnly?: boolean;
|
||||
httpOnly?: boolean;
|
||||
sameSite?: string;
|
||||
secure?: boolean;
|
||||
session?: boolean;
|
||||
storeId?: number;
|
||||
}
|
||||
|
||||
export interface ICookieStore {
|
||||
[key: string]: ICookie[];
|
||||
}
|
||||
Reference in new issue
Block a user