Skip to content

Commit

Permalink
feat: 允许用户删除站点某条记录
Browse files Browse the repository at this point in the history
closed: #537
  • Loading branch information
Rhilip committed Apr 2, 2022
1 parent d9516f1 commit e9b4bbe
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 1 deletion.
6 changes: 6 additions & 0 deletions resource/i18n/en.json
Expand Up @@ -177,6 +177,7 @@
"getUserInfoAbort": "Get user profile request has been canceled. ({siteName})",
"getUserInfoAbortError": "Cancellation failed to get user profile request. ({siteName})",
"headers": {
"date": "Date",
"site": "Site",
"userName": "User name",
"levelName": "Level",
Expand Down Expand Up @@ -676,13 +677,18 @@
"timezone": "Timezone",
"disableMessageCount": "Display message count"
},
"userinfo": {
"title": "User Info",
"deleteConfirm": "confirm deletion? This operation cannot be restored, please make sure that you have made a corresponding backup."
},
"index": {
"importAll": "One-click import site",
"importAllConfirm": "Are you sure you want to import site operations? This will import sites that have been logged in to the browser but have not been added.",
"removeSelectedConfirm": "Are you sure you want to delete the selected site?",
"removeConfirm": "Are you sure you want to delete this site?",
"removeTitle": "Delete confirmation",
"plugins": "Plugins",
"showUserInfo": "UserInfo",
"title": "Site settings",
"subTitle": "Only the configured site will display the plugin icon and the corresponding function; the offline site will no longer participate in the search and information acquisition;",
"searchEntry": "Search Entry",
Expand Down
6 changes: 6 additions & 0 deletions resource/i18n/zh-CN.json
Expand Up @@ -174,6 +174,7 @@
"getUserInfoAbort": "{siteName} 获取用户资料请求已取消",
"getUserInfoAbortError": "{siteName} 获取用户资料请求取消失败",
"headers": {
"date": "日期",
"site": "站点",
"userName": "用户名",
"levelName": "等级",
Expand Down Expand Up @@ -672,13 +673,18 @@
"timezone": "时区",
"disableMessageCount": "关闭消息提醒"
},
"userinfo": {
"title": "用户数据",
"deleteConfirm": "确认删除?这个操作不可恢复,请确认你做好了相应备份。"
},
"index": {
"importAll": "一键导入站点",
"importAllConfirm": "确认要进行导入站点操作吗?此操作会导入已在浏览器上登录过但未添加的站点。",
"removeSelectedConfirm": "确认要删除已选中的站点吗?",
"removeConfirm": "确认要删除这个站点吗?",
"removeTitle": "删除确认",
"plugins": "插件",
"showUserInfo": "用户数据",
"title": "站点设置",
"subTitle": "只有配置过的站点才会显示插件图标及相应的功能;<br/>已离线的站点不再参与搜索和信息获取;",
"searchEntry": "搜索入口",
Expand Down
23 changes: 22 additions & 1 deletion src/options/views/settings/Sites/Index.vue
Expand Up @@ -125,6 +125,13 @@
@click="editPlugins(props.item)"
:title="$t('settings.sites.index.plugins')"
>assistant</v-icon>
<v-icon
v-if="props.item.allowGetUserInfo"
small
class="ml-2"
@click="editUserInfo(props.item)"
:title="$t('setting.sites.index.showUserInfo')"
>view_list</v-icon>
<v-icon
small
class="ml-2"
Expand Down Expand Up @@ -154,6 +161,7 @@
<AddSite v-model="showAddDialog" @save="addSite" />
<!-- 编辑站点 -->
<EditSite v-model="showEditDialog" :site="selectedSite" @save="updateSite" />
<UserInfo v-model="showUserInfo" :site="selectedSite"></UserInfo>

<v-dialog v-model="dialogRemoveConfirm" width="300">
<v-card>
Expand Down Expand Up @@ -206,6 +214,7 @@ import {
} from "@/interface/common";
import AddSite from "./Add.vue";
import EditSite from "./Edit.vue";
import UserInfo from "./UserInfo.vue";
import { filters } from "@/service/filters";
import Extension from "@/service/extension";
Expand All @@ -217,7 +226,8 @@ const extension = new Extension();
export default Vue.extend({
components: {
AddSite,
EditSite
EditSite,
UserInfo
},
data() {
return {
Expand All @@ -227,6 +237,7 @@ export default Vue.extend({
},
showAddDialog: false,
showEditDialog: false,
showUserInfo: false,
siteDuplicate: false,
sites: [] as Site[],
selectedSite: {},
Expand Down Expand Up @@ -258,6 +269,16 @@ export default Vue.extend({
this.showEditDialog = true;
}
},
editUserInfo(item: any) {
let index = this.$store.state.options.sites.findIndex((site: any) => {
return item.name === site.name;
});
if (index !== -1) {
this.selectedSite = this.$store.state.options.sites[index];
this.showUserInfo = true;
}
},
removeConfirm(item: any) {
this.selectedSite = item;
this.dialogRemoveConfirm = true;
Expand Down
202 changes: 202 additions & 0 deletions src/options/views/settings/Sites/UserInfo.vue
@@ -0,0 +1,202 @@
<template>
<v-dialog v-model="show" max-width="1200">
<v-card>
<v-card-title
class="headline blue-grey darken-2"
style="color:white"
>{{ $t('settings.sites.userinfo.title') }}@{{ this.site.name }}</v-card-title>

<v-card-text>
<v-data-table
:headers="headers"
:items="userData"
:pagination.sync="pagination"
>
<template slot="items" slot-scope="props">
<td>{{ props.item.date }}</td>
<td>{{ props.item.name }}</td>
<td>{{ props.item.levelName }}</td>
<td class="number">
<div>
{{ props.item.uploaded | formatSize }}
<v-icon small color="green darken-4">expand_less</v-icon>
</div>
<div>
{{ props.item.downloaded | formatSize }}
<v-icon small color="red darken-4">expand_more</v-icon>
</div>
</td>
<td class="number">{{ props.item.ratio | formatRatio }}</td>
<td class="number">{{ props.item.seeding }}</td>
<td class="number">{{ props.item.seedingSize | formatSize }}</td>
<td class="number">{{ props.item.bonus | formatNumber }}</td>
<td>
<v-icon
small
color="error"
class="ml-2"
@click="removeConfirm(props.item)"
:title="$t('common.remove')"
:disabled="props.item.date === 'latest'"
>delete</v-icon>
</td>
</template>

</v-data-table>
</v-card-text>

<v-divider></v-divider>

<v-card-actions class="pa-3">
<v-spacer></v-spacer>
<v-btn flat color="success" @click="save">
<v-icon>check_circle_outline</v-icon>
<span class="ml-1">{{ $t('common.ok') }}</span>
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script lang="ts">
// @ts-nocheck
import Vue from "vue";
export default Vue.extend({
name: "UserInfo",
data() {
return {
dataKey: 'PT-Plugin-Plus-User-Datas',
show: false,
rawUserData: [],
pagination: {
descending: true,
sortBy: "date",
rowsPerPage: 25
},
headers: [
{
text: this.$t("home.headers.date"),
align: "left",
value: "date",
width: "130px"
},
{
text: this.$t("home.headers.userName"),
align: "left",
value: "name"
},
{
text: this.$t("home.headers.levelName"),
align: "left",
value: "levelName"
},
{
text: this.$t("home.headers.activitiyData"),
align: "right",
value: "uploaded",
width: "160px"
},
{
text: this.$t("home.headers.ratio"),
align: "right",
value: "ratio"
},
{
text: this.$t("home.headers.seeding"),
align: "right",
value: "seeding"
},
{
text: this.$t("home.headers.seedingSize"),
align: "right",
value: "seedingSize"
},
{
text: this.$t("home.headers.bonus"),
align: "right",
value: "bonus"
},
{
text: this.$t("settings.sites.index.headers.action"),
value: "name",
sortable: false,
width: '50px'
}
]
}
},
props: {
value: Boolean,
site: Object
},
model: {
prop: "value",
event: "change"
},
filters: {
formatRatio(v: any) {
if (v > 10000 || v == -1) {
return "";
}
let number = parseFloat(v);
if (isNaN(number)) {
return "";
}
return number.toFixed(2);
}
},
watch: {
show() {
this.$emit("change", this.show);
},
value() {
if (this.value) {
chrome.storage.local.get(this.dataKey, (result) => {
this.rawUserData = result[this.dataKey][this.site.host];
this.show = this.value;
});
}
}
},
computed: {
userData() {
return Object.entries(this.rawUserData).map(v => {
const user = v[1];
const {downloaded, uploaded} = user;
if (downloaded == 0 && uploaded > 0) {
user.ratio = -1;
}
// 重新以 上传量 / 下载量计算分享率
else if (downloaded > 0) {
user.ratio = uploaded / downloaded;
}
user['date'] = v[0];
return user;
})
}
},
methods: {
save() {
this.show = false;
},
removeConfirm(item) {
if (confirm(this.$t('settings.sites.userinfo.deleteConfirm'))) {
this.$delete(this.rawUserData, item.date);
chrome.storage.local.get(this.dataKey, (result) => {
delete result[this.dataKey][this.site.host][item.date];
chrome.storage.local.set(result, () => {
});
});
}
}
}
})
</script>

<style scoped>
.number {
text-align: right;
}
</style>

2 comments on commit e9b4bbe

@Rhilip
Copy link
Collaborator Author

@Rhilip Rhilip commented on e9b4bbe Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

操作方式见: https://t.me/ptpluginplus/103

@lzl20110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大佬,能否增加个多选 我想删除某个日期之前的所有数据 现在一次删除一条太慢了

Please sign in to comment.