UNPKG

vue-finder-senior

Version:

VueFinderSenior is a file manager component for vue3. And there are multiple adaptable backends available . like Python PHP Go Rust

273 lines (221 loc) 10.2 kB
## vue-finder-senior File Manager ## vue-finder-senior 文件管理器 [![GitHub](https://img.shields.io/github/license/n1crack/vuefinder)](https://github.com/n1crack/vuefinder/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/vuefinder)](https://www.npmjs.com/package/vuefinder) ### About Vuefinder is a file manager component for Vue.js version 3. vue-finder-senior 是Vue.js版本3的文件管理器组件,是在[Vuefinder](https://github.com/n1crack/vuefinder) 的基础上进行修改,新增更多按键自定义等功能。 ### Demo [Live Demo](https://vuefinder.ozdemir.be/) [ [Source](https://github.com/n1crack/vuefinder) ] ### Installation ```bash npm i vue-finder-senior ``` JS entry point (it can be index.js or main.js) ```js import { createApp } from 'vue' import App from './App.vue' import 'vuefinder/dist/style.css' import VueFinder from 'vuefinder/dist/vuefinder' const app = createApp(App) //By default, Vuefinder will use English as the main language. // However, if you want to support multiple languages and customize the localization, // you can import the language files manually during component registration. app.use(VueFinder) app.mount('#app') ``` ### Localization You can manually import the localization files from the package and register them with Vuefinder. The localization files are located in the dist/locales folder. ```js import en from 'vuefinder/dist/locales/en.js' import tr from 'vuefinder/dist/locales/tr.js' import ru from 'vuefinder/dist/locales/ru.js' app.use(VueFinder, { i18n: { en, tr, ru } }); ``` ### Async Localization Alternatively, you can import the localization files asynchronously during component registration. This can be useful for lazy loading or if you prefer to load the files dynamically. ```js app.use(VueFinder, { i18n: { en: async () => await import("vuefinder/dist/locales/en.js"), de: async () => await import("vuefinder/dist/locales/de.js"), // Add more locales as needed } }); ``` #### Vue Template ```vue <div> <vue-finder id='my_vuefinder' :request="request"></vue-finder> </div> ... <script setup> const request = "http://vuefinder-php.test" // Or ... const request = { // ----- CHANGE ME! ----- // [REQUIRED] Url for development server endpoint baseUrl: "http://vuefinder-php.test", // ----- CHANGE ME! ----- // Additional headers & params & body headers: { "X-ADDITIONAL-HEADER": 'yes' }, params: { additionalParam1: 'yes' }, body: { additionalBody1: ['yes'] }, // And/or transform request callback transformRequest: req => { if (req.method === 'get') { req.params.vf = "1" } return req; }, // XSRF Token header name xsrfHeaderName: "X-CSRF-TOKEN", } </script> ``` ### Styling Vuefinder uses the BEM (Block Element Modifier) convention for its CSS classes, with default styles applied using TailwindCSS. This structured approach helps maintain a clear and consistent naming convention for CSS classes, making it easier to understand and manage styles across the project. To customize or update the styles, simply find the appropriate BEM class in the component’s style section and override the styles as needed. ### Props | Prop | Value | Default | Description | |-------------------|:-------------:|------------|:------------------------------------------------------------| | id | string | _null_ | required | | request | string/object | _object_ | required - backend url or request object, see above | | locale | string | en | optional - default language code | | theme | string | system | optional - default theme, options: "system","light","dark" | | max-file-size | string | 10mb | optional - client side max file upload | | max-height | string | 600px | optional - max height of the component | | menu | array | [] | optional - customize right click menu(自定义右键菜单) | | features | array | _null_ | optional - array of the enabled features | | path | string | _null_ | optional - initial directory, example: 'media://public' | | persist | boolean | false | optional - keep current directory on page refresh | | full-screen | boolean | false | optional - start in full screen mode | | select-button | object | _object_ | optional - adds select button in status bar, see example | | loading-indicator | string | circular | optional - style of loading indicator: "circular", "linear" | | onError | function | _function_ | optional - a callback to implement custom error handling | ### Events | Event | Description | |-----------------------------------------|:---------------------------------------------------------------------------------------------------------------------------| | `'select': (items: any[]) => void` | The callback function is invoked when the user selects a file or folder, and the selected elements are passed as arguments | | `'update:path': (path: string) => void` | The callback function is invoked when the user opens another folder. | ### Selection There are 2 ways to select files and folders. First one, you can use the select button in the status bar. To enable the select button, you can use the select-button prop. when you set the select-button active to true, the select button will be visible in the status bar. ```vue <vue-finder id='my_vuefinder' :request="request" :select-button="handleSelectButton" /> <script setup> // other codes const handleSelectButton = { // show select button active: true, // allow multiple selection multiple: false, // handle click event click: (items, event) => { if (!items.length) { alert('No item selected'); return; } alert('Selected: ' + items[0].path); console.log(items, event); } } </script> ``` Alternatively, you can use the select event to get the selected items. ```vue <vue-finder id='my_vuefinder' :request="request" @select="handleSelect" /> <script setup> // other codes // we can define a ref object to store the selected items const selectedFiles = ref([]); // handle select event, and store the selected items const handleSelect = (selection) => { selectedFiles.value = selection } // then with a button click, you can get the selected items easily // you can add this method to the click event of a button. const handleButtonClick = () => { console.log(selectedFiles.value); } </script> ``` Customize right-click menu. ```vue <vue-finder id='my_vuefinder' :request="request" :menu="menu" /> <script setup> // other codes const menu = [ { index: 2, // position (菜单位置 越大越往下) label: "设置为数据集", // 显示名称,如果需要使用多语言,需要显示英文,然后到对应的语言包(例如zhCN.js)添加对应关系 show: (app, option) => true, // 右键时是否展示 返回值为true/false handler: (app, option) => {console.log("设置为数据集", app, option)} // 菜单点击后方法回调 } ] </script> ``` ### Features - Multi adapter/storage (see https://github.com/thephpleague/flysystem) - File and folder operations - Create a new file - Create a new folder - Rename - Delete - Archive (zip) - Unarchive (unzip) - Text editing - Image Crop Tool - Upload / Download files - Search (deep based on current folder) - Nice UI - Context Menu - Breadcrumb links - Toolbar - File explorer - Status bar - Image thumbnails - Toast notifications - Appearance - Multi language - Full Screen - View Modes: list, grid - Dark Mode - Accessibility - Drag & drop support - Move items (to a folder or up one folder) with drag and drop - Mouse selection ### Backend - PHP: [VueFinder Php Library](https://github.com/n1crack/vuefinder-php) - Python: [Python WSGI](https://github.com/abichinger/vuefinder-wsgi) - Go: [vuefinder-go](https://github.com/Duke1616/vuefinder-go) - Rust: [vuefinder-rust](https://github.com/boenfu/vuefinder-rust) You can use any backend language. Just be sure, the response should be compatible. If you develop a backend library for another language, please let me know to add it here. ### Collaboration If you want to contribute to the project, please feel free to fork the repository and submit your changes as a pull request. Ensure that the changes you submit are applicable for general use rather than specific to your project. ### Dependencies - [Vue3](https://vuejs.org/) - [Cropperjs](https://github.com/fengyuanchen/cropperjs) : JavaScript image cropper - [DragSelect](https://github.com/ThibaultJanBeyer/DragSelect/) : Selection utility - [Uppy](https://github.com/transloadit/uppy) : Upload library - [vanilla-lazyload](https://github.com/verlok/vanilla-lazyload) : lightweight and flexible lazy loading for thumbnails - [mitt](https://github.com/developit/mitt) : Tiny 200 byte functional event emitter / pubsub - [OverlayScrollbars](https://kingsora.github.io/OverlayScrollbars) : scrollbar plugin ### License Copyright (c) 2018 Yusuf ÖZDEMİR, released under [the MIT license](LICENSE)