diff --git a/components.d.ts b/components.d.ts
index bbec505..4b333bc 100644
--- a/components.d.ts
+++ b/components.d.ts
@@ -8,6 +8,7 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
Copyright: typeof import('./src/components/Copyright.vue')['default']
+ ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
RegularPage: typeof import('./src/components/RegularPage.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
@@ -15,7 +16,6 @@ declare module 'vue' {
TAvatar: typeof import('tdesign-vue-next')['Avatar']
TButton: typeof import('tdesign-vue-next')['Button']
TCard: typeof import('tdesign-vue-next')['Card']
- TCheckbox: typeof import('tdesign-vue-next')['Checkbox']
TDialog: typeof import('tdesign-vue-next')['Dialog']
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
TForm: typeof import('tdesign-vue-next')['Form']
@@ -24,11 +24,13 @@ declare module 'vue' {
TIcon: typeof import('tdesign-vue-next')['Icon']
TInput: typeof import('tdesign-vue-next')['Input']
TLayout: typeof import('tdesign-vue-next')['Layout']
- TLink: typeof import('tdesign-vue-next')['Link']
TMenu: typeof import('tdesign-vue-next')['Menu']
TMenuItem: typeof import('tdesign-vue-next')['MenuItem']
+ TRadioButton: typeof import('tdesign-vue-next')['RadioButton']
+ TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
TSpace: typeof import('tdesign-vue-next')['Space']
TTable: typeof import('tdesign-vue-next')['Table']
TTag: typeof import('tdesign-vue-next')['Tag']
+ TUpload: typeof import('tdesign-vue-next')['Upload']
}
}
diff --git a/src/api/carousal.ts b/src/api/carousal.ts
index 09f3ca6..84aa263 100644
--- a/src/api/carousal.ts
+++ b/src/api/carousal.ts
@@ -1,8 +1,7 @@
import httpClient from './httpClient'
import type { CreateCarousalsRequest, GetCarousalsRequest } from '@/model/carousals'
-import type { UnwrapNestedRefs } from 'vue'
-export const createCarousal = (createCarousalsRequest: UnwrapNestedRefs<{ size: number; page: number }> & {}) => {
+export const createCarousal = (createCarousalsRequest: CreateCarousalsRequest) => {
return httpClient.post('/carousals', createCarousalsRequest)
}
diff --git a/src/components/ImageUpload.vue b/src/components/ImageUpload.vue
new file mode 100644
index 0000000..5522c8b
--- /dev/null
+++ b/src/components/ImageUpload.vue
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/model/carousals.ts b/src/model/carousals.ts
index 1c132ea..7bd74a5 100644
--- a/src/model/carousals.ts
+++ b/src/model/carousals.ts
@@ -1,12 +1,12 @@
export interface CreateCarousalsRequest {
imageUrl:string,
targetType:string,
- targetUrl:string,
- targetId:string
+ targetUrl?:string,
+ targetId?:string
}
export interface GetCarousalsRequest {
- page:string,
- size:string,
- order?:string
+ page:number,
+ size:number,
+ order?:[string]
}
diff --git a/src/pages/carousal/components/CarousalDialog.vue b/src/pages/carousal/components/CarousalDialog.vue
index 8d6e8d1..8a8e003 100644
--- a/src/pages/carousal/components/CarousalDialog.vue
+++ b/src/pages/carousal/components/CarousalDialog.vue
@@ -1,6 +1,6 @@
-
-
-
+
+
+
-
-
+
+
+ {{item.label}}
+
-
-
+
+
+
+
+
@@ -26,6 +31,8 @@
import type { Classify } from '@/model/classify'
import { computed, ref, reactive, watch } from 'vue'
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
+import ImageUpload from '@/components/ImageUpload.vue'
+import { createCarousal } from '@/api/carousal'
const props = defineProps<{
isEdit?: Boolean | null
headerTitle?: String | null
@@ -34,97 +41,107 @@ const props = defineProps<{
const form = ref(null)
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
-const classifyData: FormProps['data'] = reactive({ name: '', sort: 0 })
-const rules: FormProps['rules'] = {
- name: [
- {
- required: true,
- message: '分类名称不能为空',
- type: 'error',
- trigger: 'blur'
- },
- {
- required: true,
- message: '分类名称不能为空',
- type: 'error',
- trigger: 'change'
- },
- {
- whitespace: true,
- message: '分类名称不能为空'
- },
- {
- min: 4,
- message: '输入汉字长度应在2到5之间',
- type: 'error',
- trigger: 'blur'
- },
- {
- max: 10,
- message: '输入汉字长度应在2到5之间',
- type: 'error',
- trigger: 'blur'
- }
- ],
- numbering: [
- {
- required: true,
- message: '分类编号不能为空',
- type: 'error',
- trigger: 'blur'
- },
- {
- required: true,
- message: '分类编号不能为空',
- type: 'error',
- trigger: 'change'
- },
- {
- whitespace: true,
- message: '分类编号不能为空'
- },
- {
- min: 4,
- message: '输入字符应大于4个字符长度',
- type: 'error',
- trigger: 'blur'
- },
- {
- pattern: /^[A-Za-z]+$/,
- message: '输入字符须为英文字母',
- type: 'error',
- trigger: 'blur'
- }
- ],
- sort: [
- {
- required: true,
- message: '排序级别不能为空',
- type: 'error',
- trigger: 'blur'
- },
- {
- required: true,
- message: '排序级别不能为空',
- type: 'error',
- trigger: 'change'
- },
- {
- whitespace: true,
- message: '排序级别不能为空'
- },
- {
- pattern: /^[1-9]\d*$/,
- message: '排序级别必须为正整数',
- type: 'error',
- trigger: 'blur'
- }
- ]
+const carousalData: FormProps['data'] = reactive({})
+const rules = computed(() => {
+ const commonRules = {
+ imageUrl: [
+ {
+ required: true,
+ message: '轮播图必须是上传',
+ type: 'error',
+ trigger: 'change',
+ },
+ ],
+ targetType: [
+ {
+ required: true,
+ message: '请选择跳转类型',
+ type: 'error',
+ trigger: 'blur',
+ },
+ {
+ required: true,
+ message: '请选择跳转类型',
+ type: 'error',
+ trigger: 'change',
+ },
+ ],
+ };
+ return carousalData.targetType === 'article'
+ ? {...commonRules, targetId: [{ required: true, message: '文章 id 不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '文章 id 不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] }
+ : {...commonRules, targetUrl: [{ required: true, message: '网址路径不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '网址路径不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] };
+});
+// const rules: FormProps['rules'] = {
+// imageUrl:[
+// {
+// required: true,
+// message:'轮播图必须是上传',
+// type:'error',
+// trigger: 'change'
+// }
+// ],
+// targetType:[
+// {
+// required: true,
+// message: '请选择跳转类型',
+// type: 'error',
+// trigger: 'blur'
+// },
+// {
+// required: true,
+// message: '请选择跳转类型',
+// type: 'error',
+// trigger: 'change'
+// },
+// ],
+// targetId:[
+// {
+// required: true,
+// message: '文章id不能为空',
+// type: 'error',
+// trigger: 'blur'
+// },
+// {
+// required: true,
+// message: '文章id不能为空',
+// type: 'error',
+// trigger: 'change'
+// },
+// {
+// whitespace: true,
+// message: '网址路径不能为空'
+// },
+// ],
+// targetUrl:[
+// {
+// required: true,
+// message: '网址路径不能为空',
+// type: 'error',
+// trigger: 'blur'
+// },
+// {
+// required: true,
+// message: '网址路径不能为空',
+// type: 'error',
+// trigger: 'change'
+// },
+// {
+// whitespace: true,
+// message: '网址路径不能为空'
+// },
+// ],
+// }
+const handleSuccessImg = (res:string) => {
+ carousalData.imageUrl = res
}
+const typeOption = reactive([
+ { value: 'article', label: '文章' },
+ { value: 'url', label: '地址' },
+])
watch(
() => props.classify,
(newClassify) => {
- Object.assign(classifyData, newClassify)
+ Object.assign(carousalData, newClassify)
},
{ deep: true }
)
@@ -132,8 +149,16 @@ const fetchSaveClassifyData = async () => {
/* TODO: 保存分类数据 */
if (form.value) {
const valid = await form.value.validate()
+ // console.log(valid,'valid')
if (valid && typeof valid === 'boolean') {
/* TODO: 校验通过保存分类数据 */
+ if (carousalData.targetType === 'article') {
+ delete carousalData.targetUrl
+ } else if (carousalData.targetType === 'url') {
+ delete carousalData.targetId
+ }
+ const createCarousalApi = createCarousal(carousalData)
+ console.log(createCarousalApi,'createCarousalApi')
return
}
}
diff --git a/src/pages/carousal/index.vue b/src/pages/carousal/index.vue
index e3dc60b..e85ec6e 100644
--- a/src/pages/carousal/index.vue
+++ b/src/pages/carousal/index.vue
@@ -4,7 +4,7 @@ import { onMounted, ref, reactive } from 'vue'
import type { BaseTableColumns } from 'tdesign-vue-next'
import type { Classify } from '@/model/classify'
import ClassifyDialog from '@/pages/carousal/components/CarousalDialog.vue'
-import { createCarousal } from '@/api/carousal'
+import { getCarousalList } from '@/api/carousal'
const columns: BaseTableColumns = [
{
@@ -19,7 +19,7 @@ const columns: BaseTableColumns = [
},
{
title: '显示状态',
- colKey: 'targetType',
+ colKey: 'status',
width: 100
},
{
@@ -32,15 +32,23 @@ const loading = ref(false)
const data = ref([])
const pagination = reactive({
page: 1,
- size: 10
+ size: 10,
+ total:0
+})
+const query = reactive({
+ page:1,
+ size:10,
})
const classifyDialogVisible = ref(false)
const isEdit = ref(false)
-const currentTableData = ref({})
-const fetchClassifyTableData = () => {
+const currentTableData = ref<{}>({})
+const fetchClassifyTableData = async () => {
/* TODO: 获取轮播图表格数据 */
- const createCarousalApi = createCarousal(pagination)
- console.log(createCarousalApi,'api')
+ query.page = pagination.page
+ query.size = pagination.size
+ const getCarousalListApi = await getCarousalList(query)
+ currentTableData.value = getCarousalListApi.data
+ pagination.total = getCarousalListApi.pagination.total
}
onMounted(fetchClassifyTableData)
const editClick = (classify: Classify) => {
@@ -92,7 +100,7 @@ const onPageChange = () => {
:classify="currentTableData"
v-model:visible="classifyDialogVisible"
:isEdit="isEdit"
- headerTitle="分类"
+ headerTitle="轮播图"
>
diff --git a/src/router/index.ts b/src/router/index.ts
index 59dc447..cbe0493 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -45,13 +45,13 @@ const router = createRouter({
]
})
-// router.beforeEach((to, from, next) => {
-// if (to.name !== 'login') {
-// const appStore = useAppStore()
-// appStore.isLogin ? next() : next({ name: 'login' })
-// return
-// }
-// next()
-// })
+router.beforeEach((to, from, next) => {
+ if (to.name !== 'login') {
+ const appStore = useAppStore()
+ appStore.isLogin ? next() : next({ name: 'login' })
+ return
+ }
+ next()
+})
export default router