update cookies store
This commit is contained in:
1 parent
053c14b72d
commit
fb3e8655e9
8 files changed
+117
-5
No files matched your search
@@ -8,6 +8,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons": "^0.0.11",
|
||||
"@types/chrome": "^0.0.157",
|
||||
"axios": "^0.21.1",
|
||||
"dayjs": "^1.10.7",
|
||||
"diff-match-patch": "^1.0.5",
|
||||
|
||||
Vendored
+1
@@ -1,4 +1,5 @@
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="chrome" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default {
|
||||
saved: '保存成功',
|
||||
extensionNotInstalled: '你尚未安装浏览器插件,请安装浏览器插件。'
|
||||
};
|
||||
@@ -6,6 +6,15 @@
|
||||
<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">
|
||||
@@ -14,10 +23,9 @@
|
||||
</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.status')"> </el-table-column>
|
||||
<el-table-column :label="$t('common.entity.operation')">
|
||||
<template #default="scope">
|
||||
<el-button @click="onSetup(scope.row)" round type="primary" size="small">
|
||||
<el-button @click="onSetup(scope.row.alias)" round type="primary" size="small">
|
||||
{{ $t('common.button.setup') }}
|
||||
</el-button>
|
||||
</template>
|
||||
@@ -34,6 +42,7 @@ 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';
|
||||
|
||||
interface IData {
|
||||
items: IPlatform[];
|
||||
@@ -50,6 +59,17 @@ export default defineComponent({
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
extensionInstalled() {
|
||||
return document.getElementById('extension-id');
|
||||
},
|
||||
extensionId() {
|
||||
return document.getElementById('extension-id')?.getAttribute('value');
|
||||
},
|
||||
extensionVersion() {
|
||||
return document.getElementById('extension-version')?.getAttribute('value');
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
this.loading = true;
|
||||
PlatformService.getAll().then(({ data: data }: { data: IPlatformListResponse }): void => {
|
||||
@@ -59,8 +79,17 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
onSetup(row) {
|
||||
console.log('333');
|
||||
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
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export interface IPlatform {
|
||||
id: number;
|
||||
name: string;
|
||||
alias: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export const PLATFORM_ALIAS_JUEJIN = 'juejin';
|
||||
export const PLATFORM_ALIAS_CSDN = 'csdn';
|
||||
export const PLATFORM_ALIAS_ZHIHU = 'zhihu';
|
||||
export const PLATFORM_ALIAS_SIFOU = 'sifou';
|
||||
export const PLATFORM_DOMAIN_JUEJIN = '.juejin.cn';
|
||||
export const PLATFORM_DOMAIN_CSDN = '.csdn.net';
|
||||
export const PLATFORM_DOMAIN_ZHIHU = '.zhihu.com';
|
||||
export const PLATFORM_DOMAIN_SIFOU = '.segmentfault.com';
|
||||
|
||||
export const PLATFORM_ALIAS_DOMAIN_MAP = {
|
||||
[PLATFORM_ALIAS_JUEJIN]: PLATFORM_DOMAIN_JUEJIN,
|
||||
[PLATFORM_ALIAS_CSDN]: PLATFORM_DOMAIN_CSDN,
|
||||
[PLATFORM_ALIAS_ZHIHU]: PLATFORM_DOMAIN_ZHIHU,
|
||||
[PLATFORM_ALIAS_SIFOU]: PLATFORM_DOMAIN_SIFOU
|
||||
};
|
||||
|
||||
export type IAlias = typeof PLATFORM_ALIAS_JUEJIN | typeof PLATFORM_ALIAS_CSDN | typeof PLATFORM_ALIAS_ZHIHU;
|
||||
|
||||
export const getDomainByAlias = (alias: IAlias) => {
|
||||
return PLATFORM_ALIAS_DOMAIN_MAP[alias];
|
||||
};
|
||||
+34
-1
@@ -1,12 +1,16 @@
|
||||
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';
|
||||
|
||||
export interface IState {
|
||||
count: number;
|
||||
accessToken: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
user: IUser | undefined;
|
||||
cookies: {
|
||||
[PLATFORM_ALIAS_JUEJIN]: string;
|
||||
};
|
||||
}
|
||||
|
||||
const store = createStore({
|
||||
@@ -15,7 +19,10 @@ const store = createStore({
|
||||
count: 0,
|
||||
accessToken: undefined,
|
||||
refreshToken: undefined,
|
||||
user: undefined
|
||||
user: undefined,
|
||||
cookies: {
|
||||
[PLATFORM_ALIAS_JUEJIN]: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
@@ -33,6 +40,17 @@ const store = createStore({
|
||||
...state.user,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
setCookies(
|
||||
state: IState,
|
||||
payload: {
|
||||
alias: IPlatformAlias;
|
||||
value: Array<any>;
|
||||
}
|
||||
): void {
|
||||
console.log('cookies', payload);
|
||||
console.log('cookies', JSON.stringify(payload.value));
|
||||
state.cookies[payload.alias] = JSON.stringify(payload.value);
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@@ -49,6 +67,16 @@ const store = createStore({
|
||||
},
|
||||
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
|
||||
commit('setUser', payload);
|
||||
},
|
||||
setCookies(
|
||||
{ commit }: ActionContext<IState, IState>,
|
||||
payload: {
|
||||
alias: IPlatformAlias;
|
||||
value: Array<any>;
|
||||
}
|
||||
) {
|
||||
console.log('setCookies', payload);
|
||||
commit('setCookies', payload);
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -63,6 +91,11 @@ const store = createStore({
|
||||
},
|
||||
user(state): IUser | undefined {
|
||||
return state.user;
|
||||
},
|
||||
cookies(state) {
|
||||
return (alias: string) => {
|
||||
return JSON.parse(state.cookies[alias]);
|
||||
};
|
||||
}
|
||||
},
|
||||
plugins: [createPersistedState()]
|
||||
|
||||
@@ -195,6 +195,14 @@
|
||||
estree-walker "^1.0.1"
|
||||
picomatch "^2.2.2"
|
||||
|
||||
"@types/chrome@^0.0.157":
|
||||
version "0.0.157"
|
||||
resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.157.tgz#5a50bd378f4f632383c6ebbc34c88fb87d501f58"
|
||||
integrity sha512-q5SSmA9nKaDzFi8QkJW9kW8MYwWg9O7PKPUdBxsz+3rPcIF1Kxw0Bexpd70Uq1mU6PN4DBp4qKMXQDybUeiI9w==
|
||||
dependencies:
|
||||
"@types/filesystem" "*"
|
||||
"@types/har-format" "*"
|
||||
|
||||
"@types/estree@0.0.39":
|
||||
version "0.0.39"
|
||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
|
||||
@@ -205,6 +213,23 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.48.tgz#18dc8091b285df90db2f25aa7d906cfc394b7f74"
|
||||
integrity sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==
|
||||
|
||||
"@types/filesystem@*":
|
||||
version "0.0.32"
|
||||
resolved "https://registry.yarnpkg.com/@types/filesystem/-/filesystem-0.0.32.tgz#307df7cc084a2293c3c1a31151b178063e0a8edf"
|
||||
integrity sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==
|
||||
dependencies:
|
||||
"@types/filewriter" "*"
|
||||
|
||||
"@types/filewriter@*":
|
||||
version "0.0.29"
|
||||
resolved "https://registry.yarnpkg.com/@types/filewriter/-/filewriter-0.0.29.tgz#a48795ecadf957f6c0d10e0c34af86c098fa5bee"
|
||||
integrity sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==
|
||||
|
||||
"@types/har-format@*":
|
||||
version "1.2.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/har-format/-/har-format-1.2.7.tgz#debfe36378f26c4fc2abca1df99f00a8ff94fd29"
|
||||
integrity sha512-/TPzUG0tJn5x1TUcVLlDx2LqbE58hyOzDVAc9kf8SpOEmguHjU6bKUyfqb211AdqLOmU/SNyXvLKPNP5qTlfRw==
|
||||
|
||||
"@types/lodash@^4.14.172":
|
||||
version "4.14.172"
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.172.tgz#aad774c28e7bfd7a67de25408e03ee5a8c3d028a"
|
||||
|
||||
Reference in new issue
Block a user