|
@@ -5,36 +5,45 @@
|
|
|
:confirmBtn="confirmBtn"
|
|
:confirmBtn="confirmBtn"
|
|
|
:closeOnOverlayClick="false"
|
|
:closeOnOverlayClick="false"
|
|
|
@close="handleCloseDialog"
|
|
@close="handleCloseDialog"
|
|
|
- @confirm="fetchSaveClassifyData"
|
|
|
|
|
|
|
+ @confirm="SaveCategoryData"
|
|
|
>
|
|
>
|
|
|
<t-space direction="vertical" style="width: 100%">
|
|
<t-space direction="vertical" style="width: 100%">
|
|
|
- <TForm ref="form" :data="classifyData" :rules="rules" resetType="initial">
|
|
|
|
|
|
|
+ <TForm ref="form" :data="categoryData" :rules="rules" resetType="initial">
|
|
|
<TFormItem label="分类名称:" name="name" help="名称长度小于5个汉字,大于2个汉字">
|
|
<TFormItem label="分类名称:" name="name" help="名称长度小于5个汉字,大于2个汉字">
|
|
|
- <t-input v-model.trim="classifyData.name" clearable placeholder="请输入分类名称" />
|
|
|
|
|
|
|
+ <t-input v-model.trim="categoryData.name" clearable placeholder="请输入分类名称" />
|
|
|
</TFormItem>
|
|
</TFormItem>
|
|
|
- <TFormItem label="分类编号:" name="numbering" help="编号由大于4个字符的英文字母组成">
|
|
|
|
|
- <t-input v-model.trim="classifyData.numbering" clearable placeholder="请输入分类编号" />
|
|
|
|
|
|
|
+ <TFormItem label="分类编号:" name="code" help="编号由大于4个字符的英文字母组成">
|
|
|
|
|
+ <t-input v-model.trim="categoryData.code" clearable placeholder="请输入分类编号" />
|
|
|
</TFormItem>
|
|
</TFormItem>
|
|
|
- <TFormItem label="排序级别:" name="sort" help="排序级别由正整数组成">
|
|
|
|
|
- <t-input v-model.trim="classifyData.sort" clearable placeholder="请输入排序级别" />
|
|
|
|
|
|
|
+ <TFormItem label="排序级别:" name="order" help="排序级别由正整数组成">
|
|
|
|
|
+ <t-input-number
|
|
|
|
|
+ :min="0"
|
|
|
|
|
+ name="order"
|
|
|
|
|
+ theme="normal"
|
|
|
|
|
+ class="!w-full"
|
|
|
|
|
+ placeholder="请输入排序级别"
|
|
|
|
|
+ v-model.trim="categoryData.order"
|
|
|
|
|
+ ></t-input-number>
|
|
|
</TFormItem>
|
|
</TFormItem>
|
|
|
</TForm>
|
|
</TForm>
|
|
|
</t-space>
|
|
</t-space>
|
|
|
</t-dialog>
|
|
</t-dialog>
|
|
|
</template>
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
-import type { Classify } from '@/model/classify'
|
|
|
|
|
|
|
+import type { Category } from '@/model/category'
|
|
|
import { computed, ref, reactive, watch } from 'vue'
|
|
import { computed, ref, reactive, watch } from 'vue'
|
|
|
|
|
+import { createCategoryRequest, updateCategoryByIdRequest } from '@/api/category'
|
|
|
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
|
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
|
|
|
|
+import { MessagePlugin } from 'tdesign-vue-next'
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
|
isEdit?: Boolean | null
|
|
isEdit?: Boolean | null
|
|
|
headerTitle?: String | null
|
|
headerTitle?: String | null
|
|
|
- classify: Classify | {}
|
|
|
|
|
|
|
+ category: Category | {}
|
|
|
}>()
|
|
}>()
|
|
|
const form = ref<FormInstanceFunctions | null>(null)
|
|
const form = ref<FormInstanceFunctions | null>(null)
|
|
|
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
|
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
|
|
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
|
|
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
|
|
|
-const classifyData: FormProps['data'] = reactive({ name: '', sort: 0 })
|
|
|
|
|
|
|
+const categoryData: FormProps['data'] = reactive({ name: '', order: 1 })
|
|
|
const rules: FormProps['rules'] = {
|
|
const rules: FormProps['rules'] = {
|
|
|
name: [
|
|
name: [
|
|
|
{
|
|
{
|
|
@@ -66,7 +75,7 @@ const rules: FormProps['rules'] = {
|
|
|
trigger: 'blur'
|
|
trigger: 'blur'
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
- numbering: [
|
|
|
|
|
|
|
+ code: [
|
|
|
{
|
|
{
|
|
|
required: true,
|
|
required: true,
|
|
|
message: '分类编号不能为空',
|
|
message: '分类编号不能为空',
|
|
@@ -96,7 +105,7 @@ const rules: FormProps['rules'] = {
|
|
|
trigger: 'blur'
|
|
trigger: 'blur'
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
- sort: [
|
|
|
|
|
|
|
+ order: [
|
|
|
{
|
|
{
|
|
|
required: true,
|
|
required: true,
|
|
|
message: '排序级别不能为空',
|
|
message: '排序级别不能为空',
|
|
@@ -122,18 +131,27 @@ const rules: FormProps['rules'] = {
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
|
watch(
|
|
watch(
|
|
|
- () => props.classify,
|
|
|
|
|
- (newClassify) => {
|
|
|
|
|
- Object.assign(classifyData, newClassify)
|
|
|
|
|
|
|
+ () => props.category,
|
|
|
|
|
+ (newCategory) => {
|
|
|
|
|
+ Object.assign(categoryData, newCategory)
|
|
|
},
|
|
},
|
|
|
{ deep: true }
|
|
{ deep: true }
|
|
|
)
|
|
)
|
|
|
-const fetchSaveClassifyData = async () => {
|
|
|
|
|
- /* TODO: 保存分类数据 */
|
|
|
|
|
|
|
+const emit = defineEmits<{
|
|
|
|
|
+ success: [void]
|
|
|
|
|
+}>()
|
|
|
|
|
+const SaveCategoryData = async () => {
|
|
|
if (form.value) {
|
|
if (form.value) {
|
|
|
const valid = await form.value.validate()
|
|
const valid = await form.value.validate()
|
|
|
if (valid && typeof valid === 'boolean') {
|
|
if (valid && typeof valid === 'boolean') {
|
|
|
- /* TODO: 校验通过保存分类数据 */
|
|
|
|
|
|
|
+ const { code, name, order, id } = categoryData
|
|
|
|
|
+ if (!props.isEdit) {
|
|
|
|
|
+ await createCategoryRequest({ code, name, order })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ await updateCategoryByIdRequest(id, { code, name, order })
|
|
|
|
|
+ }
|
|
|
|
|
+ MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}分类成功`)
|
|
|
|
|
+ emit('success')
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|