Skip to content

Commit

Permalink
增加图片裁剪插件示例
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Sep 4, 2024
1 parent 8bf90c3 commit 76336c1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"animate.css": "^4.1.1",
"axios": "^1.7.7",
"bytemd": "^1.21.0",
"cropperjs": "^1.6.2",
"dayjs": "^1.11.13",
"defu": "^6.1.4",
"disable-devtool": "^0.3.7",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/router/modules/plugin.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ const routes: RouteRecordRaw = {
icon: 'i-mdi:file-eye-outline',
},
},
{
path: 'cropper',
name: 'pluginExampleCropper',
component: () => import('@/views/plugin_example/cropper.vue'),
meta: {
title: '图片裁剪',
icon: 'i-mdi:crop',
},
},
],
}

Expand Down
61 changes: 61 additions & 0 deletions src/views/plugin_example/cropper.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<route lang="yaml">
meta:
enabled: false
</route>

<script lang="ts" setup>
import Cropper from 'cropperjs'
import 'cropperjs/dist/cropper.css'
import Alert from './components/alert.vue'
let cropper: any = null
const imageRef = ref()
const cropImage = ref('')
onMounted(() => {
cropper = new Cropper(imageRef.value, {
aspectRatio: 1,
viewMode: 1,
dragMode: 'move',
})
})
function onCrop() {
const canvas = cropper.getCroppedCanvas()
cropImage.value = canvas.toDataURL()
}
function open(url: string) {
window.open(url, '_blank')
}
</script>

<template>
<div>
<Alert />
<PageHeader title="图片裁剪">
<template #content>
<p style="margin-bottom: 0;">
安装命令:<ElTag>pnpm add cropperjs</ElTag>
</p>
</template>
<ElButton @click="open('https://github.com/fengyuanchen/cropperjs')">
<template #icon>
<SvgIcon name="i-ep:link" />
</template>
访问 cropperjs
</ElButton>
</PageHeader>
<PageMain>
<div>
<img ref="imageRef" src="@/assets/images/logo.png" class="block h-xl w-xl">
</div>
<HButton @click="onCrop">
裁剪
</HButton>
</PageMain>
<PageMain v-if="cropImage">
<img :src="cropImage" class="block h-xs w-xs">
</PageMain>
</div>
</template>

0 comments on commit 76336c1

Please sign in to comment.