Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daf2f1f7dc | ||
|
|
8a96ca3bc4 | ||
|
|
9617d80ff4 | ||
|
|
46fead9039 | ||
|
|
f20cd94eec | ||
|
|
0cfcebdebd | ||
|
|
a859521682 | ||
|
|
f8425de967 | ||
|
|
a77af184df | ||
|
|
fdf572d3ef | ||
|
|
b4541b6f78 | ||
|
|
37a8db0055 | ||
|
|
b3ae608daa | ||
|
|
9e7e7215e9 | ||
|
|
6120d0b8fa | ||
|
|
280847acd1 | ||
|
|
00dd253202 | ||
|
|
cba8f966ac | ||
|
|
f3d5e881af | ||
|
|
9e94573046 | ||
|
|
5f9e951aa8 | ||
|
|
b455930798 |
No files matched your search
@@ -1,3 +1,3 @@
|
||||
VITE_ENABLE_MOCK=false
|
||||
VITE_API_PREFIX=/api
|
||||
VITE_PROXY_ENDPOINT=https://bright.yilibili.com/api
|
||||
VITE_PROXY_ENDPOINT=http://localhost:8000
|
||||
+4
-1
@@ -1 +1,4 @@
|
||||
VITE_ENABLE_MOCK=true
|
||||
VITE_ENABLE_MOCK=false
|
||||
VITE_API_PREFIX=/api
|
||||
VITE_PROXY_ENDPOINT=https://bright.yilibili.com
|
||||
|
||||
Vendored
+8
-4
@@ -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,20 +16,23 @@ 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']
|
||||
TFormItem: typeof import('tdesign-vue-next')['FormItem']
|
||||
THeader: typeof import('tdesign-vue-next')['Header']
|
||||
TIcon: typeof import('tdesign-vue-next')['Icon']
|
||||
TImageViewer: typeof import('tdesign-vue-next')['ImageViewer']
|
||||
TInput: typeof import('tdesign-vue-next')['Input']
|
||||
TInputNumber: typeof import('tdesign-vue-next')['InputNumber']
|
||||
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']
|
||||
TSelectInput: typeof import('tdesign-vue-next')['SelectInput']
|
||||
TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm']
|
||||
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']
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import httpClient from './httpClient'
|
||||
import type { CreateCarousalsRequest, GetCarousalsRequest } from '@/model/carousals'
|
||||
|
||||
export const createCarousal = (createCarousalsRequest: CreateCarousalsRequest) => {
|
||||
return httpClient.post('/carousals', createCarousalsRequest)
|
||||
}
|
||||
|
||||
export const getCarousalList = (getCarousalsRequest:GetCarousalsRequest) => {
|
||||
return httpClient.get('/carousals',getCarousalsRequest)
|
||||
}
|
||||
export const getCarousalItem = (id:string) => {
|
||||
return httpClient.get(`/carousals/${id}`)
|
||||
}
|
||||
|
||||
export const updateCarousalItem = (id:number,updateCarousalsRequest: CreateCarousalsRequest) => {
|
||||
return httpClient.put(`/carousals/${id}`,updateCarousalsRequest)
|
||||
}
|
||||
|
||||
export const deleteCarousal = (id:string | number) => {
|
||||
return httpClient.delete(`/carousals/${id}`)
|
||||
}
|
||||
|
||||
export const activeCarousal = (id: string | number) => {
|
||||
return httpClient.put(`/carousals/${id}/active`)
|
||||
}
|
||||
|
||||
export const inactiveCarousal = (id: string | number ) => {
|
||||
return httpClient.put(`/carousals/${id}/inactive`)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import httpClient from '@/api/httpClient'
|
||||
import type { PageResult } from '@/model/base'
|
||||
import type { Category,CategorySearchFilter, } from '@/model/category'
|
||||
|
||||
export const searchCategoryRequest = (categoryFilterParam:CategorySearchFilter ) => {
|
||||
return httpClient.get<PageResult<Category>>('/categories',categoryFilterParam)
|
||||
}
|
||||
|
||||
export const createCategoryRequest = (category: Pick<Category,'name'|'code'|'order'>) => {
|
||||
return httpClient.post<Category>('/categories',category)
|
||||
}
|
||||
|
||||
export const deleteCategoryRequest = (id: string) => {
|
||||
return httpClient.delete(`/categories/${id}`,)
|
||||
}
|
||||
|
||||
export const searchCategoryByIdRequest = (id: string) => {
|
||||
return httpClient.get<Category>(`/categories/${id}`)
|
||||
}
|
||||
|
||||
export const updateCategoryByIdRequest = (id: string,category: Pick<Category,'name'|'code'|'order'>) => {
|
||||
return httpClient.put<Category>(`/categories/${id}`,category)
|
||||
}
|
||||
+13
-9
@@ -1,5 +1,5 @@
|
||||
import axios, { type AxiosInstance } from 'axios'
|
||||
import type { ErrorResponse } from '@/model/base'
|
||||
import axios, { type AxiosInstance, } from 'axios'
|
||||
import type { ErrorResponse,ErrorResponseList } from '@/model/base'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
|
||||
@@ -9,18 +9,22 @@ const client: AxiosInstance = axios.create({
|
||||
})
|
||||
|
||||
const handleError = (errorResponse: ErrorResponse) => {
|
||||
|
||||
MessagePlugin.error(errorResponse.message)
|
||||
}
|
||||
client.interceptors.response.use(
|
||||
(response) => {
|
||||
if (response.data.code) {
|
||||
handleError(response.data)
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
return response
|
||||
},
|
||||
(error) => {
|
||||
const errorResponse = error.response.data as ErrorResponse
|
||||
let errorResponse: ErrorResponse;
|
||||
if (Array.isArray(error.response.data)) {
|
||||
const errorResponseList = error.response.data as ErrorResponseList;
|
||||
errorResponse = errorResponseList[0];
|
||||
} else {
|
||||
// 否则,将其视为单个 ErrorResponse
|
||||
errorResponse = error.response.data as ErrorResponse;
|
||||
}
|
||||
handleError(errorResponse)
|
||||
return Promise.reject(errorResponse)
|
||||
}
|
||||
@@ -43,8 +47,8 @@ export default {
|
||||
const response = await client.post<T>(url, data)
|
||||
return response.data as T
|
||||
},
|
||||
delete: async (url: string) => {
|
||||
await client.delete(url)
|
||||
delete: async (url: string,params?:any) => {
|
||||
await client.delete(url,{params})
|
||||
},
|
||||
put: async <T>(url: string, data: Record<string, any> = {}) => {
|
||||
const response = await client.put<T>(url, data)
|
||||
|
||||
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
// @ts-nocheck
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
// Generated by unplugin-auto-import
|
||||
// biome-ignore lint: disable
|
||||
export {}
|
||||
declare global {
|
||||
const EffectScope: typeof import('vue')['EffectScope']
|
||||
const computed: typeof import('vue')['computed']
|
||||
const createApp: typeof import('vue')['createApp']
|
||||
const customRef: typeof import('vue')['customRef']
|
||||
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
||||
const defineComponent: typeof import('vue')['defineComponent']
|
||||
const effectScope: typeof import('vue')['effectScope']
|
||||
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
||||
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
||||
const h: typeof import('vue')['h']
|
||||
const inject: typeof import('vue')['inject']
|
||||
const isProxy: typeof import('vue')['isProxy']
|
||||
const isReactive: typeof import('vue')['isReactive']
|
||||
const isReadonly: typeof import('vue')['isReadonly']
|
||||
const isRef: typeof import('vue')['isRef']
|
||||
const markRaw: typeof import('vue')['markRaw']
|
||||
const nextTick: typeof import('vue')['nextTick']
|
||||
const onActivated: typeof import('vue')['onActivated']
|
||||
const onBeforeMount: typeof import('vue')['onBeforeMount']
|
||||
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
|
||||
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
|
||||
const onDeactivated: typeof import('vue')['onDeactivated']
|
||||
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
|
||||
const onMounted: typeof import('vue')['onMounted']
|
||||
const onRenderTracked: typeof import('vue')['onRenderTracked']
|
||||
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
|
||||
const onScopeDispose: typeof import('vue')['onScopeDispose']
|
||||
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
|
||||
const onUnmounted: typeof import('vue')['onUnmounted']
|
||||
const onUpdated: typeof import('vue')['onUpdated']
|
||||
const onWatcherCleanup: typeof import('vue')['onWatcherCleanup']
|
||||
const provide: typeof import('vue')['provide']
|
||||
const reactive: typeof import('vue')['reactive']
|
||||
const readonly: typeof import('vue')['readonly']
|
||||
const ref: typeof import('vue')['ref']
|
||||
const resolveComponent: typeof import('vue')['resolveComponent']
|
||||
const shallowReactive: typeof import('vue')['shallowReactive']
|
||||
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
||||
const shallowRef: typeof import('vue')['shallowRef']
|
||||
const toRaw: typeof import('vue')['toRaw']
|
||||
const toRef: typeof import('vue')['toRef']
|
||||
const toRefs: typeof import('vue')['toRefs']
|
||||
const toValue: typeof import('vue')['toValue']
|
||||
const triggerRef: typeof import('vue')['triggerRef']
|
||||
const unref: typeof import('vue')['unref']
|
||||
const useAttrs: typeof import('vue')['useAttrs']
|
||||
const useCssModule: typeof import('vue')['useCssModule']
|
||||
const useCssVars: typeof import('vue')['useCssVars']
|
||||
const useId: typeof import('vue')['useId']
|
||||
const useModel: typeof import('vue')['useModel']
|
||||
const useSlots: typeof import('vue')['useSlots']
|
||||
const useTemplateRef: typeof import('vue')['useTemplateRef']
|
||||
const watch: typeof import('vue')['watch']
|
||||
const watchEffect: typeof import('vue')['watchEffect']
|
||||
const watchPostEffect: typeof import('vue')['watchPostEffect']
|
||||
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
|
||||
}
|
||||
// for type re-export
|
||||
declare global {
|
||||
// @ts-ignore
|
||||
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
|
||||
import('vue')
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import { MessagePlugin, type UploadProps } from 'tdesign-vue-next'
|
||||
import { ref, watch } 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){
|
||||
console.log(file1.value,'file1')
|
||||
emits('on-success',file.url)
|
||||
}
|
||||
}
|
||||
const appStore = useAppStore()
|
||||
|
||||
const uploadHeaders = ref<UploadProps['headers']>({
|
||||
Authorization: `Bearer ${appStore.token}`
|
||||
})
|
||||
const props = defineProps({
|
||||
imageUrl:{
|
||||
type:Object,
|
||||
default:() => {
|
||||
return { url: '' }
|
||||
}
|
||||
}
|
||||
})
|
||||
const emits = defineEmits(['on-success'])
|
||||
watch(() => props.imageUrl,(newVal) => {
|
||||
if(newVal){
|
||||
if(newVal.url !== ''){
|
||||
file1.value = [{ ...newVal }]
|
||||
}else{
|
||||
file1.value = []
|
||||
}
|
||||
}
|
||||
},{
|
||||
deep:true,
|
||||
immediate:true
|
||||
})
|
||||
</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>
|
||||
@@ -15,9 +15,9 @@ export const useSearchable = <T extends BaseFilterRequest, D extends BaseModel>(
|
||||
loading.value = true
|
||||
const result = await api({...filter.value, page: pagination.page, size: pagination.size, ...defaultFilter})
|
||||
data.value = result.data
|
||||
pagination.page = result.paging.page
|
||||
pagination.size = result.paging.size
|
||||
pagination.total = result.paging.total
|
||||
pagination.page = result.pagination.page
|
||||
pagination.size = result.pagination.size
|
||||
pagination.total = result.pagination.total
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -5,7 +5,7 @@ export interface ErrorResponse {
|
||||
message: string;
|
||||
}
|
||||
export interface BaseModel {
|
||||
id: number
|
||||
id: string
|
||||
createdTime: string
|
||||
updateTime: string
|
||||
}
|
||||
@@ -25,6 +25,8 @@ export interface BaseFilterRequest extends Partial<Paging>{
|
||||
}
|
||||
|
||||
export interface PageResult<T> {
|
||||
paging: Paging,
|
||||
pagination: Paging,
|
||||
data: T[]
|
||||
}
|
||||
|
||||
export interface ErrorResponseList extends Array<ErrorResponse> {}
|
||||
@@ -0,0 +1,12 @@
|
||||
export interface CreateCarousalsRequest {
|
||||
imageUrl:string,
|
||||
targetType:string,
|
||||
targetUrl?:string,
|
||||
targetId?:string
|
||||
}
|
||||
export interface GetCarousalsRequest {
|
||||
page:number,
|
||||
size:number,
|
||||
order?:[string]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { AuditBaseModel,Paging } from '@/model/base'
|
||||
|
||||
|
||||
export interface Category extends AuditBaseModel{
|
||||
name: string
|
||||
code:string
|
||||
order: number
|
||||
}
|
||||
|
||||
|
||||
export interface CategorySearchFilter extends Partial<Paging>{
|
||||
order?: string
|
||||
}
|
||||
|
||||
|
||||
export interface UpdateCategoryRequest{
|
||||
name: string
|
||||
code:string
|
||||
order: number
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { BaseModel } from '@/model/base'
|
||||
|
||||
export interface Classify extends BaseModel{
|
||||
numbering:string
|
||||
name: string
|
||||
sort: string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
width="70%"
|
||||
:header="header"
|
||||
:confirmBtn="confirmBtn"
|
||||
:closeOnOverlayClick="false"
|
||||
@close="handleCloseDialog"
|
||||
@confirm="fetchSaveCarousalData"
|
||||
>
|
||||
<t-space direction="vertical" style="width: 100%">
|
||||
<TForm ref="form" :data="carousalData" :rules="rules" resetType="initial" label-width="100">
|
||||
<TFormItem label="轮播图:" name="imageUrl">
|
||||
<ImageUpload @on-success="handleSuccessImg" :image-url="imgUrl"/>
|
||||
</TFormItem>
|
||||
<TFormItem label="跳转类型:" name="targetType" >
|
||||
<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 label="跳转文章路径:" name="targetId" v-if="carousalData.targetType === 'article' ">
|
||||
<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>
|
||||
</TForm>
|
||||
</t-space>
|
||||
</t-dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, reactive, watch } from 'vue'
|
||||
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
||||
import ImageUpload from '@/components/ImageUpload.vue'
|
||||
import { createCarousal, updateCarousalItem } from '@/api/carousal'
|
||||
const props = defineProps<{
|
||||
isEdit?: Boolean | null
|
||||
headerTitle?: String | null
|
||||
carousal: {} | number
|
||||
}>()
|
||||
const emit = defineEmits(['success'])
|
||||
const form = ref<FormInstanceFunctions | null>(null)
|
||||
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
||||
const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
||||
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
|
||||
const carousalData: FormProps['data'] = ref({})
|
||||
const imgUrl = ref({})
|
||||
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.value.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 handleSuccessImg = (res:string) => {
|
||||
console.log(res,'图片地址')
|
||||
carousalData.value.imageUrl = res
|
||||
}
|
||||
const typeOption = reactive([
|
||||
{ value: 'article', label: '文章' },
|
||||
{ value: 'url', label: '地址' },
|
||||
])
|
||||
const handleFormTypeData = () => {
|
||||
if (carousalData.value.targetType === 'article') {
|
||||
delete carousalData.value.targetUrl
|
||||
} else if (carousalData.value.targetType === 'url') {
|
||||
delete carousalData.value.targetId
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.carousal,
|
||||
(newClassify) => {
|
||||
carousalData.value = Object.assign({}, newClassify)
|
||||
const carousalObj = Object.assign({},newClassify)
|
||||
// imgUrl.value.url = carousalObj.imageUrl || ''
|
||||
imgUrl.value = { url: carousalObj.imageUrl || '' }
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
},
|
||||
)
|
||||
const fetchSaveCarousalData = async () => {
|
||||
/* TODO: 保存分类数据 */
|
||||
if (form.value) {
|
||||
const valid = await form.value.validate()
|
||||
// console.log(valid,'valid')
|
||||
if (valid && typeof valid === 'boolean') {
|
||||
/* TODO: 校验通过保存分类数据 */
|
||||
handleFormTypeData()
|
||||
// console.log(formType.value,'formType')
|
||||
let res
|
||||
switch (formType.value){
|
||||
case 'create':
|
||||
res = await createCarousal(carousalData.value)
|
||||
emit('success')
|
||||
break;
|
||||
case 'update':
|
||||
const fieldsToKeep = ["imageUrl", "targetType", "targetUrl", "targetId"];
|
||||
const requestObj = {};
|
||||
|
||||
for (const field of fieldsToKeep) {
|
||||
if (carousalData.value[field]!== null && carousalData.value[field]!== undefined) {
|
||||
requestObj[field] = carousalData.value[field];
|
||||
}
|
||||
}
|
||||
handleFormTypeData()
|
||||
res = await updateCarousalItem(carousalData.value.id,requestObj)
|
||||
emit('success')
|
||||
break;
|
||||
default:
|
||||
res = await createCarousal(carousalData.value)
|
||||
emit('success')
|
||||
break;
|
||||
}
|
||||
// const createCarousalApi = createCarousal(carousalData.value)
|
||||
// console.log(createCarousalApi,'createCarousalApi')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
const handleCloseDialog = () => {
|
||||
// 数据&&规则校验结果重置
|
||||
if (form.value) {
|
||||
form.value.reset()
|
||||
form.value.clearValidate()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,207 @@
|
||||
<script setup lang="ts">
|
||||
import RegularPage from '@/components/RegularPage.vue'
|
||||
import { onMounted, ref, reactive } from 'vue'
|
||||
import type { BaseTableColumns } from 'tdesign-vue-next'
|
||||
import CarousalDialog from '@/pages/carousal/components/CarousalDialog.vue'
|
||||
import { activeCarousal, deleteCarousal, getCarousalList, inactiveCarousal } from '@/api/carousal'
|
||||
import { BrowseIcon } from 'tdesign-icons-vue-next'
|
||||
|
||||
const columns: BaseTableColumns = [
|
||||
{
|
||||
title: 'ID',
|
||||
colKey: 'id',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '轮播图',
|
||||
colKey: 'imageUrl',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '显示状态',
|
||||
colKey: 'status',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
colKey: 'operation',
|
||||
width: 100,
|
||||
}
|
||||
]
|
||||
const loading = ref(false)
|
||||
const data = ref([])
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
size: 10,
|
||||
total:0
|
||||
})
|
||||
const query = reactive({
|
||||
page:1,
|
||||
size:10,
|
||||
})
|
||||
const carousalDialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const currentTableData = ref<{}>({})
|
||||
const fetchSaveCarousalData = async () => {
|
||||
/* TODO: 获取轮播图表格数据 */
|
||||
query.page = pagination.page
|
||||
query.size = pagination.size
|
||||
const getCarousalListApi = await getCarousalList(query)
|
||||
data.value = getCarousalListApi.data
|
||||
pagination.total = getCarousalListApi.pagination.total
|
||||
}
|
||||
onMounted(fetchSaveCarousalData)
|
||||
const editClick = (row:object) => {
|
||||
isEdit.value = true
|
||||
currentTableData.value = Object.assign({}, row)
|
||||
carousalDialogVisible.value = true
|
||||
}
|
||||
const showClick = async (res:object) => {
|
||||
if (res.status === 'active'){
|
||||
await inactiveCarousal(res.id)
|
||||
} else {
|
||||
await activeCarousal(res.id)
|
||||
}
|
||||
await fetchSaveCarousalData()
|
||||
}
|
||||
const delClick = async (row:object) => {
|
||||
console.log(row,'删除')
|
||||
await deleteCarousal(row.id)
|
||||
await fetchSaveCarousalData()
|
||||
}
|
||||
const handleCreateCarousal = () => {
|
||||
isEdit.value = false
|
||||
carousalDialogVisible.value = true
|
||||
currentTableData.value = {}
|
||||
}
|
||||
const onPageChange = () => {
|
||||
/* TODO: 分页切换 */
|
||||
}
|
||||
const handleSuccessDialog = async () => {
|
||||
await fetchSaveCarousalData()
|
||||
carousalDialogVisible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RegularPage title="轮播图管理">
|
||||
<template #right-area>
|
||||
<TButton @click="handleCreateCarousal">创建轮播图</TButton>
|
||||
</template>
|
||||
<TTable
|
||||
class="w-full h-full"
|
||||
row-key="id"
|
||||
height="92%"
|
||||
table-layout="auto"
|
||||
:data="data"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
cell-empty-content="-"
|
||||
:paginationAffixedBottom="true"
|
||||
:pagination="{
|
||||
total: pagination.total,
|
||||
current: pagination.page,
|
||||
pageSize: pagination.size,
|
||||
onChange: onPageChange
|
||||
}"
|
||||
>
|
||||
<template #imageUrl="{row}">
|
||||
<div class="tdesign-demo-image-viewer__base">
|
||||
<t-image-viewer :images="[row.imageUrl]">
|
||||
<template #trigger="{ open }">
|
||||
<div class="tdesign-demo-image-viewer__ui-image">
|
||||
<img alt="test" :src="row.imageUrl" class="tdesign-demo-image-viewer__ui-image--img" />
|
||||
<div class="tdesign-demo-image-viewer__ui-image--hover" @click="open">
|
||||
<span><BrowseIcon size="1.4em" /> 预览</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-image-viewer>
|
||||
</div>
|
||||
</template>
|
||||
<template #status="{row}">
|
||||
<TSpace>
|
||||
<TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{row.status === 'active' ? '显示中' : '已关闭'}}</TTag>
|
||||
</TSpace>
|
||||
</template>
|
||||
<template #roles="{ row }">
|
||||
<TSpace>
|
||||
<TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
|
||||
role.label
|
||||
}}</TTag>
|
||||
</TSpace>
|
||||
</template>
|
||||
<template #operation="{ row }">
|
||||
<TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
|
||||
<TButton variant="text" size="small" theme="primary" @click="showClick(row)">{{ row.status === 'active' ? '关闭显示' : '开启显示'}}</TButton>
|
||||
<TButton variant="text" size="small" theme="danger" @click="delClick(row)">删除</TButton>
|
||||
</template>
|
||||
</TTable>
|
||||
<CarousalDialog
|
||||
:carousal="currentTableData"
|
||||
v-model:visible="carousalDialogVisible"
|
||||
:isEdit="isEdit"
|
||||
@success="handleSuccessDialog"
|
||||
headerTitle="轮播图"
|
||||
></CarousalDialog>
|
||||
</RegularPage>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.t-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.tdesign-demo-image-viewer__ui-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: inline-flex;
|
||||
position: relative;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: var(--td-radius-small);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tdesign-demo-image-viewer__ui-image--hover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
opacity: 0;
|
||||
background-color: rgba(0, 0, 0, 0.6);
|
||||
color: var(--td-text-color-anti);
|
||||
line-height: 22px;
|
||||
transition: 0.2s;
|
||||
}
|
||||
|
||||
.tdesign-demo-image-viewer__ui-image:hover .tdesign-demo-image-viewer__ui-image--hover {
|
||||
opacity: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tdesign-demo-image-viewer__ui-image--img {
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
|
||||
.tdesign-demo-image-viewer__ui-image--icons .tdesign-demo-icon {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tdesign-demo-image-viewer__base {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: 4px solid var(--td-bg-color-secondarycontainer);
|
||||
border-radius: var(--td-radius-medium);
|
||||
}
|
||||
</style>
|
||||
+36
-18
@@ -5,36 +5,45 @@
|
||||
:confirmBtn="confirmBtn"
|
||||
:closeOnOverlayClick="false"
|
||||
@close="handleCloseDialog"
|
||||
@confirm="fetchSaveClassifyData"
|
||||
@confirm="SaveCategoryData"
|
||||
>
|
||||
<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个汉字">
|
||||
<t-input v-model.trim="classifyData.name" clearable placeholder="请输入分类名称" />
|
||||
<t-input v-model.trim="categoryData.name" clearable placeholder="请输入分类名称" />
|
||||
</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 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>
|
||||
</TForm>
|
||||
</t-space>
|
||||
</t-dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import type { Classify } from '@/model/classify'
|
||||
import type { Category } from '@/model/category'
|
||||
import { computed, ref, reactive, watch } from 'vue'
|
||||
import { createCategoryRequest, updateCategoryByIdRequest } from '@/api/category'
|
||||
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
const props = defineProps<{
|
||||
isEdit?: Boolean | null
|
||||
headerTitle?: String | null
|
||||
classify: Classify | {}
|
||||
category: Category | {}
|
||||
}>()
|
||||
const form = ref<FormInstanceFunctions | null>(null)
|
||||
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
||||
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'] = {
|
||||
name: [
|
||||
{
|
||||
@@ -66,7 +75,7 @@ const rules: FormProps['rules'] = {
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
numbering: [
|
||||
code: [
|
||||
{
|
||||
required: true,
|
||||
message: '分类编号不能为空',
|
||||
@@ -96,7 +105,7 @@ const rules: FormProps['rules'] = {
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
sort: [
|
||||
order: [
|
||||
{
|
||||
required: true,
|
||||
message: '排序级别不能为空',
|
||||
@@ -122,18 +131,27 @@ const rules: FormProps['rules'] = {
|
||||
]
|
||||
}
|
||||
watch(
|
||||
() => props.classify,
|
||||
(newClassify) => {
|
||||
Object.assign(classifyData, newClassify)
|
||||
() => props.category,
|
||||
(newCategory) => {
|
||||
Object.assign(categoryData, newCategory)
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
const fetchSaveClassifyData = async () => {
|
||||
/* TODO: 保存分类数据 */
|
||||
const emit = defineEmits<{
|
||||
success: [void]
|
||||
}>()
|
||||
const SaveCategoryData = async () => {
|
||||
if (form.value) {
|
||||
const valid = await form.value.validate()
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import type { Category, CategorySearchFilter } from '@/model/category'
|
||||
import RegularPage from '@/components/RegularPage.vue'
|
||||
import { searchCategoryRequest, deleteCategoryRequest } from '@/api/category'
|
||||
import type { BaseTableColumns } from 'tdesign-vue-next'
|
||||
import { useSearchable } from '@/composables/useSearchable'
|
||||
import CategoryDialog from '@/pages/category/components/CategoryDialog.vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
|
||||
const { data, loading, pagination, onPageChange, fetchData } = useSearchable<
|
||||
CategorySearchFilter,
|
||||
Category
|
||||
>(searchCategoryRequest)
|
||||
const columns: BaseTableColumns = [
|
||||
{
|
||||
title: '分类名称',
|
||||
colKey: 'name',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '分类编号',
|
||||
colKey: 'code',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
colKey: 'order',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
colKey: 'operation',
|
||||
width: 100
|
||||
}
|
||||
]
|
||||
const categoryDialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const currentTableData = ref<Category | {}>({})
|
||||
onMounted(fetchData)
|
||||
const editClick = (category: Category) => {
|
||||
isEdit.value = true
|
||||
currentTableData.value = category
|
||||
categoryDialogVisible.value = true
|
||||
}
|
||||
const handleCategoryDialogSuccess = () => {
|
||||
fetchData()
|
||||
categoryDialogVisible.value = false
|
||||
}
|
||||
const handleCategoryDialogClosed = () => {
|
||||
isEdit.value = false
|
||||
currentTableData.value = {}
|
||||
}
|
||||
const deleteCategoryClick = async (id: string) => {
|
||||
await deleteCategoryRequest(id)
|
||||
fetchData()
|
||||
MessagePlugin.success('删除分类成功')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RegularPage title="分类管理">
|
||||
<template #right-area>
|
||||
<TButton @click="categoryDialogVisible = true">创建分类</TButton>
|
||||
</template>
|
||||
<TTable
|
||||
class="w-full h-full"
|
||||
row-key="id"
|
||||
height="92%"
|
||||
table-layout="auto"
|
||||
:data="data"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
cell-empty-content="-"
|
||||
:paginationAffixedBottom="true"
|
||||
:pagination="{
|
||||
total: pagination.total,
|
||||
current: pagination.page,
|
||||
pageSize: pagination.size,
|
||||
onChange: onPageChange
|
||||
}"
|
||||
>
|
||||
<template #operation="{ row }">
|
||||
<TSpace :size="1">
|
||||
<TButton variant="text" size="small" theme="primary" @click="editClick(row)"
|
||||
>编辑</TButton
|
||||
>
|
||||
<t-popconfirm
|
||||
theme="default"
|
||||
content="确认删除此项分类吗"
|
||||
@confirm="deleteCategoryClick(row.id)"
|
||||
>
|
||||
<TButton variant="text" size="small" theme="danger">删除</TButton>
|
||||
</t-popconfirm>
|
||||
</TSpace>
|
||||
</template>
|
||||
</TTable>
|
||||
<CategoryDialog
|
||||
headerTitle="分类"
|
||||
:isEdit="isEdit"
|
||||
:category="currentTableData"
|
||||
v-model:visible="categoryDialogVisible"
|
||||
@closed="handleCategoryDialogClosed"
|
||||
@success="handleCategoryDialogSuccess"
|
||||
></CategoryDialog>
|
||||
</RegularPage>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.t-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,107 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import RegularPage from '@/components/RegularPage.vue'
|
||||
import { onMounted, ref, reactive } from 'vue'
|
||||
import type { BaseTableColumns } from 'tdesign-vue-next'
|
||||
import type { Classify } from '@/model/classify'
|
||||
import ClassifyDialog from '@/pages/classify/components/ClassifyDialog.vue'
|
||||
|
||||
const columns: BaseTableColumns = [
|
||||
{
|
||||
title: '分类名称',
|
||||
colKey: 'name',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '分类编号',
|
||||
colKey: 'numbering',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
colKey: 'sort',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
colKey: 'operation',
|
||||
width: 100
|
||||
}
|
||||
]
|
||||
const loading = ref(false)
|
||||
const data = ref(
|
||||
Array.from({ length: 1 })
|
||||
.fill({ id: '1', name: '趣味科普', numbering: 'enjoy', sort: '1' })
|
||||
.map((item) => item)
|
||||
)
|
||||
const pagination = reactive({
|
||||
total: 1,
|
||||
page: 1,
|
||||
size: 10
|
||||
})
|
||||
const classifyDialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const currentTableData = ref<Classify | {}>({})
|
||||
const fetchClassifyTableData = () => {
|
||||
/* TODO: 获取分类表格数据 */
|
||||
}
|
||||
onMounted(fetchClassifyTableData)
|
||||
const editClick = (classify: Classify) => {
|
||||
isEdit.value = true
|
||||
currentTableData.value = classify
|
||||
console.log(classify)
|
||||
|
||||
classifyDialogVisible.value = true
|
||||
}
|
||||
const onPageChange = () => {
|
||||
/* TODO: 分页切换 */
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RegularPage title="分类管理">
|
||||
<template #right-area>
|
||||
<TButton @click="classifyDialogVisible = true">创建分类</TButton>
|
||||
</template>
|
||||
<TTable
|
||||
class="w-full h-full"
|
||||
row-key="id"
|
||||
height="92%"
|
||||
table-layout="auto"
|
||||
:data="data"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
cell-empty-content="-"
|
||||
:paginationAffixedBottom="true"
|
||||
:pagination="{
|
||||
total: pagination.total,
|
||||
current: pagination.page,
|
||||
pageSize: pagination.size,
|
||||
onChange: onPageChange
|
||||
}"
|
||||
>
|
||||
<template #roles="{ row }">
|
||||
<TSpace>
|
||||
<TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
|
||||
role.label
|
||||
}}</TTag>
|
||||
</TSpace>
|
||||
</template>
|
||||
<template #operation="{ row }">
|
||||
<TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
|
||||
</template>
|
||||
</TTable>
|
||||
<ClassifyDialog
|
||||
:classify="currentTableData"
|
||||
v-model:visible="classifyDialogVisible"
|
||||
:isEdit="isEdit"
|
||||
headerTitle="分类"
|
||||
></ClassifyDialog>
|
||||
</RegularPage>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.t-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -20,6 +20,7 @@ const handleLogin = async () => {
|
||||
return
|
||||
}
|
||||
try {
|
||||
loading.value = true
|
||||
await appStore.login(loginForm)
|
||||
} finally {
|
||||
loading.value = false
|
||||
|
||||
+13
-4
@@ -6,14 +6,23 @@ import Layout from '@/layouts/Layout.vue'
|
||||
|
||||
export const asyncRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'classify',
|
||||
path: 'classify',
|
||||
component: () => import('@/pages/classify/index.vue'),
|
||||
name: 'category',
|
||||
path: 'category',
|
||||
component: () => import('@/pages/category/index.vue'),
|
||||
meta: {
|
||||
title: '分类管理',
|
||||
icon: 'system-3'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'carousal',
|
||||
path: 'carousal',
|
||||
component: () => import('@/pages/carousal/index.vue'),
|
||||
meta: {
|
||||
title: '轮播图管理',
|
||||
icon: 'system-3'
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
@@ -24,7 +33,7 @@ const router = createRouter({
|
||||
component: Layout,
|
||||
path: '/',
|
||||
redirect: {
|
||||
name: 'classify'
|
||||
name: 'category'
|
||||
},
|
||||
children: asyncRoutes
|
||||
},
|
||||
|
||||
@@ -14,6 +14,10 @@ export default defineConfig(({ command, mode }) => {
|
||||
return {
|
||||
plugins: [
|
||||
vue(),
|
||||
AutoImport({
|
||||
imports:['vue'],
|
||||
dts:"src/auto-import.d.ts" // 会自动生成此文件
|
||||
}),
|
||||
vueDevTools(),
|
||||
AutoImport({
|
||||
resolvers: [
|
||||
|
||||
Reference in new issue
Block a user