소스 검색

chore: 添加TODO注释;以更优雅的方式跳出循环

黄兆琦 8 달 전
부모
커밋
24e69ecf36

+ 1 - 2
src/views/mall/product/spu/form/ProductAttributes.vue

@@ -31,6 +31,7 @@
         class="!w-30"
         @blur="handleInputConfirm(index, item.id)"
         @keyup.enter="handleInputConfirm(index, item.id)"
+        @change="handleInputConfirm(index, item.id)"
       >
         <el-option
           v-for="item2 in item.propertyOpts"
@@ -39,7 +40,6 @@
           :value="item2.name"
         />
       </el-select>
-      <!-- <el-input :id="`input${index}`" v-model="inputValue" class="!w-20" /> -->
       <el-button
         v-show="!inputVisible(index)"
         class="button-new-tag ml-1"
@@ -54,7 +54,6 @@
 </template>
 
 <script lang="ts" setup>
-import { ElInput } from 'element-plus'
 import * as PropertyApi from '@/api/mall/product/property'
 import { PropertyAndValues } from '@/views/mall/product/spu/components'
 import { propTypes } from '@/utils/propTypes'

+ 6 - 6
src/views/mall/product/spu/form/ProductPropertyAddForm.vue

@@ -99,15 +99,14 @@ const submitForm = async () => {
       values: []
     })
     // 判断最终提交的属性名称是否是选择的 自己手动输入的属性名称不执行emit
-    attrOption.value.forEach((item) => {
-      if (item.name === formData.value.name) {
-        emit('success', propertyId, item.id)
+    for (const element of attrOption.value) {
+      if (element.name === formData.value.name) {
+        emit('success', propertyId, element.id)
         message.success(t('common.createSuccess'))
         dialogVisible.value = false
-        // 中断循环
-        throw new Error()
+        return
       }
-    })
+    }
     message.success(t('common.createSuccess'))
     dialogVisible.value = false
   } finally {
@@ -127,6 +126,7 @@ const resetForm = () => {
 const getAttrOption = async () => {
   formLoading.value = true
   try {
+    // TODO @芋艿:需要增加一个全列表接口
     const data = await PropertyApi.getPropertyPage({ pageNo: 1, pageSize: 100 })
     attrOption.value = data.list
   } finally {

+ 1 - 0
src/views/mall/product/spu/form/SkuForm.vue

@@ -201,6 +201,7 @@ const generateSkus = (propertyList: any[]) => {
 const getPropertyValueList = async (id, propertyId) => {
   formLoading.value = true
   try {
+    // TODO @芋艿:需要增加一个全列表接口
     const data = await PropertyApi.getPropertyValuePage({ pageNo: 1, pageSize: 100, propertyId })
     propertyList.value.find((item) => item.id === id).propertyOpts = data.list
   } finally {