feature:咨询管理页面开发及接口对接 #6

Merged
ilhamtahir merged 21 commits from feature/24-article into main 2024-11-22 11:18:26 +08:00
7 changed files with 221 additions and 120 deletions
Showing only changes of commit 9e7e7215e9 - Show all commits

No files matched your search

+4 -2
View File
@@ -8,6 +8,7 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
Copyright: typeof import('./src/components/Copyright.vue')['default'] Copyright: typeof import('./src/components/Copyright.vue')['default']
ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
RegularPage: typeof import('./src/components/RegularPage.vue')['default'] RegularPage: typeof import('./src/components/RegularPage.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
@@ -15,7 +16,6 @@ declare module 'vue' {
TAvatar: typeof import('tdesign-vue-next')['Avatar'] TAvatar: typeof import('tdesign-vue-next')['Avatar']
TButton: typeof import('tdesign-vue-next')['Button'] TButton: typeof import('tdesign-vue-next')['Button']
TCard: typeof import('tdesign-vue-next')['Card'] TCard: typeof import('tdesign-vue-next')['Card']
TCheckbox: typeof import('tdesign-vue-next')['Checkbox']
TDialog: typeof import('tdesign-vue-next')['Dialog'] TDialog: typeof import('tdesign-vue-next')['Dialog']
TDropdown: typeof import('tdesign-vue-next')['Dropdown'] TDropdown: typeof import('tdesign-vue-next')['Dropdown']
TForm: typeof import('tdesign-vue-next')['Form'] TForm: typeof import('tdesign-vue-next')['Form']
@@ -24,11 +24,13 @@ declare module 'vue' {
TIcon: typeof import('tdesign-vue-next')['Icon'] TIcon: typeof import('tdesign-vue-next')['Icon']
TInput: typeof import('tdesign-vue-next')['Input'] TInput: typeof import('tdesign-vue-next')['Input']
TLayout: typeof import('tdesign-vue-next')['Layout'] TLayout: typeof import('tdesign-vue-next')['Layout']
TLink: typeof import('tdesign-vue-next')['Link']
TMenu: typeof import('tdesign-vue-next')['Menu'] TMenu: typeof import('tdesign-vue-next')['Menu']
TMenuItem: typeof import('tdesign-vue-next')['MenuItem'] 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'] TSpace: typeof import('tdesign-vue-next')['Space']
TTable: typeof import('tdesign-vue-next')['Table'] TTable: typeof import('tdesign-vue-next')['Table']
TTag: typeof import('tdesign-vue-next')['Tag'] TTag: typeof import('tdesign-vue-next')['Tag']
TUpload: typeof import('tdesign-vue-next')['Upload']
} }
} }
+1 -2
View File
@@ -1,8 +1,7 @@
import httpClient from './httpClient' import httpClient from './httpClient'
import type { CreateCarousalsRequest, GetCarousalsRequest } from '@/model/carousals' 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) return httpClient.post('/carousals', createCarousalsRequest)
} }
+67
View File
@@ -0,0 +1,67 @@
<script setup lang="ts">
import { MessagePlugin, type UploadProps } from 'tdesign-vue-next'
import {ref} from 'vue'
import { useAppStore } from '@/stores/app'
const imageViewerProps = ref<UploadProps['imageViewerProps']>({
closeOnEscKeydown: false,
});
const sizeLimit = ref<UploadProps['sizeLimit']>({
size: 2,
unit: 'MB',
});
const file1 = ref<UploadProps['value']>([]);
const disabled = ref(false);
const autoUpload = ref(true);
const showImageFileName = ref(true);
const uploadAllFilesInOneRequest = ref(false);
const handleFail: UploadProps['onFail'] = ({ file }) => {
MessagePlugin.error(`文件 ${file.name} 上传失败`);
};
const handleSuccess: UploadProps['onSuccess'] = ({ file }) => {
if(file?.url){
emits('on-success',file.url)
}
}
const appStore = useAppStore()
const uploadHeaders = ref<UploadProps['headers']>({
Authorization: `Bearer ${appStore.token}`
})
const emits = defineEmits(['on-success'])
</script>
<template>
<div>
<t-upload
ref="uploadRef1"
v-model="file1"
:image-viewer-props="imageViewerProps"
:size-limit="sizeLimit"
action="/api/files/upload"
:headers="uploadHeaders"
theme="image"
tips="图片上传限制为2M"
accept="image/*"
:disabled="disabled"
:auto-upload="autoUpload"
:show-image-file-name="showImageFileName"
:upload-all-files-in-one-request="uploadAllFilesInOneRequest"
:locale="{
triggerUploadText: {
image: '请选择图片',
},
}"
@fail="handleFail"
@success="handleSuccess"
>
<!-- custom UI -->
<!-- <template #fileListDisplay="{ files }">
<div>{{ JSON.stringify(files) }}</div>
</template> -->
</t-upload>
</div>
</template>
<style scoped>
</style>
+5 -5
View File
@@ -1,12 +1,12 @@
export interface CreateCarousalsRequest { export interface CreateCarousalsRequest {
imageUrl:string, imageUrl:string,
targetType:string, targetType:string,
targetUrl:string, targetUrl?:string,
targetId:string targetId?:string
} }
export interface GetCarousalsRequest { export interface GetCarousalsRequest {
page:string, page:number,
size:string, size:number,
order?:string order?:[string]
} }
+120 -95
View File
@@ -1,6 +1,6 @@
<template> <template>
<t-dialog <t-dialog
width="40%" width="70%"
:header="header" :header="header"
:confirmBtn="confirmBtn" :confirmBtn="confirmBtn"
:closeOnOverlayClick="false" :closeOnOverlayClick="false"
@@ -8,15 +8,20 @@
@confirm="fetchSaveClassifyData" @confirm="fetchSaveClassifyData"
> >
<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="carousalData" :rules="rules" resetType="initial">
<TFormItem label="分类名称:" name="name" help="名称长度小于5个汉字,大于2个汉字"> <TFormItem label="轮播图:" name="imageUrl">
<t-input v-model.trim="classifyData.name" clearable placeholder="请输入分类名称" /> <ImageUpload @on-success="handleSuccessImg"/>
</TFormItem> </TFormItem>
<TFormItem label="分类编号:" name="numbering" help="编号由大于4个字符的英文字母组成"> <TFormItem label="跳转类型:" name="targetType" >
<t-input v-model.trim="classifyData.numbering" clearable placeholder="请输入分类编号" /> <t-radio-group :default-value="carousalData.targetType" v-model="carousalData.targetType">
<t-radio-button v-for="(item,index) in typeOption" :key="index" :value="item.value">{{item.label}}</t-radio-button>
</t-radio-group>
</TFormItem> </TFormItem>
<TFormItem label="排序级别:" name="sort" help="排序级别由正整数组成"> <TFormItem label="跳转文章路径:" name="targetId" v-if="carousalData.targetType === 'article' ">
<t-input v-model.trim="classifyData.sort" clearable placeholder="请输入排序级别" /> <t-input v-model.trim="carousalData.targetId" clearable placeholder="请输入文章id" />
</TFormItem>
<TFormItem label="跳转网址路径:" name="targetUrl" v-else-if="carousalData.targetType === 'url' ">
<t-input v-model.trim="carousalData.targetUrl" clearable placeholder="请输入网址路径" />
</TFormItem> </TFormItem>
</TForm> </TForm>
</t-space> </t-space>
@@ -26,6 +31,8 @@
import type { Classify } from '@/model/classify' import type { Classify } from '@/model/classify'
import { computed, ref, reactive, watch } from 'vue' import { computed, ref, reactive, watch } from 'vue'
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next' import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
import ImageUpload from '@/components/ImageUpload.vue'
import { createCarousal } from '@/api/carousal'
const props = defineProps<{ const props = defineProps<{
isEdit?: Boolean | null isEdit?: Boolean | null
headerTitle?: String | null headerTitle?: String | null
@@ -34,97 +41,107 @@ const props = defineProps<{
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 carousalData: FormProps['data'] = reactive({})
const rules: FormProps['rules'] = { const rules = computed(() => {
name: [ const commonRules = {
{ imageUrl: [
required: true, {
message: '分类名称不能为空', required: true,
type: 'error', message: '轮播图必须是上传',
trigger: 'blur' type: 'error',
}, trigger: 'change',
{ },
required: true, ],
message: '分类名称不能为空', targetType: [
type: 'error', {
trigger: 'change' required: true,
}, message: '请选择跳转类型',
{ type: 'error',
whitespace: true, trigger: 'blur',
message: '分类名称不能为空' },
}, {
{ required: true,
min: 4, message: '请选择跳转类型',
message: '输入汉字长度应在2到5之间', type: 'error',
type: 'error', trigger: 'change',
trigger: 'blur' },
}, ],
{ };
max: 10, return carousalData.targetType === 'article'
message: '输入汉字长度应在2到5之间', ? {...commonRules, targetId: [{ required: true, message: '文章 id 不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '文章 id 不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] }
type: 'error', : {...commonRules, targetUrl: [{ required: true, message: '网址路径不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '网址路径不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] };
trigger: 'blur' });
} // const rules: FormProps['rules'] = {
], // imageUrl:[
numbering: [ // {
{ // required: true,
required: true, // message:'轮播图必须是上传',
message: '分类编号不能为空', // type:'error',
type: 'error', // trigger: 'change'
trigger: 'blur' // }
}, // ],
{ // targetType:[
required: true, // {
message: '分类编号不能为空', // required: true,
type: 'error', // message: '请选择跳转类型',
trigger: 'change' // type: 'error',
}, // trigger: 'blur'
{ // },
whitespace: true, // {
message: '分类编号不能为空' // required: true,
}, // message: '请选择跳转类型',
{ // type: 'error',
min: 4, // trigger: 'change'
message: '输入字符应大于4个字符长度', // },
type: 'error', // ],
trigger: 'blur' // targetId:[
}, // {
{ // required: true,
pattern: /^[A-Za-z]+$/, // message: '文章id不能为空',
message: '输入字符须为英文字母', // type: 'error',
type: 'error', // trigger: 'blur'
trigger: 'blur' // },
} // {
], // required: true,
sort: [ // message: '文章id不能为空',
{ // type: 'error',
required: true, // trigger: 'change'
message: '排序级别不能为空', // },
type: 'error', // {
trigger: 'blur' // whitespace: true,
}, // message: '网址路径不能为空'
{ // },
required: true, // ],
message: '排序级别不能为空', // targetUrl:[
type: 'error', // {
trigger: 'change' // required: true,
}, // message: '网址路径不能为空',
{ // type: 'error',
whitespace: true, // trigger: 'blur'
message: '排序级别不能为空' // },
}, // {
{ // required: true,
pattern: /^[1-9]\d*$/, // message: '网址路径不能为空',
message: '排序级别必须为正整数', // type: 'error',
type: 'error', // trigger: 'change'
trigger: 'blur' // },
} // {
] // whitespace: true,
// message: '网址路径不能为空'
// },
// ],
// }
const handleSuccessImg = (res:string) => {
carousalData.imageUrl = res
} }
const typeOption = reactive([
{ value: 'article', label: '文章' },
{ value: 'url', label: '地址' },
])
watch( watch(
() => props.classify, () => props.classify,
(newClassify) => { (newClassify) => {
Object.assign(classifyData, newClassify) Object.assign(carousalData, newClassify)
}, },
{ deep: true } { deep: true }
) )
@@ -132,8 +149,16 @@ const fetchSaveClassifyData = async () => {
/* TODO: 保存分类数据 */ /* TODO: 保存分类数据 */
if (form.value) { if (form.value) {
const valid = await form.value.validate() const valid = await form.value.validate()
// console.log(valid,'valid')
if (valid && typeof valid === 'boolean') { if (valid && typeof valid === 'boolean') {
/* TODO: 校验通过保存分类数据 */ /* 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 return
} }
} }
+16 -8
View File
@@ -4,7 +4,7 @@ import { onMounted, ref, reactive } from 'vue'
import type { BaseTableColumns } from 'tdesign-vue-next' import type { BaseTableColumns } from 'tdesign-vue-next'
import type { Classify } from '@/model/classify' import type { Classify } from '@/model/classify'
import ClassifyDialog from '@/pages/carousal/components/CarousalDialog.vue' import ClassifyDialog from '@/pages/carousal/components/CarousalDialog.vue'
import { createCarousal } from '@/api/carousal' import { getCarousalList } from '@/api/carousal'
const columns: BaseTableColumns = [ const columns: BaseTableColumns = [
{ {
@@ -19,7 +19,7 @@ const columns: BaseTableColumns = [
}, },
{ {
title: '显示状态', title: '显示状态',
colKey: 'targetType', colKey: 'status',
width: 100 width: 100
}, },
{ {
@@ -32,15 +32,23 @@ const loading = ref(false)
const data = ref([]) const data = ref([])
const pagination = reactive({ const pagination = reactive({
page: 1, page: 1,
size: 10 size: 10,
total:0
})
const query = reactive({
page:1,
size:10,
}) })
const classifyDialogVisible = ref(false) const classifyDialogVisible = ref(false)
const isEdit = ref(false) const isEdit = ref(false)
const currentTableData = ref<Classify | {}>({}) const currentTableData = ref<{}>({})
const fetchClassifyTableData = () => { const fetchClassifyTableData = async () => {
/* TODO: 获取轮播图表格数据 */ /* TODO: 获取轮播图表格数据 */
const createCarousalApi = createCarousal(pagination) query.page = pagination.page
console.log(createCarousalApi,'api') query.size = pagination.size
const getCarousalListApi = await getCarousalList(query)
currentTableData.value = getCarousalListApi.data
pagination.total = getCarousalListApi.pagination.total
} }
onMounted(fetchClassifyTableData) onMounted(fetchClassifyTableData)
const editClick = (classify: Classify) => { const editClick = (classify: Classify) => {
@@ -92,7 +100,7 @@ const onPageChange = () => {
:classify="currentTableData" :classify="currentTableData"
v-model:visible="classifyDialogVisible" v-model:visible="classifyDialogVisible"
:isEdit="isEdit" :isEdit="isEdit"
headerTitle="分类" headerTitle="轮播图"
></ClassifyDialog> ></ClassifyDialog>
</RegularPage> </RegularPage>
</template> </template>
+8 -8
View File
@@ -45,13 +45,13 @@ const router = createRouter({
] ]
}) })
// router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// if (to.name !== 'login') { if (to.name !== 'login') {
// const appStore = useAppStore() const appStore = useAppStore()
// appStore.isLogin ? next() : next({ name: 'login' }) appStore.isLogin ? next() : next({ name: 'login' })
// return return
// } }
// next() next()
// }) })
export default router export default router