From b8ce330c12700f9de73013308656964e80e2739b Mon Sep 17 00:00:00 2001 From: Siyu Kong Date: Tue, 28 Mar 2023 20:35:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=A8=A1=E5=9D=97=E9=A1=B5=E9=9D=A2&api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mall/product/category.ts | 60 +++++++++ src/views/mall/product/category/form.vue | 149 ++++++++++++++++++++++ src/views/mall/product/category/index.vue | 137 ++++++++++++++++++++ src/views/mall/product/category/utils.ts | 44 +++++++ 4 files changed, 390 insertions(+) create mode 100644 src/api/mall/product/category.ts create mode 100644 src/views/mall/product/category/form.vue create mode 100644 src/views/mall/product/category/index.vue create mode 100644 src/views/mall/product/category/utils.ts diff --git a/src/api/mall/product/category.ts b/src/api/mall/product/category.ts new file mode 100644 index 00000000..7ae81285 --- /dev/null +++ b/src/api/mall/product/category.ts @@ -0,0 +1,60 @@ +import request from '@/config/axios' + +/** + * 产品分类 + */ +export interface CategoryVO { + /** + * 分类编号 + */ + id?: number + /** + * 父分类编号 + */ + parentId?: number + /** + * 分类名称 + */ + name: string + /** + * 分类图片 + */ + picUrl: string + /** + * 分类排序 + */ + sort?: number + /** + * 分类描述 + */ + description?: string + /** + * 开启状态 + */ + status: number +} + +// 创建商品分类 +export const createCategory = (data: CategoryVO) => { + return request.post({ url: '/product/category/create', data }) +} + +// 更新商品分类 +export const updateCategory = (data: CategoryVO) => { + return request.put({ url: '/product/category/update', data }) +} + +// 删除商品分类 +export const deleteCategory = (id: number) => { + return request.delete({ url: `/product/category/delete?id=${id}` }) +} + +// 获得商品分类 +export const getCategory = (id: number) => { + return request.get({ url: `/product/category/get?id=${id}` }) +} + +// 获得商品分类列表 +export const getCategoryList = (params: any) => { + return request.get({ url: '/product/category/list', params }) +} diff --git a/src/views/mall/product/category/form.vue b/src/views/mall/product/category/form.vue new file mode 100644 index 00000000..e2b6f62a --- /dev/null +++ b/src/views/mall/product/category/form.vue @@ -0,0 +1,149 @@ + + diff --git a/src/views/mall/product/category/index.vue b/src/views/mall/product/category/index.vue new file mode 100644 index 00000000..12f51cff --- /dev/null +++ b/src/views/mall/product/category/index.vue @@ -0,0 +1,137 @@ + + diff --git a/src/views/mall/product/category/utils.ts b/src/views/mall/product/category/utils.ts new file mode 100644 index 00000000..a3774f22 --- /dev/null +++ b/src/views/mall/product/category/utils.ts @@ -0,0 +1,44 @@ +export const parseTime = (time) => { + if (!time) { + return null + } + const format = '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time + } else { + if (typeof time === 'string' && /^[0-9]+$/.test(time)) { + time = parseInt(time) + } else if (typeof time === 'string') { + time = time + .replace(new RegExp(/-/gm), '/') + .replace('T', ' ') + .replace(new RegExp(/\.[\d]{3}/gm), '') + } + if (typeof time === 'number' && time.toString().length === 10) { + time = time * 1000 + } + date = new Date(time) + } + const formatObj = { + y: date.getFullYear(), + m: date.getMonth() + 1, + d: date.getDate(), + h: date.getHours(), + i: date.getMinutes(), + s: date.getSeconds(), + a: date.getDay() + } + const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { + let value = formatObj[key] + // Note: getDay() returns 0 on Sunday + if (key === 'a') { + return ['日', '一', '二', '三', '四', '五', '六'][value] + } + if (result.length > 0 && value < 10) { + value = '0' + value + } + return value || 0 + }) + return time_str +}