feat: add member config
parent
da45d15f0d
commit
089d3bbd9b
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
|
export namespace MemberConfigApi {
|
||||||
|
/** 积分设置信息 */
|
||||||
|
export interface Config {
|
||||||
|
id?: number;
|
||||||
|
pointTradeDeductEnable: number;
|
||||||
|
pointTradeDeductUnitPrice: number;
|
||||||
|
pointTradeDeductMaxPrice: number;
|
||||||
|
pointTradeGivePoint: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查询积分设置详情 */
|
||||||
|
export function getConfig() {
|
||||||
|
return requestClient.get<MemberConfigApi.Config>('/member/config/get');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增修改积分设置 */
|
||||||
|
export function saveConfig(data: MemberConfigApi.Config) {
|
||||||
|
return requestClient.put('/member/config/save', data);
|
||||||
|
}
|
||||||
|
|
@ -1,34 +1,114 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { MemberConfigApi } from '#/api/member/config';
|
||||||
|
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
import { Button } from 'ant-design-vue';
|
import { Card, message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { DocAlert } from '#/components/doc-alert';
|
import { useVbenForm } from '#/adapter/form';
|
||||||
|
import { getConfig, saveConfig } from '#/api/member/config';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const emit = defineEmits(['success']);
|
||||||
|
const formData = ref<MemberConfigApi.Config>();
|
||||||
|
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
|
commonConfig: {
|
||||||
|
// 所有表单项
|
||||||
|
labelClass: 'w-2/6',
|
||||||
|
},
|
||||||
|
layout: 'horizontal',
|
||||||
|
wrapperClass: 'grid-cols-1',
|
||||||
|
actionWrapperClass: 'text-center',
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
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() {
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 提交表单
|
||||||
|
const data = (await formApi.getValues()) as MemberConfigApi.Config;
|
||||||
|
formApi.setState({ commonConfig: { disabled: true } });
|
||||||
|
try {
|
||||||
|
await saveConfig(data);
|
||||||
|
// 关闭并提示
|
||||||
|
emit('success');
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} finally {
|
||||||
|
formApi.setState({ commonConfig: { disabled: false } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getConfigInfo() {
|
||||||
|
try {
|
||||||
|
const res = await getConfig();
|
||||||
|
formData.value = res;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getConfigInfo();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page>
|
<Page auto-content-height>
|
||||||
<DocAlert
|
<Card title="积分设置">
|
||||||
title="会员手册(功能开启)"
|
<Form class="w-1/4" />
|
||||||
url="https://doc.iocoder.cn/member/build/"
|
</Card>
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
danger
|
|
||||||
type="link"
|
|
||||||
target="_blank"
|
|
||||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
|
||||||
>
|
|
||||||
该功能支持 Vue3 + element-plus 版本!
|
|
||||||
</Button>
|
|
||||||
<br />
|
|
||||||
<Button
|
|
||||||
type="link"
|
|
||||||
target="_blank"
|
|
||||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/member/config/index"
|
|
||||||
>
|
|
||||||
可参考
|
|
||||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/member/config/index
|
|
||||||
代码,pull request 贡献给我们!
|
|
||||||
</Button>
|
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue