diff --git a/components.d.ts b/components.d.ts index 2460b53..c0b9ad9 100644 --- a/components.d.ts +++ b/components.d.ts @@ -18,6 +18,7 @@ declare module 'vue' { TAvatar: typeof import('tdesign-vue-next')['Avatar'] TButton: typeof import('tdesign-vue-next')['Button'] TCard: typeof import('tdesign-vue-next')['Card'] + TCol: typeof import('tdesign-vue-next')['Col'] TDialog: typeof import('tdesign-vue-next')['Dialog'] TDropdown: typeof import('tdesign-vue-next')['Dropdown'] TForm: typeof import('tdesign-vue-next')['Form'] @@ -33,8 +34,8 @@ declare module 'vue' { TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm'] TRadioButton: typeof import('tdesign-vue-next')['RadioButton'] TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup'] + TRow: typeof import('tdesign-vue-next')['Row'] TSelect: typeof import('tdesign-vue-next')['Select'] - TSelectInput: typeof import('tdesign-vue-next')['SelectInput'] TSpace: typeof import('tdesign-vue-next')['Space'] TTable: typeof import('tdesign-vue-next')['Table'] TTag: typeof import('tdesign-vue-next')['Tag'] diff --git a/src/components/ImageUpload.vue b/src/components/ImageUpload.vue index 5e78cda..92b6509 100644 --- a/src/components/ImageUpload.vue +++ b/src/components/ImageUpload.vue @@ -9,7 +9,7 @@ const sizeLimit = ref({ size: 2, unit: 'MB', }); -const file1 = ref([]); +const fileList = ref([]); const disabled = ref(false); const autoUpload = ref(true); const showImageFileName = ref(true); @@ -19,8 +19,7 @@ const handleFail: UploadProps['onFail'] = ({ file }) => { }; const handleSuccess: UploadProps['onSuccess'] = ({ file }) => { if(file?.url){ - console.log(file1.value,'file1') - emits('on-success',file.url) + emits('update:modelValue',file.url) } } const appStore = useAppStore() @@ -28,35 +27,33 @@ const appStore = useAppStore() const uploadHeaders = ref({ Authorization: `Bearer ${appStore.token}` }) -const props = defineProps({ - imageUrl:{ - type:Object, - default:() => { - return { url: '' } - } - } + + +const props = withDefaults(defineProps<{ + modelValue: string +}>(), { + modelValue: '' }) -const emits = defineEmits(['on-success']) -watch(() => props.imageUrl,(newVal) => { + +const emits = defineEmits<{ + 'update:modelValue': [string] +}>() +watch(() => props.modelValue,(newVal) => { if (!newVal) return - if (newVal.url !== '') { - file1.value = [{...newVal}] - } else { - file1.value = [] - } + fileList.value = [{url: newVal}] },{ deep:true, immediate:true }) + diff --git a/src/layouts/components/UserArea.vue b/src/layouts/components/UserArea.vue index 75352cf..1c24efd 100644 --- a/src/layouts/components/UserArea.vue +++ b/src/layouts/components/UserArea.vue @@ -2,9 +2,8 @@ import { ChevronDownIcon } from 'tdesign-icons-vue-next' import type { DropdownOption } from 'tdesign-vue-next' import { useAppStore } from '@/stores/app' -import type { User } from '@/models/user' const appStore = useAppStore() -const currentUser: User = appStore.currentUser +const currentUser = appStore.currentUser const options: DropdownOption[] = [ { content: '退出登录', diff --git a/src/model/article.ts b/src/model/article.ts index 030709f..66935e0 100644 --- a/src/model/article.ts +++ b/src/model/article.ts @@ -2,8 +2,8 @@ import type { AuditBaseModel,Paging } from '@/model/base' import type { Category } from './category' export enum ArticleStatus { - Draft = 'draft', - Published = 'published', + DRAFT = 'draft', + PUBLISHED = 'published', Closed = 'closed' } @@ -12,6 +12,8 @@ export interface Article extends AuditBaseModel{ content:string category: Category status: ArticleStatus + thumbnail: string + description: string } @@ -26,4 +28,6 @@ export interface CreateArticleRequest{ categoryId: string title: string content: string + thumbnail: string + description:string } diff --git a/src/pages/article/components/ArticleDialog.vue b/src/pages/article/components/ArticleDialog.vue index e20c3d9..6df5788 100644 --- a/src/pages/article/components/ArticleDialog.vue +++ b/src/pages/article/components/ArticleDialog.vue @@ -11,6 +11,7 @@ import { MessagePlugin } from 'tdesign-vue-next' import { updateArticle, createArticle } from '@/api/article' import { searchCategories } from '@/api/category' import Editor from '@/components/Editor.vue' +import ImageUpload from '@/components/ImageUpload.vue' const props = defineProps<{ headerTitle?: String | null article: Article | null @@ -19,7 +20,7 @@ const props = defineProps<{ const formRef = ref(null) const headerText = computed(() => `${props.article ? '编辑' : '创建'}${props.headerTitle || ''}`) const confirmBtnText = computed(() => (props.article ? '保存' : '确定')) -const articleData = reactive({ title: '', categoryId: '', content: ''}) +const articleData = reactive({ title: '', categoryId: '', content: '', thumbnail: '', description: ''}) const rules: FormRules = { title: [ @@ -77,6 +78,26 @@ const rules: FormRules = { type: 'error', trigger: 'blur' } + ], + thumbnail: [ + { + required: true, + message: '请上传封面图', + type: 'error', + trigger: 'blur' + }, + { + whitespace: true, + message: '请上传封面图' + } + ], + description: [ + { + max: 500, + message: '描述不超过500字', + type: 'error', + trigger: 'blur' + } ] } watch( @@ -85,6 +106,7 @@ watch( articleData.categoryId = newArticleData?.category.id || '' articleData.title = newArticleData?.title || '' articleData.content = newArticleData?.content || '' + articleData.thumbnail = newArticleData?.thumbnail || '' }, { deep: true } ) @@ -143,6 +165,9 @@ fetchCategories('') + + + + + + diff --git a/tsconfig.node.json b/tsconfig.node.json index f094063..293b392 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -11,7 +11,6 @@ "composite": true, "noEmit": true, "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", - "module": "ESNext", "moduleResolution": "Bundler", "types": ["node"]