Move distribution entry to navigator (#34)

This commit is contained in:
AceDataCloud committed 2024-01-07 12:21:29 +00:00
1 parent 74eff9ffda
commit 23158b67f4
14 files changed
+102 -73

No files matched your search

-182
View File
@@ -1,182 +0,0 @@
<template>
<el-row class="panel">
<el-col :span="24">
<el-row>
<el-col :span="24">
<h2 class="title">{{ $t('common.title.distributionHistory') }}</h2>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-card shadow="hover">
<el-table v-loading="loading" :data="distributionHistories" stripe>
<el-table-column prop="id" :label="$t('distribution.field.id')" class-name="text-center" width="350px">
<template #default="scope">
<span class="key">{{ scope.row.id }}</span>
<span class="copy">
<copy-to-clipboard :content="scope.row.id" />
</span>
</template>
</el-table-column>
<el-table-column
prop="id"
:label="$t('distribution.field.userId')"
class-name="text-center"
width="350px"
>
<template #default="scope">
<span class="key">{{ scope.row.user_id }}</span>
<span class="copy">
<copy-to-clipboard :content="scope.row.user_id" />
</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.price')" width="100px">
<template #default="scope">
<span class="price">¥{{ scope.row?.price?.toFixed(2) }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.reward')" width="100px">
<template #default="scope">
<span class="description">¥{{ scope.row?.reward?.toFixed(2) }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.percentage')" width="100px">
<template #default="scope">
<span class="description">{{ scope.row.percentage }}%</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.createdAt')" width="200px">
<template #default="scope">
<span class="created-at">{{ $dayjs.format(scope.row.created_at) }}</span>
</template>
</el-table-column>
</el-table>
</el-card>
</el-col>
</el-row>
<el-row>
<el-col :span="10" :offset="14">
<div class="pagination m-v-lg">
<pagination :current-page="page" :page-size="limit" :total="total" @change="onPageChange"> </pagination>
</div>
</el-col>
</el-row>
</el-col>
</el-row>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Pagination from '@/components/common/Pagination.vue';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { ElRow, ElCol, ElTable, ElTableColumn, ElCard } from 'element-plus';
import { distributionHistoryOperator, IDistributionHistory, IDistributionStatus } from '@/operators/distribution';
interface IData {
distributionHistories: IDistributionHistory[];
distributionStatus: IDistributionStatus | undefined;
loading: boolean;
total: number | undefined;
limit: number;
}
export default defineComponent({
name: 'ConsoleDistributionList',
components: {
Pagination,
CopyToClipboard,
ElRow,
ElCol,
ElTable,
ElTableColumn,
ElCard
},
data(): IData {
return {
distributionHistories: [],
distributionStatus: undefined,
loading: false,
total: undefined,
limit: 10
};
},
computed: {
redirect() {
return this.$route.query.redirect;
},
page() {
return parseInt(this.$route.query.page?.toString() || '1');
}
},
watch: {
page: {
handler() {
this.onFetchData();
}
}
},
mounted() {
this.onFetchData();
},
methods: {
onPageChange(page: number) {
this.$router.push({
name: this.$route.name?.toString(),
query: {
page: page
}
});
},
onFetchData() {
this.loading = true;
Promise.all([this.onFetchDistributionHistory()]).finally(() => {
this.loading = false;
});
},
async onFetchDistributionHistory() {
const { data } = await distributionHistoryOperator.getAll({
user_id: this.$store.getters.user.id,
ordering: '-created_at',
limit: this.limit,
offset: (this.page - 1) * this.limit
});
this.distributionHistories = data.items;
this.total = data.count;
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 26px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
.el-table {
min-height: calc(100vh - 300px);
margin-bottom: 50px;
}
.panel {
padding: 30px;
width: calc(100% - 300px);
background-color: #f3f5f6;
height: 100%;
overflow-y: scroll;
.api-key {
.copy {
cursor: pointer;
margin: 0 10px;
}
}
}
.pagination {
float: right;
}
</style>
-435
View File
@@ -1,435 +0,0 @@
<template>
<el-row class="panel">
<el-col :span="24">
<el-row>
<el-col :span="24">
<h2 class="title">{{ $t('common.title.distribution') }}</h2>
<p class="message mb-4">
{{ $t('distribution.message.distributionDescription') }}
</p>
</el-col>
</el-row>
<el-row :gutter="15">
<el-col :md="6" :xs="24">
<el-card shadow="hover" class="item-mini mb-4">
<el-skeleton v-if="loading" />
<div v-else>
<div class="icon-wrapper">
<font-awesome-icon icon="fa-solid fa-wallet" class="icon" />
</div>
<div class="text-left">
<p class="description">{{ $t('distribution.title.price') }}</p>
<p class="value">¥{{ distributionStatus?.price?.toFixed(2) }}</p>
</div>
<el-button type="primary" class="btn" @click="goHistory"
>{{ $t('distribution.button.detail') }}
</el-button>
</div>
</el-card>
</el-col>
<el-col :md="6" :xs="24">
<el-card shadow="hover" class="item-mini mb-4">
<el-skeleton v-if="loading" />
<div v-else>
<div class="icon-wrapper">
<font-awesome-icon icon="fa-solid fa-coins" class="icon" />
</div>
<div class="text-left">
<p class="description">{{ $t('distribution.title.reward') }}</p>
<p class="value">¥{{ distributionStatus?.reward?.toFixed(2) }}</p>
</div>
<el-tooltip effect="dark" :content="$t('distribution.message.howToWithdrawal')" placement="top">
<el-button type="primary" class="btn">{{ $t('distribution.button.withdrawal') }} </el-button>
</el-tooltip>
</div>
</el-card>
</el-col>
<el-col :md="6" :xs="24">
<el-card shadow="hover" class="item-mini mb-4">
<el-skeleton v-if="loading" />
<div v-else>
<div class="icon-wrapper">
<font-awesome-icon icon="fa-solid fa-percent" class="icon" />
</div>
<div class="text-left">
<p class="description">{{ $t('distribution.title.percentage') }}</p>
<p class="value">{{ distributionStatus?.level?.percentage }}%</p>
</div>
</div>
</el-card>
</el-col>
<el-col :md="6" :xs="24">
<el-card shadow="hover" class="item-mini mb-4">
<el-skeleton v-if="loading" />
<div v-else>
<div class="icon-wrapper">
<font-awesome-icon icon="fa-regular fa-user" class="icon" />
</div>
<div class="text-left">
<p class="description">{{ $t('distribution.title.inviteesCount') }}</p>
<p class="value">{{ inviteesCount }}</p>
</div>
<el-button type="primary" class="btn" @click="goInvitees"
>{{ $t('distribution.button.detail') }}
</el-button>
</div>
</el-card>
</el-col>
</el-row>
<el-row :gutter="15">
<el-col :md="12" :xs="24">
<el-card shadow="hover" class="distribution-info mb-4">
<el-skeleton v-if="loading" />
<div v-else>
<h4 class="title">
{{ $t('distribution.title.distributionLink') }}
</h4>
<el-divider class="mt-4 mb-4" />
<div class="link-wrapper">
<font-awesome-icon v-if="false" icon="fa-solid fa-link" class="icon" />
<a :href="distributionLink" class="link">
{{ distributionLink }}
</a>
<copy-to-clipboard :content="distributionLink" />
</div>
<div class="qr-wrapper">
<qr-code
v-if="distributionLink"
:value="distributionLink"
:size="150"
class="block mb-2 ml-auto mr-auto"
/>
<p>
{{ $t('distribution.message.distributionQrDescription') }}
</p>
</div>
<p class="description">
{{ $t('distribution.message.distributionLinkDescription') }}
<span class="more">
<el-tooltip
effect="dark"
:content="$t('distribution.message.distributionLinkDescription2')"
placement="top"
>
{{ $t('distribution.message.technicalDetail') }}
</el-tooltip>
</span>
</p>
</div>
</el-card>
</el-col>
<el-col :md="12" :xs="24">
<el-card shadow="hover" class="level-info mb-4">
<el-skeleton v-if="loading" />
<div v-else>
<h4 class="title">
{{ $t('distribution.title.levelInfo') }}
</h4>
<el-divider class="mt-4 mb-4" />
<div class="clear-both overflow-hidden">
<div class="float-left description">
<p class="mt-0">
{{ $t('distribution.title.currentLevel') }}: L{{ distributionStatus?.level?.level }}
</p>
<p class="mt-0">
{{ $t('distribution.title.currentPercentage') }}:
{{ distributionLevelMap[distributionStatus?.level?.level!]?.percentage }}%
</p>
</div>
<div class="float-right description">
<p class="mt-0">
{{ $t('distribution.title.nextLevel') }}: L{{ distributionStatus?.level?.level! + 1 }}
</p>
<p class="mt-0">
{{ $t('distribution.title.nextPercentage') }}:
{{ distributionLevelMap[distributionStatus?.level?.level! + 1]?.percentage }}%
</p>
</div>
</div>
<el-progress
:text-inside="true"
:stroke-width="20"
:percentage="getPercentageForNextLevel()"
class="mb-2"
>
</el-progress>
<p class="description">
{{ $t('distribution.message.deltaPriceForNextLevel') }}: ¥{{ getDeltaForNextLevel() }}
</p>
<el-divider />
<el-table v-if="distributionLevels" :data="distributionLevels" stripe>
<el-table-column :label="$t('distribution.field.level')">
<template #default="scope">
<span class="level">L{{ scope.row?.level }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.threshold')">
<template #default="scope">
<span class="level">¥{{ scope.row?.threshold }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.percentage')">
<template #default="scope">
<span class="level">{{ scope.row?.percentage }}%</span>
</template>
</el-table-column>
</el-table>
</div>
</el-card>
</el-col>
</el-row>
</el-col>
</el-row>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import {
ElRow,
ElCol,
ElProgress,
ElTable,
ElTableColumn,
ElButton,
ElCard,
ElDivider,
ElTooltip,
ElSkeleton
} from 'element-plus';
import {
distributionLevelOperator,
distributionStatusOperator,
IDistributionLevel,
IDistributionStatus
} from '@/operators';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ROUTE_CONSOLE_DISTRIBUTION_HISTORY, ROUTE_CONSOLE_DISTRIBUTION_INVITEES } from '@/router';
import { IUser, userOperator } from '@/operators';
import QrCode from 'qrcode.vue';
interface IData {
invitees: IUser[];
inviteesCount: number | undefined;
distributionLevels: IDistributionLevel[];
distributionStatus: IDistributionStatus | undefined;
loading: boolean;
}
export default defineComponent({
name: 'ConsoleDistributionList',
components: {
CopyToClipboard,
FontAwesomeIcon,
QrCode,
ElProgress,
ElRow,
ElCol,
ElButton,
ElDivider,
ElCard,
ElTooltip,
ElTable,
ElTableColumn,
ElSkeleton
},
data(): IData {
return {
invitees: [],
inviteesCount: undefined,
distributionLevels: [],
distributionStatus: undefined,
loading: false
};
},
computed: {
redirect() {
return this.$route.query.redirect;
},
page() {
return parseInt(this.$route.query.page?.toString() || '1');
},
distributionLevelMap() {
let result: {
[key: number]: IDistributionLevel;
} = {};
this.distributionLevels.forEach((item) => {
result[item.level] = item;
});
return result;
},
distributionLink() {
const origin = window.location.origin;
if (!this.$store.getters.user?.id) {
return origin;
}
return `${origin}?inviter_id=${this.$store.getters.user.id}`;
}
},
watch: {
page: {
handler() {
this.onFetchData();
}
}
},
async mounted() {
this.onFetchData();
},
methods: {
goHistory() {
this.$router.push({
name: ROUTE_CONSOLE_DISTRIBUTION_HISTORY
});
},
goInvitees() {
this.$router.push({
name: ROUTE_CONSOLE_DISTRIBUTION_INVITEES
});
},
onPageChange(page: number) {
this.$router.push({
name: this.$route.name?.toString(),
query: {
page: page
}
});
},
getPercentageForNextLevel() {
const currentThreshold = this.distributionLevelMap[this.distributionStatus?.level?.level!]?.threshold;
const nextThreshold = this.distributionLevelMap[this.distributionStatus?.level?.level! + 1]?.threshold;
return Math.floor(
((this.distributionStatus?.price! - currentThreshold!) / (nextThreshold! - currentThreshold!)) * 100
);
},
getDeltaForNextLevel() {
const nextThreshold = this.distributionLevelMap[this.distributionStatus?.level?.level! + 1]?.threshold;
return Math.floor(nextThreshold - this.distributionStatus?.price!);
},
async onFetchData() {
this.loading = true;
await distributionStatusOperator.initialize();
Promise.all([this.onFetchDistributionStatus(), this.onFetchDistributionLevels(), this.onFetchInvitees()]).finally(
() => {
this.loading = false;
}
);
},
async onFetchDistributionStatus() {
const { data } = await distributionStatusOperator.getAll({
user_id: this.$store.getters.user.id
});
if (data.items && data.items.length > 0) {
this.distributionStatus = data.items[0];
}
},
async onFetchDistributionLevels() {
const { data } = await distributionLevelOperator.getAll();
this.distributionLevels = data.items;
},
async onFetchInvitees() {
const { data } = await userOperator.getInvitees({});
this.invitees = data.items;
this.inviteesCount = data.count;
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 26px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
.item-mini {
position: relative;
.icon-wrapper {
height: 40px;
width: 40px;
line-height: 40px;
border-radius: 50%;
background-color: #eee;
text-align: center;
margin-bottom: 10px;
.icon {
color: var(--el-color-primary);
}
}
.btn {
position: absolute;
right: 20px;
top: 50%;
border-radius: 20px;
transform: translateY(-50%);
}
.value {
font-weight: 600;
font-size: 30px;
margin: 0;
}
.description {
color: #999;
font-size: 14px;
margin-bottom: 5px;
}
}
.level-info,
.distribution-info {
.title {
font-size: 20px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
.icon {
margin-right: 5px;
}
.qr-wrapper {
padding: 15px 0;
p {
text-align: center;
color: #999;
font-size: 12px;
}
}
.link-wrapper {
margin-bottom: 10px;
.link {
color: var(--el-color-primary);
cursor: pointer;
text-decoration: dashed;
font-size: 14px;
margin-bottom: 10px;
}
}
.description {
color: #999;
font-size: 14px;
margin-bottom: 10px;
.more {
color: var(--el-color-primary);
cursor: pointer;
}
}
}
.panel {
padding: 30px;
width: calc(100% - 300px);
background-color: #f3f5f6;
height: 100%;
overflow-y: scroll;
.message {
font-size: 14px;
color: #666;
}
}
</style>
-159
View File
@@ -1,159 +0,0 @@
<template>
<el-row class="panel">
<el-col :span="24">
<el-row>
<el-col :span="24">
<h2 class="title">{{ $t('common.title.invitee') }}</h2>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-card shadow="hover">
<el-table v-loading="loading" :data="invitees" stripe>
<el-table-column prop="id" :label="$t('user.field.id')" class-name="text-center" width="350px">
<template #default="scope">
<span class="key">{{ scope.row.id }}</span>
<span class="copy">
<copy-to-clipboard :content="scope.row.id" />
</span>
</template>
</el-table-column>
<el-table-column :label="$t('user.field.username')" width="300px">
<template #default="scope">
<span class="description">{{ scope.row?.username }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('user.field.nickname')" width="200px">
<template #default="scope">
<span class="description">{{ scope.row.nickname }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('user.field.isVerified')" width="100px">
<template #default="scope">
<el-switch :model-value="scope.row?.is_verified" />
</template>
</el-table-column>
<el-table-column :label="$t('user.field.dateJoined')">
<template #default="scope">
<span class="created-at">{{ $dayjs.format(scope.row.date_joined) }}</span>
</template>
</el-table-column>
</el-table>
</el-card>
</el-col>
</el-row>
<el-row>
<el-col :span="10" :offset="14">
<div class="pagination m-v-lg">
<pagination :current-page="page" :page-size="limit" :total="total" @change="onPageChange"> </pagination>
</div>
</el-col>
</el-row>
</el-col>
</el-row>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Pagination from '@/components/common/Pagination.vue';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { ElRow, ElCol, ElTable, ElTableColumn, ElCard, ElSwitch } from 'element-plus';
import { IUser, userOperator } from '@/operators';
interface IData {
invitees: IUser[];
loading: boolean;
total: number | undefined;
limit: number;
}
export default defineComponent({
name: 'ConsoleDistributionInvitees',
components: {
Pagination,
CopyToClipboard,
ElRow,
ElSwitch,
ElCol,
ElTable,
ElTableColumn,
ElCard
},
data(): IData {
return {
invitees: [],
loading: false,
total: undefined,
limit: 10
};
},
computed: {
redirect() {
return this.$route.query.redirect;
},
page() {
return parseInt(this.$route.query.page?.toString() || '1');
}
},
watch: {
page: {
handler() {
this.onFetchData();
}
}
},
mounted() {
this.onFetchData();
},
methods: {
onPageChange(page: number) {
this.$router.push({
name: this.$route.name?.toString(),
query: {
page: page
}
});
},
onFetchData() {
this.loading = true;
Promise.all([this.onFetchInvitees()]).finally(() => {
this.loading = false;
});
},
async onFetchInvitees() {
const { data } = await userOperator.getInvitees({
limit: this.limit,
offset: (this.page - 1) * this.limit
});
this.invitees = data.items;
this.total = data.count;
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 26px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
.el-table {
min-height: calc(100vh - 300px);
margin-bottom: 50px;
}
.panel {
padding: 30px;
width: calc(100% - 300px);
background-color: #f3f5f6;
height: 100%;
overflow-y: scroll;
}
.pagination {
float: right;
}
</style>