diff --git a/src/api/index.ts b/src/api/index.ts index 800d80f..04b74cf 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,10 +1,12 @@ import request from '@/utils/request' import login from './login' import commodity from './commodity' +import resource from './resource' const totalApiConfig = { login, - commodity + commodity, + resource } Object.values(totalApiConfig).forEach((apiConfig) => { diff --git a/src/api/resource.ts b/src/api/resource.ts new file mode 100644 index 0000000..490df97 --- /dev/null +++ b/src/api/resource.ts @@ -0,0 +1,12 @@ +const resource = { + /** + * 资源列表 + */ + getResourceList: ['/resource/list'], // 获取资源列表 + uploadFile: ['/upload/file', { headers: { 'Content-Type': 'multipart/form-data' } }], // 上传文件 + addOrEditResource: ['/resource/addOrUpdate'], // 新增和编辑资源 + sortResource: ['/resource/sort'], // 资源排序 + deleteResource: ['/resource/delete'] // 资源删除 +} + +export default resource diff --git a/src/auto-import.d.ts b/src/auto-import.d.ts index 634a50d..700add6 100644 --- a/src/auto-import.d.ts +++ b/src/auto-import.d.ts @@ -6,77 +6,95 @@ // biome-ignore lint: disable export {} declare global { - const EffectScope: typeof import('vue')['EffectScope'] - const api: typeof import('../../../../../../src/api/index')['api'] - 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 getCurrentWatcher: typeof import('vue')['getCurrentWatcher'] - const h: typeof import('vue')['h'] - const handleInit: typeof import('../../../../../../src/utils/page/index')['handleInit'] - const handleMessageBox: typeof import('../../../../../../src/utils/page/index')['handleMessageBox'] - 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 isShallow: typeof import('vue')['isShallow'] - 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 onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave'] - const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate'] - 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 pageConfig: typeof import('../../../../../../src/utils/page/config')['pageConfig'] - 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 useLink: typeof import('vue-router')['useLink'] - const useModel: typeof import('vue')['useModel'] - const useRoute: typeof import('vue-router')['useRoute'] - const useRouter: typeof import('vue-router')['useRouter'] - 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'] + const EffectScope: (typeof import('vue'))['EffectScope'] + const api: (typeof import('src/api/index'))['api'] + 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 getCurrentWatcher: (typeof import('vue'))['getCurrentWatcher'] + const h: (typeof import('vue'))['h'] + const handleInit: (typeof import('src/utils/page/index'))['handleInit'] + const handleMessageBox: (typeof import('src/utils/page/index'))['handleMessageBox'] + 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 isShallow: (typeof import('vue'))['isShallow'] + 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 onBeforeRouteLeave: (typeof import('vue-router'))['onBeforeRouteLeave'] + const onBeforeRouteUpdate: (typeof import('vue-router'))['onBeforeRouteUpdate'] + 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 pageConfig: (typeof import('src/utils/page/config'))['pageConfig'] + 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 useLink: (typeof import('vue-router'))['useLink'] + const useModel: (typeof import('vue'))['useModel'] + const useRoute: (typeof import('vue-router'))['useRoute'] + const useRouter: (typeof import('vue-router'))['useRouter'] + 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, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, ShallowRef, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' + export type { + Component, + Slot, + Slots, + ComponentPublicInstance, + ComputedRef, + DirectiveBinding, + ExtractDefaultPropTypes, + ExtractPropTypes, + ExtractPublicPropTypes, + InjectionKey, + PropType, + Ref, + ShallowRef, + MaybeRef, + MaybeRefOrGetter, + VNode, + WritableComputedRef + } from 'vue' import('vue') } diff --git a/src/utils/page/index.ts b/src/utils/page/index.ts index daadee2..a7f463d 100644 --- a/src/utils/page/index.ts +++ b/src/utils/page/index.ts @@ -55,14 +55,14 @@ export const getTableData = ( .$api(params) .then((res) => { const result = res as { - data: {}[] + data: { rows: [] } code: string resultMsg: string - totalRows: number + totalPage: number } table.$loading = false - table.$data = result.data - table.$pages.total = result.totalRows + table.$data = result.data.rows + table.$pages.total = result.totalPage }) .catch(() => { table.$loading = false diff --git a/src/utils/request.ts b/src/utils/request.ts index 4c874f8..5e4c689 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -55,7 +55,7 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( (response: AxiosResponse) => { - if ([200].includes(response.data.code) || response.config.third) { + if (['200'].includes(response.data.code) || response.config.third) { return response.data } else { if (response.data.code === 401) { diff --git a/src/views/goods/commodity/index.vue b/src/views/goods/commodity/index.vue index 711f595..047a705 100644 --- a/src/views/goods/commodity/index.vue +++ b/src/views/goods/commodity/index.vue @@ -59,5 +59,5 @@ const { commodityType, onChangeCommodityType, commodityTypeOptions } = useCommod onChangeCommodityType(commodityType.value) /** 页面缓存 */ -defineOptions({ name: 'supplier-config' }) +defineOptions({ name: 'Commodity' }) diff --git a/src/views/goods/home-goods/index.vue b/src/views/goods/home-goods/index.vue index 9ccf76e..fa012f5 100644 --- a/src/views/goods/home-goods/index.vue +++ b/src/views/goods/home-goods/index.vue @@ -49,5 +49,5 @@ setTimeout(() => { }, 2000) /** 页面缓存 */ -defineOptions({ name: 'supplier-config' }) +defineOptions({ name: 'HomeGoods' }) diff --git a/src/views/resource/list copy/index.vue b/src/views/resource/list copy/index.vue new file mode 100644 index 0000000..875c4bd --- /dev/null +++ b/src/views/resource/list copy/index.vue @@ -0,0 +1,131 @@ + + + 资源展示: + + + + {{ data.fileName }} + + + 编辑 + 添加 + + 删除 + + + + + + + + + + + diff --git a/src/views/resource/list copy/mock.ts b/src/views/resource/list copy/mock.ts new file mode 100644 index 0000000..8deede7 --- /dev/null +++ b/src/views/resource/list copy/mock.ts @@ -0,0 +1,162 @@ +interface Tree { + id: number + resourceUrl: string + type: string + fileName: string + defaultSort: number + children?: Tree[] +} +interface OriginDataItem { + id: number + resourceUrl: string + fileName: string + type: string + defaultSort: number + parentId?: number +} + +export const originData: OriginDataItem[] = [ + { + id: 12, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 10, + defaultSort: 2 + }, + { + id: 78, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 77, + defaultSort: 1 + }, + { + id: 80, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 78, + defaultSort: 4 + }, + { + id: 82, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 81, + defaultSort: 1 + }, + { + id: 84, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 83, + defaultSort: 1 + }, + { + id: 86, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 85, + defaultSort: 1 + }, + { + id: 88, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 87, + defaultSort: 1 + }, + { + id: 90, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 89, + defaultSort: 1 + }, + { + id: 92, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 91, + defaultSort: 1 + }, + { + id: 94, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 93, + defaultSort: 1 + } +] + +/** + * 将 originData 转换为 dataSource 的树形结构 + * @param data 原始数据数组 + * @returns 转换后的树形结构数据 + */ +export function transformToTreeData(data: OriginDataItem[]): Tree[] { + // 创建映射表,用于快速查找 + const itemMap = new Map() + const result: Tree[] = [] + + // 首先创建所有节点 + data.forEach((item) => { + itemMap.set(item.id, { + id: item.id, + resourceUrl: item.resourceUrl, + type: item.type, + fileName: item.fileName, + defaultSort: item.defaultSort, + children: [] + }) + }) + + // 构建树形结构 + data.forEach((item) => { + const treeNode = itemMap.get(item.id)! + + if (item.parentId) { + const parentNode = itemMap.get(item.parentId) + if (parentNode) { + parentNode.children!.push(treeNode) + } else { + // 如果找不到父节点,作为根节点处理 + result.push(treeNode) + } + } else { + // 没有父节点,作为根节点 + result.push(treeNode) + } + }) + + // 递归排序函数 + function sortChildren(node: Tree) { + if (node.children && node.children.length > 0) { + // 重新排列 children + node.children = node.children.sort((a, b) => a.defaultSort - b.defaultSort) + + // 递归处理子节点 + node.children.forEach((child) => sortChildren(child)) + } + } + + // 重新排列根节点 + const sortedResult = result.sort((a, b) => a.defaultSort - b.defaultSort) + + // 递归排序所有子节点 + sortedResult.forEach((node) => sortChildren(node)) + + return sortedResult +} + +// 使用示例 +export const transformedDataSource = ref(transformToTreeData(originData)) diff --git a/src/views/resource/list copy/use-drag.ts b/src/views/resource/list copy/use-drag.ts new file mode 100644 index 0000000..1c0ad62 --- /dev/null +++ b/src/views/resource/list copy/use-drag.ts @@ -0,0 +1,39 @@ +import type { DragEvents } from 'element-plus/es/components/tree/src/model/useDragNode' +import type { NodeDropType, RenderContentContext } from 'element-plus' + +type Node = RenderContentContext['node'] + +// 开始拖拽 +export const handleDragStart = (node: Node, ev: DragEvents) => { + console.log('drag start', node) +} +// 拖拽进入其他节点时触发的事件 +export const handleDragEnter = (draggingNode: Node, dropNode: Node, ev: DragEvents) => { + console.log('tree drag enter:', dropNode.label) +} +// 拖拽离开某个节点时触发的事件 +export const handleDragLeave = (draggingNode: Node, dropNode: Node, ev: DragEvents) => { + console.log('tree drag leave:', dropNode.label) +} +// 在拖拽节点时触发的事件(类似浏览器的 mouseover 事件) +export const handleDragOver = (draggingNode: Node, dropNode: Node, ev: DragEvents) => { + console.log('tree drag over:', dropNode.label) +} +// 拖拽结束时(可能未成功)触发的事件 +export const handleDragEnd = ( + draggingNode: Node, + dropNode: Node, + dropType: NodeDropType, + ev: DragEvents +) => { + console.log('tree drag end:', dropNode && dropNode.label, dropType) +} +// 拖拽成功完成时触发的事件 +export const handleDrop = ( + draggingNode: Node, + dropNode: Node, + dropType: NodeDropType, + ev: DragEvents +) => { + console.log('tree drop:', dropNode.label, dropType) +} diff --git a/src/views/resource/list/config.ts b/src/views/resource/list/config.ts new file mode 100644 index 0000000..ded5c3c --- /dev/null +++ b/src/views/resource/list/config.ts @@ -0,0 +1,33 @@ +import { handleData } from 'lz-utils-lib' +const configData = ref() +export const initConfig = () => { + configData.value = pageConfig({ + search: { + fileName: { label: '文件名称', clearable: true } + }, + table: { + selection: { width: 50 }, + fileName: { label: '文件名称', slot: 'fileName', width: 500 }, + pathname: { + label: '路径', + width: 160, + formatter: (row: any) => row.locations.map((item: any) => item.fileName).join('/') + }, + modifyTime: { + label: '修改时间', + width: 160, + formatter: (row: any) => handleData.formatTime(row.modifyTime, 'YYYY-MM-DD hh:mm:ss') + }, + btn: { + types: ['warning', 'danger', ''], + names: ['重命名', '删除', '跳转'], + width: 150 + } + }, + dialog: { + parentId: { label: '父级文件夹', slot: 'parentId' }, + files: { label: '上传文件', slot: 'files' } + } + }) + return configData +} diff --git a/src/views/resource/list/index.vue b/src/views/resource/list/index.vue index 6590afe..bdcc0ee 100644 --- a/src/views/resource/list/index.vue +++ b/src/views/resource/list/index.vue @@ -1,128 +1,328 @@ - - 类目展示: - - - - {{ data.label }} - - - 编辑 - 添加 - - 删除 - - - + + + + 新增文件夹 + 添加文件 + 移动 - + + + + + + + + {{ item.label }} + + > + + + + + + + + + + + + {{ + scope.row.fileName + }} + + + + + + + + + + + + + + + + + + + + - - diff --git a/src/views/resource/list/mock.ts b/src/views/resource/list/mock.ts index f169cfb..16fa94f 100644 --- a/src/views/resource/list/mock.ts +++ b/src/views/resource/list/mock.ts @@ -1,56 +1,91 @@ -interface Tree { +interface OriginDataItem { id: number - label: string - children?: Tree[] + resourceUrl: string + fileName: string + type: string + defaultSort: number + parentId?: number } -export const dataSource = ref([ +export const originData: OriginDataItem[] = [ { - id: 1, - label: 'Level one 1', - children: [ - { - id: 4, - label: 'Level two 1-1', - children: [ - { - id: 9, - label: 'Level three 1-1-1' - }, - { - id: 10, - label: 'Level three 1-1-2' - } - ] - } - ] + id: 12, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 10, + defaultSort: 2 }, { - id: 2, - label: 'Level one 2', - children: [ - { - id: 5, - label: 'Level two 2-1' - }, - { - id: 6, - label: 'Level two 2-2' - } - ] + id: 78, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 77, + defaultSort: 1 }, { - id: 3, - label: 'Level one 3', - children: [ - { - id: 7, - label: 'Level two 3-1' - }, - { - id: 8, - label: 'Level two 3-2' - } - ] + id: 80, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 78, + defaultSort: 4 + }, + { + id: 82, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 81, + defaultSort: 1 + }, + { + id: 84, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 83, + defaultSort: 1 + }, + { + id: 86, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 85, + defaultSort: 1 + }, + { + id: 88, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 87, + defaultSort: 1 + }, + { + id: 90, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 89, + defaultSort: 1 + }, + { + id: 92, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 91, + defaultSort: 1 + }, + { + id: 94, + resourceUrl: 'bbb', + type: 'image', + fileName: '张三', + parentId: 93, + defaultSort: 1 } -]) +]
资源展示:
类目展示:
+ + {{ item.label }} + + > +
+ + + +