-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 添加资源按钮管理功能及组件支持 * feat: 增强资源按钮交互及上传功能 * feat: 改进资源上传接口及事件处理逻辑
- Loading branch information
Showing
6 changed files
with
159 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* MineAdmin is committed to providing solutions for quickly building web applications | ||
* Please view the LICENSE file that was distributed with this source code, | ||
* For the full copyright and license information. | ||
* Thank you very much for using MineAdmin. | ||
* | ||
* @Author X.Mo<[email protected]> | ||
* @Link https://github.com/mineadmin | ||
*/ | ||
import type { Resources } from '#/global' | ||
import { uploadLocal } from '@/utils/uploadLocal.ts' | ||
|
||
const resourceDefaultButtons: Resources.Button[] = [ | ||
{ | ||
name: 'local-image-upload', | ||
label: '图片上传', | ||
icon: 'solar:upload-square-broken', | ||
upload: (files: FileList, args: Resources.Args) => { | ||
const options = { file: files[0] } | ||
uploadLocal(options).then(() => { | ||
args?.getResourceList?.() | ||
}).catch((e) => { | ||
throw new Error(e) | ||
}) | ||
}, | ||
uploadConfig: { | ||
accept: 'image/*', | ||
limit: 1, | ||
}, | ||
order: 0, | ||
}, | ||
{ | ||
name: 'local-file-upload', | ||
label: '文件上传', | ||
icon: 'hugeicons:file-upload', | ||
upload: (files: FileList, args: Resources.Args) => { | ||
const options = { file: files[0] } | ||
uploadLocal(options).then(() => { | ||
args?.getResourceList?.() | ||
}).catch((e) => { | ||
throw new Error(e) | ||
}) | ||
}, | ||
uploadConfig: { | ||
accept: '.doc,.xls,.ppt,.txt,.pdf', | ||
limit: 1, | ||
}, | ||
order: 1, | ||
}, | ||
] | ||
|
||
const useResourceStore = defineStore( | ||
'useResourceStore', | ||
() => { | ||
const resourceButtons = ref<Resources.Button[]>([]) | ||
|
||
const getButton = (name: string): Resources.Button | undefined => { | ||
return resourceButtons.value.find(item => item.name === name) | ||
} | ||
|
||
const addButton = (button: Resources.Button): boolean => { | ||
if (getButton(button.name)) { | ||
return false | ||
} | ||
else { | ||
resourceButtons.value.push(button) | ||
return true | ||
} | ||
} | ||
|
||
const removeButton = (name: string) => { | ||
resourceButtons.value = resourceButtons.value.filter(item => item.name !== name) | ||
} | ||
|
||
const getAllButton = () => { | ||
return resourceButtons.value | ||
} | ||
|
||
resourceDefaultButtons.forEach(item => addButton(item)) | ||
|
||
return { | ||
addButton, | ||
removeButton, | ||
getButton, | ||
getAllButton, | ||
} | ||
}, | ||
) | ||
|
||
export default useResourceStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import type {UploadRequestOptions} from "element-plus"; | ||
|
||
/** | ||
* MineAdmin is committed to providing solutions for quickly building web applications | ||
* Please view the LICENSE file that was distributed with this source code, | ||
|
@@ -9,14 +7,14 @@ import type {UploadRequestOptions} from "element-plus"; | |
* @Author X.Mo<[email protected]> | ||
* @Link https://github.com/mineadmin | ||
*/ | ||
export function uploadLocal(options: UploadRequestOptions, url?: string = '/admin/attachment/upload', key?: string = 'file') { | ||
export function uploadLocal(options: any, url?: string, key?: string) { | ||
const upload = (formData: FormData) => { | ||
return useHttp().post(url, formData) | ||
return useHttp().post(url ?? '/admin/attachment/upload', formData) | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
const formData = new FormData() | ||
formData.append(key, options.file) | ||
formData.append(key ?? 'file', options.file) | ||
upload(formData).then((res: Record<string, any>) => { | ||
res.code === 200 ? resolve(res) : reject(res) | ||
}).catch((err) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters