lyrasoft / attachment
LYRASOFT 附件包
1.0.5
2023-12-22 07:29 UTC
Requires
- lyrasoft/luna: ^1.0||^2.0
- myclabs/php-enum: ^1.8
README
安装
composer require lyrasoft/attachment
当需要更改 mig、entity、repo 时可以复制出来
php windwalker pkg:install lyrasoft/attachment -t migrations -t entity -t attachment_modal
使用
首先到 unicorn.php
中注册 AttachmentPackage
'unicorn' => [
.....
'providers' => [
\Lyrasoft\Attachment\AttachmentPackage::class,
],
]
<x-attachment-field
:items="$attachments"
:insertBtn="true"
:accept="'pdf,gif'"
>
</x-attachment-field>
选项
如果要单独使用文件列表或是上传Input的话也可以单独使用
<!-- 一般使用,啟動插入文章功能。預設會指定 #input-tiem-fulltext --> <x-attachment-field :items="$attachments" :insertBtn="true"></x-attachment-field> <!-- 一般使用,啟動插入文章功能。自訂 Tinymce id --> <!-- 插入 file-drag 專屬 options --> <x-attachment-field :options="$options" insertBtn="#input-item-content"></x-attachment-field> <!-- 頁面上插入第二組時,可以自訂另一個 name --> <!-- id 也可以自訂,如果沒自訂,會用隨機碼,不會衝突 --> <x-attachment-field id="input-attachments-other" name="othert_attachments" :options="$options" insertBtn="#input-item-content"></x-attachment-field>
CSS / JS
插入 attachment 元素后,就会自动插入,如果需要手动引入,可以下面代码
$asset->css('vendor/lyrasoft/attachment/dist/attachment.min.css'); $asset->js('vendor/lyrasoft/attachment/dist/attachment.min.js');
插槽
如果你想自定义额外的按钮的动作,可以使用 buttons
插槽
<x-attachment-field :items="$attachments">
<x-slot name="buttons">
@scope($item, $i)
Do anything with $item
</x-slot>
</x-attachment-field>
单独引入组件
<attachment-field>
: 最完整的组件,包含列表 & 上传器<attachment-uploader>
: 使用 file-drag 做的上传器<attachment-list>
: 上传附件列表
备注
- 记得要在 view 中利用
repo
或是ORM
取出 attachments 并塞入 field 的 option 中。 - 在controller 内记得写存储及删除的内容,有删除文件的话可以从中
$app->input()
取得remove_attachments
里面是 attachment 的 ID