gemer zhang 6 ماه پیش
والد
کامیت
74f0912369

+ 1 - 0
packages/backend/src/modules/category/category.service.ts

@@ -15,6 +15,7 @@ export class CategoryService {
 
   async create(createCategoryDto: CreateCategoryDto) {
     const category = this.categoryRepo.create(createCategoryDto);
+    // console.log('category', category);
     return this.categoryRepo.save(category);
   }
 

+ 6 - 4
packages/backend/src/modules/category/dto.ts

@@ -38,6 +38,11 @@ export class CreateCategoryDto {
   @IsString()
   @IsOptional()
   remark?: string;
+
+  @ApiProperty({ required: false })
+  @IsArray()
+  @IsOptional()
+  translations?: CreateCategoryTranslations[];
 }
 
 export class GetCategoryDto {
@@ -57,10 +62,7 @@ export class GetCategoryDto {
   @Allow()
   enable?: boolean;
 
-  @ApiProperty({ required: false })
-  @IsArray()
-  @IsOptional()
-  translations?: CreateCategoryTranslations[];
+
 }
 export class CreateCategoryTranslations {
   @ApiProperty({ required: false })

+ 9 - 1
packages/frontend/src/views/category/index.vue

@@ -157,7 +157,7 @@ const columns = [
             type: 'primary',
             style: 'margin-left: 12px;',
             disabled: row.code === 'SUPER_ADMIN',
-            onClick: () => handleEdit(row),
+            onClick: () => handleFormEdit(row),
           },
           {
             default: () => '编辑',
@@ -198,6 +198,14 @@ async function handleEnable(row) {
   }
 }
 
+async function handleFormEdit(data = {}) {
+  if (data.translations.length === 0) {
+    initTranslations(data, ['title', 'description'])
+  }
+
+  handleEdit(data)
+}
+
 const allCategory = ref([])
 api.getAll().then(({ data = [] }) => (allCategory.value = data.map(item => ({ label: item.title, value: item.id }))))
 </script>

+ 26 - 3
packages/frontend/src/views/menu/index.vue

@@ -18,9 +18,9 @@
                   <n-card :bordered="false" size="small">
                     <template #cover>
                       <!-- <div style="width: 100%;height: 50px;overflow: hidden;"> -->
-                      <n-image
+                      <n-image
                         preview-disabled :src="child.cover" object-fit="scale-down"
-                        style="width: 100%;height: 50px;overflow: hidden;"
+                        style="width: 100%;height: 50px;overflow: hidden;"
                       />
                       <!-- </div> -->
                     </template>
@@ -84,7 +84,27 @@
             v-model:value="modalForm.styleType" :options="styleEnum" clearable filterable tag
           />
         </n-form-item>
+        <n-tabs type="line" v-if="modalForm.translations.length > 0" animated>
+          <template v-for="(lang, index) in langs" :key="lang">
+            <n-tab-pane :name="lang" :tab="langLabel[lang]" :index="index">
+              <n-form-item label="名称" path="title" :rule="{
+                required: true,
+                message: '请输入名称',
+                trigger: ['input', 'blur'],
+              }">
+                <n-input v-model:value="modalForm.translations[index].title" />
+              </n-form-item>
 
+              <n-form-item label="描述" path="description" :rule="{
+                required: false,
+                message: '请输入描述',
+                trigger: ['input', 'blur'],
+              }">
+                <n-input v-model:value="modalForm.translations[index].description" type="textarea" />
+              </n-form-item>
+            </n-tab-pane>
+          </template>
+        </n-tabs>
         <n-form-item label="备注" path="remark">
           <n-input v-model:value="modalForm.remark" />
         </n-form-item>
@@ -117,6 +137,7 @@
 import { MeModal } from '@/components'
 import { useCrud } from '@/composables'
 import { useUserStore } from '@/store/index.js'
+import { initTranslations, langLabel, langs } from '@/utils/translations'
 import { styleEnum } from '@/utils/enum.js'
 import { onMounted } from 'vue'
 import { useRouter } from 'vue-router'
@@ -137,7 +158,9 @@ const { modalRef, modalFormRef, modalAction, modalForm, handleAdd, handleDelete,
     doCreate: MenuApi.create,
     doDelete: MenuApi.delete,
     doUpdate: MenuApi.update,
-    initForm: { enable: true, isPublish: true },
+    initForm: { enable: true, isPublish: true,  
+    translations: initTranslations({}, ['title', 'remark']).translations
+   },
     refresh: (_, keepCurrentPage) => $table.value?.handleSearch(keepCurrentPage),
   })
 onMounted(() => {

+ 7 - 5
packages/frontend/src/views/menu/list.vue

@@ -90,7 +90,7 @@
         }">
           <n-input-number v-model:value="modalForm.order" />
         </n-form-item>
-
+        <!-- {{ modalForm.translations }} -->
         <n-tabs type="line" v-if="modalForm.translations.length > 0" animated>
           <template v-for="(lang, index) in langs" :key="lang">
             <n-tab-pane :name="lang" :tab="langLabel[lang]" :index="index">
@@ -186,10 +186,7 @@ const { modalRef, modalFormRef, modalAction, modalForm, handleAdd, handleDelete,
       enable: true,
       isPublish: true,
       order: 0,
-      translations: [
-        { locale: 'zh', title: '', description: '' },
-        { locale: 'en', title: '', description: '' },
-      ],
+      translations: initTranslations({}, ['title', 'description']).translations,
     },
     refresh: (_, keepCurrentPage) => $table.value?.handleSearch(keepCurrentPage),
   })
@@ -386,6 +383,11 @@ function handleTopMenuEdit() {
     level: 0,
     parentId: null,
   }
+
+  if (modalForm.value.translations.length === 0) {
+    initTranslations(modalForm.value, ['title', 'description'])
+  }
+
   handleEdit(modalForm.value, '编辑顶层菜单', () => {
     getMenuDetail()
   })