Files
certd/packages/ui/certd-client/src/components/vip-button/index.vue
T

450 lines
12 KiB
Vue
Raw Normal View History

2024-08-14 21:24:12 +08:00
<template>
2024-10-11 03:23:03 +08:00
<div v-if="!settingStore.isComm || userStore.isAdmin" class="layout-vip isPlus" @click="openUpgrade">
2024-08-14 21:24:12 +08:00
<contextHolder />
2024-09-01 04:49:26 +08:00
<fs-icon icon="mingcute:vip-1-line" :title="text.title" />
<div v-if="mode !== 'icon'" class="text">
<a-tooltip>
<template #title> {{ text.title }}</template>
<span>{{ text.name }}</span>
</a-tooltip>
2024-08-14 21:24:12 +08:00
</div>
</div>
</template>
<script lang="tsx" setup>
2024-11-30 01:57:09 +08:00
import { computed, onMounted, reactive } from "vue";
2024-08-14 21:24:12 +08:00
import dayjs from "dayjs";
import { message, Modal } from "ant-design-vue";
import * as api from "./api";
2024-08-25 01:55:34 +08:00
import { useSettingStore } from "/@/store/modules/settings";
2024-09-24 02:42:08 +08:00
import { useRouter } from "vue-router";
2024-10-05 01:46:25 +08:00
import { useUserStore } from "/@/store/modules/user";
2024-11-30 01:57:09 +08:00
import { mitter } from "/@/utils/util.mitt";
2024-11-17 01:06:27 +08:00
2024-10-05 01:46:25 +08:00
const settingStore = useSettingStore();
2024-09-01 04:49:26 +08:00
const props = withDefaults(
defineProps<{
2024-11-30 01:57:09 +08:00
mode?: "comm" | "button" | "nav" | "icon";
2024-09-01 04:49:26 +08:00
}>(),
{
mode: "button"
}
);
type Text = {
name: string;
title?: string;
2024-08-24 23:48:26 +08:00
};
2024-09-01 04:49:26 +08:00
const text = computed<Text>(() => {
2024-10-05 01:46:25 +08:00
const vipLabel = settingStore.vipLabel;
2024-09-01 04:49:26 +08:00
const map = {
2024-11-30 01:57:09 +08:00
isComm: {
comm: {
name: `${vipLabel}已开通`,
title: "到期时间:" + expireTime.value
},
button: {
name: `${vipLabel}已开通`,
title: "到期时间:" + expireTime.value
},
icon: {
name: "",
title: `${vipLabel}已开通`
},
nav: {
name: `${vipLabel}`,
title: "到期时间:" + expireTime.value
}
},
2024-09-01 04:49:26 +08:00
isPlus: {
2024-11-30 01:57:09 +08:00
comm: {
name: "商业版功能",
title: "升级商业版,获取商业授权"
},
2024-09-01 04:49:26 +08:00
button: {
2024-10-03 01:29:12 +08:00
name: `${vipLabel}已开通`,
2024-09-01 04:49:26 +08:00
title: "到期时间:" + expireTime.value
},
icon: {
name: "",
2024-10-03 01:29:12 +08:00
title: `${vipLabel}已开通`
2024-09-01 04:49:26 +08:00
},
nav: {
2024-10-03 01:29:12 +08:00
name: `${vipLabel}`,
2024-09-01 04:49:26 +08:00
title: "到期时间:" + expireTime.value
}
},
free: {
2024-11-30 01:57:09 +08:00
comm: {
name: "商业版功能",
title: "升级商业版,获取商业授权"
},
2024-09-01 04:49:26 +08:00
button: {
2024-11-30 01:57:09 +08:00
name: "专业版功能",
2024-09-01 04:49:26 +08:00
title: "升级专业版,享受更多VIP特权"
},
icon: {
name: "",
2024-11-30 01:57:09 +08:00
title: "专业版功能"
2024-09-01 04:49:26 +08:00
},
nav: {
2024-10-23 16:33:53 +08:00
name: "基础版",
2024-09-01 04:49:26 +08:00
title: "升级专业版,享受更多VIP特权"
}
}
};
2024-11-30 01:57:09 +08:00
if (settingStore.isComm) {
return map.isComm[props.mode];
} else if (settingStore.isPlus) {
2024-09-01 04:49:26 +08:00
return map.isPlus[props.mode];
2024-08-24 23:48:26 +08:00
} else {
2024-09-01 04:49:26 +08:00
return map.free[props.mode];
2024-08-24 23:48:26 +08:00
}
});
2024-08-25 01:55:34 +08:00
const expireTime = computed(() => {
2024-10-05 01:46:25 +08:00
if (settingStore.isPlus) {
return dayjs(settingStore.plusInfo.expireTime).format("YYYY-MM-DD");
2024-08-25 01:55:34 +08:00
}
return "";
});
const expiredDays = computed(() => {
2024-10-05 01:46:25 +08:00
if (settingStore.plusInfo?.isPlus && !settingStore.isPlus) {
2024-08-25 01:55:34 +08:00
//已过期多少天
2024-10-05 01:46:25 +08:00
const days = dayjs().diff(dayjs(settingStore.plusInfo.expireTime), "day");
return `${settingStore.vipLabel}已过期${days}`;
2024-08-25 01:55:34 +08:00
}
return "";
});
2024-08-14 21:24:12 +08:00
const formState = reactive({
2024-12-09 00:12:15 +08:00
code: "",
inviteCode: ""
2024-08-14 21:24:12 +08:00
});
2024-09-24 02:42:08 +08:00
const router = useRouter();
2024-08-14 21:24:12 +08:00
async function doActive() {
if (!formState.code) {
message.error("请输入激活码");
throw new Error("请输入激活码");
}
const res = await api.doActive(formState);
if (res) {
2024-10-14 11:52:37 +08:00
await settingStore.init();
2024-10-05 01:46:25 +08:00
const vipLabel = settingStore.vipLabel;
2024-08-14 21:24:12 +08:00
Modal.success({
title: "激活成功",
2024-10-05 01:46:25 +08:00
content: `您已成功激活${vipLabel},有效期至:${dayjs(settingStore.plusInfo.expireTime).format("YYYY-MM-DD")}`,
2024-09-24 02:42:08 +08:00
onOk() {
if (!(settingStore.installInfo.bindUserId > 0)) {
//未绑定账号
Modal.confirm({
title: "是否绑定袖手账号",
2024-10-03 01:29:12 +08:00
content: "绑定账号后,可以避免License丢失,强烈建议绑定",
2024-09-24 02:42:08 +08:00
onOk() {
router.push("/sys/account");
}
});
}
}
2024-08-14 21:24:12 +08:00
});
}
}
2024-08-25 01:55:34 +08:00
const computedSiteId = computed(() => settingStore.installInfo?.siteId);
2024-08-14 21:24:12 +08:00
const [modal, contextHolder] = Modal.useModal();
2024-10-05 01:46:25 +08:00
const userStore = useUserStore();
2024-11-08 17:33:30 +08:00
function goAccount() {
Modal.destroyAll();
router.push("/sys/account");
}
2024-11-17 01:06:27 +08:00
async function getVipTrial() {
const res = await api.getVipTrial();
message.success(`恭喜,您已获得专业版${res.duration}天试用`);
await settingStore.init();
}
2024-11-08 17:33:30 +08:00
function openTrialModal() {
Modal.destroyAll();
modal.confirm({
title: "7天专业版试用获取",
2024-11-17 01:06:27 +08:00
okText: "立即获取",
2024-11-08 17:33:30 +08:00
onOk() {
2024-11-17 01:06:27 +08:00
getVipTrial();
2024-11-08 17:33:30 +08:00
},
width: 600,
content: () => {
return (
<div class="flex-col mt-10 mb-10">
<div>感谢您对开源项目的支持</div>
2024-11-17 01:06:27 +08:00
<div>点击确认即可获取7天专业版试用</div>
2024-11-08 17:33:30 +08:00
</div>
);
}
});
}
function openStarModal() {
Modal.destroyAll();
const goGithub = () => {
window.open("https://github.com/certd/certd/");
};
modal.confirm({
title: "7天专业版试用获取",
okText: "立即去Star",
onOk() {
goGithub();
openTrialModal();
},
width: 600,
content: () => {
return (
<div class="flex mt-10 mb-10">
<div>可以先请您帮忙点个star吗感谢感谢</div>
<img class="ml-5" src="https://img.shields.io/github/stars/certd/certd?logo=github" />
</div>
);
}
});
}
2024-08-14 21:24:12 +08:00
function openUpgrade() {
2024-09-02 01:02:41 +08:00
if (!userStore.isAdmin) {
message.info("仅限管理员操作");
return;
}
2024-08-14 21:24:12 +08:00
const placeholder = "请输入激活码";
2024-10-05 01:46:25 +08:00
const isPlus = settingStore.isPlus;
2024-10-03 01:29:12 +08:00
let title = "激活专业版/商业版";
2024-10-05 01:46:25 +08:00
if (settingStore.isComm) {
2024-10-03 01:29:12 +08:00
title = "续期商业版";
2024-10-05 01:46:25 +08:00
} else if (settingStore.isPlus) {
2024-10-03 01:29:12 +08:00
title = "续期专业版/升级商业版";
}
2024-11-08 16:53:45 +08:00
const vipTypeDefine = {
free: {
title: "基础版",
2024-12-23 23:33:13 +08:00
desc: "社区免费版",
2024-11-08 16:53:45 +08:00
type: "free",
2024-12-24 01:12:12 +08:00
icon: "lucide:package-open",
2024-12-23 23:33:13 +08:00
privilege: ["证书申请无限制", "域名数量无限制", "证书流水线数量无限制", "常用的主机、云平台、cdn等部署插件", "邮件、webhook通知方式"]
2024-11-08 16:53:45 +08:00
},
plus: {
title: "专业版",
2024-12-23 23:33:13 +08:00
desc: "开源需要您的赞助支持",
2024-11-08 16:53:45 +08:00
type: "plus",
2024-12-23 23:33:13 +08:00
privilege: ["可加VIP群,您需求将优先实现", "站点证书监控无限制", "更多通知方式", "更多强大部署插件,宝塔、群晖、1Panel等"],
2024-11-08 16:53:45 +08:00
trial: {
2024-12-23 23:33:13 +08:00
title: "点击获取7天试用",
2024-11-08 16:53:45 +08:00
click: () => {
2024-11-08 17:33:30 +08:00
openStarModal();
2024-11-08 16:53:45 +08:00
}
2024-12-23 23:33:13 +08:00
},
2024-12-24 01:12:12 +08:00
icon: "stash:thumb-up",
2024-12-23 23:33:13 +08:00
price: 29.9,
get() {
return (
<a-tooltip title="爱发电赞助“VIP会员”后获取一年期专业版激活码,开源需要您的支持">
<a-button size="small" type="primary" href="https://afdian.com/a/greper" target="_blank">
爱发电赞助后获取
</a-button>
</a-tooltip>
);
2024-11-08 16:53:45 +08:00
}
},
comm: {
title: "商业版",
desc: "商业授权,可对外运营",
2024-11-08 16:53:45 +08:00
type: "comm",
2024-12-24 01:12:12 +08:00
icon: "vaadin:handshake",
2024-12-23 23:33:13 +08:00
privilege: ["拥有专业版所有特权", "允许商用,可修改logo、标题", "数据统计", "插件管理", "多用户无限制", "支持用户支付"],
price: 399,
get() {
return <a-button size="small">请联系作者获取</a-button>;
}
2024-11-08 16:53:45 +08:00
}
};
const modalRef = modal.confirm({
2024-10-03 01:29:12 +08:00
title,
2024-08-14 21:24:12 +08:00
async onOk() {
2024-08-21 12:38:09 +08:00
return await doActive();
2024-08-14 21:24:12 +08:00
},
2024-10-01 23:52:44 +08:00
maskClosable: true,
2024-08-21 12:38:09 +08:00
okText: "激活",
2024-12-23 23:33:13 +08:00
width: 1000,
2024-08-14 21:24:12 +08:00
content: () => {
2024-12-23 23:33:13 +08:00
let activationCodeGetWay = (
<span>
<a href="https://afdian.com/a/greper" target="_blank">
爱发电赞助VIP会员后获取一年期专业版激活码
</a>
<span> 商业版请直接联系作者</span>
</span>
);
2024-10-05 01:46:25 +08:00
const vipLabel = settingStore.vipLabel;
const slots = [];
for (const key in vipTypeDefine) {
2024-10-10 18:38:22 +08:00
// @ts-ignore
2024-10-05 01:46:25 +08:00
const item = vipTypeDefine[key];
const vipBlockClass = `vip-block ${key === settingStore.plusInfo.vipType ? "current" : ""}`;
slots.push(
<a-col span={8}>
<div class={vipBlockClass}>
2024-12-24 01:12:12 +08:00
<h3 class="block-header ">
<span class="flex-o">{item.title}</span>
2024-11-08 16:53:45 +08:00
{item.trial && (
<span class="trial">
<a-tooltip title={item.trial.message}>
<a onClick={item.trial.click}>{item.trial.title}</a>
</a-tooltip>
</span>
)}
</h3>
2024-12-24 01:12:12 +08:00
<div style="color:green" class="flex-o">
<fs-icon icon={item.icon} class="fs-16 flex-o" />
{item.desc}
</div>
<ul class="flex-1 privilege">
2024-10-10 18:38:22 +08:00
{item.privilege.map((p: string) => (
2024-12-23 23:33:13 +08:00
<li class="flex-baseline">
2024-10-05 01:46:25 +08:00
<fs-icon class="color-green" icon="ion:checkmark-sharp" />
{p}
</li>
))}
</ul>
2024-12-23 23:33:13 +08:00
<div class="footer flex-between flex-vc">
<div class="price-show">
{item.price && (
<span>
<span class="price-text">¥{item.price}</span>
/
</span>
)}
{!item.price && (
<span>
<span class="price-text">免费</span>
</span>
)}
</div>
<div class="get-show">{item.get && <div>{item.get()}</div>}</div>
</div>
2024-10-05 01:46:25 +08:00
</div>
</a-col>
);
}
2024-08-14 21:24:12 +08:00
return (
2024-10-03 22:03:49 +08:00
<div class="mt-10 mb-10 vip-active-modal">
<div class="vip-type-vs">
2024-10-05 01:46:25 +08:00
<a-row gutter={20}>{slots}</a-row>
2024-08-21 12:38:09 +08:00
</div>
2024-10-05 01:46:25 +08:00
<div class="mt-10">
2024-09-02 23:55:38 +08:00
<h3 class="block-header">{isPlus ? "续期" : "立刻激活"}</h3>
2024-10-05 01:46:25 +08:00
<div>{isPlus ? `当前${vipLabel}已激活,到期时间` + dayjs(settingStore.plusInfo.expireTime).format("YYYY-MM-DD") : ""}</div>
2024-08-21 12:38:09 +08:00
<div class="mt-10">
2024-08-25 01:55:34 +08:00
<div class="flex-o w-100">
<span>站点ID</span>
<fs-copyable class="flex-1" v-model={computedSiteId.value}></fs-copyable>
</div>
<a-input class="mt-10" v-model:value={formState.code} placeholder={placeholder} />
2024-12-09 00:12:15 +08:00
<a-input class="mt-10" v-model:value={formState.inviteCode} placeholder={"邀请码【选填】,可额外获得专业版30天/商业版15天时长"} />
2024-08-21 12:38:09 +08:00
</div>
<div class="mt-10">
没有激活码
2024-10-10 18:38:22 +08:00
{activationCodeGetWay}
2024-08-21 12:38:09 +08:00
</div>
<div class="mt-10">
激活码使用过一次之后不可再次使用如果要更换站点<a onClick={goAccount}>绑定账号</a>然后"转移VIP"即可
</div>
2024-08-14 21:24:12 +08:00
</div>
</div>
);
}
});
}
2024-11-30 01:57:09 +08:00
onMounted(() => {
mitter.on("openVipModal", () => {
if (props.mode === "nav" && !settingStore.isPlus) {
openUpgrade();
}
});
});
2024-08-14 21:24:12 +08:00
</script>
<style lang="less">
.layout-vip {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
2024-08-24 23:48:26 +08:00
cursor: pointer;
2024-09-01 04:49:26 +08:00
2024-08-14 21:24:12 +08:00
&.isPlus {
color: #c5913f;
}
.text {
margin-left: 5px;
}
}
2024-10-03 22:03:49 +08:00
.vip-active-modal {
2024-10-05 01:46:25 +08:00
.vip-block {
2024-12-23 23:33:13 +08:00
display: flex;
flex-direction: column;
2024-10-05 01:46:25 +08:00
padding: 10px;
border: 1px solid #eee;
border-radius: 5px;
2024-12-23 23:33:13 +08:00
height: 250px;
2024-10-05 01:46:25 +08:00
//background-color: rgba(250, 237, 167, 0.79);
&.current {
border-color: green;
}
.block-header {
padding: 0px;
2024-11-08 16:53:45 +08:00
display: flex;
justify-content: space-between;
.trial {
font-size: 12px;
font-wight: 400;
}
2024-10-05 01:46:25 +08:00
}
2024-12-23 23:33:13 +08:00
.footer {
padding-top: 5px;
margin-top: 0px;
border-top: 1px solid #eee;
.price-text {
font-size: 18px;
color: red;
}
}
2024-10-05 01:46:25 +08:00
}
2024-10-03 22:03:49 +08:00
ul {
list-style-type: unset;
margin-left: 0px;
padding: 0;
}
.color-green {
color: green;
}
2024-10-03 22:03:49 +08:00
.vip-type-vs {
2024-12-24 01:12:12 +08:00
.privilege {
.fs-icon {
color: green;
}
}
2024-10-03 22:03:49 +08:00
.fs-icon {
margin-right: 5px;
}
}
}
2024-08-14 21:24:12 +08:00
</style>