feat:【antd】【ele】【member 会员】config 迁移 ele
This commit is contained in:
52
apps/web-ele/src/views/member/config/data.ts
Normal file
52
apps/web-ele/src/views/member/config/data.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
|
||||||
|
export const schema: VbenFormSchema[] = [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
fieldName: 'id',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: [''],
|
||||||
|
show: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Switch',
|
||||||
|
fieldName: 'pointTradeDeductEnable',
|
||||||
|
label: '积分抵扣',
|
||||||
|
help: '下单积分是否抵用订单金额',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'InputNumber',
|
||||||
|
fieldName: 'pointTradeDeductUnitPrice',
|
||||||
|
label: '积分抵扣',
|
||||||
|
help: '积分抵用比例(1 积分抵多少金额),单位:元',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
precision: 2,
|
||||||
|
class: 'w-full',
|
||||||
|
placeholder: '请输入积分抵扣单价',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'InputNumber',
|
||||||
|
fieldName: 'pointTradeDeductMaxPrice',
|
||||||
|
label: '积分抵扣最大值',
|
||||||
|
help: '单次下单积分使用上限,0 不限制',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
class: 'w-full',
|
||||||
|
placeholder: '请输入积分抵扣最大值',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'InputNumber',
|
||||||
|
fieldName: 'pointTradeGivePoint',
|
||||||
|
label: '1 元赠送多少分',
|
||||||
|
help: '下单支付金额按比例赠送积分(实际支付 1 元赠送多少积分)',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
class: 'w-full',
|
||||||
|
placeholder: '请输入赠送积分比例',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -4,6 +4,7 @@ import type { MemberConfigApi } from '#/api/member/config';
|
|||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
|
import { fenToYuan, yuanToFen } from '@vben/utils';
|
||||||
|
|
||||||
import { ElCard, ElMessage } from 'element-plus';
|
import { ElCard, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
@@ -11,94 +12,47 @@ import { useVbenForm } from '#/adapter/form';
|
|||||||
import { getConfig, saveConfig } from '#/api/member/config';
|
import { getConfig, saveConfig } from '#/api/member/config';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
const emit = defineEmits(['success']);
|
import { schema } from './data';
|
||||||
|
|
||||||
const formData = ref<MemberConfigApi.Config>();
|
const formData = ref<MemberConfigApi.Config>();
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
// 所有表单项
|
labelWidth: 120,
|
||||||
labelClass: 'w-2/6',
|
|
||||||
},
|
},
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
wrapperClass: 'grid-cols-1',
|
schema,
|
||||||
schema: [
|
handleSubmit,
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'id',
|
|
||||||
dependencies: {
|
|
||||||
triggerFields: [''],
|
|
||||||
show: () => false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Switch',
|
|
||||||
fieldName: 'pointTradeDeductEnable',
|
|
||||||
label: '积分抵扣',
|
|
||||||
help: '开启后,用户可以积分抵扣',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'InputNumber',
|
|
||||||
fieldName: 'pointTradeDeductUnitPrice',
|
|
||||||
label: '积分抵扣单价',
|
|
||||||
help: '用户每消费1元,可以抵扣多少积分',
|
|
||||||
componentProps: {
|
|
||||||
min: 0,
|
|
||||||
precision: 2,
|
|
||||||
class: 'w-full',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'InputNumber',
|
|
||||||
fieldName: 'pointTradeDeductMaxPrice',
|
|
||||||
label: '积分抵扣最大值',
|
|
||||||
help: '单次下单积分使用上限,0 不限制',
|
|
||||||
componentProps: {
|
|
||||||
min: 0,
|
|
||||||
class: 'w-full',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'InputNumber',
|
|
||||||
fieldName: 'pointTradeGivePoint',
|
|
||||||
label: '1 元赠送多少分',
|
|
||||||
help: '下单支付金额按比例赠送积分(实际支付 1 元赠送多少积分)',
|
|
||||||
componentProps: {
|
|
||||||
min: 0,
|
|
||||||
class: 'w-full',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
// 提交函数
|
|
||||||
handleSubmit: onSubmit,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function onSubmit() {
|
/** 提交表单 */
|
||||||
|
async function handleSubmit() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const data = (await formApi.getValues()) as MemberConfigApi.Config;
|
const data = (await formApi.getValues()) as MemberConfigApi.Config;
|
||||||
formApi.setState({ commonConfig: { disabled: true } });
|
// 转换金额单位
|
||||||
try {
|
data.pointTradeDeductUnitPrice = yuanToFen(data.pointTradeDeductUnitPrice);
|
||||||
await saveConfig(data);
|
await saveConfig(data);
|
||||||
// 关闭并提示
|
// 关闭并提示
|
||||||
emit('success');
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
|
||||||
} finally {
|
|
||||||
formApi.setState({ commonConfig: { disabled: false } });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获取配置 */
|
||||||
async function getConfigInfo() {
|
async function getConfigInfo() {
|
||||||
try {
|
const res = await getConfig();
|
||||||
const res = await getConfig();
|
formData.value = res;
|
||||||
formData.value = res;
|
// 转换金额单位
|
||||||
} catch (error) {
|
res.pointTradeDeductUnitPrice = Number.parseFloat(
|
||||||
console.error(error);
|
fenToYuan(res.pointTradeDeductUnitPrice),
|
||||||
}
|
);
|
||||||
|
// 设置到 values
|
||||||
|
await formApi.setValues(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getConfigInfo();
|
getConfigInfo();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user