新增:优惠券

This commit is contained in:
2025-08-09 15:31:09 +08:00
parent 46ab97d002
commit 30c867c6b6
27 changed files with 1953 additions and 469 deletions

View File

@@ -0,0 +1,106 @@
import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { ShopCoupon, ShopCouponParam } from './model';
import { MODULES_API_URL } from '@/config/setting';
/**
* 分页查询优惠券
*/
export async function pageShopCoupon(params: ShopCouponParam) {
const res = await request.get<ApiResult<PageResult<ShopCoupon>>>(
MODULES_API_URL + '/shop/shop-coupon/page',
{
params
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询优惠券列表
*/
export async function listShopCoupon(params?: ShopCouponParam) {
const res = await request.get<ApiResult<ShopCoupon[]>>(
MODULES_API_URL + '/shop/shop-coupon',
{
params
}
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 添加优惠券
*/
export async function addShopCoupon(data: ShopCoupon) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-coupon',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 修改优惠券
*/
export async function updateShopCoupon(data: ShopCoupon) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-coupon',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 删除优惠券
*/
export async function removeShopCoupon(id?: number) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-coupon/' + id
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 批量删除优惠券
*/
export async function removeBatchShopCoupon(data: (number | undefined)[]) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-coupon/batch',
{
data
}
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 根据id查询优惠券
*/
export async function getShopCoupon(id: number) {
const res = await request.get<ApiResult<ShopCoupon>>(
MODULES_API_URL + '/shop/shop-coupon/' + id
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}

View File

@@ -0,0 +1,65 @@
import type { PageParam } from '@/api/index';
/**
* 优惠券
*/
export interface ShopCoupon {
// id
id?: number;
// 优惠券名称
name?: string;
// 优惠券描述
description?: string;
// 优惠券类型(10满减券 20折扣券 30免费劵)
type?: number;
// 满减券-减免金额
reducePrice?: string;
// 折扣券-折扣率(0-100)
discount?: number;
// 最低消费金额
minPrice?: string;
// 到期类型(10领取后生效 20固定时间)
expireType?: number;
// 领取后生效-有效天数
expireDay?: number;
// 有效期开始时间
startTime?: string;
// 有效期结束时间
endTime?: string;
// 适用范围(10全部商品 20指定商品 30指定分类)
applyRange?: number;
// 适用范围配置(json格式)
applyRangeConfig?: string;
// 是否过期(0未过期 1已过期)
isExpire?: number;
// 排序(数字越小越靠前)
sortNumber?: number;
// 状态, 0正常, 1禁用
status?: number;
// 是否删除, 0否, 1是
deleted?: number;
// 创建用户ID
userId?: number;
// 租户id
tenantId?: number;
// 创建时间
createTime?: string;
// 修改时间
updateTime?: string;
// 发放总数量(-1表示无限制)
totalCount?: number;
// 已发放数量
issuedCount?: number;
// 每人限领数量(-1表示无限制)
limitPerUser?: number;
// 是否启用(0禁用 1启用)
enabled?: string;
}
/**
* 优惠券搜索条件
*/
export interface ShopCouponParam extends PageParam {
id?: number;
keywords?: string;
}

View File

@@ -1,5 +1,5 @@
import request from '@/utils/request'; import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api'; import type { ApiResult, PageResult } from '@/api/index';
import type { ShopGoodsCoupon, ShopGoodsCouponParam } from './model'; import type { ShopGoodsCoupon, ShopGoodsCouponParam } from './model';
import { MODULES_API_URL } from '@/config/setting'; import { MODULES_API_URL } from '@/config/setting';

View File

@@ -1,4 +1,4 @@
import type { PageParam } from '@/api'; import type { PageParam } from '@/api/index';
/** /**
* 商品优惠券表 * 商品优惠券表

View File

@@ -0,0 +1,106 @@
import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { ShopUserCoupon, ShopUserCouponParam } from './model';
import { MODULES_API_URL } from '@/config/setting';
/**
* 分页查询用户优惠券
*/
export async function pageShopUserCoupon(params: ShopUserCouponParam) {
const res = await request.get<ApiResult<PageResult<ShopUserCoupon>>>(
MODULES_API_URL + '/shop/shop-user-coupon/page',
{
params
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询用户优惠券列表
*/
export async function listShopUserCoupon(params?: ShopUserCouponParam) {
const res = await request.get<ApiResult<ShopUserCoupon[]>>(
MODULES_API_URL + '/shop/shop-user-coupon',
{
params
}
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 添加用户优惠券
*/
export async function addShopUserCoupon(data: ShopUserCoupon) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-user-coupon',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 修改用户优惠券
*/
export async function updateShopUserCoupon(data: ShopUserCoupon) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-user-coupon',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 删除用户优惠券
*/
export async function removeShopUserCoupon(id?: number) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-user-coupon/' + id
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 批量删除用户优惠券
*/
export async function removeBatchShopUserCoupon(data: (number | undefined)[]) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-user-coupon/batch',
{
data
}
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 根据id查询用户优惠券
*/
export async function getShopUserCoupon(id: number) {
const res = await request.get<ApiResult<ShopUserCoupon>>(
MODULES_API_URL + '/shop/shop-user-coupon/' + id
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}

View File

@@ -0,0 +1,61 @@
import type { PageParam } from '@/api/index';
/**
* 用户优惠券
*/
export interface ShopUserCoupon {
// id
id?: string;
// 优惠券模板ID
couponId?: number;
// 用户ID
userId?: number;
// 优惠券名称
name?: string;
// 优惠券描述
description?: string;
// 优惠券类型(10满减券 20折扣券 30免费劵)
type?: number;
// 满减券-减免金额
reducePrice?: string;
// 折扣券-折扣率(0-100)
discount?: number;
// 最低消费金额
minPrice?: string;
// 适用范围(10全部商品 20指定商品 30指定分类)
applyRange?: number;
// 适用范围配置(json格式)
applyRangeConfig?: string;
// 有效期开始时间
startTime?: string;
// 有效期结束时间
endTime?: string;
// 使用状态(0未使用 1已使用 2已过期)
status?: number;
// 使用时间
useTime?: string;
// 使用订单ID
orderId?: string;
// 使用订单号
orderNo?: string;
// 获取方式(10主动领取 20系统发放 30活动赠送)
obtainType?: number;
// 获取来源描述
obtainSource?: string;
// 是否删除, 0否, 1是
deleted?: string;
// 租户id
tenantId?: number;
// 创建时间
createTime?: string;
// 修改时间
updateTime?: string;
}
/**
* 用户优惠券搜索条件
*/
export interface ShopUserCouponParam extends PageParam {
id?: number;
keywords?: string;
}

View File

@@ -8,7 +8,7 @@ import {
} from '@/api/system/chat'; } from '@/api/system/chat';
import { emitter } from '@/utils/common'; import { emitter } from '@/utils/common';
const SOCKET_URL: string = 'wss://server.gxwebsoft.com'; const SOCKET_URL: string = 'wss://server.websoft.top';
interface ConnectionOptions { interface ConnectionOptions {
token: string; token: string;

View File

@@ -198,7 +198,6 @@ const columns = ref<ColumnItem[]>([
dataIndex: 'articleId', dataIndex: 'articleId',
key: 'articleId', key: 'articleId',
align: 'center', align: 'center',
hideInTable: true,
width: 90 width: 90
}, },
{ {

View File

@@ -5,7 +5,7 @@
:visible="visible" :visible="visible"
:maskClosable="false" :maskClosable="false"
:maxable="maxable" :maxable="maxable"
:title="isUpdate ? '编辑页面管理记录表' : '添加页面管理记录表'" :title="isUpdate ? '编辑页面' : '添加页面'"
:body-style="{ paddingBottom: '28px' }" :body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible" @update:visible="updateVisible"
@ok="save" @ok="save"
@@ -19,18 +19,25 @@
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' } styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
" "
> >
<a-form-item label="页面标题" name="name"> <a-form-item label="页面" name="name">
<a-input <a-input
allow-clear allow-clear
placeholder="请输入页面标题" placeholder="请输入页面标题"
v-model:value="form.name" v-model:value="form.name"
/> />
</a-form-item> </a-form-item>
<a-form-item label="所属栏目ID" name="categoryId"> <a-form-item label="所属栏目" name="categoryId">
<a-input <a-tree-select
allow-clear allow-clear
placeholder="请输入所属栏目ID" :tree-data="navigationList"
v-model:value="form.categoryId" tree-default-expand-all
style="width: 320px"
placeholder="请选择栏目"
:value="form.categoryId || undefined"
:listHeight="700"
:dropdown-style="{ overflow: 'auto' }"
@update:value="(value?: number) => (form.categoryId = value)"
@change="onCategoryId"
/> />
</a-form-item> </a-form-item>
<a-form-item label="页面关键词" name="keywords"> <a-form-item label="页面关键词" name="keywords">
@@ -75,13 +82,6 @@
v-model:value="form.content" v-model:value="form.content"
/> />
</a-form-item> </a-form-item>
<a-form-item label="是否开启布局" name="showLayout">
<a-input
allow-clear
placeholder="请输入是否开启布局"
v-model:value="form.showLayout"
/>
</a-form-item>
<a-form-item label="页面布局" name="layout"> <a-form-item label="页面布局" name="layout">
<a-input <a-input
allow-clear allow-clear
@@ -89,20 +89,6 @@
v-model:value="form.layout" v-model:value="form.layout"
/> />
</a-form-item> </a-form-item>
<a-form-item label="上级id, 0是顶级" name="parentId">
<a-input
allow-clear
placeholder="请输入上级id, 0是顶级"
v-model:value="form.parentId"
/>
</a-form-item>
<a-form-item label="用户ID" name="userId">
<a-input
allow-clear
placeholder="请输入用户ID"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="设为首页" name="home"> <a-form-item label="设为首页" name="home">
<a-input <a-input
allow-clear allow-clear
@@ -110,7 +96,7 @@
v-model:value="form.home" v-model:value="form.home"
/> />
</a-form-item> </a-form-item>
<a-form-item label="排序(数字越小越靠前)" name="sortNumber"> <a-form-item label="排序" name="sortNumber">
<a-input-number <a-input-number
:min="0" :min="0"
:max="9999" :max="9999"
@@ -127,19 +113,12 @@
v-model:value="form.comments" v-model:value="form.comments"
/> />
</a-form-item> </a-form-item>
<a-form-item label="状态, 0正常, 1冻结" name="status"> <a-form-item label="状态" name="status">
<a-radio-group v-model:value="form.status"> <a-radio-group v-model:value="form.status">
<a-radio :value="0">显示</a-radio> <a-radio :value="0">显示</a-radio>
<a-radio :value="1">隐藏</a-radio> <a-radio :value="1">隐藏</a-radio>
</a-radio-group> </a-radio-group>
</a-form-item> </a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
</a-form> </a-form>
</ele-modal> </ele-modal>
</template> </template>
@@ -155,6 +134,7 @@
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types'; import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form'; import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model'; import { FileRecord } from '@/api/system/file/model';
import {CmsNavigation} from "@/api/cms/cmsNavigation/model";
// 是否是修改 // 是否是修改
const isUpdate = ref(false); const isUpdate = ref(false);
@@ -168,6 +148,8 @@
visible: boolean; visible: boolean;
// 修改回显的数据 // 修改回显的数据
data?: CmsDesign | null; data?: CmsDesign | null;
// 栏目数据
navigationList?: CmsNavigation[];
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -7,34 +7,103 @@
</template> </template>
<span>添加</span> <span>添加</span>
</a-button> </a-button>
<a-tree-select
allow-clear
:tree-data="navigationList"
tree-default-expand-all
style="width: 240px"
:listHeight="700"
placeholder="请选择栏目"
:value="where.categoryId || undefined"
:dropdown-style="{ overflow: 'auto' }"
@update:value="(value?: number) => (where.categoryId = value)"
@change="onCategoryId"
/>
<a-input-search
allow-clear
placeholder="请输入关键词"
style="width: 240px"
v-model:value="where.keywords"
@search="reload"
/>
<a-button @click="resetFields">重置</a-button>
</a-space> </a-space>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue'; import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model'; import { ref, watch } from 'vue';
import { watch } from 'vue'; import { listCmsNavigation } from '@/api/cms/cmsNavigation';
import { CmsNavigation } from '@/api/cms/cmsNavigation/model';
import { toTreeData } from 'ele-admin-pro';
import useSearch from '@/utils/use-search';
import type { CmsDesignParam } from '@/api/cms/cmsDesign/model';
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
// 选中的角色 // 选中的数据
selection?: []; selection?: [];
}>(), }>(),
{} {}
); );
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'search', where?: GradeParam): void; (e: 'search', where?: CmsDesignParam): void;
(e: 'add'): void; (e: 'add'): void;
(e: 'remove'): void; (e: 'remove'): void;
(e: 'batchMove'): void; (e: 'batchMove'): void;
}>(); }>();
// 栏目数据
const navigationList = ref<CmsNavigation[]>([]);
// 表单数据
const { where, resetFields } = useSearch<CmsDesignParam>({
keywords: '',
categoryId: undefined,
});
// 新增 // 新增
const add = () => { const add = () => {
emit('add'); emit('add');
}; };
// 搜索
const reload = () => {
emit('search', where);
};
// 按分类查询
const onCategoryId = (id: number) => {
where.categoryId = id;
emit('search', where);
};
// 加载栏目数据
if (!navigationList.value.length) {
listCmsNavigation({}).then((res) => {
navigationList.value = toTreeData({
data: res?.map((d) => {
d.value = d.navigationId;
d.label = d.title;
if (!d.component) {
d.disabled = true;
}
if (
d.model == 'index' ||
d.model == 'page' ||
d.model == 'order'
) {
d.disabled = true;
}
return d;
}),
idField: 'navigationId',
parentIdField: 'parentId'
});
});
}
watch( watch(
() => props.selection, () => props.selection,
() => {} () => {}

View File

@@ -1,6 +1,8 @@
<template> <template>
<div class="page"> <a-page-header :title="getPageTitle()" @back="() => $router.go(-1)">
<div class="ele-body"> <template #extra>
<Extra/>
</template>
<a-card :bordered="false" :body-style="{ padding: '16px' }"> <a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table <ele-pro-table
ref="tableRef" ref="tableRef"
@@ -46,13 +48,12 @@
<!-- 编辑弹窗 --> <!-- 编辑弹窗 -->
<CmsDesignEdit v-model:visible="showEdit" :data="current" @done="reload" /> <CmsDesignEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div> </a-page-header>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { createVNode, ref } from 'vue'; import { createVNode, ref } from 'vue';
import { useI18n } from 'vue-i18n'; // import { useI18n } from 'vue-i18n';
import { message, Modal } from 'ant-design-vue'; import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'; import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro'; import type { EleProTable } from 'ele-admin-pro';
@@ -65,6 +66,8 @@
import CmsDesignEdit from './components/cmsDesignEdit.vue'; import CmsDesignEdit from './components/cmsDesignEdit.vue';
import { pageCmsDesign, removeCmsDesign, removeBatchCmsDesign } from '@/api/cms/cmsDesign'; import { pageCmsDesign, removeCmsDesign, removeBatchCmsDesign } from '@/api/cms/cmsDesign';
import type { CmsDesign, CmsDesignParam } from '@/api/cms/cmsDesign/model'; import type { CmsDesign, CmsDesignParam } from '@/api/cms/cmsDesign/model';
import {getPageTitle} from "@/utils/common";
import Extra from "@/views/bszx/extra.vue";
// 表格实例 // 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null); const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
@@ -74,7 +77,7 @@
// 当前编辑数据 // 当前编辑数据
const current = ref<CmsDesign | null>(null); const current = ref<CmsDesign | null>(null);
// 多语言 // 多语言
const { locale } = useI18n(); // const { locale } = useI18n();
// 是否显示编辑弹窗 // 是否显示编辑弹窗
const showEdit = ref(false); const showEdit = ref(false);
// 是否显示批量移动弹窗 // 是否显示批量移动弹窗
@@ -93,7 +96,7 @@
if (filters) { if (filters) {
where.status = filters.status; where.status = filters.status;
} }
where.lang = locale.value || undefined; // where.lang = locale.value || undefined;
return pageCmsDesign({ return pageCmsDesign({
...where, ...where,
...orders, ...orders,
@@ -112,106 +115,21 @@
width: 90, width: 90,
}, },
{ {
title: '页面标题', title: '页面',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name'
align: 'center',
}, },
{ {
title: '所属栏目ID', title: '排序',
dataIndex: 'categoryId',
key: 'categoryId',
align: 'center',
},
{
title: '页面关键词',
dataIndex: 'keywords',
key: 'keywords',
align: 'center',
},
{
title: '页面描述',
dataIndex: 'description',
key: 'description',
align: 'center',
},
{
title: '缩列图',
dataIndex: 'photo',
key: 'photo',
align: 'center',
},
{
title: '购买链接',
dataIndex: 'buyUrl',
key: 'buyUrl',
align: 'center',
},
{
title: '页面样式',
dataIndex: 'style',
key: 'style',
align: 'center',
},
{
title: '页面内容',
dataIndex: 'content',
key: 'content',
align: 'center',
},
{
title: '是否开启布局',
dataIndex: 'showLayout',
key: 'showLayout',
align: 'center',
},
{
title: '页面布局',
dataIndex: 'layout',
key: 'layout',
align: 'center',
},
{
title: '上级id, 0是顶级',
dataIndex: 'parentId',
key: 'parentId',
align: 'center',
},
{
title: '用户ID',
dataIndex: 'userId',
key: 'userId',
align: 'center',
},
{
title: '设为首页',
dataIndex: 'home',
key: 'home',
align: 'center',
},
{
title: '排序(数字越小越靠前)',
dataIndex: 'sortNumber', dataIndex: 'sortNumber',
key: 'sortNumber', key: 'sortNumber',
align: 'center', align: 'center'
}, },
{ {
title: '备注', title: '状态',
dataIndex: 'comments',
key: 'comments',
align: 'center',
},
{
title: '状态, 0正常, 1冻结',
dataIndex: 'status', dataIndex: 'status',
key: 'status', key: 'status',
align: 'center', align: 'center'
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
}, },
{ {
title: '创建时间', title: '创建时间',
@@ -220,6 +138,7 @@
align: 'center', align: 'center',
sorter: true, sorter: true,
ellipsis: true, ellipsis: true,
width: 180,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd') customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
}, },
{ {

View File

@@ -8,7 +8,7 @@
<!-- 表格 --> <!-- 表格 -->
<ele-pro-table <ele-pro-table
ref="tableRef" ref="tableRef"
row-key="websiteId" row-key="id"
:columns="columns" :columns="columns"
:datasource="datasource" :datasource="datasource"
:customRow="customRow" :customRow="customRow"
@@ -22,6 +22,7 @@
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="column.key === 'name'"> <template v-if="column.key === 'name'">
<div class="ele-text-heading" @mouseover="onCopyIcon(record.name)" @mouseleave="hideCopyIcon">{{ record.name }}<CopyOutlined class="px-2" v-if="currentName == record.name" @click="copyText(`config.${record.name}`)"/></div> <div class="ele-text-heading" @mouseover="onCopyIcon(record.name)" @mouseleave="hideCopyIcon">{{ record.name }}<CopyOutlined class="px-2" v-if="currentName == record.name" @click="copyText(`config.${record.name}`)"/></div>
<div class="text-gray-300">{{ record.comments }}</div>
</template> </template>
<template v-if="column.key === 'value'"> <template v-if="column.key === 'value'">
<a-image <a-image
@@ -121,20 +122,19 @@
// 表格列配置 // 表格列配置
const columns = ref<any[]>([ const columns = ref<any[]>([
// {
// title: 'ID',
// dataIndex: 'id',
// width: 120
// },
{ {
title: 'ID', title: '字段',
dataIndex: 'id',
width: 120
},
{
title: '字段名称',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
width: 240,
ellipsis: true ellipsis: true
}, },
{ {
title: '字段内容', title: '',
dataIndex: 'value', dataIndex: 'value',
key: 'value', key: 'value',
ellipsis: true ellipsis: true

View File

@@ -0,0 +1,42 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
watch(
() => props.selection,
() => {}
);
</script>

View File

@@ -0,0 +1,339 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑优惠券' : '添加优惠券'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="优惠券名称" name="name">
<a-input
allow-clear
placeholder="请输入优惠券名称"
v-model:value="form.name"
/>
</a-form-item>
<a-form-item label="优惠券描述" name="description">
<a-input
allow-clear
placeholder="请输入优惠券描述"
v-model:value="form.description"
/>
</a-form-item>
<a-form-item label="优惠券类型(10满减券 20折扣券 30免费劵)" name="type">
<a-input
allow-clear
placeholder="请输入优惠券类型(10满减券 20折扣券 30免费劵)"
v-model:value="form.type"
/>
</a-form-item>
<a-form-item label="满减券-减免金额" name="reducePrice">
<a-input
allow-clear
placeholder="请输入满减券-减免金额"
v-model:value="form.reducePrice"
/>
</a-form-item>
<a-form-item label="折扣券-折扣率(0-100)" name="discount">
<a-input
allow-clear
placeholder="请输入折扣券-折扣率(0-100)"
v-model:value="form.discount"
/>
</a-form-item>
<a-form-item label="最低消费金额" name="minPrice">
<a-input
allow-clear
placeholder="请输入最低消费金额"
v-model:value="form.minPrice"
/>
</a-form-item>
<a-form-item label="到期类型(10领取后生效 20固定时间)" name="expireType">
<a-input
allow-clear
placeholder="请输入到期类型(10领取后生效 20固定时间)"
v-model:value="form.expireType"
/>
</a-form-item>
<a-form-item label="领取后生效-有效天数" name="expireDay">
<a-input
allow-clear
placeholder="请输入领取后生效-有效天数"
v-model:value="form.expireDay"
/>
</a-form-item>
<a-form-item label="有效期开始时间" name="startTime">
<a-input
allow-clear
placeholder="请输入有效期开始时间"
v-model:value="form.startTime"
/>
</a-form-item>
<a-form-item label="有效期结束时间" name="endTime">
<a-input
allow-clear
placeholder="请输入有效期结束时间"
v-model:value="form.endTime"
/>
</a-form-item>
<a-form-item label="适用范围(10全部商品 20指定商品 30指定分类)" name="applyRange">
<a-input
allow-clear
placeholder="请输入适用范围(10全部商品 20指定商品 30指定分类)"
v-model:value="form.applyRange"
/>
</a-form-item>
<a-form-item label="适用范围配置(json格式)" name="applyRangeConfig">
<a-input
allow-clear
placeholder="请输入适用范围配置(json格式)"
v-model:value="form.applyRangeConfig"
/>
</a-form-item>
<a-form-item label="是否过期(0未过期 1已过期)" name="isExpire">
<a-input
allow-clear
placeholder="请输入是否过期(0未过期 1已过期)"
v-model:value="form.isExpire"
/>
</a-form-item>
<a-form-item label="排序(数字越小越靠前)" name="sortNumber">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
<a-form-item label="状态, 0正常, 1禁用" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="0">显示</a-radio>
<a-radio :value="1">隐藏</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
<a-form-item label="创建用户ID" name="userId">
<a-input
allow-clear
placeholder="请输入创建用户ID"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="修改时间" name="updateTime">
<a-input
allow-clear
placeholder="请输入修改时间"
v-model:value="form.updateTime"
/>
</a-form-item>
<a-form-item label="发放总数量(-1表示无限制)" name="totalCount">
<a-input
allow-clear
placeholder="请输入发放总数量(-1表示无限制)"
v-model:value="form.totalCount"
/>
</a-form-item>
<a-form-item label="已发放数量" name="issuedCount">
<a-input
allow-clear
placeholder="请输入已发放数量"
v-model:value="form.issuedCount"
/>
</a-form-item>
<a-form-item label="每人限领数量(-1表示无限制)" name="limitPerUser">
<a-input
allow-clear
placeholder="请输入每人限领数量(-1表示无限制)"
v-model:value="form.limitPerUser"
/>
</a-form-item>
<a-form-item label="是否启用(0禁用 1启用)" name="enabled">
<a-input
allow-clear
placeholder="请输入是否启用(0禁用 1启用)"
v-model:value="form.enabled"
/>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject, uuid } from 'ele-admin-pro';
import { addShopCoupon, updateShopCoupon } from '@/api/shop/shopCoupon';
import { ShopCoupon } from '@/api/shop/shopCoupon/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: ShopCoupon | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const images = ref<ItemType[]>([]);
// 用户信息
const form = reactive<ShopCoupon>({
id: undefined,
name: undefined,
description: undefined,
type: undefined,
reducePrice: undefined,
discount: undefined,
minPrice: undefined,
expireType: undefined,
expireDay: undefined,
startTime: undefined,
endTime: undefined,
applyRange: undefined,
applyRangeConfig: undefined,
isExpire: undefined,
sortNumber: undefined,
status: undefined,
deleted: undefined,
userId: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
totalCount: undefined,
issuedCount: undefined,
limitPerUser: undefined,
enabled: undefined,
shopCouponId: undefined,
shopCouponName: '',
status: 0,
comments: '',
sortNumber: 100
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
shopCouponName: [
{
required: true,
type: 'string',
message: '请填写优惠券名称',
trigger: 'blur'
}
]
});
const chooseImage = (data: FileRecord) => {
images.value.push({
uid: data.id,
url: data.path,
status: 'done'
});
form.image = data.path;
};
const onDeleteItem = (index: number) => {
images.value.splice(index, 1);
form.image = '';
};
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateShopCoupon : addShopCoupon;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
images.value = [];
if (props.data) {
assignObject(form, props.data);
if(props.data.image){
images.value.push({
uid: uuid(),
url: props.data.image,
status: 'done'
})
}
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>

View File

@@ -0,0 +1,347 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="shopCouponId"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<ShopCouponEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ShopCouponEdit from './components/shopCouponEdit.vue';
import { pageShopCoupon, removeShopCoupon, removeBatchShopCoupon } from '@/api/shop/shopCoupon';
import type { ShopCoupon, ShopCouponParam } from '@/api/shop/shopCoupon/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<ShopCoupon[]>([]);
// 当前编辑数据
const current = ref<ShopCoupon | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageShopCoupon({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'id',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 90,
},
{
title: '优惠券名称',
dataIndex: 'name',
key: 'name',
align: 'center',
},
{
title: '优惠券描述',
dataIndex: 'description',
key: 'description',
align: 'center',
},
{
title: '优惠券类型(10满减券 20折扣券 30免费劵)',
dataIndex: 'type',
key: 'type',
align: 'center',
},
{
title: '满减券-减免金额',
dataIndex: 'reducePrice',
key: 'reducePrice',
align: 'center',
},
{
title: '折扣券-折扣率(0-100)',
dataIndex: 'discount',
key: 'discount',
align: 'center',
},
{
title: '最低消费金额',
dataIndex: 'minPrice',
key: 'minPrice',
align: 'center',
},
{
title: '到期类型(10领取后生效 20固定时间)',
dataIndex: 'expireType',
key: 'expireType',
align: 'center',
},
{
title: '领取后生效-有效天数',
dataIndex: 'expireDay',
key: 'expireDay',
align: 'center',
},
{
title: '有效期开始时间',
dataIndex: 'startTime',
key: 'startTime',
align: 'center',
},
{
title: '有效期结束时间',
dataIndex: 'endTime',
key: 'endTime',
align: 'center',
},
{
title: '适用范围(10全部商品 20指定商品 30指定分类)',
dataIndex: 'applyRange',
key: 'applyRange',
align: 'center',
},
{
title: '适用范围配置(json格式)',
dataIndex: 'applyRangeConfig',
key: 'applyRangeConfig',
align: 'center',
},
{
title: '是否过期(0未过期 1已过期)',
dataIndex: 'isExpire',
key: 'isExpire',
align: 'center',
},
{
title: '排序(数字越小越靠前)',
dataIndex: 'sortNumber',
key: 'sortNumber',
align: 'center',
},
{
title: '状态, 0正常, 1禁用',
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
},
{
title: '创建用户ID',
dataIndex: 'userId',
key: 'userId',
align: 'center',
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '修改时间',
dataIndex: 'updateTime',
key: 'updateTime',
align: 'center',
},
{
title: '发放总数量(-1表示无限制)',
dataIndex: 'totalCount',
key: 'totalCount',
align: 'center',
},
{
title: '已发放数量',
dataIndex: 'issuedCount',
key: 'issuedCount',
align: 'center',
},
{
title: '每人限领数量(-1表示无限制)',
dataIndex: 'limitPerUser',
key: 'limitPerUser',
align: 'center',
},
{
title: '是否启用(0禁用 1启用)',
dataIndex: 'enabled',
key: 'enabled',
align: 'center',
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ShopCouponParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: ShopCoupon) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ShopCoupon) => {
const hide = message.loading('请求中..', 0);
removeShopCoupon(row.shopCouponId)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchShopCoupon(selection.value.map((d) => d.shopCouponId))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ShopCoupon) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'ShopCoupon'
};
</script>
<style lang="less" scoped></style>

View File

@@ -7,6 +7,18 @@
</template> </template>
<span>添加</span> <span>添加</span>
</a-button> </a-button>
<a-button
danger
type="primary"
class="ele-btn-icon"
:disabled="selection?.length === 0"
@click="removeBatch"
>
<template #icon>
<DeleteOutlined/>
</template>
<span>批量删除</span>
</a-button>
<a-radio-group v-model:value="type" @change="handleSearch"> <a-radio-group v-model:value="type" @change="handleSearch">
<a-radio-button value="出售中" <a-radio-button value="出售中"
>出售中({{ goodsCount?.totalNum }}) >出售中({{ goodsCount?.totalNum }})
@@ -90,6 +102,11 @@
emit('add'); emit('add');
}; };
// 批量删除
const removeBatch = () => {
emit('remove');
};
const handleSearch = (e) => { const handleSearch = (e) => {
const text = e.target.value; const text = e.target.value;
resetFields(); resetFields();

View File

@@ -24,6 +24,9 @@
> >
<a-tabs type="card" v-model:active-key="active" @change="onChange"> <a-tabs type="card" v-model:active-key="active" @change="onChange">
<a-tab-pane tab="基本信息" key="base"> <a-tab-pane tab="基本信息" key="base">
<a-form-item label="商品ID" name="goodsId">
{{ form.goodsId }}
</a-form-item>
<a-form-item label="商品名称" name="name"> <a-form-item label="商品名称" name="name">
<a-input <a-input
allow-clear allow-clear

View File

@@ -10,6 +10,7 @@
:columns="columns" :columns="columns"
:datasource="datasource" :datasource="datasource"
:customRow="customRow" :customRow="customRow"
v-model:selection="selection"
tool-class="ele-toolbar-form" tool-class="ele-toolbar-form"
class="sys-org-table" class="sys-org-table"
> >
@@ -46,11 +47,11 @@
</template> </template>
<template v-if="column.key === 'action'"> <template v-if="column.key === 'action'">
<a-space> <a-space>
<a @click="openEdit(record)">修改</a> <a @click.stop="openEdit(record)">修改</a>
<a-divider type="vertical"/> <a-divider type="vertical"/>
<a-popconfirm <a-popconfirm
title="确定要删除此记录吗?" title="确定要删除此记录吗?"
@confirm="remove(record)" @confirm.stop="remove(record)"
> >
<a class="ele-text-danger">删除</a> <a class="ele-text-danger">删除</a>
</a-popconfirm> </a-popconfirm>
@@ -137,7 +138,7 @@ const columns = ref<ColumnItem[]>([
title: '商品', title: '商品',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
width: 280 width: 300
}, },
// { // {
// title: '编号', // title: '编号',
@@ -149,7 +150,8 @@ const columns = ref<ColumnItem[]>([
title: '价格', title: '价格',
dataIndex: 'price', dataIndex: 'price',
key: 'price', key: 'price',
align: 'center' align: 'center',
customRender: ({text}) => `${text}`
}, },
{ {
title: '销量', title: '销量',
@@ -185,7 +187,8 @@ const columns = ref<ColumnItem[]>([
title: '排序号', title: '排序号',
dataIndex: 'sortNumber', dataIndex: 'sortNumber',
key: 'sortNumber', key: 'sortNumber',
align: 'center' align: 'center',
width: 120
}, },
{ {
title: '创建时间', title: '创建时间',
@@ -194,16 +197,17 @@ const columns = ref<ColumnItem[]>([
align: 'center', align: 'center',
sorter: true, sorter: true,
ellipsis: true, ellipsis: true,
customRender: ({text}) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '操作',
key: 'action',
width: 180, width: 180,
fixed: 'right', customRender: ({text}) => toDateString(text, 'yyyy-MM-dd')
align: 'center',
hideInSetting: true
} }
// {
// title: '操作',
// key: 'action',
// width: 180,
// fixed: 'right',
// align: 'center',
// hideInSetting: true
// }
]); ]);
/* 搜索 */ /* 搜索 */

View File

@@ -1,6 +1,18 @@
<!-- 搜索表单 --> <!-- 搜索表单 -->
<template> <template>
<a-space :size="10" style="flex-wrap: wrap"> <a-space :size="10" style="flex-wrap: wrap">
<a-button
danger
type="primary"
class="ele-btn-icon"
:disabled="selection?.length === 0"
@click="removeBatch"
>
<template #icon>
<DeleteOutlined/>
</template>
<span>批量删除</span>
</a-button>
<a-select <a-select
v-model:value="where.type" v-model:value="where.type"
style="width: 150px" style="width: 150px"
@@ -9,7 +21,8 @@
> >
<a-select-option value="">全部</a-select-option> <a-select-option value="">全部</a-select-option>
<a-select-option :value="1">普通订单</a-select-option> <a-select-option :value="1">普通订单</a-select-option>
<a-select-option :value="0">未付款</a-select-option> <a-select-option :value="2">秒杀订单</a-select-option>
<a-select-option :value="3">拼团订单</a-select-option>
</a-select> </a-select>
<a-select <a-select
v-model:value="where.payStatus" v-model:value="where.payStatus"
@@ -43,16 +56,7 @@
placeholder="付款方式" placeholder="付款方式"
@change="search" @change="search"
/> />
<a-select
v-model:value="where.isInvoice"
style="width: 150px"
placeholder="开票状态"
@change="search"
>
<a-select-option :value="1">已开票</a-select-option>
<a-select-option :value="0">未开票</a-select-option>
<a-select-option :value="2">不能开票</a-select-option>
</a-select>
<a-range-picker <a-range-picker
v-model:value="dateRange" v-model:value="dateRange"
@change="search" @change="search"
@@ -67,18 +71,6 @@
/> />
<a-button @click="reset">重置</a-button> <a-button @click="reset">重置</a-button>
<a-button @click="handleExport">导出</a-button> <a-button @click="handleExport">导出</a-button>
<a-button
danger
type="primary"
class="ele-btn-icon"
:disabled="selection?.length === 0"
@click="removeBatch"
>
<template #icon>
<DeleteOutlined/>
</template>
<span>批量删除</span>
</a-button>
</a-space> </a-space>
</template> </template>
@@ -86,7 +78,6 @@
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { utils, writeFile } from 'xlsx'; import { utils, writeFile } from 'xlsx';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import {DeleteOutlined} from '@ant-design/icons-vue';
import useSearch from "@/utils/use-search"; import useSearch from "@/utils/use-search";
import {ShopOrder, ShopOrderParam} from "@/api/shop/shopOrder/model"; import {ShopOrder, ShopOrderParam} from "@/api/shop/shopOrder/model";
import {listShopOrder} from "@/api/shop/shopOrder"; import {listShopOrder} from "@/api/shop/shopOrder";
@@ -119,7 +110,6 @@
payStatus: undefined, payStatus: undefined,
orderStatus: undefined, orderStatus: undefined,
payType: undefined, payType: undefined,
isInvoice: undefined,
}); });
const reload = () => { const reload = () => {

View File

@@ -104,11 +104,11 @@
</template> </template>
<template v-if="column.key === 'action'"> <template v-if="column.key === 'action'">
<a-space> <a-space>
<a @click="openEdit(record)">修改</a> <a @click.stop="openEdit(record)">修改</a>
<a-divider type="vertical"/> <a-divider type="vertical"/>
<a-popconfirm <a-popconfirm
title="确定要删除此记录吗?" title="确定要删除此记录吗?"
@confirm="remove(record)" @confirm.stop="remove(record)"
> >
<a class="ele-text-danger">删除</a> <a class="ele-text-danger">删除</a>
</a-popconfirm> </a-popconfirm>
@@ -247,15 +247,15 @@ const columns = ref<ColumnItem[]>([
sorter: true, sorter: true,
ellipsis: true, ellipsis: true,
customRender: ({text}) => toDateString(text) customRender: ({text}) => toDateString(text)
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
} }
// {
// title: '操作',
// key: 'action',
// width: 180,
// fixed: 'right',
// align: 'center',
// hideInSetting: true
// }
]); ]);
/* 搜索 */ /* 搜索 */

View File

@@ -0,0 +1,42 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
watch(
() => props.selection,
() => {}
);
</script>

View File

@@ -0,0 +1,321 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑用户优惠券' : '添加用户优惠券'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="优惠券模板ID" name="couponId">
<a-input
allow-clear
placeholder="请输入优惠券模板ID"
v-model:value="form.couponId"
/>
</a-form-item>
<a-form-item label="用户ID" name="userId">
<a-input
allow-clear
placeholder="请输入用户ID"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="优惠券名称" name="name">
<a-input
allow-clear
placeholder="请输入优惠券名称"
v-model:value="form.name"
/>
</a-form-item>
<a-form-item label="优惠券描述" name="description">
<a-input
allow-clear
placeholder="请输入优惠券描述"
v-model:value="form.description"
/>
</a-form-item>
<a-form-item label="优惠券类型(10满减券 20折扣券 30免费劵)" name="type">
<a-input
allow-clear
placeholder="请输入优惠券类型(10满减券 20折扣券 30免费劵)"
v-model:value="form.type"
/>
</a-form-item>
<a-form-item label="满减券-减免金额" name="reducePrice">
<a-input
allow-clear
placeholder="请输入满减券-减免金额"
v-model:value="form.reducePrice"
/>
</a-form-item>
<a-form-item label="折扣券-折扣率(0-100)" name="discount">
<a-input
allow-clear
placeholder="请输入折扣券-折扣率(0-100)"
v-model:value="form.discount"
/>
</a-form-item>
<a-form-item label="最低消费金额" name="minPrice">
<a-input
allow-clear
placeholder="请输入最低消费金额"
v-model:value="form.minPrice"
/>
</a-form-item>
<a-form-item label="适用范围(10全部商品 20指定商品 30指定分类)" name="applyRange">
<a-input
allow-clear
placeholder="请输入适用范围(10全部商品 20指定商品 30指定分类)"
v-model:value="form.applyRange"
/>
</a-form-item>
<a-form-item label="适用范围配置(json格式)" name="applyRangeConfig">
<a-input
allow-clear
placeholder="请输入适用范围配置(json格式)"
v-model:value="form.applyRangeConfig"
/>
</a-form-item>
<a-form-item label="有效期开始时间" name="startTime">
<a-input
allow-clear
placeholder="请输入有效期开始时间"
v-model:value="form.startTime"
/>
</a-form-item>
<a-form-item label="有效期结束时间" name="endTime">
<a-input
allow-clear
placeholder="请输入有效期结束时间"
v-model:value="form.endTime"
/>
</a-form-item>
<a-form-item label="使用状态(0未使用 1已使用 2已过期)" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="0">显示</a-radio>
<a-radio :value="1">隐藏</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="使用时间" name="useTime">
<a-input
allow-clear
placeholder="请输入使用时间"
v-model:value="form.useTime"
/>
</a-form-item>
<a-form-item label="使用订单ID" name="orderId">
<a-input
allow-clear
placeholder="请输入使用订单ID"
v-model:value="form.orderId"
/>
</a-form-item>
<a-form-item label="使用订单号" name="orderNo">
<a-input
allow-clear
placeholder="请输入使用订单号"
v-model:value="form.orderNo"
/>
</a-form-item>
<a-form-item label="获取方式(10主动领取 20系统发放 30活动赠送)" name="obtainType">
<a-input
allow-clear
placeholder="请输入获取方式(10主动领取 20系统发放 30活动赠送)"
v-model:value="form.obtainType"
/>
</a-form-item>
<a-form-item label="获取来源描述" name="obtainSource">
<a-input
allow-clear
placeholder="请输入获取来源描述"
v-model:value="form.obtainSource"
/>
</a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
<a-form-item label="修改时间" name="updateTime">
<a-input
allow-clear
placeholder="请输入修改时间"
v-model:value="form.updateTime"
/>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject, uuid } from 'ele-admin-pro';
import { addShopUserCoupon, updateShopUserCoupon } from '@/api/shop/shopUserCoupon';
import { ShopUserCoupon } from '@/api/shop/shopUserCoupon/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: ShopUserCoupon | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const images = ref<ItemType[]>([]);
// 用户信息
const form = reactive<ShopUserCoupon>({
id: undefined,
couponId: undefined,
userId: undefined,
name: undefined,
description: undefined,
type: undefined,
reducePrice: undefined,
discount: undefined,
minPrice: undefined,
applyRange: undefined,
applyRangeConfig: undefined,
startTime: undefined,
endTime: undefined,
status: undefined,
useTime: undefined,
orderId: undefined,
orderNo: undefined,
obtainType: undefined,
obtainSource: undefined,
deleted: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
shopUserCouponId: undefined,
shopUserCouponName: '',
status: 0,
comments: '',
sortNumber: 100
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
shopUserCouponName: [
{
required: true,
type: 'string',
message: '请填写用户优惠券名称',
trigger: 'blur'
}
]
});
const chooseImage = (data: FileRecord) => {
images.value.push({
uid: data.id,
url: data.path,
status: 'done'
});
form.image = data.path;
};
const onDeleteItem = (index: number) => {
images.value.splice(index, 1);
form.image = '';
};
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateShopUserCoupon : addShopUserCoupon;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
images.value = [];
if (props.data) {
assignObject(form, props.data);
if(props.data.image){
images.value.push({
uid: uuid(),
url: props.data.image,
status: 'done'
})
}
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>

View File

@@ -0,0 +1,335 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="shopUserCouponId"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<ShopUserCouponEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ShopUserCouponEdit from './components/shopUserCouponEdit.vue';
import { pageShopUserCoupon, removeShopUserCoupon, removeBatchShopUserCoupon } from '@/api/shop/shopUserCoupon';
import type { ShopUserCoupon, ShopUserCouponParam } from '@/api/shop/shopUserCoupon/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<ShopUserCoupon[]>([]);
// 当前编辑数据
const current = ref<ShopUserCoupon | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageShopUserCoupon({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'id',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 90,
},
{
title: '优惠券模板ID',
dataIndex: 'couponId',
key: 'couponId',
align: 'center',
},
{
title: '用户ID',
dataIndex: 'userId',
key: 'userId',
align: 'center',
},
{
title: '优惠券名称',
dataIndex: 'name',
key: 'name',
align: 'center',
},
{
title: '优惠券描述',
dataIndex: 'description',
key: 'description',
align: 'center',
},
{
title: '优惠券类型(10满减券 20折扣券 30免费劵)',
dataIndex: 'type',
key: 'type',
align: 'center',
},
{
title: '满减券-减免金额',
dataIndex: 'reducePrice',
key: 'reducePrice',
align: 'center',
},
{
title: '折扣券-折扣率(0-100)',
dataIndex: 'discount',
key: 'discount',
align: 'center',
},
{
title: '最低消费金额',
dataIndex: 'minPrice',
key: 'minPrice',
align: 'center',
},
{
title: '适用范围(10全部商品 20指定商品 30指定分类)',
dataIndex: 'applyRange',
key: 'applyRange',
align: 'center',
},
{
title: '适用范围配置(json格式)',
dataIndex: 'applyRangeConfig',
key: 'applyRangeConfig',
align: 'center',
},
{
title: '有效期开始时间',
dataIndex: 'startTime',
key: 'startTime',
align: 'center',
},
{
title: '有效期结束时间',
dataIndex: 'endTime',
key: 'endTime',
align: 'center',
},
{
title: '使用状态(0未使用 1已使用 2已过期)',
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '使用时间',
dataIndex: 'useTime',
key: 'useTime',
align: 'center',
},
{
title: '使用订单ID',
dataIndex: 'orderId',
key: 'orderId',
align: 'center',
},
{
title: '使用订单号',
dataIndex: 'orderNo',
key: 'orderNo',
align: 'center',
},
{
title: '获取方式(10主动领取 20系统发放 30活动赠送)',
dataIndex: 'obtainType',
key: 'obtainType',
align: 'center',
},
{
title: '获取来源描述',
dataIndex: 'obtainSource',
key: 'obtainSource',
align: 'center',
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '修改时间',
dataIndex: 'updateTime',
key: 'updateTime',
align: 'center',
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ShopUserCouponParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: ShopUserCoupon) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ShopUserCoupon) => {
const hide = message.loading('请求中..', 0);
removeShopUserCoupon(row.shopUserCouponId)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchShopUserCoupon(selection.value.map((d) => d.shopUserCouponId))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ShopUserCoupon) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'ShopUserCoupon'
};
</script>
<style lang="less" scoped></style>

View File

@@ -27,9 +27,9 @@
</div> </div>
<a-form-item label="request合法域名" name="request"> <a-form-item label="request合法域名" name="request">
<a-input-group compact> <a-input-group compact>
<a-input :value="`https://server.gxwebsoft.com;https://cms-api.websoft.top;`" placeholder="请输入小程序AppSecret" style="width: calc(100% - 50px)" /> <a-input :value="`https://server.websoft.top;https://cms-api.websoft.top;`" placeholder="请输入小程序AppSecret" style="width: calc(100% - 50px)" />
<a-tooltip title="复制"> <a-tooltip title="复制">
<a-button @click="onCopyText(`https://server.gxwebsoft.com;https://cms-api.websoft.top;`)"> <a-button @click="onCopyText(`https://server.websoft.top;https://cms-api.websoft.top;`)">
<template #icon><CopyOutlined /></template> <template #icon><CopyOutlined /></template>
</a-button> </a-button>
</a-tooltip> </a-tooltip>
@@ -37,9 +37,9 @@
</a-form-item> </a-form-item>
<a-form-item label="socket合法域名" name="socket"> <a-form-item label="socket合法域名" name="socket">
<a-input-group compact> <a-input-group compact>
<a-input :value="`wss://server.gxwebsoft.com`" placeholder="请输入小程序AppSecret" style="width: calc(100% - 50px)" /> <a-input :value="`wss://server.websoft.top`" placeholder="请输入小程序AppSecret" style="width: calc(100% - 50px)" />
<a-tooltip title="复制"> <a-tooltip title="复制">
<a-button @click="onCopyText(`wss://server.gxwebsoft.com`)"> <a-button @click="onCopyText(`wss://server.websoft.top`)">
<template #icon><CopyOutlined /></template> <template #icon><CopyOutlined /></template>
</a-button> </a-button>
</a-tooltip> </a-tooltip>

View File

@@ -44,12 +44,12 @@
<a-form-item label="网页授权域名" name="authorize"> <a-form-item label="网页授权域名" name="authorize">
<a-input-group compact> <a-input-group compact>
<a-input <a-input
:value="`https://server.gxwebsoft.com`" :value="`https://server.websoft.top`"
placeholder="请输入网页授权域名" placeholder="请输入网页授权域名"
style="width: calc(100% - 50px)" style="width: calc(100% - 50px)"
/> />
<a-tooltip title="复制"> <a-tooltip title="复制">
<a-button @click="onCopyText(`https://server.gxwebsoft.com`)"> <a-button @click="onCopyText(`https://server.websoft.top`)">
<template #icon><CopyOutlined /></template> <template #icon><CopyOutlined /></template>
</a-button> </a-button>
</a-tooltip> </a-tooltip>

View File

@@ -1,263 +0,0 @@
<template>
<div class="store-test-page">
<a-card title="状态管理测试页面" :bordered="false">
<a-space direction="vertical" style="width: 100%">
<!-- 网站信息测试 -->
<a-card title="网站信息 Store 测试" size="small">
<a-spin :spinning="siteLoading">
<a-descriptions :column="2" size="small">
<a-descriptions-item label="网站名称">
{{ websiteName || '暂无数据' }}
</a-descriptions-item>
<a-descriptions-item label="网站Logo">
<img v-if="websiteLogo" :src="websiteLogo" alt="logo" style="width: 50px; height: 50px;" />
<span v-else>暂无Logo</span>
</a-descriptions-item>
<a-descriptions-item label="网站描述">
{{ websiteComments || '暂无描述' }}
</a-descriptions-item>
<a-descriptions-item label="运行天数">
{{ runDays }}
</a-descriptions-item>
<a-descriptions-item label="网站域名">
{{ websiteDomain || '暂无域名' }}
</a-descriptions-item>
<a-descriptions-item label="网站ID">
{{ websiteId || '暂无ID' }}
</a-descriptions-item>
</a-descriptions>
<a-space style="margin-top: 16px">
<a-button @click="refreshSiteInfo" :loading="siteLoading">
刷新网站信息
</a-button>
<a-button @click="clearSiteCache">
清除网站缓存
</a-button>
</a-space>
</a-spin>
</a-card>
<!-- 统计数据测试 -->
<a-card title="统计数据 Store 测试" size="small">
<a-spin :spinning="statisticsLoading">
<a-row :gutter="16">
<a-col :span="6">
<a-statistic
title="用户总数"
:value="userCount"
:value-style="{ color: '#3f8600' }"
/>
</a-col>
<a-col :span="6">
<a-statistic
title="订单总数"
:value="orderCount"
:value-style="{ color: '#1890ff' }"
/>
</a-col>
<a-col :span="6">
<a-statistic
title="总销售额"
:value="totalSales"
:value-style="{ color: '#cf1322' }"
/>
</a-col>
<a-col :span="6">
<a-statistic
title="今日销售额"
:value="todaySales"
:value-style="{ color: '#722ed1' }"
/>
</a-col>
</a-row>
<a-space style="margin-top: 16px">
<a-button @click="refreshStatistics" :loading="statisticsLoading">
刷新统计数据
</a-button>
<a-button @click="clearStatisticsCache">
清除统计缓存
</a-button>
<a-button
@click="toggleAutoRefresh"
:type="autoRefreshEnabled ? 'primary' : 'default'"
>
{{ autoRefreshEnabled ? '停止自动刷新' : '开始自动刷新' }}
</a-button>
</a-space>
</a-spin>
</a-card>
<!-- 缓存状态信息 -->
<a-card title="缓存状态信息" size="small">
<a-descriptions :column="2" size="small">
<a-descriptions-item label="网站信息缓存有效">
<a-tag :color="siteStore.isCacheValid ? 'green' : 'red'">
{{ siteStore.isCacheValid ? '有效' : '无效' }}
</a-tag>
</a-descriptions-item>
<a-descriptions-item label="统计数据缓存有效">
<a-tag :color="statisticsStore.isCacheValid ? 'green' : 'red'">
{{ statisticsStore.isCacheValid ? '有效' : '无效' }}
</a-tag>
</a-descriptions-item>
<a-descriptions-item label="网站信息最后更新">
{{ siteStore.lastUpdateTime ? new Date(siteStore.lastUpdateTime).toLocaleString() : '从未更新' }}
</a-descriptions-item>
<a-descriptions-item label="统计数据最后更新">
{{ statisticsStore.lastUpdateTime ? new Date(statisticsStore.lastUpdateTime).toLocaleString() : '从未更新' }}
</a-descriptions-item>
</a-descriptions>
</a-card>
<!-- 操作日志 -->
<a-card title="操作日志" size="small">
<a-list
:data-source="logs"
size="small"
:pagination="{ pageSize: 5 }"
>
<template #renderItem="{ item }">
<a-list-item>
<a-list-item-meta>
<template #title>
<span>{{ item.action }}</span>
<a-tag size="small" style="margin-left: 8px">
{{ item.timestamp }}
</a-tag>
</template>
<template #description>
{{ item.result }}
</template>
</a-list-item-meta>
</a-list-item>
</template>
</a-list>
</a-card>
</a-space>
</a-card>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue';
import { useSiteData } from '@/composables/useSiteData';
import { useSiteStore } from '@/store/modules/site';
import { useStatisticsStore } from '@/store/modules/statistics';
// 使用组合式函数
const {
websiteName,
websiteLogo,
websiteComments,
websiteDomain,
websiteId,
runDays,
userCount,
orderCount,
totalSales,
todaySales,
siteLoading,
statisticsLoading,
fetchSiteInfo,
fetchStatistics,
clearCache
} = useSiteData();
// 直接使用 store用于访问更多详细信息
const siteStore = useSiteStore();
const statisticsStore = useStatisticsStore();
// 本地状态
const autoRefreshEnabled = ref(false);
const logs = ref<Array<{ action: string; timestamp: string; result: string }>>([]);
// 添加日志
const addLog = (action: string, result: string) => {
logs.value.unshift({
action,
timestamp: new Date().toLocaleTimeString(),
result
});
// 只保留最近20条日志
if (logs.value.length > 20) {
logs.value = logs.value.slice(0, 20);
}
};
// 刷新网站信息
const refreshSiteInfo = async () => {
try {
await fetchSiteInfo(true);
addLog('刷新网站信息', '成功');
} catch (error) {
addLog('刷新网站信息', `失败: ${error}`);
}
};
// 刷新统计数据
const refreshStatistics = async () => {
try {
await fetchStatistics(true);
addLog('刷新统计数据', '成功');
} catch (error) {
addLog('刷新统计数据', `失败: ${error}`);
}
};
// 清除网站缓存
const clearSiteCache = () => {
siteStore.clearCache();
addLog('清除网站缓存', '成功');
};
// 清除统计缓存
const clearStatisticsCache = () => {
statisticsStore.clearCache();
addLog('清除统计缓存', '成功');
};
// 切换自动刷新
const toggleAutoRefresh = () => {
if (autoRefreshEnabled.value) {
statisticsStore.stopAutoRefresh();
autoRefreshEnabled.value = false;
addLog('停止自动刷新', '成功');
} else {
statisticsStore.startAutoRefresh(10000); // 10秒间隔用于测试
autoRefreshEnabled.value = true;
addLog('开始自动刷新', '10秒间隔');
}
};
onMounted(async () => {
addLog('页面加载', '开始初始化');
try {
await Promise.all([
fetchSiteInfo(),
fetchStatistics()
]);
addLog('初始化数据', '成功');
} catch (error) {
addLog('初始化数据', `失败: ${error}`);
}
});
onUnmounted(() => {
// 清理自动刷新
if (autoRefreshEnabled.value) {
statisticsStore.stopAutoRefresh();
}
addLog('页面卸载', '清理完成');
});
</script>
<style scoped>
.store-test-page {
padding: 20px;
}
</style>

View File

@@ -22,7 +22,7 @@ export default defineConfig(({ command }) => {
}, },
// server: { // server: {
// proxy: { // proxy: {
// '/api': 'https://server.gxwebsoft.com' // '/api': 'https://server.websoft.top'
// } // }
// }, // },
plugins: [ plugins: [