Created
August 26, 2023 03:00
-
-
Save fimars/852e5747ca213fd02ad7723c32734295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-nocheck | |
import Plan from 'src/store/plan' | |
import packagePrivileges from 'src/common/constants/packagePrivileges' | |
import objectExt from 'src/utils/objectExt' | |
import { Box, Button } from '@vec6/next-ui' | |
import links from 'src/common/constants/links' | |
import User from 'src/store/user' | |
export default { | |
/** | |
* OSS存储 | |
*/ | |
oss_storage: { | |
errorMessage: () => $i18n._t('not enough storage space.'), | |
condition(value = 0) { | |
const key = packagePrivileges.oss_storage | |
const scope = Plan.getRightsItem(key) | |
if (!scope) return true | |
const limitValue = _.get(scope, 'rights_value', 0) + _.get(scope, 'resource_value', 0) | |
const usedValue = _.get(scope, 'rights_used', 0) + _.get(scope, 'resource_value_used', 0) + value | |
return usedValue > limitValue | |
}, | |
}, | |
/** | |
* 发布页面次数 | |
*/ | |
published_pages: { | |
errorMessage: () => $i18n._t('The number of published pages has reached the maximum limit.'), | |
condition(value = 0) { | |
const key = packagePrivileges.published_pages | |
const scope = Plan.getRightsItem(key) | |
if (!scope) return true | |
const limitValue = _.get(scope, 'rights_value', 0) + _.get(scope, 'resource_value', 0) | |
const usedValue = _.get(scope, 'rights_used', 0) + _.get(scope, 'resource_value_used', 0) + value | |
return usedValue > limitValue | |
}, | |
}, | |
/** | |
* 无限发布页面 | |
*/ | |
unlimited_published_pages: { | |
errorMessage: () => $i18n._t('The number of published pages has reached the maximum limit.'), | |
condition() { | |
const key = packagePrivileges.unlimited_published_pages | |
const scope = Plan.getRightsItem(key) | |
if (!scope) return true | |
return !scope.rights_value | |
}, | |
}, | |
/** | |
* 安装模板 | |
*/ | |
install_template: { | |
errorMessage: () => { | |
return ( | |
<Typography.Text> | |
{ | |
$i18n._t('Unable to install template, please upgrade plan.') | |
} | |
</Typography.Text> | |
) | |
}, | |
condition(template: any) { | |
const pricing_id = Plan.pricing.id | |
const ids: string[] = objectExt | |
.parse(template.used_for, []) | |
.map((item) => item.pricing_id) | |
return !ids.includes(pricing_id) | |
}, | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 审查是否超出套餐权益 | |
* @param key 套餐权益 | |
* @param value 附加值 | |
* @returns | |
*/ | |
export const auditPackagePrivilege = (key: keyof typeof rules, value?: any) => { | |
const handle = rules[key] | |
const checkResult = handle.condition(value) | |
const result = { | |
valid: true, | |
message: () => '', | |
} | |
// 未超过套餐限制 | |
if (!checkResult) return result | |
result.valid = false | |
// @ts-ignore | |
result.message = handle.errorMessage | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment