ソースを参照

REVIEW 商品分类

YunaiV 2 年 前
コミット
00c3133391

+ 1 - 1
src/views/infra/codegen/index.vue

@@ -163,7 +163,7 @@ const queryParams = reactive({
 const queryFormRef = ref() // 搜索的表单
 const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
 
-/** 查询参数列表 */
+/** 查询列表 */
 const getList = async () => {
   loading.value = true
   try {

+ 1 - 1
src/views/infra/job/index.vue

@@ -168,7 +168,7 @@ const queryParams = reactive({
 const queryFormRef = ref() // 搜索的表单
 const exportLoading = ref(false) // 导出的加载中
 
-/** 查询参数列表 */
+/** 查询列表 */
 const getList = async () => {
   loading.value = true
   try {

+ 1 - 1
src/views/infra/job/logger/index.vue

@@ -141,7 +141,7 @@ const queryParams = reactive({
 const queryFormRef = ref() // 搜索的表单
 const exportLoading = ref(false) // 导出的加载中
 
-/** 查询参数列表 */
+/** 查询列表 */
 const getList = async () => {
   loading.value = true
   try {

+ 36 - 38
src/views/mall/product/category/form.vue → src/views/mall/product/category/CategoryForm.vue

@@ -10,11 +10,11 @@
       <el-form-item label="上级分类" prop="parentId">
         <el-tree-select
           v-model="formData.parentId"
-          :data="parentCategoryOptions"
-          check-strictly
-          :render-after-expand="false"
-          placeholder="上级分类"
+          :data="categoryTree"
           :props="{ label: 'name', value: 'id' }"
+          :render-after-expand="false"
+          placeholder="请选择上级分类"
+          check-strictly
           default-expand-all
         />
       </el-form-item>
@@ -32,10 +32,11 @@
       <el-form-item label="开启状态" prop="status">
         <el-radio-group v-model="formData.status">
           <el-radio
-            v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
+            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
             :key="dict.value"
-            :label="parseInt(dict.value)"
-            >{{ dict.label }}
+            :label="dict.value"
+          >
+            {{ dict.label }}
           </el-radio>
         </el-radio-group>
       </el-form-item>
@@ -44,18 +45,16 @@
       </el-form-item>
     </el-form>
     <template #footer>
-      <div class="dialog-footer">
-        <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
-        <el-button @click="modelVisible = false">取 消</el-button>
-      </div>
+      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
+      <el-button @click="modelVisible = false">取 消</el-button>
     </template>
   </Dialog>
 </template>
 <script setup lang="ts">
-import { DICT_TYPE, getDictOptions } from '@/utils/dict'
-import * as ProductCategoryApi from '@/api/mall/product/category'
+import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
+import { CommonStatusEnum } from '@/utils/constants'
 import { handleTree } from '@/utils/tree'
-
+import * as ProductCategoryApi from '@/api/mall/product/category'
 const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 
@@ -63,15 +62,13 @@ const modelVisible = ref(false) // 弹窗的是否展示
 const modelTitle = ref('') // 弹窗的标题
 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
 const formType = ref('') // 表单的类型:create - 新增;update - 修改
-
-const defaultFormData: ProductCategoryApi.CategoryVO = {
+const formData = ref({
   id: undefined,
   name: '',
   picUrl: '',
-  status: 0,
+  status: CommonStatusEnum.ENABLE,
   description: ''
-}
-const formData = ref({ ...defaultFormData })
+})
 const formRules = reactive({
   parentId: [{ required: true, message: '请选择上级分类', trigger: 'blur' }],
   name: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }],
@@ -80,17 +77,14 @@ const formRules = reactive({
   status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }]
 })
 const formRef = ref() // 表单 Ref
-
-const list = ref([])
-const parentCategoryOptions = ref<any[]>([])
+const categoryTree = ref<any[]>([]) // 分类树
 
 /** 打开弹窗 */
-const openModal = async (type: string, id?: number) => {
+const open = async (type: string, id?: number) => {
   modelVisible.value = true
   modelTitle.value = t('action.' + type)
   formType.value = type
   resetForm()
-  getList()
   // 修改时,设置数据
   if (id) {
     formLoading.value = true
@@ -100,20 +94,10 @@ const openModal = async (type: string, id?: number) => {
       formLoading.value = false
     }
   }
+  // 获得分类树
+  await getTree()
 }
-defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
-
-// 获取上级分类选项
-const getList = async () => {
-  try {
-    const data = await ProductCategoryApi.getCategoryList({})
-    list.value = data
-    const tree = handleTree(data, 'id', 'parentId')
-    const menu = { id: 0, name: '顶级分类', children: tree }
-    parentCategoryOptions.value = [menu]
-  } finally {
-  }
-}
+defineExpose({ open }) // 提供 open 方法,用于打开弹窗
 
 /** 提交表单 */
 const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
@@ -143,7 +127,21 @@ const submitForm = async () => {
 
 /** 重置表单 */
 const resetForm = () => {
-  formData.value = { ...defaultFormData }
+  formData.value = {
+    id: undefined,
+    name: '',
+    picUrl: '',
+    status: CommonStatusEnum.ENABLE,
+    description: ''
+  }
   formRef.value?.resetFields()
 }
+
+/** 获得分类树 */
+const getTree = async () => {
+  const data = await ProductCategoryApi.getCategoryList({})
+  const tree = handleTree(data, 'id', 'parentId')
+  const menu = { id: 0, name: '顶级分类', children: tree }
+  categoryTree.value = [menu]
+}
 </script>

+ 32 - 26
src/views/mall/product/category/index.vue

@@ -1,7 +1,13 @@
 <template>
-  <content-wrap>
-    <!-- 搜索工作栏 -->
-    <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
+  <!-- 搜索工作栏 -->
+  <ContentWrap>
+    <el-form
+      class="-mb-15px"
+      :model="queryParams"
+      ref="queryFormRef"
+      :inline="true"
+      label-width="68px"
+    >
       <el-form-item label="分类名称" prop="name">
         <el-input
           v-model="queryParams.name"
@@ -13,23 +19,25 @@
       <el-form-item>
         <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
         <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
-        <el-button type="primary" @click="openModal('create')" v-hasPermi="['infra:config:create']">
+        <el-button
+          type="primary"
+          plain
+          @click="openForm('create')"
+          v-hasPermi="['product:category:create']"
+        >
           <Icon icon="ep:plus" class="mr-5px" /> 新增
         </el-button>
       </el-form-item>
     </el-form>
+  </ContentWrap>
 
-    <!-- 列表 -->
-    <el-table v-loading="loading" :data="list" align="center" default-expand-all row-key="id">
+  <!-- 列表 -->
+  <ContentWrap>
+    <el-table v-loading="loading" :data="list" row-key="id" default-expand-all>
       <el-table-column label="分类名称" prop="name" sortable />
       <el-table-column label="分类图片" align="center" prop="picUrl">
         <template #default="scope">
-          <img
-            v-if="scope.row.picUrl"
-            :src="scope.row.picUrl"
-            alt="分类图片"
-            style="height: 100px"
-          />
+          <img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="分类图片" class="h-100px" />
         </template>
       </el-table-column>
       <el-table-column label="分类排序" align="center" prop="sort" />
@@ -50,8 +58,8 @@
           <el-button
             link
             type="primary"
-            @click="openModal('update', scope.row.id)"
-            v-hasPermi="['infra:config:update']"
+            @click="openForm('update', scope.row.id)"
+            v-hasPermi="['product:category:update']"
           >
             编辑
           </el-button>
@@ -59,25 +67,24 @@
             link
             type="danger"
             @click="handleDelete(scope.row.id)"
-            v-hasPermi="['infra:config:delete']"
+            v-hasPermi="['product:category:delete']"
           >
             删除
           </el-button>
         </template>
       </el-table-column>
     </el-table>
-  </content-wrap>
+  </ContentWrap>
 
   <!-- 表单弹窗:添加/修改 -->
-  <config-form ref="modalRef" @success="getList" />
+  <CategoryForm ref="formRef" @success="getList" />
 </template>
-<script setup lang="ts" name="Config">
+<script setup lang="ts" name="ProductCategory">
 import { DICT_TYPE } from '@/utils/dict'
+import { handleTree } from '@/utils/tree'
 import { dateFormatter } from '@/utils/formatTime'
 import * as ProductCategoryApi from '@/api/mall/product/category'
-import ConfigForm from './form.vue'
-import { handleTree } from '@/utils/tree'
-
+import CategoryForm from './CategoryForm.vue'
 const message = useMessage() // 消息弹窗
 const { t } = useI18n() // 国际化
 
@@ -88,13 +95,12 @@ const queryParams = reactive({
 })
 const queryFormRef = ref() // 搜索的表单
 
-/** 查询参数列表 */
+/** 查询列表 */
 const getList = async () => {
   loading.value = true
   try {
     const data = await ProductCategoryApi.getCategoryList(queryParams)
     list.value = handleTree(data, 'id', 'parentId')
-    console.info(list)
   } finally {
     loading.value = false
   }
@@ -112,9 +118,9 @@ const resetQuery = () => {
 }
 
 /** 添加/修改操作 */
-const modalRef = ref()
-const openModal = (type: string, id?: number) => {
-  modalRef.value.openModal(type, id)
+const formRef = ref()
+const openForm = (type: string, id?: number) => {
+  formRef.value.open(type, id)
 }
 
 /** 删除按钮操作 */

+ 0 - 44
src/views/mall/product/category/utils.ts

@@ -1,44 +0,0 @@
-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
-}

+ 1 - 1
src/views/system/dept/index.vue

@@ -55,8 +55,8 @@
       v-loading="loading"
       :data="list"
       row-key="id"
+      default-expand-all
       v-if="refreshTable"
-      :default-expand-all="isExpandAll"
     >
       <el-table-column prop="name" label="部门名称" width="260" />
       <el-table-column prop="leader" label="负责人" width="120">