优化上传组件

This commit is contained in:
plightfield 2024-09-09 18:39:15 +08:00
parent 0bfd823733
commit ece577a0ae
4 changed files with 44 additions and 9 deletions

View File

@ -24,6 +24,8 @@
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.3", "pinia-plugin-persistedstate": "^3.2.3",
"uuid": "^10.0.0", "uuid": "^10.0.0",
"v-viewer": "^3.0.13",
"viewerjs": "^1.11.6",
"vue": "^3.4.29" "vue": "^3.4.29"
}, },
"devDependencies": { "devDependencies": {

View File

@ -11,7 +11,7 @@ import {
Modal Modal
} from 'ant-design-vue' } from 'ant-design-vue'
import useSearchConfigStore from './useSearchConfigStore' import useSearchConfigStore from './useSearchConfigStore'
import { EditOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons-vue' import { EditOutlined, DeleteOutlined, PlusOutlined, CheckOutlined } from '@ant-design/icons-vue'
import asyncLoader from '@/utils/asyncLoader' import asyncLoader from '@/utils/asyncLoader'
const ImageUploader = asyncLoader(() => import('@/utils/ImageUploader')) const ImageUploader = asyncLoader(() => import('@/utils/ImageUploader'))
const SearchItem = defineComponent({ const SearchItem = defineComponent({
@ -188,7 +188,7 @@ export default defineComponent(() => {
<ImageUploader v-model:value={addState.icon} /> <ImageUploader v-model:value={addState.icon} />
</Form.Item> </Form.Item>
<Form.Item class="flex justify-end mb-0"> <Form.Item class="flex justify-end mb-0">
<Button type="primary" htmlType="submit"> <Button type="primary" htmlType="submit" icon={<CheckOutlined />}>
</Button> </Button>
</Form.Item> </Form.Item>

View File

@ -39,6 +39,16 @@ body {
position: relative; position: relative;
top: -3px; top: -3px;
} }
.ant-modal-content {
background-color: rgba(255, 255, 255, 0.9) !important;
backdrop-filter: blur(20px);
}
.ant-modal-header {
background-color: transparent !important;
}
.viewer-backdrop {
backdrop-filter: blur(10px);
}
/* 滚动条样式 */ /* 滚动条样式 */
::-webkit-scrollbar { ::-webkit-scrollbar {

View File

@ -1,10 +1,12 @@
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import { OhVueIcon, addIcons } from 'oh-vue-icons' import { OhVueIcon, addIcons } from 'oh-vue-icons'
import { MdUpload } from 'oh-vue-icons/icons' import { MdUpload, FaEye } from 'oh-vue-icons/icons'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import upload from './upload' import upload from './upload'
import 'viewerjs/dist/viewer.css'
import { api as showViewer } from 'v-viewer'
addIcons(MdUpload) addIcons(MdUpload, FaEye)
// !清 asyncLoader 加载使用 // !清 asyncLoader 加载使用
export default defineComponent({ export default defineComponent({
@ -39,7 +41,9 @@ export default defineComponent({
style="display:none" style="display:none"
ref={(el) => (input = el as any)} ref={(el) => (input = el as any)}
onChange={(e) => { onChange={(e) => {
const file: File | undefined = (e.target as any).files?.[0] const el = e.target as any
const file: File | undefined = el.files?.[0]
el.value = ''
if (!file) return if (!file) return
console.log(file.size, props.size) console.log(file.size, props.size)
if (file.size > props.size * 1000 * 1000) { if (file.size > props.size * 1000 * 1000) {
@ -47,13 +51,12 @@ export default defineComponent({
return return
} }
upload(file, 'test').then((res) => { upload(file, 'test').then((res) => {
console.log(res)
ctx.emit('update:value', res) ctx.emit('update:value', res)
}) })
}} }}
/> />
<div <div
class="flex justify-center items-center rounded bg-slate-200 hover:bg-slate-300 transition-all cursor-pointer bg-cover bg-no-repeat bg-center" class="flex justify-center items-center rounded bg-slate-200 hover:bg-slate-300 transition-all bg-cover bg-no-repeat bg-center cursor-pointer"
style={{ style={{
width: props.width + 'px', width: props.width + 'px',
height: props.width / props.ratio + 'px', height: props.width / props.ratio + 'px',
@ -63,9 +66,29 @@ export default defineComponent({
input?.click() input?.click()
}} }}
> >
{!props.value && <OhVueIcon name="md-upload" scale={2} fill="rgba(0,0,0,0.2)" />} {props.value ? (
<div class="w-full h-full opacity-0 hover:opacity-100 relative transition-all bg-slate-800/20 flex justify-center items-center">
<div
class="px-1 rounded hover:bg-white/20"
onClick={(e) => {
e.stopPropagation()
showViewer({
images: [props.value],
options: {
navbar: false,
toolbar: false
}
})
}}
>
<OhVueIcon name="fa-eye" scale={1.2} fill="rgba(255,255,255,.4)" />
</div>
</div>
) : (
<OhVueIcon name="md-upload" scale={2} fill="rgba(0,0,0,0.2)" />
)}
</div> </div>
<div class="text-xs mt-1 text-black/60"> .png, .jpeg, .jpg, .svg</div> <div class="text-xs mt-1 text-black/60"> .png, .jpeg, .jpg, .svg</div>{' '}
</div> </div>
) )
} }