update platfrom management
This commit is contained in:
1 parent
fb3e8655e9
commit
0b19f69025
9 files changed
+158
-70
No files matched your search
@@ -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
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user